Merge branch 'development' of https://gitlab.lrz.de/lrr-tum/students/eragp-misim...
[Mograsim.git] / net.mograsim.logic.model / src / net / mograsim / logic / model / serializing / SubmodelComponentParams.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 SubmodelComponentParams
15 {
16         // basic stuff
17         public double width, height;
18         public InterfacePinParams[] interfacePins;
19         public SubmodelParameters submodel;
20
21         // functionality that needs to be expressed in Java code
22         public String outlineRendererSnippetID;
23         public JsonElement outlineRendererParams;
24
25         public String symbolRendererSnippetID;
26         public JsonElement symbolRendererParams;
27
28         public String highLevelStateHandlerSnippetID;
29         public JsonElement highLevelStateHandlerParams;
30
31         public static class InterfacePinParams
32         {
33                 public Point location;
34                 public String name;
35                 public int logicWidth;
36         }
37
38         public static class SubmodelParameters
39         {
40                 public double innerScale;
41                 public InnerComponentParams[] subComps;
42                 public InnerWireParams[] innerWires;
43
44                 public static class InnerComponentParams
45                 {
46                         public Point pos;
47                         public String id;
48                         public String name;
49                         public JsonElement params;
50                 }
51
52                 public static class InnerWireParams
53                 {
54                         public InnerPinParams pin1, pin2;
55                         public Point[] path;
56
57                         public static class InnerPinParams
58                         {
59                                 public String compName;
60                                 public String pinName;
61                         }
62                 }
63         }
64
65         public static SubmodelComponentParams readJson(String path) throws IOException
66         {
67                 return JsonHandler.readJson(path, SubmodelComponentParams.class);
68         }
69
70         /**
71          * Writes this {@link SubmodelComponentParams} object into a file in json format. The correct file extension is important! Check
72          * {@link SubmodelComponentParams}.fileExtension
73          */
74         public void writeJson(String path)
75         {
76                 try
77                 {
78                         JsonHandler.writeJson(this, path);
79                 }
80                 catch (IOException e)
81                 {
82                         System.err.println("Failed to write SubComponentParams to file");
83                         e.printStackTrace();
84                 }
85         }
86 }