The line dash of singlebit wires changes according to their value
authorDaniel Kirschten <daniel.kirschten@gmx.de>
Mon, 18 May 2020 15:05:56 +0000 (17:05 +0200)
committerDaniel Kirschten <daniel.kirschten@gmx.de>
Mon, 18 May 2020 15:05:56 +0000 (17:05 +0200)
Fixes #2

plugins/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/examples/ModelComponentTestbench.java
plugins/net.mograsim.logic.model/src/net/mograsim/logic/model/BitVectorFormatter.java
plugins/net.mograsim.logic.model/src/net/mograsim/logic/model/model/wires/ModelWire.java
plugins/net.mograsim.logic.model/src/net/mograsim/logic/model/preferences/DefaultRenderPreferences.java
plugins/net.mograsim.logic.model/src/net/mograsim/logic/model/preferences/RenderPreferences.java

index 7a009d9..46fc1db 100644 (file)
@@ -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<String> inputPinNames = new ArrayList<>();
                List<String> outputPinNames = new ArrayList<>();
index be77c93..b8cd0f9 100644 (file)
@@ -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());
index 813f06d..130389f 100644 (file)
@@ -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));
        }
 
index 43d58c7..e0a6887 100644 (file)
@@ -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);
                }
index 7f90988..9996361 100644 (file)
@@ -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";