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.GUIComponent;
9 import net.mograsim.logic.ui.model.components.GUICustomComponentCreator;
10 import net.mograsim.logic.ui.model.components.GUIManualSwitch;
11 import net.mograsim.logic.ui.model.components.SimpleRectangularSubmodelComponent;
12 import net.mograsim.logic.ui.model.components.SubmodelComponent;
13 import net.mograsim.logic.ui.model.components.mi.nandbased.GUIand;
14 import net.mograsim.logic.ui.model.components.mi.nandbased.GUIfulladder;
15 import net.mograsim.logic.ui.model.components.mi.nandbased.GUIhalfadder;
16 import net.mograsim.logic.ui.model.components.mi.nandbased.GUImux1;
17 import net.mograsim.logic.ui.model.components.mi.nandbased.GUImux1_4;
18 import net.mograsim.logic.ui.model.components.mi.nandbased.GUIsel2_4;
19 import net.mograsim.logic.ui.model.components.params.RectComponentParams;
20 import net.mograsim.logic.ui.model.components.params.SubComponentParams;
21 import net.mograsim.logic.ui.model.wires.GUIWire;
23 public class JsonExample
25 public static void main(String[] args)
27 SimpleLogicUIStandalone.executeVisualisation(JsonExample::createFromJsonExample);
30 private static class TestComponent extends SimpleRectangularSubmodelComponent
32 protected TestComponent(ViewModelModifiable model)
34 super(model, 1, "Test");
37 GUICustomComponentCreator.create(submodelModifiable, "HalfAdder.rc");
41 // Execute only after HalfAdder.rc has been created
42 public static void refJsonFromJsonTest(ViewModelModifiable model)
44 TestComponent t = new TestComponent(model);
45 t.calculateParams().writeJson("Test.sc");
46 SubmodelComponent c = GUICustomComponentCreator.create(model, "Test.sc");
51 public static void createHalfAdderExample(ViewModelModifiable model)
53 GUIhalfadder tmp = new GUIhalfadder(model);
55 RectComponentParams p = tmp.calculateRectParams();
56 SubComponentParams pC = tmp.calculateParams();
59 p.writeJson("HalfAdder.rc");
60 pC.writeJson("HalfAdder.sc");
61 p = RectComponentParams.readJson("HalfAdder.rc");
62 pC = SubComponentParams.readJson("HalfAdder.sc");
69 SubmodelComponent adder = GUICustomComponentCreator.create(model, p, "");
70 adder = GUICustomComponentCreator.create(model, pC, "");
74 @SuppressWarnings("unused") // for GUIWires being created
75 public static void createFromJsonExample(ViewModelModifiable model)
77 SimpleRectangularSubmodelComponent tmp = new GUIhalfadder(model);
79 RectComponentParams p = tmp.calculateRectParams();
82 p.writeJson("HalfAdder.rc");
83 p = RectComponentParams.readJson("HalfAdder.rc");
89 tmp = new GUIfulladder(model);
90 SubComponentParams pC = tmp.calculateParams();
91 tmp.moveTo(1000, 100);
94 pC.writeJson("FullAdder.sc");
95 pC = SubComponentParams.readJson("FullAdder.sc");
102 SimpleRectangularSubmodelComponent adder = new GUIfulladder(model);
104 GUIManualSwitch swA = new GUIManualSwitch(model);
106 GUIManualSwitch swB = new GUIManualSwitch(model);
108 GUIManualSwitch swC = new GUIManualSwitch(model);
111 adder.moveTo(30, 10);
112 GUIBitDisplay bdY = new GUIBitDisplay(model);
113 bdY.moveTo(90, 12.5);
114 GUIBitDisplay bdZ = new GUIBitDisplay(model);
117 new GUIWire(model, swA.getOutputPin(), adder.getInputPins().get(0));
118 new GUIWire(model, swB.getOutputPin(), adder.getInputPins().get(1));
119 new GUIWire(model, swC.getOutputPin(), adder.getInputPins().get(2));
121 new GUIWire(model, adder.getOutputPins().get(0), bdY.getInputPin());
122 new GUIWire(model, adder.getOutputPins().get(1), bdZ.getInputPin());
124 SubmodelComponent adder2 = GUICustomComponentCreator.create(model, pC, "");
126 swA = new GUIManualSwitch(model);
128 swB = new GUIManualSwitch(model);
130 swC = new GUIManualSwitch(model);
133 adder2.moveTo(30, 80);
134 bdY = new GUIBitDisplay(model);
136 bdZ = new GUIBitDisplay(model);
139 new GUIWire(model, swA.getOutputPin(), adder2.getPins().get(0));
140 new GUIWire(model, swB.getOutputPin(), adder2.getPins().get(1));
141 new GUIWire(model, swC.getOutputPin(), adder2.getPins().get(2));
143 new GUIWire(model, adder2.getPins().get(3), bdY.getInputPin());
144 new GUIWire(model, adder2.getPins().get(4), bdZ.getInputPin());