Added convenience constructors in GUIWire
[Mograsim.git] / net.mograsim.logic.ui / src / net / mograsim / logic / ui / model / components / mi / nandbased / GUIdlatch.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 GUIdlatch extends SubmodelComponent
12 {
13         private final Pin pinD;
14         private final Pin pinE;
15         private final Pin pinQ;
16         private final Pin pin_Q;
17
18         public GUIdlatch(ViewModelModifiable model)
19         {
20                 super(model, "GUIdlatch");
21                 setSize(35, 25);
22                 setSubmodelScale(.4);
23
24                 Pin D = addSubmodelInterface(1, 0, 5);
25                 Pin E = addSubmodelInterface(1, 0, 20);
26                 Pin Q = addSubmodelInterface(1, 35, 5);
27                 Pin _Q = addSubmodelInterface(1, 35, 20);
28
29                 this.pinD = getSupermodelPin(D);
30                 this.pinE = getSupermodelPin(E);
31                 this.pinQ = getSupermodelPin(Q);
32                 this.pin_Q = getSupermodelPin(_Q);
33
34                 initSubmodelComponents(D, E, Q, _Q);
35         }
36
37         @SuppressWarnings("unused") // for GUIWires being created
38         private void initSubmodelComponents(Pin D, Pin E, Pin Q, Pin _Q)
39         {
40                 GUINandGate nand1 = new GUINandGate(submodelModifiable, 1);
41                 GUINandGate nand2 = new GUINandGate(submodelModifiable, 1);
42                 GUI_rsLatch _rsLatch = new GUI_rsLatch(submodelModifiable);
43
44                 WireCrossPoint cp1 = new WireCrossPoint(submodelModifiable, 1);
45                 WireCrossPoint cp2 = new WireCrossPoint(submodelModifiable, 1);
46
47                 nand1.moveTo(10, 7.5);
48                 nand2.moveTo(15, 35);
49                 _rsLatch.moveTo(45, 7.5);
50                 cp1.moveTo(5, 50);
51                 cp2.moveTo(35, 17.5);
52
53                 new GUIWire(submodelModifiable, D, nand1.getInputPins().get(0));
54                 new GUIWire(submodelModifiable, E, cp1);
55                 new GUIWire(submodelModifiable, cp1, nand1.getInputPins().get(1), new Point(5, 22.5));
56                 new GUIWire(submodelModifiable, cp1, nand2.getInputPins().get(1));
57                 new GUIWire(submodelModifiable, nand1.getOutputPin(), cp2);
58                 new GUIWire(submodelModifiable, cp2, nand2.getInputPins().get(0), new Point(35, 30), new Point(10, 30), new Point(10, 40));
59                 new GUIWire(submodelModifiable, cp2, _rsLatch.getPin_S(), new Point(35, 12.5));
60                 new GUIWire(submodelModifiable, nand2.getOutputPin(), _rsLatch.getPin_R(), new Point(40, 45), new Point(40, 27.5));
61                 new GUIWire(submodelModifiable, _rsLatch.getPinQ(), Q);
62                 new GUIWire(submodelModifiable, _rsLatch.getPin_Q(), _Q, new Point(82.5, 27.5), new Point(82.5, 50));
63         }
64
65         public Pin getPinD()
66         {
67                 return pinD;
68         }
69
70         public Pin getPinE()
71         {
72                 return pinE;
73         }
74
75         public Pin getPinQ()
76         {
77                 return pinQ;
78         }
79
80         public Pin getPin_Q()
81         {
82                 return pin_Q;
83         }
84 }