mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-10 17:22:09 +10:00
fix rotation
This commit is contained in:
+1
-3
@@ -65,8 +65,6 @@ import org.diylc.presenter.AreaUtils;
|
|||||||
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 = "Rotary Switch (Open)", author = "Branislav Stojkovic",
|
@ComponentDescriptor(name = "Rotary Switch (Open)", author = "Branislav Stojkovic",
|
||||||
category = "Electro-Mechanical", instanceNamePrefix = "SW",
|
category = "Electro-Mechanical", instanceNamePrefix = "SW",
|
||||||
description = "Open rotary switch in several different switching configurations",
|
description = "Open rotary switch in several different switching configurations",
|
||||||
@@ -403,7 +401,7 @@ public class RotarySwitchOpen extends AbstractAngledComponent<RotarySwitchOpenTy
|
|||||||
String[] switchingMarkers =
|
String[] switchingMarkers =
|
||||||
SwitchUtils.getSwitchingMarkers(this, this.getControlPointCount(), false);
|
SwitchUtils.getSwitchingMarkers(this, this.getControlPointCount(), false);
|
||||||
|
|
||||||
if (showMarkers) {
|
if (getShowMarkers()) {
|
||||||
g2d.setColor(labelColor);
|
g2d.setColor(labelColor);
|
||||||
int innerPinSpacing = getClosestOdd(INNER_PIN_SPACING.convertToPixels());
|
int innerPinSpacing = getClosestOdd(INNER_PIN_SPACING.convertToPixels());
|
||||||
int innerCommonPinSpacing = getClosestOdd(INNER_COMMON_PIN_SPACING.convertToPixels());
|
int innerCommonPinSpacing = getClosestOdd(INNER_COMMON_PIN_SPACING.convertToPixels());
|
||||||
|
|||||||
+43
-23
@@ -35,9 +35,8 @@ import java.util.stream.IntStream;
|
|||||||
|
|
||||||
import org.diylc.appframework.miscutils.ConfigurationManager;
|
import org.diylc.appframework.miscutils.ConfigurationManager;
|
||||||
|
|
||||||
import org.diylc.common.IPlugInPort;
|
import org.diylc.awt.StringUtils;
|
||||||
import org.diylc.common.ObjectCache;
|
import org.diylc.common.*;
|
||||||
import org.diylc.common.OrientationHV;
|
|
||||||
import org.diylc.components.AbstractTransparentComponent;
|
import org.diylc.components.AbstractTransparentComponent;
|
||||||
import org.diylc.components.guitar.Freeway3x4_03SwitchPositionPropertyValueSource;
|
import org.diylc.components.guitar.Freeway3x4_03SwitchPositionPropertyValueSource;
|
||||||
import org.diylc.components.transform.MiniToggleSwitchTransformer;
|
import org.diylc.components.transform.MiniToggleSwitchTransformer;
|
||||||
@@ -56,6 +55,7 @@ import org.diylc.core.gerber.IGerberComponentSimple;
|
|||||||
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;
|
import static org.diylc.utils.SwitchUtils.getConnectedTerminals;
|
||||||
|
|
||||||
@@ -73,12 +73,14 @@ public class SlideSwitch extends AbstractTransparentComponent<SlideSwitchType> i
|
|||||||
private static Size LUG_WIDTH = new Size(0.020d, SizeUnit.in);
|
private static Size LUG_WIDTH = new Size(0.020d, SizeUnit.in);
|
||||||
private static Size LUG_THICKNESS = new Size(0.1d, SizeUnit.in);
|
private static Size LUG_THICKNESS = new Size(0.1d, SizeUnit.in);
|
||||||
private static Size HOLE_DIAMETER = new Size(3d, SizeUnit.mm);
|
private static Size HOLE_DIAMETER = new Size(3d, SizeUnit.mm);
|
||||||
|
private static Size MARKER_OFFSET = new Size(0.05d, SizeUnit.in);
|
||||||
|
|
||||||
private static Color BODY_COLOR = PHENOLIC_DARK_COLOR;
|
private static Color BODY_COLOR = PHENOLIC_DARK_COLOR;
|
||||||
private static Color BORDER_COLOR = Color.gray;
|
private static Color BORDER_COLOR = Color.gray;
|
||||||
public static Color TERMINAL_COLOR = METAL_COLOR;
|
public static Color TERMINAL_COLOR = METAL_COLOR;
|
||||||
public static Color LABEL_COLOR = Color.white;
|
public static Color LABEL_COLOR = Color.white;
|
||||||
public static Color BRACKET_COLOR = Color.lightGray;
|
public static Color BRACKET_COLOR = Color.lightGray;
|
||||||
|
public static Color MARKER_COLOR = Color.lightGray;
|
||||||
|
|
||||||
protected Point2D[] controlPoints = new Point2D[] {new Point2D.Double(0, 0)};
|
protected Point2D[] controlPoints = new Point2D[] {new Point2D.Double(0, 0)};
|
||||||
transient protected Shape[] body;
|
transient protected Shape[] body;
|
||||||
@@ -94,7 +96,7 @@ public class SlideSwitch extends AbstractTransparentComponent<SlideSwitchType> i
|
|||||||
private Boolean showBracket = true;
|
private Boolean showBracket = true;
|
||||||
|
|
||||||
private Integer selectedPosition;
|
private Integer selectedPosition;
|
||||||
private Boolean highlightConnectedTerminals;
|
private Boolean showMarkers;
|
||||||
|
|
||||||
public SlideSwitch() {
|
public SlideSwitch() {
|
||||||
super();
|
super();
|
||||||
@@ -133,9 +135,10 @@ public class SlideSwitch extends AbstractTransparentComponent<SlideSwitchType> i
|
|||||||
firstPoint.getY() + 3 * rowSpacing)};
|
firstPoint.getY() + 3 * rowSpacing)};
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
AffineTransform xform =
|
|
||||||
AffineTransform.getRotateInstance(-Math.PI / 2, firstPoint.getX(), firstPoint.getY());
|
|
||||||
if (getOrientation() == OrientationHV.HORIZONTAL) {
|
if (getOrientation() == OrientationHV.HORIZONTAL) {
|
||||||
|
AffineTransform xform =
|
||||||
|
AffineTransform.getRotateInstance(-Math.PI / 2, firstPoint.getX(), firstPoint.getY());
|
||||||
for (int i = 1; i < controlPoints.length; i++) {
|
for (int i = 1; i < controlPoints.length; i++) {
|
||||||
xform.transform(controlPoints[i], controlPoints[i]);
|
xform.transform(controlPoints[i], controlPoints[i]);
|
||||||
}
|
}
|
||||||
@@ -284,8 +287,6 @@ public class SlideSwitch extends AbstractTransparentComponent<SlideSwitchType> i
|
|||||||
lugHeight = getClosestOdd((int) LUG_THICKNESS.convertToPixels());
|
lugHeight = getClosestOdd((int) LUG_THICKNESS.convertToPixels());
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Set<Integer>> connectedTerminals = getConnectedTerminals(this, controlPoints.length);
|
|
||||||
|
|
||||||
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(1));
|
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(1));
|
||||||
for (int i = 0; i < controlPoints.length; i++) {
|
for (int i = 0; i < controlPoints.length; i++) {
|
||||||
Point2D p = controlPoints[i];
|
Point2D p = controlPoints[i];
|
||||||
@@ -294,15 +295,7 @@ public class SlideSwitch extends AbstractTransparentComponent<SlideSwitchType> i
|
|||||||
g2d.drawRect((int) (p.getX() - lugWidth / 2d), (int) (p.getY() - lugHeight / 2d), lugWidth,
|
g2d.drawRect((int) (p.getX() - lugWidth / 2d), (int) (p.getY() - lugHeight / 2d), lugWidth,
|
||||||
lugHeight);
|
lugHeight);
|
||||||
} else {
|
} else {
|
||||||
int finalI = i;
|
g2d.setColor(TERMINAL_COLOR);
|
||||||
int groupIndex = IntStream.range(0, connectedTerminals.size())
|
|
||||||
.filter(j -> connectedTerminals.get(j).contains(finalI))
|
|
||||||
.findFirst().orElse(-1);
|
|
||||||
if (groupIndex < 0) {
|
|
||||||
g2d.setColor(TERMINAL_COLOR);
|
|
||||||
} else {
|
|
||||||
g2d.setColor(ISwitch.POLE_COLORS[groupIndex]);
|
|
||||||
}
|
|
||||||
g2d.fillRect((int) (p.getX() - lugWidth / 2d), (int) (p.getY() - lugHeight / 2d), lugWidth,
|
g2d.fillRect((int) (p.getX() - lugWidth / 2d), (int) (p.getY() - lugHeight / 2d), lugWidth,
|
||||||
lugHeight);
|
lugHeight);
|
||||||
g2d.setColor(TERMINAL_COLOR.darker());
|
g2d.setColor(TERMINAL_COLOR.darker());
|
||||||
@@ -310,6 +303,33 @@ public class SlideSwitch extends AbstractTransparentComponent<SlideSwitchType> i
|
|||||||
lugHeight);
|
lugHeight);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (getShowMarkers()) {
|
||||||
|
String[] markers =
|
||||||
|
SwitchUtils.getSwitchingMarkers(this, getControlPointCount(), false);
|
||||||
|
|
||||||
|
g2d.setColor(MARKER_COLOR);
|
||||||
|
|
||||||
|
double offset = MARKER_OFFSET.convertToPixels();
|
||||||
|
for (int i = 0; i < getControlPointCount(); i++) {
|
||||||
|
if (markers[i] == null)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
Point2D p = getControlPoint(i);
|
||||||
|
int direction = switchType == SlideSwitchType.SPDT || i < getControlPointCount() / 2 ? 1 : -1;
|
||||||
|
Point2D labelPoint = new Point2D.Double(direction * offset, 0);
|
||||||
|
|
||||||
|
AffineTransform tx = null;
|
||||||
|
if (getOrientation() == OrientationHV.HORIZONTAL) {
|
||||||
|
tx = AffineTransform.getRotateInstance(-Math.PI / 2, 0, 0);
|
||||||
|
}
|
||||||
|
if (tx != null) {
|
||||||
|
tx.transform(labelPoint, labelPoint);
|
||||||
|
}
|
||||||
|
StringUtils.drawCenteredText(g2d, markers[i], p.getX() + labelPoint.getX(), p.getY() + labelPoint.getY(),
|
||||||
|
HorizontalAlignment.CENTER, VerticalAlignment.CENTER);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Shape[] getBody() {
|
public Shape[] getBody() {
|
||||||
@@ -504,16 +524,16 @@ public class SlideSwitch extends AbstractTransparentComponent<SlideSwitchType> i
|
|||||||
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
|
||||||
|
|||||||
@@ -151,21 +151,24 @@ public class LeverSwitch extends AbstractAngledComponent<LeverSwitch.LeverSwitch
|
|||||||
SwitchUtils.getSwitchingMarkers(this, getControlPointCount(), false);
|
SwitchUtils.getSwitchingMarkers(this, getControlPointCount(), false);
|
||||||
double theta = getAngle().getValueRad();
|
double theta = getAngle().getValueRad();
|
||||||
g2d.setColor(MARKER_COLOR);
|
g2d.setColor(MARKER_COLOR);
|
||||||
AffineTransform tx = null;
|
double x = controlPoints[0].getX();
|
||||||
if (theta != 0) {
|
double y = controlPoints[0].getY();
|
||||||
tx = AffineTransform.getRotateInstance(theta, getControlPoint(0).getX(), getControlPoint(0).getY());
|
|
||||||
}
|
|
||||||
double offset = MARKER_OFFSET.convertToPixels();
|
double offset = MARKER_OFFSET.convertToPixels();
|
||||||
for (int i = 0; i < getControlPointCount(); i++) {
|
for (int i = 0; i < getControlPointCount(); i++) {
|
||||||
if (markers[i] == null)
|
if (markers[i] == null)
|
||||||
continue;;
|
continue;
|
||||||
|
|
||||||
Point2D p = getControlPoint(i);
|
Point2D p = getControlPoint(i);
|
||||||
Point2D labelPoint = new Point2D.Double(p.getX() + offset, p.getY());
|
Point2D labelPoint = new Point2D.Double(offset, 0);
|
||||||
|
AffineTransform tx = null;
|
||||||
|
if (theta != 0) {
|
||||||
|
tx = AffineTransform.getRotateInstance(theta);
|
||||||
|
}
|
||||||
if (tx != null) {
|
if (tx != null) {
|
||||||
tx.transform(labelPoint, labelPoint);
|
tx.transform(labelPoint, labelPoint);
|
||||||
}
|
}
|
||||||
StringUtils.drawCenteredText(g2d, markers[i], labelPoint.getX(), labelPoint.getY(),
|
StringUtils.drawCenteredText(g2d, markers[i], p.getX() + labelPoint.getX(), p.getY() + labelPoint.getY(),
|
||||||
HorizontalAlignment.CENTER, VerticalAlignment.CENTER);
|
HorizontalAlignment.CENTER, VerticalAlignment.CENTER);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -253,8 +256,8 @@ public class LeverSwitch extends AbstractAngledComponent<LeverSwitch.LeverSwitch
|
|||||||
// Rotate if needed
|
// Rotate if needed
|
||||||
if (theta != 0) {
|
if (theta != 0) {
|
||||||
AffineTransform rotation = AffineTransform.getRotateInstance(theta, controlPoints[0].getX(), controlPoints[0].getY());
|
AffineTransform rotation = AffineTransform.getRotateInstance(theta, controlPoints[0].getX(), controlPoints[0].getY());
|
||||||
// Skip the last two because terminals are already rotated
|
// Skip the last one because terminals are already rotated
|
||||||
for (int i = 0; i < body.length - 2; i++) {
|
for (int i = 0; i < body.length - 1; i++) {
|
||||||
Shape shape = body[i];
|
Shape shape = body[i];
|
||||||
Area area = (Area) shape;
|
Area area = (Area) shape;
|
||||||
area.transform(rotation);
|
area.transform(rotation);
|
||||||
|
|||||||
Reference in New Issue
Block a user