mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-10 17:22:09 +10:00
added ic pins
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>lastPath</string>
|
|
||||||
<string>C:\Documents and Settings\Branislav Stojkovic\Desktop</string>
|
|
||||||
</entry>
|
|
||||||
<entry>
|
<entry>
|
||||||
<string>metric</string>
|
<string>metric</string>
|
||||||
<boolean>true</boolean>
|
<boolean>true</boolean>
|
||||||
</entry>
|
</entry>
|
||||||
|
<entry>
|
||||||
|
<string>lastPath</string>
|
||||||
|
<string>C:\Documents and Settings\Branislav Stojkovic\Desktop</string>
|
||||||
|
</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.
+3
-2
@@ -31,6 +31,7 @@ public abstract class AbstractLeadedDIYComponent<T> extends AbstractTransparentC
|
|||||||
public static Color LEAD_COLOR = Color.black;
|
public static Color LEAD_COLOR = Color.black;
|
||||||
public static Color LABEL_COLOR = Color.black;
|
public static Color LABEL_COLOR = Color.black;
|
||||||
public static Color LABEL_COLOR_SELECTED = Color.red;
|
public static Color LABEL_COLOR_SELECTED = Color.red;
|
||||||
|
public static Size LEAD_THICKNESS = new Size(0.3d, SizeUnit.mm);
|
||||||
|
|
||||||
protected Size width;
|
protected Size width;
|
||||||
protected Size height;
|
protected Size height;
|
||||||
@@ -83,7 +84,7 @@ public abstract class AbstractLeadedDIYComponent<T> extends AbstractTransparentC
|
|||||||
* @return default lead thickness. Override this method to change it.
|
* @return default lead thickness. Override this method to change it.
|
||||||
*/
|
*/
|
||||||
protected Size getLeadThickness() {
|
protected Size getLeadThickness() {
|
||||||
return new Size(0.5d, SizeUnit.mm);
|
return LEAD_THICKNESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -100,7 +101,7 @@ public abstract class AbstractLeadedDIYComponent<T> extends AbstractTransparentC
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Point getControlPoint(int index) {
|
public Point getControlPoint(int index) {
|
||||||
return (Point) points[index].clone();
|
return (Point) points[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
+1
-1
@@ -18,7 +18,7 @@ public class Size extends AbstractMeasure<SizeUnit> {
|
|||||||
|
|
||||||
public int convertToPixels() {
|
public int convertToPixels() {
|
||||||
double factor = getUnit().getFactor() / SizeUnit.in.getFactor();
|
double factor = getUnit().getFactor() / SizeUnit.in.getFactor();
|
||||||
return (int) (factor * Constants.PIXELS_PER_INCH * getValue());
|
return (int) Math.round(factor * Constants.PIXELS_PER_INCH * getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
+76
-25
@@ -7,7 +7,10 @@ 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.Rectangle;
|
||||||
|
import java.awt.Shape;
|
||||||
import java.awt.geom.Rectangle2D;
|
import java.awt.geom.Rectangle2D;
|
||||||
|
import java.awt.geom.RoundRectangle2D;
|
||||||
|
|
||||||
import org.diylc.common.Orientation;
|
import org.diylc.common.Orientation;
|
||||||
import org.diylc.components.AbstractTransparentComponent;
|
import org.diylc.components.AbstractTransparentComponent;
|
||||||
@@ -25,9 +28,14 @@ public class DIL_IC extends AbstractTransparentComponent<String> {
|
|||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
public static Color BODY_COLOR = Color.gray;
|
public static Color BODY_COLOR = Color.gray;
|
||||||
public static Color BORDER_COLOR = Color.black;
|
public static Color BORDER_COLOR = Color.gray.darker();
|
||||||
|
public static Color PIN_COLOR = Color.decode("#00B2EE");
|
||||||
|
public static Color PIN_BORDER_COLOR = PIN_COLOR.darker();
|
||||||
|
public static Color INDENT_COLOR = Color.lightGray;
|
||||||
public static Color LABEL_COLOR = Color.white;
|
public static Color LABEL_COLOR = Color.white;
|
||||||
public static int EDGE_RADIUS = 6;
|
public static int EDGE_RADIUS = 6;
|
||||||
|
public static Size PIN_SIZE = new Size(0.04d, SizeUnit.in);
|
||||||
|
public static Size INDENT_SIZE = new Size(0.15d, SizeUnit.in);
|
||||||
|
|
||||||
private String name = "New Component";
|
private String name = "New Component";
|
||||||
private String value = "";
|
private String value = "";
|
||||||
@@ -40,6 +48,12 @@ public class DIL_IC extends AbstractTransparentComponent<String> {
|
|||||||
new Point((int) (3 * Constants.GRID), (int) Constants.GRID),
|
new Point((int) (3 * Constants.GRID), (int) Constants.GRID),
|
||||||
new Point((int) (3 * Constants.GRID), (int) (2 * Constants.GRID)),
|
new Point((int) (3 * Constants.GRID), (int) (2 * Constants.GRID)),
|
||||||
new Point((int) (3 * Constants.GRID), (int) (3 * Constants.GRID)) };
|
new Point((int) (3 * Constants.GRID), (int) (3 * Constants.GRID)) };
|
||||||
|
private Shape body;
|
||||||
|
|
||||||
|
public DIL_IC() {
|
||||||
|
super();
|
||||||
|
updateControlPoints();
|
||||||
|
}
|
||||||
|
|
||||||
@EditableProperty(defaultable = false)
|
@EditableProperty(defaultable = false)
|
||||||
public String getName() {
|
public String getName() {
|
||||||
@@ -66,6 +80,8 @@ public class DIL_IC extends AbstractTransparentComponent<String> {
|
|||||||
|
|
||||||
public void setOrientation(Orientation orientation) {
|
public void setOrientation(Orientation orientation) {
|
||||||
this.orientation = orientation;
|
this.orientation = orientation;
|
||||||
|
// Reset body shape;
|
||||||
|
body = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@EditableProperty(name = "Pins")
|
@EditableProperty(name = "Pins")
|
||||||
@@ -76,6 +92,8 @@ public class DIL_IC extends AbstractTransparentComponent<String> {
|
|||||||
public void setPinCount(PinCount pinCount) {
|
public void setPinCount(PinCount pinCount) {
|
||||||
this.pinCount = pinCount;
|
this.pinCount = pinCount;
|
||||||
updateControlPoints();
|
updateControlPoints();
|
||||||
|
// Reset body shape;
|
||||||
|
body = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@EditableProperty(name = "Row spacing")
|
@EditableProperty(name = "Row spacing")
|
||||||
@@ -86,6 +104,8 @@ public class DIL_IC extends AbstractTransparentComponent<String> {
|
|||||||
public void setRowSpacing(Size rowSpacing) {
|
public void setRowSpacing(Size rowSpacing) {
|
||||||
this.rowSpacing = rowSpacing;
|
this.rowSpacing = rowSpacing;
|
||||||
updateControlPoints();
|
updateControlPoints();
|
||||||
|
// Reset body shape;
|
||||||
|
body = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -101,12 +121,14 @@ public class DIL_IC extends AbstractTransparentComponent<String> {
|
|||||||
@Override
|
@Override
|
||||||
public void setControlPoint(Point point, int index) {
|
public void setControlPoint(Point point, int index) {
|
||||||
controlPoints[index].setLocation(point);
|
controlPoints[index].setLocation(point);
|
||||||
|
body = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateControlPoints() {
|
private void updateControlPoints() {
|
||||||
Point firstPoint = controlPoints[0];
|
Point firstPoint = controlPoints[0];
|
||||||
controlPoints = new Point[pinCount.getValue()];
|
controlPoints = new Point[pinCount.getValue()];
|
||||||
controlPoints[0] = firstPoint;
|
controlPoints[0] = firstPoint;
|
||||||
|
// Update control points.
|
||||||
int dx1;
|
int dx1;
|
||||||
int dy1;
|
int dy1;
|
||||||
int dx2;
|
int dx2;
|
||||||
@@ -146,40 +168,68 @@ public class DIL_IC extends AbstractTransparentComponent<String> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Shape getBody() {
|
||||||
|
if (body == null) {
|
||||||
|
int x = controlPoints[0].x;
|
||||||
|
int y = controlPoints[0].y;
|
||||||
|
int width;
|
||||||
|
int height;
|
||||||
|
int pinSize = PIN_SIZE.convertToPixels();
|
||||||
|
switch (orientation) {
|
||||||
|
case DEFAULT:
|
||||||
|
width = rowSpacing.convertToPixels() - pinSize;
|
||||||
|
height = (int) ((pinCount.getValue() / 2) * Constants.GRID);
|
||||||
|
x += pinSize / 2;
|
||||||
|
y -= (int) (Constants.GRID / 2);
|
||||||
|
break;
|
||||||
|
case _90:
|
||||||
|
width = (int) ((pinCount.getValue() / 2) * Constants.GRID);
|
||||||
|
height = rowSpacing.convertToPixels() - pinSize;
|
||||||
|
x -= (int) (Constants.GRID / 2) + width - Constants.GRID;
|
||||||
|
y += pinSize / 2;
|
||||||
|
break;
|
||||||
|
case _180:
|
||||||
|
width = rowSpacing.convertToPixels() - pinSize;
|
||||||
|
height = (int) ((pinCount.getValue() / 2) * Constants.GRID);
|
||||||
|
x -= rowSpacing.convertToPixels() - pinSize / 2;
|
||||||
|
y -= (int) (Constants.GRID / 2) + height - Constants.GRID;
|
||||||
|
break;
|
||||||
|
case _270:
|
||||||
|
width = (int) ((pinCount.getValue() / 2) * Constants.GRID);
|
||||||
|
height = rowSpacing.convertToPixels() - pinSize;
|
||||||
|
x -= (int) (Constants.GRID / 2);
|
||||||
|
y += pinSize / 2;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new RuntimeException("Unexpected orientation: " + orientation);
|
||||||
|
}
|
||||||
|
body = new RoundRectangle2D.Double(x, y, width, height, EDGE_RADIUS, EDGE_RADIUS);
|
||||||
|
}
|
||||||
|
return body;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void draw(Graphics2D g2d, ComponentState componentState, Project project) {
|
public void draw(Graphics2D g2d, ComponentState componentState, Project project) {
|
||||||
int x = controlPoints[0].x;
|
int pinSize = PIN_SIZE.convertToPixels() / 2 * 2;
|
||||||
int y = controlPoints[0].y;
|
for (Point point : controlPoints) {
|
||||||
int width;
|
g2d.setColor(PIN_COLOR);
|
||||||
int height;
|
g2d.fillRect(point.x - pinSize / 2, point.y - pinSize / 2, pinSize, pinSize);
|
||||||
if (orientation == Orientation.DEFAULT || orientation == Orientation._180) {
|
g2d.setColor(PIN_BORDER_COLOR);
|
||||||
width = rowSpacing.convertToPixels();
|
g2d.drawRect(point.x - pinSize / 2, point.y - pinSize / 2, pinSize, pinSize);
|
||||||
height = (int) ((pinCount.getValue() / 2) * Constants.GRID);
|
|
||||||
y -= (int) (Constants.GRID / 2);
|
|
||||||
} else {
|
|
||||||
width = (int) ((pinCount.getValue() / 2) * Constants.GRID);
|
|
||||||
height = rowSpacing.convertToPixels();
|
|
||||||
x -= (int) (Constants.GRID / 2);
|
|
||||||
}
|
|
||||||
if (orientation == Orientation._90) {
|
|
||||||
x -= width - Constants.GRID;
|
|
||||||
} else if (orientation == Orientation._180) {
|
|
||||||
x -= rowSpacing.convertToPixels();
|
|
||||||
y -= height - Constants.GRID;
|
|
||||||
}
|
}
|
||||||
if (componentState != ComponentState.DRAGGING) {
|
if (componentState != ComponentState.DRAGGING) {
|
||||||
Composite oldComposite = g2d.getComposite();
|
Composite oldComposite = g2d.getComposite();
|
||||||
if (alpha < MAX_ALPHA) {
|
if (alpha < MAX_ALPHA) {
|
||||||
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER,
|
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1f * alpha
|
||||||
1f * alpha / MAX_ALPHA));
|
/ MAX_ALPHA));
|
||||||
}
|
}
|
||||||
g2d.setColor(BODY_COLOR);
|
g2d.setColor(BODY_COLOR);
|
||||||
g2d.fillRoundRect(x, y, width, height, EDGE_RADIUS, EDGE_RADIUS);
|
g2d.fill(getBody());
|
||||||
g2d.setComposite(oldComposite);
|
g2d.setComposite(oldComposite);
|
||||||
}
|
}
|
||||||
g2d.setColor(BORDER_COLOR);
|
g2d.setColor(BORDER_COLOR);
|
||||||
g2d.setStroke(new BasicStroke());
|
g2d.setStroke(new BasicStroke());
|
||||||
g2d.drawRoundRect(x, y, width, height, EDGE_RADIUS, EDGE_RADIUS);
|
g2d.draw(getBody());
|
||||||
// Draw label.
|
// Draw label.
|
||||||
g2d.setFont(Constants.LABEL_FONT);
|
g2d.setFont(Constants.LABEL_FONT);
|
||||||
g2d.setColor(componentState == ComponentState.DRAGGING ? BORDER_COLOR : LABEL_COLOR);
|
g2d.setColor(componentState == ComponentState.DRAGGING ? BORDER_COLOR : LABEL_COLOR);
|
||||||
@@ -188,8 +238,9 @@ public class DIL_IC extends AbstractTransparentComponent<String> {
|
|||||||
int textHeight = (int) (rect.getHeight());
|
int textHeight = (int) (rect.getHeight());
|
||||||
int textWidth = (int) (rect.getWidth());
|
int textWidth = (int) (rect.getWidth());
|
||||||
// Center text horizontally and vertically
|
// Center text horizontally and vertically
|
||||||
x += (width - textWidth) / 2;
|
Rectangle bounds = getBody().getBounds();
|
||||||
y += (height - textHeight) / 2 + fontMetrics.getAscent();
|
int x = bounds.x + (bounds.width - textWidth) / 2;
|
||||||
|
int y = bounds.y + (bounds.height - textHeight) / 2 + fontMetrics.getAscent();
|
||||||
g2d.drawString(getName(), x, y);
|
g2d.drawString(getName(), x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user