show markers

This commit is contained in:
Bane Stojkovic
2025-03-27 19:18:43 +01:00
parent 8267d17ff7
commit b3ad9cc0d9
9 changed files with 44 additions and 40 deletions
@@ -21,7 +21,9 @@
*/ */
package org.diylc.core; package org.diylc.core;
import java.awt.*; import java.awt.Color;
import java.util.List;
import java.util.Map;
/** /**
* Interface for all component that can act as switches. They must have at least one position. * Interface for all component that can act as switches. They must have at least one position.
@@ -81,4 +83,6 @@ public interface ISwitch extends IContinuity {
} }
return arePointsConnected(index1, index2, getSelectedPosition()); return arePointsConnected(index1, index2, getSelectedPosition());
} }
List<Integer> getCommonPoints();
} }
@@ -27,6 +27,26 @@ import java.util.*;
public class SwitchUtils { public class SwitchUtils {
public static Map<Integer, List<List<Integer>>> getSwitchingMatrix(ISwitch switchComponent, int numPoints) {
Map<Integer, List<List<Integer>>> result = new HashMap<>();
for (Integer commonPoint : switchComponent.getCommonPoints()) {
List<List<Integer>> connectedPoints = new ArrayList<>();
result.put(commonPoint, connectedPoints);
for (int i = 0; i < switchComponent.getPositionCount(); i++) {
List<Integer> positionPoints = new ArrayList<>();
for (int j = 0; j < numPoints; j++) {
if (commonPoint != j && switchComponent.arePointsConnected(commonPoint, j, i)) {
positionPoints.add(j);
}
}
connectedPoints.add(positionPoints);
}
}
return result;
}
public static List<Set<Integer>> getConnectedTerminals(ISwitch switchComponent, int numPoints) { public static List<Set<Integer>> getConnectedTerminals(ISwitch switchComponent, int numPoints) {
if (!Boolean.TRUE.equals(switchComponent.getHighlightConnectedTerminals())) { if (!Boolean.TRUE.equals(switchComponent.getHighlightConnectedTerminals())) {
@@ -33,8 +33,7 @@ public class SwitchUtilsTest {
return selectedPosition; return selectedPosition;
} }
@Override public Boolean getShowMarkers() {
public Boolean getHighlightConnectedTerminals() {
return renderConnected; return renderConnected;
} }
@@ -533,8 +533,7 @@ public class MiniToggleSwitch extends AbstractTransparentComponent<ToggleSwitchT
} }
@EditableProperty(name = "Highlight Connected") @EditableProperty(name = "Highlight Connected")
@Override public Boolean getShowMarkers() {
public Boolean getHighlightConnectedTerminals() {
if (highlightConnectedTerminals == null) { if (highlightConnectedTerminals == null) {
highlightConnectedTerminals = false; highlightConnectedTerminals = false;
} }
@@ -107,7 +107,6 @@ public class RotarySwitchOpen extends AbstractAngledComponent<RotarySwitchOpenTy
private double[] pointAngles; private double[] pointAngles;
private Integer selectedPosition; private Integer selectedPosition;
private Boolean highlightConnectedTerminals;
public RotarySwitchOpen() { public RotarySwitchOpen() {
super(); super();
@@ -600,19 +599,6 @@ public class RotarySwitchOpen extends AbstractAngledComponent<RotarySwitchOpenTy
this.selectedPosition = selectedPosition; this.selectedPosition = selectedPosition;
} }
@EditableProperty(name = "Highlight Connected")
@Override
public Boolean getHighlightConnectedTerminals() {
if (highlightConnectedTerminals == null) {
highlightConnectedTerminals = false;
}
return highlightConnectedTerminals;
}
public void setHighlightConnectedTerminals(Boolean highlightConnectedTerminals) {
this.highlightConnectedTerminals = highlightConnectedTerminals;
}
@Override @Override
public Rectangle2D getCachingBounds() { public Rectangle2D getCachingBounds() {
Shape[] body = getBody(); Shape[] body = getBody();
@@ -505,8 +505,7 @@ public class SlideSwitch extends AbstractTransparentComponent<SlideSwitchType> i
} }
@EditableProperty(name = "Highlight Connected") @EditableProperty(name = "Highlight Connected")
@Override public Boolean getShowMarkers() {
public Boolean getHighlightConnectedTerminals() {
if (highlightConnectedTerminals == null) { if (highlightConnectedTerminals == null) {
highlightConnectedTerminals = false; highlightConnectedTerminals = false;
} }
@@ -451,8 +451,7 @@ public class Freeway3x3_03 extends AbstractTransparentComponent<Void> implements
} }
@EditableProperty(name = "Highlight Connected") @EditableProperty(name = "Highlight Connected")
@Override public Boolean getShowMarkers() {
public Boolean getHighlightConnectedTerminals() {
if (highlightConnectedTerminals == null) { if (highlightConnectedTerminals == null) {
highlightConnectedTerminals = false; highlightConnectedTerminals = false;
} }
@@ -83,7 +83,7 @@ public class LeverSwitch extends AbstractAngledComponent<LeverSwitch.LeverSwitch
@Deprecated @Deprecated
private Boolean highlightCommon; private Boolean highlightCommon;
private Integer selectedPosition; private Integer selectedPosition;
private Boolean highlightConnectedTerminals; private Boolean showMarkers;
public LeverSwitch() { public LeverSwitch() {
super(); super();
@@ -521,17 +521,16 @@ public class LeverSwitch extends AbstractAngledComponent<LeverSwitch.LeverSwitch
this.body = null; this.body = null;
} }
@EditableProperty(name = "Highlight Connected") @EditableProperty(name = "Markers")
@Override public Boolean getShowMarkers() {
public Boolean getHighlightConnectedTerminals() { if (showMarkers == null) {
if (highlightConnectedTerminals == null) { showMarkers = false;
highlightConnectedTerminals = false;
} }
return highlightConnectedTerminals; return showMarkers;
} }
public void setHighlightConnectedTerminals(Boolean highlightConnectedTerminals) { public void setShowMarkers(Boolean showMarkers) {
this.highlightConnectedTerminals = highlightConnectedTerminals; this.showMarkers = showMarkers;
this.body = null; this.body = null;
} }
@@ -90,7 +90,7 @@ public class SchallerMegaSwitch extends AbstractAngledComponent<String> implemen
private transient Double labelDy = null; private transient Double labelDy = null;
private Integer selectedPosition; private Integer selectedPosition;
private Boolean highlightConnectedTerminals; private Boolean showMarkers;
public SchallerMegaSwitch() { public SchallerMegaSwitch() {
super(); super();
@@ -570,16 +570,15 @@ public class SchallerMegaSwitch extends AbstractAngledComponent<String> implemen
} }
@EditableProperty(name = "Highlight Connected") @EditableProperty(name = "Highlight Connected")
@Override public Boolean getShowMarkers() {
public Boolean getHighlightConnectedTerminals() { if (showMarkers == null) {
if (highlightConnectedTerminals == null) { showMarkers = false;
highlightConnectedTerminals = false;
} }
return highlightConnectedTerminals; return showMarkers;
} }
public void setHighlightConnectedTerminals(Boolean highlightConnectedTerminals) { public void setShowMarkers(Boolean showMarkers) {
this.highlightConnectedTerminals = highlightConnectedTerminals; this.showMarkers = showMarkers;
this.body = null; this.body = null;
} }