From b456eecf8d1563c7e0ca64a5bc2cf146173dc3ff Mon Sep 17 00:00:00 2001 From: Daniel Kirschten Date: Mon, 18 May 2020 17:05:56 +0200 Subject: [PATCH] The line dash of singlebit wires changes according to their value Fixes #2 --- .../examples/ModelComponentTestbench.java | 6 +-- .../logic/model/BitVectorFormatter.java | 51 +++++++++++++++++++ .../logic/model/model/wires/ModelWire.java | 2 + .../preferences/DefaultRenderPreferences.java | 10 ++++ .../model/preferences/RenderPreferences.java | 5 ++ 5 files changed, 71 insertions(+), 3 deletions(-) diff --git a/plugins/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/examples/ModelComponentTestbench.java b/plugins/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/examples/ModelComponentTestbench.java index 7a009d97..46fc1db4 100644 --- a/plugins/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/examples/ModelComponentTestbench.java +++ b/plugins/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/examples/ModelComponentTestbench.java @@ -6,6 +6,7 @@ import java.util.List; import net.mograsim.logic.model.SimpleLogicUIStandalone; import net.mograsim.logic.model.am2900.Am2900Loader; +import net.mograsim.logic.model.am2900.machine.Am2900ExpertMachineDefinition; import net.mograsim.logic.model.model.LogicModelModifiable; import net.mograsim.logic.model.model.components.ModelComponent; import net.mograsim.logic.model.model.components.atomic.ModelBitDisplay; @@ -14,7 +15,6 @@ import net.mograsim.logic.model.model.components.atomic.ModelTextComponent; import net.mograsim.logic.model.model.wires.ModelWire; import net.mograsim.logic.model.model.wires.Pin; import net.mograsim.logic.model.model.wires.PinUsage; -import net.mograsim.logic.model.serializing.IndirectModelComponentCreator; public class ModelComponentTestbench { @@ -27,8 +27,8 @@ public class ModelComponentTestbench public static void createTestbench(LogicModelModifiable model) { Am2900Loader.setup(); -// ModelComponent comp = new Am2900ExpertMachineDefinition().createNew(model).getAm2900(); - ModelComponent comp = IndirectModelComponentCreator.createComponent(model, "ram5_12"); + ModelComponent comp = new Am2900ExpertMachineDefinition().createNew(model).getAm2900(); +// ModelComponent comp = IndirectModelComponentCreator.createComponent(model, "ram5_12"); List inputPinNames = new ArrayList<>(); List outputPinNames = new ArrayList<>(); diff --git a/plugins/net.mograsim.logic.model/src/net/mograsim/logic/model/BitVectorFormatter.java b/plugins/net.mograsim.logic.model/src/net/mograsim/logic/model/BitVectorFormatter.java index be77c93b..b8cd0f9d 100644 --- a/plugins/net.mograsim.logic.model/src/net/mograsim/logic/model/BitVectorFormatter.java +++ b/plugins/net.mograsim.logic.model/src/net/mograsim/logic/model/BitVectorFormatter.java @@ -1,10 +1,15 @@ package net.mograsim.logic.model; import static net.mograsim.logic.model.preferences.RenderPreferences.BIT_ONE_COLOR; +import static net.mograsim.logic.model.preferences.RenderPreferences.BIT_ONE_DASH; import static net.mograsim.logic.model.preferences.RenderPreferences.BIT_U_COLOR; +import static net.mograsim.logic.model.preferences.RenderPreferences.BIT_U_DASH; import static net.mograsim.logic.model.preferences.RenderPreferences.BIT_X_COLOR; +import static net.mograsim.logic.model.preferences.RenderPreferences.BIT_X_DASH; import static net.mograsim.logic.model.preferences.RenderPreferences.BIT_ZERO_COLOR; +import static net.mograsim.logic.model.preferences.RenderPreferences.BIT_ZERO_DASH; import static net.mograsim.logic.model.preferences.RenderPreferences.BIT_Z_COLOR; +import static net.mograsim.logic.model.preferences.RenderPreferences.BIT_Z_DASH; import java.math.BigInteger; @@ -76,6 +81,52 @@ public class BitVectorFormatter return bitvector; } + public static double[] formatAsLineDash(RenderPreferences renderPrefs, ReadEnd end) + { + return formatAsLineDash(renderPrefs, end == null ? null : end.getValues()); + } + + public static double[] formatAsLineDash(RenderPreferences renderPrefs, BitVector bitVector) + { + // TODO maybe find a line dash assignment for multiple-bit bit vectors? + if (bitVector == null || bitVector.length() != 1) + return null; + String prefName; + switch (bitVector.getLSBit(0)) + { + case ONE: + prefName = BIT_ONE_DASH; + break; + case U: + prefName = BIT_U_DASH; + break; + case X: + prefName = BIT_X_DASH; + break; + case Z: + prefName = BIT_Z_DASH; + break; + case ZERO: + prefName = BIT_ZERO_DASH; + break; + default: + throw new IllegalArgumentException("Unknown enum constant: " + bitVector.getLSBit(0)); + } + return parseLineDashes(renderPrefs.getString(prefName)); + } + + // TODO this method does not belong here + public static double[] parseLineDashes(String dashesString) + { + if (dashesString.isEmpty()) + return null; + String[] dashesStrings = dashesString.split(","); + double[] dashes = new double[dashesStrings.length]; + for (int i = 0; i < dashesStrings.length; i++) + dashes[i] = Double.parseDouble(dashesStrings[i]); + return dashes; + } + public static ColorDefinition formatAsColor(RenderPreferences renderPrefs, ReadEnd end) { return formatAsColor(renderPrefs, end == null ? null : end.getValues()); diff --git a/plugins/net.mograsim.logic.model/src/net/mograsim/logic/model/model/wires/ModelWire.java b/plugins/net.mograsim.logic.model/src/net/mograsim/logic/model/model/wires/ModelWire.java index 813f06dd..130389f4 100644 --- a/plugins/net.mograsim.logic.model/src/net/mograsim/logic/model/model/wires/ModelWire.java +++ b/plugins/net.mograsim.logic.model/src/net/mograsim/logic/model/model/wires/ModelWire.java @@ -373,7 +373,9 @@ public class ModelWire if (wireColor != null) gc.setForeground(ColorManager.current().toColor(wireColor)); gc.setLineWidth(renderPrefs.getDouble(logicWidth == 1 ? WIRE_WIDTH_SINGLEBIT : WIRE_WIDTH_MULTIBIT)); + gc.setLineDash(BitVectorFormatter.formatAsLineDash(renderPrefs, end)); gc.drawPolyline(effectivePath); + gc.setLineDash(null); gc.setLineWidth(renderPrefs.getDouble(DEFAULT_LINE_WIDTH)); } diff --git a/plugins/net.mograsim.logic.model/src/net/mograsim/logic/model/preferences/DefaultRenderPreferences.java b/plugins/net.mograsim.logic.model/src/net/mograsim/logic/model/preferences/DefaultRenderPreferences.java index 43d58c7f..e0a68876 100644 --- a/plugins/net.mograsim.logic.model/src/net/mograsim/logic/model/preferences/DefaultRenderPreferences.java +++ b/plugins/net.mograsim.logic.model/src/net/mograsim/logic/model/preferences/DefaultRenderPreferences.java @@ -65,6 +65,16 @@ public class DefaultRenderPreferences extends DefaultPreferences implements Rend { switch (name) { + case BIT_ZERO_DASH: + return "10, 2.5"; + case BIT_Z_DASH: + return "10, 0.25, 0.25, 1.5, 0.25, 0.25"; + case BIT_X_DASH: + return "10, 0.25, 0.25, 0.25, 0.25, 0.5, 0.25, 0.25, 0.25, 0.25"; + case BIT_U_DASH: + return "10, 0.25, 0.25, 0.25, 1, 0.25, 0.25, 0.25"; + case BIT_ONE_DASH: + return "10, 0.5, 1.5, 0.5"; default: throw new IllegalArgumentException("Unknown string preference name: " + name); } diff --git a/plugins/net.mograsim.logic.model/src/net/mograsim/logic/model/preferences/RenderPreferences.java b/plugins/net.mograsim.logic.model/src/net/mograsim/logic/model/preferences/RenderPreferences.java index 7f90988b..99963610 100644 --- a/plugins/net.mograsim.logic.model/src/net/mograsim/logic/model/preferences/RenderPreferences.java +++ b/plugins/net.mograsim.logic.model/src/net/mograsim/logic/model/preferences/RenderPreferences.java @@ -21,6 +21,11 @@ public interface RenderPreferences extends Preferences public static final String WIRE_WIDTH_MULTIBIT = PREFIX + "linewidth.wire.multibit"; public static final String WIRE_WIDTH_SINGLEBIT = PREFIX + "linewidth.wire.singlebit"; public static final String DEFAULT_LINE_WIDTH = PREFIX + "linewidth.default"; + public static final String BIT_ZERO_DASH = PREFIX + "linedash.bit.zero"; + public static final String BIT_Z_DASH = PREFIX + "linedash.bit.z"; + public static final String BIT_X_DASH = PREFIX + "linedash.bit.x"; + public static final String BIT_U_DASH = PREFIX + "linedash.bit.u"; + public static final String BIT_ONE_DASH = PREFIX + "linedash.bit.one"; public static final String ZOOM_BUTTON = PREFIX + "button.zoom"; public static final String DRAG_BUTTON = PREFIX + "button.drag"; public static final String ACTION_BUTTON = PREFIX + "button.action"; -- 2.17.1