mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-10 17:22:09 +10:00
Potentiometers can show an optional shaft, can have either solder lugs
or PCB pins and rendering includes the wafer
This commit is contained in:
@@ -6,9 +6,11 @@ import java.awt.Composite;
|
|||||||
import java.awt.FontMetrics;
|
import java.awt.FontMetrics;
|
||||||
import java.awt.Graphics2D;
|
import java.awt.Graphics2D;
|
||||||
import java.awt.Point;
|
import java.awt.Point;
|
||||||
|
import java.awt.Polygon;
|
||||||
import java.awt.geom.Area;
|
import java.awt.geom.Area;
|
||||||
import java.awt.geom.Ellipse2D;
|
import java.awt.geom.Ellipse2D;
|
||||||
import java.awt.geom.Rectangle2D;
|
import java.awt.geom.Rectangle2D;
|
||||||
|
import java.awt.geom.RoundRectangle2D;
|
||||||
|
|
||||||
import org.diylc.appframework.miscutils.ConfigurationManager;
|
import org.diylc.appframework.miscutils.ConfigurationManager;
|
||||||
import org.diylc.common.IPlugInPort;
|
import org.diylc.common.IPlugInPort;
|
||||||
@@ -27,7 +29,7 @@ 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 = "Potentiometer (panel mount)", author = "Branislav Stojkovic", category = "Passive",
|
@ComponentDescriptor(name = "Potentiometer", author = "Branislav Stojkovic", category = "Passive",
|
||||||
creationMethod = CreationMethod.SINGLE_CLICK, instanceNamePrefix = "VR",
|
creationMethod = CreationMethod.SINGLE_CLICK, instanceNamePrefix = "VR",
|
||||||
description = "Panel mount potentiometer with solder lugs", zOrder = IDIYComponent.COMPONENT, stretchable = false,
|
description = "Panel mount potentiometer with solder lugs", zOrder = IDIYComponent.COMPONENT, stretchable = false,
|
||||||
transformer = PotentiometerTransformer.class)
|
transformer = PotentiometerTransformer.class)
|
||||||
@@ -38,14 +40,24 @@ public class PotentiometerPanel extends AbstractPotentiometer {
|
|||||||
protected static Size BODY_DIAMETER = new Size(1d, SizeUnit.in);
|
protected static Size BODY_DIAMETER = new Size(1d, SizeUnit.in);
|
||||||
protected static Size SPACING = new Size(0.3d, SizeUnit.in);
|
protected static Size SPACING = new Size(0.3d, SizeUnit.in);
|
||||||
protected static Size LUG_DIAMETER = new Size(0.15d, SizeUnit.in);
|
protected static Size LUG_DIAMETER = new Size(0.15d, SizeUnit.in);
|
||||||
protected static Color BODY_COLOR = Color.gray.brighter();
|
protected static Size PIN_SIZE = new Size(0.05d, SizeUnit.in);
|
||||||
|
protected static Size NUT_SIZE = new Size(0.4d, SizeUnit.in);
|
||||||
|
protected static Size SHAFT_SIZE = new Size(1 / 4d, SizeUnit.in);
|
||||||
|
protected static Color BODY_COLOR = Color.lightGray;
|
||||||
|
protected static Color WAFER_COLOR = Color.decode("#CD8500");
|
||||||
protected static Color BORDER_COLOR = Color.gray;
|
protected static Color BORDER_COLOR = Color.gray;
|
||||||
|
protected static Color NUT_COLOR = Color.decode("#CBD5DB");
|
||||||
|
|
||||||
|
|
||||||
protected Size bodyDiameter = BODY_DIAMETER;
|
protected Size bodyDiameter = BODY_DIAMETER;
|
||||||
protected Size spacing = SPACING;
|
protected Size spacing = SPACING;
|
||||||
protected Size lugDiameter = LUG_DIAMETER;
|
protected Size lugDiameter = LUG_DIAMETER;
|
||||||
protected Color bodyColor = BODY_COLOR;
|
protected Color bodyColor = BODY_COLOR;
|
||||||
protected Color borderColor = BORDER_COLOR;
|
protected Color borderColor = BORDER_COLOR;
|
||||||
|
protected Color nutColor = NUT_COLOR;
|
||||||
|
protected Color waferColor = WAFER_COLOR;
|
||||||
|
protected Type type = Type.ThroughHole;
|
||||||
|
protected boolean showShaft = false;
|
||||||
// Array of 7 elements: 3 lug connectors, 1 pot body and 3 lugs
|
// Array of 7 elements: 3 lug connectors, 1 pot body and 3 lugs
|
||||||
transient protected Area[] body = null;
|
transient protected Area[] body = null;
|
||||||
|
|
||||||
@@ -82,71 +94,123 @@ public class PotentiometerPanel extends AbstractPotentiometer {
|
|||||||
int spacing = (int) this.spacing.convertToPixels();
|
int spacing = (int) this.spacing.convertToPixels();
|
||||||
int diameter = getClosestOdd(bodyDiameter.convertToPixels());
|
int diameter = getClosestOdd(bodyDiameter.convertToPixels());
|
||||||
if (body == null) {
|
if (body == null) {
|
||||||
body = new Area[7];
|
// mandatory: 0, 1, 2 pins, 3 body, 9 wafer
|
||||||
|
// optional: 4, 5, 6 lugs, 7 nut, 8 shaft
|
||||||
|
body = new Area[10];
|
||||||
|
|
||||||
// Add lugs.
|
// Add lugs.
|
||||||
int lugDiameter = getClosestOdd(this.lugDiameter.convertToPixels());
|
int pinWidth = (int) PIN_SIZE.convertToPixels();
|
||||||
int holeDiameter = getClosestOdd(this.lugDiameter.convertToPixels() / 2);
|
|
||||||
for (int i = 0; i < 3; i++) {
|
int centerX = 0;
|
||||||
Area area =
|
int centerY = 0;
|
||||||
new Area(new Ellipse2D.Double(controlPoints[i].x - lugDiameter / 2, controlPoints[i].y - lugDiameter / 2,
|
|
||||||
lugDiameter, lugDiameter));
|
double waferWidth = 2.5 * spacing;
|
||||||
body[4 + i] = area;
|
double waferHeight = spacing;
|
||||||
}
|
|
||||||
|
|
||||||
switch (orientation) {
|
switch (orientation) {
|
||||||
case DEFAULT:
|
case DEFAULT:
|
||||||
body[3] =
|
centerX = controlPoints[0].x + spacing;
|
||||||
new Area(new Ellipse2D.Double(controlPoints[0].x + spacing - diameter / 2, controlPoints[0].y - spacing
|
centerY = controlPoints[0].y - spacing / 2 - diameter / 2;
|
||||||
/ 2 - diameter, diameter, diameter));
|
|
||||||
|
body[9] =
|
||||||
|
new Area(new RoundRectangle2D.Double(centerX - waferWidth / 2, controlPoints[0].y - waferHeight - spacing
|
||||||
|
/ 2, waferWidth, waferHeight, spacing / 4, spacing / 4));
|
||||||
|
|
||||||
for (int i = 0; i < 3; i++) {
|
for (int i = 0; i < 3; i++) {
|
||||||
body[i] =
|
body[i] =
|
||||||
new Area(new Rectangle2D.Double(controlPoints[i].x - holeDiameter / 2, controlPoints[i].y
|
new Area(new Rectangle2D.Double(controlPoints[i].x - pinWidth / 2, controlPoints[i].y
|
||||||
- (spacing + diameter) / 2, holeDiameter, (spacing + diameter) / 2));
|
- (spacing + diameter) / 2, pinWidth, (spacing + diameter) / 2));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case _90:
|
case _90:
|
||||||
body[3] =
|
centerX = controlPoints[0].x + spacing / 2 + diameter / 2;
|
||||||
new Area(new Ellipse2D.Double(controlPoints[0].x + spacing / 2, controlPoints[0].y + spacing - diameter
|
centerY = controlPoints[0].y + spacing;
|
||||||
/ 2, diameter, diameter));
|
|
||||||
|
body[9] =
|
||||||
|
new Area(new RoundRectangle2D.Double(controlPoints[0].x + spacing / 2, centerY - waferWidth / 2,
|
||||||
|
waferHeight, waferWidth, spacing / 4, spacing / 4));
|
||||||
|
|
||||||
for (int i = 0; i < 3; i++) {
|
for (int i = 0; i < 3; i++) {
|
||||||
body[i] =
|
body[i] =
|
||||||
new Area(new Rectangle2D.Double(controlPoints[i].x, controlPoints[i].y - holeDiameter / 2,
|
new Area(new Rectangle2D.Double(controlPoints[i].x, controlPoints[i].y - pinWidth / 2,
|
||||||
(spacing + diameter) / 2, holeDiameter));
|
(spacing + diameter) / 2, pinWidth));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case _180:
|
case _180:
|
||||||
body[3] =
|
centerX = controlPoints[0].x - spacing;
|
||||||
new Area(new Ellipse2D.Double(controlPoints[0].x - spacing - diameter / 2, controlPoints[0].y + spacing
|
centerY = controlPoints[0].y + spacing / 2 + diameter / 2;
|
||||||
/ 2, diameter, diameter));
|
|
||||||
|
body[9] =
|
||||||
|
new Area(new RoundRectangle2D.Double(centerX - waferWidth / 2, controlPoints[0].y + spacing / 2,
|
||||||
|
waferWidth, waferHeight, spacing / 4, spacing / 4));
|
||||||
|
|
||||||
for (int i = 0; i < 3; i++) {
|
for (int i = 0; i < 3; i++) {
|
||||||
body[i] =
|
body[i] =
|
||||||
new Area(new Rectangle2D.Double(controlPoints[i].x - holeDiameter / 2, controlPoints[i].y,
|
new Area(new Rectangle2D.Double(controlPoints[i].x - pinWidth / 2, controlPoints[i].y, pinWidth,
|
||||||
holeDiameter, (spacing + diameter) / 2));
|
(spacing + diameter) / 2));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case _270:
|
case _270:
|
||||||
body[3] =
|
centerX = controlPoints[0].x - spacing / 2 - diameter / 2;
|
||||||
new Area(new Ellipse2D.Double(controlPoints[0].x - spacing / 2 - diameter, controlPoints[0].y - spacing
|
centerY = controlPoints[0].y - spacing;
|
||||||
- diameter / 2, diameter, diameter));
|
|
||||||
|
body[9] =
|
||||||
|
new Area(new RoundRectangle2D.Double(controlPoints[0].x - waferHeight - spacing / 2, centerY - waferWidth
|
||||||
|
/ 2, waferHeight, waferWidth, spacing / 4, spacing / 4));
|
||||||
|
|
||||||
for (int i = 0; i < 3; i++) {
|
for (int i = 0; i < 3; i++) {
|
||||||
body[i] =
|
body[i] =
|
||||||
new Area(new Rectangle2D.Double(controlPoints[i].x - (spacing + diameter) / 2, controlPoints[i].y
|
new Area(new Rectangle2D.Double(controlPoints[i].x - (spacing + diameter) / 2, controlPoints[i].y
|
||||||
- holeDiameter / 2, (spacing + diameter) / 2, holeDiameter));
|
- pinWidth / 2, (spacing + diameter) / 2, pinWidth));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
body[3] = new Area(new Ellipse2D.Double(centerX - diameter / 2, centerY - diameter / 2, diameter, diameter));
|
||||||
|
|
||||||
|
body[9].subtract(body[3]);
|
||||||
|
|
||||||
for (int i = 0; i < 3; i++) {
|
for (int i = 0; i < 3; i++) {
|
||||||
for (int j = 3; j < 7; j++) {
|
body[i].subtract(body[3]);
|
||||||
body[i].subtract(body[j]);
|
}
|
||||||
|
|
||||||
|
if (getType() == Type.ThroughHole) {
|
||||||
|
int lugDiameter = getClosestOdd(this.lugDiameter.convertToPixels());
|
||||||
|
int holeDiameter = getClosestOdd(this.lugDiameter.convertToPixels() / 2);
|
||||||
|
|
||||||
|
for (int i = 0; i < 3; i++) {
|
||||||
|
Area area =
|
||||||
|
new Area(new Ellipse2D.Double(controlPoints[i].x - lugDiameter / 2, controlPoints[i].y - lugDiameter / 2,
|
||||||
|
lugDiameter, lugDiameter));
|
||||||
|
body[4 + i] = area;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < 3; i++) {
|
||||||
|
for (int j = 0; j < 3; j++) {
|
||||||
|
body[i].subtract(body[4 + j]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Make holes in the lugs.
|
||||||
|
for (int i = 0; i < 3; i++) {
|
||||||
|
body[4 + i].subtract(new Area(new Ellipse2D.Double(controlPoints[i].x - holeDiameter / 2, controlPoints[i].y
|
||||||
|
- holeDiameter / 2, holeDiameter, holeDiameter)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Make holes in the lugs.
|
if (getShowShaft()) {
|
||||||
for (int i = 0; i < 3; i++) {
|
int nutSize = (int) NUT_SIZE.convertToPixels();
|
||||||
body[4 + i].subtract(new Area(new Ellipse2D.Double(controlPoints[i].x - holeDiameter / 2, controlPoints[i].y
|
int shaftSize = (int) SHAFT_SIZE.convertToPixels();
|
||||||
- holeDiameter / 2, holeDiameter, holeDiameter)));
|
int[] xPoints = new int[6];
|
||||||
|
int[] yPoints = new int[6];
|
||||||
|
for (int i = 0; i < 6; i++) {
|
||||||
|
double alpha = Math.toRadians(60 * i);
|
||||||
|
xPoints[i] = (int) (centerX + Math.cos(alpha) * nutSize / 2);
|
||||||
|
yPoints[i] = (int) (centerY + Math.sin(alpha) * nutSize / 2);
|
||||||
|
}
|
||||||
|
body[7] = new Area(new Polygon(xPoints, yPoints, 6));
|
||||||
|
body[8] =
|
||||||
|
new Area(new Ellipse2D.Double(centerX - shaftSize / 2, centerY - shaftSize / 2, shaftSize, shaftSize));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return body;
|
return body;
|
||||||
@@ -170,9 +234,22 @@ public class PotentiometerPanel extends AbstractPotentiometer {
|
|||||||
IDrawingObserver drawingObserver) {
|
IDrawingObserver drawingObserver) {
|
||||||
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(1));
|
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(1));
|
||||||
Theme theme = (Theme) ConfigurationManager.getInstance().readObject(IPlugInPort.THEME_KEY, Constants.DEFAULT_THEME);
|
Theme theme = (Theme) ConfigurationManager.getInstance().readObject(IPlugInPort.THEME_KEY, Constants.DEFAULT_THEME);
|
||||||
for (Area shape : getBody()) {
|
Area[] body = getBody();
|
||||||
|
for (int i = 0; i < body.length; i++) {
|
||||||
|
Area shape = body[i];
|
||||||
|
// determine color
|
||||||
if (shape != null) {
|
if (shape != null) {
|
||||||
g2d.setColor(bodyColor);
|
switch (i) {
|
||||||
|
case 7:
|
||||||
|
g2d.setColor(getNutColor());
|
||||||
|
break;
|
||||||
|
case 9:
|
||||||
|
g2d.setColor(getWaferColor());
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
g2d.setColor(getBodyColor());
|
||||||
|
}
|
||||||
|
|
||||||
Composite oldComposite = g2d.getComposite();
|
Composite oldComposite = g2d.getComposite();
|
||||||
if (alpha < MAX_ALPHA) {
|
if (alpha < MAX_ALPHA) {
|
||||||
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1f * alpha / MAX_ALPHA));
|
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1f * alpha / MAX_ALPHA));
|
||||||
@@ -189,7 +266,7 @@ public class PotentiometerPanel extends AbstractPotentiometer {
|
|||||||
} else {
|
} else {
|
||||||
finalBorderColor =
|
finalBorderColor =
|
||||||
componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING ? SELECTION_COLOR
|
componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING ? SELECTION_COLOR
|
||||||
: borderColor;
|
: getBorderColor();
|
||||||
}
|
}
|
||||||
g2d.setColor(finalBorderColor);
|
g2d.setColor(finalBorderColor);
|
||||||
g2d.draw(shape);
|
g2d.draw(shape);
|
||||||
@@ -265,6 +342,29 @@ public class PotentiometerPanel extends AbstractPotentiometer {
|
|||||||
body = null;
|
body = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@EditableProperty
|
||||||
|
public Type getType() {
|
||||||
|
if (type == null)
|
||||||
|
type = Type.ThroughHole;
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setType(Type type) {
|
||||||
|
this.type = type;
|
||||||
|
body = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@EditableProperty(name = "Nut")
|
||||||
|
public Color getNutColor() {
|
||||||
|
if (nutColor == null)
|
||||||
|
nutColor = NUT_COLOR;
|
||||||
|
return nutColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNutColor(Color nutColor) {
|
||||||
|
this.nutColor = nutColor;
|
||||||
|
}
|
||||||
|
|
||||||
@EditableProperty(name = "Diameter")
|
@EditableProperty(name = "Diameter")
|
||||||
public Size getBodyDiameter() {
|
public Size getBodyDiameter() {
|
||||||
return bodyDiameter;
|
return bodyDiameter;
|
||||||
@@ -302,4 +402,40 @@ public class PotentiometerPanel extends AbstractPotentiometer {
|
|||||||
public void setBorderColor(Color borderColor) {
|
public void setBorderColor(Color borderColor) {
|
||||||
this.borderColor = borderColor;
|
this.borderColor = borderColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@EditableProperty(name = "Show shaft")
|
||||||
|
public boolean getShowShaft() {
|
||||||
|
return showShaft;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setShowShaft(boolean showShaft) {
|
||||||
|
this.showShaft = showShaft;
|
||||||
|
this.body = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@EditableProperty(name = "Wafer")
|
||||||
|
public Color getWaferColor() {
|
||||||
|
if (waferColor == null)
|
||||||
|
waferColor = WAFER_COLOR;
|
||||||
|
return waferColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setWaferColor(Color waferColor) {
|
||||||
|
this.waferColor = waferColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum Type {
|
||||||
|
ThroughHole("Through Hole"), PCB("PCB");
|
||||||
|
|
||||||
|
private String value;
|
||||||
|
|
||||||
|
private Type(String value) {
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
@@ -1749,5 +1749,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>40</minor>
|
||||||
|
<build>0</build>
|
||||||
|
</versionNumber>
|
||||||
|
<releaseDate>2017-04-25 00:00:00.000 CET</releaseDate>
|
||||||
|
<name></name>
|
||||||
|
<changes>
|
||||||
|
<org.diylc.appframework.update.Change>
|
||||||
|
<changeType>NEW_FEATURE</changeType>
|
||||||
|
<description>Potentiometers can show an optional shaft, can have either solder lugs or PCB pins and rendering includes the wafer</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