diff --git a/diylc/diylc-library/lib/diylc-core.jar b/diylc/diylc-library/lib/diylc-core.jar index 723dd0f6..cdeba84a 100644 Binary files a/diylc/diylc-library/lib/diylc-core.jar and b/diylc/diylc-library/lib/diylc-core.jar differ diff --git a/diylc/diylc-library/src/org/diylc/components/electromechanical/OpenJack1_4.java b/diylc/diylc-library/src/org/diylc/components/electromechanical/OpenJack1_4.java index d8065533..f59e506c 100644 --- a/diylc/diylc-library/src/org/diylc/components/electromechanical/OpenJack1_4.java +++ b/diylc/diylc-library/src/org/diylc/components/electromechanical/OpenJack1_4.java @@ -57,7 +57,7 @@ import org.diylc.utils.Constants; public class OpenJack1_4 extends AbstractMultiPartComponent { private static final double RING_THETA = Math.PI * 0.795; - private static final double SLEEVE_THETA = Math.PI * 0.295; + private static final double SLEEVE_THETA = Math.PI * 0.29444444444; private static final double SLEEVE_SWITCHED_THETA = Math.PI * 4 / 3; private static final double SWITCH_THETA = Math.PI * 5 / 3; @@ -76,8 +76,10 @@ public class OpenJack1_4 extends AbstractMultiPartComponent { private String value = ""; private Point[] controlPoints = new Point[] {new Point(0, 0), new Point(0, 0), new Point(0, 0)}; - transient Area[] body; - private Orientation orientation = Orientation.DEFAULT; + transient Area[] body; + @Deprecated + private Orientation orientation = Orientation.DEFAULT; + private Integer angle = 0; private OpenJackType type = OpenJackType.MONO; private boolean showLabels = true; @@ -86,7 +88,6 @@ public class OpenJack1_4 extends AbstractMultiPartComponent { updateControlPoints(); } - @SuppressWarnings("incomplete-switch") @Override public void draw(Graphics2D g2d, ComponentState componentState, boolean outlineMode, Project project, IDrawingObserver drawingObserver) { @@ -162,24 +163,9 @@ public class OpenJack1_4 extends AbstractMultiPartComponent { Point sleeveLabel = new Point(0, 0); ringTransform.transform(tipLabel, ringOrSwitchLabel); sleeveTransform.transform(tipLabel, sleeveLabel); - double theta = 0; - // Rotate if needed - if (orientation != Orientation.DEFAULT) { - switch (orientation) { - case _90: - theta = Math.PI / 2; - break; - case _180: - theta = Math.PI; - break; - case _270: - theta = Math.PI * 3 / 2; - break; - } - } - if (theta != 0) { - AffineTransform rotation = AffineTransform.getRotateInstance(theta, controlPoints[0].x, controlPoints[0].y); + if (getTheta() != 0) { + AffineTransform rotation = AffineTransform.getRotateInstance(getTheta(), controlPoints[0].x, controlPoints[0].y); rotation.transform(tipLabel, tipLabel); rotation.transform(ringOrSwitchLabel, ringOrSwitchLabel); rotation.transform(sleeveLabel, sleeveLabel); @@ -195,7 +181,6 @@ public class OpenJack1_4 extends AbstractMultiPartComponent { drawSelectionOutline(g2d, componentState, outlineMode, project, drawingObserver); } - @SuppressWarnings("incomplete-switch") public Area[] getBody() { if (body == null) { body = new Area[4]; @@ -255,25 +240,9 @@ public class OpenJack1_4 extends AbstractMultiPartComponent { body[3] = ringOrSwitch; } - double theta = 0; // Rotate if needed - if (orientation != Orientation.DEFAULT) { - switch (orientation) { - case _90: - theta = Math.PI / 2; - break; - case _180: - theta = Math.PI; - break; - case _270: - theta = Math.PI * 3 / 2; - break; - } - } - - // Rotate if needed - if (theta != 0) { - AffineTransform rotation = AffineTransform.getRotateInstance(theta, x, y); + if (getTheta() != 0) { + AffineTransform rotation = AffineTransform.getRotateInstance(getTheta(), x, y); // Skip the last one because it's already rotated for (int i = 0; i < body.length; i++) { Shape shape = body[i]; @@ -288,7 +257,6 @@ public class OpenJack1_4 extends AbstractMultiPartComponent { return body; } - @SuppressWarnings("incomplete-switch") private void updateControlPoints() { int x = controlPoints[0].x; int y = controlPoints[0].y; @@ -302,20 +270,8 @@ public class OpenJack1_4 extends AbstractMultiPartComponent { AffineTransform.getRotateInstance(getType() == OpenJackType.SWITCHED ? SWITCH_THETA : RING_THETA, x, centerY).transform(controlPoints[0], controlPoints[2]); // Rotate if needed - if (orientation != Orientation.DEFAULT) { - double theta = 0; - switch (orientation) { - case _90: - theta = Math.PI / 2; - break; - case _180: - theta = Math.PI; - break; - case _270: - theta = Math.PI * 3 / 2; - break; - } - AffineTransform rotation = AffineTransform.getRotateInstance(theta, x, y); + if (getTheta() != 0) { + AffineTransform rotation = AffineTransform.getRotateInstance(getTheta(), x, y); for (Point point : controlPoints) { rotation.transform(point, point); } @@ -386,17 +342,27 @@ public class OpenJack1_4 extends AbstractMultiPartComponent { public void setValue(String value) { this.value = value; } - + @EditableProperty - public Orientation getOrientation() { - return orientation; - } - - public void setOrientation(Orientation orientation) { - this.orientation = orientation; - updateControlPoints(); - // Invalidate the body - body = null; + public Integer getAngle() { + if (angle == null) { + if (orientation != null) + angle = Integer.parseInt(orientation.name().replace("_", "")); + else + angle = 0; + } + return angle; + } + + public void setAngle(Integer angle) { + this.angle = angle; + updateControlPoints(); + // Invalidate the body + body = null; + } + + protected double getTheta() { + return Math.toRadians(getAngle()); } @EditableProperty diff --git a/diylc/diylc-library/src/org/diylc/components/electromechanical/PilotLampHolder.java b/diylc/diylc-library/src/org/diylc/components/electromechanical/PilotLampHolder.java index 206d6194..51c0a010 100644 --- a/diylc/diylc-library/src/org/diylc/components/electromechanical/PilotLampHolder.java +++ b/diylc/diylc-library/src/org/diylc/components/electromechanical/PilotLampHolder.java @@ -59,7 +59,9 @@ public class PilotLampHolder extends AbstractMultiPartComponent { private static final long serialVersionUID = 1L; 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 final double SLEEVE_THETA = Math.PI * 0.29444444444; private static Size THREAD_OUTER_DIAMETER = new Size(11 / 16d, SizeUnit.in); private static Size NUT_DIAMETER = new Size(14 / 16d, SizeUnit.in); @@ -75,8 +77,10 @@ public class PilotLampHolder extends AbstractMultiPartComponent { private String value = ""; private Point[] controlPoints = new Point[] { new Point(0, 0), new Point(0, 0), new Point(0, 0), new Point(0, 0) }; - transient Area[] body; - private Orientation orientation = Orientation.DEFAULT; + transient Area[] body; + @Deprecated + private Orientation orientation = Orientation.DEFAULT; + private Integer angle = 0; public PilotLampHolder() { super(); @@ -154,7 +158,6 @@ public class PilotLampHolder extends AbstractMultiPartComponent { drawSelectionOutline(g2d, componentState, outlineMode, project, drawingObserver); } - @SuppressWarnings("incomplete-switch") public Area[] getBody() { if (body == null) { body = new Area[6]; @@ -191,7 +194,7 @@ public class PilotLampHolder extends AbstractMultiPartComponent { Area sleeve = new Area(new RoundRectangle2D.Double(x - springWidth / 2, y - holeToEdge, springWidth, springLength, springWidth, springWidth)); - sleeve.transform(AffineTransform.getRotateInstance(Math.PI * 0.295, x, centerY)); + sleeve.transform(AffineTransform.getRotateInstance(SLEEVE_THETA, x, centerY)); sleeve.add(new Area(new Ellipse2D.Double(x - ringDiameter / 2, centerY - ringDiameter / 2, ringDiameter, ringDiameter))); sleeve.subtract(new Area(new Ellipse2D.Double(x - innerDiameter / 2, centerY - innerDiameter / 2, innerDiameter, innerDiameter))); @@ -230,26 +233,10 @@ public class PilotLampHolder extends AbstractMultiPartComponent { body[5] = link; nut.subtract(link); - thread.subtract(link); - - double theta = 0; - // Rotate if needed - if (orientation != Orientation.DEFAULT) { - switch (orientation) { - case _90: - theta = Math.PI / 2; - break; - case _180: - theta = Math.PI; - break; - case _270: - theta = Math.PI * 3 / 2; - break; - } - } + thread.subtract(link); - if (theta != 0) { - AffineTransform rotation = AffineTransform.getRotateInstance(theta, x, y); + if (getTheta() != 0) { + AffineTransform rotation = AffineTransform.getRotateInstance(getTheta(), x, y); for (Area area : body) { if (area != null) area.transform(rotation); @@ -264,7 +251,6 @@ public class PilotLampHolder extends AbstractMultiPartComponent { return body; } - @SuppressWarnings("incomplete-switch") private void updateControlPoints() { int x = controlPoints[0].x; int y = controlPoints[0].y; @@ -283,20 +269,8 @@ public class PilotLampHolder extends AbstractMultiPartComponent { rotation.transform(controlPoints[2], controlPoints[3]); // Rotate if needed - if (orientation != Orientation.DEFAULT) { - double theta = 0; - switch (orientation) { - case _90: - theta = Math.PI / 2; - break; - case _180: - theta = Math.PI; - break; - case _270: - theta = Math.PI * 3 / 2; - break; - } - rotation = AffineTransform.getRotateInstance(theta, x, y); + if (getTheta() != 0) { + rotation = AffineTransform.getRotateInstance(getTheta(), x, y); for (Point point : controlPoints) { rotation.transform(point, point); } @@ -412,15 +386,25 @@ public class PilotLampHolder extends AbstractMultiPartComponent { this.value = value; } - @EditableProperty - public Orientation getOrientation() { - return orientation; - } - - public void setOrientation(Orientation orientation) { - this.orientation = orientation; - updateControlPoints(); - // Invalidate the body - body = null; + @EditableProperty + public Integer getAngle() { + if (angle == null) { + if (orientation != null) + angle = Integer.parseInt(orientation.name().replace("_", "")); + else + angle = 0; + } + return angle; + } + + public void setAngle(Integer angle) { + this.angle = angle; + updateControlPoints(); + // Invalidate the body + body = null; + } + + protected double getTheta() { + return Math.toRadians(getAngle()); } } diff --git a/diylc/diylc-swing/lib/diylc-core.jar b/diylc/diylc-swing/lib/diylc-core.jar index 723dd0f6..cdeba84a 100644 Binary files a/diylc/diylc-swing/lib/diylc-core.jar and b/diylc/diylc-swing/lib/diylc-core.jar differ diff --git a/diylc/diylc-swing/library/main.jar b/diylc/diylc-swing/library/main.jar index f3358e68..1bf6c60f 100644 Binary files a/diylc/diylc-swing/library/main.jar and b/diylc/diylc-swing/library/main.jar differ diff --git a/diylc/diylc-swing/update.xml b/diylc/diylc-swing/update.xml index b00f5e6c..9e7f6753 100644 --- a/diylc/diylc-swing/update.xml +++ b/diylc/diylc-swing/update.xml @@ -2590,6 +2590,10 @@ NEW_FEATURE Added pinout property to all transistor components + + NEW_FEATURE + Ability to enter arbitrary angle of rotation for "Open 1/4" Jack" and "Pilot Lamp Holder" + IMPROVEMENT When in "Highlight Connected Area" mode, the status bar shows useful information making it harder to forget what the mode does