mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-11 01:32:08 +10:00
switch enhancements
This commit is contained in:
-2
@@ -57,8 +57,6 @@ import org.diylc.core.measures.SizeUnit;
|
|||||||
import org.diylc.utils.Constants;
|
import org.diylc.utils.Constants;
|
||||||
import org.diylc.utils.SwitchUtils;
|
import org.diylc.utils.SwitchUtils;
|
||||||
|
|
||||||
import static org.diylc.utils.SwitchUtils.getConnectedTerminals;
|
|
||||||
|
|
||||||
@ComponentDescriptor(name = "Slide Switch", category = "Electro-Mechanical",
|
@ComponentDescriptor(name = "Slide Switch", category = "Electro-Mechanical",
|
||||||
author = "Branislav Stojkovic", description = "Panel mounted slide switch",
|
author = "Branislav Stojkovic", description = "Panel mounted slide switch",
|
||||||
zOrder = IDIYComponent.COMPONENT, instanceNamePrefix = "SW", autoEdit = false,
|
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.SVGUniverse;
|
||||||
import com.kitfox.svg.ShapeElement;
|
import com.kitfox.svg.ShapeElement;
|
||||||
|
|
||||||
import org.diylc.common.IPlugInPort;
|
import org.diylc.awt.StringUtils;
|
||||||
import org.diylc.common.ObjectCache;
|
import org.diylc.common.*;
|
||||||
import org.diylc.common.Orientation;
|
|
||||||
import org.diylc.components.AbstractTransparentComponent;
|
import org.diylc.components.AbstractTransparentComponent;
|
||||||
import org.diylc.components.transform.Freeway3x3_03Transformer;
|
import org.diylc.components.transform.Freeway3x3_03Transformer;
|
||||||
import org.diylc.core.*;
|
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.Size;
|
||||||
import org.diylc.core.measures.SizeUnit;
|
import org.diylc.core.measures.SizeUnit;
|
||||||
import org.diylc.utils.Constants;
|
import org.diylc.utils.Constants;
|
||||||
|
import org.diylc.utils.SwitchUtils;
|
||||||
import static org.diylc.utils.SwitchUtils.getConnectedTerminals;
|
|
||||||
|
|
||||||
@ComponentDescriptor(name = "Freeway 3X3-03 Toggle", category = "Guitar",
|
@ComponentDescriptor(name = "Freeway 3X3-03 Toggle", category = "Guitar",
|
||||||
author = "Branislav Stojkovic", description = "Freeway 3X3-03 Toggle Switch",
|
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 PAD_COLOR = COPPER_COLOR;
|
||||||
private static Color LABEL_COLOR = Color.WHITE;
|
private static Color LABEL_COLOR = Color.WHITE;
|
||||||
private static Color CASE_COLOR = METAL_COLOR;
|
private static Color CASE_COLOR = METAL_COLOR;
|
||||||
|
private static Color MARKER_COLOR = Color.lightGray;
|
||||||
|
|
||||||
private static final double[] X_OFFSETS =
|
private static final double[] X_OFFSETS =
|
||||||
new double[] {9, 15, 21, 21, 21, 21, 21, 21, 12, 3, 3, 3, 3, 3, 3};
|
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 Orientation orientation = Orientation.DEFAULT;
|
||||||
|
|
||||||
private Integer selectedPosition;
|
private Integer selectedPosition;
|
||||||
private Boolean highlightConnectedTerminals;
|
private Boolean showMarkers;
|
||||||
|
|
||||||
private transient SVGDiagram svgDiagram;
|
private transient SVGDiagram svgDiagram;
|
||||||
private transient List<Shape> pads;
|
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));
|
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1f * alpha / MAX_ALPHA));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
AffineTransform oldTx = new AffineTransform(g2d.getTransform());
|
||||||
|
|
||||||
if (getOrientation() != Orientation.DEFAULT) {
|
if (getOrientation() != Orientation.DEFAULT) {
|
||||||
double theta = orientation.toRadians();
|
double theta = orientation.toRadians();
|
||||||
g2d.rotate(theta, x, y);
|
g2d.rotate(theta, x, y);
|
||||||
@@ -181,33 +182,15 @@ public class Freeway3x3_03 extends AbstractTransparentComponent<Void> implements
|
|||||||
g2d.setColor(finalBorderColor);
|
g2d.setColor(finalBorderColor);
|
||||||
g2d.draw(base);
|
g2d.draw(base);
|
||||||
|
|
||||||
List<Set<Integer>> connectedTerminals = getConnectedTerminals(this, controlPoints.length);
|
|
||||||
|
|
||||||
drawingObserver.startTrackingContinuityArea(true);
|
drawingObserver.startTrackingContinuityArea(true);
|
||||||
for (int i = 0; i < pads.size(); i++) {
|
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);
|
g2d.setColor(PAD_COLOR);
|
||||||
} else {
|
|
||||||
g2d.setColor(ISwitch.POLE_COLORS[groupIndex]);
|
|
||||||
}
|
|
||||||
g2d.fill(pads.get(i));
|
g2d.fill(pads.get(i));
|
||||||
}
|
}
|
||||||
drawingObserver.stopTrackingContinuityArea();
|
drawingObserver.stopTrackingContinuityArea();
|
||||||
|
|
||||||
for (int i = 0; i < pads.size(); i++) {
|
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());
|
g2d.setColor(PAD_COLOR.darker());
|
||||||
} else {
|
|
||||||
g2d.setColor(ISwitch.POLE_COLORS[groupIndex].darker());
|
|
||||||
}
|
|
||||||
g2d.draw(pads.get(i));
|
g2d.draw(pads.get(i));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -222,6 +205,20 @@ public class Freeway3x3_03 extends AbstractTransparentComponent<Void> implements
|
|||||||
g2d.setColor(CASE_COLOR.darker());
|
g2d.setColor(CASE_COLOR.darker());
|
||||||
g2d.draw(caseShape);
|
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);
|
g2d.setComposite(oldComposite);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -450,16 +447,16 @@ public class Freeway3x3_03 extends AbstractTransparentComponent<Void> implements
|
|||||||
this.selectedPosition = selectedPosition;
|
this.selectedPosition = selectedPosition;
|
||||||
}
|
}
|
||||||
|
|
||||||
@EditableProperty(name = "Highlight Connected")
|
@EditableProperty(name = "Markers")
|
||||||
public Boolean getShowMarkers() {
|
public Boolean getShowMarkers() {
|
||||||
if (highlightConnectedTerminals == null) {
|
if (showMarkers == null) {
|
||||||
highlightConnectedTerminals = false;
|
showMarkers = false;
|
||||||
}
|
}
|
||||||
return highlightConnectedTerminals;
|
return showMarkers;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setHighlightConnectedTerminals(Boolean highlightConnectedTerminals) {
|
public void setShowMarkers(Boolean showMarkers) {
|
||||||
this.highlightConnectedTerminals = highlightConnectedTerminals;
|
this.showMarkers = showMarkers;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
+19
-58
@@ -35,6 +35,7 @@ import java.util.List;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.stream.IntStream;
|
import java.util.stream.IntStream;
|
||||||
|
|
||||||
|
import com.kitfox.svg.A;
|
||||||
import org.diylc.appframework.miscutils.ConfigurationManager;
|
import org.diylc.appframework.miscutils.ConfigurationManager;
|
||||||
|
|
||||||
import org.diylc.awt.StringUtils;
|
import org.diylc.awt.StringUtils;
|
||||||
@@ -54,8 +55,6 @@ import org.diylc.core.measures.Size;
|
|||||||
import org.diylc.core.measures.SizeUnit;
|
import org.diylc.core.measures.SizeUnit;
|
||||||
import org.diylc.utils.Constants;
|
import org.diylc.utils.Constants;
|
||||||
|
|
||||||
import static org.diylc.utils.SwitchUtils.getConnectedTerminals;
|
|
||||||
|
|
||||||
@ComponentDescriptor(name = "Schaller Megaswitch", category = "Guitar",
|
@ComponentDescriptor(name = "Schaller Megaswitch", category = "Guitar",
|
||||||
author = "Branislav Stojkovic", description = "Several variations of Schaller Megaswitch",
|
author = "Branislav Stojkovic", description = "Several variations of Schaller Megaswitch",
|
||||||
zOrder = IDIYComponent.COMPONENT, instanceNamePrefix = "SW",
|
zOrder = IDIYComponent.COMPONENT, instanceNamePrefix = "SW",
|
||||||
@@ -209,9 +208,8 @@ public class SchallerMegaSwitch extends AbstractAngledComponent<String> implemen
|
|||||||
|
|
||||||
public Shape[] getBody() {
|
public Shape[] getBody() {
|
||||||
if (body == null) {
|
if (body == null) {
|
||||||
List<Set<Integer>> connectedTerminals = getConnectedTerminals(this, controlPoints.length);
|
|
||||||
|
|
||||||
body = new Shape[3 + connectedTerminals.size()];
|
body = new Shape[3];
|
||||||
|
|
||||||
int lastPointIdx =
|
int lastPointIdx =
|
||||||
type == MegaSwitchType.M ? controlPoints.length / 2 - 1 : controlPoints.length - 1;
|
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));
|
new Area(new Rectangle2D.Double(waferX, waferY, waferThickness, waferLength));
|
||||||
|
|
||||||
body[1] = waferArea;
|
body[1] = waferArea;
|
||||||
|
body[2] = new Area();
|
||||||
|
|
||||||
double theta = getAngle().getValueRad();
|
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++) {
|
for (int i = 0; i < controlPoints.length; i++) {
|
||||||
Point2D point = controlPoints[i];
|
Point2D point = controlPoints[i];
|
||||||
Area terminal = new Area(new RoundRectangle2D.Double(point.getX() - terminalSize / 2,
|
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);
|
terminal.transform(rotation);
|
||||||
}
|
}
|
||||||
|
|
||||||
int finalI = i;
|
((Area)body[2]).add(terminal);
|
||||||
int groupIndex = IntStream.range(0, connectedTerminals.size())
|
|
||||||
.filter(j -> connectedTerminals.get(j).contains(finalI))
|
|
||||||
.findFirst().orElse(-1);
|
|
||||||
|
|
||||||
((Area)body[3 + groupIndex]).add(terminal);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Rotate if needed
|
// Rotate if needed
|
||||||
@@ -304,24 +294,12 @@ public class SchallerMegaSwitch extends AbstractAngledComponent<String> implemen
|
|||||||
double terminalWidth = TERMINAL_WIDTH.convertToPixels();
|
double terminalWidth = TERMINAL_WIDTH.convertToPixels();
|
||||||
int waferThickness = (int) WAFER_THICKNESS.convertToPixels();
|
int waferThickness = (int) WAFER_THICKNESS.convertToPixels();
|
||||||
|
|
||||||
int pointCount = 0;
|
int pointCount = switch (type) {
|
||||||
|
case E, P -> 7;
|
||||||
switch (type) {
|
case E_PLUS -> 9;
|
||||||
case E:
|
case S, T -> 8;
|
||||||
case P:
|
case M -> 24;
|
||||||
pointCount = 7;
|
};
|
||||||
break;
|
|
||||||
case E_PLUS:
|
|
||||||
pointCount = 9;
|
|
||||||
break;
|
|
||||||
case S:
|
|
||||||
case T:
|
|
||||||
pointCount = 8;
|
|
||||||
break;
|
|
||||||
case M:
|
|
||||||
pointCount = 24;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
controlPoints = new Point2D[pointCount];
|
controlPoints = new Point2D[pointCount];
|
||||||
if (pointCount < 12) {
|
if (pointCount < 12) {
|
||||||
@@ -509,37 +487,21 @@ public class SchallerMegaSwitch extends AbstractAngledComponent<String> implemen
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean arePointsConnected(int index1, int index2, int position) {
|
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);
|
List<int[]> positionConnections = connections.get(position);
|
||||||
for (int[] arr : positionConnections) {
|
for (int[] arr : positionConnections) {
|
||||||
if (arr[0] == index1 && arr[1] == index2) {
|
if (arr[0] == index1 && arr[1] == index2) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -569,7 +531,7 @@ public class SchallerMegaSwitch extends AbstractAngledComponent<String> implemen
|
|||||||
this.body = null;
|
this.body = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@EditableProperty(name = "Highlight Connected")
|
@EditableProperty(name = "Markers")
|
||||||
public Boolean getShowMarkers() {
|
public Boolean getShowMarkers() {
|
||||||
if (showMarkers == null) {
|
if (showMarkers == null) {
|
||||||
showMarkers = false;
|
showMarkers = false;
|
||||||
@@ -579,7 +541,6 @@ public class SchallerMegaSwitch extends AbstractAngledComponent<String> implemen
|
|||||||
|
|
||||||
public void setShowMarkers(Boolean showMarkers) {
|
public void setShowMarkers(Boolean showMarkers) {
|
||||||
this.showMarkers = showMarkers;
|
this.showMarkers = showMarkers;
|
||||||
this.body = null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final List<List<int[]>> E_CONNECTIONS = Arrays.asList(
|
private static final List<List<int[]>> E_CONNECTIONS = Arrays.asList(
|
||||||
|
|||||||
Reference in New Issue
Block a user