mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-07 12:24:58 +10:00
Ability to rotate 'Lever Switch' and 'Schaller Megaswitch' by any angle
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
|
||||
DIY Layout Creator (DIYLC).
|
||||
Copyright (c) 2009-2018 held jointly by the individual authors.
|
||||
|
||||
This file is part of DIYLC.
|
||||
|
||||
DIYLC is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
DIYLC is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with DIYLC. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
*/
|
||||
package org.diylc.components;
|
||||
|
||||
import java.awt.Shape;
|
||||
import org.diylc.common.Orientation;
|
||||
import org.diylc.core.Angle;
|
||||
import org.diylc.core.annotations.EditableProperty;
|
||||
|
||||
public abstract class AbstractAngledComponent<T> extends AbstractTransparentComponent<T> {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Deprecated
|
||||
protected transient Orientation orientation;
|
||||
protected int angle;
|
||||
|
||||
transient protected Shape[] body;
|
||||
|
||||
protected abstract void updateControlPoints();
|
||||
|
||||
@EditableProperty
|
||||
@SuppressWarnings("incomplete-switch")
|
||||
public Angle getAngle() {
|
||||
if (orientation != null) {
|
||||
switch (orientation) {
|
||||
case _90:
|
||||
angle = 90;
|
||||
break;
|
||||
case _180:
|
||||
angle = 180;
|
||||
break;
|
||||
case _270:
|
||||
angle = 270;
|
||||
break;
|
||||
}
|
||||
orientation = null;
|
||||
}
|
||||
return Angle.of(angle);
|
||||
}
|
||||
|
||||
public void setAngle(Angle angle) {
|
||||
this.angle = angle.getValue();
|
||||
updateControlPoints();
|
||||
// Reset body shape
|
||||
body = null;
|
||||
}
|
||||
}
|
||||
@@ -46,7 +46,17 @@ public class Angle {
|
||||
private static Map<Integer, Angle> valueCache = new HashMap<Integer, Angle>();
|
||||
|
||||
public synchronized static Angle of(int angle) {
|
||||
valueCache.computeIfAbsent(angle, (value) -> new Angle(value));
|
||||
return valueCache.get(angle);
|
||||
int newValue = angle;
|
||||
while (newValue < 0)
|
||||
newValue += 360;
|
||||
while (newValue >= 360)
|
||||
newValue -= 360;
|
||||
valueCache.computeIfAbsent(newValue, (value) -> new Angle(value));
|
||||
return valueCache.get(newValue);
|
||||
}
|
||||
|
||||
public Angle rotate(int direction) {
|
||||
int newValue = value + direction * 90;
|
||||
return Angle.of(newValue);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,6 +38,7 @@ import org.diylc.common.IPlugInPort;
|
||||
import org.diylc.common.Orientation;
|
||||
import org.diylc.common.OrientationHV;
|
||||
import org.diylc.common.PropertyWrapper;
|
||||
import org.diylc.core.Angle;
|
||||
import org.diylc.core.CreationMethod;
|
||||
import org.diylc.core.IDIYComponent;
|
||||
import org.diylc.core.Project;
|
||||
@@ -432,12 +433,10 @@ public class InstantiationManager {
|
||||
} else if (value instanceof OrientationHV) {
|
||||
angleProperty.setValue(OrientationHV.values()[(((OrientationHV) value).ordinal() + 1)
|
||||
% OrientationHV.values().length]);
|
||||
} else if (angleProperty.getName().equalsIgnoreCase("angle")) {
|
||||
int angle = (Integer) angleProperty.getValue();
|
||||
angle += 90;
|
||||
if (angle >= 360)
|
||||
angle -= 360;
|
||||
angleProperty.setValue(angle);
|
||||
} else if (value instanceof Angle) {
|
||||
Angle angle = (Angle) angleProperty.getValue();
|
||||
Angle newAngle = angle.rotate(1);
|
||||
angleProperty.setValue(newAngle);
|
||||
}
|
||||
angleProperty.writeTo(component);
|
||||
}
|
||||
|
||||
@@ -4010,6 +4010,10 @@
|
||||
<changeType>NEW_FEATURE</changeType>
|
||||
<description>Added 'DP4T (6-Position Oak Grigsby)' as a new type of Lever Switch component</description>
|
||||
</org.diylc.appframework.update.Change>
|
||||
<org.diylc.appframework.update.Change>
|
||||
<changeType>NEW_FEATURE</changeType>
|
||||
<description>Ability to rotate 'Lever Switch' and 'Schaller Megaswitch' by any angle</description>
|
||||
</org.diylc.appframework.update.Change>
|
||||
<org.diylc.appframework.update.Change>
|
||||
<changeType>IMPROVEMENT</changeType>
|
||||
<description>Ability to rotate all guitar/bass pickups through the 'Transform Selection' feature or keyboard shortcut</description>
|
||||
|
||||
Binary file not shown.
@@ -37,8 +37,8 @@ import java.util.List;
|
||||
import org.diylc.appframework.miscutils.ConfigurationManager;
|
||||
import org.diylc.common.IPlugInPort;
|
||||
import org.diylc.common.ObjectCache;
|
||||
import org.diylc.common.Orientation;
|
||||
import org.diylc.components.AbstractTransparentComponent;
|
||||
import org.diylc.components.AbstractAngledComponent;
|
||||
import org.diylc.components.transform.AngledComponentTransformer;
|
||||
import org.diylc.core.ComponentState;
|
||||
import org.diylc.core.IDIYComponent;
|
||||
import org.diylc.core.IDrawingObserver;
|
||||
@@ -56,8 +56,8 @@ import org.diylc.utils.Constants;
|
||||
@ComponentDescriptor(name = "Lever Switch", category = "Guitar", author = "Branislav Stojkovic",
|
||||
description = "Strat-style lever switch", zOrder = IDIYComponent.COMPONENT,
|
||||
instanceNamePrefix = "SW", keywordPolicy = KeywordPolicy.SHOW_TAG,
|
||||
keywordTag = "Guitar Wiring Diagram")
|
||||
public class LeverSwitch extends AbstractTransparentComponent<String> implements ISwitch {
|
||||
keywordTag = "Guitar Wiring Diagram", transformer = AngledComponentTransformer.class)
|
||||
public class LeverSwitch extends AbstractAngledComponent<String> implements ISwitch {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@@ -79,8 +79,6 @@ public class LeverSwitch extends AbstractTransparentComponent<String> implements
|
||||
|
||||
private String value = "";
|
||||
private Point2D[] controlPoints = new Point2D[] {new Point2D.Double(0, 0)};
|
||||
transient Shape[] body;
|
||||
private Orientation orientation = Orientation.DEFAULT;
|
||||
private LeverSwitchType type = LeverSwitchType.DP3T;
|
||||
private Boolean highlightCommon;
|
||||
|
||||
@@ -205,21 +203,7 @@ public class LeverSwitch extends AbstractTransparentComponent<String> implements
|
||||
}
|
||||
body[1] = waferArea;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
double theta = Math.toRadians(getAngle().getValue());
|
||||
|
||||
Area terminalArea = new Area();
|
||||
Area commonTerminalArea = new Area();
|
||||
@@ -264,7 +248,7 @@ public class LeverSwitch extends AbstractTransparentComponent<String> implements
|
||||
}
|
||||
|
||||
@SuppressWarnings("incomplete-switch")
|
||||
private void updateControlPoints() {
|
||||
protected void updateControlPoints() {
|
||||
double x = controlPoints[0].getX();
|
||||
double y = controlPoints[0].getY();
|
||||
int waferSpacing = (int) WAFER_SPACING.convertToPixels();
|
||||
@@ -314,19 +298,8 @@ public class LeverSwitch extends AbstractTransparentComponent<String> implements
|
||||
}
|
||||
|
||||
// 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;
|
||||
}
|
||||
if (getAngle().getValue() != 0) {
|
||||
double theta = Math.toRadians(getAngle().getValue());
|
||||
AffineTransform rotation = AffineTransform.getRotateInstance(theta, x, y);
|
||||
for (Point2D point : controlPoints) {
|
||||
rotation.transform(point, point);
|
||||
@@ -403,11 +376,6 @@ public class LeverSwitch extends AbstractTransparentComponent<String> implements
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@EditableProperty
|
||||
public Orientation getOrientation() {
|
||||
return orientation;
|
||||
}
|
||||
|
||||
@EditableProperty
|
||||
public LeverSwitchType getType() {
|
||||
return type;
|
||||
@@ -418,13 +386,6 @@ public class LeverSwitch extends AbstractTransparentComponent<String> implements
|
||||
updateControlPoints();
|
||||
// Invalidate body
|
||||
this.body = null;
|
||||
}
|
||||
|
||||
public void setOrientation(Orientation orientation) {
|
||||
this.orientation = orientation;
|
||||
updateControlPoints();
|
||||
// Invalidate the body
|
||||
body = null;
|
||||
}
|
||||
|
||||
@EditableProperty(name = "Mark Common Lugs")
|
||||
|
||||
@@ -37,9 +37,10 @@ import org.diylc.awt.StringUtils;
|
||||
import org.diylc.common.HorizontalAlignment;
|
||||
import org.diylc.common.IPlugInPort;
|
||||
import org.diylc.common.ObjectCache;
|
||||
import org.diylc.common.Orientation;
|
||||
import org.diylc.common.VerticalAlignment;
|
||||
import org.diylc.components.AbstractTransparentComponent;
|
||||
import org.diylc.components.AbstractAngledComponent;
|
||||
import org.diylc.components.transform.AngledComponentTransformer;
|
||||
import org.diylc.core.Angle;
|
||||
import org.diylc.core.ComponentState;
|
||||
import org.diylc.core.IDIYComponent;
|
||||
import org.diylc.core.IDrawingObserver;
|
||||
@@ -58,8 +59,8 @@ import org.diylc.utils.Constants;
|
||||
@ComponentDescriptor(name = "Schaller Megaswitch", category = "Guitar",
|
||||
author = "Branislav Stojkovic", description = "Several variations of Schaller Megaswitch",
|
||||
zOrder = IDIYComponent.COMPONENT, instanceNamePrefix = "SW",
|
||||
keywordPolicy = KeywordPolicy.SHOW_TAG, keywordTag = "Guitar Wiring Diagram")
|
||||
public class SchallerMegaSwitch extends AbstractTransparentComponent<String> implements ISwitch {
|
||||
keywordPolicy = KeywordPolicy.SHOW_TAG, keywordTag = "Guitar Wiring Diagram", transformer = AngledComponentTransformer.class)
|
||||
public class SchallerMegaSwitch extends AbstractAngledComponent<String> implements ISwitch {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@@ -82,8 +83,6 @@ public class SchallerMegaSwitch extends AbstractTransparentComponent<String> imp
|
||||
|
||||
private String value = "";
|
||||
private Point2D[] controlPoints = new Point2D[] {new Point2D.Double(0, 0)};
|
||||
transient Shape[] body;
|
||||
private Orientation orientation = Orientation.DEFAULT;
|
||||
private MegaSwitchType type = MegaSwitchType.E;
|
||||
private Color labelColor = Color.gray;
|
||||
|
||||
@@ -189,26 +188,21 @@ public class SchallerMegaSwitch extends AbstractTransparentComponent<String> imp
|
||||
double y =
|
||||
(controlPoints[0].getY() + controlPoints[lastPointIdx].getY()) / 2 + getLabelDy() * 2.25;
|
||||
|
||||
double theta = 0;
|
||||
switch (orientation) {
|
||||
case DEFAULT:
|
||||
case _180:
|
||||
theta = -Math.PI / 2;
|
||||
break;
|
||||
case _90:
|
||||
case _270:
|
||||
theta = 0;
|
||||
break;
|
||||
double theta = Math.toRadians(getAngle().getValue()) - Math.PI / 2;
|
||||
|
||||
if ((theta >= Math.PI / 2 && theta <= Math.PI) || (theta < -Math.PI / 2 && theta > -Math.PI)) {
|
||||
theta += Math.PI;
|
||||
}
|
||||
|
||||
g2d.rotate(theta, x, y);
|
||||
if (theta != 0) {
|
||||
g2d.rotate(theta, x, y);
|
||||
}
|
||||
|
||||
g2d.setFont(project.getFont().deriveFont((float) (project.getFont().getSize2D() * 1.25)));
|
||||
StringUtils.drawCenteredText(g2d, "Schaller Megaswitch® " + type.toString(), x, y,
|
||||
HorizontalAlignment.CENTER, VerticalAlignment.CENTER);
|
||||
}
|
||||
|
||||
@SuppressWarnings("incomplete-switch")
|
||||
public Shape[] getBody() {
|
||||
if (body == null) {
|
||||
body = new Shape[4];
|
||||
@@ -254,21 +248,7 @@ public class SchallerMegaSwitch extends AbstractTransparentComponent<String> imp
|
||||
|
||||
body[1] = waferArea;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
double theta = Math.toRadians(getAngle().getValue());
|
||||
|
||||
Area terminalArea = new Area();
|
||||
for (int i = 0; i < controlPoints.length; i++) {
|
||||
@@ -280,6 +260,12 @@ public class SchallerMegaSwitch extends AbstractTransparentComponent<String> imp
|
||||
point.getY() - terminalSize / 4, terminalSize / 2, terminalSize / 2, terminalSize / 2,
|
||||
terminalSize / 2)));
|
||||
|
||||
if (theta != 0) {
|
||||
// Skip the last two because terminals are already rotated
|
||||
AffineTransform rotation = AffineTransform.getRotateInstance(theta, point.getX(), point.getY());
|
||||
terminal.transform(rotation);
|
||||
}
|
||||
|
||||
terminalArea.add(terminal);
|
||||
}
|
||||
body[2] = terminalArea;
|
||||
@@ -299,7 +285,7 @@ public class SchallerMegaSwitch extends AbstractTransparentComponent<String> imp
|
||||
}
|
||||
|
||||
@SuppressWarnings("incomplete-switch")
|
||||
private void updateControlPoints() {
|
||||
protected void updateControlPoints() {
|
||||
double x = controlPoints[0].getX();
|
||||
double y = controlPoints[0].getY();
|
||||
double terminalSpacing = TERMINAL_SPACING.convertToPixels();
|
||||
@@ -340,46 +326,26 @@ public class SchallerMegaSwitch extends AbstractTransparentComponent<String> imp
|
||||
}
|
||||
|
||||
// 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;
|
||||
}
|
||||
if (getAngle().getValue() != 0) {
|
||||
double theta = Math.toRadians(getAngle().getValue());
|
||||
AffineTransform rotation = AffineTransform.getRotateInstance(theta, x, y);
|
||||
for (Point2D point : controlPoints) {
|
||||
rotation.transform(point, point);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAngle(Angle angle) {
|
||||
super.setAngle(angle);
|
||||
updateLabelPositions();
|
||||
}
|
||||
|
||||
private void updateLabelPositions() {
|
||||
double labelOffset = LABEL_OFFSET.convertToPixels();
|
||||
switch (orientation) {
|
||||
case DEFAULT:
|
||||
labelDx = -labelOffset;
|
||||
labelDy = 0d;
|
||||
break;
|
||||
case _90:
|
||||
labelDx = 0d;
|
||||
labelDy = -labelOffset;
|
||||
break;
|
||||
case _180:
|
||||
labelDx = labelOffset;
|
||||
labelDy = 0d;
|
||||
break;
|
||||
case _270:
|
||||
labelDx = 0d;
|
||||
labelDy = labelOffset;
|
||||
break;
|
||||
}
|
||||
double theta = Math.toRadians(getAngle().getValue()) - Math.PI;
|
||||
labelDx = Math.cos(theta) * labelOffset;
|
||||
labelDy = Math.sin(theta) * labelOffset;
|
||||
}
|
||||
|
||||
private double getLabelDx() {
|
||||
@@ -477,11 +443,6 @@ public class SchallerMegaSwitch extends AbstractTransparentComponent<String> imp
|
||||
this.labelColor = labelColor;
|
||||
}
|
||||
|
||||
@EditableProperty
|
||||
public Orientation getOrientation() {
|
||||
return orientation;
|
||||
}
|
||||
|
||||
@EditableProperty
|
||||
public MegaSwitchType getType() {
|
||||
return type;
|
||||
@@ -494,14 +455,6 @@ public class SchallerMegaSwitch extends AbstractTransparentComponent<String> imp
|
||||
this.body = null;
|
||||
}
|
||||
|
||||
public void setOrientation(Orientation orientation) {
|
||||
this.orientation = orientation;
|
||||
updateControlPoints();
|
||||
updateLabelPositions();
|
||||
// Invalidate the body
|
||||
body = null;
|
||||
}
|
||||
|
||||
public enum MegaSwitchType {
|
||||
E("E"), E_PLUS("E+"), M("M"), P("P"), S("S"), T("T");
|
||||
|
||||
|
||||
+7
-7
@@ -24,15 +24,15 @@ package org.diylc.components.transform;
|
||||
import java.awt.geom.AffineTransform;
|
||||
import java.awt.geom.Point2D;
|
||||
import org.diylc.common.IComponentTransformer;
|
||||
import org.diylc.components.tube.Jumbo4PinTubeSocket;
|
||||
import org.diylc.components.AbstractAngledComponent;
|
||||
import org.diylc.core.Angle;
|
||||
import org.diylc.core.IDIYComponent;
|
||||
|
||||
public class JumboTubeSocketTransformer implements IComponentTransformer {
|
||||
public class AngledComponentTransformer implements IComponentTransformer {
|
||||
|
||||
@Override
|
||||
public boolean canRotate(IDIYComponent<?> component) {
|
||||
return Jumbo4PinTubeSocket.class.isAssignableFrom(component.getClass());
|
||||
return AbstractAngledComponent.class.isAssignableFrom(component.getClass());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -54,10 +54,10 @@ public class JumboTubeSocketTransformer implements IComponentTransformer {
|
||||
component.setControlPoint(p, index);
|
||||
}
|
||||
|
||||
Jumbo4PinTubeSocket tube = (Jumbo4PinTubeSocket) component;
|
||||
Angle angle = tube.getAngle();
|
||||
Angle newAngle = Angle.of(angle.getValue() + direction * 90);
|
||||
tube.setAngle(newAngle);
|
||||
AbstractAngledComponent<?> angledComponent = (AbstractAngledComponent<?>) component;
|
||||
Angle angle = angledComponent.getAngle();
|
||||
Angle newAngle = angle.rotate(direction);
|
||||
angledComponent.setAngle(newAngle);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1,66 +0,0 @@
|
||||
/*
|
||||
|
||||
DIY Layout Creator (DIYLC).
|
||||
Copyright (c) 2009-2018 held jointly by the individual authors.
|
||||
|
||||
This file is part of DIYLC.
|
||||
|
||||
DIYLC is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
DIYLC is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with DIYLC. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
*/
|
||||
package org.diylc.components.transform;
|
||||
|
||||
import java.awt.geom.AffineTransform;
|
||||
import java.awt.geom.Point2D;
|
||||
import org.diylc.common.IComponentTransformer;
|
||||
import org.diylc.components.tube.TubeSocket;
|
||||
import org.diylc.core.Angle;
|
||||
import org.diylc.core.IDIYComponent;
|
||||
|
||||
public class TubeSocketTransformer implements IComponentTransformer {
|
||||
|
||||
@Override
|
||||
public boolean canRotate(IDIYComponent<?> component) {
|
||||
return TubeSocket.class.isAssignableFrom(component.getClass());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canMirror(IDIYComponent<?> component) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mirroringChangesCircuit() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void rotate(IDIYComponent<?> component, Point2D center, int direction) {
|
||||
AffineTransform rotate = AffineTransform.getRotateInstance(Math.PI / 2 * direction, center.getX(), center.getY());
|
||||
for (int index = 0; index < component.getControlPointCount(); index++) {
|
||||
Point2D p = new Point2D.Double();
|
||||
rotate.transform(component.getControlPoint(index), p);
|
||||
component.setControlPoint(p, index);
|
||||
}
|
||||
|
||||
TubeSocket tube = (TubeSocket) component;
|
||||
Angle angle = tube.getAngle();
|
||||
Angle newAngle = Angle.of(angle.getValue() + direction * 90);
|
||||
tube.setAngle(newAngle);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mirror(IDIYComponent<?> component, Point2D center, int direction) {
|
||||
}
|
||||
}
|
||||
@@ -34,11 +34,9 @@ import org.diylc.awt.StringUtils;
|
||||
import org.diylc.common.HorizontalAlignment;
|
||||
import org.diylc.common.IPlugInPort;
|
||||
import org.diylc.common.ObjectCache;
|
||||
import org.diylc.common.Orientation;
|
||||
import org.diylc.common.VerticalAlignment;
|
||||
import org.diylc.components.AbstractTransparentComponent;
|
||||
import org.diylc.components.transform.JumboTubeSocketTransformer;
|
||||
import org.diylc.core.Angle;
|
||||
import org.diylc.components.AbstractAngledComponent;
|
||||
import org.diylc.components.transform.AngledComponentTransformer;
|
||||
import org.diylc.core.ComponentState;
|
||||
import org.diylc.core.IDIYComponent;
|
||||
import org.diylc.core.IDrawingObserver;
|
||||
@@ -54,8 +52,8 @@ import org.diylc.utils.Constants;
|
||||
@ComponentDescriptor(name = "4-pin Jumbo Tube Socket", category = "Tubes",
|
||||
author = "Branislav Stojkovic", description = "4-pin Jumbo ceramic tube socket for 211, 805 and 845 tubes",
|
||||
zOrder = IDIYComponent.COMPONENT, instanceNamePrefix = "J", enableCache = true,
|
||||
transformer = JumboTubeSocketTransformer.class)
|
||||
public class Jumbo4PinTubeSocket extends AbstractTransparentComponent<String> {
|
||||
transformer = AngledComponentTransformer.class)
|
||||
public class Jumbo4PinTubeSocket extends AbstractAngledComponent<String> {
|
||||
|
||||
|
||||
private static final Size JUMBO_PIN_SPACING = new Size(98.5d, SizeUnit.mm);
|
||||
@@ -78,10 +76,7 @@ public class Jumbo4PinTubeSocket extends AbstractTransparentComponent<String> {
|
||||
private static String[] electrodeLabels = new String[] {"G", "F", "P", "F"};
|
||||
|
||||
private String type = "";
|
||||
@Deprecated
|
||||
private Orientation orientation;
|
||||
// private Mount mount = Mount.CHASSIS;
|
||||
private int angle;
|
||||
|
||||
private Color color = BODY_COLOR;
|
||||
|
||||
private Color labelColor = LABEL_COLOR;
|
||||
@@ -89,40 +84,11 @@ public class Jumbo4PinTubeSocket extends AbstractTransparentComponent<String> {
|
||||
|
||||
private Point2D[] controlPoints = new Point2D[] {new Point2D.Double(0, 0)};
|
||||
|
||||
transient private Shape[] body;
|
||||
|
||||
public Jumbo4PinTubeSocket() {
|
||||
super();
|
||||
updateControlPoints();
|
||||
}
|
||||
|
||||
@EditableProperty
|
||||
@SuppressWarnings("incomplete-switch")
|
||||
public Angle getAngle() {
|
||||
if (orientation != null) {
|
||||
switch (orientation) {
|
||||
case _90:
|
||||
angle = 90;
|
||||
break;
|
||||
case _180:
|
||||
angle = 180;
|
||||
break;
|
||||
case _270:
|
||||
angle = 270;
|
||||
break;
|
||||
}
|
||||
orientation = null;
|
||||
}
|
||||
return Angle.of(angle);
|
||||
}
|
||||
|
||||
public void setAngle(Angle angle) {
|
||||
this.angle = angle.getValue();
|
||||
updateControlPoints();
|
||||
// Reset body shape
|
||||
body = null;
|
||||
}
|
||||
|
||||
@EditableProperty
|
||||
public Color getColor() {
|
||||
if (color == null) {
|
||||
@@ -135,7 +101,7 @@ public class Jumbo4PinTubeSocket extends AbstractTransparentComponent<String> {
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
private void updateControlPoints() {
|
||||
protected void updateControlPoints() {
|
||||
Point2D firstPoint = controlPoints[0];
|
||||
int pinCount = 4;
|
||||
int pinSpacing = getClosestOdd(JUMBO_PIN_SPACING.convertToPixels());
|
||||
|
||||
@@ -36,11 +36,9 @@ import org.diylc.awt.StringUtils;
|
||||
import org.diylc.common.HorizontalAlignment;
|
||||
import org.diylc.common.IPlugInPort;
|
||||
import org.diylc.common.ObjectCache;
|
||||
import org.diylc.common.Orientation;
|
||||
import org.diylc.common.VerticalAlignment;
|
||||
import org.diylc.components.AbstractTransparentComponent;
|
||||
import org.diylc.components.transform.TubeSocketTransformer;
|
||||
import org.diylc.core.Angle;
|
||||
import org.diylc.components.AbstractAngledComponent;
|
||||
import org.diylc.components.transform.AngledComponentTransformer;
|
||||
import org.diylc.core.ComponentState;
|
||||
import org.diylc.core.IDIYComponent;
|
||||
import org.diylc.core.IDrawingObserver;
|
||||
@@ -57,8 +55,8 @@ import org.diylc.utils.Constants;
|
||||
@ComponentDescriptor(name = "Tube Socket", author = "Branislav Stojkovic", category = "Tubes",
|
||||
instanceNamePrefix = "V", description = "Various types of tube/valve sockets",
|
||||
zOrder = IDIYComponent.COMPONENT, keywordPolicy = KeywordPolicy.SHOW_VALUE, enableCache = true,
|
||||
transformer = TubeSocketTransformer.class)
|
||||
public class TubeSocket extends AbstractTransparentComponent<String> {
|
||||
transformer = AngledComponentTransformer.class)
|
||||
public class TubeSocket extends AbstractAngledComponent<String> {
|
||||
|
||||
private static final Size B9A_PIN_SPACING_CHASSIS = new Size(12.5d, SizeUnit.mm);
|
||||
private static final Size B9A_PIN_SPACING_PCB = new Size(21d, SizeUnit.mm);
|
||||
@@ -90,10 +88,6 @@ public class TubeSocket extends AbstractTransparentComponent<String> {
|
||||
|
||||
private Base base = Base.B9A;
|
||||
private String type = "";
|
||||
@Deprecated
|
||||
private Orientation orientation;
|
||||
// private Mount mount = Mount.CHASSIS;
|
||||
private int angle;
|
||||
private Color color = BODY_COLOR;
|
||||
private String electrodeLabels = null;
|
||||
private Mount mount = Mount.CHASSIS;
|
||||
@@ -101,8 +95,6 @@ public class TubeSocket extends AbstractTransparentComponent<String> {
|
||||
|
||||
private Point2D[] controlPoints = new Point2D[] {new Point2D.Double(0, 0)};
|
||||
|
||||
transient private Shape body;
|
||||
|
||||
public TubeSocket() {
|
||||
super();
|
||||
updateControlPoints();
|
||||
@@ -120,33 +112,6 @@ public class TubeSocket extends AbstractTransparentComponent<String> {
|
||||
body = null;
|
||||
}
|
||||
|
||||
@EditableProperty
|
||||
@SuppressWarnings("incomplete-switch")
|
||||
public Angle getAngle() {
|
||||
if (orientation != null) {
|
||||
switch (orientation) {
|
||||
case _90:
|
||||
angle = 90;
|
||||
break;
|
||||
case _180:
|
||||
angle = 180;
|
||||
break;
|
||||
case _270:
|
||||
angle = 270;
|
||||
break;
|
||||
}
|
||||
orientation = null;
|
||||
}
|
||||
return Angle.of(angle);
|
||||
}
|
||||
|
||||
public void setAngle(Angle angle) {
|
||||
this.angle = angle.getValue();
|
||||
updateControlPoints();
|
||||
// Reset body shape
|
||||
body = null;
|
||||
}
|
||||
|
||||
@EditableProperty
|
||||
public Color getColor() {
|
||||
if (color == null) {
|
||||
@@ -168,7 +133,8 @@ public class TubeSocket extends AbstractTransparentComponent<String> {
|
||||
// this.mount = mount;
|
||||
// }
|
||||
|
||||
private void updateControlPoints() {
|
||||
@Override
|
||||
protected void updateControlPoints() {
|
||||
Point2D firstPoint = controlPoints[0];
|
||||
int pinCount;
|
||||
int pinSpacing;
|
||||
@@ -211,7 +177,7 @@ public class TubeSocket extends AbstractTransparentComponent<String> {
|
||||
}
|
||||
}
|
||||
|
||||
public Shape getBody() {
|
||||
public Shape[] getBody() {
|
||||
if (body == null) {
|
||||
int bodyDiameter;
|
||||
switch (base) {
|
||||
@@ -231,10 +197,10 @@ public class TubeSocket extends AbstractTransparentComponent<String> {
|
||||
throw new RuntimeException("Unexpected base: " + base);
|
||||
}
|
||||
|
||||
body =
|
||||
Ellipse2D baseShape =
|
||||
new Ellipse2D.Double(controlPoints[0].getX() - bodyDiameter / 2, controlPoints[0].getY() - bodyDiameter / 2,
|
||||
bodyDiameter, bodyDiameter);
|
||||
Area bodyArea = new Area(body);
|
||||
Area bodyArea = new Area(baseShape);
|
||||
int holeSize = getClosestOdd(base == Base.B12C ? B12C_HOLE_SIZE.convertToPixels() : HOLE_SIZE.convertToPixels());
|
||||
bodyArea.subtract(new Area(new Ellipse2D.Double(controlPoints[0].getX() - holeSize / 2, controlPoints[0].getY() - holeSize
|
||||
/ 2, holeSize, holeSize)));
|
||||
@@ -260,7 +226,7 @@ public class TubeSocket extends AbstractTransparentComponent<String> {
|
||||
bodyArea.subtract(new Area(new Ellipse2D.Double(controlPoints[0].getX() - cutoutDiameter / 2, controlPoints[0].getY() + bodyDiameter / 2 - cutoutDiameter / 4, cutoutDiameter, cutoutDiameter)));
|
||||
}
|
||||
|
||||
body = bodyArea;
|
||||
body = new Shape[] { bodyArea };
|
||||
}
|
||||
return body;
|
||||
}
|
||||
@@ -272,14 +238,14 @@ public class TubeSocket extends AbstractTransparentComponent<String> {
|
||||
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(1));
|
||||
|
||||
// Draw body
|
||||
Shape body = getBody();
|
||||
Shape[] body = getBody();
|
||||
Composite oldComposite = g2d.getComposite();
|
||||
if (alpha < MAX_ALPHA) {
|
||||
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1f * alpha / MAX_ALPHA));
|
||||
}
|
||||
if (componentState != ComponentState.DRAGGING) {
|
||||
g2d.setColor(outlineMode ? Constants.TRANSPARENT_COLOR : getColor());
|
||||
g2d.fill(body);
|
||||
g2d.fill(body[0]);
|
||||
}
|
||||
g2d.setComposite(oldComposite);
|
||||
Color finalBorderColor;
|
||||
@@ -295,7 +261,7 @@ public class TubeSocket extends AbstractTransparentComponent<String> {
|
||||
: getColor().darker();
|
||||
}
|
||||
g2d.setColor(finalBorderColor);
|
||||
g2d.draw(body);
|
||||
g2d.draw(body[0]);
|
||||
|
||||
drawingObserver.stopTracking();
|
||||
|
||||
@@ -449,7 +415,7 @@ public class TubeSocket extends AbstractTransparentComponent<String> {
|
||||
|
||||
@Override
|
||||
public Rectangle2D getCachingBounds() {
|
||||
Rectangle2D rect = getBody().getBounds2D();
|
||||
Rectangle2D rect = getBody()[0].getBounds2D();
|
||||
int margin = 40; // to catch the pins that are outside the body, if needed
|
||||
return new Rectangle2D.Double(rect.getX() - margin, rect.getY() - margin, rect.getWidth() + 2 * margin, rect.getHeight() + 2 * margin);
|
||||
}
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user