mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-10 17:22:09 +10:00
added abstract curve
This commit is contained in:
@@ -6,14 +6,14 @@
|
|||||||
<unit class="org.diylc.core.measures.ResistanceUnit">K</unit>
|
<unit class="org.diylc.core.measures.ResistanceUnit">K</unit>
|
||||||
</org.diylc.core.measures.Resistance>
|
</org.diylc.core.measures.Resistance>
|
||||||
</entry>
|
</entry>
|
||||||
<entry>
|
|
||||||
<string>metric</string>
|
|
||||||
<boolean>true</boolean>
|
|
||||||
</entry>
|
|
||||||
<entry>
|
<entry>
|
||||||
<string>lastPath</string>
|
<string>lastPath</string>
|
||||||
<string>C:\Documents and Settings\Branislav Stojkovic\Desktop</string>
|
<string>C:\Documents and Settings\Branislav Stojkovic\Desktop</string>
|
||||||
</entry>
|
</entry>
|
||||||
|
<entry>
|
||||||
|
<string>metric</string>
|
||||||
|
<boolean>true</boolean>
|
||||||
|
</entry>
|
||||||
<entry>
|
<entry>
|
||||||
<string>default.org.diylc.components.passive.AxialFilmCapacitor:Width</string>
|
<string>default.org.diylc.components.passive.AxialFilmCapacitor:Width</string>
|
||||||
<org.diylc.core.measures.Size>
|
<org.diylc.core.measures.Size>
|
||||||
|
|||||||
Binary file not shown.
+106
@@ -0,0 +1,106 @@
|
|||||||
|
package org.diylc.components;
|
||||||
|
|
||||||
|
import java.awt.AlphaComposite;
|
||||||
|
import java.awt.BasicStroke;
|
||||||
|
import java.awt.Color;
|
||||||
|
import java.awt.Composite;
|
||||||
|
import java.awt.Graphics2D;
|
||||||
|
import java.awt.Point;
|
||||||
|
import java.awt.geom.CubicCurve2D;
|
||||||
|
|
||||||
|
import org.diylc.core.ComponentState;
|
||||||
|
import org.diylc.core.Project;
|
||||||
|
import org.diylc.core.annotations.EditableProperty;
|
||||||
|
import org.diylc.utils.Constants;
|
||||||
|
|
||||||
|
public abstract class AbstractCurvedComponent<T> extends AbstractTransparentComponent<T> {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
public static Color GUIDELINE_COLOR = Color.blue;
|
||||||
|
|
||||||
|
protected Point[] controlPoints = new Point[] {
|
||||||
|
new Point(-5 * Constants.GRID, -5 * Constants.GRID), new Point(0, -3 * Constants.GRID),
|
||||||
|
new Point(0, 3 * Constants.GRID), new Point(5 * Constants.GRID, 5 * Constants.GRID) };
|
||||||
|
|
||||||
|
protected Color color = getDefaultColor();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Draws the specified curve onto graphics.
|
||||||
|
*
|
||||||
|
* @param curve
|
||||||
|
* @param g2d
|
||||||
|
*/
|
||||||
|
protected abstract void drawCurve(CubicCurve2D curve, Graphics2D g2d);
|
||||||
|
|
||||||
|
protected abstract Color getDefaultColor();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void drawIcon(Graphics2D g2d, int width, int height) {
|
||||||
|
g2d.setColor(getDefaultColor().darker());
|
||||||
|
g2d.setStroke(new BasicStroke(3));
|
||||||
|
CubicCurve2D curve = new CubicCurve2D.Double(1, height - 1, width / 4, height / 3,
|
||||||
|
3 * width / 4, 2 * height / 3, width - 1, 1);
|
||||||
|
g2d.draw(curve);
|
||||||
|
g2d.setColor(getDefaultColor());
|
||||||
|
g2d.setStroke(new BasicStroke(1));
|
||||||
|
g2d.draw(curve);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void draw(Graphics2D g2d, ComponentState componentState, Project project) {
|
||||||
|
if (componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING) {
|
||||||
|
g2d.setStroke(new BasicStroke(1, BasicStroke.CAP_ROUND, BasicStroke.JOIN_MITER, 10f,
|
||||||
|
new float[] { 2f, 3f }, 5f));
|
||||||
|
g2d.setColor(GUIDELINE_COLOR);
|
||||||
|
g2d.drawLine(controlPoints[0].x, controlPoints[0].y, controlPoints[1].x,
|
||||||
|
controlPoints[1].y);
|
||||||
|
g2d.drawLine(controlPoints[1].x, controlPoints[1].y, controlPoints[2].x,
|
||||||
|
controlPoints[2].y);
|
||||||
|
g2d.drawLine(controlPoints[2].x, controlPoints[2].y, controlPoints[3].x,
|
||||||
|
controlPoints[3].y);
|
||||||
|
}
|
||||||
|
CubicCurve2D curve = new CubicCurve2D.Double(controlPoints[0].x, controlPoints[0].y,
|
||||||
|
controlPoints[1].x, controlPoints[1].y, controlPoints[2].x, controlPoints[2].y,
|
||||||
|
controlPoints[3].x, controlPoints[3].y);
|
||||||
|
|
||||||
|
Composite oldComposite = g2d.getComposite();
|
||||||
|
if (alpha < MAX_ALPHA) {
|
||||||
|
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1f * alpha
|
||||||
|
/ MAX_ALPHA));
|
||||||
|
}
|
||||||
|
// g2d.setColor(color.darker());
|
||||||
|
// g2d.setStroke(new BasicStroke(thickness));
|
||||||
|
// g2d.draw(path);
|
||||||
|
// g2d.setColor(color);
|
||||||
|
// g2d.setStroke(new BasicStroke(thickness - 2));
|
||||||
|
// g2d.draw(path);
|
||||||
|
drawCurve(curve, g2d);
|
||||||
|
g2d.setComposite(oldComposite);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getControlPointCount() {
|
||||||
|
return controlPoints.length;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Point getControlPoint(int index) {
|
||||||
|
return controlPoints[index];
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setControlPoint(Point point, int index) {
|
||||||
|
controlPoints[index].setLocation(point);
|
||||||
|
}
|
||||||
|
|
||||||
|
@EditableProperty
|
||||||
|
public Color getColor() {
|
||||||
|
return color;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setColor(Color color) {
|
||||||
|
this.color = color;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+1
-1
@@ -35,7 +35,7 @@ public interface IDIYComponent<T> extends Serializable {
|
|||||||
public static final int ABOVE_CHASSIS = 3;
|
public static final int ABOVE_CHASSIS = 3;
|
||||||
public static final int BELOW_BOARD = 4;
|
public static final int BELOW_BOARD = 4;
|
||||||
public static final int BOARD = 5;
|
public static final int BOARD = 5;
|
||||||
public static final int ABOVE_BOARD = 5;
|
public static final int ABOVE_BOARD = 6;
|
||||||
public static final int COMPONENT = 7;
|
public static final int COMPONENT = 7;
|
||||||
public static final int ABOVE_COMPONENT = 8;
|
public static final int ABOVE_COMPONENT = 8;
|
||||||
|
|
||||||
|
|||||||
Binary file not shown.
+1
-1
@@ -12,7 +12,7 @@ import org.diylc.core.annotations.EditableProperty;
|
|||||||
import org.diylc.core.measures.Size;
|
import org.diylc.core.measures.Size;
|
||||||
import org.diylc.core.measures.SizeUnit;
|
import org.diylc.core.measures.SizeUnit;
|
||||||
|
|
||||||
@ComponentDescriptor(name = "Copper Trace", author = "Branislav Stojkovic", category = "Connectivity", instanceNamePrefix = "J", description = "Jumper wire", zOrder = IDIYComponent.ABOVE_BOARD)
|
@ComponentDescriptor(name = "Copper Trace", author = "Branislav Stojkovic", category = "Connectivity", instanceNamePrefix = "CT", description = "", zOrder = IDIYComponent.ABOVE_BOARD)
|
||||||
public class CopperTrace extends AbstractLeadedDIYComponent<Void> {
|
public class CopperTrace extends AbstractLeadedDIYComponent<Void> {
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|||||||
+48
@@ -0,0 +1,48 @@
|
|||||||
|
package org.diylc.components.connectivity;
|
||||||
|
|
||||||
|
import java.awt.BasicStroke;
|
||||||
|
import java.awt.Color;
|
||||||
|
import java.awt.Graphics2D;
|
||||||
|
import java.awt.geom.CubicCurve2D;
|
||||||
|
|
||||||
|
import org.diylc.components.AbstractCurvedComponent;
|
||||||
|
import org.diylc.core.IDIYComponent;
|
||||||
|
import org.diylc.core.annotations.ComponentDescriptor;
|
||||||
|
import org.diylc.core.annotations.EditableProperty;
|
||||||
|
import org.diylc.core.measures.Size;
|
||||||
|
import org.diylc.core.measures.SizeUnit;
|
||||||
|
|
||||||
|
@ComponentDescriptor(name = "Curved Trace", author = "Branislav Stojkovic", category = "Connectivity", instanceNamePrefix = "CT", description = "Curved copper trace with two control points", zOrder = IDIYComponent.ABOVE_BOARD)
|
||||||
|
public class CurvedTrace extends AbstractCurvedComponent<Size> {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
public static Color COLOR = Color.black;
|
||||||
|
public static Size SIZE = new Size(1d, SizeUnit.mm);
|
||||||
|
|
||||||
|
protected Size size = SIZE;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Color getDefaultColor() {
|
||||||
|
return COLOR;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void drawCurve(CubicCurve2D curve, Graphics2D g2d) {
|
||||||
|
int thickness = size.convertToPixels();
|
||||||
|
g2d.setStroke(new BasicStroke(thickness));
|
||||||
|
g2d.setColor(color);
|
||||||
|
g2d.draw(curve);
|
||||||
|
}
|
||||||
|
|
||||||
|
@EditableProperty(name = "Width")
|
||||||
|
@Override
|
||||||
|
public Size getValue() {
|
||||||
|
return size;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setValue(Size value) {
|
||||||
|
this.size = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
+9
-74
@@ -1,97 +1,41 @@
|
|||||||
package org.diylc.components.connectivity;
|
package org.diylc.components.connectivity;
|
||||||
|
|
||||||
import java.awt.AlphaComposite;
|
|
||||||
import java.awt.BasicStroke;
|
import java.awt.BasicStroke;
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
import java.awt.Composite;
|
|
||||||
import java.awt.Graphics2D;
|
import java.awt.Graphics2D;
|
||||||
import java.awt.Point;
|
|
||||||
import java.awt.geom.CubicCurve2D;
|
import java.awt.geom.CubicCurve2D;
|
||||||
import java.awt.geom.Path2D;
|
|
||||||
|
|
||||||
import org.diylc.components.AbstractTransparentComponent;
|
import org.diylc.components.AbstractCurvedComponent;
|
||||||
import org.diylc.core.ComponentState;
|
|
||||||
import org.diylc.core.IDIYComponent;
|
import org.diylc.core.IDIYComponent;
|
||||||
import org.diylc.core.Project;
|
|
||||||
import org.diylc.core.annotations.ComponentDescriptor;
|
import org.diylc.core.annotations.ComponentDescriptor;
|
||||||
import org.diylc.core.annotations.EditableProperty;
|
import org.diylc.core.annotations.EditableProperty;
|
||||||
import org.diylc.utils.Constants;
|
import org.diylc.utils.Constants;
|
||||||
|
|
||||||
@ComponentDescriptor(name = "Hookup wire", author = "Branislav Stojkovic", category = "Connectivity", instanceNamePrefix = "W", description = "Jumper wire", zOrder = IDIYComponent.ABOVE_COMPONENT)
|
@ComponentDescriptor(name = "Hookup Wire", author = "Branislav Stojkovic", category = "Connectivity", instanceNamePrefix = "W", description = "Flexible wire with two control points", zOrder = IDIYComponent.ABOVE_COMPONENT)
|
||||||
public class HookupWire extends AbstractTransparentComponent<AWG> {
|
public class HookupWire extends AbstractCurvedComponent<AWG> {
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
public static Color GUIDELINE_COLOR = Color.blue;
|
|
||||||
public static Color COLOR = Color.green;
|
public static Color COLOR = Color.green;
|
||||||
public static double INSULATION_THICKNESS_PCT = 0.3;
|
public static double INSULATION_THICKNESS_PCT = 0.3;
|
||||||
|
|
||||||
private Point[] controlPoints = new Point[] {
|
protected AWG value = AWG._22;
|
||||||
new Point(-5 * Constants.GRID, -5 * Constants.GRID), new Point(0, -3 * Constants.GRID),
|
|
||||||
new Point(0, 3 * Constants.GRID), new Point(5 * Constants.GRID, 5 * Constants.GRID) };
|
|
||||||
|
|
||||||
private AWG value = AWG._22;
|
|
||||||
private Color color = COLOR;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void drawIcon(Graphics2D g2d, int width, int height) {
|
protected Color getDefaultColor() {
|
||||||
g2d.setColor(COLOR.darker());
|
return COLOR;
|
||||||
g2d.setStroke(new BasicStroke(3));
|
|
||||||
CubicCurve2D curve = new CubicCurve2D.Double(1, height - 1, width / 4, height / 3,
|
|
||||||
3 * width / 4, 2 * height / 3, width - 1, 1);
|
|
||||||
g2d.draw(curve);
|
|
||||||
g2d.setColor(COLOR);
|
|
||||||
g2d.setStroke(new BasicStroke(1));
|
|
||||||
g2d.draw(curve);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void draw(Graphics2D g2d, ComponentState componentState, Project project) {
|
protected void drawCurve(CubicCurve2D curve, Graphics2D g2d) {
|
||||||
if (componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING) {
|
|
||||||
g2d.setStroke(new BasicStroke(1, BasicStroke.CAP_ROUND, BasicStroke.JOIN_MITER, 10f,
|
|
||||||
new float[] { 2f, 3f }, 5f));
|
|
||||||
g2d.setColor(GUIDELINE_COLOR);
|
|
||||||
g2d.drawLine(controlPoints[0].x, controlPoints[0].y, controlPoints[1].x,
|
|
||||||
controlPoints[1].y);
|
|
||||||
g2d.drawLine(controlPoints[1].x, controlPoints[1].y, controlPoints[2].x,
|
|
||||||
controlPoints[2].y);
|
|
||||||
g2d.drawLine(controlPoints[2].x, controlPoints[2].y, controlPoints[3].x,
|
|
||||||
controlPoints[3].y);
|
|
||||||
}
|
|
||||||
int thickness = (int) (Math.pow(Math.E, -1.12436 - 0.11594 * value.getValue())
|
int thickness = (int) (Math.pow(Math.E, -1.12436 - 0.11594 * value.getValue())
|
||||||
* Constants.PIXELS_PER_INCH * (1 + 2 * INSULATION_THICKNESS_PCT));
|
* Constants.PIXELS_PER_INCH * (1 + 2 * INSULATION_THICKNESS_PCT));
|
||||||
Path2D path = new Path2D.Double();
|
|
||||||
path.moveTo(controlPoints[0].x, controlPoints[0].y);
|
|
||||||
path.curveTo(controlPoints[1].x, controlPoints[1].y, controlPoints[2].x,
|
|
||||||
controlPoints[2].y, controlPoints[3].x, controlPoints[3].y);
|
|
||||||
|
|
||||||
Composite oldComposite = g2d.getComposite();
|
|
||||||
if (alpha < MAX_ALPHA) {
|
|
||||||
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1f * alpha
|
|
||||||
/ MAX_ALPHA));
|
|
||||||
}
|
|
||||||
g2d.setColor(color.darker());
|
g2d.setColor(color.darker());
|
||||||
g2d.setStroke(new BasicStroke(thickness));
|
g2d.setStroke(new BasicStroke(thickness));
|
||||||
g2d.draw(path);
|
g2d.draw(curve);
|
||||||
g2d.setColor(color);
|
g2d.setColor(color);
|
||||||
g2d.setStroke(new BasicStroke(thickness - 2));
|
g2d.setStroke(new BasicStroke(thickness - 2));
|
||||||
g2d.draw(path);
|
g2d.draw(curve);
|
||||||
g2d.setComposite(oldComposite);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getControlPointCount() {
|
|
||||||
return controlPoints.length;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Point getControlPoint(int index) {
|
|
||||||
return controlPoints[index];
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setControlPoint(Point point, int index) {
|
|
||||||
controlPoints[index].setLocation(point);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@EditableProperty(name = "AWG")
|
@EditableProperty(name = "AWG")
|
||||||
@@ -104,13 +48,4 @@ public class HookupWire extends AbstractTransparentComponent<AWG> {
|
|||||||
public void setValue(AWG value) {
|
public void setValue(AWG value) {
|
||||||
this.value = value;
|
this.value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@EditableProperty
|
|
||||||
public Color getColor() {
|
|
||||||
return color;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setColor(Color color) {
|
|
||||||
this.color = color;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -10,7 +10,7 @@ import org.diylc.core.IDIYComponent;
|
|||||||
import org.diylc.core.annotations.ComponentDescriptor;
|
import org.diylc.core.annotations.ComponentDescriptor;
|
||||||
import org.diylc.core.measures.Size;
|
import org.diylc.core.measures.Size;
|
||||||
|
|
||||||
@ComponentDescriptor(name = "Jumper", author = "Branislav Stojkovic", category = "Connectivity", instanceNamePrefix = "J", description = "Jumper wire", zOrder = IDIYComponent.ABOVE_BOARD)
|
@ComponentDescriptor(name = "Jumper", author = "Branislav Stojkovic", category = "Connectivity", instanceNamePrefix = "J", description = "", zOrder = IDIYComponent.ABOVE_BOARD)
|
||||||
public class Jumper extends AbstractLeadedDIYComponent<Void> {
|
public class Jumper extends AbstractLeadedDIYComponent<Void> {
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|||||||
Reference in New Issue
Block a user