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;
11 import net.mograsim.logic.model.snippets.highlevelstatehandlers.standard.StandardHighLevelStateHandler;
12 import net.mograsim.logic.model.snippets.highlevelstatehandlers.standard.atomic.DelegatingAtomicHighLevelStateHandler;
14 public class GUIdlatch extends SimpleRectangularSubmodelComponent
16 private StandardHighLevelStateHandler highLevelStateHandler;
18 public GUIdlatch(ViewModelModifiable model)
23 public GUIdlatch(ViewModelModifiable model, String name)
25 super(model, 1, "GUIdlatch", name);
27 setInputPins("D", "E");
28 setOutputPins("Q", "_Q");
29 initSubmodelComponents();
32 @SuppressWarnings("unused") // for GUIWires being created
33 private void initSubmodelComponents()
35 Pin D = getSubmodelPin("D");
36 Pin E = getSubmodelPin("E");
37 Pin Q = getSubmodelPin("Q");
38 Pin _Q = getSubmodelPin("_Q");
40 GUINandGate nand1 = new GUINandGate(submodelModifiable, 1);
41 GUINandGate nand2 = new GUINandGate(submodelModifiable, 1);
42 GUI_rsLatch _rsLatch = new GUI_rsLatch(submodelModifiable);
44 WireCrossPoint cp1 = new WireCrossPoint(submodelModifiable, 1);
45 WireCrossPoint cp2 = new WireCrossPoint(submodelModifiable, 1);
47 nand1.moveTo(10, 2.5);
48 nand2.moveTo(15, 27.5);
49 _rsLatch.moveTo(45, 7.5);
50 cp1.moveCenterTo(5, 37.5);
51 cp2.moveCenterTo(35, 12.5);
53 new GUIWire(submodelModifiable, D, nand1.getPin("A"));
54 new GUIWire(submodelModifiable, E, cp1, new Point[0]);
55 new GUIWire(submodelModifiable, cp1, nand1.getPin("B"), new Point(5, 17.5));
56 new GUIWire(submodelModifiable, cp1, nand2.getPin("B"), new Point(5, 42.5));
57 new GUIWire(submodelModifiable, nand1.getPin("Y"), cp2, new Point[0]);
58 new GUIWire(submodelModifiable, cp2, nand2.getPin("A"), new Point(35, 25), new Point(10, 25), new Point(10, 32.5));
59 new GUIWire(submodelModifiable, cp2, _rsLatch.getPin("_S"), new Point[0]);
60 new GUIWire(submodelModifiable, nand2.getPin("Y"), _rsLatch.getPin("_R"), new Point(40, 37.5), new Point(40, 22.5));
61 new GUIWire(submodelModifiable, _rsLatch.getPin("Q"), Q, new Point[0]);
62 new GUIWire(submodelModifiable, _rsLatch.getPin("_Q"), _Q);
64 this.highLevelStateHandler = new StandardHighLevelStateHandler(this);
65 highLevelStateHandler.addAtomicHighLevelState("q", DelegatingAtomicHighLevelStateHandler::new).set(_rsLatch, "q");
69 public Object getHighLevelState(String stateID)
71 return highLevelStateHandler.getHighLevelState(stateID);
75 public void setHighLevelState(String stateID, Object newState)
77 highLevelStateHandler.setHighLevelState(stateID, newState);
82 IndirectGUIComponentCreator.setComponentSupplier(GUIdlatch.class.getCanonicalName(), (m, p, n) -> new GUIdlatch(m, n));