mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-10 17:22:09 +10:00
flip potentiometer symbol horizontally
This commit is contained in:
Binary file not shown.
@@ -12,6 +12,7 @@ import org.diylc.core.IDIYComponent;
|
||||
import org.diylc.core.annotations.ComponentDescriptor;
|
||||
import org.diylc.core.annotations.KeywordPolicy;
|
||||
import org.diylc.components.semiconductors.AbstractTransistorSymbol;
|
||||
import org.diylc.components.semiconductors.SymbolFlipping;
|
||||
|
||||
@ComponentDescriptor(name = "Potentiometer Symbol", author = "MCbx", category = "Schematics",
|
||||
instanceNamePrefix = " VR", description = "Potentiometer symbol", stretchable = false,
|
||||
@@ -69,32 +70,43 @@ public class PotentiometerSymbol extends AbstractTransistorSymbol {
|
||||
|
||||
@Override
|
||||
protected int getLabelX(Rectangle2D shapeRect, Rectangle2D textRect, FontMetrics fontMetrics, boolean outlineMode) {
|
||||
int pinSpacing = (int) PIN_SPACING.convertToPixels();
|
||||
if (controlPoints[0].x < controlPoints[1].x && controlPoints[0].x < controlPoints[2].x)
|
||||
return controlPoints[1].x + pinSpacing / 3;
|
||||
if (controlPoints[0].y < controlPoints[1].y && controlPoints[0].y < controlPoints[2].y)
|
||||
return controlPoints[0].x - (int) (textRect.getWidth() / 2);
|
||||
if (controlPoints[0].x > controlPoints[1].x && controlPoints[0].x > controlPoints[2].x)
|
||||
return controlPoints[1].x - pinSpacing / 2 - (int) textRect.getWidth();
|
||||
if (controlPoints[0].y > controlPoints[1].y && controlPoints[0].y > controlPoints[2].y)
|
||||
return controlPoints[0].x - (int) (textRect.getWidth() / 2);
|
||||
return 2 * ((int) (shapeRect.getWidth() - textRect.getWidth()) / 2 + (int) shapeRect.getX());
|
||||
int x = super.getLabelX(shapeRect, textRect, fontMetrics, outlineMode);
|
||||
if (getFlip() == SymbolFlipping.X)
|
||||
return x - (int) (PIN_SPACING.convertToPixels() / 2);
|
||||
return x + (int) PIN_SPACING.convertToPixels();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getLabelY(Rectangle2D shapeRect, Rectangle2D textRect, FontMetrics fontMetrics, boolean outlineMode) {
|
||||
int pinSpacing = (int) PIN_SPACING.convertToPixels();
|
||||
if (controlPoints[0].x < controlPoints[1].x && controlPoints[0].x < controlPoints[2].x)
|
||||
return controlPoints[0].y;
|
||||
if (controlPoints[0].y < controlPoints[1].y && controlPoints[0].y < controlPoints[2].y)
|
||||
return controlPoints[1].y + pinSpacing * 2 / 3;
|
||||
if (controlPoints[0].x > controlPoints[1].x && controlPoints[0].x > controlPoints[2].x)
|
||||
return controlPoints[0].y;
|
||||
if (controlPoints[0].y > controlPoints[1].y && controlPoints[0].y > controlPoints[2].y)
|
||||
return controlPoints[1].y - pinSpacing * 2 / 3;
|
||||
return 2 * ((int) (shapeRect.getHeight() - textRect.getHeight()) / 2 + fontMetrics.getAscent() + (int) shapeRect
|
||||
.getY());
|
||||
}
|
||||
// @Override
|
||||
// protected int getLabelX(Rectangle2D shapeRect, Rectangle2D textRect, FontMetrics fontMetrics,
|
||||
// boolean outlineMode) {
|
||||
// int pinSpacing = (int) PIN_SPACING.convertToPixels();
|
||||
// if (controlPoints[0].x < controlPoints[1].x && controlPoints[0].x < controlPoints[2].x)
|
||||
// return controlPoints[1].x + pinSpacing / 3;
|
||||
// if (controlPoints[0].y < controlPoints[1].y && controlPoints[0].y < controlPoints[2].y)
|
||||
// return controlPoints[0].x - (int) (textRect.getWidth() / 2);
|
||||
// if (controlPoints[0].x > controlPoints[1].x && controlPoints[0].x > controlPoints[2].x)
|
||||
// return controlPoints[1].x - pinSpacing / 2 - (int) textRect.getWidth();
|
||||
// if (controlPoints[0].y > controlPoints[1].y && controlPoints[0].y > controlPoints[2].y)
|
||||
// return controlPoints[0].x - (int) (textRect.getWidth() / 2);
|
||||
// return 2 * ((int) (shapeRect.getWidth() - textRect.getWidth()) / 2 + (int) shapeRect.getX());
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// protected int getLabelY(Rectangle2D shapeRect, Rectangle2D textRect, FontMetrics fontMetrics,
|
||||
// boolean outlineMode) {
|
||||
// int pinSpacing = (int) PIN_SPACING.convertToPixels();
|
||||
// if (controlPoints[0].x < controlPoints[1].x && controlPoints[0].x < controlPoints[2].x)
|
||||
// return controlPoints[0].y;
|
||||
// if (controlPoints[0].y < controlPoints[1].y && controlPoints[0].y < controlPoints[2].y)
|
||||
// return controlPoints[1].y + pinSpacing * 2 / 3;
|
||||
// if (controlPoints[0].x > controlPoints[1].x && controlPoints[0].x > controlPoints[2].x)
|
||||
// return controlPoints[0].y;
|
||||
// if (controlPoints[0].y > controlPoints[1].y && controlPoints[0].y > controlPoints[2].y)
|
||||
// return controlPoints[1].y - pinSpacing * 2 / 3;
|
||||
// return 2 * ((int) (shapeRect.getHeight() - textRect.getHeight()) / 2 + fontMetrics.getAscent()
|
||||
// + (int) shapeRect
|
||||
// .getY());
|
||||
// }
|
||||
|
||||
@Override
|
||||
public void drawIcon(Graphics2D g2d, int width, int height) {
|
||||
|
||||
+14
-18
@@ -69,26 +69,16 @@ public abstract class AbstractTransistorSymbol extends AbstractComponent<String>
|
||||
|
||||
Shape[] body = getBody();
|
||||
|
||||
int rotation = 0;
|
||||
// determine rotation using control points
|
||||
if (controlPoints[1].x == controlPoints[2].x) {
|
||||
if (controlPoints[0].x > controlPoints[1].x) {
|
||||
rotation = 180;
|
||||
}
|
||||
}
|
||||
if (controlPoints[1].y == controlPoints[2].y) {
|
||||
rotation = 90;
|
||||
if (controlPoints[0].y > controlPoints[1].y) {
|
||||
rotation = 270;
|
||||
}
|
||||
}
|
||||
AffineTransform old = g2d.getTransform();
|
||||
g2d.rotate(Math.toRadians(rotation), controlPoints[0].x, controlPoints[0].y);
|
||||
|
||||
if (this.flip == SymbolFlipping.Y) {
|
||||
g2d.translate(0, controlPoints[0].y);
|
||||
g2d.scale(1, -1);
|
||||
g2d.translate(0, -1 * controlPoints[0].y);
|
||||
} else if (this.flip == SymbolFlipping.X) {
|
||||
g2d.translate(controlPoints[0].x, 0);
|
||||
g2d.scale(-1, 1);
|
||||
g2d.translate(-1 * controlPoints[0].x, 0);
|
||||
}
|
||||
|
||||
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(2));
|
||||
@@ -129,7 +119,8 @@ public abstract class AbstractTransistorSymbol extends AbstractComponent<String>
|
||||
Rectangle shapeRect = body[0].getBounds().union(body[1].getBounds()).union(body[2].getBounds());
|
||||
|
||||
drawCenteredText(g2d, label, getLabelX(shapeRect, textRect, fontMetrics, outlineMode),
|
||||
getLabelY(shapeRect, textRect, fontMetrics, outlineMode), HorizontalAlignment.LEFT, VerticalAlignment.CENTER);
|
||||
getLabelY(shapeRect, textRect, fontMetrics, outlineMode), flip == SymbolFlipping.X ? HorizontalAlignment.RIGHT
|
||||
: HorizontalAlignment.LEFT, VerticalAlignment.CENTER);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -143,7 +134,9 @@ public abstract class AbstractTransistorSymbol extends AbstractComponent<String>
|
||||
}
|
||||
|
||||
protected int getLabelX(Rectangle2D shapeRect, Rectangle2D textRect, FontMetrics fontMetrics, boolean outlineMode) {
|
||||
return controlPoints[0].x + (int) PIN_SPACING.convertToPixels() * 2;
|
||||
int f = flip == SymbolFlipping.X ? -1 : 1;
|
||||
int d = flip == SymbolFlipping.X ? (int) PIN_SPACING.convertToPixels() / 2 : 0;
|
||||
return controlPoints[0].x + f * (int) (PIN_SPACING.convertToPixels() * 1.5 + d);
|
||||
}
|
||||
|
||||
protected int getLabelY(Rectangle2D shapeRect, Rectangle2D textRect, FontMetrics fontMetrics, boolean outlineMode) {
|
||||
@@ -156,10 +149,12 @@ public abstract class AbstractTransistorSymbol extends AbstractComponent<String>
|
||||
int x = controlPoints[0].x;
|
||||
int y = controlPoints[0].y;
|
||||
|
||||
controlPoints[1].x = x + pinSpacing * 2;
|
||||
int f = flip == SymbolFlipping.X ? -1 : 1;
|
||||
|
||||
controlPoints[1].x = x + f * pinSpacing * 2;
|
||||
controlPoints[1].y = y - pinSpacing * 2;
|
||||
|
||||
controlPoints[2].x = x + pinSpacing * 2;
|
||||
controlPoints[2].x = x + f * pinSpacing * 2;
|
||||
controlPoints[2].y = y + pinSpacing * 2;
|
||||
}
|
||||
|
||||
@@ -198,6 +193,7 @@ public abstract class AbstractTransistorSymbol extends AbstractComponent<String>
|
||||
|
||||
public void setFlip(SymbolFlipping flip) {
|
||||
this.flip = flip;
|
||||
updateControlPoints();
|
||||
}
|
||||
|
||||
@EditableProperty
|
||||
|
||||
@@ -2,13 +2,15 @@ package org.diylc.components.semiconductors;
|
||||
|
||||
public enum SymbolFlipping {
|
||||
|
||||
NONE, Y;
|
||||
NONE, X, Y;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
switch (this) {
|
||||
case Y:
|
||||
return "Y-axis";
|
||||
case X:
|
||||
return "X-axis";
|
||||
case NONE:
|
||||
return "None";
|
||||
default:
|
||||
|
||||
Reference in New Issue
Block a user