Added fulladder. GUIWires are now drawn with right angles.
authorFabian Stemmler <stemmler@in.tum.de>
Wed, 5 Jun 2019 14:34:42 +0000 (16:34 +0200)
committerFabian Stemmler <stemmler@in.tum.de>
Wed, 5 Jun 2019 14:34:42 +0000 (16:34 +0200)
net.mograsim.logic.ui/src/net/mograsim/logic/ui/model/components/mi/nandbased/GUIfulladder.java [new file with mode: 0644]
net.mograsim.logic.ui/src/net/mograsim/logic/ui/model/wires/GUIWire.java

diff --git a/net.mograsim.logic.ui/src/net/mograsim/logic/ui/model/components/mi/nandbased/GUIfulladder.java b/net.mograsim.logic.ui/src/net/mograsim/logic/ui/model/components/mi/nandbased/GUIfulladder.java
new file mode 100644 (file)
index 0000000..0e3a8fd
--- /dev/null
@@ -0,0 +1,83 @@
+package net.mograsim.logic.ui.model.components.mi.nandbased;
+
+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.wires.GUIWire;
+import net.mograsim.logic.ui.model.wires.Pin;
+
+public class GUIfulladder extends SubmodelComponent
+{
+       private final Pin pinA;
+       private final Pin pinB;
+       private final Pin pinC;
+       private final Pin pinY;
+       private final Pin pinZ;
+
+       public GUIfulladder(ViewModelModifiable model)
+       {
+               super(model, "GUIfulladder");
+               setSize(50, 40);
+               setSubmodelScale(.4);
+
+               Pin A = addSubmodelInterface(1, 0, 5);
+               Pin B = addSubmodelInterface(1, 0, 20);
+               Pin C = addSubmodelInterface(1, 0, 35);
+               Pin Y = addSubmodelInterface(1, 50, 5);
+               Pin Z = addSubmodelInterface(1, 50, 20);
+
+               this.pinA = getSupermodelPin(A);
+               this.pinB = getSupermodelPin(B);
+               this.pinC = getSupermodelPin(C);
+               this.pinY = getSupermodelPin(Y);
+               this.pinZ = getSupermodelPin(Z);
+
+               initSubmodelComponents(A, B, C, Y, Z);
+       }
+
+       @SuppressWarnings("unused") // for GUIWires being created
+       private void initSubmodelComponents(Pin A, Pin B, Pin C, Pin Y, Pin Z)
+       {
+               GUIhalfadder halfBC = new GUIhalfadder(submodelModifiable);
+               GUIhalfadder halfAY = new GUIhalfadder(submodelModifiable);
+               GUINandGate nandZ = new GUINandGate(submodelModifiable, 1);
+
+               halfAY.moveTo(55, 7.5);
+               halfBC.moveTo(10, 40);
+               nandZ.moveTo(100, 25);
+
+               new GUIWire(submodelModifiable, A, halfAY.getPinA());
+               new GUIWire(submodelModifiable, B, halfBC.getPinA());// , new Point(5, 50), new Point(5, 45));
+               new GUIWire(submodelModifiable, C, halfBC.getPinB());// , new Point(5, 87.5), new Point(5, 60));
+               new GUIWire(submodelModifiable, halfBC.getPinY(), halfAY.getPinB());// , new Point(50, 45), new Point(50, 27.5));
+               new GUIWire(submodelModifiable, halfBC.getPin_Z(), nandZ.getInputPins().get(1));
+               new GUIWire(submodelModifiable, halfAY.getPinY(), Y);
+               new GUIWire(submodelModifiable, halfAY.getPin_Z(), nandZ.getInputPins().get(0));
+               new GUIWire(submodelModifiable, nandZ.getOutputPin(), Z);
+       }
+
+       public Pin getPinA()
+       {
+               return pinA;
+       }
+
+       public Pin getPinB()
+       {
+               return pinB;
+       }
+
+       public Pin getPinC()
+       {
+               return pinC;
+       }
+
+       public Pin getPinY()
+       {
+               return pinY;
+       }
+
+       public Pin getPinZ()
+       {
+               return pinZ;
+       }
+}
\ No newline at end of file
index b69c810..63c2160 100644 (file)
@@ -47,13 +47,15 @@ public class GUIWire
                this.logicWidth = pin1.logicWidth;
                if (pin2.logicWidth != pin1.logicWidth)
                        throw new IllegalArgumentException("Can't connect pins of different logic width");
-               this.path = new double[path.length * 2 + 4];
-               for (int srcI = 0, dstI = 2; srcI < path.length; srcI++, dstI += 2)
+
+               if (path.length == 0)
                {
-                       this.path[dstI + 0] = path[srcI].x;
-                       this.path[dstI + 1] = path[srcI].y;
+                       Point pos1 = pin1.getPos(), pos2 = pin2.getPos();
+                       path = new Point[] { new Point((pos1.x + pos2.x) / 2, pos1.y), new Point((pos1.x + pos2.x) / 2, pos2.y) };
                }
 
+               applyPath(path);
+
                this.pin1 = pin1;
                this.pin2 = pin2;
 
@@ -67,6 +69,17 @@ public class GUIWire
                model.wireCreated(this);
        }
 
+       private void applyPath(Point... path)
+       {
+               this.path = new double[path.length * 2 + 4];
+
+               for (int srcI = 0, dstI = 2; srcI < path.length; srcI++, dstI += 2)
+               {
+                       this.path[dstI + 0] = path[srcI].x;
+                       this.path[dstI + 1] = path[srcI].y;
+               }
+       }
+
        private void pin1Moved()
        {
                Point pos = pin1.getPos();