Adapted GUIhalfadder to SimpleRectangularSubmodelComponent
authorDaniel Kirschten <daniel.kirschten@gmx.de>
Wed, 5 Jun 2019 15:24:39 +0000 (17:24 +0200)
committerDaniel Kirschten <daniel.kirschten@gmx.de>
Wed, 5 Jun 2019 15:24:39 +0000 (17:24 +0200)
net.mograsim.logic.ui/src/net/mograsim/logic/ui/examples/SubmodelComponentTestbench.java
net.mograsim.logic.ui/src/net/mograsim/logic/ui/model/components/mi/nandbased/GUIhalfadder.java

index e7e38ff..5de6912 100644 (file)
@@ -4,7 +4,7 @@ import net.mograsim.logic.ui.SimpleLogicUIStandalone;
 import net.mograsim.logic.ui.model.ViewModelModifiable;
 import net.mograsim.logic.ui.model.components.GUIBitDisplay;
 import net.mograsim.logic.ui.model.components.GUIManualSwitch;
-import net.mograsim.logic.ui.model.components.SubmodelComponent;
+import net.mograsim.logic.ui.model.components.SimpleRectangularSubmodelComponent;
 import net.mograsim.logic.ui.model.components.mi.nandbased.GUIhalfadder;
 import net.mograsim.logic.ui.model.wires.GUIWire;
 
@@ -18,21 +18,20 @@ public class SubmodelComponentTestbench
        @SuppressWarnings("unused") // for GUIWires being created
        public static void createTestbench(ViewModelModifiable model)
        {
-               SubmodelComponent comp = new GUIhalfadder(model);
-               int inputCount = 2;
+               SimpleRectangularSubmodelComponent comp = new GUIhalfadder(model);
 
                comp.moveTo(100, 0);
-               for (int i = 0; i < inputCount; i++)
+               for (int i = 0; i < comp.getInputPins().size(); i++)
                {
                        GUIManualSwitch sw = new GUIManualSwitch(model);
                        sw.moveTo(0, 20 * i);
-                       new GUIWire(model, comp.getPins().get(i), sw.getOutputPin());
+                       new GUIWire(model, comp.getInputPins().get(i), sw.getOutputPin());
                }
-               for (int i = inputCount; i < comp.getPins().size(); i++)
+               for (int i = 0; i < comp.getOutputPins().size(); i++)
                {
                        GUIBitDisplay bd = new GUIBitDisplay(model);
-                       bd.moveTo(200, 20 * (i - inputCount));
-                       new GUIWire(model, comp.getPins().get(i), bd.getInputPin());
+                       bd.moveTo(200, 20 * i);
+                       new GUIWire(model, comp.getOutputPins().get(i), bd.getInputPin());
                }
        }
 }
\ No newline at end of file
index 2571ff7..2e7aea8 100644 (file)
@@ -3,40 +3,30 @@ package net.mograsim.logic.ui.model.components.mi.nandbased;
 import net.haspamelodica.swt.helper.swtobjectwrappers.Point;
 import net.mograsim.logic.ui.model.ViewModelModifiable;
 import net.mograsim.logic.ui.model.components.GUINandGate;
-import net.mograsim.logic.ui.model.components.SubmodelComponent;
+import net.mograsim.logic.ui.model.components.SimpleRectangularSubmodelComponent;
 import net.mograsim.logic.ui.model.wires.GUIWire;
 import net.mograsim.logic.ui.model.wires.Pin;
 import net.mograsim.logic.ui.model.wires.WireCrossPoint;
 
