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