Ground symbol enhancements

This commit is contained in:
Bane Stojkovic
2022-10-30 10:12:10 +01:00
parent e3d2ad82c9
commit d75653c424
@@ -38,7 +38,8 @@ import org.diylc.core.annotations.BomPolicy;
import org.diylc.core.annotations.ComponentDescriptor; import org.diylc.core.annotations.ComponentDescriptor;
import org.diylc.core.annotations.EditableProperty; import org.diylc.core.annotations.EditableProperty;
import org.diylc.core.measures.Size; import org.diylc.core.measures.Size;
import org.diylc.core.measures.SizeUnit; import org.diylc.core.measures.SizeUnit;
import org.diylc.utils.Constants;
@ComponentDescriptor(name = "Ground", author = "Branislav Stojkovic", category = "Schematic Symbols", @ComponentDescriptor(name = "Ground", author = "Branislav Stojkovic", category = "Schematic Symbols",
instanceNamePrefix = "GND", description = "Ground schematic symbol", instanceNamePrefix = "GND", description = "Ground schematic symbol",
@@ -54,15 +55,16 @@ public class GroundSymbol extends AbstractComponent<Void> implements ICommonNode
private Color color = COLOR; private Color color = COLOR;
private Size size = SIZE; private Size size = SIZE;
private GroundSymbolType type = GroundSymbolType.DEFAULT; private GroundSymbolType type = GroundSymbolType.DEFAULT;
private Orientation orientation = Orientation.DEFAULT; private Orientation orientation = Orientation.DEFAULT;
private Integer stroke = 1;
@SuppressWarnings("incomplete-switch") @SuppressWarnings("incomplete-switch")
@Override @Override
public void draw(Graphics2D g2d, ComponentState componentState, boolean outlineMode, Project project, public void draw(Graphics2D g2d, ComponentState componentState, boolean outlineMode, Project project,
IDrawingObserver drawingObserver) { IDrawingObserver drawingObserver) {
double sizePx = size.convertToPixels(); double sizePx = size.convertToPixels();
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(1)); g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke((float)getStroke()));
g2d.setColor(color);
double x = point.getX(); double x = point.getX();
double y = point.getY(); double y = point.getY();
@@ -77,19 +79,26 @@ public class GroundSymbol extends AbstractComponent<Void> implements ICommonNode
g2d.rotate(Math.PI * 3 / 2, point.getX(), point.getY()); g2d.rotate(Math.PI * 3 / 2, point.getX(), point.getY());
break; break;
} }
Polygon poly =
new Polygon(new int[] {(int)(x - sizePx / 2), (int)(x + sizePx / 2), (int)x}, new int[] {(int)(y + sizePx / 6), (int)(y + sizePx / 6),
(int)(y + sizePx)}, 3);
g2d.setColor(Constants.TRANSPARENT_COLOR);
g2d.fill(poly);
drawingObserver.stopTracking();
g2d.setColor(color);
g2d.drawLine((int)x, (int)y, (int)x, (int)(y + sizePx / 6)); g2d.drawLine((int)x, (int)y, (int)x, (int)(y + sizePx / 6));
if (type == GroundSymbolType.DEFAULT) { if (type == GroundSymbolType.DEFAULT) {
double delta = sizePx / 7; double delta = sizePx / 7.5;
for (int i = 0; i < 5; i++) { for (int i = 0; i < 5; i++) {
g2d.drawLine((int)(x - sizePx / 2 + delta * i), (int)(y + sizePx / 6 * (i + 1)), (int)(x + sizePx / 2 - delta * i), (int)(y + sizePx / 6 g2d.drawLine((int)(x - sizePx / 2 + delta * i), (int)(y + sizePx / 6 * (i + 1)), (int)(x + sizePx / 2 - delta * i), (int)(y + sizePx / 6
* (i + 1))); * (i + 1)));
} }
} else { } else {
Polygon poly = g2d.draw(poly);
new Polygon(new int[] {(int)(x - sizePx / 2), (int)(x + sizePx / 2), (int)x}, new int[] {(int)(y + sizePx / 6), (int)(y + sizePx / 6),
(int)(y + sizePx)}, 3);
g2d.draw(poly);
} }
} }
@@ -114,6 +123,18 @@ public class GroundSymbol extends AbstractComponent<Void> implements ICommonNode
this.type = type; this.type = type;
} }
@EditableProperty
public int getStroke() {
if (stroke == null) {
stroke = 1;
}
return stroke;
}
public void setStroke(int stroke) {
this.stroke = stroke;
}
@EditableProperty @EditableProperty
public Orientation getOrientation() { public Orientation getOrientation() {
if (orientation == null) if (orientation == null)