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
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,8 +45,7 @@ public class BJTSymbol extends Abstract3LegSymbol {
protected BJTPolarity polarity = BJTPolarity.NPN;
public Shape[] getBody() {
if (body == null) {
body = new Shape[3];
Shape[] body = new Shape[3];
int x = controlPoints[0].x;
int y = controlPoints[0].y;
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));
}
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,8 +43,7 @@ public class JFETSymbol extends Abstract3LegSymbol {
protected FETPolarity polarity = FETPolarity.NEGATIVE;
public Shape[] getBody() {
if (body == null) {
body = new Shape[3];
Shape[] body = new Shape[3];
int x = controlPoints[0].x;
int y = controlPoints[0].y;
int pinSpacing = (int) PIN_SPACING.convertToPixels();
@@ -79,7 +78,7 @@ public class JFETSymbol extends Abstract3LegSymbol {
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,8 +43,7 @@ public class MOSFETSymbol extends Abstract3LegSymbol {
protected FETPolarity polarity = FETPolarity.NEGATIVE;
public Shape[] getBody() {
if (body == null) {
body = new Shape[3];
Shape[] body = new Shape[3];
int x = controlPoints[0].x;
int y = controlPoints[0].y;
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);
}
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.
+4
View File
@@ -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>