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=6f6147ad2324a70b3b5e52ffd9f385af6d8c3e54;hb=1e4c26b6d59f2cc40ce5af657c54ce65788e2c43;hp=6398817d1cb1cf917185dc9b1c7c8996a28f0f52;hpb=a84700145147c263ad6692c99117a7cf37832378;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 6398817d..6f6147ad 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,10 +10,13 @@ import net.haspamelodica.swt.helper.gcs.GeneralGC; import net.haspamelodica.swt.helper.swtobjectwrappers.Point; import net.haspamelodica.swt.helper.swtobjectwrappers.Rectangle; import net.mograsim.logic.core.LogicObserver; +import net.mograsim.logic.core.types.BitVector; import net.mograsim.logic.core.types.BitVectorFormatter; +import net.mograsim.logic.core.wires.Wire; import net.mograsim.logic.core.wires.Wire.ReadEnd; -import net.mograsim.logic.ui.ColorHelper; import net.mograsim.logic.ui.model.ViewModelModifiable; +import net.mograsim.preferences.ColorDefinition; +import net.mograsim.preferences.ColorManager; /** * A wire connecting exactly two {@link Pin}s. @@ -71,37 +74,7 @@ public class GUIWire * * @author Daniel Kirschten */ - public GUIWire(ViewModelModifiable model, WireCrossPoint pin1, WireCrossPoint pin2) - { - this(model, pin1, pin2, (Point[]) null); - } - - /** - * Creates a new {@link GUIWire} with automatic interpolation. - * - * @author Daniel Kirschten - */ - public GUIWire(ViewModelModifiable model, WireCrossPoint pin1, Pin pin2) - { - this(model, pin1, pin2, (Point[]) null); - } - - /** - * Creates a new {@link GUIWire} with automatic interpolation. - * - * @author Daniel Kirschten - */ - public GUIWire(ViewModelModifiable model, Pin pin1, WireCrossPoint pin2) - { - this(model, pin1, pin2, (Point[]) null); - } - - /** - * Creates a new {@link GUIWire} with automatic interpolation. - * - * @author Daniel Kirschten - */ - public GUIWire(ViewModelModifiable model, Pin pin1, Pin pin2) + public GUIWire(ViewModelModifiable model, ConnectionPoint pin1, ConnectionPoint pin2) { this(model, pin1, pin2, (Point[]) null); } @@ -111,7 +84,7 @@ public class GUIWire * * @author Daniel Kirschten */ - public GUIWire(ViewModelModifiable model, WireCrossPoint pin1, WireCrossPoint pin2, Point... path) + public GUIWire(ViewModelModifiable model, ConnectionPoint pin1, ConnectionPoint pin2, Point... path) { this(model, pin1.getPin(), pin2.getPin(), path); } @@ -121,27 +94,7 @@ public class GUIWire * * @author Daniel Kirschten */ - public GUIWire(ViewModelModifiable model, WireCrossPoint pin1, Pin pin2, Point... path) - { - this(model, pin1.getPin(), pin2, path); - } - - /** - * Creates a new {@link GUIWire} without automatic interpolation. - * - * @author Daniel Kirschten - */ - public GUIWire(ViewModelModifiable model, Pin pin1, WireCrossPoint pin2, Point... path) - { - this(model, pin1, pin2.getPin(), path); - } - - /** - * Creates a new {@link GUIWire} without automatic interpolation. - * - * @author Daniel Kirschten - */ - public GUIWire(ViewModelModifiable model, Pin pin1, Pin pin2, Point... path) + GUIWire(ViewModelModifiable model, Pin pin1, Pin pin2, Point... path) { logicObs = (i) -> callRedrawListeners(); this.model = model; @@ -274,7 +227,10 @@ public class GUIWire */ public void render(GeneralGC gc) { - ColorHelper.executeWithDifferentForeground(gc, BitVectorFormatter.formatAsColor(end), () -> gc.drawPolyline(effectivePath)); + ColorDefinition wireColor = BitVectorFormatter.formatAsColor(end); + if (wireColor != null) + gc.setForeground(ColorManager.current().toColor(wireColor)); + gc.drawPolyline(effectivePath); } /** @@ -308,6 +264,38 @@ public class GUIWire end.registerObserver(logicObs); } + /** + * Returns whether this {@link GUIWire} has a logic model binding or not. + * + * @author Daniel Kirschten + */ + public boolean hasLogicModelBinding() + { + return end != null; + } + + /** + * If this {@link GUIWire} has a logic model binding, delegates to {@link Wire#forceValues(BitVector)} for the {@link Wire} + * corresponding to this {@link GUIWire}. + * + * @author Daniel Kirschten + */ + public void forceWireValues(BitVector values) + { + end.getWire().forceValues(values); + } + + /** + * If this {@link GUIWire} has a logic model binding, delegates to {@link ReadEnd#getValues()} for the {@link ReadEnd} corresponding to + * this {@link GUIWire}. + * + * @author Daniel Kirschten + */ + public BitVector getWireValues() + { + return end.getValues(); + } + // listeners // @formatter:off @@ -318,4 +306,9 @@ public class GUIWire private void callRedrawListeners() {redrawListeners.forEach(l -> l.run());} // @formatter:on + @Override + public String toString() + { + return "GUIWire [" + pin1 + "---" + pin2 + ", value=" + (end == null ? "null" : end.getValues()) + "]"; + } } \ No newline at end of file