1 package net.mograsim.logic.ui.examples;
3 import java.io.IOException;
5 import net.mograsim.logic.ui.SimpleLogicUIStandalone;
6 import net.mograsim.logic.ui.model.ViewModelModifiable;
7 import net.mograsim.logic.ui.model.components.GUIBitDisplay;
8 import net.mograsim.logic.ui.model.components.GUICustomComponentCreator;
9 import net.mograsim.logic.ui.model.components.GUIManualSwitch;
10 import net.mograsim.logic.ui.model.components.SimpleRectangularSubmodelComponent;
11 import net.mograsim.logic.ui.model.components.SubmodelComponent;
12 import net.mograsim.logic.ui.model.components.mi.nandbased.GUIfulladder;
13 import net.mograsim.logic.ui.model.components.mi.nandbased.GUIhalfadder;
14 import net.mograsim.logic.ui.model.components.params.SubComponentParams;
15 import net.mograsim.logic.ui.model.wires.GUIWire;
17 public class JsonExample
19 public static void main(String[] args)
21 SimpleLogicUIStandalone.executeVisualisation(JsonExample::createHalfAdderExample);
24 private static class TestComponent extends SimpleRectangularSubmodelComponent
26 protected TestComponent(ViewModelModifiable model)
28 super(model, 1, "Test");
31 GUICustomComponentCreator.create(submodelModifiable, "HalfAdder.rc");
35 // Execute only after HalfAdder.rc has been created
36 public static void refJsonFromJsonTest(ViewModelModifiable model)
38 TestComponent t = new TestComponent(model);
39 t.calculateParams().writeJson("Test.sc");
40 SubmodelComponent c = GUICustomComponentCreator.create(model, "Test.sc");
45 public static void createHalfAdderExample(ViewModelModifiable model)
47 GUIhalfadder tmp = new GUIhalfadder(model);
49 SubComponentParams p = tmp.calculateParams();
50 SubComponentParams pC = tmp.calculateParams();
53 p.writeJson("HalfAdder.rc");
54 pC.writeJson("HalfAdder.sc");
55 p = SubComponentParams.readJson("HalfAdder.rc");
56 pC = SubComponentParams.readJson("HalfAdder.sc");
63 SubmodelComponent adder = GUICustomComponentCreator.create(model, p, "");
64 adder = GUICustomComponentCreator.create(model, pC, "");
68 @SuppressWarnings("unused") // for GUIWires being created
69 public static void createFromJsonExample(ViewModelModifiable model)
71 SimpleRectangularSubmodelComponent tmp = new GUIhalfadder(model);
73 SubComponentParams p = tmp.calculateParams();
76 p.writeJson("HalfAdder.rc");
77 p = SubComponentParams.readJson("HalfAdder.rc");
83 tmp = new GUIfulladder(model);
84 SubComponentParams pC = tmp.calculateParams();
85 tmp.moveTo(1000, 100);
88 pC.writeJson("FullAdder.sc");
89 pC = SubComponentParams.readJson("FullAdder.sc");
96 SimpleRectangularSubmodelComponent adder = new GUIfulladder(model);
98 GUIManualSwitch swA = new GUIManualSwitch(model);
100 GUIManualSwitch swB = new GUIManualSwitch(model);
102 GUIManualSwitch swC = new GUIManualSwitch(model);
105 adder.moveTo(30, 10);
106 GUIBitDisplay bdY = new GUIBitDisplay(model);
107 bdY.moveTo(90, 12.5);
108 GUIBitDisplay bdZ = new GUIBitDisplay(model);
111 new GUIWire(model, swA.getOutputPin(), adder.getInputPins().get(0));
112 new GUIWire(model, swB.getOutputPin(), adder.getInputPins().get(1));
113 new GUIWire(model, swC.getOutputPin(), adder.getInputPins().get(2));
115 new GUIWire(model, adder.getOutputPins().get(0), bdY.getInputPin());
116 new GUIWire(model, adder.getOutputPins().get(1), bdZ.getInputPin());
118 SubmodelComponent adder2 = GUICustomComponentCreator.create(model, pC, "");
120 swA = new GUIManualSwitch(model);
122 swB = new GUIManualSwitch(model);
124 swC = new GUIManualSwitch(model);
127 adder2.moveTo(30, 80);
128 bdY = new GUIBitDisplay(model);
130 bdZ = new GUIBitDisplay(model);
133 new GUIWire(model, swA.getOutputPin(), adder2.getPins().get(0));
134 new GUIWire(model, swB.getOutputPin(), adder2.getPins().get(1));
135 new GUIWire(model, swC.getOutputPin(), adder2.getPins().get(2));
137 new GUIWire(model, adder2.getPins().get(3), bdY.getInputPin());
138 new GUIWire(model, adder2.getPins().get(4), bdZ.getInputPin());