Implemented GUIhalfadder
[Mograsim.git] / net.mograsim.logic.ui / src / net / mograsim / logic / ui / model / components / mi / nandbased / GUIhalfadder.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 GUIhalfadder extends SubmodelComponent
12 {
13         private final Pin pinA;
14         private final Pin pinB;
15         private final Pin pinY;
16         private final Pin pin_Z;
17
18         public GUIhalfadder(ViewModelModifiable model)
19         {
20                 super(model, "GUIhalfadder");
21                 setSize(35, 25);
22                 setSubmodelScale(.4);
23
24                 Pin A = addSubmodelInterface(1, 0, 5);
25                 Pin B = addSubmodelInterface(1, 0, 20);
26                 Pin Y = addSubmodelInterface(1, 35, 5);
27                 Pin _Z = addSubmodelInterface(1, 35, 20);
28
29                 this.pinA = getSupermodelPin(A);
30                 this.pinB = getSupermodelPin(B);
31                 this.pinY = getSupermodelPin(Y);
32                 this.pin_Z = getSupermodelPin(_Z);
33
34                 initSubmodelComponents(A, B, Y, _Z);
35         }
36
37         @SuppressWarnings("unused") // for GUIWires being created
38         private void initSubmodelComponents(Pin A, Pin B, Pin Y, Pin _Z)
39         {
40                 GUINandGate nand_Z = new GUINandGate(submodelModifiable, 1);
41                 GUINandGate nandYA = new GUINandGate(submodelModifiable, 1);
42                 GUINandGate nandYB = new GUINandGate(submodelModifiable, 1);
43                 GUINandGate nandY = new GUINandGate(submodelModifiable, 1);
44
45                 WireCrossPoint cpA = new WireCrossPoint(submodelModifiable, 1);
46                 WireCrossPoint cpB = new WireCrossPoint(submodelModifiable, 1);
47                 WireCrossPoint cp_Z = new WireCrossPoint(submodelModifiable, 1);
48
49                 nand_Z.moveTo(10, 21.25);
50                 nandYA.moveTo(40, 2.5);
51                 nandYB.moveTo(40, 40);
52                 nandY.moveTo(65, 2.5);
53                 cpA.moveTo(5, 12.5);
54                 cpB.moveTo(5, 50);
55                 cp_Z.moveTo(35, 31.25);
56
57                 new GUIWire(submodelModifiable, A, cpA);
58                 new GUIWire(submodelModifiable, cpA, nandYA.getInputPins().get(0), new Point(5, 7.5));
59                 new GUIWire(submodelModifiable, cpA, nand_Z.getInputPins().get(0), new Point(5, 26.25));
60                 new GUIWire(submodelModifiable, B, cpB);
61                 new GUIWire(submodelModifiable, cpB, nandYB.getInputPins().get(1), new Point(5, 55));
62                 new GUIWire(submodelModifiable, cpB, nand_Z.getInputPins().get(1), new Point(5, 36.25));
63                 new GUIWire(submodelModifiable, nand_Z.getOutputPin(), cp_Z);
64                 new GUIWire(submodelModifiable, cp_Z, _Z, new Point(80, 31.25), new Point(80, 50));
65                 new GUIWire(submodelModifiable, cp_Z, nandYA.getInputPins().get(1), new Point(35, 17.5));
66                 new GUIWire(submodelModifiable, cp_Z, nandYB.getInputPins().get(0), new Point(35, 45));
67                 new GUIWire(submodelModifiable, nandYA.getOutputPin(), nandY.getInputPins().get(0), new Point(62.5, 12.5), new Point(62.5, 7.5));
68                 new GUIWire(submodelModifiable, nandYB.getOutputPin(), nandY.getInputPins().get(1), new Point(62.5, 50), new Point(62.5, 17.5));
69                 new GUIWire(submodelModifiable, nandY.getOutputPin(), Y);
70         }
71
72         public Pin getPinA()
73         {
74                 return pinA;
75         }
76
77         public Pin getPinB()
78         {
79                 return pinB;
80         }
81
82         public Pin getPinY()
83         {
84                 return pinY;
85         }
86
87         public Pin getPin_Z()
88         {
89                 return pin_Z;
90         }
91 }