X-Git-Url: https://mograsim.net/gitweb/?a=blobdiff_plain;f=net.mograsim.logic.ui.am2900%2Fsrc%2Fnet%2Fmograsim%2Flogic%2Fui%2Fexamples%2FSubmodelComponentTestbench.java;h=9215db1aa6f0a356aa7801fd55f4449ac8801f3a;hb=0885062ad73925732b1a4e4c79f910dec9862fd3;hp=a3dda8af12555c31e367c6b2b1bbb6c583f6fcd7;hpb=01c5d7035474a5eb58f216b6831b2c0d8c174efa;p=Mograsim.git 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 a3dda8af..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 @@ -1,12 +1,16 @@ package net.mograsim.logic.ui.examples; +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.atomic.GUIBitDisplay; 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.SimpleRectangularSubmodelComponent; +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.serializing.SubmodelComponentDeserializer; public class SubmodelComponentTestbench { @@ -18,20 +22,30 @@ public class SubmodelComponentTestbench @SuppressWarnings("unused") // for GUIWires being created public static void createTestbench(ViewModelModifiable model) { - SimpleRectangularSubmodelComponent comp = new GUIAm2901(model); + 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()) + if (p.getRelX() == 0) + inputPinNames.add(p.name); + else + outputPinNames.add(p.name); comp.moveTo(100, 0); - for (int i = 0; i < comp.getInputPinNames().size(); i++) + for (int i = 0; i < inputPinNames.size(); i++) { GUIManualSwitch sw = new GUIManualSwitch(model); sw.moveTo(0, 20 * i); - new GUIWire(model, comp.getPin(comp.getInputPinNames().get(i)), sw.getOutputPin()); + new GUIWire(model, comp.getPin(inputPinNames.get(i)), sw.getOutputPin()); } - for (int i = 0; i < comp.getOutputPinNames().size(); i++) + for (int i = 0; i < outputPinNames.size(); i++) { GUIBitDisplay bd = new GUIBitDisplay(model); bd.moveTo(200, 20 * i); - new GUIWire(model, comp.getPin(comp.getOutputPinNames().get(i)), bd.getInputPin()); + new GUIWire(model, comp.getPin(outputPinNames.get(i)), bd.getInputPin()); } } } \ No newline at end of file