Added fulladder. GUIWires are now drawn with right angles.
[Mograsim.git] / net.mograsim.logic.ui / src / net / mograsim / logic / ui / model / components / mi / nandbased / GUIfulladder.java
1 package net.mograsim.logic.ui.model.components.mi.nandbased;
2
3 import net.mograsim.logic.ui.model.ViewModelModifiable;
4 import net.mograsim.logic.ui.model.components.GUINandGate;
5 import net.mograsim.logic.ui.model.components.SubmodelComponent;
6 import net.mograsim.logic.ui.model.wires.GUIWire;
7 import net.mograsim.logic.ui.model.wires.Pin;
8
9 public class GUIfulladder extends SubmodelComponent
10 {
11         private final Pin pinA;
12         private final Pin pinB;
13         private final Pin pinC;
14         private final Pin pinY;
15         private final Pin pinZ;
16
17         public GUIfulladder(ViewModelModifiable model)
18         {
19                 super(model, "GUIfulladder");
20                 setSize(50, 40);
21                 setSubmodelScale(.4);
22
23                 Pin A = addSubmodelInterface(1, 0, 5);
24                 Pin B = addSubmodelInterface(1, 0, 20);
25                 Pin C = addSubmodelInterface(1, 0, 35);
26                 Pin Y = addSubmodelInterface(1, 50, 5);
27                 Pin Z = addSubmodelInterface(1, 50, 20);
28
29                 this.pinA = getSupermodelPin(A);
30                 this.pinB = getSupermodelPin(B);
31                 this.pinC = getSupermodelPin(C);
32                 this.pinY = getSupermodelPin(Y);
33                 this.pinZ = getSupermodelPin(Z);
34
35                 initSubmodelComponents(A, B, C, Y, Z);
36         }
37
38         @SuppressWarnings("unused") // for GUIWires being created
39         private void initSubmodelComponents(Pin A, Pin B, Pin C, Pin Y, Pin Z)
40         {
41                 GUIhalfadder halfBC = new GUIhalfadder(submodelModifiable);
42                 GUIhalfadder halfAY = new GUIhalfadder(submodelModifiable);
43                 GUINandGate nandZ = new GUINandGate(submodelModifiable, 1);
44
45                 halfAY.moveTo(55, 7.5);
46                 halfBC.moveTo(10, 40);
47                 nandZ.moveTo(100, 25);
48
49                 new GUIWire(submodelModifiable, A, halfAY.getPinA());
50                 new GUIWire(submodelModifiable, B, halfBC.getPinA());// , new Point(5, 50), new Point(5, 45));
51                 new GUIWire(submodelModifiable, C, halfBC.getPinB());// , new Point(5, 87.5), new Point(5, 60));
52                 new GUIWire(submodelModifiable, halfBC.getPinY(), halfAY.getPinB());// , new Point(50, 45), new Point(50, 27.5));
53                 new GUIWire(submodelModifiable, halfBC.getPin_Z(), nandZ.getInputPins().get(1));
54                 new GUIWire(submodelModifiable, halfAY.getPinY(), Y);
55                 new GUIWire(submodelModifiable, halfAY.getPin_Z(), nandZ.getInputPins().get(0));
56                 new GUIWire(submodelModifiable, nandZ.getOutputPin(), Z);
57         }
58
59         public Pin getPinA()
60         {
61                 return pinA;
62         }
63
64         public Pin getPinB()
65         {
66                 return pinB;
67         }
68
69         public Pin getPinC()
70         {
71                 return pinC;
72         }
73
74         public Pin getPinY()
75         {
76                 return pinY;
77         }
78
79         public Pin getPinZ()
80         {
81                 return pinZ;
82         }
83 }