From: Daniel Kirschten Date: Fri, 5 Jul 2019 14:16:01 +0000 (+0200) Subject: Switched mostly to using deserialized component versions X-Git-Url: https://mograsim.net/gitweb/?a=commitdiff_plain;h=0885062ad73925732b1a4e4c79f910dec9862fd3;p=Mograsim.git Switched mostly to using deserialized component versions Didn't switch where high level states are needed --- diff --git a/net.mograsim.logic.ui.am2900/src/net/mograsim/logic/ui/examples/SubmodelComponentTestbench.java b/net.mograsim.logic.ui.am2900/src/net/mograsim/logic/ui/examples/SubmodelComponentTestbench.java index 5f10c729..9215db1a 100644 --- a/net.mograsim.logic.ui.am2900/src/net/mograsim/logic/ui/examples/SubmodelComponentTestbench.java +++ b/net.mograsim.logic.ui.am2900/src/net/mograsim/logic/ui/examples/SubmodelComponentTestbench.java @@ -25,6 +25,7 @@ public class SubmodelComponentTestbench SubmodelComponent comp = SubmodelComponentDeserializer.create(model, "components/am2901/GUIAm2901.json"); // guess which pins are outputs and which are inputs + // TODO this code exists three times... but it seems too "hacky" to put it in a helper class List inputPinNames = new ArrayList<>(); List outputPinNames = new ArrayList<>(); for (Pin p : comp.getPins().values()) diff --git a/net.mograsim.logic.ui.am2900/test/net/mograsim/logic/ui/am2900/Am2901Testbench.java b/net.mograsim.logic.ui.am2900/test/net/mograsim/logic/ui/am2900/Am2901Testbench.java index 0a06914b..c35402b1 100644 --- a/net.mograsim.logic.ui.am2900/test/net/mograsim/logic/ui/am2900/Am2901Testbench.java +++ b/net.mograsim.logic.ui.am2900/test/net/mograsim/logic/ui/am2900/Am2901Testbench.java @@ -1,5 +1,8 @@ package net.mograsim.logic.ui.am2900; +import java.util.ArrayList; +import java.util.List; + import net.mograsim.logic.ui.SimpleLogicUIStandalone; import net.mograsim.logic.ui.model.ViewModelModifiable; import net.mograsim.logic.ui.model.components.GUIComponent; @@ -8,11 +11,9 @@ import net.mograsim.logic.ui.model.components.atomic.GUIBitDisplay; import net.mograsim.logic.ui.model.components.atomic.GUIManualSwitch; import net.mograsim.logic.ui.model.components.atomic.GUINotGate; import net.mograsim.logic.ui.model.components.atomic.TextComponent; -import net.mograsim.logic.ui.model.components.mi.nandbased.GUIdff; -import net.mograsim.logic.ui.model.components.mi.nandbased.am2901.GUIAm2901; -import net.mograsim.logic.ui.model.components.submodels.SimpleRectangularSubmodelComponent; import net.mograsim.logic.ui.model.wires.Pin; import net.mograsim.logic.ui.model.wires.WireCrossPoint; +import net.mograsim.logic.ui.serializing.IndirectGUIComponentCreator; import net.mograsim.logic.ui.util.ModellingTool; public class Am2901Testbench @@ -24,7 +25,7 @@ public class Am2901Testbench public static void createTestbench(ViewModelModifiable model) { - SimpleRectangularSubmodelComponent comp = new GUIAm2901(model); + GUIComponent comp = IndirectGUIComponentCreator.createComponent(model, "GUIAm2901"); ModellingTool tool = ModellingTool.createFor(model); comp.moveTo(240, 0); @@ -49,22 +50,32 @@ public class Am2901Testbench and.moveTo(135, -30); Pin last = and.getPin("Y"); - for (int i = 0; i < comp.getInputPinNames().size(); i++) + // guess which pins are outputs and which are inputs + // TODO this code exists three times... but it seems too "hacky" to put it in a helper class + List inputPinNames = new ArrayList<>(); + List outputPinNames = new ArrayList<>(); + for (Pin p : comp.getPins().values()) + if (p.getRelX() == 0) + inputPinNames.add(p.name); + else + outputPinNames.add(p.name); + + for (int i = 0; i < inputPinNames.size(); i++) { double x = 55 + 70 * (i % 2); double y = 10 * i; WireCrossPoint wcp = new WireCrossPoint(model, 1); - GUIComponent d_ff = new GUIdff(model); + GUIComponent d_ff = IndirectGUIComponentCreator.createComponent(model, "GUIdff"); GUIManualSwitch sw = new GUIManualSwitch(model); tool.connect(last, wcp); tool.connect(wcp, d_ff, "C"); tool.connect(sw, d_ff, "", "D"); - tool.connect(d_ff, comp, "Q", comp.getInputPinNames().get(i)); + tool.connect(d_ff, comp, "Q", inputPinNames.get(i)); last = wcp.getPin(); - TextComponent label = new TextComponent(model, comp.getInputPinNames().get(i)); + TextComponent label = new TextComponent(model, inputPinNames.get(i)); sw.moveTo(x, y + 7.5); wcp.moveTo(160, y); @@ -72,15 +83,15 @@ public class Am2901Testbench label.moveTo(x - 25, y + 15); } - for (int i = 0; i < comp.getOutputPinNames().size(); i++) + for (int i = 0; i < outputPinNames.size(); i++) { double x = 300 + 75 * (i % 2); double y = 10 * i - 2.5; GUIBitDisplay bd = new GUIBitDisplay(model); bd.moveTo(x, y); - tool.connect(bd.getInputPin(), comp, comp.getOutputPinNames().get(i)); + tool.connect(bd.getInputPin(), comp, outputPinNames.get(i)); - TextComponent label = new TextComponent(model, comp.getOutputPinNames().get(i)); + TextComponent label = new TextComponent(model, outputPinNames.get(i)); label.moveTo(x + 50, y + 8); } } diff --git a/net.mograsim.logic.ui.am2900/test/net/mograsim/logic/ui/am2900/TestableAm2901Impl.java b/net.mograsim.logic.ui.am2900/test/net/mograsim/logic/ui/am2900/TestableAm2901Impl.java index 9ca395af..25f15669 100644 --- a/net.mograsim.logic.ui.am2900/test/net/mograsim/logic/ui/am2900/TestableAm2901Impl.java +++ b/net.mograsim.logic.ui.am2900/test/net/mograsim/logic/ui/am2900/TestableAm2901Impl.java @@ -3,9 +3,11 @@ package net.mograsim.logic.ui.am2900; import static org.junit.jupiter.api.Assertions.fail; import java.lang.reflect.Field; +import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; import java.util.LinkedList; +import java.util.List; import java.util.Objects; import java.util.Queue; import java.util.Set; @@ -25,12 +27,13 @@ import net.mograsim.logic.ui.model.components.atomic.GUIManualSwitch; import net.mograsim.logic.ui.model.components.mi.nandbased.am2901.GUIAm2901; import net.mograsim.logic.ui.model.components.submodels.SubmodelComponent; import net.mograsim.logic.ui.model.wires.GUIWire; +import net.mograsim.logic.ui.model.wires.Pin; import net.mograsim.logic.ui.modeladapter.LogicModelParameters; import net.mograsim.logic.ui.modeladapter.ViewLogicModelAdapter; public class TestableAm2901Impl implements TestableAm2901 { - private GUIAm2901 am2901; + private GUIComponent am2901; private Timeline timeline; private ManualSwitch I8, I7, I6, I5, I4, I3, I2, I1, I0; private ManualSwitch C; @@ -100,10 +103,21 @@ public class TestableAm2901Impl implements TestableAm2901 { // Create view model ViewModelModifiable viewModel = new ViewModelModifiable(); + // TODO replace with deserialized version as soon as high level states work for deserialized components am2901 = new GUIAm2901(viewModel); +// am2901 = IndirectGUIComponentCreator.createComponent(viewModel, "GUIAm2901"); + // guess which pins are outputs and which are inputs + // TODO this code exists three times... but it seems too "hacky" to put it in a helper class + List inputPinNames = new ArrayList<>(); + List outputPinNames = new ArrayList<>(); + for (Pin p : am2901.getPins().values()) + if (p.getRelX() == 0) + inputPinNames.add(p.name); + else + outputPinNames.add(p.name); // Get switches HashMap idSwitchMap = new HashMap<>(); - for (String id : am2901.getInputPinNames()) + for (String id : inputPinNames) { GUIManualSwitch sw = new GUIManualSwitch(viewModel); new GUIWire(viewModel, am2901.getPin(id), sw.getOutputPin()); @@ -111,7 +125,7 @@ public class TestableAm2901Impl implements TestableAm2901 } // Get displays HashMap idDisplayMap = new HashMap<>(); - for (String id : am2901.getOutputPinNames()) + for (String id : outputPinNames) { GUIBitDisplay bd = new GUIBitDisplay(viewModel); // bd.addRedrawListener(() -> System.out.println(id + " " + bd.getBitDisplay().getDisplayedValue())); diff --git a/net.mograsim.logic.ui/src/net/mograsim/logic/ui/serializing/IndirectGUIComponentCreator.java b/net.mograsim.logic.ui/src/net/mograsim/logic/ui/serializing/IndirectGUIComponentCreator.java index c40897a9..456d19c1 100644 --- a/net.mograsim.logic.ui/src/net/mograsim/logic/ui/serializing/IndirectGUIComponentCreator.java +++ b/net.mograsim.logic.ui/src/net/mograsim/logic/ui/serializing/IndirectGUIComponentCreator.java @@ -6,6 +6,7 @@ import java.util.HashMap; import java.util.Map; import com.google.gson.JsonElement; +import com.google.gson.JsonNull; import net.mograsim.logic.ui.model.ViewModelModifiable; import net.mograsim.logic.ui.model.components.GUIComponent; @@ -55,6 +56,11 @@ public class IndirectGUIComponentCreator componentProviders.put(className, componentProvider); } + public static GUIComponent createComponent(ViewModelModifiable model, String id) + { + return createComponent(model, id, JsonNull.INSTANCE); + } + public static GUIComponent createComponent(ViewModelModifiable model, String id, JsonElement params) { if (id != null)