mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-10 09:12: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.ComponentDescriptor;
|
||||||
import org.diylc.core.annotations.KeywordPolicy;
|
import org.diylc.core.annotations.KeywordPolicy;
|
||||||
import org.diylc.components.semiconductors.AbstractTransistorSymbol;
|
import org.diylc.components.semiconductors.AbstractTransistorSymbol;
|
||||||
|
import org.diylc.components.semiconductors.SymbolFlipping;
|
||||||
|
|
||||||
@ComponentDescriptor(name = "Potentiometer Symbol", author = "MCbx", category = "Schematics",
|
@ComponentDescriptor(name = "Potentiometer Symbol", author = "MCbx", category = "Schematics",
|
||||||
instanceNamePrefix = " VR", description = "Potentiometer symbol", stretchable = false,
|
instanceNamePrefix = " VR", description = "Potentiometer symbol", stretchable = false,
|
||||||
@@ -69,32 +70,43 @@ public class PotentiometerSymbol extends AbstractTransistorSymbol {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected int getLabelX(Rectangle2D shapeRect, Rectangle2D textRect, FontMetrics fontMetrics, boolean outlineMode) {
|
protected int getLabelX(Rectangle2D shapeRect, Rectangle2D textRect, FontMetrics fontMetrics, boolean outlineMode) {
|
||||||
int pinSpacing = (int) PIN_SPACING.convertToPixels();
|
int x = super.getLabelX(shapeRect, textRect, fontMetrics, outlineMode);
|
||||||
if (controlPoints[0].x < controlPoints[1].x && controlPoints[0].x < controlPoints[2].x)
|
if (getFlip() == SymbolFlipping.X)
|
||||||
return controlPoints[1].x + pinSpacing / 3;
|
return x - (int) (PIN_SPACING.convertToPixels() / 2);
|
||||||
if (controlPoints[0].y < controlPoints[1].y && controlPoints[0].y < controlPoints[2].y)
|
return x + (int) PIN_SPACING.convertToPixels();
|
||||||
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
|
// @Override
|
||||||
protected int getLabelY(Rectangle2D shapeRect, Rectangle2D textRect, FontMetrics fontMetrics, boolean outlineMode) {
|
// protected int getLabelX(Rectangle2D shapeRect, Rectangle2D textRect, FontMetrics fontMetrics,
|
||||||
int pinSpacing = (int) PIN_SPACING.convertToPixels();
|
// boolean outlineMode) {
|
||||||
if (controlPoints[0].x < controlPoints[1].x && controlPoints[0].x < controlPoints[2].x)
|
// int pinSpacing = (int) PIN_SPACING.convertToPixels();
|
||||||
return controlPoints[0].y;
|
// if (controlPoints[0].x < controlPoints[1].x && controlPoints[0].x < controlPoints[2].x)
|
||||||
if (controlPoints[0].y < controlPoints[1].y && controlPoints[0].y < controlPoints[2].y)
|
// return controlPoints[1].x + pinSpacing / 3;
|
||||||
return controlPoints[1].y + pinSpacing * 2 / 3;
|
// if (controlPoints[0].y < controlPoints[1].y && controlPoints[0].y < controlPoints[2].y)
|
||||||
if (controlPoints[0].x > controlPoints[1].x && controlPoints[0].x > controlPoints[2].x)
|
// return controlPoints[0].x - (int) (textRect.getWidth() / 2);
|
||||||
return controlPoints[0].y;
|
// if (controlPoints[0].x > controlPoints[1].x && controlPoints[0].x > controlPoints[2].x)
|
||||||
if (controlPoints[0].y > controlPoints[1].y && controlPoints[0].y > controlPoints[2].y)
|
// return controlPoints[1].x - pinSpacing / 2 - (int) textRect.getWidth();
|
||||||
return controlPoints[1].y - pinSpacing * 2 / 3;
|
// if (controlPoints[0].y > controlPoints[1].y && controlPoints[0].y > controlPoints[2].y)
|
||||||
return 2 * ((int) (shapeRect.getHeight() - textRect.getHeight()) / 2 + fontMetrics.getAscent() + (int) shapeRect
|
// return controlPoints[0].x - (int) (textRect.getWidth() / 2);
|
||||||
.getY());
|
// 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
|
@Override
|
||||||
public void drawIcon(Graphics2D g2d, int width, int height) {
|
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();
|
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();
|
AffineTransform old = g2d.getTransform();
|
||||||
g2d.rotate(Math.toRadians(rotation), controlPoints[0].x, controlPoints[0].y);
|
|
||||||
|
|
||||||
if (this.flip == SymbolFlipping.Y) {
|
if (this.flip == SymbolFlipping.Y) {
|
||||||
g2d.translate(0, controlPoints[0].y);
|
g2d.translate(0, controlPoints[0].y);
|
||||||
g2d.scale(1, -1);
|
g2d.scale(1, -1);
|
||||||
g2d.translate(0, -1 * controlPoints[0].y);
|
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));
|
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());
|
Rectangle shapeRect = body[0].getBounds().union(body[1].getBounds()).union(body[2].getBounds());
|
||||||
|
|
||||||
drawCenteredText(g2d, label, getLabelX(shapeRect, textRect, fontMetrics, outlineMode),
|
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
|
@Override
|
||||||
@@ -143,7 +134,9 @@ public abstract class AbstractTransistorSymbol extends AbstractComponent<String>
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected int getLabelX(Rectangle2D shapeRect, Rectangle2D textRect, FontMetrics fontMetrics, boolean outlineMode) {
|
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) {
|
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 x = controlPoints[0].x;
|
||||||
int y = controlPoints[0].y;
|
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[1].y = y - pinSpacing * 2;
|
||||||
|
|
||||||
controlPoints[2].x = x + pinSpacing * 2;
|
controlPoints[2].x = x + f * pinSpacing * 2;
|
||||||
controlPoints[2].y = y + pinSpacing * 2;
|
controlPoints[2].y = y + pinSpacing * 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -198,6 +193,7 @@ public abstract class AbstractTransistorSymbol extends AbstractComponent<String>
|
|||||||
|
|
||||||
public void setFlip(SymbolFlipping flip) {
|
public void setFlip(SymbolFlipping flip) {
|
||||||
this.flip = flip;
|
this.flip = flip;
|
||||||
|
updateControlPoints();
|
||||||
}
|
}
|
||||||
|
|
||||||
@EditableProperty
|
@EditableProperty
|
||||||
|
|||||||
@@ -2,13 +2,15 @@ package org.diylc.components.semiconductors;
|
|||||||
|
|
||||||
public enum SymbolFlipping {
|
public enum SymbolFlipping {
|
||||||
|
|
||||||
NONE, Y;
|
NONE, X, Y;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
switch (this) {
|
switch (this) {
|
||||||
case Y:
|
case Y:
|
||||||
return "Y-axis";
|
return "Y-axis";
|
||||||
|
case X:
|
||||||
|
return "X-axis";
|
||||||
case NONE:
|
case NONE:
|
||||||
return "None";
|
return "None";
|
||||||
default:
|
default:
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
@@ -1345,7 +1345,11 @@
|
|||||||
<org.diylc.appframework.update.Change>
|
<org.diylc.appframework.update.Change>
|
||||||
<changeType>NEW_FEATURE</changeType>
|
<changeType>NEW_FEATURE</changeType>
|
||||||
<description>Added Public Announcements feature</description>
|
<description>Added Public Announcements feature</description>
|
||||||
</org.diylc.appframework.update.Change>
|
</org.diylc.appframework.update.Change>
|
||||||
|
<org.diylc.appframework.update.Change>
|
||||||
|
<changeType>IMPROVEMENT</changeType>
|
||||||
|
<description>Potentiometer symbol can be flipped horizontally</description>
|
||||||
|
</org.diylc.appframework.update.Change>
|
||||||
<org.diylc.appframework.update.Change>
|
<org.diylc.appframework.update.Change>
|
||||||
<changeType>IMPROVEMENT</changeType>
|
<changeType>IMPROVEMENT</changeType>
|
||||||
<description>Reduced DIYLC package size</description>
|
<description>Reduced DIYLC package size</description>
|
||||||
@@ -1368,7 +1372,7 @@
|
|||||||
</org.diylc.appframework.update.Change>
|
</org.diylc.appframework.update.Change>
|
||||||
<org.diylc.appframework.update.Change>
|
<org.diylc.appframework.update.Change>
|
||||||
<changeType>IMPROVEMENT</changeType>
|
<changeType>IMPROVEMENT</changeType>
|
||||||
<description>Toggle switch spacing can be changed</description>
|
<description>Toggle switch terminal spacing can be changed</description>
|
||||||
</org.diylc.appframework.update.Change>
|
</org.diylc.appframework.update.Change>
|
||||||
<org.diylc.appframework.update.Change>
|
<org.diylc.appframework.update.Change>
|
||||||
<changeType>IMPROVEMENT</changeType>
|
<changeType>IMPROVEMENT</changeType>
|
||||||
|
|||||||
Reference in New Issue
Block a user