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 GUIdff extends SimpleRectangularSubmodelComponent
16 private StandardHighLevelStateHandler highLevelStateHandler;
18 public GUIdff(ViewModelModifiable model)
23 public GUIdff(ViewModelModifiable model, String name)
25 super(model, 1, "GUIdff", name);
27 setInputPins("C", "D");
28 setOutputPins("Q", "_Q");
29 initSubmodelComponents();
32 @SuppressWarnings("unused") // for GUIWires being created
33 private void initSubmodelComponents()
35 Pin C = getSubmodelPin("C");
36 Pin D = getSubmodelPin("D");
37 Pin Q = getSubmodelPin("Q");
38 Pin _Q = getSubmodelPin("_Q");
40 GUI_rsLatch _rsLatch1 = new GUI_rsLatch(submodelModifiable);
41 GUInand3 nand3 = new GUInand3(submodelModifiable);
42 GUINandGate nand2 = new GUINandGate(submodelModifiable, 1);
43 GUI_rsLatch _rsLatch2 = new GUI_rsLatch(submodelModifiable);
45 WireCrossPoint cp1 = new WireCrossPoint(submodelModifiable, 1);
46 WireCrossPoint cp2 = new WireCrossPoint(submodelModifiable, 1);
47 WireCrossPoint cp3 = new WireCrossPoint(submodelModifiable, 1);
48 WireCrossPoint cp4 = new WireCrossPoint(submodelModifiable, 1);
50 _rsLatch1.moveTo(40, 10);
52 nand2.moveTo(120, 60);
53 _rsLatch2.moveTo(120, 30);
54 cp1.moveCenterTo(10, 25);
55 cp2.moveCenterTo(20, 65);
56 cp3.moveCenterTo(100, 35);
57 cp4.moveCenterTo(100, 45);
59 new GUIWire(submodelModifiable, C, cp1, new Point[0]);
60 new GUIWire(submodelModifiable, cp1, _rsLatch1.getPin("_R"), new Point[0]);
61 new GUIWire(submodelModifiable, cp1, nand3.getPin("B"), new Point(10, 55));
62 new GUIWire(submodelModifiable, D, nand2.getPin("B"), new Point[0]);
63 new GUIWire(submodelModifiable, nand2.getPin("Y"), cp2, new Point(145, 70), new Point(145, 85), new Point(20, 85));
64 new GUIWire(submodelModifiable, cp2, _rsLatch1.getPin("_S"), new Point(20, 15));
65 new GUIWire(submodelModifiable, cp2, nand3.getPin("C"), new Point[0]);
66 new GUIWire(submodelModifiable, _rsLatch1.getPin("_Q"), cp3, new Point(100, 25));
67 new GUIWire(submodelModifiable, cp3, nand3.getPin("A"), new Point(30, 35), new Point(30, 45));
68 new GUIWire(submodelModifiable, cp3, _rsLatch2.getPin("_S"), new Point[0]);
69 new GUIWire(submodelModifiable, nand3.getPin("Y"), cp4, new Point[0]);
70 new GUIWire(submodelModifiable, cp4, _rsLatch2.getPin("_R"), new Point[0]);
71 new GUIWire(submodelModifiable, cp4, nand2.getPin("A"), new Point(100, 65));
72 new GUIWire(submodelModifiable, _rsLatch2.getPin("Q"), Q);
73 new GUIWire(submodelModifiable, _rsLatch2.getPin("_Q"), _Q);
75 highLevelStateHandler = new StandardHighLevelStateHandler(this);
76 highLevelStateHandler.addAtomicHighLevelState("q", DelegatingAtomicHighLevelStateHandler::new).set(_rsLatch2, "q");
80 public Object getHighLevelState(String stateID)
82 return highLevelStateHandler.getHighLevelState(stateID);
86 public void setHighLevelState(String stateID, Object newState)
88 highLevelStateHandler.setHighLevelState(stateID, newState);
93 IndirectGUIComponentCreator.setComponentSupplier(GUIdff.class.getCanonicalName(), (m, p, n) -> new GUIdff(m, n));