Pins now have names
[Mograsim.git] / net.mograsim.logic.ui / src / net / mograsim / logic / ui / model / components / SubmodelComponentParams.java
1 package net.mograsim.logic.ui.model.components;
2
3 import java.io.IOException;
4 import java.util.Map;
5
6 import net.haspamelodica.swt.helper.swtobjectwrappers.Point;
7 import net.mograsim.logic.ui.util.JsonHandler;
8
9 /**
10  * This class contains all the information necessary to create a new {@link SubmodelComponent}
11  */
12 public class SubmodelComponentParams
13 {
14         String type;
15         double width, height;
16         InterfacePinParams[] interfacePins;
17         ComponentCompositionParams composition;
18         Map<String, Object> specialized;
19
20         public static class InterfacePinParams
21         {
22                 public Point location;
23                 public String name;
24                 public int logicWidth;
25         }
26
27         public static class InnerWireParams
28         {
29                 public InnerPinParams pin1, pin2;
30                 public Point[] path;
31         }
32
33         public static class InnerPinParams
34         {
35                 public int compId, pinIndex;
36         }
37
38         public static class ComponentCompositionParams
39         {
40                 double innerScale;
41                 InnerComponentParams[] subComps;
42                 InnerWireParams[] innerWires;
43
44                 public static class InnerComponentParams
45                 {
46                         public Point pos;
47                         public String type;
48                         public int logicWidth;
49                 }
50         }
51
52         public static SubmodelComponentParams readJson(String path) throws IOException
53         {
54                 return JsonHandler.readJson(path, SubmodelComponentParams.class);
55         }
56
57         /**
58          * Writes this {@link SubmodelComponentParams} object into a file in json format. The correct file extension is important! Check
59          * {@link SubmodelComponentParams}.fileExtension
60          */
61         public void writeJson(String path)
62         {
63                 try
64                 {
65                         JsonHandler.writeJson(this, path);
66                 }
67                 catch (IOException e)
68                 {
69                         System.err.println("Failed to write SubComponentParams to file");
70                         e.printStackTrace();
71                 }
72         }
73 }