BJT symbol

This commit is contained in:
bancika
2012-03-10 03:47:30 +00:00
parent 89bf22bcf8
commit a7b48f4f52
9 changed files with 131 additions and 3 deletions
@@ -56,7 +56,7 @@ public class Presenter implements IPlugInPort {
private static final Logger LOG = Logger.getLogger(Presenter.class);
public static final VersionNumber CURRENT_VERSION = new VersionNumber(3, 3, 0);
public static final VersionNumber CURRENT_VERSION = new VersionNumber(3, 4, 0);
public static final String DEFAULTS_KEY_PREFIX = "default.";
public static final List<IDIYComponent<?>> EMPTY_SELECTION = Collections.emptyList();
@@ -111,7 +111,7 @@ public class ProjectFileManager {
FileOutputStream fos;
fos = new FileOutputStream(fileName);
Writer writer = new OutputStreamWriter(fos, "UTF-8");
writer.write("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>");
writer.write("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n");
xStream.toXML(project, writer);
fos.close();
if (!isBackup) {
@@ -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();
@@ -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;
}
}
@@ -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;
}
}
@@ -486,6 +486,10 @@
<changeType>NEW_FEATURE</changeType>
<description>IC Symbol</description>
</org.diylc.appframework.update.Change>
<org.diylc.appframework.update.Change>
<changeType>NEW_FEATURE</changeType>
<description>BJT Symbol</description>
</org.diylc.appframework.update.Change>
<org.diylc.appframework.update.Change>
<changeType>NEW_FEATURE</changeType>
<description>MOSFET Symbol</description>
@@ -506,6 +510,10 @@
<changeType>BUG_FIX</changeType>
<description>"Index out of bounds" exception logs when selecting components</description>
</org.diylc.appframework.update.Change>
<org.diylc.appframework.update.Change>
<changeType>BUG_FIX</changeType>
<description>Loading files fails because encoding is not recognized</description>
</org.diylc.appframework.update.Change>
<org.diylc.appframework.update.Change>
<changeType>BUG_FIX</changeType>
<description>Application breaks when resistance is set to 0 ohms</description>