b166d5776efe52639e8ac4fbfc190fa4a2ab1530
[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;
36                 public String pinName;
37         }
38
39         public static class ComponentCompositionParams
40         {
41                 double innerScale;
42                 InnerComponentParams[] subComps;
43                 InnerWireParams[] innerWires;
44
45                 public static class InnerComponentParams
46                 {
47                         public Point pos;
48                         public String type;
49                         public int logicWidth;
50                 }
51         }
52
53         public static SubmodelComponentParams readJson(String path) throws IOException
54         {
55                 return JsonHandler.readJson(path, SubmodelComponentParams.class);
56         }
57
58         /**
59          * Writes this {@link SubmodelComponentParams} object into a file in json format. The correct file extension is important! Check
60          * {@link SubmodelComponentParams}.fileExtension
61          */
62         public void writeJson(String path)
63         {
64                 try
65                 {
66                         JsonHandler.writeJson(this, path);
67                 }
68                 catch (IOException e)
69                 {
70                         System.err.println("Failed to write SubComponentParams to file");
71                         e.printStackTrace();
72                 }
73         }
74 }