mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-11 01:32:08 +10:00
show markers for lever switch
This commit is contained in:
@@ -33,12 +33,14 @@ import java.awt.geom.Point2D;
|
|||||||
import java.awt.geom.Rectangle2D;
|
import java.awt.geom.Rectangle2D;
|
||||||
import java.awt.geom.RoundRectangle2D;
|
import java.awt.geom.RoundRectangle2D;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.stream.IntStream;
|
|
||||||
|
|
||||||
import org.diylc.appframework.miscutils.ConfigurationManager;
|
import org.diylc.appframework.miscutils.ConfigurationManager;
|
||||||
|
|
||||||
|
import org.diylc.awt.StringUtils;
|
||||||
|
import org.diylc.common.HorizontalAlignment;
|
||||||
import org.diylc.common.IPlugInPort;
|
import org.diylc.common.IPlugInPort;
|
||||||
import org.diylc.common.ObjectCache;
|
import org.diylc.common.ObjectCache;
|
||||||
|
import org.diylc.common.VerticalAlignment;
|
||||||
import org.diylc.components.AbstractAngledComponent;
|
import org.diylc.components.AbstractAngledComponent;
|
||||||
import org.diylc.components.transform.AngledComponentTransformer;
|
import org.diylc.components.transform.AngledComponentTransformer;
|
||||||
import org.diylc.core.*;
|
import org.diylc.core.*;
|
||||||
@@ -49,8 +51,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 = "Lever Switch", category = "Guitar", author = "Branislav Stojkovic",
|
@ComponentDescriptor(name = "Lever Switch", category = "Guitar", author = "Branislav Stojkovic",
|
||||||
description = "Strat-style lever switch", zOrder = IDIYComponent.COMPONENT,
|
description = "Strat-style lever switch", zOrder = IDIYComponent.COMPONENT,
|
||||||
@@ -63,6 +64,7 @@ public class LeverSwitch extends AbstractAngledComponent<LeverSwitch.LeverSwitch
|
|||||||
private static Color BASE_COLOR = Color.lightGray;
|
private static Color BASE_COLOR = Color.lightGray;
|
||||||
private static Color WAFER_COLOR = Color.decode("#CD8500");
|
private static Color WAFER_COLOR = Color.decode("#CD8500");
|
||||||
private static Color LUG_COLOR = METAL_COLOR;
|
private static Color LUG_COLOR = METAL_COLOR;
|
||||||
|
private static Color MARKER_COLOR = Color.gray;
|
||||||
|
|
||||||
private static Size BASE_WIDTH = new Size(10d, SizeUnit.mm);
|
private static Size BASE_WIDTH = new Size(10d, SizeUnit.mm);
|
||||||
private static Size BASE_LENGTH = new Size(47.5d, SizeUnit.mm);
|
private static Size BASE_LENGTH = new Size(47.5d, SizeUnit.mm);
|
||||||
@@ -74,6 +76,7 @@ public class LeverSwitch extends AbstractAngledComponent<LeverSwitch.LeverSwitch
|
|||||||
private static Size TERMINAL_WIDTH = new Size(2d, SizeUnit.mm);
|
private static Size TERMINAL_WIDTH = new Size(2d, SizeUnit.mm);
|
||||||
private static Size TERMINAL_LENGTH = new Size(0.1d, SizeUnit.in);
|
private static Size TERMINAL_LENGTH = new Size(0.1d, SizeUnit.in);
|
||||||
private static Size TERMINAL_SPACING = new Size(0.1d, SizeUnit.in);
|
private static Size TERMINAL_SPACING = new Size(0.1d, SizeUnit.in);
|
||||||
|
private static Size MARKER_OFFSET = new Size(0.1d, SizeUnit.in);
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
@Deprecated
|
@Deprecated
|
||||||
@@ -142,11 +145,29 @@ public class LeverSwitch extends AbstractAngledComponent<LeverSwitch.LeverSwitch
|
|||||||
g2d.fill(body[2]);
|
g2d.fill(body[2]);
|
||||||
g2d.setColor(LUG_COLOR.darker());
|
g2d.setColor(LUG_COLOR.darker());
|
||||||
g2d.draw(body[2]);
|
g2d.draw(body[2]);
|
||||||
for (int i = 3; i < body.length; i++) {
|
|
||||||
g2d.setColor(ISwitch.POLE_COLORS[i - 3]);
|
if (getShowMarkers()) {
|
||||||
g2d.fill(body[i]);
|
String[] markers =
|
||||||
g2d.setColor(ISwitch.POLE_COLORS[i - 3].darker());
|
SwitchUtils.getSwitchingMarkers(this, getControlPointCount(), false);
|
||||||
g2d.draw(body[i]);
|
double theta = getAngle().getValueRad();
|
||||||
|
g2d.setColor(MARKER_COLOR);
|
||||||
|
AffineTransform tx = null;
|
||||||
|
if (theta != 0) {
|
||||||
|
tx = AffineTransform.getRotateInstance(theta, getControlPoint(0).getX(), getControlPoint(0).getY());
|
||||||
|
}
|
||||||
|
double offset = MARKER_OFFSET.convertToPixels();
|
||||||
|
for (int i = 0; i < getControlPointCount(); i++) {
|
||||||
|
if (markers[i] == null)
|
||||||
|
continue;;
|
||||||
|
|
||||||
|
Point2D p = getControlPoint(i);
|
||||||
|
Point2D labelPoint = new Point2D.Double(p.getX() + offset, p.getY());
|
||||||
|
if (tx != null) {
|
||||||
|
tx.transform(labelPoint, labelPoint);
|
||||||
|
}
|
||||||
|
StringUtils.drawCenteredText(g2d, markers[i], labelPoint.getX(), labelPoint.getY(),
|
||||||
|
HorizontalAlignment.CENTER, VerticalAlignment.CENTER);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// g2d.setColor(Color.black);
|
// g2d.setColor(Color.black);
|
||||||
@@ -208,34 +229,25 @@ public class LeverSwitch extends AbstractAngledComponent<LeverSwitch.LeverSwitch
|
|||||||
|
|
||||||
double theta = getAngle().getValueRad();
|
double theta = getAngle().getValueRad();
|
||||||
|
|
||||||
List<Set<Integer>> connectedTerminals = getConnectedTerminals(this, controlPoints.length);
|
body = new Shape[3];
|
||||||
|
|
||||||
body = new Shape[3 + connectedTerminals.size()];
|
|
||||||
body[0] = baseArea;
|
body[0] = baseArea;
|
||||||
body[1] = waferArea;
|
body[1] = waferArea;
|
||||||
for (int i = 0; i <= connectedTerminals.size(); i++) {
|
body[2] = new Area();
|
||||||
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 =
|
Area terminal =
|
||||||
new Area(new RoundRectangle2D.Double(point.getX() - terminalLength / 2, point.getY() - terminalWidth / 2,
|
new Area(new RoundRectangle2D.Double(point.getX() - terminalLength / 2d, point.getY() - terminalWidth / 2d,
|
||||||
terminalLength, terminalWidth, terminalWidth / 2, terminalWidth / 2));
|
terminalLength, terminalWidth, terminalWidth / 2d, terminalWidth / 2d));
|
||||||
terminal.subtract(new Area(new RoundRectangle2D.Double(point.getX() - terminalLength / 4, point.getY() - terminalWidth
|
terminal.subtract(new Area(new RoundRectangle2D.Double(point.getX() - terminalLength / 4d, point.getY() - terminalWidth
|
||||||
/ 4, terminalLength / 2, terminalWidth / 2, terminalWidth / 2, terminalWidth / 2)));
|
/ 4d, terminalLength / 2d, terminalWidth / 2d, terminalWidth / 2d, terminalWidth / 2d)));
|
||||||
// Rotate the terminal if needed
|
// Rotate the terminal if needed
|
||||||
if (theta != 0) {
|
if (theta != 0) {
|
||||||
AffineTransform rotation = AffineTransform.getRotateInstance(theta, point.getX(), point.getY());
|
AffineTransform rotation = AffineTransform.getRotateInstance(theta, point.getX(), point.getY());
|
||||||
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
|
||||||
|
|||||||
Reference in New Issue
Block a user