mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-10 17:22:09 +10:00
Ability to change resistor shape (tubular or standard "dog bone")
This commit is contained in:
@@ -39,6 +39,7 @@ public class Resistor extends AbstractLeadedComponent<Resistance> {
|
|||||||
private Power power = Power.HALF;
|
private Power power = Power.HALF;
|
||||||
private org.diylc.core.measures.Power powerNew = null;
|
private org.diylc.core.measures.Power powerNew = null;
|
||||||
private ResistorColorCode colorCode = ResistorColorCode._5_BAND;
|
private ResistorColorCode colorCode = ResistorColorCode._5_BAND;
|
||||||
|
private ResistorShape shape = ResistorShape.Standard;
|
||||||
|
|
||||||
public Resistor() {
|
public Resistor() {
|
||||||
super();
|
super();
|
||||||
@@ -122,8 +123,20 @@ public class Resistor extends AbstractLeadedComponent<Resistance> {
|
|||||||
this.colorCode = colorCode;
|
this.colorCode = colorCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@EditableProperty
|
||||||
|
public ResistorShape getShape() {
|
||||||
|
if (shape == null)
|
||||||
|
shape = ResistorShape.Standard;
|
||||||
|
return shape;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setShape(ResistorShape shape) {
|
||||||
|
this.shape = shape;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Shape getBodyShape() {
|
protected Shape getBodyShape() {
|
||||||
|
if (shape == ResistorShape.Standard) {
|
||||||
double length = getLength().convertToPixels();
|
double length = getLength().convertToPixels();
|
||||||
double width = getClosestOdd(getWidth().convertToPixels());
|
double width = getClosestOdd(getWidth().convertToPixels());
|
||||||
Rectangle2D rect = new Rectangle2D.Double(width / 2, width / 10, length - width, width * 8 / 10);
|
Rectangle2D rect = new Rectangle2D.Double(width / 2, width / 10, length - width, width * 8 / 10);
|
||||||
@@ -132,6 +145,8 @@ public class Resistor extends AbstractLeadedComponent<Resistance> {
|
|||||||
a.add(new Area(new Ellipse2D.Double(length - width, 0, width, width)));
|
a.add(new Area(new Ellipse2D.Double(length - width, 0, width, width)));
|
||||||
return a;
|
return a;
|
||||||
}
|
}
|
||||||
|
return new Rectangle2D.Double(0f, 0f, getLength().convertToPixels(), getClosestOdd(getWidth().convertToPixels()));
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void decorateComponentBody(Graphics2D g2d, boolean outlineMode) {
|
protected void decorateComponentBody(Graphics2D g2d, boolean outlineMode) {
|
||||||
@@ -139,6 +154,7 @@ public class Resistor extends AbstractLeadedComponent<Resistance> {
|
|||||||
if (colorCode == ResistorColorCode.NONE || outlineMode || value == null) {
|
if (colorCode == ResistorColorCode.NONE || outlineMode || value == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (shape == ResistorShape.Standard) {
|
||||||
int width = getClosestOdd(getWidth().convertToPixels());
|
int width = getClosestOdd(getWidth().convertToPixels());
|
||||||
Color[] bands = value.getColorCode(colorCode);
|
Color[] bands = value.getColorCode(colorCode);
|
||||||
int x = width + FIRST_BAND;
|
int x = width + FIRST_BAND;
|
||||||
@@ -148,6 +164,17 @@ public class Resistor extends AbstractLeadedComponent<Resistance> {
|
|||||||
g2d.drawLine(x, width / 10 + 2, x, width * 8 / 10 + 1);
|
g2d.drawLine(x, width / 10 + 2, x, width * 8 / 10 + 1);
|
||||||
x += BAND_SPACING;
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -167,4 +194,8 @@ public class Resistor extends AbstractLeadedComponent<Resistance> {
|
|||||||
public boolean getFlipStanding() {
|
public boolean getFlipStanding() {
|
||||||
return super.getFlipStanding();
|
return super.getFlipStanding();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public enum ResistorShape {
|
||||||
|
Tubular, Standard
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Binary file not shown.
@@ -1551,7 +1551,7 @@
|
|||||||
<minor>36</minor>
|
<minor>36</minor>
|
||||||
<build>0</build>
|
<build>0</build>
|
||||||
</versionNumber>
|
</versionNumber>
|
||||||
<releaseDate>2017-01-05 20:00:00.000 CET</releaseDate>
|
<releaseDate>2017-01-26 20:00:00.000 CET</releaseDate>
|
||||||
<name></name>
|
<name></name>
|
||||||
<changes>
|
<changes>
|
||||||
<org.diylc.appframework.update.Change>
|
<org.diylc.appframework.update.Change>
|
||||||
@@ -1613,5 +1613,21 @@
|
|||||||
</changes>
|
</changes>
|
||||||
<url>https://github.com/bancika/diy-layout-creator/releases</url>
|
<url>https://github.com/bancika/diy-layout-creator/releases</url>
|
||||||
</org.diylc.appframework.update.Version>
|
</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>
|
</a>
|
||||||
</java.util.Arrays_-ArrayList>
|
</java.util.Arrays_-ArrayList>
|
||||||
Reference in New Issue
Block a user