1 package net.mograsim.logic.model.examples;
3 import java.io.IOException;
4 import java.io.UncheckedIOException;
5 import java.util.ArrayList;
8 import net.mograsim.logic.model.SimpleLogicUIStandalone;
9 import net.mograsim.logic.model.model.ViewModelModifiable;
10 import net.mograsim.logic.model.model.components.atomic.GUIBitDisplay;
11 import net.mograsim.logic.model.model.components.atomic.GUIManualSwitch;
12 import net.mograsim.logic.model.model.components.submodels.SubmodelComponent;
13 import net.mograsim.logic.model.model.wires.GUIWire;
14 import net.mograsim.logic.model.model.wires.Pin;
15 import net.mograsim.logic.model.serializing.SubmodelComponentSerializer;
17 public class SubmodelComponentTestbench
19 public static void main(String[] args)
21 SimpleLogicUIStandalone.executeVisualisation(SubmodelComponentTestbench::createTestbench);
24 @SuppressWarnings("unused") // for GUIWires being created
25 public static void createTestbench(ViewModelModifiable model)
27 SubmodelComponent comp;
30 comp = SubmodelComponentSerializer.deserialize(model, "components/am2901/GUIAm2901.json");
34 throw new UncheckedIOException(e);
37 // guess which pins are outputs and which are inputs
38 // TODO this code exists three times... but it seems too "hacky" to put it in a helper class
39 List<String> inputPinNames = new ArrayList<>();
40 List<String> outputPinNames = new ArrayList<>();
41 for (Pin p : comp.getPins().values())
43 inputPinNames.add(p.name);
45 outputPinNames.add(p.name);
48 for (int i = 0; i < inputPinNames.size(); i++)
50 GUIManualSwitch sw = new GUIManualSwitch(model);
52 new GUIWire(model, comp.getPin(inputPinNames.get(i)), sw.getOutputPin());
54 for (int i = 0; i < outputPinNames.size(); i++)
56 GUIBitDisplay bd = new GUIBitDisplay(model);
57 bd.moveTo(200, 20 * i);
58 new GUIWire(model, comp.getPin(outputPinNames.get(i)), bd.getInputPin());