SimpleRectangularSubmodelComponent now supports pin names
[Mograsim.git] / net.mograsim.logic.ui / src / net / mograsim / logic / ui / model / components / mi / nandbased / GUI_rsLatch.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.SimpleRectangularSubmodelComponent;
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 GUI_rsLatch extends SimpleRectangularSubmodelComponent
12 {
13         public GUI_rsLatch(ViewModelModifiable model)
14         {
15                 super(model, 1, "_rsLatch");
16                 setSubmodelScale(.4);
17                 setInputPins("_S", "_R");
18                 setOutputPins("Q", "_Q");
19                 initSubmodelComponents();
20         }
21
22         @SuppressWarnings("unused") // for GUIWires being created
23         private void initSubmodelComponents()
24         {
25                 Pin _S = getInputSubmodelPins().get(0);
26                 Pin _R = getInputSubmodelPins().get(1);
27                 Pin Q = getOutputSubmodelPins().get(0);
28                 Pin _Q = getOutputSubmodelPins().get(1);
29
30                 GUINandGate nand1 = new GUINandGate(submodelModifiable, 1);
31                 GUINandGate nand2 = new GUINandGate(submodelModifiable, 1);
32
33                 WireCrossPoint cp1 = new WireCrossPoint(submodelModifiable, 1);
34                 WireCrossPoint cp2 = new WireCrossPoint(submodelModifiable, 1);
35
36                 nand1.moveTo(10, 7.5);
37                 nand2.moveTo(40, 12.5);
38                 cp1.moveCenterTo(35, 17.5);
39                 cp2.moveCenterTo(65, 37.5);
40
41                 new GUIWire(submodelModifiable, _S, nand1.getInputPins().get(0), new Point[0]);
42                 new GUIWire(submodelModifiable, _R, nand2.getInputPins().get(1), new Point(35, 37.5), new Point(35, 27.5));
43                 new GUIWire(submodelModifiable, nand1.getOutputPin(), cp1, new Point[0]);
44                 new GUIWire(submodelModifiable, nand2.getOutputPin(), cp2, new Point(65, 22.5));
45                 new GUIWire(submodelModifiable, cp1, nand2.getInputPins().get(0), new Point[0]);
46                 new GUIWire(submodelModifiable, cp2, nand1.getInputPins().get(1), new Point(65, 42.5), new Point(5, 42.5), new Point(5, 22.5));
47                 new GUIWire(submodelModifiable, cp1, Q, new Point(35, 17.5), new Point(35, 7.5), new Point(65, 7.5), new Point(65, 12.5));
48                 new GUIWire(submodelModifiable, cp2, _Q, new Point[0]);
49         }
50 }