X-Git-Url: https://mograsim.net/gitweb/?a=blobdiff_plain;f=net.mograsim.logic.model.am2900%2Fsrc%2Fnet%2Fmograsim%2Flogic%2Fmodel%2Fexamples%2FGUIComponentTestbench.java;h=66e321274103ff2c4e9d7d7aea4b5892e15191cf;hb=0dff0f06c05ad9b778c29d05b300b399937097e9;hp=362524bfbd6a09d1c9be5c3005a9e6b14a792b9f;hpb=878fc9be0e47ad35a3237685eb83e3609a3820e3;p=Mograsim.git diff --git a/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/examples/GUIComponentTestbench.java b/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/examples/GUIComponentTestbench.java index 362524bf..66e32127 100644 --- a/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/examples/GUIComponentTestbench.java +++ b/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/examples/GUIComponentTestbench.java @@ -9,6 +9,8 @@ import net.mograsim.logic.model.model.ViewModelModifiable; import net.mograsim.logic.model.model.components.GUIComponent; import net.mograsim.logic.model.model.components.atomic.GUIBitDisplay; import net.mograsim.logic.model.model.components.atomic.GUIManualSwitch; +import net.mograsim.logic.model.model.components.atomic.SimpleRectangularHardcodedGUIComponent; +import net.mograsim.logic.model.model.components.atomic.SimpleRectangularHardcodedGUIComponent.Usage; import net.mograsim.logic.model.model.wires.GUIWire; import net.mograsim.logic.model.model.wires.Pin; import net.mograsim.logic.model.serializing.IndirectGUIComponentCreator; @@ -23,17 +25,26 @@ public class GUIComponentTestbench @SuppressWarnings("unused") // for GUIWires being created public static void createTestbench(ViewModelModifiable model) { - GUIComponent comp = IndirectGUIComponentCreator.createComponent(model, "GUIAm2901", "Am2901"); + GUIComponent comp = IndirectGUIComponentCreator.createComponent(model, "file:components/am2904/GUIAm2904MSR.json"); // guess which pins are outputs and which are inputs // TODO this code exists four 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); + if (comp instanceof SimpleRectangularHardcodedGUIComponent) + { + SimpleRectangularHardcodedGUIComponent compCasted = (SimpleRectangularHardcodedGUIComponent) comp; + for (Pin p : comp.getPins().values()) + if (compCasted.getPinUsage(p) == Usage.INPUT) + inputPinNames.add(p.name); + else + outputPinNames.add(p.name); + } else + for (Pin p : comp.getPins().values()) + if (p.getRelX() < comp.getWidth()) + inputPinNames.add(p.name); + else + outputPinNames.add(p.name); inputPinNames.sort(Comparator.comparing(comp::getPin, Comparator.comparing(Pin::getRelY))); outputPinNames.sort(Comparator.comparing(comp::getPin, Comparator.comparing(Pin::getRelY))); @@ -41,15 +52,17 @@ public class GUIComponentTestbench comp.moveTo(100, 0); for (int i = 0; i < inputPinNames.size(); i++) { - GUIManualSwitch sw = new GUIManualSwitch(model); + String pinName = inputPinNames.get(i); + GUIManualSwitch sw = new GUIManualSwitch(model, comp.getPin(pinName).logicWidth); sw.moveTo(0, 20 * i); - new GUIWire(model, comp.getPin(inputPinNames.get(i)), sw.getOutputPin()); + new GUIWire(model, comp.getPin(pinName), sw.getOutputPin()); } for (int i = 0; i < outputPinNames.size(); i++) { - GUIBitDisplay bd = new GUIBitDisplay(model); + String pinName = outputPinNames.get(i); + GUIBitDisplay bd = new GUIBitDisplay(model, comp.getPin(pinName).logicWidth); bd.moveTo(200, 20 * i); - new GUIWire(model, comp.getPin(outputPinNames.get(i)), bd.getInputPin()); + new GUIWire(model, comp.getPin(pinName), bd.getInputPin()); } } } \ No newline at end of file