mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-11 09:42:08 +10:00
BJT symbol
This commit is contained in:
+1
-1
@@ -34,7 +34,7 @@ public abstract class AbstractTransistorSymbol extends AbstractComponent<String>
|
||||
new Point(0, 0) };
|
||||
protected Color color = COLOR;
|
||||
protected Display display = Display.NAME;
|
||||
protected Shape[] body;
|
||||
transient protected Shape[] body;
|
||||
|
||||
public AbstractTransistorSymbol() {
|
||||
super();
|
||||
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
package org.diylc.components.semiconductors;
|
||||
|
||||
public enum BJTPolarity {
|
||||
|
||||
NPN("NPN"), PNP("PNP");
|
||||
|
||||
private String title;
|
||||
|
||||
private BJTPolarity(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return title;
|
||||
}
|
||||
}
|
||||
+99
@@ -0,0 +1,99 @@
|
||||
package org.diylc.components.semiconductors;
|
||||
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Polygon;
|
||||
import java.awt.Shape;
|
||||
import java.awt.geom.AffineTransform;
|
||||
import java.awt.geom.Area;
|
||||
import java.awt.geom.GeneralPath;
|
||||
|
||||
import org.diylc.common.ObjectCache;
|
||||
import org.diylc.core.IDIYComponent;
|
||||
import org.diylc.core.annotations.ComponentDescriptor;
|
||||
import org.diylc.core.annotations.EditableProperty;
|
||||
|
||||
@ComponentDescriptor(name = "BJT Symbol", author = "Branislav Stojkovic", category = "Semiconductors", instanceNamePrefix = "Q", description = "Bipolar junction transistor schematic symbol", stretchable = false, zOrder = IDIYComponent.COMPONENT)
|
||||
public class BJTSymbol extends AbstractTransistorSymbol {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
protected BJTPolarity polarity = BJTPolarity.NPN;
|
||||
|
||||
public Shape[] getBody() {
|
||||
if (body == null) {
|
||||
body = new Shape[3];
|
||||
int x = controlPoints[0].x;
|
||||
int y = controlPoints[0].y;
|
||||
int pinSpacing = (int) PIN_SPACING.convertToPixels();
|
||||
|
||||
GeneralPath polyline = new GeneralPath();
|
||||
|
||||
polyline.moveTo(x + pinSpacing / 2, y - pinSpacing * 3 / 2);
|
||||
polyline.lineTo(x + pinSpacing / 2, y + pinSpacing * 3 / 2);
|
||||
|
||||
body[0] = polyline;
|
||||
|
||||
polyline = new GeneralPath();
|
||||
|
||||
polyline.moveTo(x, y);
|
||||
polyline.lineTo(x + pinSpacing / 2, y);
|
||||
polyline.moveTo(x + pinSpacing / 2, y - pinSpacing * 7 / 8);
|
||||
polyline.lineTo(x + pinSpacing * 2, y - pinSpacing * 3 / 2);
|
||||
polyline.lineTo(x + pinSpacing * 2, y - pinSpacing * 2);
|
||||
polyline.moveTo(x + pinSpacing / 2, y + pinSpacing * 7 / 8);
|
||||
polyline.lineTo(x + pinSpacing * 2, y + pinSpacing * 3 / 2);
|
||||
polyline.lineTo(x + pinSpacing * 2, y + pinSpacing * 2);
|
||||
body[1] = polyline;
|
||||
|
||||
Area arrow;
|
||||
double theta;
|
||||
if (polarity == BJTPolarity.NPN) {
|
||||
theta = Math.atan(5.0 / 12);
|
||||
arrow = new Area(new Polygon(new int[] { x + pinSpacing, x + pinSpacing,
|
||||
x + pinSpacing * 10 / 6 }, new int[] {
|
||||
y - pinSpacing / 5 + pinSpacing * 7 / 8,
|
||||
y + pinSpacing / 5 + pinSpacing * 7 / 8, y + pinSpacing * 7 / 8 }, 3));
|
||||
arrow.transform(AffineTransform.getRotateInstance(theta, x + pinSpacing / 2, y
|
||||
+ pinSpacing * 7 / 8));
|
||||
} else {
|
||||
theta = -Math.atan(5.0 / 12);
|
||||
arrow = new Area(new Polygon(new int[] { x + pinSpacing, x + pinSpacing * 10 / 6,
|
||||
x + pinSpacing * 10 / 6 }, new int[] { y - pinSpacing * 7 / 8,
|
||||
y - pinSpacing / 5 - pinSpacing * 7 / 8,
|
||||
y + pinSpacing / 5 - pinSpacing * 7 / 8 }, 3));
|
||||
arrow.transform(AffineTransform.getRotateInstance(theta, x + pinSpacing / 2, y
|
||||
- pinSpacing * 7 / 8));
|
||||
}
|
||||
body[2] = arrow;
|
||||
}
|
||||
return body;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawIcon(Graphics2D g2d, int width, int height) {
|
||||
g2d.setColor(COLOR);
|
||||
|
||||
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(2));
|
||||
g2d.drawLine(width / 3, height / 5, width / 3, height * 4 / 5);
|
||||
|
||||
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(1));
|
||||
g2d.drawLine(width / 8, height / 2, width / 3, height / 2);
|
||||
|
||||
g2d.drawLine(width * 3 / 4, 1, width * 3 / 4, height / 4);
|
||||
g2d.drawLine(width / 3, height / 3 + 1, width * 3 / 4, height / 4);
|
||||
|
||||
g2d.drawLine(width * 3 / 4, height - 1, width * 3 / 4, height * 3 / 4);
|
||||
g2d.drawLine(width / 3, height * 2 / 3 - 1, width * 3 / 4, height * 3 / 4);
|
||||
}
|
||||
|
||||
@EditableProperty(name = "Polarity")
|
||||
public BJTPolarity getPolarity() {
|
||||
return polarity;
|
||||
}
|
||||
|
||||
public void setPolarity(BJTPolarity polarity) {
|
||||
this.polarity = polarity;
|
||||
// Invalidate body
|
||||
body = null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user