transistor and potentiometer symbols can be rotated

This commit is contained in:
bancika
2016-12-22 15:21:01 +01:00
parent a32105e156
commit f79498bc22
6 changed files with 50 additions and 10 deletions
@@ -14,6 +14,7 @@ import org.diylc.common.Display;
import org.diylc.common.HorizontalAlignment; import org.diylc.common.HorizontalAlignment;
import org.diylc.common.IPlugInPort; import org.diylc.common.IPlugInPort;
import org.diylc.common.ObjectCache; import org.diylc.common.ObjectCache;
import org.diylc.common.Orientation;
import org.diylc.common.VerticalAlignment; import org.diylc.common.VerticalAlignment;
import org.diylc.components.AbstractComponent; import org.diylc.components.AbstractComponent;
import org.diylc.components.semiconductors.SymbolFlipping; import org.diylc.components.semiconductors.SymbolFlipping;
@@ -41,6 +42,7 @@ public abstract class Abstract3LegSymbol extends AbstractComponent<String> {
protected SymbolFlipping flip = FLIPPING; protected SymbolFlipping flip = FLIPPING;
protected Display display = Display.NAME; protected Display display = Display.NAME;
transient protected Shape[] body; transient protected Shape[] body;
protected Orientation orientation = Orientation.DEFAULT;
public Abstract3LegSymbol() { public Abstract3LegSymbol() {
super(); super();
@@ -183,8 +185,8 @@ public abstract class Abstract3LegSymbol extends AbstractComponent<String> {
@Override @Override
public void setControlPoint(Point point, int index) { public void setControlPoint(Point point, int index) {
controlPoints[index].setLocation(point); controlPoints[index].setLocation(point);
// Invalidate body
body = null; refreshDrawing();
} }
@EditableProperty @EditableProperty
@@ -194,7 +196,8 @@ public abstract class Abstract3LegSymbol extends AbstractComponent<String> {
public void setFlip(SymbolFlipping flip) { public void setFlip(SymbolFlipping flip) {
this.flip = flip; this.flip = flip;
updateControlPoints();
refreshDrawing();
} }
@EditableProperty @EditableProperty
@@ -215,6 +218,42 @@ public abstract class Abstract3LegSymbol extends AbstractComponent<String> {
this.display = display; this.display = display;
} }
@EditableProperty
public Orientation getOrientation() {
if (orientation == null)
orientation = Orientation.DEFAULT;
return orientation;
}
public void setOrientation(Orientation orientation) {
this.orientation = orientation;
refreshDrawing();
}
protected void refreshDrawing() {
updateControlPoints();
// make sure we have a new drawing
body = null;
getBody();
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]);
}
}
}
/** /**
* Returns transistor shape consisting of 3 parts, in this order: main body, connectors, polarity * Returns transistor shape consisting of 3 parts, in this order: main body, connectors, polarity
* arrow. * arrow.
@@ -95,7 +95,8 @@ public class BJTSymbol extends Abstract3LegSymbol {
public void setPolarity(BJTPolarity polarity) { public void setPolarity(BJTPolarity polarity) {
this.polarity = polarity; this.polarity = polarity;
// Invalidate body
body = null;
refreshDrawing();
} }
} }
@@ -87,7 +87,7 @@ public class JFETSymbol extends Abstract3LegSymbol {
public void setPolarity(FETPolarity polarity) { public void setPolarity(FETPolarity polarity) {
this.polarity = polarity; this.polarity = polarity;
// Invalidate body
body = null; refreshDrawing();
} }
} }
@@ -90,7 +90,7 @@ public class MOSFETSymbol extends Abstract3LegSymbol {
public void setPolarity(FETPolarity polarity) { public void setPolarity(FETPolarity polarity) {
this.polarity = polarity; this.polarity = polarity;
// Invalidate body
body = null; refreshDrawing();
} }
} }
Binary file not shown.
+1 -1
View File
@@ -1420,7 +1420,7 @@
</org.diylc.appframework.update.Change> </org.diylc.appframework.update.Change>
<org.diylc.appframework.update.Change> <org.diylc.appframework.update.Change>
<changeType>NEW_FEATURE</changeType> <changeType>NEW_FEATURE</changeType>
<description>Tube symbols can be rotated</description> <description>Tube, transistor and potentiometer symbols can be rotated</description>
</org.diylc.appframework.update.Change> </org.diylc.appframework.update.Change>
<org.diylc.appframework.update.Change> <org.diylc.appframework.update.Change>
<changeType>IMPROVEMENT</changeType> <changeType>IMPROVEMENT</changeType>