When loaded from an existing file "Potentiometer Symbol" doesn't retain

the specified orientation
This commit is contained in:
Branislav Stojkovic
2019-01-10 19:47:22 +01:00
parent 7caadec1ec
commit 007a52f0b5
7 changed files with 146 additions and 134 deletions
@@ -90,6 +90,10 @@ public abstract class Abstract3LegSymbol extends AbstractComponent<String> {
// Draw transistor // Draw transistor
if (this.body == null) {
this.body = getBody();
applyOrientation(this.body);
}
Shape[] body = getBody(); Shape[] body = getBody();
AffineTransform old = g2d.getTransform(); AffineTransform old = g2d.getTransform();
@@ -166,7 +170,7 @@ public abstract class Abstract3LegSymbol extends AbstractComponent<String> {
return controlPoints[0].y; return controlPoints[0].y;
} }
private void updateControlPoints() { protected void updateControlPoints() {
int pinSpacing = (int) PIN_SPACING.convertToPixels(); int pinSpacing = (int) PIN_SPACING.convertToPixels();
// Update control points. // Update control points.
int x = controlPoints[0].x; 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].x = x + f * pinSpacing * 2;
controlPoints[2].y = y + 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 @Override
@@ -206,7 +220,8 @@ public abstract class Abstract3LegSymbol extends AbstractComponent<String> {
public void setControlPoint(Point point, int index) { public void setControlPoint(Point point, int index) {
controlPoints[index].setLocation(point); controlPoints[index].setLocation(point);
refreshDrawing(); // make sure we have a new drawing
body = null;
} }
@EditableProperty @EditableProperty
@@ -217,7 +232,9 @@ public abstract class Abstract3LegSymbol extends AbstractComponent<String> {
public void setFlip(SymbolFlipping flip) { public void setFlip(SymbolFlipping flip) {
this.flip = flip; this.flip = flip;
refreshDrawing(); updateControlPoints();
// make sure we have a new drawing
body = null;
} }
@EditableProperty @EditableProperty
@@ -249,27 +266,22 @@ public abstract class Abstract3LegSymbol extends AbstractComponent<String> {
public void setOrientation(Orientation orientation) { public void setOrientation(Orientation orientation) {
this.orientation = orientation; this.orientation = orientation;
refreshDrawing();
}
protected void refreshDrawing() {
updateControlPoints(); updateControlPoints();
// make sure we have a new drawing // make sure we have a new drawing
body = null; body = null;
getBody(); }
protected void applyOrientation(Shape[] body) {
if (getOrientation() == Orientation.DEFAULT) if (getOrientation() == Orientation.DEFAULT)
return; return;
Point first = this.controlPoints[0]; Point first = this.controlPoints[0];
double angle = Double.parseDouble(getOrientation().name().replace("_", "")); double angle = Double.parseDouble(getOrientation().name().replace("_", ""));
AffineTransform rotate = AffineTransform.getRotateInstance(Math.toRadians(angle), first.x, first.y); 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 (body != null) {
} for (int i = 0; i < body.length; i++) {
if (this.body != null) { body[i] = rotate.createTransformedShape(body[i]);
for (int i = 0; i < this.body.length; i++) {
this.body[i] = rotate.createTransformedShape(this.body[i]);
} }
} }
} }
@@ -45,8 +45,7 @@ public class BJTSymbol extends Abstract3LegSymbol {
protected BJTPolarity polarity = BJTPolarity.NPN; protected BJTPolarity polarity = BJTPolarity.NPN;
public Shape[] getBody() { public Shape[] getBody() {
if (body == null) { Shape[] body = new Shape[3];
body = new Shape[3];
int x = controlPoints[0].x; int x = controlPoints[0].x;
int y = controlPoints[0].y; int y = controlPoints[0].y;
int pinSpacing = (int) PIN_SPACING.convertToPixels(); int pinSpacing = (int) PIN_SPACING.convertToPixels();
@@ -87,7 +86,7 @@ public class BJTSymbol extends Abstract3LegSymbol {
arrow.transform(AffineTransform.getRotateInstance(theta, x + pinSpacing / 2, y - pinSpacing / 2)); arrow.transform(AffineTransform.getRotateInstance(theta, x + pinSpacing / 2, y - pinSpacing / 2));
} }
body[2] = arrow; body[2] = arrow;
}
return body; return body;
} }
@@ -116,7 +115,6 @@ public class BJTSymbol extends Abstract3LegSymbol {
public void setPolarity(BJTPolarity polarity) { public void setPolarity(BJTPolarity polarity) {
this.polarity = polarity; this.polarity = polarity;
body = null;
refreshDrawing();
} }
} }
@@ -43,8 +43,7 @@ public class JFETSymbol extends Abstract3LegSymbol {
protected FETPolarity polarity = FETPolarity.NEGATIVE; protected FETPolarity polarity = FETPolarity.NEGATIVE;
public Shape[] getBody() { public Shape[] getBody() {
if (body == null) { Shape[] body = new Shape[3];
body = new Shape[3];
int x = controlPoints[0].x; int x = controlPoints[0].x;
int y = controlPoints[0].y; int y = controlPoints[0].y;
int pinSpacing = (int) PIN_SPACING.convertToPixels(); int pinSpacing = (int) PIN_SPACING.convertToPixels();
@@ -79,7 +78,7 @@ public class JFETSymbol extends Abstract3LegSymbol {
y + pinSpacing / 5, y - pinSpacing / 5}, 3); y + pinSpacing / 5, y - pinSpacing / 5}, 3);
} }
body[2] = arrow; body[2] = arrow;
}
return body; return body;
} }
@@ -108,6 +107,6 @@ public class JFETSymbol extends Abstract3LegSymbol {
public void setPolarity(FETPolarity polarity) { public void setPolarity(FETPolarity polarity) {
this.polarity = polarity; this.polarity = polarity;
refreshDrawing(); body = null;
} }
} }
@@ -43,8 +43,7 @@ public class MOSFETSymbol extends Abstract3LegSymbol {
protected FETPolarity polarity = FETPolarity.NEGATIVE; protected FETPolarity polarity = FETPolarity.NEGATIVE;
public Shape[] getBody() { public Shape[] getBody() {
if (body == null) { Shape[] body = new Shape[3];
body = new Shape[3];
int x = controlPoints[0].x; int x = controlPoints[0].x;
int y = controlPoints[0].y; int y = controlPoints[0].y;
int pinSpacing = (int) PIN_SPACING.convertToPixels(); int pinSpacing = (int) PIN_SPACING.convertToPixels();
@@ -82,7 +81,7 @@ public class MOSFETSymbol extends Abstract3LegSymbol {
new int[] {y - pinSpacing, y - pinSpacing * 6 / 5, y - pinSpacing * 4 / 5}, 3); new int[] {y - pinSpacing, y - pinSpacing * 6 / 5, y - pinSpacing * 4 / 5}, 3);
} }
body[2] = arrow; body[2] = arrow;
}
return body; return body;
} }
@@ -111,6 +110,6 @@ public class MOSFETSymbol extends Abstract3LegSymbol {
public void setPolarity(FETPolarity polarity) { public void setPolarity(FETPolarity polarity) {
this.polarity = polarity; this.polarity = polarity;
refreshDrawing(); body = null;
} }
} }
Binary file not shown.
Binary file not shown.
+4
View File
@@ -2166,6 +2166,10 @@
<changeType>BUG_FIX</changeType> <changeType>BUG_FIX</changeType>
<description>Project font gets reverted to "Square721 BT" on Undo</description> <description>Project font gets reverted to "Square721 BT" on Undo</description>
</org.diylc.appframework.update.Change> </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> </changes>
<url>https://github.com/bancika/diy-layout-creator/releases</url> <url>https://github.com/bancika/diy-layout-creator/releases</url>
</org.diylc.appframework.update.Version> </org.diylc.appframework.update.Version>