-public class GUIhalfadder extends SubmodelComponent
+public class GUIhalfadder extends SimpleRectangularSubmodelComponent
 {
-       private final Pin pinA;
-       private final Pin pinB;
-       private final Pin pinY;
-       private final Pin pin_Z;
-
        public GUIhalfadder(ViewModelModifiable model)
        {
-               super(model, "GUIhalfadder");
-               setSize(35, 25);
+               super(model, 1, "GUIhalfadder");
                setSubmodelScale(.4);
-
-               Pin A = addSubmodelInterface(1, 0, 5);
-               Pin B = addSubmodelInterface(1, 0, 20);
-               Pin Y = addSubmodelInterface(1, 35, 5);
-               Pin _Z = addSubmodelInterface(1, 35, 20);
-
-               this.pinA = getSupermodelPin(A);
-               this.pinB = getSupermodelPin(B);
-               this.pinY = getSupermodelPin(Y);
-               this.pin_Z = getSupermodelPin(_Z);
-
-               initSubmodelComponents(A, B, Y, _Z);
+               setInputCount(2);
+               setOutputCount(2);
+               initSubmodelComponents();
        }
 
        @SuppressWarnings("unused") // for GUIWires being created
-       private void initSubmodelComponents(Pin A, Pin B, Pin Y, Pin _Z)
+       private void initSubmodelComponents()
        {
+               Pin A = getInputSubmodelPins().get(0);
+               Pin B = getInputSubmodelPins().get(1);
+               Pin Y = getOutputSubmodelPins().get(0);
+               Pin _Z = getOutputSubmodelPins().get(1);
+
                GUINandGate nand_Z = new GUINandGate(submodelModifiable, 1);
                GUINandGate nandYA = new GUINandGate(submodelModifiable, 1);
                GUINandGate nandYB = new GUINandGate(submodelModifiable, 1);
@@ -46,46 +36,26 @@ public class GUIhalfadder extends SubmodelComponent
                WireCrossPoint cpB = new WireCrossPoint(submodelModifiable, 1);
                WireCrossPoint cp_Z = new WireCrossPoint(submodelModifiable, 1);
 
-               nand_Z.moveTo(10, 21.25);
+               nand_Z.moveTo(10, 15);
                nandYA.moveTo(40, 2.5);
-               nandYB.moveTo(40, 40);
+               nandYB.moveTo(40, 27.5);
                nandY.moveTo(65, 2.5);
                cpA.moveTo(5, 12.5);
-               cpB.moveTo(5, 50);
-               cp_Z.moveTo(35, 31.25);
+               cpB.moveTo(5, 37.5);
+               cp_Z.moveTo(35, 25);
 
                new GUIWire(submodelModifiable, A, cpA);
                new GUIWire(submodelModifiable, cpA, nandYA.getInputPins().get(0), new Point(5, 7.5));
-               new GUIWire(submodelModifiable, cpA, nand_Z.getInputPins().get(0), new Point(5, 26.25));
+               new GUIWire(submodelModifiable, cpA, nand_Z.getInputPins().get(0), new Point(5, 20));
                new GUIWire(submodelModifiable, B, cpB);
-               new GUIWire(submodelModifiable, cpB, nandYB.getInputPins().get(1), new Point(5, 55));
-               new GUIWire(submodelModifiable, cpB, nand_Z.getInputPins().get(1), new Point(5, 36.25));
+               new GUIWire(submodelModifiable, cpB, nandYB.getInputPins().get(1), new Point(5, 42.5));
+               new GUIWire(submodelModifiable, cpB, nand_Z.getInputPins().get(1), new Point(5, 30));
                new GUIWire(submodelModifiable, nand_Z.getOutputPin(), cp_Z);
-               new GUIWire(submodelModifiable, cp_Z, _Z, new Point(80, 31.25), new Point(80, 50));
+               new GUIWire(submodelModifiable, cp_Z, _Z, new Point(80, 25), new Point(80, 37.5));
                new GUIWire(submodelModifiable, cp_Z, nandYA.getInputPins().get(1), new Point(35, 17.5));
-               new GUIWire(submodelModifiable, cp_Z, nandYB.getInputPins().get(0), new Point(35, 45));
+               new GUIWire(submodelModifiable, cp_Z, nandYB.getInputPins().get(0), new Point(35, 32.5));
                new GUIWire(submodelModifiable, nandYA.getOutputPin(), nandY.getInputPins().get(0), new Point(62.5, 12.5), new Point(62.5, 7.5));
-               new GUIWire(submodelModifiable, nandYB.getOutputPin(), nandY.getInputPins().get(1), new Point(62.5, 50), new Point(62.5, 17.5));
+               new GUIWire(submodelModifiable, nandYB.getOutputPin(), nandY.getInputPins().get(1), new Point(62.5, 37.5), new Point(62.5, 17.5));
                new GUIWire(submodelModifiable, nandY.getOutputPin(), Y);
        }
-
-       public Pin getPinA()
-       {
-               return pinA;
-       }
-
-       public Pin getPinB()
-       {
-               return pinB;
-       }
-
-       public Pin getPinY()
-       {
-               return pinY;
-       }
-
-       public Pin getPin_Z()
-       {
-               return pin_Z;
-       }
 }
\ No newline at end of file