Implemented GUIdemux2
[Mograsim.git] / net.mograsim.logic.ui / src / net / mograsim / logic / ui / model / components / mi / nandbased / GUIdemux2.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 GUIdemux2 extends SubmodelComponent
12 {
13         private final Pin pinS0;
14         private final Pin pinS1;
15         private final Pin pinY00;
16         private final Pin pinY01;
17         private final Pin pinY10;
18         private final Pin pinY11;
19
20         public GUIdemux2(ViewModelModifiable model)
21         {
22                 super(model, "GUIdemux2");
23                 setSize(40, 42.5);
24                 setSubmodelScale(.4);
25
26                 Pin S0 = addSubmodelInterface(1, 0, 5);
27                 Pin S1 = addSubmodelInterface(1, 0, 15);
28                 Pin Y00 = addSubmodelInterface(1, 40, 5);
29                 Pin Y01 = addSubmodelInterface(1, 40, 15);
30                 Pin Y10 = addSubmodelInterface(1, 40, 25);
31                 Pin Y11 = addSubmodelInterface(1, 40, 35);
32
33                 this.pinS0 = getSupermodelPin(S0);
34                 this.pinS1 = getSupermodelPin(S1);
35                 this.pinY00 = getSupermodelPin(Y00);
36                 this.pinY01 = getSupermodelPin(Y01);
37                 this.pinY10 = getSupermodelPin(Y10);
38                 this.pinY11 = getSupermodelPin(Y11);
39
40                 initSubmodelComponents(S0, S1, Y00, Y01, Y10, Y11);
41         }
42
43         @SuppressWarnings("unused") // for GUIWires being created
44         private void initSubmodelComponents(Pin S0, Pin S1, Pin Y00, Pin Y01, Pin Y10, Pin Y11)
45         {
46                 GUINandGate notS0 = new GUINandGate(submodelModifiable, 1);
47                 GUINandGate notS1 = new GUINandGate(submodelModifiable, 1);
48                 GUIand andY00 = new GUIand(submodelModifiable);
49                 GUIand andY01 = new GUIand(submodelModifiable);
50                 GUIand andY10 = new GUIand(submodelModifiable);
51                 GUIand andY11 = new GUIand(submodelModifiable);
52
53                 WireCrossPoint cpS01 = new WireCrossPoint(submodelModifiable, 1);
54                 WireCrossPoint cpS02 = new WireCrossPoint(submodelModifiable, 1);
55                 WireCrossPoint cpS03 = new WireCrossPoint(submodelModifiable, 1);
56                 WireCrossPoint cpS11 = new WireCrossPoint(submodelModifiable, 1);
57                 WireCrossPoint cpS12 = new WireCrossPoint(submodelModifiable, 1);
58                 WireCrossPoint cpS13 = new WireCrossPoint(submodelModifiable, 1);
59                 WireCrossPoint cpNotS0 = new WireCrossPoint(submodelModifiable, 1);
60                 WireCrossPoint cpNotS1 = new WireCrossPoint(submodelModifiable, 1);
61
62                 notS0.moveTo(15, 2.5);
63                 notS1.moveTo(15, 27.5);
64                 andY00.moveTo(55, 2.5);
65                 andY01.moveTo(55, 27.5);
66                 andY10.moveTo(55, 52.5);
67                 andY11.moveTo(55, 77.5);
68                 cpS01.moveTo(5, 12.5);
69                 cpS11.moveTo(10, 37.5);
70                 cpS02.moveTo(5, 17.5);
71                 cpS12.moveTo(10, 42.5);
72                 cpS03.moveTo(50, 67.5);
73                 cpS13.moveTo(40, 72.5);
74                 cpNotS0.moveTo(40, 12.5);
75                 cpNotS1.moveTo(45, 37.5);
76
77                 new GUIWire(submodelModifiable, S0, cpS01.getPin());
78                 new GUIWire(submodelModifiable, S1, cpS11.getPin());
79                 new GUIWire(submodelModifiable, cpS01.getPin(), notS0.getInputPins().get(0), new Point(5, 7.5));
80                 new GUIWire(submodelModifiable, cpS11.getPin(), notS1.getInputPins().get(0), new Point(10, 32.5));
81                 new GUIWire(submodelModifiable, cpS01.getPin(), cpS02.getPin());
82                 new GUIWire(submodelModifiable, cpS11.getPin(), cpS12.getPin());
83                 new GUIWire(submodelModifiable, cpS02.getPin(), notS0.getInputPins().get(1));
84                 new GUIWire(submodelModifiable, cpS12.getPin(), notS1.getInputPins().get(1));
85                 new GUIWire(submodelModifiable, cpS02.getPin(), cpS03.getPin(), new Point(5, 67.5));
86                 new GUIWire(submodelModifiable, cpS12.getPin(), cpS13.getPin(), new Point(10, 62.5), new Point(40, 62.5));
87                 new GUIWire(submodelModifiable, notS0.getOutputPin(), cpNotS0.getPin());
88                 new GUIWire(submodelModifiable, notS1.getOutputPin(), cpNotS1.getPin());
89                 new GUIWire(submodelModifiable, cpNotS0.getPin(), andY00.getPinA(), new Point(40, 7.5));
90                 new GUIWire(submodelModifiable, cpNotS1.getPin(), andY00.getPinB(), new Point(45, 22.5));
91                 new GUIWire(submodelModifiable, cpS03.getPin(), andY01.getPinA(), new Point(50, 32.5));
92                 new GUIWire(submodelModifiable, cpNotS1.getPin(), andY01.getPinB(), new Point(45, 47.5));
93                 new GUIWire(submodelModifiable, cpNotS0.getPin(), andY10.getPinA(), new Point(40, 57.5));
94                 new GUIWire(submodelModifiable, cpS13.getPin(), andY10.getPinB());
95                 new GUIWire(submodelModifiable, cpS03.getPin(), andY11.getPinA(), new Point(50, 82.5));
96                 new GUIWire(submodelModifiable, cpS13.getPin(), andY11.getPinB(), new Point(40, 97.5));
97                 new GUIWire(submodelModifiable, andY00.getPinY(), Y00, new Point(95, 15), new Point(95, 12.5));
98                 new GUIWire(submodelModifiable, andY01.getPinY(), Y01, new Point(95, 40), new Point(95, 37.5));
99                 new GUIWire(submodelModifiable, andY10.getPinY(), Y10, new Point(95, 65), new Point(95, 62.5));
100                 new GUIWire(submodelModifiable, andY11.getPinY(), Y11, new Point(95, 90), new Point(95, 87.5));
101         }
102
103         public Pin getPinS0()
104         {
105                 return pinS0;
106         }
107
108         public Pin getPinS1()
109         {
110                 return pinS1;
111         }
112
113         public Pin getPinY00()
114         {
115                 return pinY00;
116         }
117
118         public Pin getPinY01()
119         {
120                 return pinY01;
121         }
122
123         public Pin getPinY10()
124         {
125                 return pinY10;
126         }
127
128         public Pin getPinY11()
129         {
130                 return pinY11;
131         }
132 }