mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-11 01:32:08 +10:00
When loaded from an existing file "Potentiometer Symbol" doesn't retain
the specified orientation
This commit is contained in:
@@ -90,6 +90,10 @@ public abstract class Abstract3LegSymbol extends AbstractComponent<String> {
|
||||
|
||||
// Draw transistor
|
||||
|
||||
if (this.body == null) {
|
||||
this.body = getBody();
|
||||
applyOrientation(this.body);
|
||||
}
|
||||
Shape[] body = getBody();
|
||||
|
||||
AffineTransform old = g2d.getTransform();
|
||||
@@ -166,7 +170,7 @@ public abstract class Abstract3LegSymbol extends AbstractComponent<String> {
|
||||
return controlPoints[0].y;
|
||||
}
|
||||
|
||||
private void updateControlPoints() {
|
||||
protected void updateControlPoints() {
|
||||
int pinSpacing = (int) PIN_SPACING.convertToPixels();
|
||||
// Update control points.
|
||||
int x = controlPoints[0].x;
|
||||
@@ -179,6 +183,16 @@ public abstract class Abstract3LegSymbol extends AbstractComponent<String> {
|
||||
|
||||
controlPoints[2].x = x + f * pinSpacing * 2;
|
||||
controlPoints[2].y = y + pinSpacing * 2;
|
||||
|
||||
if (getOrientation() != Orientation.DEFAULT)
|
||||
{
|
||||
Point first = this.controlPoints[0];
|
||||
double angle = Double.parseDouble(getOrientation().name().replace("_", ""));
|
||||
AffineTransform rotate = AffineTransform.getRotateInstance(Math.toRadians(angle), first.x, first.y);
|
||||
for (int i = 1; i < this.controlPoints.length; i++) {
|
||||
rotate.transform(this.controlPoints[i], this.controlPoints[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -206,7 +220,8 @@ public abstract class Abstract3LegSymbol extends AbstractComponent<String> {
|
||||
public void setControlPoint(Point point, int index) {
|
||||
controlPoints[index].setLocation(point);
|
||||
|
||||
refreshDrawing();
|
||||
// make sure we have a new drawing
|
||||
body = null;
|
||||
}
|
||||
|
||||
@EditableProperty
|
||||
@@ -217,7 +232,9 @@ public abstract class Abstract3LegSymbol extends AbstractComponent<String> {
|
||||
public void setFlip(SymbolFlipping flip) {
|
||||
this.flip = flip;
|
||||
|
||||
refreshDrawing();
|
||||
updateControlPoints();
|
||||
// make sure we have a new drawing
|
||||
body = null;
|
||||
}
|
||||
|
||||
@EditableProperty
|
||||
@@ -249,27 +266,22 @@ public abstract class Abstract3LegSymbol extends AbstractComponent<String> {
|
||||
public void setOrientation(Orientation orientation) {
|
||||
this.orientation = orientation;
|
||||
|
||||
refreshDrawing();
|
||||
}
|
||||
|
||||
protected void refreshDrawing() {
|
||||
updateControlPoints();
|
||||
// make sure we have a new drawing
|
||||
body = null;
|
||||
getBody();
|
||||
}
|
||||
|
||||
protected void applyOrientation(Shape[] body) {
|
||||
if (getOrientation() == Orientation.DEFAULT)
|
||||
return;
|
||||
|
||||
Point first = this.controlPoints[0];
|
||||
double angle = Double.parseDouble(getOrientation().name().replace("_", ""));
|
||||
AffineTransform rotate = AffineTransform.getRotateInstance(Math.toRadians(angle), first.x, first.y);
|
||||
for (int i = 1; i < this.controlPoints.length; i++) {
|
||||
rotate.transform(this.controlPoints[i], this.controlPoints[i]);
|
||||
}
|
||||
if (this.body != null) {
|
||||
for (int i = 0; i < this.body.length; i++) {
|
||||
this.body[i] = rotate.createTransformedShape(this.body[i]);
|
||||
|
||||
if (body != null) {
|
||||
for (int i = 0; i < body.length; i++) {
|
||||
body[i] = rotate.createTransformedShape(body[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,49 +45,48 @@ public class BJTSymbol extends Abstract3LegSymbol {
|
||||
protected BJTPolarity polarity = BJTPolarity.NPN;
|
||||
|
||||
public Shape[] getBody() {
|
||||
if (body == null) {
|
||||
body = new Shape[3];
|
||||
int x = controlPoints[0].x;
|
||||
int y = controlPoints[0].y;
|
||||
int pinSpacing = (int) PIN_SPACING.convertToPixels();
|
||||
Shape[] body = new Shape[3];
|
||||
int x = controlPoints[0].x;
|
||||
int y = controlPoints[0].y;
|
||||
int pinSpacing = (int) PIN_SPACING.convertToPixels();
|
||||
|
||||
GeneralPath polyline = new GeneralPath();
|
||||
GeneralPath polyline = new GeneralPath();
|
||||
|
||||
polyline.moveTo(x + pinSpacing / 2, y - pinSpacing);
|
||||
polyline.lineTo(x + pinSpacing / 2, y + pinSpacing);
|
||||
polyline.moveTo(x + pinSpacing / 2, y - pinSpacing);
|
||||
polyline.lineTo(x + pinSpacing / 2, y + pinSpacing);
|
||||
|
||||
body[0] = polyline;
|
||||
body[0] = polyline;
|
||||
|
||||
polyline = new GeneralPath();
|
||||
polyline = new GeneralPath();
|
||||
|
||||
polyline.moveTo(x, y);
|
||||
polyline.lineTo(x + pinSpacing / 2, y);
|
||||
polyline.moveTo(x + pinSpacing / 2, y - pinSpacing / 2);
|
||||
polyline.lineTo(x + pinSpacing * 2, y - pinSpacing);
|
||||
polyline.lineTo(x + pinSpacing * 2, y - pinSpacing * 2);
|
||||
polyline.moveTo(x + pinSpacing / 2, y + pinSpacing / 2);
|
||||
polyline.lineTo(x + pinSpacing * 2, y + pinSpacing);
|
||||
polyline.lineTo(x + pinSpacing * 2, y + pinSpacing * 2);
|
||||
body[1] = polyline;
|
||||
polyline.moveTo(x, y);
|
||||
polyline.lineTo(x + pinSpacing / 2, y);
|
||||
polyline.moveTo(x + pinSpacing / 2, y - pinSpacing / 2);
|
||||
polyline.lineTo(x + pinSpacing * 2, y - pinSpacing);
|
||||
polyline.lineTo(x + pinSpacing * 2, y - pinSpacing * 2);
|
||||
polyline.moveTo(x + pinSpacing / 2, y + pinSpacing / 2);
|
||||
polyline.lineTo(x + pinSpacing * 2, y + pinSpacing);
|
||||
polyline.lineTo(x + pinSpacing * 2, y + pinSpacing * 2);
|
||||
body[1] = polyline;
|
||||
|
||||
Area arrow;
|
||||
double theta;
|
||||
if (polarity == BJTPolarity.NPN) {
|
||||
theta = Math.atan(1.0 / 3);
|
||||
arrow =
|
||||
new Area(new Polygon(new int[] {x + pinSpacing, x + pinSpacing, x + pinSpacing * 10 / 6}, new int[] {
|
||||
y - pinSpacing / 5 + pinSpacing / 2, y + pinSpacing / 5 + pinSpacing / 2, y + pinSpacing / 2}, 3));
|
||||
arrow.transform(AffineTransform.getRotateInstance(theta, x + pinSpacing / 2, y + pinSpacing / 2));
|
||||
} else {
|
||||
theta = -Math.atan(1.0 / 3);
|
||||
arrow =
|
||||
new Area(
|
||||
new Polygon(new int[] {x + pinSpacing, x + pinSpacing * 10 / 6, x + pinSpacing * 10 / 6}, new int[] {
|
||||
y - pinSpacing / 2, y - pinSpacing / 5 - pinSpacing / 2, y + pinSpacing / 5 - pinSpacing / 2}, 3));
|
||||
arrow.transform(AffineTransform.getRotateInstance(theta, x + pinSpacing / 2, y - pinSpacing / 2));
|
||||
}
|
||||
body[2] = arrow;
|
||||
Area arrow;
|
||||
double theta;
|
||||
if (polarity == BJTPolarity.NPN) {
|
||||
theta = Math.atan(1.0 / 3);
|
||||
arrow =
|
||||
new Area(new Polygon(new int[] {x + pinSpacing, x + pinSpacing, x + pinSpacing * 10 / 6}, new int[] {
|
||||
y - pinSpacing / 5 + pinSpacing / 2, y + pinSpacing / 5 + pinSpacing / 2, y + pinSpacing / 2}, 3));
|
||||
arrow.transform(AffineTransform.getRotateInstance(theta, x + pinSpacing / 2, y + pinSpacing / 2));
|
||||
} else {
|
||||
theta = -Math.atan(1.0 / 3);
|
||||
arrow =
|
||||
new Area(
|
||||
new Polygon(new int[] {x + pinSpacing, x + pinSpacing * 10 / 6, x + pinSpacing * 10 / 6}, new int[] {
|
||||
y - pinSpacing / 2, y - pinSpacing / 5 - pinSpacing / 2, y + pinSpacing / 5 - pinSpacing / 2}, 3));
|
||||
arrow.transform(AffineTransform.getRotateInstance(theta, x + pinSpacing / 2, y - pinSpacing / 2));
|
||||
}
|
||||
body[2] = arrow;
|
||||
|
||||
return body;
|
||||
}
|
||||
|
||||
@@ -116,7 +115,6 @@ public class BJTSymbol extends Abstract3LegSymbol {
|
||||
public void setPolarity(BJTPolarity polarity) {
|
||||
this.polarity = polarity;
|
||||
|
||||
|
||||
refreshDrawing();
|
||||
body = null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,43 +43,42 @@ public class JFETSymbol extends Abstract3LegSymbol {
|
||||
protected FETPolarity polarity = FETPolarity.NEGATIVE;
|
||||
|
||||
public Shape[] getBody() {
|
||||
if (body == null) {
|
||||
body = new Shape[3];
|
||||
int x = controlPoints[0].x;
|
||||
int y = controlPoints[0].y;
|
||||
int pinSpacing = (int) PIN_SPACING.convertToPixels();
|
||||
Shape[] body = new Shape[3];
|
||||
int x = controlPoints[0].x;
|
||||
int y = controlPoints[0].y;
|
||||
int pinSpacing = (int) PIN_SPACING.convertToPixels();
|
||||
|
||||
GeneralPath polyline = new GeneralPath();
|
||||
GeneralPath polyline = new GeneralPath();
|
||||
|
||||
polyline.moveTo(x + pinSpacing, y - pinSpacing);
|
||||
polyline.lineTo(x + pinSpacing, y + pinSpacing);
|
||||
polyline.moveTo(x + pinSpacing, y - pinSpacing);
|
||||
polyline.lineTo(x + pinSpacing, y + pinSpacing);
|
||||
|
||||
body[0] = polyline;
|
||||
body[0] = polyline;
|
||||
|
||||
polyline = new GeneralPath();
|
||||
polyline = new GeneralPath();
|
||||
|
||||
polyline.moveTo(x, y);
|
||||
polyline.lineTo(x + pinSpacing, y);
|
||||
polyline.moveTo(x + pinSpacing, y - pinSpacing * 7 / 8);
|
||||
polyline.lineTo(x + pinSpacing * 2, y - pinSpacing * 7 / 8);
|
||||
polyline.lineTo(x + pinSpacing * 2, y - pinSpacing * 2);
|
||||
polyline.moveTo(x + pinSpacing, y + pinSpacing * 7 / 8);
|
||||
polyline.lineTo(x + pinSpacing * 2, y + pinSpacing * 7 / 8);
|
||||
polyline.lineTo(x + pinSpacing * 2, y + pinSpacing * 2);
|
||||
body[1] = polyline;
|
||||
polyline.moveTo(x, y);
|
||||
polyline.lineTo(x + pinSpacing, y);
|
||||
polyline.moveTo(x + pinSpacing, y - pinSpacing * 7 / 8);
|
||||
polyline.lineTo(x + pinSpacing * 2, y - pinSpacing * 7 / 8);
|
||||
polyline.lineTo(x + pinSpacing * 2, y - pinSpacing * 2);
|
||||
polyline.moveTo(x + pinSpacing, y + pinSpacing * 7 / 8);
|
||||
polyline.lineTo(x + pinSpacing * 2, y + pinSpacing * 7 / 8);
|
||||
polyline.lineTo(x + pinSpacing * 2, y + pinSpacing * 2);
|
||||
body[1] = polyline;
|
||||
|
||||
Polygon arrow;
|
||||
if (polarity == FETPolarity.NEGATIVE) {
|
||||
arrow =
|
||||
new Polygon(new int[] {x + pinSpacing * 2 / 6, x + pinSpacing * 2 / 6, x + pinSpacing * 6 / 6}, new int[] {
|
||||
y - pinSpacing / 5, y + pinSpacing / 5, y}, 3);
|
||||
} else {
|
||||
arrow =
|
||||
new Polygon(new int[] {x + pinSpacing / 6, x + pinSpacing * 5 / 6, x + pinSpacing * 5 / 6}, new int[] {y,
|
||||
y + pinSpacing / 5, y - pinSpacing / 5}, 3);
|
||||
}
|
||||
body[2] = arrow;
|
||||
Polygon arrow;
|
||||
if (polarity == FETPolarity.NEGATIVE) {
|
||||
arrow =
|
||||
new Polygon(new int[] {x + pinSpacing * 2 / 6, x + pinSpacing * 2 / 6, x + pinSpacing * 6 / 6}, new int[] {
|
||||
y - pinSpacing / 5, y + pinSpacing / 5, y}, 3);
|
||||
} else {
|
||||
arrow =
|
||||
new Polygon(new int[] {x + pinSpacing / 6, x + pinSpacing * 5 / 6, x + pinSpacing * 5 / 6}, new int[] {y,
|
||||
y + pinSpacing / 5, y - pinSpacing / 5}, 3);
|
||||
}
|
||||
body[2] = arrow;
|
||||
|
||||
return body;
|
||||
}
|
||||
|
||||
@@ -108,6 +107,6 @@ public class JFETSymbol extends Abstract3LegSymbol {
|
||||
public void setPolarity(FETPolarity polarity) {
|
||||
this.polarity = polarity;
|
||||
|
||||
refreshDrawing();
|
||||
body = null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,46 +43,45 @@ public class MOSFETSymbol extends Abstract3LegSymbol {
|
||||
protected FETPolarity polarity = FETPolarity.NEGATIVE;
|
||||
|
||||
public Shape[] getBody() {
|
||||
if (body == null) {
|
||||
body = new Shape[3];
|
||||
int x = controlPoints[0].x;
|
||||
int y = controlPoints[0].y;
|
||||
int pinSpacing = (int) PIN_SPACING.convertToPixels();
|
||||
Shape[] body = new Shape[3];
|
||||
int x = controlPoints[0].x;
|
||||
int y = controlPoints[0].y;
|
||||
int pinSpacing = (int) PIN_SPACING.convertToPixels();
|
||||
|
||||
GeneralPath polyline = new GeneralPath();
|
||||
GeneralPath polyline = new GeneralPath();
|
||||
|
||||
polyline.moveTo(x + pinSpacing / 2, y - pinSpacing + 1);
|
||||
polyline.lineTo(x + pinSpacing / 2, y + pinSpacing - 1);
|
||||
polyline.moveTo(x + pinSpacing, y - pinSpacing + 1);
|
||||
polyline.lineTo(x + pinSpacing, y + pinSpacing - 1);
|
||||
body[0] = polyline;
|
||||
polyline.moveTo(x + pinSpacing / 2, y - pinSpacing + 1);
|
||||
polyline.lineTo(x + pinSpacing / 2, y + pinSpacing - 1);
|
||||
polyline.moveTo(x + pinSpacing, y - pinSpacing + 1);
|
||||
polyline.lineTo(x + pinSpacing, y + pinSpacing - 1);
|
||||
body[0] = polyline;
|
||||
|
||||
polyline = new GeneralPath();
|
||||
polyline = new GeneralPath();
|
||||
|
||||
polyline.moveTo(x + pinSpacing, y - pinSpacing);
|
||||
polyline.lineTo(x + pinSpacing * 2, y - pinSpacing);
|
||||
polyline.moveTo(x + pinSpacing, y + pinSpacing);
|
||||
polyline.lineTo(x + pinSpacing * 2, y + pinSpacing);
|
||||
polyline.moveTo(x, y);
|
||||
polyline.lineTo(x + pinSpacing / 2, y);
|
||||
polyline.moveTo(x + pinSpacing * 2, y - pinSpacing * 2);
|
||||
polyline.lineTo(x + pinSpacing * 2, y - pinSpacing);
|
||||
polyline.moveTo(x + pinSpacing * 2, y + pinSpacing * 2);
|
||||
polyline.lineTo(x + pinSpacing * 2, y + pinSpacing);
|
||||
body[1] = polyline;
|
||||
polyline.moveTo(x + pinSpacing, y - pinSpacing);
|
||||
polyline.lineTo(x + pinSpacing * 2, y - pinSpacing);
|
||||
polyline.moveTo(x + pinSpacing, y + pinSpacing);
|
||||
polyline.lineTo(x + pinSpacing * 2, y + pinSpacing);
|
||||
polyline.moveTo(x, y);
|
||||
polyline.lineTo(x + pinSpacing / 2, y);
|
||||
polyline.moveTo(x + pinSpacing * 2, y - pinSpacing * 2);
|
||||
polyline.lineTo(x + pinSpacing * 2, y - pinSpacing);
|
||||
polyline.moveTo(x + pinSpacing * 2, y + pinSpacing * 2);
|
||||
polyline.lineTo(x + pinSpacing * 2, y + pinSpacing);
|
||||
body[1] = polyline;
|
||||
|
||||
Polygon arrow;
|
||||
if (polarity == FETPolarity.NEGATIVE) {
|
||||
arrow =
|
||||
new Polygon(new int[] {x + pinSpacing * 8 / 6, x + pinSpacing * 8 / 6, x + pinSpacing * 12 / 6}, new int[] {
|
||||
y + pinSpacing * 6 / 5, y + pinSpacing * 4 / 5, y + pinSpacing}, 3);
|
||||
} else {
|
||||
arrow =
|
||||
new Polygon(new int[] {x + pinSpacing * 7 / 6, x + pinSpacing * 11 / 6, x + pinSpacing * 11 / 6},
|
||||
new int[] {y - pinSpacing, y - pinSpacing * 6 / 5, y - pinSpacing * 4 / 5}, 3);
|
||||
}
|
||||
body[2] = arrow;
|
||||
Polygon arrow;
|
||||
if (polarity == FETPolarity.NEGATIVE) {
|
||||
arrow =
|
||||
new Polygon(new int[] {x + pinSpacing * 8 / 6, x + pinSpacing * 8 / 6, x + pinSpacing * 12 / 6}, new int[] {
|
||||
y + pinSpacing * 6 / 5, y + pinSpacing * 4 / 5, y + pinSpacing}, 3);
|
||||
} else {
|
||||
arrow =
|
||||
new Polygon(new int[] {x + pinSpacing * 7 / 6, x + pinSpacing * 11 / 6, x + pinSpacing * 11 / 6},
|
||||
new int[] {y - pinSpacing, y - pinSpacing * 6 / 5, y - pinSpacing * 4 / 5}, 3);
|
||||
}
|
||||
body[2] = arrow;
|
||||
|
||||
return body;
|
||||
}
|
||||
|
||||
@@ -111,6 +110,6 @@ public class MOSFETSymbol extends Abstract3LegSymbol {
|
||||
public void setPolarity(FETPolarity polarity) {
|
||||
this.polarity = polarity;
|
||||
|
||||
refreshDrawing();
|
||||
body = null;
|
||||
}
|
||||
}
|
||||
|
||||
Binary file not shown.
Binary file not shown.
@@ -2166,6 +2166,10 @@
|
||||
<changeType>BUG_FIX</changeType>
|
||||
<description>Project font gets reverted to "Square721 BT" on Undo</description>
|
||||
</org.diylc.appframework.update.Change>
|
||||
<org.diylc.appframework.update.Change>
|
||||
<changeType>BUG_FIX</changeType>
|
||||
<description>When loaded from an existing file "Potentiometer Symbol" doesn't retain the specified orientation</description>
|
||||
</org.diylc.appframework.update.Change>
|
||||
</changes>
|
||||
<url>https://github.com/bancika/diy-layout-creator/releases</url>
|
||||
</org.diylc.appframework.update.Version>
|
||||
|
||||
Reference in New Issue
Block a user