Implemented GUIdff
[Mograsim.git] / net.mograsim.logic.ui / src / net / mograsim / logic / ui / model / components / mi / nandbased / GUIdff.java
1 package net.mograsim.logic.ui.model.components.mi.nandbased;
2
3 import net.haspamelodica.swt.helper.swtobjectwrappers.Point;
4 import net.mograsim.logic.ui.model.ViewModelModifiable;
5 import net.mograsim.logic.ui.model.components.GUINandGate;
6 import net.mograsim.logic.ui.model.components.SubmodelComponent;
7 import net.mograsim.logic.ui.model.wires.GUIWire;
8 import net.mograsim.logic.ui.model.wires.Pin;
9 import net.mograsim.logic.ui.model.wires.WireCrossPoint;
10
11 public class GUIdff extends SubmodelComponent
12 {
13         private final Pin pinC;
14         private final Pin pinD;
15         private final Pin pinQ;
16         private final Pin pin_Q;
17
18         public GUIdff(ViewModelModifiable model)
19         {
20                 super(model, "GUIdff");
21                 setSize(35, 25);
22                 setSubmodelScale(.2);
23
24                 Pin C = addSubmodelInterface(1, 0, 5);
25                 Pin D = addSubmodelInterface(1, 0, 20);
26                 Pin Q = addSubmodelInterface(1, 35, 5);
27                 Pin _Q = addSubmodelInterface(1, 35, 20);
28
29                 this.pinC = getSupermodelPin(C);
30                 this.pinD = getSupermodelPin(D);
31                 this.pinQ = getSupermodelPin(Q);
32                 this.pin_Q = getSupermodelPin(_Q);
33
34                 initSubmodelComponents(C, D, Q, _Q);
35         }
36
37         @SuppressWarnings("unused") // for GUIWires being created
38         private void initSubmodelComponents(Pin C, Pin D, Pin Q, Pin _Q)
39         {
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);
44
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);
49
50                 _rsLatch1.moveTo(40, 5);
51                 nand3.moveTo(40, 40);
52                 nand2.moveTo(40, 85);
53                 _rsLatch2.moveTo(120, 35);
54                 cp1.moveTo(10, 25);
55                 cp2.moveTo(20, 65);
56                 cp3.moveTo(100, 35);
57                 cp4.moveTo(100, 55);
58
59                 new GUIWire(submodelModifiable, C, cp1.getPin());
60                 new GUIWire(submodelModifiable, cp1.getPin(), _rsLatch1.getPin_R());
61                 new GUIWire(submodelModifiable, cp1.getPin(), nand3.getPinB(), new Point(10, 55));
62                 new GUIWire(submodelModifiable, D, nand2.getInputPins().get(1));
63                 new GUIWire(submodelModifiable, nand2.getOutputPin(), cp2.getPin(), new Point(65, 95), new Point(65, 75), new Point(20, 75));
64                 new GUIWire(submodelModifiable, cp2.getPin(), _rsLatch1.getPin_S(), new Point(20, 10));
65                 new GUIWire(submodelModifiable, cp2.getPin(), nand3.getPinC());
66                 new GUIWire(submodelModifiable, _rsLatch1.getPin_Q(), cp3.getPin(), new Point(100, 25));
67                 new GUIWire(submodelModifiable, cp3.getPin(), nand3.getPinA(), new Point(30, 35), new Point(30, 45));
68                 new GUIWire(submodelModifiable, cp3.getPin(), _rsLatch2.getPin_S(), new Point(100, 40));
69                 new GUIWire(submodelModifiable, nand3.getPinY(), cp4.getPin());
70                 new GUIWire(submodelModifiable, cp4.getPin(), _rsLatch2.getPin_R());
71                 new GUIWire(submodelModifiable, cp4.getPin(), nand2.getInputPins().get(0), new Point(100, 80), new Point(30, 80),
72                                 new Point(30, 90));
73                 new GUIWire(submodelModifiable, _rsLatch2.getPinQ(), Q, new Point(165, 40), new Point(165, 25));
74                 new GUIWire(submodelModifiable, _rsLatch2.getPin_Q(), _Q, new Point(165, 55), new Point(165, 100));
75         }
76
77         public Pin getPinC()
78         {
79                 return pinC;
80         }
81
82         public Pin getPinD()
83         {
84                 return pinD;
85         }
86
87         public Pin getPinQ()
88         {
89                 return pinQ;
90         }
91
92         public Pin getPin_Q()
93         {
94                 return pin_Q;
95         }
96 }