Improved GUImux1_4 rendering
[Mograsim.git] / net.mograsim.logic.ui / src / net / mograsim / logic / ui / model / components / mi / nandbased / GUImux1_4.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.SimpleRectangularSubmodelComponent;
6 import net.mograsim.logic.ui.model.wires.GUIWire;
7 import net.mograsim.logic.ui.model.wires.Pin;
8 import net.mograsim.logic.ui.model.wires.WireCrossPoint;
9
10 /**
11  * @formatter:off
12  * Inputs:
13  * 0: select
14  * 1: I0_0
15  * 2: I0_1
16  * 3: I0_2
17  * 4: I0_3
18  * 5: I1_0
19  * 6: I1_1
20  * 7: I1_2
21  * 8: I1_3
22  * Outputs:
23  * 0: Y0
24  * 1: Y1
25  * 2: Y2
26  * 3: Y3
27  * @formatter:on
28  */
29 public class GUImux1_4 extends SimpleRectangularSubmodelComponent
30 {
31         public GUImux1_4(ViewModelModifiable model)
32         {
33                 super(model, 1, "GUImux1_4");
34                 setSubmodelScale(.4);
35                 setInputCount(9);
36                 setOutputCount(4);
37                 initSubmodelComponents();
38         }
39
40         @SuppressWarnings("unused")
41         private void initSubmodelComponents()
42         {
43
44                 GUImux1 mux1 = new GUImux1(submodelModifiable);
45                 GUImux1 mux2 = new GUImux1(submodelModifiable);
46                 GUImux1 mux3 = new GUImux1(submodelModifiable);
47                 GUImux1 mux4 = new GUImux1(submodelModifiable);
48
49                 GUImux1 mux[] = { mux1, mux2, mux3, mux4 };
50                 WireCrossPoint[] cps = new WireCrossPoint[mux.length - 1];
51
52                 double muxXOffset = 30, muxYOffset = 7.5, muxYMargin = 5;
53                 Pin test = getInputPins().get(0);
54                 Pin test2 = mux[0].getInputPins().get(1);
55                 for (int i = 0; i < mux.length; i++)
56                 {
57                         mux[i].moveTo(muxXOffset, muxYOffset + (mux[0].getBounds().height + muxYMargin) * i);
58                         Pin inPinA = getInputSubmodelPins().get(i + 1);
59                         Pin inPinB = getInputSubmodelPins().get(mux.length + i + 1);
60                         Pin muxPin = mux[i].getInputPins().get(1);
61
62                         new GUIWire(submodelModifiable, inPinA, muxPin, new Point(inPinA.getPos().x + 5, inPinA.getPos().y),
63                                         new Point(inPinA.getPos().x + 5, muxPin.getPos().y));
64                         new GUIWire(submodelModifiable, inPinB, mux[i].getInputPins().get(2), new Point(10 + 5 * i, inPinB.getPos().y),
65                                         new Point(10 + 5 * i, mux[i].getInputPins().get(2).getPos().y));
66                         new GUIWire(submodelModifiable, mux[i].getOutputPins().get(0), getOutputSubmodelPins().get(i));
67
68                         if (i != mux.length - 1)
69                         {
70                                 WireCrossPoint cp = new WireCrossPoint(submodelModifiable, logicWidth);
71                                 cps[i] = cp;
72                                 Pin p = mux[i].getInputPins().get(0);
73                                 cp.moveTo(muxXOffset - 3, p.getPos().y);
74                                 new GUIWire(submodelModifiable, cp, mux[i].getInputPins().get(0));
75                                 if (i > 0)
76                                         new GUIWire(submodelModifiable, cps[i - 1], cp, new Point[0]);
77                                 else
78                                         new GUIWire(submodelModifiable, getInputSubmodelPins().get(0), cp, new Point[0]);
79                         } else
80                         {
81                                 new GUIWire(submodelModifiable, cps[i - 1], mux[i].getInputPins().get(0),
82                                                 new Point(cps[i - 1].getPin().getPos().x, mux[i].getInputPins().get(0).getPos().y));
83                         }
84                 }
85         }
86 }