X-Git-Url: https://mograsim.net/gitweb/?a=blobdiff_plain;f=net.mograsim.logic.ui%2Fsrc%2Fnet%2Fmograsim%2Flogic%2Fui%2Fmodel%2Fwires%2FGUIWire.java;h=63c2160dab73d258dd5bbf6eea723b6d2f82b40f;hb=63a0289cdf12e2f349267b6be9897350171d9741;hp=50871fe59b7c13bb82e406f73e3796af3edf7361;hpb=e7193d1fb16edc79e9cc3d8adcfb71caecd8463b;p=Mograsim.git diff --git a/net.mograsim.logic.ui/src/net/mograsim/logic/ui/model/wires/GUIWire.java b/net.mograsim.logic.ui/src/net/mograsim/logic/ui/model/wires/GUIWire.java index 50871fe5..63c2160d 100644 --- a/net.mograsim.logic.ui/src/net/mograsim/logic/ui/model/wires/GUIWire.java +++ b/net.mograsim.logic.ui/src/net/mograsim/logic/ui/model/wires/GUIWire.java @@ -10,11 +10,11 @@ import net.mograsim.logic.core.LogicObserver; import net.mograsim.logic.core.types.BitVectorFormatter; import net.mograsim.logic.core.wires.Wire.ReadEnd; import net.mograsim.logic.ui.ColorHelper; -import net.mograsim.logic.ui.model.ViewModel; +import net.mograsim.logic.ui.model.ViewModelModifiable; public class GUIWire { - private final ViewModel model; + private final ViewModelModifiable model; public final int logicWidth; private Pin pin1; private Pin pin2; @@ -25,20 +25,37 @@ public class GUIWire private final LogicObserver logicObs; private ReadEnd end; - public GUIWire(ViewModel model, Pin pin1, Pin pin2, Point... path) + public GUIWire(ViewModelModifiable model, WireCrossPoint pin1, WireCrossPoint pin2, Point... path) + { + this(model, pin1.getPin(), pin2.getPin(), path); + } + + public GUIWire(ViewModelModifiable model, WireCrossPoint pin1, Pin pin2, Point... path) + { + this(model, pin1.getPin(), pin2, path); + } + + public GUIWire(ViewModelModifiable model, Pin pin1, WireCrossPoint pin2, Point... path) + { + this(model, pin1, pin2.getPin(), path); + } + + public GUIWire(ViewModelModifiable model, Pin pin1, Pin pin2, Point... path) { logicObs = (i) -> callRedrawListeners(); this.model = model; 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; @@ -52,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();