From d75653c42476f4db35f23539c2c17684c542d799 Mon Sep 17 00:00:00 2001 From: Bane Stojkovic Date: Sun, 30 Oct 2022 10:12:10 +0100 Subject: [PATCH] Ground symbol enhancements --- .../diylc/components/misc/GroundSymbol.java | 43 ++++++++++++++----- 1 file changed, 32 insertions(+), 11 deletions(-) diff --git a/diylc/diylc-library/src/org/diylc/components/misc/GroundSymbol.java b/diylc/diylc-library/src/org/diylc/components/misc/GroundSymbol.java index 5545b8d9..1d19cae1 100644 --- a/diylc/diylc-library/src/org/diylc/components/misc/GroundSymbol.java +++ b/diylc/diylc-library/src/org/diylc/components/misc/GroundSymbol.java @@ -38,7 +38,8 @@ import org.diylc.core.annotations.BomPolicy; import org.diylc.core.annotations.ComponentDescriptor; import org.diylc.core.annotations.EditableProperty; 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", instanceNamePrefix = "GND", description = "Ground schematic symbol", @@ -54,15 +55,16 @@ public class GroundSymbol extends AbstractComponent implements ICommonNode private Color color = COLOR; private Size size = SIZE; private GroundSymbolType type = GroundSymbolType.DEFAULT; - private Orientation orientation = Orientation.DEFAULT; + private Orientation orientation = Orientation.DEFAULT; + private Integer stroke = 1; @SuppressWarnings("incomplete-switch") @Override public void draw(Graphics2D g2d, ComponentState componentState, boolean outlineMode, Project project, IDrawingObserver drawingObserver) { double sizePx = size.convertToPixels(); - g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(1)); - g2d.setColor(color); + g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke((float)getStroke())); + double x = point.getX(); double y = point.getY(); @@ -77,19 +79,26 @@ public class GroundSymbol extends AbstractComponent implements ICommonNode g2d.rotate(Math.PI * 3 / 2, point.getX(), point.getY()); 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)); if (type == GroundSymbolType.DEFAULT) { - double delta = sizePx / 7; + double delta = sizePx / 7.5; 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 * (i + 1))); } - } else { - 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.draw(poly); + } else { + g2d.draw(poly); } } @@ -114,6 +123,18 @@ public class GroundSymbol extends AbstractComponent implements ICommonNode this.type = type; } + @EditableProperty + public int getStroke() { + if (stroke == null) { + stroke = 1; + } + return stroke; + } + + public void setStroke(int stroke) { + this.stroke = stroke; + } + @EditableProperty public Orientation getOrientation() { if (orientation == null)