Simplified file representation of SubmodelComponents
[Mograsim.git] / net.mograsim.logic.ui / src / net / mograsim / logic / ui / model / components / params / SubComponentParams.java
1 package net.mograsim.logic.ui.model.components.params;
2
3 import java.io.IOException;
4 import java.util.Map;
5
6 import net.haspamelodica.swt.helper.swtobjectwrappers.Point;
7
8 public class SubComponentParams
9 {
10         public String type;
11         public final static String fileExtension = ".sc";
12         public double width, height;
13         public InterfacePinParams[] interfacePins;
14         public GeneralComponentParams composition;
15         public Map<String, Object> specialized;
16
17         public static class InterfacePinParams
18         {
19                 public Point location;
20                 public int logicWidth;
21         }
22
23         public static class InnerWireParams
24         {
25                 public InnerPinParams pin1, pin2;
26                 public Point[] path;
27         }
28
29         public static class InnerPinParams
30         {
31                 public int compId, pinIndex;
32         }
33
34         public static SubComponentParams readJson(String path) throws IOException
35         {
36                 return JsonHandler.readJson(path, SubComponentParams.class);
37         }
38
39         /**
40          * Writes this {@link SubComponentParams} object into a file in json format. The correct file extension is important! Check
41          * {@link SubComponentParams}.fileExtension
42          */
43         public void writeJson(String path)
44         {
45                 try
46                 {
47                         JsonHandler.writeJson(this, path);
48                 }
49                 catch (IOException e)
50                 {
51                         System.err.println("Failed to write SubComponentParams to file");
52                         e.printStackTrace();
53                 }
54         }
55 }