abb93cc339c3a04f4cacfd6bc0f84eb5ebf67864
[Mograsim.git] / net.mograsim.logic.ui.am2900 / src / net / mograsim / logic / ui / model / components / mi / nandbased / GUIhalfadder.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.atomic.GUINandGate;
6 import net.mograsim.logic.ui.model.components.submodels.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 import net.mograsim.logic.ui.serializing.IndirectGUIComponentCreator;
11
12 public class GUIhalfadder extends SimpleRectangularSubmodelComponent
13 {
14         public GUIhalfadder(ViewModelModifiable model)
15         {
16                 this(model, null);
17         }
18
19         public GUIhalfadder(ViewModelModifiable model, String name)
20         {
21                 super(model, 1, "GUIhalfadder", name);
22                 setSubmodelScale(.4);
23                 setInputPins("A", "B");
24                 setOutputPins("Y", "_Z");
25                 initSubmodelComponents();
26         }
27
28         @SuppressWarnings("unused") // for GUIWires being created
29         private void initSubmodelComponents()
30         {
31                 Pin A = getSubmodelPin("A");
32                 Pin B = getSubmodelPin("B");
33                 Pin Y = getSubmodelPin("Y");
34                 Pin _Z = getSubmodelPin("_Z");
35
36                 GUINandGate nand_Z = new GUINandGate(submodelModifiable, 1);
37                 GUINandGate nandYA = new GUINandGate(submodelModifiable, 1);
38                 GUINandGate nandYB = new GUINandGate(submodelModifiable, 1);
39                 GUINandGate nandY = new GUINandGate(submodelModifiable, 1);
40
41                 WireCrossPoint cpA = new WireCrossPoint(submodelModifiable, 1);
42                 WireCrossPoint cpB = new WireCrossPoint(submodelModifiable, 1);
43                 WireCrossPoint cp_Z = new WireCrossPoint(submodelModifiable, 1);
44
45                 nand_Z.moveTo(10, 15);
46                 nandYA.moveTo(40, 2.5);
47                 nandYB.moveTo(40, 27.5);
48                 nandY.moveTo(65, 2.5);
49                 cpA.moveCenterTo(5, 12.5);
50                 cpB.moveCenterTo(5, 37.5);
51                 cp_Z.moveCenterTo(35, 25);
52
53                 new GUIWire(submodelModifiable, A, cpA, new Point[0]);
54                 new GUIWire(submodelModifiable, cpA, nandYA.getPin("A"), new Point(5, 7.5));
55                 new GUIWire(submodelModifiable, cpA, nand_Z.getPin("A"), new Point(5, 20));
56                 new GUIWire(submodelModifiable, B, cpB, new Point[0]);
57                 new GUIWire(submodelModifiable, cpB, nandYB.getPin("B"), new Point(5, 42.5));
58                 new GUIWire(submodelModifiable, cpB, nand_Z.getPin("B"), new Point(5, 30));
59                 new GUIWire(submodelModifiable, nand_Z.getPin("Y"), cp_Z, new Point[0]);
60                 new GUIWire(submodelModifiable, cp_Z, _Z, new Point(80, 25), new Point(80, 37.5));
61                 new GUIWire(submodelModifiable, cp_Z, nandYA.getPin("B"), new Point(35, 17.5));
62                 new GUIWire(submodelModifiable, cp_Z, nandYB.getPin("A"), new Point(35, 32.5));
63                 new GUIWire(submodelModifiable, nandYA.getPin("Y"), nandY.getPin("A"), new Point(62.5, 12.5), new Point(62.5, 7.5));
64                 new GUIWire(submodelModifiable, nandYB.getPin("Y"), nandY.getPin("B"), new Point(62.5, 37.5), new Point(62.5, 17.5));
65                 new GUIWire(submodelModifiable, nandY.getPin("Y"), Y, new Point[0]);
66         }
67
68         static
69         {
70                 IndirectGUIComponentCreator.setComponentSupplier(GUIhalfadder.class.getCanonicalName(), (m, p, n) -> new GUIhalfadder(m, n));
71         }
72 }