X-Git-Url: https://mograsim.net/gitweb/?a=blobdiff_plain;ds=sidebyside;f=net.mograsim.logic.model.am2900%2Fsrc%2Fnet%2Fmograsim%2Flogic%2Fmodel%2Fexamples%2FSubmodelComponentTestbench.java;fp=net.mograsim.logic.model.am2900%2Fsrc%2Fnet%2Fmograsim%2Flogic%2Fmodel%2Fexamples%2FSubmodelComponentTestbench.java;h=0d9c604d7c948fee21f9293cd4b3a02e672016bd;hb=b5d8c2d71e27350ea7c9314e40df5bb0584271cd;hp=0000000000000000000000000000000000000000;hpb=69cb6725ef670328959d55649257ded6ac924b33;p=Mograsim.git diff --git a/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/examples/SubmodelComponentTestbench.java b/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/examples/SubmodelComponentTestbench.java new file mode 100644 index 00000000..0d9c604d --- /dev/null +++ b/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/examples/SubmodelComponentTestbench.java @@ -0,0 +1,51 @@ +package net.mograsim.logic.model.examples; + +import java.util.ArrayList; +import java.util.List; + +import net.mograsim.logic.model.SimpleLogicUIStandalone; +import net.mograsim.logic.model.model.ViewModelModifiable; +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.submodels.SubmodelComponent; +import net.mograsim.logic.model.model.wires.GUIWire; +import net.mograsim.logic.model.model.wires.Pin; +import net.mograsim.logic.model.serializing.SubmodelComponentDeserializer; + +public class SubmodelComponentTestbench +{ + public static void main(String[] args) + { + SimpleLogicUIStandalone.executeVisualisation(SubmodelComponentTestbench::createTestbench); + } + + @SuppressWarnings("unused") // for GUIWires being created + public static void createTestbench(ViewModelModifiable 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 < inputPinNames.size(); i++) + { + GUIManualSwitch sw = new GUIManualSwitch(model); + sw.moveTo(0, 20 * i); + new GUIWire(model, comp.getPin(inputPinNames.get(i)), sw.getOutputPin()); + } + for (int i = 0; i < outputPinNames.size(); i++) + { + GUIBitDisplay bd = new GUIBitDisplay(model); + bd.moveTo(200, 20 * i); + new GUIWire(model, comp.getPin(outputPinNames.get(i)), bd.getInputPin()); + } + } +} \ No newline at end of file