33419069f5ef6e0d925802a1397dc7347a82d19d
[Mograsim.git] / net.mograsim.logic.ui / src / net / mograsim / logic / ui / model / components / mi / nandbased / GUIdff.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 GUIdff extends SimpleRectangularSubmodelComponent
12 {
13         public GUIdff(ViewModelModifiable model)
14         {
15                 super(model, 1, "GUIdff");
16                 setSubmodelScale(.2);
17                 setInputPins("C", "D");
18                 setOutputPins("Q", "_Q");
19                 initSubmodelComponents();
20         }
21
22         @SuppressWarnings("unused") // for GUIWires being created
23         private void initSubmodelComponents()
24         {
25                 Pin C = getInputSubmodelPins().get(0);
26                 Pin D = getInputSubmodelPins().get(1);
27                 Pin Q = getOutputSubmodelPins().get(0);
28                 Pin _Q = getOutputSubmodelPins().get(1);
29
30                 GUI_rsLatch _rsLatch1 = new GUI_rsLatch(submodelModifiable);
31                 GUInand3 nand3 = new GUInand3(submodelModifiable);
32                 GUINandGate nand2 = new GUINandGate(submodelModifiable, 1);
33                 GUI_rsLatch _rsLatch2 = new GUI_rsLatch(submodelModifiable);
34
35                 WireCrossPoint cp1 = new WireCrossPoint(submodelModifiable, 1);
36                 WireCrossPoint cp2 = new WireCrossPoint(submodelModifiable, 1);
37                 WireCrossPoint cp3 = new WireCrossPoint(submodelModifiable, 1);
38                 WireCrossPoint cp4 = new WireCrossPoint(submodelModifiable, 1);
39
40                 _rsLatch1.moveTo(40, 10);
41                 nand3.moveTo(40, 40);
42                 nand2.moveTo(120, 60);
43                 _rsLatch2.moveTo(120, 30);
44                 cp1.moveCenterTo(10, 25);
45                 cp2.moveCenterTo(20, 65);
46                 cp3.moveCenterTo(100, 35);
47                 cp4.moveCenterTo(100, 45);
48
49                 new GUIWire(submodelModifiable, C, cp1, new Point[0]);
50                 new GUIWire(submodelModifiable, cp1, _rsLatch1.getInputPins().get(1), new Point[0]);
51                 new GUIWire(submodelModifiable, cp1, nand3.getInputPins().get(1), new Point(10, 55));
52                 new GUIWire(submodelModifiable, D, nand2.getInputPins().get(1), new Point[0]);
53                 new GUIWire(submodelModifiable, nand2.getOutputPin(), cp2, new Point(145, 70), new Point(145, 85), new Point(20, 85));
54                 new GUIWire(submodelModifiable, cp2, _rsLatch1.getInputPins().get(0), new Point(20, 15));
55                 new GUIWire(submodelModifiable, cp2, nand3.getInputPins().get(2), new Point[0]);
56                 new GUIWire(submodelModifiable, _rsLatch1.getOutputPins().get(1), cp3, new Point(100, 25));
57                 new GUIWire(submodelModifiable, cp3, nand3.getInputPins().get(0), new Point(30, 35), new Point(30, 45));
58                 new GUIWire(submodelModifiable, cp3, _rsLatch2.getInputPins().get(0), new Point[0]);
59                 new GUIWire(submodelModifiable, nand3.getOutputPins().get(0), cp4, new Point[0]);
60                 new GUIWire(submodelModifiable, cp4, _rsLatch2.getInputPins().get(1), new Point[0]);
61                 new GUIWire(submodelModifiable, cp4, nand2.getInputPins().get(0), new Point(100, 65));
62                 new GUIWire(submodelModifiable, _rsLatch2.getOutputPins().get(0), Q);
63                 new GUIWire(submodelModifiable, _rsLatch2.getOutputPins().get(1), _Q);
64         }
65 }