2da80aecab82618f7f251bf549c8e25e1e6d5181
[Mograsim.git] / net.mograsim.logic.model.am2900 / src / net / mograsim / logic / model / examples / SubmodelComponentTestbench.java
1 package net.mograsim.logic.model.examples;
2
3 import java.util.ArrayList;
4 import java.util.List;
5
6 import net.mograsim.logic.model.SimpleLogicUIStandalone;
7 import net.mograsim.logic.model.model.ViewModelModifiable;
8 import net.mograsim.logic.model.model.components.GUIComponent;
9 import net.mograsim.logic.model.model.components.atomic.GUIBitDisplay;
10 import net.mograsim.logic.model.model.components.atomic.GUIManualSwitch;
11 import net.mograsim.logic.model.model.wires.GUIWire;
12 import net.mograsim.logic.model.model.wires.Pin;
13 import net.mograsim.logic.model.serializing.IndirectGUIComponentCreator;
14
15 public class SubmodelComponentTestbench
16 {
17         public static void main(String[] args)
18         {
19                 SimpleLogicUIStandalone.executeVisualisation(SubmodelComponentTestbench::createTestbench);
20         }
21
22         @SuppressWarnings("unused") // for GUIWires being created
23         public static void createTestbench(ViewModelModifiable model)
24         {
25                 GUIComponent comp = IndirectGUIComponentCreator.createComponent(model, "GUIAm2901", "Am2901");
26
27                 // guess which pins are outputs and which are inputs
28                 // TODO this code exists three times... but it seems too "hacky" to put it in a helper class
29                 // TODO sort pins correctly - use Y coordinate
30                 List<String> inputPinNames = new ArrayList<>();
31                 List<String> outputPinNames = new ArrayList<>();
32                 for (Pin p : comp.getPins().values())
33                         if (p.getRelX() == 0)
34                                 inputPinNames.add(p.name);
35                         else
36                                 outputPinNames.add(p.name);
37
38                 comp.moveTo(100, 0);
39                 for (int i = 0; i < inputPinNames.size(); i++)
40                 {
41                         GUIManualSwitch sw = new GUIManualSwitch(model);
42                         sw.moveTo(0, 20 * i);
43                         new GUIWire(model, comp.getPin(inputPinNames.get(i)), sw.getOutputPin());
44                 }
45                 for (int i = 0; i < outputPinNames.size(); i++)
46                 {
47                         GUIBitDisplay bd = new GUIBitDisplay(model);
48                         bd.moveTo(200, 20 * i);
49                         new GUIWire(model, comp.getPin(outputPinNames.get(i)), bd.getInputPin());
50                 }
51         }
52 }