mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-10 17:22:09 +10:00
Added MOSFET Symbol
This commit is contained in:
+185
@@ -0,0 +1,185 @@
|
|||||||
|
package org.diylc.components.semiconductors;
|
||||||
|
|
||||||
|
import java.awt.Color;
|
||||||
|
import java.awt.Graphics2D;
|
||||||
|
import java.awt.Point;
|
||||||
|
import java.awt.Shape;
|
||||||
|
|
||||||
|
import org.diylc.appframework.miscutils.ConfigurationManager;
|
||||||
|
import org.diylc.common.Display;
|
||||||
|
import org.diylc.common.HorizontalAlignment;
|
||||||
|
import org.diylc.common.IPlugInPort;
|
||||||
|
import org.diylc.common.ObjectCache;
|
||||||
|
import org.diylc.common.VerticalAlignment;
|
||||||
|
import org.diylc.components.AbstractComponent;
|
||||||
|
import org.diylc.core.ComponentState;
|
||||||
|
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.EditableProperty;
|
||||||
|
import org.diylc.core.measures.Size;
|
||||||
|
import org.diylc.core.measures.SizeUnit;
|
||||||
|
import org.diylc.utils.Constants;
|
||||||
|
|
||||||
|
public abstract class AbstractTransistorSymbol extends AbstractComponent<String> {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
public static Size PIN_SPACING = new Size(0.1d, SizeUnit.in);
|
||||||
|
public static Color COLOR = Color.black;
|
||||||
|
|
||||||
|
protected TransistorPolarity polarity = TransistorPolarity.NPN;
|
||||||
|
protected String value = "";
|
||||||
|
protected Point[] controlPoints = new Point[] { new Point(0, 0), new Point(0, 0),
|
||||||
|
new Point(0, 0) };
|
||||||
|
protected Color color = COLOR;
|
||||||
|
protected Display display = Display.NAME;
|
||||||
|
protected Shape[] body;
|
||||||
|
|
||||||
|
public AbstractTransistorSymbol() {
|
||||||
|
super();
|
||||||
|
updateControlPoints();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void draw(Graphics2D g2d, ComponentState componentState, boolean outlineMode,
|
||||||
|
Project project, IDrawingObserver drawingObserver) {
|
||||||
|
if (checkPointsClipped(g2d.getClip())) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
int pinSpacing = (int) PIN_SPACING.convertToPixels();
|
||||||
|
Color finalColor;
|
||||||
|
if (componentState == ComponentState.SELECTED) {
|
||||||
|
finalColor = SELECTION_COLOR;
|
||||||
|
} else if (outlineMode) {
|
||||||
|
Theme theme = (Theme) ConfigurationManager.getInstance().readObject(
|
||||||
|
IPlugInPort.THEME_KEY, Constants.DEFAULT_THEME);
|
||||||
|
finalColor = theme.getOutlineColor();
|
||||||
|
} else {
|
||||||
|
finalColor = color;
|
||||||
|
}
|
||||||
|
g2d.setColor(finalColor);
|
||||||
|
|
||||||
|
// Draw transistor
|
||||||
|
|
||||||
|
int x = controlPoints[0].x;
|
||||||
|
int y = controlPoints[0].y;
|
||||||
|
|
||||||
|
Shape[] body = getBody();
|
||||||
|
|
||||||
|
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(2));
|
||||||
|
g2d.draw(body[0]);
|
||||||
|
|
||||||
|
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(1));
|
||||||
|
g2d.draw(body[1]);
|
||||||
|
|
||||||
|
g2d.fill(body[2]);
|
||||||
|
|
||||||
|
// Draw label
|
||||||
|
g2d.setFont(LABEL_FONT);
|
||||||
|
Color finalLabelColor;
|
||||||
|
if (outlineMode) {
|
||||||
|
Theme theme = (Theme) ConfigurationManager.getInstance().readObject(
|
||||||
|
IPlugInPort.THEME_KEY, Constants.DEFAULT_THEME);
|
||||||
|
finalLabelColor = componentState == ComponentState.SELECTED
|
||||||
|
|| componentState == ComponentState.DRAGGING ? LABEL_COLOR_SELECTED : theme
|
||||||
|
.getOutlineColor();
|
||||||
|
} else {
|
||||||
|
finalLabelColor = componentState == ComponentState.SELECTED
|
||||||
|
|| componentState == ComponentState.DRAGGING ? LABEL_COLOR_SELECTED
|
||||||
|
: LABEL_COLOR;
|
||||||
|
}
|
||||||
|
g2d.setColor(finalLabelColor);
|
||||||
|
drawCenteredText(g2d, display == Display.VALUE ? getValue() : getName(),
|
||||||
|
x + pinSpacing * 2, y, HorizontalAlignment.LEFT, VerticalAlignment.CENTER);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Point getControlPoint(int index) {
|
||||||
|
return controlPoints[index];
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getControlPointCount() {
|
||||||
|
return controlPoints.length;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateControlPoints() {
|
||||||
|
int pinSpacing = (int) PIN_SPACING.convertToPixels();
|
||||||
|
// Update control points.
|
||||||
|
int x = controlPoints[0].x;
|
||||||
|
int y = controlPoints[0].y;
|
||||||
|
|
||||||
|
controlPoints[1].x = x + pinSpacing * 2;
|
||||||
|
controlPoints[1].y = y - pinSpacing * 2;
|
||||||
|
|
||||||
|
controlPoints[2].x = x + pinSpacing * 2;
|
||||||
|
controlPoints[2].y = y + pinSpacing * 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public VisibilityPolicy getControlPointVisibilityPolicy(int index) {
|
||||||
|
return VisibilityPolicy.WHEN_SELECTED;
|
||||||
|
}
|
||||||
|
|
||||||
|
@EditableProperty
|
||||||
|
@Override
|
||||||
|
public String getValue() {
|
||||||
|
return this.value;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setValue(String value) {
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isControlPointSticky(int index) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setControlPoint(Point point, int index) {
|
||||||
|
controlPoints[index].setLocation(point);
|
||||||
|
// Invalidate body
|
||||||
|
body = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@EditableProperty
|
||||||
|
public TransistorPolarity getPolarity() {
|
||||||
|
return polarity;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPolarity(TransistorPolarity polarity) {
|
||||||
|
this.polarity = polarity;
|
||||||
|
// Invalidate body
|
||||||
|
body = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@EditableProperty
|
||||||
|
public Color getColor() {
|
||||||
|
return color;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setColor(Color color) {
|
||||||
|
this.color = color;
|
||||||
|
}
|
||||||
|
|
||||||
|
@EditableProperty
|
||||||
|
public Display getDisplay() {
|
||||||
|
return display;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDisplay(Display display) {
|
||||||
|
this.display = display;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns transistor shape consisting of 3 parts, in this order: main body,
|
||||||
|
* connectors, polarity arrow.
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
protected abstract Shape[] getBody();
|
||||||
|
}
|
||||||
-1
@@ -1,7 +1,6 @@
|
|||||||
package org.diylc.components.semiconductors;
|
package org.diylc.components.semiconductors;
|
||||||
|
|
||||||
import java.awt.AlphaComposite;
|
import java.awt.AlphaComposite;
|
||||||
import java.awt.BasicStroke;
|
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
import java.awt.Composite;
|
import java.awt.Composite;
|
||||||
import java.awt.Graphics2D;
|
import java.awt.Graphics2D;
|
||||||
|
|||||||
+77
@@ -0,0 +1,77 @@
|
|||||||
|
package org.diylc.components.semiconductors;
|
||||||
|
|
||||||
|
import java.awt.Graphics2D;
|
||||||
|
import java.awt.Polygon;
|
||||||
|
import java.awt.Shape;
|
||||||
|
import java.awt.geom.Area;
|
||||||
|
import java.awt.geom.GeneralPath;
|
||||||
|
import java.awt.geom.Rectangle2D;
|
||||||
|
|
||||||
|
import org.diylc.common.ObjectCache;
|
||||||
|
import org.diylc.core.IDIYComponent;
|
||||||
|
import org.diylc.core.annotations.ComponentDescriptor;
|
||||||
|
|
||||||
|
@ComponentDescriptor(name = "MOSFET Symbol", author = "Branislav Stojkovic", category = "Semiconductors", instanceNamePrefix = "Q", description = "BJT NPN and PNP transistor", stretchable = false, zOrder = IDIYComponent.COMPONENT)
|
||||||
|
public class MOSFETSymbol extends AbstractTransistorSymbol {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
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);
|
||||||
|
polyline.lineTo(x + pinSpacing / 2, y + pinSpacing);
|
||||||
|
polyline.moveTo(x + pinSpacing, y - pinSpacing);
|
||||||
|
polyline.lineTo(x + pinSpacing, y + pinSpacing);
|
||||||
|
polyline.moveTo(x + pinSpacing, y - pinSpacing);
|
||||||
|
polyline.lineTo(x + pinSpacing * 2, y - pinSpacing);
|
||||||
|
polyline.moveTo(x + pinSpacing, y + pinSpacing);
|
||||||
|
polyline.lineTo(x + pinSpacing * 2, y + pinSpacing);
|
||||||
|
body[0] = polyline;
|
||||||
|
|
||||||
|
polyline = new GeneralPath();
|
||||||
|
|
||||||
|
polyline.moveTo(x, y);
|
||||||
|
polyline.lineTo(x + pinSpacing / 2, y);
|
||||||
|
polyline.moveTo(x + pinSpacing * 2, y - pinSpacing * 2);
|
||||||
|
polyline.lineTo(x + pinSpacing * 2, y - pinSpacing);
|
||||||
|
polyline.moveTo(x + pinSpacing * 2, y + pinSpacing * 2);
|
||||||
|
polyline.lineTo(x + pinSpacing * 2, y + pinSpacing);
|
||||||
|
body[1] = polyline;
|
||||||
|
|
||||||
|
Polygon arrow;
|
||||||
|
if (polarity == TransistorPolarity.PNP) {
|
||||||
|
arrow = new Polygon(new int[] { x + pinSpacing * 8 / 6, x + pinSpacing * 8 / 6,
|
||||||
|
x + pinSpacing * 12 / 6 }, new int[] { y + pinSpacing * 6 / 5,
|
||||||
|
y + pinSpacing * 4 / 5, y + pinSpacing }, 3);
|
||||||
|
} else {
|
||||||
|
arrow = new Polygon(new int[] { x + pinSpacing * 7 / 6, x + pinSpacing * 11 / 6,
|
||||||
|
x + pinSpacing * 11 / 6 }, new int[] { y - pinSpacing,
|
||||||
|
y - pinSpacing * 6 / 5, y - pinSpacing * 4 / 5 }, 3);
|
||||||
|
}
|
||||||
|
body[2] = arrow;
|
||||||
|
}
|
||||||
|
return body;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void drawIcon(Graphics2D g2d, int width, int height) {
|
||||||
|
g2d.setColor(COLOR);
|
||||||
|
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(1));
|
||||||
|
g2d.drawLine(width / 5, height / 2, width / 2, height / 2);
|
||||||
|
g2d.drawLine(width / 2, height / 4, width / 2, height * 3 / 4);
|
||||||
|
g2d.drawLine(width * 3 / 5, height / 4, width * 3 / 5, height * 3 / 4);
|
||||||
|
|
||||||
|
g2d.drawLine(width * 4 / 5, 1, width * 4 / 5, height / 4);
|
||||||
|
g2d.drawLine(width * 4 / 5, height / 4, width * 3 / 5, height / 4);
|
||||||
|
|
||||||
|
g2d.drawLine(width * 4 / 5, height - 1, width * 4 / 5, height * 3 / 4);
|
||||||
|
g2d.drawLine(width * 4 / 5, height * 3 / 4, width * 3 / 5, height * 3 / 4);
|
||||||
|
}
|
||||||
|
}
|
||||||
+6
@@ -0,0 +1,6 @@
|
|||||||
|
package org.diylc.components.semiconductors;
|
||||||
|
|
||||||
|
public enum TransistorPolarity {
|
||||||
|
|
||||||
|
NPN, PNP,
|
||||||
|
}
|
||||||
Binary file not shown.
@@ -486,6 +486,10 @@
|
|||||||
<changeType>NEW_FEATURE</changeType>
|
<changeType>NEW_FEATURE</changeType>
|
||||||
<description>IC Symbol</description>
|
<description>IC Symbol</description>
|
||||||
</org.diylc.appframework.update.Change>
|
</org.diylc.appframework.update.Change>
|
||||||
|
<org.diylc.appframework.update.Change>
|
||||||
|
<changeType>NEW_FEATURE</changeType>
|
||||||
|
<description>MOSFET Symbol</description>
|
||||||
|
</org.diylc.appframework.update.Change>
|
||||||
<org.diylc.appframework.update.Change>
|
<org.diylc.appframework.update.Change>
|
||||||
<changeType>NEW_FEATURE</changeType>
|
<changeType>NEW_FEATURE</changeType>
|
||||||
<description>Line connector</description>
|
<description>Line connector</description>
|
||||||
|
|||||||
Reference in New Issue
Block a user