mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-10 09:12:09 +10:00
Tube symbols can be rotated
This commit is contained in:
@@ -3,13 +3,16 @@ package org.diylc.components.tube;
|
|||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
import java.awt.Graphics2D;
|
import java.awt.Graphics2D;
|
||||||
import java.awt.Point;
|
import java.awt.Point;
|
||||||
|
import java.awt.Rectangle;
|
||||||
import java.awt.Shape;
|
import java.awt.Shape;
|
||||||
|
import java.awt.geom.AffineTransform;
|
||||||
|
|
||||||
import org.diylc.appframework.miscutils.ConfigurationManager;
|
import org.diylc.appframework.miscutils.ConfigurationManager;
|
||||||
import org.diylc.common.Display;
|
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.core.ComponentState;
|
import org.diylc.core.ComponentState;
|
||||||
@@ -34,6 +37,8 @@ public abstract class AbstractTubeSymbol extends AbstractComponent<String> {
|
|||||||
protected Display display = Display.NAME;
|
protected Display display = Display.NAME;
|
||||||
transient protected Shape[] body;
|
transient protected Shape[] body;
|
||||||
protected boolean showHeaters;
|
protected boolean showHeaters;
|
||||||
|
protected Orientation orientation = Orientation.DEFAULT;
|
||||||
|
protected Point[] controlPoints;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void draw(Graphics2D g2d, ComponentState componentState, boolean outlineMode, Project project,
|
public void draw(Graphics2D g2d, ComponentState componentState, boolean outlineMode, Project project,
|
||||||
@@ -82,7 +87,9 @@ public abstract class AbstractTubeSymbol extends AbstractComponent<String> {
|
|||||||
: LABEL_COLOR;
|
: LABEL_COLOR;
|
||||||
}
|
}
|
||||||
g2d.setColor(finalLabelColor);
|
g2d.setColor(finalLabelColor);
|
||||||
Point p = getTextLocation();
|
|
||||||
|
Rectangle rect = body[2] != null ? body[2].getBounds() : body[1].getBounds();
|
||||||
|
|
||||||
String label = "";
|
String label = "";
|
||||||
label = display == Display.VALUE ? getValue() : getName();
|
label = display == Display.VALUE ? getValue() : getName();
|
||||||
if (display == Display.NONE) {
|
if (display == Display.NONE) {
|
||||||
@@ -91,7 +98,24 @@ public abstract class AbstractTubeSymbol extends AbstractComponent<String> {
|
|||||||
if (display == Display.BOTH) {
|
if (display == Display.BOTH) {
|
||||||
label = getName() + " " + (getValue() == null ? "" : getValue().toString());
|
label = getName() + " " + (getValue() == null ? "" : getValue().toString());
|
||||||
}
|
}
|
||||||
drawCenteredText(g2d, label, p.x, p.y, HorizontalAlignment.LEFT, VerticalAlignment.TOP);
|
drawCenteredText(g2d, label, rect.x + rect.width, rect.y + rect.height, HorizontalAlignment.RIGHT, VerticalAlignment.BOTTOM);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Point getControlPoint(int index) {
|
||||||
|
return controlPoints[index];
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getControlPointCount() {
|
||||||
|
return controlPoints.length;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setControlPoint(Point point, int index) {
|
||||||
|
controlPoints[index].setLocation(point);
|
||||||
|
|
||||||
|
refreshDrawing();
|
||||||
}
|
}
|
||||||
|
|
||||||
@EditableProperty
|
@EditableProperty
|
||||||
@@ -130,8 +154,41 @@ public abstract class AbstractTubeSymbol extends AbstractComponent<String> {
|
|||||||
|
|
||||||
public void setShowHeaters(boolean showHeaters) {
|
public void setShowHeaters(boolean showHeaters) {
|
||||||
this.showHeaters = showHeaters;
|
this.showHeaters = showHeaters;
|
||||||
// Invalidate body
|
|
||||||
|
refreshDrawing();
|
||||||
|
}
|
||||||
|
|
||||||
|
@EditableProperty
|
||||||
|
public Orientation getOrientation() {
|
||||||
|
return orientation;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOrientation(Orientation orientation) {
|
||||||
|
this.orientation = orientation;
|
||||||
|
|
||||||
|
refreshDrawing();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void refreshDrawing() {
|
||||||
|
updateControlPoints();
|
||||||
|
// make sure we have a new drawing
|
||||||
body = null;
|
body = null;
|
||||||
|
getBody();
|
||||||
|
|
||||||
|
if (this.orientation == Orientation.DEFAULT)
|
||||||
|
return;
|
||||||
|
|
||||||
|
Point first = this.controlPoints[0];
|
||||||
|
double angle = Double.parseDouble(this.orientation.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]);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -142,4 +199,6 @@ public abstract class AbstractTubeSymbol extends AbstractComponent<String> {
|
|||||||
protected abstract Shape[] getBody();
|
protected abstract Shape[] getBody();
|
||||||
|
|
||||||
protected abstract Point getTextLocation();
|
protected abstract Point getTextLocation();
|
||||||
|
|
||||||
|
protected abstract void updateControlPoints();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,13 +22,12 @@ public class DiodeSymbol extends AbstractTubeSymbol {
|
|||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
protected Point[] controlPoints = new Point[] {new Point(0, 0), new Point(0, 0), new Point(0, 0), new Point(0, 0),
|
|
||||||
new Point(0, 0)};
|
|
||||||
|
|
||||||
protected boolean directlyHeated = false;
|
protected boolean directlyHeated = false;
|
||||||
|
|
||||||
public DiodeSymbol() {
|
public DiodeSymbol() {
|
||||||
super();
|
super();
|
||||||
|
this.controlPoints = new Point[] {new Point(0, 0), new Point(0, 0), new Point(0, 0), new Point(0, 0),
|
||||||
|
new Point(0, 0)};
|
||||||
updateControlPoints();
|
updateControlPoints();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -111,15 +110,6 @@ public class DiodeSymbol extends AbstractTubeSymbol {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Point getControlPoint(int index) {
|
|
||||||
return controlPoints[index];
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getControlPointCount() {
|
|
||||||
return controlPoints.length;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void updateControlPoints() {
|
protected void updateControlPoints() {
|
||||||
int pinSpacing = (int) PIN_SPACING.convertToPixels();
|
int pinSpacing = (int) PIN_SPACING.convertToPixels();
|
||||||
// Update control points.
|
// Update control points.
|
||||||
@@ -139,13 +129,6 @@ public class DiodeSymbol extends AbstractTubeSymbol {
|
|||||||
controlPoints[4].y = y + pinSpacing * 3;
|
controlPoints[4].y = y + pinSpacing * 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setControlPoint(Point point, int index) {
|
|
||||||
controlPoints[index].setLocation(point);
|
|
||||||
// Invalidate body
|
|
||||||
body = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public VisibilityPolicy getControlPointVisibilityPolicy(int index) {
|
public VisibilityPolicy getControlPointVisibilityPolicy(int index) {
|
||||||
if (directlyHeated) {
|
if (directlyHeated) {
|
||||||
@@ -181,8 +164,8 @@ public class DiodeSymbol extends AbstractTubeSymbol {
|
|||||||
|
|
||||||
public void setDirectlyHeated(boolean directlyHeated) {
|
public void setDirectlyHeated(boolean directlyHeated) {
|
||||||
this.directlyHeated = directlyHeated;
|
this.directlyHeated = directlyHeated;
|
||||||
// Invalidate body
|
|
||||||
body = null;
|
refreshDrawing();
|
||||||
}
|
}
|
||||||
|
|
||||||
public class HeaterValidator implements IPropertyValidator {
|
public class HeaterValidator implements IPropertyValidator {
|
||||||
|
|||||||
@@ -21,13 +21,12 @@ public class PentodeSymbol extends AbstractTubeSymbol {
|
|||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
protected Point[] controlPoints = new Point[] {new Point(0, 0), new Point(0, 0), new Point(0, 0), new Point(0, 0),
|
|
||||||
new Point(0, 0), new Point(0, 0), new Point(0, 0)};
|
|
||||||
|
|
||||||
protected boolean exposeSuppressorGrid = true;
|
protected boolean exposeSuppressorGrid = true;
|
||||||
|
|
||||||
public PentodeSymbol() {
|
public PentodeSymbol() {
|
||||||
super();
|
super();
|
||||||
|
this.controlPoints = new Point[] {new Point(0, 0), new Point(0, 0), new Point(0, 0), new Point(0, 0),
|
||||||
|
new Point(0, 0), new Point(0, 0), new Point(0, 0)};
|
||||||
updateControlPoints();
|
updateControlPoints();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -156,16 +155,6 @@ public class PentodeSymbol extends AbstractTubeSymbol {
|
|||||||
g2d.drawLine(width / 8, height * 5 / 8, width * 7 / 8, height * 5 / 8);
|
g2d.drawLine(width / 8, height * 5 / 8, width * 7 / 8, height * 5 / 8);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public Point getControlPoint(int index) {
|
|
||||||
return controlPoints[index];
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getControlPointCount() {
|
|
||||||
return controlPoints.length;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void updateControlPoints() {
|
protected void updateControlPoints() {
|
||||||
int pinSpacing = (int) PIN_SPACING.convertToPixels();
|
int pinSpacing = (int) PIN_SPACING.convertToPixels();
|
||||||
// Update control points.
|
// Update control points.
|
||||||
@@ -191,13 +180,6 @@ public class PentodeSymbol extends AbstractTubeSymbol {
|
|||||||
controlPoints[6].y = y + pinSpacing * 2;
|
controlPoints[6].y = y + pinSpacing * 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setControlPoint(Point point, int index) {
|
|
||||||
controlPoints[index].setLocation(point);
|
|
||||||
// Invalidate body
|
|
||||||
body = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public VisibilityPolicy getControlPointVisibilityPolicy(int index) {
|
public VisibilityPolicy getControlPointVisibilityPolicy(int index) {
|
||||||
if (showHeaters) {
|
if (showHeaters) {
|
||||||
@@ -230,6 +212,7 @@ public class PentodeSymbol extends AbstractTubeSymbol {
|
|||||||
|
|
||||||
public void setExposeSuppressorGrid(boolean exposeSuppressorGrid) {
|
public void setExposeSuppressorGrid(boolean exposeSuppressorGrid) {
|
||||||
this.exposeSuppressorGrid = exposeSuppressorGrid;
|
this.exposeSuppressorGrid = exposeSuppressorGrid;
|
||||||
this.body = null;
|
|
||||||
|
refreshDrawing();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,13 +21,12 @@ public class TriodeSymbol extends AbstractTubeSymbol {
|
|||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
protected Point[] controlPoints = new Point[] {new Point(0, 0), new Point(0, 0), new Point(0, 0), new Point(0, 0),
|
|
||||||
new Point(0, 0)};
|
|
||||||
|
|
||||||
protected boolean directlyHeated = false;
|
protected boolean directlyHeated = false;
|
||||||
|
|
||||||
public TriodeSymbol() {
|
public TriodeSymbol() {
|
||||||
super();
|
super();
|
||||||
|
this.controlPoints = new Point[] {new Point(0, 0), new Point(0, 0), new Point(0, 0), new Point(0, 0),
|
||||||
|
new Point(0, 0)};
|
||||||
updateControlPoints();
|
updateControlPoints();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -127,16 +126,6 @@ public class TriodeSymbol extends AbstractTubeSymbol {
|
|||||||
g2d.drawLine(width / 8, height / 2, width * 7 / 8, height / 2);
|
g2d.drawLine(width / 8, height / 2, width * 7 / 8, height / 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public Point getControlPoint(int index) {
|
|
||||||
return controlPoints[index];
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getControlPointCount() {
|
|
||||||
return controlPoints.length;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void updateControlPoints() {
|
protected void updateControlPoints() {
|
||||||
int pinSpacing = (int) PIN_SPACING.convertToPixels();
|
int pinSpacing = (int) PIN_SPACING.convertToPixels();
|
||||||
// Update control points.
|
// Update control points.
|
||||||
@@ -156,13 +145,6 @@ public class TriodeSymbol extends AbstractTubeSymbol {
|
|||||||
controlPoints[4].y = y + pinSpacing * 3;
|
controlPoints[4].y = y + pinSpacing * 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setControlPoint(Point point, int index) {
|
|
||||||
controlPoints[index].setLocation(point);
|
|
||||||
// Invalidate body
|
|
||||||
body = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public VisibilityPolicy getControlPointVisibilityPolicy(int index) {
|
public VisibilityPolicy getControlPointVisibilityPolicy(int index) {
|
||||||
if (directlyHeated) {
|
if (directlyHeated) {
|
||||||
@@ -198,7 +180,7 @@ public class TriodeSymbol extends AbstractTubeSymbol {
|
|||||||
|
|
||||||
public void setDirectlyHeated(boolean directlyHeated) {
|
public void setDirectlyHeated(boolean directlyHeated) {
|
||||||
this.directlyHeated = directlyHeated;
|
this.directlyHeated = directlyHeated;
|
||||||
// Invalidate body
|
|
||||||
body = null;
|
refreshDrawing();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Binary file not shown.
@@ -1418,6 +1418,10 @@
|
|||||||
<changeType>NEW_FEATURE</changeType>
|
<changeType>NEW_FEATURE</changeType>
|
||||||
<description>Battery schematic symbol added</description>
|
<description>Battery schematic symbol added</description>
|
||||||
</org.diylc.appframework.update.Change>
|
</org.diylc.appframework.update.Change>
|
||||||
|
<org.diylc.appframework.update.Change>
|
||||||
|
<changeType>NEW_FEATURE</changeType>
|
||||||
|
<description>Tube symbols can be rotated</description>
|
||||||
|
</org.diylc.appframework.update.Change>
|
||||||
<org.diylc.appframework.update.Change>
|
<org.diylc.appframework.update.Change>
|
||||||
<changeType>IMPROVEMENT</changeType>
|
<changeType>IMPROVEMENT</changeType>
|
||||||
<description>Added percent text box next to the slider for editors like Alpha or Scale</description>
|
<description>Added percent text box next to the slider for editors like Alpha or Scale</description>
|
||||||
|
|||||||
Reference in New Issue
Block a user