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