mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-10 17:22:09 +10:00
refactor transistor packages with a base class, add pinouts
This commit is contained in:
Binary file not shown.
+187
@@ -0,0 +1,187 @@
|
||||
/*
|
||||
|
||||
DIY Layout Creator (DIYLC).
|
||||
Copyright (c) 2009-2018 held jointly by the individual authors.
|
||||
|
||||
This file is part of DIYLC.
|
||||
|
||||
DIYLC is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
DIYLC is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with DIYLC. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
*/
|
||||
package org.diylc.components.semiconductors;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Point;
|
||||
import java.awt.geom.Area;
|
||||
|
||||
import org.diylc.common.Display;
|
||||
import org.diylc.common.Orientation;
|
||||
import org.diylc.components.AbstractTransparentComponent;
|
||||
import org.diylc.core.VisibilityPolicy;
|
||||
import org.diylc.core.annotations.EditableProperty;
|
||||
import org.diylc.netlist.ISpiceMapper;
|
||||
|
||||
public abstract class AbstractTransistorPackage extends AbstractTransparentComponent<String> implements ISpiceMapper {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
protected String value = "";
|
||||
protected TransistorPinout pinout;
|
||||
protected Orientation orientation = Orientation.DEFAULT;
|
||||
protected Point[] controlPoints = new Point[] {new Point(0, 0), new Point(0, 0), new Point(0, 0)};
|
||||
transient protected Area[] body;
|
||||
|
||||
protected Color bodyColor;
|
||||
protected Color borderColor;
|
||||
protected Color labelColor = LABEL_COLOR;
|
||||
protected Display display = Display.NAME;
|
||||
|
||||
public AbstractTransistorPackage() {
|
||||
}
|
||||
|
||||
protected abstract void updateControlPoints();
|
||||
|
||||
@Override
|
||||
public int mapToSpiceNode(int index) {
|
||||
if (getPinout() == null)
|
||||
return index;
|
||||
|
||||
switch (getPinout()) {
|
||||
case BJT_CBE:
|
||||
return index;
|
||||
case BJT_EBC:
|
||||
return 2 - index;
|
||||
case JFET_DGS:
|
||||
case MOSFET_DGS:
|
||||
return index;
|
||||
case JFET_DSG:
|
||||
case MOSFET_DSG:
|
||||
switch (index) {
|
||||
case 0: return 0;
|
||||
case 1: return 2;
|
||||
case 2: return 1;
|
||||
}
|
||||
case JFET_GSD:
|
||||
case MOSFET_GSD:
|
||||
switch (index) {
|
||||
case 0: return 1;
|
||||
case 1: return 2;
|
||||
case 2: return 0;
|
||||
}
|
||||
case JFET_SGD:
|
||||
case MOSFET_SGD:
|
||||
return 2 - index;
|
||||
}
|
||||
|
||||
return index;
|
||||
}
|
||||
|
||||
@EditableProperty
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setValue(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@EditableProperty
|
||||
public Orientation getOrientation() {
|
||||
return orientation;
|
||||
}
|
||||
|
||||
public void setOrientation(Orientation orientation) {
|
||||
this.orientation = orientation;
|
||||
updateControlPoints();
|
||||
// Reset body shape;
|
||||
body = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getControlPointCount() {
|
||||
return controlPoints.length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Point getControlPoint(int index) {
|
||||
return controlPoints[index];
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isControlPointSticky(int index) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VisibilityPolicy getControlPointVisibilityPolicy(int index) {
|
||||
return VisibilityPolicy.NEVER;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setControlPoint(Point point, int index) {
|
||||
controlPoints[index].setLocation(point);
|
||||
body = null;
|
||||
}
|
||||
|
||||
@EditableProperty(name = "Body")
|
||||
public Color getBodyColor() {
|
||||
return bodyColor;
|
||||
}
|
||||
|
||||
public void setBodyColor(Color bodyColor) {
|
||||
this.bodyColor = bodyColor;
|
||||
}
|
||||
|
||||
@EditableProperty(name = "Border")
|
||||
public Color getBorderColor() {
|
||||
return borderColor;
|
||||
}
|
||||
|
||||
public void setBorderColor(Color borderColor) {
|
||||
this.borderColor = borderColor;
|
||||
}
|
||||
|
||||
@EditableProperty(name = "Label")
|
||||
public Color getLabelColor() {
|
||||
if (labelColor == null) {
|
||||
labelColor = LABEL_COLOR;
|
||||
}
|
||||
return labelColor;
|
||||
}
|
||||
|
||||
public void setLabelColor(Color labelColor) {
|
||||
this.labelColor = labelColor;
|
||||
}
|
||||
|
||||
@EditableProperty
|
||||
public Display getDisplay() {
|
||||
if (display == null) {
|
||||
display = Display.NAME;
|
||||
}
|
||||
return display;
|
||||
}
|
||||
|
||||
public void setDisplay(Display display) {
|
||||
this.display = display;
|
||||
}
|
||||
|
||||
@EditableProperty
|
||||
public TransistorPinout getPinout() {
|
||||
return pinout;
|
||||
}
|
||||
|
||||
public void setPinout(TransistorPinout pinout) {
|
||||
this.pinout = pinout;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package org.diylc.components.semiconductors;
|
||||
|
||||
public enum TransistorPinout {
|
||||
|
||||
BJT_EBC, BJT_CBE, JFET_DSG, JFET_GSD, JFET_DGS, JFET_SGD, MOSFET_DSG, MOSFET_GSD, MOSFET_DGS, MOSFET_SGD;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return name().replace("_", " ");
|
||||
};
|
||||
}
|
||||
@@ -21,42 +21,39 @@
|
||||
*/
|
||||
package org.diylc.components.semiconductors;
|
||||
|
||||
import java.awt.AlphaComposite;
|
||||
import java.awt.Color;
|
||||
import java.awt.Composite;
|
||||
import java.awt.FontMetrics;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Point;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.geom.Area;
|
||||
import java.awt.geom.Ellipse2D;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
import java.awt.geom.RoundRectangle2D;
|
||||
|
||||
import org.diylc.appframework.miscutils.ConfigurationManager;
|
||||
import org.diylc.common.Display;
|
||||
import org.diylc.common.IPlugInPort;
|
||||
import org.diylc.common.ObjectCache;
|
||||
import org.diylc.common.Orientation;
|
||||
import org.diylc.components.AbstractTransparentComponent;
|
||||
import org.diylc.components.transform.TO1Transformer;
|
||||
import org.diylc.core.ComponentState;
|
||||
import org.diylc.core.IDIYComponent;
|
||||
import org.diylc.core.IDrawingObserver;
|
||||
import org.diylc.core.Project;
|
||||
import org.diylc.core.Theme;
|
||||
import org.diylc.core.VisibilityPolicy;
|
||||
import org.diylc.core.annotations.ComponentDescriptor;
|
||||
import org.diylc.core.annotations.EditableProperty;
|
||||
import org.diylc.core.annotations.KeywordPolicy;
|
||||
import org.diylc.core.measures.Size;
|
||||
import org.diylc.core.measures.SizeUnit;
|
||||
import org.diylc.utils.Constants;
|
||||
import java.awt.AlphaComposite;
|
||||
import java.awt.Color;
|
||||
import java.awt.Composite;
|
||||
import java.awt.FontMetrics;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Point;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.geom.Area;
|
||||
import java.awt.geom.Ellipse2D;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
import java.awt.geom.RoundRectangle2D;
|
||||
|
||||
import org.diylc.appframework.miscutils.ConfigurationManager;
|
||||
import org.diylc.common.Display;
|
||||
import org.diylc.common.IPlugInPort;
|
||||
import org.diylc.common.ObjectCache;
|
||||
import org.diylc.components.transform.TO1Transformer;
|
||||
import org.diylc.core.ComponentState;
|
||||
import org.diylc.core.IDIYComponent;
|
||||
import org.diylc.core.IDrawingObserver;
|
||||
import org.diylc.core.Project;
|
||||
import org.diylc.core.Theme;
|
||||
import org.diylc.core.annotations.ComponentDescriptor;
|
||||
import org.diylc.core.annotations.EditableProperty;
|
||||
import org.diylc.core.annotations.KeywordPolicy;
|
||||
import org.diylc.core.measures.Size;
|
||||
import org.diylc.core.measures.SizeUnit;
|
||||
import org.diylc.utils.Constants;
|
||||
|
||||
@ComponentDescriptor(name = "Transistor (TO-1)", author = "Branislav Stojkovic", category = "Semiconductors",
|
||||
instanceNamePrefix = "Q", description = "Transistor with small metal body", stretchable = false,
|
||||
zOrder = IDIYComponent.COMPONENT, keywordPolicy = KeywordPolicy.SHOW_VALUE, transformer = TO1Transformer.class)
|
||||
public class TransistorTO1 extends AbstractTransparentComponent<String> {
|
||||
public class TransistorTO1 extends AbstractTransistorPackage {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@@ -71,71 +68,19 @@ public class TransistorTO1 extends AbstractTransparentComponent<String> {
|
||||
public static Size BODY_LENGTH = new Size(0.4d, SizeUnit.in);
|
||||
public static Size EDGE_RADIUS = new Size(2d, SizeUnit.mm);
|
||||
|
||||
private String value = "";
|
||||
private Orientation orientation = Orientation.DEFAULT;
|
||||
private Point[] controlPoints = new Point[] {new Point(0, 0), new Point(0, 0), new Point(0, 0)};
|
||||
transient private Area body;
|
||||
private Color bodyColor = BODY_COLOR;
|
||||
private Color borderColor = BORDER_COLOR;
|
||||
private Color labelColor = LABEL_COLOR;
|
||||
protected Display display = Display.NAME;
|
||||
private boolean folded = false;
|
||||
private Size pinSpacing = PIN_SPACING;
|
||||
|
||||
public TransistorTO1() {
|
||||
super();
|
||||
updateControlPoints();
|
||||
alpha = (byte) 100;
|
||||
}
|
||||
|
||||
@EditableProperty
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setValue(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@EditableProperty
|
||||
public Orientation getOrientation() {
|
||||
return orientation;
|
||||
}
|
||||
|
||||
public void setOrientation(Orientation orientation) {
|
||||
this.orientation = orientation;
|
||||
updateControlPoints();
|
||||
// Reset body shape;
|
||||
body = null;
|
||||
alpha = (byte) 100;
|
||||
bodyColor = BODY_COLOR;
|
||||
borderColor = BORDER_COLOR;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getControlPointCount() {
|
||||
return controlPoints.length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Point getControlPoint(int index) {
|
||||
return controlPoints[index];
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isControlPointSticky(int index) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VisibilityPolicy getControlPointVisibilityPolicy(int index) {
|
||||
return VisibilityPolicy.NEVER;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setControlPoint(Point point, int index) {
|
||||
controlPoints[index].setLocation(point);
|
||||
body = null;
|
||||
}
|
||||
|
||||
private void updateControlPoints() {
|
||||
protected void updateControlPoints() {
|
||||
int pinSpacing = (int) getPinSpacing().convertToPixels();
|
||||
// Update control points.
|
||||
int x = controlPoints[0].x;
|
||||
@@ -162,49 +107,52 @@ public class TransistorTO1 extends AbstractTransparentComponent<String> {
|
||||
}
|
||||
}
|
||||
|
||||
public Area getBody() {
|
||||
public Area[] getBody() {
|
||||
if (body == null) {
|
||||
int x = (controlPoints[0].x + controlPoints[1].x + controlPoints[2].x) / 3;
|
||||
int y = (controlPoints[0].y + controlPoints[1].y + controlPoints[2].y) / 3;
|
||||
int bodyDiameter = getClosestOdd(BODY_DIAMETER.convertToPixels());
|
||||
int bodyLength = getClosestOdd(BODY_LENGTH.convertToPixels());
|
||||
int edgeRadius = (int) EDGE_RADIUS.convertToPixels();
|
||||
int edgeRadius = (int) EDGE_RADIUS.convertToPixels();
|
||||
|
||||
Area newBody = null;
|
||||
|
||||
if (folded) {
|
||||
switch (orientation) {
|
||||
case DEFAULT:
|
||||
body =
|
||||
newBody =
|
||||
new Area(new RoundRectangle2D.Double(x - bodyLength, y - bodyDiameter / 2, bodyLength, bodyDiameter,
|
||||
edgeRadius, edgeRadius));
|
||||
body.add(new Area(new Rectangle2D.Double(x - bodyLength / 2, y - bodyDiameter / 2, bodyLength / 2,
|
||||
newBody.add(new Area(new Rectangle2D.Double(x - bodyLength / 2, y - bodyDiameter / 2, bodyLength / 2,
|
||||
bodyDiameter)));
|
||||
break;
|
||||
case _90:
|
||||
body =
|
||||
newBody =
|
||||
new Area(new RoundRectangle2D.Double(x - bodyDiameter / 2, y - bodyLength, bodyDiameter, bodyLength,
|
||||
edgeRadius, edgeRadius));
|
||||
body.add(new Area(new Rectangle2D.Double(x - bodyDiameter / 2, y - bodyLength / 2, bodyDiameter,
|
||||
newBody.add(new Area(new Rectangle2D.Double(x - bodyDiameter / 2, y - bodyLength / 2, bodyDiameter,
|
||||
bodyLength / 2)));
|
||||
break;
|
||||
case _180:
|
||||
body =
|
||||
newBody =
|
||||
new Area(new RoundRectangle2D.Double(x, y - bodyDiameter / 2, bodyLength, bodyDiameter, edgeRadius,
|
||||
edgeRadius));
|
||||
body.add(new Area(new Rectangle2D.Double(x, y - bodyDiameter / 2, bodyLength / 2, bodyDiameter)));
|
||||
newBody.add(new Area(new Rectangle2D.Double(x, y - bodyDiameter / 2, bodyLength / 2, bodyDiameter)));
|
||||
break;
|
||||
case _270:
|
||||
body =
|
||||
newBody =
|
||||
new Area(new RoundRectangle2D.Double(x - bodyDiameter / 2, y, bodyDiameter, bodyLength, edgeRadius,
|
||||
edgeRadius));
|
||||
body.add(new Area(new Rectangle2D.Double(x - bodyDiameter / 2, y, bodyDiameter, bodyLength / 2)));
|
||||
newBody.add(new Area(new Rectangle2D.Double(x - bodyDiameter / 2, y, bodyDiameter, bodyLength / 2)));
|
||||
break;
|
||||
default:
|
||||
throw new RuntimeException("Unexpected orientation: " + orientation);
|
||||
}
|
||||
} else {
|
||||
body = new Area(new Ellipse2D.Double(x - bodyDiameter / 2, y - bodyDiameter / 2, bodyDiameter, bodyDiameter));
|
||||
newBody = new Area(new Ellipse2D.Double(x - bodyDiameter / 2, y - bodyDiameter / 2, bodyDiameter, bodyDiameter));
|
||||
}
|
||||
|
||||
|
||||
body = new Area[] { newBody };
|
||||
}
|
||||
return body;
|
||||
}
|
||||
@@ -228,7 +176,7 @@ public class TransistorTO1 extends AbstractTransparentComponent<String> {
|
||||
g2d.drawOval(point.x - pinSize / 2, point.y - pinSize / 2, pinSize, pinSize);
|
||||
}
|
||||
|
||||
Area mainArea = getBody();
|
||||
Area mainArea = getBody()[0];
|
||||
Composite oldComposite = g2d.getComposite();
|
||||
if (alpha < MAX_ALPHA) {
|
||||
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1f * alpha / MAX_ALPHA));
|
||||
@@ -298,15 +246,6 @@ public class TransistorTO1 extends AbstractTransparentComponent<String> {
|
||||
}
|
||||
}
|
||||
|
||||
@EditableProperty(name = "Body")
|
||||
public Color getBodyColor() {
|
||||
return bodyColor;
|
||||
}
|
||||
|
||||
public void setBodyColor(Color bodyColor) {
|
||||
this.bodyColor = bodyColor;
|
||||
}
|
||||
|
||||
@EditableProperty
|
||||
public boolean getFolded() {
|
||||
return folded;
|
||||
@@ -330,34 +269,4 @@ public class TransistorTO1 extends AbstractTransparentComponent<String> {
|
||||
// Reset body shape;
|
||||
body = null;
|
||||
}
|
||||
|
||||
@EditableProperty(name = "Border")
|
||||
public Color getBorderColor() {
|
||||
return borderColor;
|
||||
}
|
||||
|
||||
public void setBorderColor(Color borderColor) {
|
||||
this.borderColor = borderColor;
|
||||
}
|
||||
|
||||
@EditableProperty(name = "Label")
|
||||
public Color getLabelColor() {
|
||||
return labelColor;
|
||||
}
|
||||
|
||||
public void setLabelColor(Color labelColor) {
|
||||
this.labelColor = labelColor;
|
||||
}
|
||||
|
||||
@EditableProperty
|
||||
public Display getDisplay() {
|
||||
if (display == null) {
|
||||
display = Display.NAME;
|
||||
}
|
||||
return display;
|
||||
}
|
||||
|
||||
public void setDisplay(Display display) {
|
||||
this.display = display;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,42 +21,39 @@
|
||||
*/
|
||||
package org.diylc.components.semiconductors;
|
||||
|
||||
import java.awt.AlphaComposite;
|
||||
import java.awt.Color;
|
||||
import java.awt.Composite;
|
||||
import java.awt.FontMetrics;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Point;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.Shape;
|
||||
import java.awt.geom.Area;
|
||||
import java.awt.geom.Ellipse2D;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
|
||||
import org.diylc.appframework.miscutils.ConfigurationManager;
|
||||
import org.diylc.common.Display;
|
||||
import org.diylc.common.IPlugInPort;
|
||||
import org.diylc.common.ObjectCache;
|
||||
import org.diylc.common.Orientation;
|
||||
import org.diylc.components.AbstractTransparentComponent;
|
||||
import org.diylc.components.transform.TO220Transformer;
|
||||
import org.diylc.core.ComponentState;
|
||||
import org.diylc.core.IDIYComponent;
|
||||
import org.diylc.core.IDrawingObserver;
|
||||
import org.diylc.core.Project;
|
||||
import org.diylc.core.Theme;
|
||||
import org.diylc.core.VisibilityPolicy;
|
||||
import org.diylc.core.annotations.ComponentDescriptor;
|
||||
import org.diylc.core.annotations.EditableProperty;
|
||||
import org.diylc.core.annotations.KeywordPolicy;
|
||||
import org.diylc.core.measures.Size;
|
||||
import org.diylc.core.measures.SizeUnit;
|
||||
import org.diylc.utils.Constants;
|
||||
import java.awt.AlphaComposite;
|
||||
import java.awt.Color;
|
||||
import java.awt.Composite;
|
||||
import java.awt.FontMetrics;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Point;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.Shape;
|
||||
import java.awt.geom.Area;
|
||||
import java.awt.geom.Ellipse2D;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
|
||||
import org.diylc.appframework.miscutils.ConfigurationManager;
|
||||
import org.diylc.common.Display;
|
||||
import org.diylc.common.IPlugInPort;
|
||||
import org.diylc.common.ObjectCache;
|
||||
import org.diylc.components.transform.TO220Transformer;
|
||||
import org.diylc.core.ComponentState;
|
||||
import org.diylc.core.IDIYComponent;
|
||||
import org.diylc.core.IDrawingObserver;
|
||||
import org.diylc.core.Project;
|
||||
import org.diylc.core.Theme;
|
||||
import org.diylc.core.annotations.ComponentDescriptor;
|
||||
import org.diylc.core.annotations.EditableProperty;
|
||||
import org.diylc.core.annotations.KeywordPolicy;
|
||||
import org.diylc.core.measures.Size;
|
||||
import org.diylc.core.measures.SizeUnit;
|
||||
import org.diylc.utils.Constants;
|
||||
|
||||
@ComponentDescriptor(name = "Transistor (TO-220)", author = "Branislav Stojkovic", category = "Semiconductors",
|
||||
instanceNamePrefix = "Q", description = "Transistors with metal tab for heat sink mounting", stretchable = false,
|
||||
zOrder = IDIYComponent.COMPONENT, keywordPolicy = KeywordPolicy.SHOW_VALUE, transformer = TO220Transformer.class)
|
||||
public class TransistorTO220 extends AbstractTransparentComponent<String> {
|
||||
public class TransistorTO220 extends AbstractTransistorPackage {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@@ -78,72 +75,21 @@ public class TransistorTO220 extends AbstractTransparentComponent<String> {
|
||||
public static Size LEAD_LENGTH = new Size(3.5d, SizeUnit.mm);
|
||||
public static Size LEAD_THICKNESS = new Size(0.8d, SizeUnit.mm);
|
||||
|
||||
private String value = "";
|
||||
private Orientation orientation = Orientation.DEFAULT;
|
||||
private Point[] controlPoints = new Point[] {new Point(0, 0), new Point(0, 0), new Point(0, 0)};
|
||||
transient private Shape[] body;
|
||||
private Color bodyColor = BODY_COLOR;
|
||||
private Color borderColor = BORDER_COLOR;
|
||||
private Color tabColor = TAB_COLOR;
|
||||
private Color tabBorderColor = TAB_BORDER_COLOR;
|
||||
private Display display = Display.NAME;
|
||||
private boolean folded = false;
|
||||
private Size leadLength = LEAD_LENGTH;
|
||||
|
||||
public TransistorTO220() {
|
||||
super();
|
||||
updateControlPoints();
|
||||
alpha = (byte) 100;
|
||||
alpha = (byte) 100;
|
||||
bodyColor = BODY_COLOR;
|
||||
borderColor = BORDER_COLOR;
|
||||
}
|
||||
|
||||
@EditableProperty
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setValue(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@EditableProperty
|
||||
public Orientation getOrientation() {
|
||||
return orientation;
|
||||
}
|
||||
|
||||
public void setOrientation(Orientation orientation) {
|
||||
this.orientation = orientation;
|
||||
updateControlPoints();
|
||||
// Reset body shape;
|
||||
body = null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getControlPointCount() {
|
||||
return controlPoints.length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Point getControlPoint(int index) {
|
||||
return controlPoints[index];
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isControlPointSticky(int index) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VisibilityPolicy getControlPointVisibilityPolicy(int index) {
|
||||
return VisibilityPolicy.NEVER;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setControlPoint(Point point, int index) {
|
||||
controlPoints[index].setLocation(point);
|
||||
body = null;
|
||||
}
|
||||
|
||||
private void updateControlPoints() {
|
||||
protected void updateControlPoints() {
|
||||
int pinSpacing = (int) PIN_SPACING.convertToPixels();
|
||||
// Update control points.
|
||||
int x = controlPoints[0].x;
|
||||
@@ -170,9 +116,9 @@ public class TransistorTO220 extends AbstractTransparentComponent<String> {
|
||||
}
|
||||
}
|
||||
|
||||
public Shape[] getBody() {
|
||||
public Area[] getBody() {
|
||||
if (body == null) {
|
||||
body = new Shape[2];
|
||||
body = new Area[2];
|
||||
int x = controlPoints[0].x;
|
||||
int y = controlPoints[0].y;
|
||||
int pinSpacing = (int) PIN_SPACING.convertToPixels();
|
||||
@@ -187,68 +133,68 @@ public class TransistorTO220 extends AbstractTransparentComponent<String> {
|
||||
switch (orientation) {
|
||||
case DEFAULT:
|
||||
if (folded) {
|
||||
body[0] = new Rectangle2D.Double(x + leadLength, y + pinSpacing - bodyWidth / 2, bodyHeight, bodyWidth);
|
||||
body[0] = new Area(new Rectangle2D.Double(x + leadLength, y + pinSpacing - bodyWidth / 2, bodyHeight, bodyWidth));
|
||||
body[1] =
|
||||
new Area(new Rectangle2D.Double(x + leadLength + bodyHeight, y + pinSpacing - bodyWidth / 2, tabHeight,
|
||||
bodyWidth));
|
||||
((Area) body[1]).subtract(new Area(new Ellipse2D.Double(x + leadLength + bodyHeight + tabHeight / 2
|
||||
- tabHoleDiameter / 2, y + pinSpacing - tabHoleDiameter / 2, tabHoleDiameter, tabHoleDiameter)));
|
||||
} else {
|
||||
body[0] =
|
||||
new Rectangle2D.Double(x - bodyThickness / 2, y + pinSpacing - bodyWidth / 2, bodyThickness, bodyWidth);
|
||||
body[1] =
|
||||
body[0] = new Area(
|
||||
new Rectangle2D.Double(x - bodyThickness / 2, y + pinSpacing - bodyWidth / 2, bodyThickness, bodyWidth));
|
||||
body[1] = new Area(
|
||||
new Rectangle2D.Double(x + bodyThickness / 2 - tabThickness, y + pinSpacing - bodyWidth / 2,
|
||||
tabThickness, bodyWidth);
|
||||
tabThickness, bodyWidth));
|
||||
}
|
||||
break;
|
||||
case _90:
|
||||
if (folded) {
|
||||
body[0] = new Rectangle2D.Double(x - pinSpacing - bodyWidth / 2, y + leadLength, bodyWidth, bodyHeight);
|
||||
body[0] = new Area(new Rectangle2D.Double(x - pinSpacing - bodyWidth / 2, y + leadLength, bodyWidth, bodyHeight));
|
||||
body[1] =
|
||||
new Area(new Rectangle2D.Double(x - pinSpacing - bodyWidth / 2, y + leadLength + bodyHeight, bodyWidth,
|
||||
tabHeight));
|
||||
((Area) body[1]).subtract(new Area(new Ellipse2D.Double(x - pinSpacing - tabHoleDiameter / 2, y
|
||||
+ leadLength + bodyHeight + tabHeight / 2 - tabHoleDiameter / 2, tabHoleDiameter, tabHoleDiameter)));
|
||||
} else {
|
||||
body[0] =
|
||||
new Rectangle2D.Double(x - pinSpacing - bodyWidth / 2, y - bodyThickness / 2, bodyWidth, bodyThickness);
|
||||
body[1] =
|
||||
body[0] = new Area(
|
||||
new Rectangle2D.Double(x - pinSpacing - bodyWidth / 2, y - bodyThickness / 2, bodyWidth, bodyThickness));
|
||||
body[1] = new Area(
|
||||
new Rectangle2D.Double(x - pinSpacing - bodyWidth / 2, y + bodyThickness / 2 - tabThickness, bodyWidth,
|
||||
tabThickness);
|
||||
tabThickness));
|
||||
}
|
||||
break;
|
||||
case _180:
|
||||
if (folded) {
|
||||
body[0] =
|
||||
body[0] = new Area(
|
||||
new Rectangle2D.Double(x - leadLength - bodyHeight, y - pinSpacing - bodyWidth / 2, bodyHeight,
|
||||
bodyWidth);
|
||||
bodyWidth));
|
||||
body[1] =
|
||||
new Area(new Rectangle2D.Double(x - leadLength - bodyHeight - tabHeight,
|
||||
y - pinSpacing - bodyWidth / 2, tabHeight, bodyWidth));
|
||||
((Area) body[1]).subtract(new Area(new Ellipse2D.Double(x - leadLength - bodyHeight - tabHeight / 2
|
||||
- tabHoleDiameter / 2, y - pinSpacing - tabHoleDiameter / 2, tabHoleDiameter, tabHoleDiameter)));
|
||||
} else {
|
||||
body[0] =
|
||||
new Rectangle2D.Double(x - bodyThickness / 2, y - pinSpacing - bodyWidth / 2, bodyThickness, bodyWidth);
|
||||
body[1] =
|
||||
new Rectangle2D.Double(x - bodyThickness / 2, y - pinSpacing - bodyWidth / 2, tabThickness, bodyWidth);
|
||||
body[0] = new Area(
|
||||
new Rectangle2D.Double(x - bodyThickness / 2, y - pinSpacing - bodyWidth / 2, bodyThickness, bodyWidth));
|
||||
body[1] = new Area(
|
||||
new Rectangle2D.Double(x - bodyThickness / 2, y - pinSpacing - bodyWidth / 2, tabThickness, bodyWidth));
|
||||
}
|
||||
break;
|
||||
case _270:
|
||||
if (folded) {
|
||||
body[0] =
|
||||
body[0] = new Area(
|
||||
new Rectangle2D.Double(x + pinSpacing - bodyWidth / 2, y - leadLength - bodyHeight, bodyWidth,
|
||||
bodyHeight);
|
||||
bodyHeight));
|
||||
body[1] =
|
||||
new Area(new Rectangle2D.Double(x + pinSpacing - bodyWidth / 2,
|
||||
y - leadLength - bodyHeight - tabHeight, bodyWidth, tabHeight));
|
||||
((Area) body[1]).subtract(new Area(new Ellipse2D.Double(x + pinSpacing - tabHoleDiameter / 2, y
|
||||
- leadLength - bodyHeight - tabHeight / 2 - tabHoleDiameter / 2, tabHoleDiameter, tabHoleDiameter)));
|
||||
} else {
|
||||
body[0] =
|
||||
new Rectangle2D.Double(x + pinSpacing - bodyWidth / 2, y - bodyThickness / 2, bodyWidth, bodyThickness);
|
||||
body[1] =
|
||||
new Rectangle2D.Double(x + pinSpacing - bodyWidth / 2, y - bodyThickness / 2, bodyWidth, tabThickness);
|
||||
body[0] = new Area(
|
||||
new Rectangle2D.Double(x + pinSpacing - bodyWidth / 2, y - bodyThickness / 2, bodyWidth, bodyThickness));
|
||||
body[1] = new Area(
|
||||
new Rectangle2D.Double(x + pinSpacing - bodyWidth / 2, y - bodyThickness / 2, bodyWidth, tabThickness));
|
||||
}
|
||||
break;
|
||||
default:
|
||||
@@ -382,7 +328,7 @@ public class TransistorTO220 extends AbstractTransparentComponent<String> {
|
||||
} else {
|
||||
finalLabelColor =
|
||||
componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING ? LABEL_COLOR_SELECTED
|
||||
: LABEL_COLOR;
|
||||
: getLabelColor();
|
||||
}
|
||||
g2d.setColor(finalLabelColor);
|
||||
String label = "";
|
||||
@@ -428,24 +374,6 @@ public class TransistorTO220 extends AbstractTransparentComponent<String> {
|
||||
g2d.drawLine(width / 2 + bodySize / 3, margin + tabSize + bodySize, width / 2 + bodySize / 3, height - margin);
|
||||
}
|
||||
|
||||
@EditableProperty(name = "Body")
|
||||
public Color getBodyColor() {
|
||||
return bodyColor;
|
||||
}
|
||||
|
||||
public void setBodyColor(Color bodyColor) {
|
||||
this.bodyColor = bodyColor;
|
||||
}
|
||||
|
||||
@EditableProperty(name = "Border")
|
||||
public Color getBorderColor() {
|
||||
return borderColor;
|
||||
}
|
||||
|
||||
public void setBorderColor(Color borderColor) {
|
||||
this.borderColor = borderColor;
|
||||
}
|
||||
|
||||
@EditableProperty(name = "Tab")
|
||||
public Color getTabColor() {
|
||||
return tabColor;
|
||||
@@ -487,17 +415,5 @@ public class TransistorTO220 extends AbstractTransparentComponent<String> {
|
||||
|
||||
public void setTabBorderColor(Color tabBorderColor) {
|
||||
this.tabBorderColor = tabBorderColor;
|
||||
}
|
||||
|
||||
@EditableProperty
|
||||
public Display getDisplay() {
|
||||
if (display == null) {
|
||||
display = Display.NAME;
|
||||
}
|
||||
return display;
|
||||
}
|
||||
|
||||
public void setDisplay(Display display) {
|
||||
this.display = display;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,42 +21,39 @@
|
||||
*/
|
||||
package org.diylc.components.semiconductors;
|
||||
|
||||
import java.awt.AlphaComposite;
|
||||
import java.awt.Color;
|
||||
import java.awt.Composite;
|
||||
import java.awt.FontMetrics;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Point;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.RenderingHints;
|
||||
import java.awt.geom.Area;
|
||||
import java.awt.geom.Ellipse2D;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
|
||||
import org.diylc.appframework.miscutils.ConfigurationManager;
|
||||
import org.diylc.common.Display;
|
||||
import org.diylc.common.IPlugInPort;
|
||||
import org.diylc.common.ObjectCache;
|
||||
import org.diylc.common.Orientation;
|
||||
import org.diylc.components.AbstractTransparentComponent;
|
||||
import org.diylc.components.transform.TO92Transformer;
|
||||
import org.diylc.core.ComponentState;
|
||||
import org.diylc.core.IDIYComponent;
|
||||
import org.diylc.core.IDrawingObserver;
|
||||
import org.diylc.core.Project;
|
||||
import org.diylc.core.Theme;
|
||||
import org.diylc.core.VisibilityPolicy;
|
||||
import org.diylc.core.annotations.ComponentDescriptor;
|
||||
import org.diylc.core.annotations.EditableProperty;
|
||||
import org.diylc.core.annotations.KeywordPolicy;
|
||||
import org.diylc.core.measures.Size;
|
||||
import org.diylc.core.measures.SizeUnit;
|
||||
import org.diylc.utils.Constants;
|
||||
import java.awt.AlphaComposite;
|
||||
import java.awt.Color;
|
||||
import java.awt.Composite;
|
||||
import java.awt.FontMetrics;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Point;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.RenderingHints;
|
||||
import java.awt.geom.Area;
|
||||
import java.awt.geom.Ellipse2D;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
|
||||
import org.diylc.appframework.miscutils.ConfigurationManager;
|
||||
import org.diylc.common.Display;
|
||||
import org.diylc.common.IPlugInPort;
|
||||
import org.diylc.common.ObjectCache;
|
||||
import org.diylc.components.transform.TO92Transformer;
|
||||
import org.diylc.core.ComponentState;
|
||||
import org.diylc.core.IDIYComponent;
|
||||
import org.diylc.core.IDrawingObserver;
|
||||
import org.diylc.core.Project;
|
||||
import org.diylc.core.Theme;
|
||||
import org.diylc.core.annotations.ComponentDescriptor;
|
||||
import org.diylc.core.annotations.EditableProperty;
|
||||
import org.diylc.core.annotations.KeywordPolicy;
|
||||
import org.diylc.core.measures.Size;
|
||||
import org.diylc.core.measures.SizeUnit;
|
||||
import org.diylc.utils.Constants;
|
||||
|
||||
@ComponentDescriptor(name = "Transistor (TO-92)", author = "Branislav Stojkovic", category = "Semiconductors",
|
||||
instanceNamePrefix = "Q", description = "Transistor with small plastic or epoxy body", stretchable = false,
|
||||
zOrder = IDIYComponent.COMPONENT, keywordPolicy = KeywordPolicy.SHOW_VALUE, transformer = TO92Transformer.class)
|
||||
public class TransistorTO92 extends AbstractTransparentComponent<String> {
|
||||
public class TransistorTO92 extends AbstractTransistorPackage {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@@ -69,42 +66,15 @@ public class TransistorTO92 extends AbstractTransparentComponent<String> {
|
||||
public static Size PIN_SPACING = new Size(0.05d, SizeUnit.in);
|
||||
public static Size BODY_DIAMETER = new Size(0.2d, SizeUnit.in);
|
||||
|
||||
private String value = "";
|
||||
private Orientation orientation = Orientation.DEFAULT;
|
||||
private Point[] controlPoints = new Point[] {new Point(0, 0), new Point(0, 0), new Point(0, 0)};
|
||||
transient private Area body;
|
||||
private Color bodyColor = BODY_COLOR;
|
||||
private Color borderColor = BORDER_COLOR;
|
||||
private Color labelColor = LABEL_COLOR;
|
||||
protected Display display = Display.NAME;
|
||||
private boolean folded = false;
|
||||
private Size pinSpacing = PIN_SPACING;
|
||||
private Size pinSpacing = PIN_SPACING;
|
||||
|
||||
public TransistorTO92() {
|
||||
super();
|
||||
updateControlPoints();
|
||||
alpha = (byte) 100;
|
||||
}
|
||||
|
||||
@EditableProperty
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setValue(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@EditableProperty
|
||||
public Orientation getOrientation() {
|
||||
return orientation;
|
||||
}
|
||||
|
||||
public void setOrientation(Orientation orientation) {
|
||||
this.orientation = orientation;
|
||||
updateControlPoints();
|
||||
// Reset body shape;
|
||||
body = null;
|
||||
alpha = (byte) 100;
|
||||
bodyColor = BODY_COLOR;
|
||||
borderColor = BORDER_COLOR;
|
||||
}
|
||||
|
||||
@EditableProperty
|
||||
@@ -132,34 +102,9 @@ public class TransistorTO92 extends AbstractTransparentComponent<String> {
|
||||
// Reset body shape;
|
||||
body = null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getControlPointCount() {
|
||||
return controlPoints.length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Point getControlPoint(int index) {
|
||||
return controlPoints[index];
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isControlPointSticky(int index) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VisibilityPolicy getControlPointVisibilityPolicy(int index) {
|
||||
return VisibilityPolicy.NEVER;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setControlPoint(Point point, int index) {
|
||||
controlPoints[index].setLocation(point);
|
||||
body = null;
|
||||
}
|
||||
|
||||
private void updateControlPoints() {
|
||||
protected void updateControlPoints() {
|
||||
int pinSpacing = (int) getPinSpacing().convertToPixels();
|
||||
// Update control points.
|
||||
int x = controlPoints[0].x;
|
||||
@@ -186,25 +131,27 @@ public class TransistorTO92 extends AbstractTransparentComponent<String> {
|
||||
}
|
||||
}
|
||||
|
||||
public Area getBody() {
|
||||
public Area[] getBody() {
|
||||
if (body == null) {
|
||||
int x = (controlPoints[0].x + controlPoints[1].x + controlPoints[2].x) / 3;
|
||||
int y = (controlPoints[0].y + controlPoints[1].y + controlPoints[2].y) / 3;
|
||||
int bodyDiameter = getClosestOdd(BODY_DIAMETER.convertToPixels());
|
||||
int bodyDiameter = getClosestOdd(BODY_DIAMETER.convertToPixels());
|
||||
|
||||
Area newBody = null;
|
||||
|
||||
if (folded) {
|
||||
switch (orientation) {
|
||||
case DEFAULT:
|
||||
body = new Area(new Rectangle2D.Double(x - bodyDiameter, y - bodyDiameter / 2, bodyDiameter, bodyDiameter));
|
||||
newBody = new Area(new Rectangle2D.Double(x - bodyDiameter, y - bodyDiameter / 2, bodyDiameter, bodyDiameter));
|
||||
break;
|
||||
case _90:
|
||||
body = new Area(new Rectangle2D.Double(x - bodyDiameter / 2, y - bodyDiameter, bodyDiameter, bodyDiameter));
|
||||
newBody = new Area(new Rectangle2D.Double(x - bodyDiameter / 2, y - bodyDiameter, bodyDiameter, bodyDiameter));
|
||||
break;
|
||||
case _180:
|
||||
body = new Area(new Rectangle2D.Double(x, y - bodyDiameter / 2, bodyDiameter, bodyDiameter));
|
||||
newBody = new Area(new Rectangle2D.Double(x, y - bodyDiameter / 2, bodyDiameter, bodyDiameter));
|
||||
break;
|
||||
case _270:
|
||||
body = new Area(new Rectangle2D.Double(x - bodyDiameter / 2, y, bodyDiameter, bodyDiameter));
|
||||
newBody = new Area(new Rectangle2D.Double(x - bodyDiameter / 2, y, bodyDiameter, bodyDiameter));
|
||||
break;
|
||||
default:
|
||||
throw new RuntimeException("Unexpected orientation: " + orientation);
|
||||
@@ -212,33 +159,35 @@ public class TransistorTO92 extends AbstractTransparentComponent<String> {
|
||||
} else {
|
||||
switch (orientation) {
|
||||
case DEFAULT:
|
||||
body =
|
||||
newBody =
|
||||
new Area(new Ellipse2D.Double(x - bodyDiameter / 2, y - bodyDiameter / 2, bodyDiameter, bodyDiameter));
|
||||
body.subtract(new Area(new Rectangle2D.Double(x - bodyDiameter, y - bodyDiameter / 2, 3 * bodyDiameter / 4,
|
||||
newBody.subtract(new Area(new Rectangle2D.Double(x - bodyDiameter, y - bodyDiameter / 2, 3 * bodyDiameter / 4,
|
||||
bodyDiameter)));
|
||||
break;
|
||||
case _90:
|
||||
body =
|
||||
newBody =
|
||||
new Area(new Ellipse2D.Double(x - bodyDiameter / 2, y - bodyDiameter / 2, bodyDiameter, bodyDiameter));
|
||||
body.subtract(new Area(new Rectangle2D.Double(x - bodyDiameter / 2, y - bodyDiameter, bodyDiameter,
|
||||
newBody.subtract(new Area(new Rectangle2D.Double(x - bodyDiameter / 2, y - bodyDiameter, bodyDiameter,
|
||||
3 * bodyDiameter / 4)));
|
||||
break;
|
||||
case _180:
|
||||
body =
|
||||
newBody =
|
||||
new Area(new Ellipse2D.Double(x - bodyDiameter / 2, y - bodyDiameter / 2, bodyDiameter, bodyDiameter));
|
||||
body.subtract(new Area(new Rectangle2D.Double(x + bodyDiameter / 4, y - bodyDiameter / 2,
|
||||
newBody.subtract(new Area(new Rectangle2D.Double(x + bodyDiameter / 4, y - bodyDiameter / 2,
|
||||
3 * bodyDiameter / 4, bodyDiameter)));
|
||||
break;
|
||||
case _270:
|
||||
body =
|
||||
newBody =
|
||||
new Area(new Ellipse2D.Double(x - bodyDiameter / 2, y - bodyDiameter / 2, bodyDiameter, bodyDiameter));
|
||||
body.subtract(new Area(new Rectangle2D.Double(x - bodyDiameter / 2, y + bodyDiameter / 4, bodyDiameter,
|
||||
newBody.subtract(new Area(new Rectangle2D.Double(x - bodyDiameter / 2, y + bodyDiameter / 4, bodyDiameter,
|
||||
3 * bodyDiameter / 4)));
|
||||
break;
|
||||
default:
|
||||
throw new RuntimeException("Unexpected orientation: " + orientation);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
body = new Area[] { newBody };
|
||||
}
|
||||
return body;
|
||||
}
|
||||
@@ -261,7 +210,7 @@ public class TransistorTO92 extends AbstractTransparentComponent<String> {
|
||||
}
|
||||
}
|
||||
|
||||
Area mainArea = getBody();
|
||||
Area mainArea = getBody()[0];
|
||||
Composite oldComposite = g2d.getComposite();
|
||||
if (alpha < MAX_ALPHA) {
|
||||
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1f * alpha / MAX_ALPHA));
|
||||
@@ -337,46 +286,4 @@ public class TransistorTO92 extends AbstractTransparentComponent<String> {
|
||||
g2d.fillOval(width / 2 - pinSize / 2, (height / 4) * (i + 1), pinSize, pinSize);
|
||||
}
|
||||
}
|
||||
|
||||
@EditableProperty(name = "Body")
|
||||
public Color getBodyColor() {
|
||||
return bodyColor;
|
||||
}
|
||||
|
||||
public void setBodyColor(Color bodyColor) {
|
||||
this.bodyColor = bodyColor;
|
||||
}
|
||||
|
||||
@EditableProperty(name = "Border")
|
||||
public Color getBorderColor() {
|
||||
return borderColor;
|
||||
}
|
||||
|
||||
public void setBorderColor(Color borderColor) {
|
||||
this.borderColor = borderColor;
|
||||
}
|
||||
|
||||
@EditableProperty(name = "Label")
|
||||
public Color getLabelColor() {
|
||||
if (labelColor == null) {
|
||||
labelColor = LABEL_COLOR;
|
||||
}
|
||||
return labelColor;
|
||||
}
|
||||
|
||||
public void setLabelColor(Color labelColor) {
|
||||
this.labelColor = labelColor;
|
||||
}
|
||||
|
||||
@EditableProperty
|
||||
public Display getDisplay() {
|
||||
if (display == null) {
|
||||
display = Display.NAME;
|
||||
}
|
||||
return display;
|
||||
}
|
||||
|
||||
public void setDisplay(Display display) {
|
||||
this.display = display;
|
||||
}
|
||||
}
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user