The final restructured version for automatic build using maven tycho
[Mograsim.git] / plugins / net.mograsim.logic.model / src / net / mograsim / logic / model / serializing / LegacySubmodelComponentParams.java
1 package net.mograsim.logic.model.serializing;
2
3 import java.io.IOException;
4
5 import com.google.gson.JsonElement;
6
7 import net.haspamelodica.swt.helper.swtobjectwrappers.Point;
8 import net.mograsim.logic.model.model.components.submodels.SubmodelComponent;
9 import net.mograsim.logic.model.util.JsonHandler;
10
11 /**
12  * This class contains all the information necessary to create a new {@link SubmodelComponent}
13  */
14 public class LegacySubmodelComponentParams
15 {
16         // basic stuff
17         public double width, height;
18         public LegacyInterfacePinParams[] interfacePins;
19         public LegacySubmodelParameters submodel;
20
21         // functionality that needs to be expressed in Java code
22         public String symbolRendererSnippetID;
23         public JsonElement symbolRendererParams;
24
25         public String outlineRendererSnippetID;
26         public JsonElement outlineRendererParams;
27
28         public String highLevelStateHandlerSnippetID;
29         public JsonElement highLevelStateHandlerParams;
30
31         public static class LegacyInterfacePinParams
32         {
33                 public Point location;
34                 public String name;
35                 public int logicWidth;
36         }
37
38         public static class LegacySubmodelParameters
39         {
40                 public double innerScale;
41                 public LegacyInnerComponentParams[] subComps;
42                 public LegacyInnerWireParams[] innerWires;
43
44                 public static class LegacyInnerComponentParams
45                 {
46                         public String id;
47                         public String name;
48                         public Point pos;
49                         public JsonElement params;
50                 }
51
52                 public static class LegacyInnerWireParams
53                 {
54                         public LegacyInnerPinParams pin1, pin2;
55                         public String name;
56                         public Point[] path;
57
58                         public static class LegacyInnerPinParams
59                         {
60                                 public String compName;
61                                 public String pinName;
62                         }
63                 }
64         }
65
66         public static LegacySubmodelComponentParams readJson(String path) throws IOException
67         {
68                 return JsonHandler.readJson(path, LegacySubmodelComponentParams.class);
69         }
70
71         /**
72          * Writes this {@link LegacySubmodelComponentParams} object into a file in json format. The correct file extension is important! Check
73          * {@link LegacySubmodelComponentParams}.fileExtension
74          */
75         public void writeJson(String path)
76         {
77                 try
78                 {
79                         JsonHandler.writeJson(this, path);
80                 }
81                 catch (IOException e)
82                 {
83                         System.err.println("Failed to write SubComponentParams to file");
84                         e.printStackTrace();
85                 }
86         }
87 }