mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-11 01:32:08 +10:00
add striped option for twisted pair
This commit is contained in:
@@ -64,12 +64,12 @@ public class ObjectCache {
|
|||||||
return stroke;
|
return stroke;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Stroke fetchStroke(float width, float[] dash, float phase) {
|
public Stroke fetchStroke(float width, float[] dash, float phase, int cap) {
|
||||||
String key = width + "|" + Arrays.toString(dash) + "|" + phase;
|
String key = width + "|" + Arrays.toString(dash) + "|" + phase + "|" + phase;
|
||||||
if (dashStrokeMap.containsKey(key)) {
|
if (dashStrokeMap.containsKey(key)) {
|
||||||
return dashStrokeMap.get(key);
|
return dashStrokeMap.get(key);
|
||||||
}
|
}
|
||||||
Stroke stroke = new BasicStroke(width, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 0, dash, phase);
|
Stroke stroke = new BasicStroke(width, cap, BasicStroke.JOIN_ROUND, 0, dash, phase);
|
||||||
dashStrokeMap.put(key, stroke);
|
dashStrokeMap.put(key, stroke);
|
||||||
return stroke;
|
return stroke;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -408,7 +408,7 @@ class G2DWrapper extends Graphics2D implements IDrawingObserver {
|
|||||||
BasicStroke bs = (BasicStroke) s;
|
BasicStroke bs = (BasicStroke) s;
|
||||||
// make thin lines even thinner to compensate for zoom factor
|
// make thin lines even thinner to compensate for zoom factor
|
||||||
if (bs.getLineWidth() <= 2 && !(s instanceof ZoomableStroke))
|
if (bs.getLineWidth() <= 2 && !(s instanceof ZoomableStroke))
|
||||||
s = ObjectCache.getInstance().fetchStroke((float) (bs.getLineWidth() / zoom), bs.getDashArray(), bs.getDashPhase());
|
s = ObjectCache.getInstance().fetchStroke((float) (bs.getLineWidth() / zoom), bs.getDashArray(), bs.getDashPhase(), bs.getEndCap());
|
||||||
}
|
}
|
||||||
canvasGraphics.setStroke(s);
|
canvasGraphics.setStroke(s);
|
||||||
}
|
}
|
||||||
|
|||||||
Binary file not shown.
@@ -18,6 +18,7 @@
|
|||||||
package org.diylc.components;
|
package org.diylc.components;
|
||||||
|
|
||||||
import java.awt.AlphaComposite;
|
import java.awt.AlphaComposite;
|
||||||
|
import java.awt.BasicStroke;
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
import java.awt.Composite;
|
import java.awt.Composite;
|
||||||
import java.awt.FontMetrics;
|
import java.awt.FontMetrics;
|
||||||
@@ -322,10 +323,10 @@ public abstract class AbstractLeadedComponent<T> extends AbstractTransparentComp
|
|||||||
break;
|
break;
|
||||||
case DASHED:
|
case DASHED:
|
||||||
stroke =
|
stroke =
|
||||||
ObjectCache.getInstance().fetchStroke(thickness, new float[] {thickness * 2, thickness * 4}, thickness * 4);
|
ObjectCache.getInstance().fetchStroke(thickness, new float[] {thickness * 2, thickness * 4}, thickness * 4, BasicStroke.CAP_SQUARE);
|
||||||
break;
|
break;
|
||||||
case DOTTED:
|
case DOTTED:
|
||||||
stroke = ObjectCache.getInstance().fetchStroke(thickness, new float[] {thickness / 4, thickness * 4}, 0);
|
stroke = ObjectCache.getInstance().fetchStroke(thickness, new float[] {thickness / 4, thickness * 4}, 0, BasicStroke.CAP_ROUND);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ import java.awt.Color;
|
|||||||
import java.awt.Graphics2D;
|
import java.awt.Graphics2D;
|
||||||
import java.awt.geom.Path2D;
|
import java.awt.geom.Path2D;
|
||||||
|
|
||||||
|
import org.diylc.common.LineStyle;
|
||||||
import org.diylc.common.ObjectCache;
|
import org.diylc.common.ObjectCache;
|
||||||
import org.diylc.common.PCBLayer;
|
import org.diylc.common.PCBLayer;
|
||||||
import org.diylc.common.SimpleComponentTransformer;
|
import org.diylc.common.SimpleComponentTransformer;
|
||||||
@@ -105,4 +106,9 @@ public class CurvedTrace extends AbstractCurvedComponent<Void> {
|
|||||||
public void setAlpha(Byte alpha) {
|
public void setAlpha(Byte alpha) {
|
||||||
super.setAlpha(alpha);
|
super.setAlpha(alpha);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public LineStyle getStyle() {
|
||||||
|
return super.getStyle();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
*/
|
*/
|
||||||
package org.diylc.components.connectivity;
|
package org.diylc.components.connectivity;
|
||||||
|
|
||||||
|
import java.awt.BasicStroke;
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
import java.awt.Graphics2D;
|
import java.awt.Graphics2D;
|
||||||
import java.awt.Shape;
|
import java.awt.Shape;
|
||||||
@@ -67,10 +68,10 @@ public class HookupWire extends AbstractCurvedComponent<Void> {
|
|||||||
break;
|
break;
|
||||||
case DASHED:
|
case DASHED:
|
||||||
stroke =
|
stroke =
|
||||||
ObjectCache.getInstance().fetchStroke(thickness, new float[] {thickness * 2, thickness * 3}, thickness * 4);
|
ObjectCache.getInstance().fetchStroke(thickness, new float[] {thickness * 2, thickness * 3}, thickness * 4, BasicStroke.CAP_SQUARE);
|
||||||
break;
|
break;
|
||||||
case DOTTED:
|
case DOTTED:
|
||||||
stroke = ObjectCache.getInstance().fetchStroke(thickness, new float[] {thickness / 4, thickness * 3}, 0);
|
stroke = ObjectCache.getInstance().fetchStroke(thickness, new float[] {thickness / 4, thickness * 3}, 0, BasicStroke.CAP_ROUND);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
Shape s = stroke.createStrokedShape(curve);
|
Shape s = stroke.createStrokedShape(curve);
|
||||||
|
|||||||
@@ -21,6 +21,7 @@
|
|||||||
*/
|
*/
|
||||||
package org.diylc.components.connectivity;
|
package org.diylc.components.connectivity;
|
||||||
|
|
||||||
|
import java.awt.BasicStroke;
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
import java.awt.Graphics2D;
|
import java.awt.Graphics2D;
|
||||||
import java.awt.Point;
|
import java.awt.Point;
|
||||||
@@ -81,10 +82,10 @@ public class Line extends AbstractLeadedComponent<Void> {
|
|||||||
stroke = ObjectCache.getInstance().fetchZoomableStroke(thickness);
|
stroke = ObjectCache.getInstance().fetchZoomableStroke(thickness);
|
||||||
break;
|
break;
|
||||||
case DASHED:
|
case DASHED:
|
||||||
stroke = ObjectCache.getInstance().fetchStroke(thickness, new float[] {thickness * 2, thickness * 4}, thickness * 4);
|
stroke = ObjectCache.getInstance().fetchStroke(thickness, new float[] {thickness * 2, thickness * 4}, thickness * 4, BasicStroke.CAP_SQUARE);
|
||||||
break;
|
break;
|
||||||
case DOTTED:
|
case DOTTED:
|
||||||
stroke = ObjectCache.getInstance().fetchStroke(thickness, new float[] {thickness, thickness * 5}, 0);
|
stroke = ObjectCache.getInstance().fetchStroke(thickness, new float[] {thickness, thickness * 5}, 0, BasicStroke.CAP_ROUND);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
g2d.setStroke(stroke);
|
g2d.setStroke(stroke);
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
*/
|
*/
|
||||||
package org.diylc.components.connectivity;
|
package org.diylc.components.connectivity;
|
||||||
|
|
||||||
|
import java.awt.BasicStroke;
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
import java.awt.Graphics2D;
|
import java.awt.Graphics2D;
|
||||||
import java.awt.Point;
|
import java.awt.Point;
|
||||||
@@ -53,41 +54,30 @@ public class TwistedWire extends AbstractCurvedComponent<Void> {
|
|||||||
|
|
||||||
public static Color COLOR = Color.green;
|
public static Color COLOR = Color.green;
|
||||||
public static Color COLOR2 = Color.blue;
|
public static Color COLOR2 = Color.blue;
|
||||||
|
public static Color STRIPE_COLOR = Color.yellow;
|
||||||
|
public static Color STRIPE_COLOR2 = Color.decode("#FF00FF");
|
||||||
public static double INSULATION_THICKNESS_PCT = 0.3;
|
public static double INSULATION_THICKNESS_PCT = 0.3;
|
||||||
|
|
||||||
protected AWG gauge = AWG._22;
|
protected AWG gauge = AWG._22;
|
||||||
|
|
||||||
private Color color2 = COLOR2;
|
private Color color2 = COLOR2;
|
||||||
|
private Color stripeColor = STRIPE_COLOR;
|
||||||
|
private Color stripeColor2 = STRIPE_COLOR2;
|
||||||
|
private boolean stripe1 = false;
|
||||||
|
private boolean stripe2 = false;
|
||||||
|
|
||||||
// cached areas
|
// cached areas
|
||||||
transient private Area firstLeadArea = null;
|
transient private Area firstLeadArea = null;
|
||||||
transient private Area secondLeadArea = null;
|
transient private Area secondLeadArea = null;
|
||||||
|
|
||||||
|
transient private Area firstLeadStripeArea = null;
|
||||||
|
transient private Area secondLeadStripeArea = null;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Color getDefaultColor() {
|
protected Color getDefaultColor() {
|
||||||
return COLOR;
|
return COLOR;
|
||||||
}
|
}
|
||||||
|
|
||||||
@EditableProperty(name = "Color 1")
|
|
||||||
public Color getLeadColor() {
|
|
||||||
return color;
|
|
||||||
}
|
|
||||||
|
|
||||||
@EditableProperty(name = "Color 2")
|
|
||||||
public Color getColor2() {
|
|
||||||
return color2;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setColor2(Color color2) {
|
|
||||||
this.color2 = color2;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public LineStyle getStyle() {
|
|
||||||
// prevent from editing
|
|
||||||
return super.getStyle();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void drawCurve(Path2D curve, Graphics2D g2d, ComponentState componentState, IDrawingObserver drawingObserver) {
|
protected void drawCurve(Path2D curve, Graphics2D g2d, ComponentState componentState, IDrawingObserver drawingObserver) {
|
||||||
int thickness =
|
int thickness =
|
||||||
@@ -99,13 +89,36 @@ public class TwistedWire extends AbstractCurvedComponent<Void> {
|
|||||||
componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING ? SELECTION_COLOR
|
componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING ? SELECTION_COLOR
|
||||||
: color2;
|
: color2;
|
||||||
|
|
||||||
if (firstLeadArea == null || secondLeadArea == null)
|
if (firstLeadArea == null || secondLeadArea == null) {
|
||||||
recalculate(curve, thickness);
|
firstLeadArea = new Area();
|
||||||
|
secondLeadArea = new Area();
|
||||||
|
recalculate(curve, thickness, firstLeadArea, secondLeadArea, false);
|
||||||
|
|
||||||
|
if (stripe1 || stripe2) {
|
||||||
|
firstLeadStripeArea = new Area();
|
||||||
|
secondLeadStripeArea = new Area();
|
||||||
|
recalculate(curve, thickness, firstLeadStripeArea, secondLeadStripeArea, true);
|
||||||
|
firstLeadStripeArea.intersect(firstLeadArea);
|
||||||
|
secondLeadStripeArea.intersect(secondLeadArea);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
g2d.setColor(curveColor1);
|
g2d.setColor(curveColor1);
|
||||||
g2d.fill(firstLeadArea);
|
g2d.fill(firstLeadArea);
|
||||||
|
|
||||||
|
if (stripe1 && componentState == ComponentState.NORMAL) {
|
||||||
|
g2d.setColor(stripeColor);
|
||||||
|
g2d.fill(firstLeadStripeArea);
|
||||||
|
}
|
||||||
|
|
||||||
g2d.setColor(curveColor2);
|
g2d.setColor(curveColor2);
|
||||||
g2d.fill(secondLeadArea);
|
g2d.fill(secondLeadArea);
|
||||||
|
|
||||||
|
if (stripe2 && componentState == ComponentState.NORMAL) {
|
||||||
|
g2d.setColor(stripeColor2);
|
||||||
|
g2d.fill(secondLeadStripeArea);
|
||||||
|
}
|
||||||
|
|
||||||
if (componentState == ComponentState.NORMAL) {
|
if (componentState == ComponentState.NORMAL) {
|
||||||
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(1f));
|
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(1f));
|
||||||
g2d.setColor(color.darker());
|
g2d.setColor(color.darker());
|
||||||
@@ -148,6 +161,8 @@ public class TwistedWire extends AbstractCurvedComponent<Void> {
|
|||||||
// invalidate cached areas
|
// invalidate cached areas
|
||||||
this.firstLeadArea = null;
|
this.firstLeadArea = null;
|
||||||
this.secondLeadArea = null;
|
this.secondLeadArea = null;
|
||||||
|
this.firstLeadStripeArea = null;
|
||||||
|
this.secondLeadStripeArea = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -157,6 +172,8 @@ public class TwistedWire extends AbstractCurvedComponent<Void> {
|
|||||||
// invalidate cached areas
|
// invalidate cached areas
|
||||||
this.firstLeadArea = null;
|
this.firstLeadArea = null;
|
||||||
this.secondLeadArea = null;
|
this.secondLeadArea = null;
|
||||||
|
this.firstLeadStripeArea = null;
|
||||||
|
this.secondLeadStripeArea = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -166,6 +183,8 @@ public class TwistedWire extends AbstractCurvedComponent<Void> {
|
|||||||
// invalidate cached areas
|
// invalidate cached areas
|
||||||
this.firstLeadArea = null;
|
this.firstLeadArea = null;
|
||||||
this.secondLeadArea = null;
|
this.secondLeadArea = null;
|
||||||
|
this.firstLeadStripeArea = null;
|
||||||
|
this.secondLeadStripeArea = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -176,9 +195,81 @@ public class TwistedWire extends AbstractCurvedComponent<Void> {
|
|||||||
@Override
|
@Override
|
||||||
public void setValue(Void value) {}
|
public void setValue(Void value) {}
|
||||||
|
|
||||||
|
@EditableProperty(name = "Color 1")
|
||||||
|
public Color getLeadColor() {
|
||||||
|
return color;
|
||||||
|
}
|
||||||
|
|
||||||
|
@EditableProperty(name = "Color 2")
|
||||||
|
public Color getColor2() {
|
||||||
|
return color2;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setColor2(Color color2) {
|
||||||
|
this.color2 = color2;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public LineStyle getStyle() {
|
||||||
|
// prevent from editing
|
||||||
|
return super.getStyle();
|
||||||
|
}
|
||||||
|
|
||||||
|
@EditableProperty(name = "Stripe 1")
|
||||||
|
public Color getStripeColor() {
|
||||||
|
return stripeColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStripeColor(Color stripeColor) {
|
||||||
|
this.stripeColor = stripeColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
@EditableProperty(name = "Stripe 2")
|
||||||
|
public Color getStripeColor2() {
|
||||||
|
return stripeColor2;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStripeColor2(Color stripeColor2) {
|
||||||
|
this.stripeColor2 = stripeColor2;
|
||||||
|
}
|
||||||
|
|
||||||
|
@EditableProperty(name = "Show Stripe 1")
|
||||||
|
public boolean getStripe1() {
|
||||||
|
return stripe1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStripe1(boolean stripe1) {
|
||||||
|
this.stripe1 = stripe1;
|
||||||
|
|
||||||
|
if (stripe1) {
|
||||||
|
// invalidate cached areas
|
||||||
|
this.firstLeadArea = null;
|
||||||
|
this.secondLeadArea = null;
|
||||||
|
this.firstLeadStripeArea = null;
|
||||||
|
this.secondLeadStripeArea = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@EditableProperty(name = "Show Stripe 2")
|
||||||
|
public boolean getStripe2() {
|
||||||
|
return stripe2;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStripe2(boolean stripe2) {
|
||||||
|
this.stripe2 = stripe2;
|
||||||
|
|
||||||
|
if (stripe2) {
|
||||||
|
// invalidate cached areas
|
||||||
|
this.firstLeadArea = null;
|
||||||
|
this.secondLeadArea = null;
|
||||||
|
this.firstLeadStripeArea = null;
|
||||||
|
this.secondLeadStripeArea = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// hard-core math below :)
|
// hard-core math below :)
|
||||||
|
|
||||||
public void recalculate(Path2D path, float thickness) {
|
public void recalculate(Path2D path, float thickness, Area firstLeadArea, Area secondLeadArea, boolean stripe) {
|
||||||
PathIterator iterator = path.getPathIterator(null);
|
PathIterator iterator = path.getPathIterator(null);
|
||||||
float[] coords = new float[6];
|
float[] coords = new float[6];
|
||||||
Point current = new Point();
|
Point current = new Point();
|
||||||
@@ -211,7 +302,12 @@ public class TwistedWire extends AbstractCurvedComponent<Void> {
|
|||||||
iterator.next();
|
iterator.next();
|
||||||
}
|
}
|
||||||
|
|
||||||
Stroke stroke = ObjectCache.getInstance().fetchBasicStroke(thickness);
|
Stroke stroke;
|
||||||
|
|
||||||
|
if (stripe)
|
||||||
|
stroke = ObjectCache.getInstance().fetchStroke(thickness, new float[] { thickness / 2, thickness * 2 }, thickness * 10, BasicStroke.CAP_BUTT);
|
||||||
|
else
|
||||||
|
stroke = ObjectCache.getInstance().fetchBasicStroke(thickness);
|
||||||
|
|
||||||
double segmentLength = thickness * 6;
|
double segmentLength = thickness * 6;
|
||||||
|
|
||||||
@@ -220,9 +316,6 @@ public class TwistedWire extends AbstractCurvedComponent<Void> {
|
|||||||
for (CubicCurve2D curve : curves)
|
for (CubicCurve2D curve : curves)
|
||||||
polygon.addAll(split(curve, segmentLength));
|
polygon.addAll(split(curve, segmentLength));
|
||||||
|
|
||||||
firstLeadArea = new Area();
|
|
||||||
secondLeadArea = new Area();
|
|
||||||
|
|
||||||
List<Path2D> firstCurves = new ArrayList<Path2D>();
|
List<Path2D> firstCurves = new ArrayList<Path2D>();
|
||||||
List<Path2D> secondCurves = new ArrayList<Path2D>();
|
List<Path2D> secondCurves = new ArrayList<Path2D>();
|
||||||
|
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user