mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-10 17:22:09 +10:00
Better rendering of TO-3 transformer package
This commit is contained in:
@@ -21,38 +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.Polygon;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.RenderingHints;
|
||||
import java.awt.geom.AffineTransform;
|
||||
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.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.AffineTransform;
|
||||
import java.awt.geom.Area;
|
||||
import java.awt.geom.Ellipse2D;
|
||||
import java.awt.geom.Point2D;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
|
||||
import org.diylc.appframework.miscutils.ConfigurationManager;
|
||||
import org.diylc.awt.TwoCircleTangent;
|
||||
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.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;
|
||||
|
||||
@ComponentDescriptor(name = "Transistor (TO-3)", author = "Branislav Stojkovic", category = "Semiconductors",
|
||||
instanceNamePrefix = "Q", description = "Transistor with large metal body", stretchable = false,
|
||||
@@ -189,36 +190,16 @@ public class TransistorTO3 extends AbstractTransparentComponent<String> {
|
||||
int innerDiameter = getClosestOdd(INNER_DIAMETER.convertToPixels());
|
||||
int smallDiameter = getClosestOdd(SMALL_DIAMETER.convertToPixels());
|
||||
int holeDistance = getClosestOdd(HOLE_DISTANCE.convertToPixels());
|
||||
int holeSize = getClosestOdd(HOLE_SIZE.convertToPixels());
|
||||
int holeSize = getClosestOdd(HOLE_SIZE.convertToPixels());
|
||||
|
||||
TwoCircleTangent left = new TwoCircleTangent(new Point2D.Double(x, y), new Point2D.Double(x - holeDistance / 2, y), largeDiameter / 2, smallDiameter / 2);
|
||||
TwoCircleTangent right = new TwoCircleTangent(new Point2D.Double(x, y), new Point2D.Double(x + holeDistance / 2, y), largeDiameter / 2, smallDiameter / 2);
|
||||
|
||||
body[0] = left;
|
||||
body[0].add(right);
|
||||
|
||||
body[0] =
|
||||
new Area(new Ellipse2D.Double(x - largeDiameter / 2, y - largeDiameter / 2, largeDiameter, largeDiameter));
|
||||
|
||||
int[] xPoints =
|
||||
new int[] {x + (int) (Math.cos(Math.PI / 4) * largeDiameter / 2),
|
||||
x + holeDistance / 2 + (int) (Math.cos(Math.PI / 4) * smallDiameter / 2),
|
||||
x + holeDistance / 2 + (int) (Math.cos(Math.PI / 4) * smallDiameter / 2),
|
||||
x + (int) (Math.cos(Math.PI / 4) * largeDiameter / 2),
|
||||
x - (int) (Math.cos(Math.PI / 4) * largeDiameter / 2),
|
||||
x - holeDistance / 2 - (int) (Math.cos(Math.PI / 4) * smallDiameter / 2),
|
||||
x - holeDistance / 2 - (int) (Math.cos(Math.PI / 4) * smallDiameter / 2),
|
||||
x - (int) (Math.cos(Math.PI / 4) * largeDiameter / 2)};
|
||||
int[] yPoints =
|
||||
new int[] {y - (int) (Math.sin(Math.PI / 4) * largeDiameter / 2),
|
||||
y - (int) (Math.sin(Math.PI / 4) * smallDiameter / 2),
|
||||
y + (int) (Math.sin(Math.PI / 4) * smallDiameter / 2),
|
||||
y + (int) (Math.sin(Math.PI / 4) * largeDiameter / 2),
|
||||
y + (int) (Math.sin(Math.PI / 4) * largeDiameter / 2),
|
||||
y + (int) (Math.sin(Math.PI / 4) * smallDiameter / 2),
|
||||
y - (int) (Math.sin(Math.PI / 4) * smallDiameter / 2),
|
||||
y - (int) (Math.sin(Math.PI / 4) * largeDiameter / 2)};
|
||||
body[0].add(new Area(new Polygon(xPoints, yPoints, xPoints.length)));
|
||||
body[0].add(new Area(new Ellipse2D.Double(x - holeDistance / 2 - smallDiameter / 2, y - smallDiameter / 2,
|
||||
smallDiameter, smallDiameter)));
|
||||
body[0].subtract(new Area(new Ellipse2D.Double(x - holeDistance / 2 - holeSize / 2, y - holeSize / 2, holeSize,
|
||||
holeSize)));
|
||||
body[0].add(new Area(new Ellipse2D.Double(x + holeDistance / 2 - smallDiameter / 2, y - smallDiameter / 2,
|
||||
smallDiameter, smallDiameter)));
|
||||
body[0].subtract(new Area(new Ellipse2D.Double(x + holeDistance / 2 - holeSize / 2, y - holeSize / 2, holeSize,
|
||||
holeSize)));
|
||||
|
||||
@@ -323,20 +304,14 @@ public class TransistorTO3 extends AbstractTransparentComponent<String> {
|
||||
@Override
|
||||
public void drawIcon(Graphics2D g2d, int width, int height) {
|
||||
g2d.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE);
|
||||
int sizeLarge = getClosestOdd(width * 3d / 4);
|
||||
int sizeInner = getClosestOdd(width * 5d / 10);
|
||||
int sizeSmall = getClosestOdd(width / 3d);
|
||||
int hole = 4 * width / 32;
|
||||
Area area = new Area(new Ellipse2D.Double((width - sizeLarge) / 2, (height - sizeLarge) / 2, sizeLarge, sizeLarge));
|
||||
|
||||
// Polygon p =
|
||||
// new Polygon(new int[] {(width - sizeSmall) / 2, (width + sizeSmall) / 2, (width + sizeLarge) / 2,
|
||||
// (width + sizeSmall) / 2, (width - sizeSmall) / 2, (width - sizeLarge) / 2}, new int[] {height / 8,
|
||||
// height / 8, height / 2, height * 7 / 8, height * 7 / 8, height / 2}, 6);
|
||||
// area.add(new Area(p));
|
||||
area.add(new Area(new Ellipse2D.Double((width - sizeSmall) / 2, height / 8 - sizeSmall / 2, sizeSmall, sizeSmall)));
|
||||
area.add(new Area(new Ellipse2D.Double((width - sizeSmall) / 2, height * 7 / 8 - sizeSmall / 2, sizeSmall,
|
||||
sizeSmall)));
|
||||
int largeR = getClosestOdd(width * 3d / 8);
|
||||
int smallR = getClosestOdd(width / 6d);
|
||||
int innerD = getClosestOdd(width / 2d);
|
||||
int hole = 4 * width / 32;
|
||||
|
||||
Area area = new TwoCircleTangent(new Point2D.Double(width * 0.5, height * 0.5), new Point2D.Double(width / 2, height / 8d), largeR, smallR);
|
||||
area.add((Area)new TwoCircleTangent(new Point2D.Double(width * 0.5, height * 0.5), new Point2D.Double(width / 2, height * 7 / 8d), largeR, smallR));
|
||||
|
||||
area.subtract(new Area(new Ellipse2D.Double((width - hole) / 2, height / 8 - hole / 2, hole, hole)));
|
||||
area.subtract(new Area(new Ellipse2D.Double((width - hole) / 2, height * 7 / 8 - hole / 2, hole, hole)));
|
||||
area.transform(AffineTransform.getRotateInstance(Math.PI / 4, width / 2, height / 2));
|
||||
@@ -344,7 +319,7 @@ public class TransistorTO3 extends AbstractTransparentComponent<String> {
|
||||
g2d.fill(area);
|
||||
g2d.setColor(BORDER_COLOR);
|
||||
g2d.draw(area);
|
||||
g2d.drawOval((width - sizeInner) / 2, (height - sizeInner) / 2, sizeInner, sizeInner);
|
||||
g2d.drawOval((width - innerD) / 2, (height - innerD) / 2, innerD, innerD);
|
||||
}
|
||||
|
||||
@EditableProperty(name = "Body")
|
||||
|
||||
Reference in New Issue
Block a user