491ea62b2fac1706f5e479f1d626519d2b885ea8
[Mograsim.git] /
1 package net.mograsim.logic.model.examples;
2
3 import java.util.ArrayList;
4 import java.util.Comparator;
5 import java.util.List;
6
7 import net.mograsim.logic.model.SimpleLogicUIStandalone;
8 import net.mograsim.logic.model.am2900.Am2900Loader;
9 import net.mograsim.logic.model.model.LogicModelModifiable;
10 import net.mograsim.logic.model.model.components.ModelComponent;
11 import net.mograsim.logic.model.model.components.atomic.ModelBitDisplay;
12 import net.mograsim.logic.model.model.components.atomic.ModelManualSwitch;
13 import net.mograsim.logic.model.model.wires.ModelWire;
14 import net.mograsim.logic.model.model.wires.Pin;
15 import net.mograsim.logic.model.model.wires.PinUsage;
16 import net.mograsim.logic.model.serializing.IndirectModelComponentCreator;
17
18 public class ModelComponentTestbench
19 {
20         public static void main(String[] args)
21         {
22                 SimpleLogicUIStandalone.executeVisualisation(ModelComponentTestbench::createTestbench);
23         }
24
25         @SuppressWarnings("unused") // for ModelWires being created
26         public static void createTestbench(LogicModelModifiable model)
27         {
28                 Am2900Loader.setup();
29 //              ModelComponent comp = new StrictAm2900MachineDefinition().createNew(model).getAm2900();
30                 ModelComponent comp = IndirectModelComponentCreator.createComponent(model, "nor12");
31
32                 List<String> inputPinNames = new ArrayList<>();
33                 List<String> outputPinNames = new ArrayList<>();
34                 for (Pin p : comp.getPins().values())
35                         if (p.usage == PinUsage.INPUT)
36                                 inputPinNames.add(p.name);
37                         else
38                                 outputPinNames.add(p.name);
39
40                 inputPinNames.sort(Comparator.comparing(comp::getPin, Comparator.comparing(Pin::getRelY)));
41                 outputPinNames.sort(Comparator.comparing(comp::getPin, Comparator.comparing(Pin::getRelY)));
42
43                 comp.moveTo(100, 0);
44                 for (int i = 0; i < inputPinNames.size(); i++)
45                 {
46                         String pinName = inputPinNames.get(i);
47                         ModelManualSwitch sw = new ModelManualSwitch(model, comp.getPin(pinName).logicWidth, pinName);
48                         sw.moveTo(0, 20 * i);
49                         new ModelWire(model, comp.getPin(pinName), sw.getOutputPin());
50                 }
51                 for (int i = 0; i < outputPinNames.size(); i++)
52                 {
53                         String pinName = outputPinNames.get(i);
54                         ModelBitDisplay bd = new ModelBitDisplay(model, comp.getPin(pinName).logicWidth, pinName);
55                         bd.moveTo(200, 20 * i);
56                         new ModelWire(model, comp.getPin(pinName), bd.getInputPin());
57                 }
58         }
59 }