Restructured Snippet support:
[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         public GUI_rsLatch(ViewModelModifiable model)
19         {
20                 this(model, null);
21         }
22
23         public GUI_rsLatch(ViewModelModifiable model, String name)
24         {
25                 super(model, 1, "_rsLatch", name);
26                 setSubmodelScale(.4);
27                 setInputPins("_S", "_R");
28                 setOutputPins("Q", "_Q");
29                 initSubmodelComponents();
30         }
31
32         @SuppressWarnings("unused") // for GUIWires being created
33         private void initSubmodelComponents()
34         {
35                 Pin _S = getSubmodelPin("_S");
36                 Pin _R = getSubmodelPin("_R");
37                 Pin Q = getSubmodelPin("Q");
38                 Pin _Q = getSubmodelPin("_Q");
39
40                 GUINandGate nand1 = new GUINandGate(submodelModifiable, 1);
41                 GUINandGate nand2 = new GUINandGate(submodelModifiable, 1);
42
43                 WireCrossPoint cp1 = new WireCrossPoint(submodelModifiable, 1);
44                 WireCrossPoint cp2 = new WireCrossPoint(submodelModifiable, 1);
45
46                 nand1.moveTo(10, 7.5);
47                 nand2.moveTo(40, 12.5);
48                 cp1.moveCenterTo(35, 17.5);
49                 cp2.moveCenterTo(65, 37.5);
50
51                 new GUIWire(submodelModifiable, _S, nand1.getPin("A"), new Point[0]);
52                 new GUIWire(submodelModifiable, _R, nand2.getPin("B"), new Point(35, 37.5), new Point(35, 27.5));
53                 new GUIWire(submodelModifiable, nand1.getPin("Y"), cp1, new Point[0]);
54                 new GUIWire(submodelModifiable, nand2.getPin("Y"), cp2, new Point(65, 22.5));
55                 new GUIWire(submodelModifiable, cp1, nand2.getPin("A"), new Point[0]);
56                 new GUIWire(submodelModifiable, cp2, nand1.getPin("B"), new Point(65, 42.5), new Point(5, 42.5), new Point(5, 22.5));
57                 GUIWire wireQ = new GUIWire(submodelModifiable, "q", cp1, Q, new Point(35, 17.5), new Point(35, 7.5), new Point(65, 7.5),
58                                 new Point(65, 12.5));
59                 GUIWire wire_Q = new GUIWire(submodelModifiable, "_q", cp2, _Q, new Point[0]);
60
61                 StandardHighLevelStateHandler highLevelStateHandler = new StandardHighLevelStateHandler(this);
62                 highLevelStateHandler.addAtomicHighLevelState("q", WireForcingAtomicHighLevelStateHandler::new).set(Arrays.asList(wireQ),
63                                 Arrays.asList(wire_Q));
64                 setHighLevelStateHandler(highLevelStateHandler);
65         }
66
67         static
68         {
69                 IndirectGUIComponentCreator.setComponentSupplier(GUI_rsLatch.class.getCanonicalName(), (m, p, n) -> new GUI_rsLatch(m, n));
70         }
71 }