X-Git-Url: https://mograsim.net/gitweb/?a=blobdiff_plain;f=net.mograsim.logic.ui%2Fsrc%2Fnet%2Fmograsim%2Flogic%2Fui%2Fexamples%2FJsonExample.java;h=9596a6934cd2b2de2be3ff199dcfcca12f834e7b;hb=19ee1a7fdb06a1df65cd7df78fed935124496707;hp=ac39fa34b0e10e2c9081b0a56cafec041c424079;hpb=b555e4c29e14f455d8ffbc810284c7bb44b459f9;p=Mograsim.git diff --git a/net.mograsim.logic.ui/src/net/mograsim/logic/ui/examples/JsonExample.java b/net.mograsim.logic.ui/src/net/mograsim/logic/ui/examples/JsonExample.java index ac39fa34..9596a693 100644 --- a/net.mograsim.logic.ui/src/net/mograsim/logic/ui/examples/JsonExample.java +++ b/net.mograsim.logic.ui/src/net/mograsim/logic/ui/examples/JsonExample.java @@ -9,16 +9,16 @@ import net.mograsim.logic.ui.model.components.GUICustomComponentCreator; import net.mograsim.logic.ui.model.components.GUIManualSwitch; import net.mograsim.logic.ui.model.components.SimpleRectangularSubmodelComponent; import net.mograsim.logic.ui.model.components.SubmodelComponent; +import net.mograsim.logic.ui.model.components.SubmodelComponentParams; import net.mograsim.logic.ui.model.components.mi.nandbased.GUIfulladder; import net.mograsim.logic.ui.model.components.mi.nandbased.GUIhalfadder; -import net.mograsim.logic.ui.model.components.params.SubComponentParams; import net.mograsim.logic.ui.model.wires.GUIWire; public class JsonExample { public static void main(String[] args) { - SimpleLogicUIStandalone.executeVisualisation(JsonExample::createHalfAdderExample); + SimpleLogicUIStandalone.executeVisualisation(JsonExample::refJsonFromJsonTest); } private static class TestComponent extends SimpleRectangularSubmodelComponent @@ -26,18 +26,18 @@ public class JsonExample protected TestComponent(ViewModelModifiable model) { super(model, 1, "Test"); - setInputCount(1); setSubmodelScale(.4); - GUICustomComponentCreator.create(submodelModifiable, "HalfAdder.rc"); + setInputPins("Input pin #0"); + GUICustomComponentCreator.create(submodelModifiable, "HalfAdder.json"); } } - // Execute only after HalfAdder.rc has been created + // Execute only after HalfAdder.json has been created public static void refJsonFromJsonTest(ViewModelModifiable model) { TestComponent t = new TestComponent(model); - t.calculateParams().writeJson("Test.sc"); - SubmodelComponent c = GUICustomComponentCreator.create(model, "Test.sc"); + t.calculateParams().writeJson("Test.json"); + SubmodelComponent c = GUICustomComponentCreator.create(model, "Test.json"); c.moveTo(0, 50); } @@ -46,54 +46,38 @@ public class JsonExample { GUIhalfadder tmp = new GUIhalfadder(model); tmp.moveTo(1000, 50); - SubComponentParams p = tmp.calculateParams(); - SubComponentParams pC = tmp.calculateParams(); + SubmodelComponentParams p = tmp.calculateParams(); try { - p.writeJson("HalfAdder.rc"); - pC.writeJson("HalfAdder.sc"); - p = SubComponentParams.readJson("HalfAdder.rc"); - pC = SubComponentParams.readJson("HalfAdder.sc"); + p.writeJson("HalfAdder.json"); + p = SubmodelComponentParams.readJson("HalfAdder.json"); } catch (IOException e) { e.printStackTrace(); } - SubmodelComponent adder = GUICustomComponentCreator.create(model, p, ""); - adder = GUICustomComponentCreator.create(model, pC, ""); - adder.moveTo(0, 200); + GUICustomComponentCreator.create(model, p, ""); } @SuppressWarnings("unused") // for GUIWires being created public static void createFromJsonExample(ViewModelModifiable model) { - SimpleRectangularSubmodelComponent tmp = new GUIhalfadder(model); - tmp.moveTo(1000, 50); - SubComponentParams p = tmp.calculateParams(); - try - { - p.writeJson("HalfAdder.rc"); - p = SubComponentParams.readJson("HalfAdder.rc"); - } - catch (IOException e) - { - e.printStackTrace(); - } - tmp = new GUIfulladder(model); - SubComponentParams pC = tmp.calculateParams(); + SimpleRectangularSubmodelComponent tmp = new GUIfulladder(model); + SubmodelComponentParams pC = tmp.calculateParams(); tmp.moveTo(1000, 100); try { - pC.writeJson("FullAdder.sc"); - pC = SubComponentParams.readJson("FullAdder.sc"); + pC.writeJson("FullAdder.json"); + pC = SubmodelComponentParams.readJson("FullAdder.json"); } catch (IOException e) { e.printStackTrace(); } - SimpleRectangularSubmodelComponent adder = new GUIfulladder(model); + SimpleRectangularSubmodelComponent adder = (SimpleRectangularSubmodelComponent) GUICustomComponentCreator.create(model, + "FullAdder.json"); GUIManualSwitch swA = new GUIManualSwitch(model); swA.moveTo(0, 0); @@ -108,12 +92,12 @@ public class JsonExample GUIBitDisplay bdZ = new GUIBitDisplay(model); bdZ.moveTo(90, 30); - new GUIWire(model, swA.getOutputPin(), adder.getInputPins().get(0)); - new GUIWire(model, swB.getOutputPin(), adder.getInputPins().get(1)); - new GUIWire(model, swC.getOutputPin(), adder.getInputPins().get(2)); + new GUIWire(model, swA.getOutputPin(), adder.getPin("A")); + new GUIWire(model, swB.getOutputPin(), adder.getPin("B")); + new GUIWire(model, swC.getOutputPin(), adder.getPin("C")); - new GUIWire(model, adder.getOutputPins().get(0), bdY.getInputPin()); - new GUIWire(model, adder.getOutputPins().get(1), bdZ.getInputPin()); + new GUIWire(model, adder.getPin("Y"), bdY.getInputPin()); + new GUIWire(model, adder.getPin("Z"), bdZ.getInputPin()); SubmodelComponent adder2 = GUICustomComponentCreator.create(model, pC, ""); @@ -130,11 +114,11 @@ public class JsonExample bdZ = new GUIBitDisplay(model); bdZ.moveTo(90, 85); - new GUIWire(model, swA.getOutputPin(), adder2.getPins().get(0)); - new GUIWire(model, swB.getOutputPin(), adder2.getPins().get(1)); - new GUIWire(model, swC.getOutputPin(), adder2.getPins().get(2)); + new GUIWire(model, swA.getOutputPin(), adder.getPin("A")); + new GUIWire(model, swB.getOutputPin(), adder.getPin("B")); + new GUIWire(model, swC.getOutputPin(), adder.getPin("C")); - new GUIWire(model, adder2.getPins().get(3), bdY.getInputPin()); - new GUIWire(model, adder2.getPins().get(4), bdZ.getInputPin()); + new GUIWire(model, adder.getPin("Y"), bdY.getInputPin()); + new GUIWire(model, adder.getPin("Z"), bdZ.getInputPin()); } } \ No newline at end of file