004aa50b75a9a224ee70c8579e89cf47139ff3a9
[Mograsim.git] / net.mograsim.logic.model.am2900 / src / net / mograsim / logic / model / model / components / mi / nandbased / GUI_rsLatch.java
1 package net.mograsim.logic.model.model.components.mi.nandbased;
2
3 import java.util.Arrays;
4
5 import net.haspamelodica.swt.helper.swtobjectwrappers.Point;
6 import net.mograsim.logic.model.model.ViewModelModifiable;
7 import net.mograsim.logic.model.model.components.atomic.GUINandGate;
8 import net.mograsim.logic.model.model.components.submodels.SimpleRectangularSubmodelComponent;
9 import net.mograsim.logic.model.model.wires.GUIWire;
10 import net.mograsim.logic.model.model.wires.Pin;
11 import net.mograsim.logic.model.model.wires.WireCrossPoint;
12 import net.mograsim.logic.model.serializing.IndirectGUIComponentCreator;
13 import net.mograsim.logic.model.snippets.highlevelstatehandlers.standard.StandardHighLevelStateHandler;
14 import net.mograsim.logic.model.snippets.highlevelstatehandlers.standard.atomic.WireForcingAtomicHighLevelStateHandler;
15
16 public class GUI_rsLatch extends SimpleRectangularSubmodelComponent
17 {
18         private StandardHighLevelStateHandler highLevelStateHandler;
19
20         public GUI_rsLatch(ViewModelModifiable model)
21         {
22                 this(model, null);
23         }
24
25         public GUI_rsLatch(ViewModelModifiable model, String name)
26         {
27                 super(model, 1, "_rsLatch", name);
28                 setSubmodelScale(.4);
29                 setInputPins("_S", "_R");
30                 setOutputPins("Q", "_Q");
31                 initSubmodelComponents();
32         }
33
34         @SuppressWarnings("unused") // for GUIWires being created
35         private void initSubmodelComponents()
36         {
37                 Pin _S = getSubmodelPin("_S");
38                 Pin _R = getSubmodelPin("_R");
39                 Pin Q = getSubmodelPin("Q");
40                 Pin _Q = getSubmodelPin("_Q");
41
42                 GUINandGate nand1 = new GUINandGate(submodelModifiable, 1);
43                 GUINandGate nand2 = new GUINandGate(submodelModifiable, 1);
44
45                 WireCrossPoint cp1 = new WireCrossPoint(submodelModifiable, 1);
46                 WireCrossPoint cp2 = new WireCrossPoint(submodelModifiable, 1);
47
48                 nand1.moveTo(10, 7.5);
49                 nand2.moveTo(40, 12.5);
50                 cp1.moveCenterTo(35, 17.5);
51                 cp2.moveCenterTo(65, 37.5);
52
53                 new GUIWire(submodelModifiable, _S, nand1.getPin("A"), new Point[0]);
54                 new GUIWire(submodelModifiable, _R, nand2.getPin("B"), new Point(35, 37.5), new Point(35, 27.5));
55                 new GUIWire(submodelModifiable, nand1.getPin("Y"), cp1, new Point[0]);
56                 new GUIWire(submodelModifiable, nand2.getPin("Y"), cp2, new Point(65, 22.5));
57                 new GUIWire(submodelModifiable, cp1, nand2.getPin("A"), new Point[0]);
58                 new GUIWire(submodelModifiable, cp2, nand1.getPin("B"), new Point(65, 42.5), new Point(5, 42.5), new Point(5, 22.5));
59                 GUIWire wireQ = new GUIWire(submodelModifiable, "q", cp1, Q, new Point(35, 17.5), new Point(35, 7.5), new Point(65, 7.5),
60                                 new Point(65, 12.5));
61                 GUIWire wire_Q = new GUIWire(submodelModifiable, "_q", cp2, _Q, new Point[0]);
62
63                 highLevelStateHandler = new StandardHighLevelStateHandler(this);
64                 highLevelStateHandler.addAtomicHighLevelState("q", WireForcingAtomicHighLevelStateHandler::new).set(Arrays.asList(wireQ),
65                                 Arrays.asList(wire_Q));
66         }
67
68         @Override
69         public Object getHighLevelState(String stateID)
70         {
71                 return highLevelStateHandler.getHighLevelState(stateID);
72         }
73
74         @Override
75         public void setHighLevelState(String stateID, Object newState)
76         {
77                 highLevelStateHandler.setHighLevelState(stateID, newState);
78         }
79
80         static
81         {
82                 IndirectGUIComponentCreator.setComponentSupplier(GUI_rsLatch.class.getCanonicalName(), (m, p, n) -> new GUI_rsLatch(m, n));
83         }
84 }