Added DeserializedSubmodelComponent Editor project
[Mograsim.git] / net.mograsim.logic.ui.am2900 / src / net / mograsim / logic / ui / model / components / mi / nandbased / GUIdlatch.java
1 package net.mograsim.logic.ui.model.components.mi.nandbased;
2
3 import net.haspamelodica.swt.helper.swtobjectwrappers.Point;
4 import net.mograsim.logic.ui.model.ViewModelModifiable;
5 import net.mograsim.logic.ui.model.components.atomic.GUINandGate;
6 import net.mograsim.logic.ui.model.components.submodels.SimpleRectangularSubmodelComponent;
7 import net.mograsim.logic.ui.model.wires.GUIWire;
8 import net.mograsim.logic.ui.model.wires.Pin;
9 import net.mograsim.logic.ui.model.wires.WireCrossPoint;
10 import net.mograsim.logic.ui.serializing.IndirectGUIComponentCreator;
11
12 public class GUIdlatch extends SimpleRectangularSubmodelComponent
13 {
14         private GUI_rsLatch _rsLatch;
15
16         public GUIdlatch(ViewModelModifiable model)
17         {
18                 super(model, 1, "GUIdlatch");
19                 setSubmodelScale(.4);
20                 setInputPins("D", "E");
21                 setOutputPins("Q", "_Q");
22                 initSubmodelComponents();
23         }
24
25         @SuppressWarnings("unused") // for GUIWires being created
26         private void initSubmodelComponents()
27         {
28                 Pin D = getSubmodelPin("D");
29                 Pin E = getSubmodelPin("E");
30                 Pin Q = getSubmodelPin("Q");
31                 Pin _Q = getSubmodelPin("_Q");
32
33                 GUINandGate nand1 = new GUINandGate(submodelModifiable, 1);
34                 GUINandGate nand2 = new GUINandGate(submodelModifiable, 1);
35                 _rsLatch = new GUI_rsLatch(submodelModifiable);
36
37                 WireCrossPoint cp1 = new WireCrossPoint(submodelModifiable, 1);
38                 WireCrossPoint cp2 = new WireCrossPoint(submodelModifiable, 1);
39
40                 nand1.moveTo(10, 2.5);
41                 nand2.moveTo(15, 27.5);
42                 _rsLatch.moveTo(45, 7.5);
43                 cp1.moveCenterTo(5, 37.5);
44                 cp2.moveCenterTo(35, 12.5);
45
46                 new GUIWire(submodelModifiable, D, nand1.getPin("A"));
47                 new GUIWire(submodelModifiable, E, cp1, new Point[0]);
48                 new GUIWire(submodelModifiable, cp1, nand1.getPin("B"), new Point(5, 17.5));
49                 new GUIWire(submodelModifiable, cp1, nand2.getPin("B"), new Point(5, 42.5));
50                 new GUIWire(submodelModifiable, nand1.getPin("Y"), cp2, new Point[0]);
51                 new GUIWire(submodelModifiable, cp2, nand2.getPin("A"), new Point(35, 25), new Point(10, 25), new Point(10, 32.5));
52                 new GUIWire(submodelModifiable, cp2, _rsLatch.getPin("_S"), new Point[0]);
53                 new GUIWire(submodelModifiable, nand2.getPin("Y"), _rsLatch.getPin("_R"), new Point(40, 37.5), new Point(40, 22.5));
54                 new GUIWire(submodelModifiable, _rsLatch.getPin("Q"), Q, new Point[0]);
55                 new GUIWire(submodelModifiable, _rsLatch.getPin("_Q"), _Q);
56
57                 addAtomicHighLevelStateID("q");
58         }
59
60         @Override
61         public void setAtomicHighLevelState(String stateID, Object newState)
62         {
63                 switch (stateID)
64                 {
65                 case "q":
66                         _rsLatch.setHighLevelState("q", newState);
67                         break;
68                 default:
69                         // should not happen because we tell SubmodelComponent to only allow these state IDs.
70                         throw new IllegalStateException("Illegal atomic state ID: " + stateID);
71                 }
72         }
73
74         @Override
75         public Object getAtomicHighLevelState(String stateID)
76         {
77                 switch (stateID)
78                 {
79                 case "q":
80                         return _rsLatch.getHighLevelState("q");
81                 default:
82                         // should not happen because we tell SubmodelComponent to only allow these state IDs.
83                         throw new IllegalStateException("Illegal atomic state ID: " + stateID);
84                 }
85         }
86
87         static
88         {
89                 IndirectGUIComponentCreator.setComponentProvider(GUIdlatch.class.getCanonicalName(), (m, p) -> new GUIdlatch(m));
90         }
91 }