Added fulladder. GUIWires are now drawn with right angles.
[Mograsim.git] / net.mograsim.logic.ui / src / net / mograsim / logic / ui / model / wires / GUIWire.java
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();