1 package net.mograsim.logic.model.model.components.mi.nandbased;
3 import net.haspamelodica.swt.helper.swtobjectwrappers.Point;
4 import net.mograsim.logic.model.model.ViewModelModifiable;
5 import net.mograsim.logic.model.model.components.atomic.GUINandGate;
6 import net.mograsim.logic.model.model.components.submodels.SimpleRectangularSubmodelComponent;
7 import net.mograsim.logic.model.model.wires.GUIWire;
8 import net.mograsim.logic.model.model.wires.Pin;
9 import net.mograsim.logic.model.model.wires.WireCrossPoint;
10 import net.mograsim.logic.model.serializing.IndirectGUIComponentCreator;
12 public class GUIdlatch extends SimpleRectangularSubmodelComponent
14 private GUI_rsLatch _rsLatch;
16 public GUIdlatch(ViewModelModifiable model)
21 public GUIdlatch(ViewModelModifiable model, String name)
23 super(model, 1, "GUIdlatch", name);
25 setInputPins("D", "E");
26 setOutputPins("Q", "_Q");
27 initSubmodelComponents();
30 @SuppressWarnings("unused") // for GUIWires being created
31 private void initSubmodelComponents()
33 Pin D = getSubmodelPin("D");
34 Pin E = getSubmodelPin("E");
35 Pin Q = getSubmodelPin("Q");
36 Pin _Q = getSubmodelPin("_Q");
38 GUINandGate nand1 = new GUINandGate(submodelModifiable, 1);
39 GUINandGate nand2 = new GUINandGate(submodelModifiable, 1);
40 _rsLatch = new GUI_rsLatch(submodelModifiable);
42 WireCrossPoint cp1 = new WireCrossPoint(submodelModifiable, 1);
43 WireCrossPoint cp2 = new WireCrossPoint(submodelModifiable, 1);
45 nand1.moveTo(10, 2.5);
46 nand2.moveTo(15, 27.5);
47 _rsLatch.moveTo(45, 7.5);
48 cp1.moveCenterTo(5, 37.5);
49 cp2.moveCenterTo(35, 12.5);
51 new GUIWire(submodelModifiable, D, nand1.getPin("A"));
52 new GUIWire(submodelModifiable, E, cp1, new Point[0]);
53 new GUIWire(submodelModifiable, cp1, nand1.getPin("B"), new Point(5, 17.5));
54 new GUIWire(submodelModifiable, cp1, nand2.getPin("B"), new Point(5, 42.5));
55 new GUIWire(submodelModifiable, nand1.getPin("Y"), cp2, new Point[0]);
56 new GUIWire(submodelModifiable, cp2, nand2.getPin("A"), new Point(35, 25), new Point(10, 25), new Point(10, 32.5));
57 new GUIWire(submodelModifiable, cp2, _rsLatch.getPin("_S"), new Point[0]);
58 new GUIWire(submodelModifiable, nand2.getPin("Y"), _rsLatch.getPin("_R"), new Point(40, 37.5), new Point(40, 22.5));
59 new GUIWire(submodelModifiable, _rsLatch.getPin("Q"), Q, new Point[0]);
60 new GUIWire(submodelModifiable, _rsLatch.getPin("_Q"), _Q);
62 addAtomicHighLevelStateID("q");
66 public void setAtomicHighLevelState(String stateID, Object newState)
71 _rsLatch.setHighLevelState("q", newState);
74 // should not happen because we tell SubmodelComponent to only allow these state IDs.
75 throw new IllegalStateException("Illegal atomic state ID: " + stateID);
80 public Object getAtomicHighLevelState(String stateID)
85 return _rsLatch.getHighLevelState("q");
87 // should not happen because we tell SubmodelComponent to only allow these state IDs.
88 throw new IllegalStateException("Illegal atomic state ID: " + stateID);
94 IndirectGUIComponentCreator.setComponentSupplier(GUIdlatch.class.getCanonicalName(), (m, p, n) -> new GUIdlatch(m, n));