mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-10 09:12:09 +10:00
work on transformer symbols
This commit is contained in:
Binary file not shown.
@@ -24,9 +24,13 @@ import org.diylc.core.measures.Size;
|
|||||||
import org.diylc.core.measures.SizeUnit;
|
import org.diylc.core.measures.SizeUnit;
|
||||||
import org.diylc.utils.Constants;
|
import org.diylc.utils.Constants;
|
||||||
|
|
||||||
@ComponentDescriptor(name = "Transformer Coil Symbol", author = "Branislav Stojkovic", category = "Schematics",
|
@ComponentDescriptor(
|
||||||
instanceNamePrefix = "L", description = "Transformer coil symbol. Use multiple instances together with \"Transformer Core Symbol\"<br>to draw transformer schematics.", stretchable = false,
|
name = "Transformer Coil Symbol",
|
||||||
zOrder = IDIYComponent.COMPONENT, rotatable = true, keywordPolicy = KeywordPolicy.SHOW_TAG,
|
author = "Branislav Stojkovic",
|
||||||
|
category = "Schematics",
|
||||||
|
instanceNamePrefix = "L",
|
||||||
|
description = "Transformer coil symbol. Use multiple instances together with \"Transformer Core Symbol\"<br>to draw transformer schematics.",
|
||||||
|
stretchable = false, zOrder = IDIYComponent.COMPONENT, rotatable = true, keywordPolicy = KeywordPolicy.SHOW_TAG,
|
||||||
keywordTag = "Schematic")
|
keywordTag = "Schematic")
|
||||||
public class TransformerCoil extends AbstractComponent<org.diylc.core.measures.Voltage> {
|
public class TransformerCoil extends AbstractComponent<org.diylc.core.measures.Voltage> {
|
||||||
|
|
||||||
@@ -34,15 +38,15 @@ public class TransformerCoil extends AbstractComponent<org.diylc.core.measures.V
|
|||||||
|
|
||||||
public static Size TAP_SPACING = new Size(0.2d, SizeUnit.in);
|
public static Size TAP_SPACING = new Size(0.2d, SizeUnit.in);
|
||||||
public static Size LEAD_SPACING = new Size(0.1d, SizeUnit.in);
|
public static Size LEAD_SPACING = new Size(0.1d, SizeUnit.in);
|
||||||
|
public static Size OFFSET = new Size(0.025d, SizeUnit.in);
|
||||||
public static Color COLOR = Color.blue;
|
public static Color COLOR = Color.blue;
|
||||||
public static Color LEAD_COLOR = Color.black;
|
public static Color LEAD_COLOR = Color.black;
|
||||||
|
|
||||||
private int tapCount = 0;
|
private Point[] controlPoints = new Point[] {new Point(0, 0), new Point(0, 0)};
|
||||||
private 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), new Point(0, 0), new Point(0, 0), new Point(0, 0)};
|
|
||||||
private Orientation orientation = Orientation.DEFAULT;
|
private Orientation orientation = Orientation.DEFAULT;
|
||||||
private org.diylc.core.measures.Voltage voltage = null;
|
private org.diylc.core.measures.Voltage voltage = null;
|
||||||
protected Color color = COLOR;
|
private Color color = COLOR;
|
||||||
|
private Size tapSpacing = TAP_SPACING;
|
||||||
|
|
||||||
private Shape[] body = null;
|
private Shape[] body = null;
|
||||||
|
|
||||||
@@ -52,7 +56,7 @@ public class TransformerCoil extends AbstractComponent<org.diylc.core.measures.V
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void updateControlPoints() {
|
private void updateControlPoints() {
|
||||||
double spacing = TAP_SPACING.convertToPixels();
|
double spacing = this.getTapSpacing().convertToPixels();
|
||||||
int fx = 1;
|
int fx = 1;
|
||||||
int fy = 1;
|
int fy = 1;
|
||||||
switch (this.orientation) {
|
switch (this.orientation) {
|
||||||
@@ -74,11 +78,6 @@ public class TransformerCoil extends AbstractComponent<org.diylc.core.measures.V
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.tapCount == 0) {
|
|
||||||
fx *= 2;
|
|
||||||
fy *= 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
Point refPoint = this.controlPoints[0];
|
Point refPoint = this.controlPoints[0];
|
||||||
for (int i = 1; i < controlPoints.length; i++) {
|
for (int i = 1; i < controlPoints.length; i++) {
|
||||||
this.controlPoints[i].setLocation(refPoint.x + i * fx * spacing, refPoint.y + i * fy * spacing);
|
this.controlPoints[i].setLocation(refPoint.x + i * fx * spacing, refPoint.y + i * fy * spacing);
|
||||||
@@ -96,17 +95,6 @@ public class TransformerCoil extends AbstractComponent<org.diylc.core.measures.V
|
|||||||
this.voltage = value;
|
this.voltage = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@EditableProperty(name = "Number of Taps", defaultable = true)
|
|
||||||
public int getTapCount() {
|
|
||||||
return tapCount;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setTapCount(int tapCount) {
|
|
||||||
this.tapCount = tapCount;
|
|
||||||
updateControlPoints();
|
|
||||||
this.body = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@EditableProperty(defaultable = true)
|
@EditableProperty(defaultable = true)
|
||||||
public Orientation getOrientation() {
|
public Orientation getOrientation() {
|
||||||
return orientation;
|
return orientation;
|
||||||
@@ -120,7 +108,7 @@ public class TransformerCoil extends AbstractComponent<org.diylc.core.measures.V
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getControlPointCount() {
|
public int getControlPointCount() {
|
||||||
return this.tapCount + 2;
|
return this.controlPoints.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -153,6 +141,17 @@ public class TransformerCoil extends AbstractComponent<org.diylc.core.measures.V
|
|||||||
this.color = color;
|
this.color = color;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@EditableProperty(name = "Size")
|
||||||
|
public Size getTapSpacing() {
|
||||||
|
return tapSpacing;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTapSpacing(Size tapSpacing) {
|
||||||
|
this.tapSpacing = tapSpacing;
|
||||||
|
this.body = null;
|
||||||
|
updateControlPoints();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void draw(Graphics2D g2d, ComponentState componentState, boolean outlineMode, Project project,
|
public void draw(Graphics2D g2d, ComponentState componentState, boolean outlineMode, Project project,
|
||||||
IDrawingObserver drawingObserver) {
|
IDrawingObserver drawingObserver) {
|
||||||
@@ -178,7 +177,7 @@ public class TransformerCoil extends AbstractComponent<org.diylc.core.measures.V
|
|||||||
g2d.draw(body[0]);
|
g2d.draw(body[0]);
|
||||||
|
|
||||||
g2d.setColor(finalColor);
|
g2d.setColor(finalColor);
|
||||||
// g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(2));
|
// g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(2));
|
||||||
g2d.draw(body[1]);
|
g2d.draw(body[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -226,31 +225,37 @@ public class TransformerCoil extends AbstractComponent<org.diylc.core.measures.V
|
|||||||
GeneralPath leads = new GeneralPath();
|
GeneralPath leads = new GeneralPath();
|
||||||
GeneralPath coil = new GeneralPath();
|
GeneralPath coil = new GeneralPath();
|
||||||
|
|
||||||
int coilsPerTap = 3;
|
int coilsPerTap = (int) Math.round(4 * tapSpacing.convertToPixels() / TAP_SPACING.convertToPixels());
|
||||||
|
|
||||||
|
double offset = OFFSET.convertToPixels();
|
||||||
|
|
||||||
for (int i = 0; i < tapCount + 2; i++) {
|
int i = 0;
|
||||||
leads.moveTo(this.controlPoints[i].x, this.controlPoints[i].y);
|
leads.moveTo(this.controlPoints[i].x, this.controlPoints[i].y);
|
||||||
leads.lineTo(this.controlPoints[i].x + fx * spacing, this.controlPoints[i].y + fy * spacing);
|
leads.lineTo(this.controlPoints[i].x + fx * (spacing + offset), this.controlPoints[i].y + fy * (spacing + offset));
|
||||||
|
leads.moveTo(this.controlPoints[i + 1].x, this.controlPoints[i + 1].y);
|
||||||
|
leads.lineTo(this.controlPoints[i + 1].x + fx * (spacing + offset), this.controlPoints[i + 1].y + fy * (spacing + offset));
|
||||||
|
|
||||||
int dx = this.controlPoints[i + 1].x - this.controlPoints[i].x;
|
double dx = this.controlPoints[i + 1].getX() - this.controlPoints[i].getX();
|
||||||
int dy = this.controlPoints[i + 1].y - this.controlPoints[i].y;
|
double dy = this.controlPoints[i + 1].getY() - this.controlPoints[i].getY();
|
||||||
// skip the last tap
|
double d = Math.max(Math.abs(dx), Math.abs(dy)) / coilsPerTap;
|
||||||
if (i < tapCount + 1) {
|
|
||||||
double x1 = this.controlPoints[i].x + fx * spacing * 2;
|
double x1 = this.controlPoints[i].getX() + fx * (spacing + d + offset);
|
||||||
double y1 = this.controlPoints[i].y + fy * spacing * 2;
|
double y1 = this.controlPoints[i].getY() + fy * (spacing + d + offset);
|
||||||
double x2 = this.controlPoints[i + 1].x + fx * spacing * 2;
|
double x2 = this.controlPoints[i + 1].getX() + fx * (spacing + d + offset);
|
||||||
double y2 = this.controlPoints[i + 1].y + fy * spacing * 2;
|
double y2 = this.controlPoints[i + 1].y + fy * (spacing + d + offset);
|
||||||
double dxa = x2 - x1;
|
double dxa = x2 - x1;
|
||||||
double dya = y2 - y1;
|
double dya = y2 - y1;
|
||||||
|
|
||||||
coil.moveTo(this.controlPoints[i].x + fx * spacing, this.controlPoints[i].y + fy * spacing);
|
coil.moveTo(this.controlPoints[i].getX() + fx * (spacing + offset), this.controlPoints[i].getY() + fy * (spacing + offset));
|
||||||
|
|
||||||
for (int j = 0; j < coilsPerTap; j++) {
|
for (int j = 0; j < coilsPerTap; j++) {
|
||||||
coil.curveTo(x1 + dxa / coilsPerTap * j, y1 + dya / coilsPerTap * j, x1 + dxa / coilsPerTap * (j + 1), y1
|
coil.curveTo(
|
||||||
+ dya / coilsPerTap * (j + 1), this.controlPoints[i].x + fx * spacing + dx / coilsPerTap * (j + 1),
|
x1 + dxa / coilsPerTap * j,
|
||||||
this.controlPoints[i].y + fy * spacing + dy / coilsPerTap * (j + 1));
|
y1 + dya / coilsPerTap * j,
|
||||||
}
|
x1 + dxa / coilsPerTap * (j + 1),
|
||||||
}
|
y1 + dya / coilsPerTap * (j + 1),
|
||||||
|
this.controlPoints[i].getX() + fx * (spacing + offset) + dx / coilsPerTap * (j + 1),
|
||||||
|
this.controlPoints[i].getY() + fy * (spacing + offset) + dy / coilsPerTap * (j + 1));
|
||||||
}
|
}
|
||||||
body = new Shape[2];
|
body = new Shape[2];
|
||||||
|
|
||||||
|
|||||||
@@ -29,13 +29,13 @@ import org.diylc.utils.Constants;
|
|||||||
category = "Schematics",
|
category = "Schematics",
|
||||||
instanceNamePrefix = "T",
|
instanceNamePrefix = "T",
|
||||||
description = "Transformer core symbol. Use multiple instances together with \"Transformer Coil Symbol\"<br>to draw transformer schematics.",
|
description = "Transformer core symbol. Use multiple instances together with \"Transformer Coil Symbol\"<br>to draw transformer schematics.",
|
||||||
stretchable = false, zOrder = IDIYComponent.COMPONENT, rotatable = true, keywordPolicy = KeywordPolicy.SHOW_TAG,
|
stretchable = true, zOrder = IDIYComponent.COMPONENT, rotatable = true, keywordPolicy = KeywordPolicy.SHOW_TAG,
|
||||||
creationMethod = CreationMethod.POINT_BY_POINT, keywordTag = "Schematic")
|
creationMethod = CreationMethod.POINT_BY_POINT, keywordTag = "Schematic")
|
||||||
public class TransformerCore extends AbstractComponent<Void> {
|
public class TransformerCore extends AbstractComponent<Void> {
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
public static Size SPACING = new Size(0.03d, SizeUnit.in);
|
public static Size SPACING = new Size(0.025d, SizeUnit.in);
|
||||||
public static Color COLOR = Color.blue;
|
public static Color COLOR = Color.blue;
|
||||||
|
|
||||||
private Point[] controlPoints = new Point[] {new Point(0, 0), new Point(0, 0)};
|
private Point[] controlPoints = new Point[] {new Point(0, 0), new Point(0, 0)};
|
||||||
@@ -118,10 +118,10 @@ public class TransformerCore extends AbstractComponent<Void> {
|
|||||||
g2d.setColor(COLOR);
|
g2d.setColor(COLOR);
|
||||||
|
|
||||||
GeneralPath polyline = new GeneralPath();
|
GeneralPath polyline = new GeneralPath();
|
||||||
polyline.moveTo(width / 8, height / 2);
|
polyline.moveTo(0, height * 7 / 16);
|
||||||
polyline.curveTo(width / 8, height / 4, width * 3 / 8, height / 4, width * 3 / 8, height / 2);
|
polyline.lineTo(width, height * 7 / 16);
|
||||||
polyline.curveTo(width * 3 / 8, height / 4, width * 5 / 8, height / 4, width * 5 / 8, height / 2);
|
polyline.moveTo(0, height * 9 / 16);
|
||||||
polyline.curveTo(width * 5 / 8, height / 4, width * 7 / 8, height / 4, width * 7 / 8, height / 2);
|
polyline.lineTo(width, height * 9 / 16);
|
||||||
|
|
||||||
g2d.draw(polyline);
|
g2d.draw(polyline);
|
||||||
}
|
}
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
@@ -1342,6 +1342,10 @@
|
|||||||
<changeType>NEW_FEATURE</changeType>
|
<changeType>NEW_FEATURE</changeType>
|
||||||
<description>Project Cloud feature introduced with global project sharing functionality</description>
|
<description>Project Cloud feature introduced with global project sharing functionality</description>
|
||||||
</org.diylc.appframework.update.Change>
|
</org.diylc.appframework.update.Change>
|
||||||
|
<org.diylc.appframework.update.Change>
|
||||||
|
<changeType>NEW_FEATURE</changeType>
|
||||||
|
<description>Transformer core and coil schematic symbols added that can be used to put together custom transformer symbols</description>
|
||||||
|
</org.diylc.appframework.update.Change>
|
||||||
<org.diylc.appframework.update.Change>
|
<org.diylc.appframework.update.Change>
|
||||||
<changeType>NEW_FEATURE</changeType>
|
<changeType>NEW_FEATURE</changeType>
|
||||||
<description>Added Public Announcements feature</description>
|
<description>Added Public Announcements feature</description>
|
||||||
|
|||||||
Reference in New Issue
Block a user