mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-11 01:32:08 +10:00
more flexible leads support
This commit is contained in:
@@ -3000,7 +3000,7 @@
|
||||
<changes>
|
||||
<org.diylc.appframework.update.Change>
|
||||
<changeType>NEW_FEATURE</changeType>
|
||||
<description>"Add Flexible Leads" action added in the context menu that replaces straight leads of leaded components with flexible leads and adds leds to some components that do not have them</description>
|
||||
<description>"Add Flexible Leads" action added in the context menu that replaces straight leads of leaded components with flexible leads and adds leds to some components that do not have them (e.g. Transistors, Tube Sockets, Potentiometers, etc)</description>
|
||||
</org.diylc.appframework.update.Change>
|
||||
<org.diylc.appframework.update.Change>
|
||||
<changeType>NEW_FEATURE</changeType>
|
||||
|
||||
+1
-1
@@ -372,7 +372,7 @@ public class RotarySelectorSwitch extends AbstractMultiPartComponent<String> {
|
||||
}
|
||||
|
||||
|
||||
public enum RotaryPositionCount {
|
||||
public static enum RotaryPositionCount {
|
||||
TWO(2), THREE(3), FOUR(4);
|
||||
|
||||
private int count;
|
||||
|
||||
@@ -189,53 +189,55 @@ public class TransistorTO126 extends AbstractTransistorPackage {
|
||||
// Draw pins.
|
||||
|
||||
if (folded) {
|
||||
int leadThickness = getClosestOdd(LEAD_THICKNESS.convertToPixels());
|
||||
int leadLength = (int) getLeadLength().convertToPixels();
|
||||
Color finalPinColor;
|
||||
Color finalPinBorderColor;
|
||||
if (outlineMode) {
|
||||
finalPinColor = new Color(0, 0, 0, 0);
|
||||
finalPinBorderColor =
|
||||
componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING ? SELECTION_COLOR
|
||||
: theme.getOutlineColor();
|
||||
} else {
|
||||
finalPinColor = METAL_COLOR;
|
||||
finalPinBorderColor = METAL_COLOR.darker();
|
||||
}
|
||||
for (Point point : controlPoints) {
|
||||
switch (orientation) {
|
||||
case DEFAULT:
|
||||
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(leadThickness));
|
||||
g2d.setColor(finalPinBorderColor);
|
||||
g2d.drawLine(point.x, point.y, point.x + leadLength - leadThickness / 2, point.y);
|
||||
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(leadThickness - 2));
|
||||
g2d.setColor(finalPinColor);
|
||||
g2d.drawLine(point.x, point.y, point.x + leadLength - leadThickness / 2, point.y);
|
||||
break;
|
||||
case _90:
|
||||
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(leadThickness));
|
||||
g2d.setColor(finalPinBorderColor);
|
||||
g2d.drawLine(point.x, point.y, point.x, point.y + leadLength - leadThickness / 2);
|
||||
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(leadThickness - 2));
|
||||
g2d.setColor(finalPinColor);
|
||||
g2d.drawLine(point.x, point.y, point.x, point.y + leadLength - leadThickness / 2);
|
||||
break;
|
||||
case _180:
|
||||
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(leadThickness));
|
||||
g2d.setColor(finalPinBorderColor);
|
||||
g2d.drawLine(point.x, point.y, point.x - leadLength - leadThickness / 2, point.y);
|
||||
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(leadThickness - 2));
|
||||
g2d.setColor(finalPinColor);
|
||||
g2d.drawLine(point.x, point.y, point.x - leadLength - leadThickness / 2, point.y);
|
||||
break;
|
||||
case _270:
|
||||
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(leadThickness));
|
||||
g2d.setColor(finalPinBorderColor);
|
||||
g2d.drawLine(point.x, point.y, point.x, point.y - leadLength);
|
||||
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(leadThickness - 2));
|
||||
g2d.setColor(finalPinColor);
|
||||
g2d.drawLine(point.x, point.y, point.x, point.y - leadLength);
|
||||
break;
|
||||
if (getLeadLength().getValue() > 0) {
|
||||
int leadThickness = getClosestOdd(LEAD_THICKNESS.convertToPixels());
|
||||
int leadLength = (int) getLeadLength().convertToPixels();
|
||||
Color finalPinColor;
|
||||
Color finalPinBorderColor;
|
||||
if (outlineMode) {
|
||||
finalPinColor = new Color(0, 0, 0, 0);
|
||||
finalPinBorderColor =
|
||||
componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING ? SELECTION_COLOR
|
||||
: theme.getOutlineColor();
|
||||
} else {
|
||||
finalPinColor = METAL_COLOR;
|
||||
finalPinBorderColor = METAL_COLOR.darker();
|
||||
}
|
||||
for (Point point : controlPoints) {
|
||||
switch (orientation) {
|
||||
case DEFAULT:
|
||||
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(leadThickness));
|
||||
g2d.setColor(finalPinBorderColor);
|
||||
g2d.drawLine(point.x, point.y, point.x + leadLength - leadThickness / 2, point.y);
|
||||
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(leadThickness - 2));
|
||||
g2d.setColor(finalPinColor);
|
||||
g2d.drawLine(point.x, point.y, point.x + leadLength - leadThickness / 2, point.y);
|
||||
break;
|
||||
case _90:
|
||||
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(leadThickness));
|
||||
g2d.setColor(finalPinBorderColor);
|
||||
g2d.drawLine(point.x, point.y, point.x, point.y + leadLength - leadThickness / 2);
|
||||
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(leadThickness - 2));
|
||||
g2d.setColor(finalPinColor);
|
||||
g2d.drawLine(point.x, point.y, point.x, point.y + leadLength - leadThickness / 2);
|
||||
break;
|
||||
case _180:
|
||||
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(leadThickness));
|
||||
g2d.setColor(finalPinBorderColor);
|
||||
g2d.drawLine(point.x, point.y, point.x - leadLength - leadThickness / 2, point.y);
|
||||
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(leadThickness - 2));
|
||||
g2d.setColor(finalPinColor);
|
||||
g2d.drawLine(point.x, point.y, point.x - leadLength - leadThickness / 2, point.y);
|
||||
break;
|
||||
case _270:
|
||||
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(leadThickness));
|
||||
g2d.setColor(finalPinBorderColor);
|
||||
g2d.drawLine(point.x, point.y, point.x, point.y - leadLength);
|
||||
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(leadThickness - 2));
|
||||
g2d.setColor(finalPinColor);
|
||||
g2d.drawLine(point.x, point.y, point.x, point.y - leadLength);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
||||
@@ -216,53 +216,55 @@ public class TransistorTO220 extends AbstractTransistorPackage {
|
||||
// Draw pins.
|
||||
|
||||
if (folded) {
|
||||
int leadThickness = getClosestOdd(LEAD_THICKNESS.convertToPixels());
|
||||
int leadLength = (int) getLeadLength().convertToPixels();
|
||||
Color finalPinColor;
|
||||
Color finalPinBorderColor;
|
||||
if (outlineMode) {
|
||||
finalPinColor = new Color(0, 0, 0, 0);
|
||||
finalPinBorderColor =
|
||||
componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING ? SELECTION_COLOR
|
||||
: theme.getOutlineColor();
|
||||
} else {
|
||||
finalPinColor = METAL_COLOR;
|
||||
finalPinBorderColor = METAL_COLOR.darker();
|
||||
}
|
||||
for (Point point : controlPoints) {
|
||||
switch (orientation) {
|
||||
case DEFAULT:
|
||||
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(leadThickness));
|
||||
g2d.setColor(finalPinBorderColor);
|
||||
g2d.drawLine(point.x, point.y, point.x + leadLength - leadThickness / 2, point.y);
|
||||
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(leadThickness - 2));
|
||||
g2d.setColor(finalPinColor);
|
||||
g2d.drawLine(point.x, point.y, point.x + leadLength - leadThickness / 2, point.y);
|
||||
break;
|
||||
case _90:
|
||||
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(leadThickness));
|
||||
g2d.setColor(finalPinBorderColor);
|
||||
g2d.drawLine(point.x, point.y, point.x, point.y + leadLength - leadThickness / 2);
|
||||
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(leadThickness - 2));
|
||||
g2d.setColor(finalPinColor);
|
||||
g2d.drawLine(point.x, point.y, point.x, point.y + leadLength - leadThickness / 2);
|
||||
break;
|
||||
case _180:
|
||||
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(leadThickness));
|
||||
g2d.setColor(finalPinBorderColor);
|
||||
g2d.drawLine(point.x, point.y, point.x - leadLength - leadThickness / 2, point.y);
|
||||
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(leadThickness - 2));
|
||||
g2d.setColor(finalPinColor);
|
||||
g2d.drawLine(point.x, point.y, point.x - leadLength - leadThickness / 2, point.y);
|
||||
break;
|
||||
case _270:
|
||||
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(leadThickness));
|
||||
g2d.setColor(finalPinBorderColor);
|
||||
g2d.drawLine(point.x, point.y, point.x, point.y - leadLength);
|
||||
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(leadThickness - 2));
|
||||
g2d.setColor(finalPinColor);
|
||||
g2d.drawLine(point.x, point.y, point.x, point.y - leadLength);
|
||||
break;
|
||||
if (getLeadLength().getValue() > 0) {
|
||||
int leadThickness = getClosestOdd(LEAD_THICKNESS.convertToPixels());
|
||||
int leadLength = (int) getLeadLength().convertToPixels();
|
||||
Color finalPinColor;
|
||||
Color finalPinBorderColor;
|
||||
if (outlineMode) {
|
||||
finalPinColor = new Color(0, 0, 0, 0);
|
||||
finalPinBorderColor =
|
||||
componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING ? SELECTION_COLOR
|
||||
: theme.getOutlineColor();
|
||||
} else {
|
||||
finalPinColor = METAL_COLOR;
|
||||
finalPinBorderColor = METAL_COLOR.darker();
|
||||
}
|
||||
for (Point point : controlPoints) {
|
||||
switch (orientation) {
|
||||
case DEFAULT:
|
||||
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(leadThickness));
|
||||
g2d.setColor(finalPinBorderColor);
|
||||
g2d.drawLine(point.x, point.y, point.x + leadLength - leadThickness / 2, point.y);
|
||||
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(leadThickness - 2));
|
||||
g2d.setColor(finalPinColor);
|
||||
g2d.drawLine(point.x, point.y, point.x + leadLength - leadThickness / 2, point.y);
|
||||
break;
|
||||
case _90:
|
||||
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(leadThickness));
|
||||
g2d.setColor(finalPinBorderColor);
|
||||
g2d.drawLine(point.x, point.y, point.x, point.y + leadLength - leadThickness / 2);
|
||||
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(leadThickness - 2));
|
||||
g2d.setColor(finalPinColor);
|
||||
g2d.drawLine(point.x, point.y, point.x, point.y + leadLength - leadThickness / 2);
|
||||
break;
|
||||
case _180:
|
||||
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(leadThickness));
|
||||
g2d.setColor(finalPinBorderColor);
|
||||
g2d.drawLine(point.x, point.y, point.x - leadLength - leadThickness / 2, point.y);
|
||||
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(leadThickness - 2));
|
||||
g2d.setColor(finalPinColor);
|
||||
g2d.drawLine(point.x, point.y, point.x - leadLength - leadThickness / 2, point.y);
|
||||
break;
|
||||
case _270:
|
||||
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(leadThickness));
|
||||
g2d.setColor(finalPinBorderColor);
|
||||
g2d.drawLine(point.x, point.y, point.x, point.y - leadLength);
|
||||
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(leadThickness - 2));
|
||||
g2d.setColor(finalPinColor);
|
||||
g2d.drawLine(point.x, point.y, point.x, point.y - leadLength);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
||||
@@ -94,7 +94,7 @@ public class TubeSocket extends AbstractTransparentComponent<String> {
|
||||
private int angle;
|
||||
private Color color = BODY_COLOR;
|
||||
private String electrodeLabels = null;
|
||||
private Mount mount = null;
|
||||
private Mount mount = Mount.CHASSIS;
|
||||
private Color labelColor = LABEL_COLOR;
|
||||
|
||||
private Point[] controlPoints = new Point[] {new Point(0, 0)};
|
||||
@@ -427,7 +427,7 @@ public class TubeSocket extends AbstractTransparentComponent<String> {
|
||||
@EditableProperty(name = "Mount")
|
||||
public Mount getMount() {
|
||||
if (mount == null)
|
||||
mount = Mount.PCB;
|
||||
mount = Mount.CHASSIS;
|
||||
return mount;
|
||||
}
|
||||
|
||||
@@ -461,7 +461,7 @@ public class TubeSocket extends AbstractTransparentComponent<String> {
|
||||
}
|
||||
}
|
||||
|
||||
static enum Mount {
|
||||
public static enum Mount {
|
||||
CHASSIS("Chassis"), PCB("PCB");
|
||||
|
||||
String name;
|
||||
|
||||
@@ -1,18 +1,27 @@
|
||||
package org.diylc.editor;
|
||||
|
||||
import java.awt.Point;
|
||||
import java.awt.geom.AffineTransform;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.diylc.common.IProjectEditor;
|
||||
import org.diylc.common.Orientation;
|
||||
import org.diylc.components.AbstractCurvedComponent.PointCount;
|
||||
import org.diylc.components.AbstractLeadedComponent;
|
||||
import org.diylc.components.connectivity.AWG;
|
||||
import org.diylc.components.connectivity.HookupWire;
|
||||
import org.diylc.components.passive.PotentiometerPanel;
|
||||
import org.diylc.components.passive.PotentiometerPanel.Type;
|
||||
import org.diylc.components.semiconductors.AbstractTransistorPackage;
|
||||
import org.diylc.components.semiconductors.TransistorTO126;
|
||||
import org.diylc.components.semiconductors.TransistorTO220;
|
||||
import org.diylc.components.tube.TubeSocket;
|
||||
import org.diylc.components.tube.TubeSocket.Mount;
|
||||
import org.diylc.core.IDIYComponent;
|
||||
import org.diylc.core.Project;
|
||||
import org.diylc.core.measures.Size;
|
||||
import org.diylc.core.measures.SizeUnit;
|
||||
import org.diylc.presenter.InstantiationManager;
|
||||
|
||||
public class FlexibleLeadsEditor implements IProjectEditor {
|
||||
@@ -25,13 +34,18 @@ public class FlexibleLeadsEditor implements IProjectEditor {
|
||||
for (IDIYComponent<?> c : selection) {
|
||||
if (c instanceof AbstractLeadedComponent<?>)
|
||||
addLeads((AbstractLeadedComponent<?>) c, project, newSelection);
|
||||
else if (c instanceof AbstractTransistorPackage)
|
||||
addLeads((AbstractTransistorPackage) c, project, newSelection);
|
||||
else if (c instanceof PotentiometerPanel)
|
||||
addLeads((PotentiometerPanel) c, project, newSelection);
|
||||
else if (c instanceof TubeSocket)
|
||||
addLeads((TubeSocket) c, project, newSelection);
|
||||
}
|
||||
|
||||
return newSelection;
|
||||
}
|
||||
|
||||
private void addLeads(AbstractLeadedComponent<?> c, Project project, Set<IDIYComponent<?>> newSelection) {
|
||||
AbstractLeadedComponent<?> leaded = (AbstractLeadedComponent<?>)c;
|
||||
private void addLeads(AbstractLeadedComponent<?> leaded, Project project, Set<IDIYComponent<?>> newSelection) {
|
||||
Size l = leaded.getLength();
|
||||
// do not apply to jumpers, etc
|
||||
if (l == null)
|
||||
@@ -77,16 +91,126 @@ public class FlexibleLeadsEditor implements IProjectEditor {
|
||||
newSelection.add(w2);
|
||||
|
||||
// inject leads right before the component
|
||||
int index = project.getComponents().indexOf(c);
|
||||
int index = project.getComponents().indexOf(leaded);
|
||||
project.getComponents().add(index, w1);
|
||||
project.getComponents().add(index, w2);
|
||||
}
|
||||
|
||||
private void addLeads(AbstractTransistorPackage c, Project project, Set<IDIYComponent<?>> newSelection) {
|
||||
if (c.getFolded()) {
|
||||
Size offsetX = new Size(0.4d, SizeUnit.in);
|
||||
Size offsetY = new Size(0.1d, SizeUnit.in);
|
||||
|
||||
} else {
|
||||
// create leads
|
||||
for (int i = 0; i < 3; i++) {
|
||||
Point p0 = c.getControlPoint(i);
|
||||
double dx = -offsetX.convertToPixels();
|
||||
double dy = offsetY.convertToPixels() * (i - 1);
|
||||
|
||||
// calculate lead position
|
||||
Point p1 = new Point((int)(p0.x + dx / 2), (int)(p0.y + dy / 2));
|
||||
Point p2 = new Point((int)(p0.x + dx), (int)(p0.y + dy));
|
||||
|
||||
if (c.getOrientation() != Orientation.DEFAULT) {
|
||||
AffineTransform tx = AffineTransform.getRotateInstance(c.getOrientation().toRadians(), p0.x, p0.y);
|
||||
tx.transform(p1, p1);
|
||||
tx.transform(p2, p2);
|
||||
}
|
||||
|
||||
HookupWire w = new HookupWire();
|
||||
// make the leads thicker for TO220 and TO126
|
||||
if (c instanceof TransistorTO220 || c instanceof TransistorTO126)
|
||||
w.setGauge(AWG._24);
|
||||
else
|
||||
w.setGauge(AWG._26);
|
||||
w.setLeadColor(AbstractTransistorPackage.METAL_COLOR);
|
||||
w.setPointCount(PointCount.THREE);
|
||||
w.setControlPoint(p0, 0);
|
||||
w.setControlPoint(p1, 1);
|
||||
w.setControlPoint(p2, 2);
|
||||
newSelection.add(w);
|
||||
|
||||
// inject leads right before the component
|
||||
int index = project.getComponents().indexOf(c);
|
||||
project.getComponents().add(index, w);
|
||||
}
|
||||
|
||||
if (c instanceof TransistorTO220) {
|
||||
TransistorTO220 t = (TransistorTO220)c;
|
||||
if (t.getFolded())
|
||||
t.setLeadLength(new Size(0d, SizeUnit.mm));
|
||||
}
|
||||
else if (c instanceof TransistorTO126) {
|
||||
TransistorTO126 t = (TransistorTO126)c;
|
||||
if (t.getFolded())
|
||||
t.setLeadLength(new Size(0d, SizeUnit.mm));
|
||||
}
|
||||
}
|
||||
|
||||
private void addLeads(PotentiometerPanel c, Project project, Set<IDIYComponent<?>> newSelection) {
|
||||
Size offsetY = new Size(1d, SizeUnit.in);
|
||||
|
||||
// don't do it for PCB type
|
||||
if (c.getType() == Type.PCB)
|
||||
return;
|
||||
|
||||
// create leads
|
||||
for (int i = 0; i < 3; i++) {
|
||||
Point p0 = c.getControlPoint(i);
|
||||
double dx = 0;
|
||||
double dy = offsetY.convertToPixels();
|
||||
|
||||
// calculate lead position
|
||||
Point p1 = new Point((int)(p0.x + dx / 2), (int)(p0.y + dy / 2));
|
||||
Point p2 = new Point((int)(p0.x + dx), (int)(p0.y + dy));
|
||||
|
||||
if (c.getOrientation() != Orientation.DEFAULT) {
|
||||
AffineTransform tx = AffineTransform.getRotateInstance(c.getOrientation().toRadians(), p0.x, p0.y);
|
||||
tx.transform(p1, p1);
|
||||
tx.transform(p2, p2);
|
||||
}
|
||||
|
||||
HookupWire w = new HookupWire();
|
||||
getInstantiationManager().fillWithDefaultProperties(w, null);
|
||||
w.setPointCount(PointCount.THREE);
|
||||
w.setControlPoint(p0, 0);
|
||||
w.setControlPoint(p1, 1);
|
||||
w.setControlPoint(p2, 2);
|
||||
newSelection.add(w);
|
||||
|
||||
// inject leads right before the component
|
||||
int index = project.getComponents().indexOf(c);
|
||||
project.getComponents().add(index + 1, w);
|
||||
}
|
||||
}
|
||||
|
||||
private void addLeads(TubeSocket c, Project project, Set<IDIYComponent<?>> newSelection) {
|
||||
Point center = c.getControlPoint(0);
|
||||
|
||||
// don't do it for PCB type
|
||||
if (c.getMount() == Mount.PCB)
|
||||
return;
|
||||
|
||||
// create leads
|
||||
for (int i = 1; i < c.getControlPointCount(); i++) {
|
||||
Point p = c.getControlPoint(i);
|
||||
double dx = p.x - center.x;
|
||||
double dy = p.y - center.y;
|
||||
|
||||
// calculate lead position
|
||||
Point p1 = new Point((int)(p.x + dx), (int)(p.y + dy));
|
||||
Point p2 = new Point((int)(p.x + dx * 2), (int)(p.y + dy * 2));
|
||||
|
||||
HookupWire w = new HookupWire();
|
||||
getInstantiationManager().fillWithDefaultProperties(w, null);
|
||||
w.setPointCount(PointCount.THREE);
|
||||
w.setControlPoint(p, 0);
|
||||
w.setControlPoint(p1, 1);
|
||||
w.setControlPoint(p2, 2);
|
||||
newSelection.add(w);
|
||||
|
||||
// inject leads right before the component
|
||||
int index = project.getComponents().indexOf(c);
|
||||
project.getComponents().add(index + 1, w);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user