1 package net.mograsim.logic.model.model.components.mi.nandbased;
3 import java.util.Arrays;
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;
16 public class GUI_rsLatch extends SimpleRectangularSubmodelComponent
18 private StandardHighLevelStateHandler highLevelStateHandler;
20 public GUI_rsLatch(ViewModelModifiable model)
25 public GUI_rsLatch(ViewModelModifiable model, String name)
27 super(model, 1, "_rsLatch", name);
29 setInputPins("_S", "_R");
30 setOutputPins("Q", "_Q");
31 initSubmodelComponents();
34 @SuppressWarnings("unused") // for GUIWires being created
35 private void initSubmodelComponents()
37 Pin _S = getSubmodelPin("_S");
38 Pin _R = getSubmodelPin("_R");
39 Pin Q = getSubmodelPin("Q");
40 Pin _Q = getSubmodelPin("_Q");
42 GUINandGate nand1 = new GUINandGate(submodelModifiable, 1);
43 GUINandGate nand2 = new GUINandGate(submodelModifiable, 1);
45 WireCrossPoint cp1 = new WireCrossPoint(submodelModifiable, 1);
46 WireCrossPoint cp2 = new WireCrossPoint(submodelModifiable, 1);
48 nand1.moveTo(10, 7.5);
49 nand2.moveTo(40, 12.5);
50 cp1.moveCenterTo(35, 17.5);
51 cp2.moveCenterTo(65, 37.5);
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),
61 GUIWire wire_Q = new GUIWire(submodelModifiable, "_q", cp2, _Q, new Point[0]);
63 highLevelStateHandler = new StandardHighLevelStateHandler(this);
64 highLevelStateHandler.addAtomicHighLevelState("q", WireForcingAtomicHighLevelStateHandler::new).set(Arrays.asList(wireQ),
65 Arrays.asList(wire_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(GUI_rsLatch.class.getCanonicalName(), (m, p, n) -> new GUI_rsLatch(m, n));