Ability to change resistor shape (tubular or standard "dog bone")

This commit is contained in:
bancika
2017-01-26 16:31:08 +01:00
parent c1c87a2454
commit 3423f00c15
3 changed files with 63 additions and 16 deletions
@@ -39,6 +39,7 @@ public class Resistor extends AbstractLeadedComponent<Resistance> {
private Power power = Power.HALF;
private org.diylc.core.measures.Power powerNew = null;
private ResistorColorCode colorCode = ResistorColorCode._5_BAND;
private ResistorShape shape = ResistorShape.Standard;
public Resistor() {
super();
@@ -122,15 +123,29 @@ public class Resistor extends AbstractLeadedComponent<Resistance> {
this.colorCode = colorCode;
}
@EditableProperty
public ResistorShape getShape() {
if (shape == null)
shape = ResistorShape.Standard;
return shape;
}
public void setShape(ResistorShape shape) {
this.shape = shape;
}
@Override
protected Shape getBodyShape() {
double length = getLength().convertToPixels();
double width = getClosestOdd(getWidth().convertToPixels());
Rectangle2D rect = new Rectangle2D.Double(width / 2, width / 10, length - width, width * 8 / 10);
Area a = new Area(rect);
a.add(new Area(new Ellipse2D.Double(0, 0, width, width)));
a.add(new Area(new Ellipse2D.Double(length - width, 0, width, width)));
return a;
if (shape == ResistorShape.Standard) {
double length = getLength().convertToPixels();
double width = getClosestOdd(getWidth().convertToPixels());
Rectangle2D rect = new Rectangle2D.Double(width / 2, width / 10, length - width, width * 8 / 10);
Area a = new Area(rect);
a.add(new Area(new Ellipse2D.Double(0, 0, width, width)));
a.add(new Area(new Ellipse2D.Double(length - width, 0, width, width)));
return a;
}
return new Rectangle2D.Double(0f, 0f, getLength().convertToPixels(), getClosestOdd(getWidth().convertToPixels()));
}
@Override
@@ -139,14 +154,26 @@ public class Resistor extends AbstractLeadedComponent<Resistance> {
if (colorCode == ResistorColorCode.NONE || outlineMode || value == null) {
return;
}
int width = getClosestOdd(getWidth().convertToPixels());
Color[] bands = value.getColorCode(colorCode);
int x = width + FIRST_BAND;
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(2));
for (int i = 0; i < bands.length; i++) {
g2d.setColor(bands[i]);
g2d.drawLine(x, width / 10 + 2, x, width * 8 / 10 + 1);
x += BAND_SPACING;
if (shape == ResistorShape.Standard) {
int width = getClosestOdd(getWidth().convertToPixels());
Color[] bands = value.getColorCode(colorCode);
int x = width + FIRST_BAND;
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(2));
for (int i = 0; i < bands.length; i++) {
g2d.setColor(bands[i]);
g2d.drawLine(x, width / 10 + 2, x, width * 8 / 10 + 1);
x += BAND_SPACING;
}
} else {
int height = getClosestOdd(getWidth().convertToPixels());
Color[] bands = value.getColorCode(colorCode);
int x = FIRST_BAND;
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(2));
for (int i = 0; i < bands.length; i++) {
g2d.setColor(bands[i]);
g2d.drawLine(x, 1, x, height - 1);
x += BAND_SPACING;
}
}
}
@@ -167,4 +194,8 @@ public class Resistor extends AbstractLeadedComponent<Resistance> {
public boolean getFlipStanding() {
return super.getFlipStanding();
}
public enum ResistorShape {
Tubular, Standard
}
}
Binary file not shown.
+17 -1
View File
@@ -1551,7 +1551,7 @@
<minor>36</minor>
<build>0</build>
</versionNumber>
<releaseDate>2017-01-05 20:00:00.000 CET</releaseDate>
<releaseDate>2017-01-26 20:00:00.000 CET</releaseDate>
<name></name>
<changes>
<org.diylc.appframework.update.Change>
@@ -1612,6 +1612,22 @@
</org.diylc.appframework.update.Change>
</changes>
<url>https://github.com/bancika/diy-layout-creator/releases</url>
</org.diylc.appframework.update.Version>
<org.diylc.appframework.update.Version>
<versionNumber>
<major>3</major>
<minor>37</minor>
<build>0</build>
</versionNumber>
<releaseDate>2017-01-26 20:00:00.000 CET</releaseDate>
<name></name>
<changes>
<org.diylc.appframework.update.Change>
<changeType>IMPROVEMENT</changeType>
<description>Ability to change resistor shape (tubular or standard "dog bone")</description>
</org.diylc.appframework.update.Change>
</changes>
<url>https://github.com/bancika/diy-layout-creator/releases</url>
</org.diylc.appframework.update.Version>
</a>
</java.util.Arrays_-ArrayList>