diff --git a/diylc/diylc-library/src/org/diylc/components/semiconductors/TransistorTO3.java b/diylc/diylc-library/src/org/diylc/components/semiconductors/TransistorTO3.java index 9f7808f3..5cd24d7d 100644 --- a/diylc/diylc-library/src/org/diylc/components/semiconductors/TransistorTO3.java +++ b/diylc/diylc-library/src/org/diylc/components/semiconductors/TransistorTO3.java @@ -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 { 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 { @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 { 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") diff --git a/diylc/diylc-swing/library/main.jar b/diylc/diylc-swing/library/main.jar index b0cc4c78..5755f26d 100644 Binary files a/diylc/diylc-swing/library/main.jar and b/diylc/diylc-swing/library/main.jar differ diff --git a/diylc/diylc-swing/update.xml b/diylc/diylc-swing/update.xml index 5d0a4d0f..17bff4c2 100644 --- a/diylc/diylc-swing/update.xml +++ b/diylc/diylc-swing/update.xml @@ -2404,7 +2404,7 @@ NEW_FEATURE - Show mouse position coordiantes in the status bar + Show mouse cursor coordiantes in the status bar NEW_FEATURE @@ -2434,6 +2434,10 @@ IMPROVEMENT Better rendering of guitar pickups when dragging and in outline mode + + IMPROVEMENT + Better rendering of TO-3 transformer package + BUG_FIX Drag&Drop from the tree sometimes picks up a wrong component type