Added two SymbolRendererProviders
[Mograsim.git] / net.mograsim.logic.ui.am2900 / src / net / mograsim / logic / ui / examples / ComponenetSerializer.java
1 package net.mograsim.logic.ui.examples;
2
3 import java.io.IOException;
4 import java.util.function.Function;
5
6 import com.google.gson.JsonObject;
7
8 import net.mograsim.logic.ui.model.ViewModelModifiable;
9 import net.mograsim.logic.ui.model.components.GUIComponent;
10 import net.mograsim.logic.ui.model.components.mi.nandbased.GUI_rsLatch;
11 import net.mograsim.logic.ui.model.components.mi.nandbased.GUIand;
12 import net.mograsim.logic.ui.model.components.mi.nandbased.GUIand41;
13 import net.mograsim.logic.ui.model.components.mi.nandbased.GUIandor414;
14 import net.mograsim.logic.ui.model.components.mi.nandbased.GUIdemux2;
15 import net.mograsim.logic.ui.model.components.mi.nandbased.GUIdff;
16 import net.mograsim.logic.ui.model.components.mi.nandbased.GUIdlatch;
17 import net.mograsim.logic.ui.model.components.mi.nandbased.GUIdlatch4;
18 import net.mograsim.logic.ui.model.components.mi.nandbased.GUIfulladder;
19 import net.mograsim.logic.ui.model.components.mi.nandbased.GUIhalfadder;
20 import net.mograsim.logic.ui.model.components.mi.nandbased.GUImux1;
21 import net.mograsim.logic.ui.model.components.mi.nandbased.GUImux1_4;
22 import net.mograsim.logic.ui.model.components.mi.nandbased.GUInand3;
23 import net.mograsim.logic.ui.model.components.mi.nandbased.GUInot4;
24 import net.mograsim.logic.ui.model.components.mi.nandbased.GUIor4;
25 import net.mograsim.logic.ui.model.components.mi.nandbased.GUIor_4;
26 import net.mograsim.logic.ui.model.components.mi.nandbased.GUIram2;
27 import net.mograsim.logic.ui.model.components.mi.nandbased.GUIram4;
28 import net.mograsim.logic.ui.model.components.mi.nandbased.GUIsel2_4;
29 import net.mograsim.logic.ui.model.components.mi.nandbased.GUIsel3_4;
30 import net.mograsim.logic.ui.model.components.mi.nandbased.GUIxor;
31 import net.mograsim.logic.ui.model.components.mi.nandbased.am2901.GUIAm2901;
32 import net.mograsim.logic.ui.model.components.mi.nandbased.am2901.GUIAm2901ALUFuncDecode;
33 import net.mograsim.logic.ui.model.components.mi.nandbased.am2901.GUIAm2901ALUInclDecode;
34 import net.mograsim.logic.ui.model.components.mi.nandbased.am2901.GUIAm2901ALUInclSourceDecodeInclFunctionDecode;
35 import net.mograsim.logic.ui.model.components.mi.nandbased.am2901.GUIAm2901ALUOneBit;
36 import net.mograsim.logic.ui.model.components.mi.nandbased.am2901.GUIAm2901DestDecode;
37 import net.mograsim.logic.ui.model.components.mi.nandbased.am2901.GUIAm2901QReg;
38 import net.mograsim.logic.ui.model.components.mi.nandbased.am2901.GUIAm2901SourceDecode;
39 import net.mograsim.logic.ui.model.components.submodels.SubmodelComponent;
40 import net.mograsim.logic.ui.serializing.SubmodelComponentParams;
41 import net.mograsim.logic.ui.util.JsonHandler;
42
43 public class ComponenetSerializer
44 {
45         public static void main(String[] args) throws IOException
46         {
47                 // we know we only use components where this works
48                 Function<GUIComponent, String> getIdentifier = c -> c.getClass().getSimpleName();
49
50                 ViewModelModifiable model = new ViewModelModifiable();
51                 SubmodelComponent[] components = { new GUIAm2901(model), new GUIAm2901ALUFuncDecode(model), new GUIAm2901ALUInclDecode(model),
52                                 new GUIAm2901ALUInclSourceDecodeInclFunctionDecode(model), new GUIAm2901ALUOneBit(model), new GUIAm2901DestDecode(model),
53                                 new GUIAm2901QReg(model), new GUIAm2901SourceDecode(model), new GUI_rsLatch(model), new GUIand(model), new GUIand41(model),
54                                 new GUIandor414(model), new GUIdemux2(model), new GUIdff(model), new GUIdlatch(model), new GUIdlatch4(model),
55                                 new GUIfulladder(model), new GUIhalfadder(model), new GUImux1(model), new GUImux1_4(model), new GUInand3(model),
56                                 new GUInot4(model), new GUIor4(model), new GUIor_4(model), new GUIram2(model), new GUIram4(model), new GUIsel2_4(model),
57                                 new GUIsel3_4(model), new GUIxor(model) };
58
59                 for (SubmodelComponent comp : components)
60                 {
61                         SubmodelComponentParams params = comp.calculateParams(getIdentifier);
62                         JsonObject symbolRendererParams = new JsonObject();
63                         symbolRendererParams.addProperty("centerText", comp.getClass().getSimpleName().substring(3)); // cut away the "GUI" part
64                         symbolRendererParams.addProperty("horizontalComponentCenter", comp.getWidth() / 2);
65                         // use the defaults from SimpleRectangularSubmodelComponent
66                         symbolRendererParams.addProperty("centerTextHeight", 5);
67                         symbolRendererParams.addProperty("pinLabelHeight", 3.5);
68                         symbolRendererParams.addProperty("pinLabelMargin", .5);
69                         params.symbolRendererSnippetID = "SimpleRectangularLikeSymbolRenderer";
70                         params.symbolRendererParams = symbolRendererParams;
71                         JsonHandler.writeJson(params, "components/"
72                                         + comp.getClass().getName().substring("net.mograsim.logic.ui.model.components.mi.nandbased.".length()).replace('.', '/')
73                                         + ".json");
74                 }
75         }
76 }