switch enhancements

This commit is contained in:
Bane Stojkovic
2025-03-27 23:48:22 +01:00
parent 5052e10f0e
commit 34054a68f1
3 changed files with 55 additions and 99 deletions
@@ -57,8 +57,6 @@ import org.diylc.core.measures.SizeUnit;
import org.diylc.utils.Constants;
import org.diylc.utils.SwitchUtils;
import static org.diylc.utils.SwitchUtils.getConnectedTerminals;
@ComponentDescriptor(name = "Slide Switch", category = "Electro-Mechanical",
author = "Branislav Stojkovic", description = "Panel mounted slide switch",
zOrder = IDIYComponent.COMPONENT, instanceNamePrefix = "SW", autoEdit = false,
@@ -45,9 +45,8 @@ import com.kitfox.svg.SVGElement;
import com.kitfox.svg.SVGUniverse;
import com.kitfox.svg.ShapeElement;
import org.diylc.common.IPlugInPort;
import org.diylc.common.ObjectCache;
import org.diylc.common.Orientation;
import org.diylc.awt.StringUtils;
import org.diylc.common.*;
import org.diylc.components.AbstractTransparentComponent;
import org.diylc.components.transform.Freeway3x3_03Transformer;
import org.diylc.core.*;
@@ -58,8 +57,7 @@ import org.diylc.core.annotations.KeywordPolicy;
import org.diylc.core.measures.Size;
import org.diylc.core.measures.SizeUnit;
import org.diylc.utils.Constants;
import static org.diylc.utils.SwitchUtils.getConnectedTerminals;
import org.diylc.utils.SwitchUtils;
@ComponentDescriptor(name = "Freeway 3X3-03 Toggle", category = "Guitar",
author = "Branislav Stojkovic", description = "Freeway 3X3-03 Toggle Switch",
@@ -76,6 +74,7 @@ public class Freeway3x3_03 extends AbstractTransparentComponent<Void> implements
private static Color PAD_COLOR = COPPER_COLOR;
private static Color LABEL_COLOR = Color.WHITE;
private static Color CASE_COLOR = METAL_COLOR;
private static Color MARKER_COLOR = Color.lightGray;
private static final double[] X_OFFSETS =
new double[] {9, 15, 21, 21, 21, 21, 21, 21, 12, 3, 3, 3, 3, 3, 3};
@@ -92,7 +91,7 @@ public class Freeway3x3_03 extends AbstractTransparentComponent<Void> implements
private Orientation orientation = Orientation.DEFAULT;
private Integer selectedPosition;
private Boolean highlightConnectedTerminals;
private Boolean showMarkers;
private transient SVGDiagram svgDiagram;
private transient List<Shape> pads;
@@ -152,6 +151,8 @@ public class Freeway3x3_03 extends AbstractTransparentComponent<Void> implements
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1f * alpha / MAX_ALPHA));
}
AffineTransform oldTx = new AffineTransform(g2d.getTransform());
if (getOrientation() != Orientation.DEFAULT) {
double theta = orientation.toRadians();
g2d.rotate(theta, x, y);
@@ -181,33 +182,15 @@ public class Freeway3x3_03 extends AbstractTransparentComponent<Void> implements
g2d.setColor(finalBorderColor);
g2d.draw(base);
List<Set<Integer>> connectedTerminals = getConnectedTerminals(this, controlPoints.length);
drawingObserver.startTrackingContinuityArea(true);
for (int i = 0; i < pads.size(); i++) {
int finalI = i;
int groupIndex = IntStream.range(0, connectedTerminals.size())
.filter(j -> connectedTerminals.get(j).contains(finalI))
.findFirst().orElse(-1);
if (groupIndex < 0) {
g2d.setColor(PAD_COLOR);
} else {
g2d.setColor(ISwitch.POLE_COLORS[groupIndex]);
}
g2d.setColor(PAD_COLOR);
g2d.fill(pads.get(i));
}
drawingObserver.stopTrackingContinuityArea();
for (int i = 0; i < pads.size(); i++) {
int finalI = i;
int groupIndex = IntStream.range(0, connectedTerminals.size())
.filter(j -> connectedTerminals.get(j).contains(finalI))
.findFirst().orElse(-1);
if (groupIndex < 0) {
g2d.setColor(PAD_COLOR.darker());
} else {
g2d.setColor(ISwitch.POLE_COLORS[groupIndex].darker());
}
g2d.setColor(PAD_COLOR.darker());
g2d.draw(pads.get(i));
}
@@ -222,6 +205,20 @@ public class Freeway3x3_03 extends AbstractTransparentComponent<Void> implements
g2d.setColor(CASE_COLOR.darker());
g2d.draw(caseShape);
if (getShowMarkers()) {
g2d.setTransform(oldTx);
// g2d.setFont(g2d.getFont().deriveFont(g2d.getFont().getSize() * 0.8f));
String[] markers = SwitchUtils.getSwitchingMarkers(this, this.getControlPointCount(), false);
g2d.setColor(MARKER_COLOR);
for (int i = 0; i < getControlPointCount(); i++) {
if (markers[i] == null)
continue;;
Point2D p = getControlPoint(i);
StringUtils.drawCenteredText(g2d, markers[i], p.getX(), p.getY(), HorizontalAlignment.CENTER, VerticalAlignment.CENTER);
}
}
g2d.setComposite(oldComposite);
}
@@ -450,16 +447,16 @@ public class Freeway3x3_03 extends AbstractTransparentComponent<Void> implements
this.selectedPosition = selectedPosition;
}
@EditableProperty(name = "Highlight Connected")
@EditableProperty(name = "Markers")
public Boolean getShowMarkers() {
if (highlightConnectedTerminals == null) {
highlightConnectedTerminals = false;
if (showMarkers == null) {
showMarkers = false;
}
return highlightConnectedTerminals;
return showMarkers;
}
public void setHighlightConnectedTerminals(Boolean highlightConnectedTerminals) {
this.highlightConnectedTerminals = highlightConnectedTerminals;
public void setShowMarkers(Boolean showMarkers) {
this.showMarkers = showMarkers;
}
@Override
@@ -35,6 +35,7 @@ import java.util.List;
import java.util.Set;
import java.util.stream.IntStream;
import com.kitfox.svg.A;
import org.diylc.appframework.miscutils.ConfigurationManager;
import org.diylc.awt.StringUtils;
@@ -54,8 +55,6 @@ import org.diylc.core.measures.Size;
import org.diylc.core.measures.SizeUnit;
import org.diylc.utils.Constants;
import static org.diylc.utils.SwitchUtils.getConnectedTerminals;
@ComponentDescriptor(name = "Schaller Megaswitch", category = "Guitar",
author = "Branislav Stojkovic", description = "Several variations of Schaller Megaswitch",
zOrder = IDIYComponent.COMPONENT, instanceNamePrefix = "SW",
@@ -209,9 +208,8 @@ public class SchallerMegaSwitch extends AbstractAngledComponent<String> implemen
public Shape[] getBody() {
if (body == null) {
List<Set<Integer>> connectedTerminals = getConnectedTerminals(this, controlPoints.length);
body = new Shape[3 + connectedTerminals.size()];
body = new Shape[3];
int lastPointIdx =
type == MegaSwitchType.M ? controlPoints.length / 2 - 1 : controlPoints.length - 1;
@@ -252,13 +250,10 @@ public class SchallerMegaSwitch extends AbstractAngledComponent<String> implemen
new Area(new Rectangle2D.Double(waferX, waferY, waferThickness, waferLength));
body[1] = waferArea;
body[2] = new Area();
double theta = getAngle().getValueRad();
for (int i = 0; i <= connectedTerminals.size(); i++) {
body[2 + i] = new Area();
}
for (int i = 0; i < controlPoints.length; i++) {
Point2D point = controlPoints[i];
Area terminal = new Area(new RoundRectangle2D.Double(point.getX() - terminalSize / 2,
@@ -274,12 +269,7 @@ public class SchallerMegaSwitch extends AbstractAngledComponent<String> implemen
terminal.transform(rotation);
}
int finalI = i;
int groupIndex = IntStream.range(0, connectedTerminals.size())
.filter(j -> connectedTerminals.get(j).contains(finalI))
.findFirst().orElse(-1);
((Area)body[3 + groupIndex]).add(terminal);
((Area)body[2]).add(terminal);
}
// Rotate if needed
@@ -304,24 +294,12 @@ public class SchallerMegaSwitch extends AbstractAngledComponent<String> implemen
double terminalWidth = TERMINAL_WIDTH.convertToPixels();
int waferThickness = (int) WAFER_THICKNESS.convertToPixels();
int pointCount = 0;
switch (type) {
case E:
case P:
pointCount = 7;
break;
case E_PLUS:
pointCount = 9;
break;
case S:
case T:
pointCount = 8;
break;
case M:
pointCount = 24;
break;
}
int pointCount = switch (type) {
case E, P -> 7;
case E_PLUS -> 9;
case S, T -> 8;
case M -> 24;
};
controlPoints = new Point2D[pointCount];
if (pointCount < 12) {
@@ -509,35 +487,19 @@ public class SchallerMegaSwitch extends AbstractAngledComponent<String> implemen
@Override
public boolean arePointsConnected(int index1, int index2, int position) {
List<List<int[]>> connections = null;
List<List<int[]>> connections = switch (type) {
case E -> E_CONNECTIONS;
case E_PLUS -> E_PLUS_CONNECTIONS;
case S -> S_CONNECTIONS;
case P -> P_CONNECTIONS;
case T -> T_CONNECTIONS;
case M -> M_CONNECTIONS;
};
switch (type) {
case E:
connections = E_CONNECTIONS;
break;
case E_PLUS:
connections = E_PLUS_CONNECTIONS;
break;
case S:
connections = S_CONNECTIONS;
break;
case P:
connections = P_CONNECTIONS;
break;
case T:
connections = T_CONNECTIONS;
break;
case M:
connections = M_CONNECTIONS;
break;
}
if (connections != null) {
List<int[]> positionConnections = connections.get(position);
for (int[] arr : positionConnections) {
if (arr[0] == index1 && arr[1] == index2) {
return true;
}
List<int[]> positionConnections = connections.get(position);
for (int[] arr : positionConnections) {
if (arr[0] == index1 && arr[1] == index2) {
return true;
}
}
@@ -569,7 +531,7 @@ public class SchallerMegaSwitch extends AbstractAngledComponent<String> implemen
this.body = null;
}
@EditableProperty(name = "Highlight Connected")
@EditableProperty(name = "Markers")
public Boolean getShowMarkers() {
if (showMarkers == null) {
showMarkers = false;
@@ -579,7 +541,6 @@ public class SchallerMegaSwitch extends AbstractAngledComponent<String> implemen
public void setShowMarkers(Boolean showMarkers) {
this.showMarkers = showMarkers;
this.body = null;
}
private static final List<List<int[]>> E_CONNECTIONS = Arrays.asList(