Improved conductivity tracking of Terminal Strip

This commit is contained in:
Bane Stojkovic
2022-11-27 13:00:34 +01:00
parent 45b9532e66
commit 0c53c8918a
6 changed files with 435 additions and 415 deletions
@@ -22,7 +22,6 @@ import java.awt.geom.Point2D;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
@@ -4194,6 +4194,10 @@
<changeType>IMPROVEMENT</changeType> <changeType>IMPROVEMENT</changeType>
<description>Potentiometer bodies are no longer considered as conductive surfaces to avoid unwanted shorts</description> <description>Potentiometer bodies are no longer considered as conductive surfaces to avoid unwanted shorts</description>
</org.diylc.appframework.update.Change> </org.diylc.appframework.update.Change>
<org.diylc.appframework.update.Change>
<changeType>IMPROVEMENT</changeType>
<description>Improved conductivity tracking of Terminal Strip</description>
</org.diylc.appframework.update.Change>
<org.diylc.appframework.update.Change> <org.diylc.appframework.update.Change>
<changeType>BUG_FIX</changeType> <changeType>BUG_FIX</changeType>
<description>Do not apply any user-default property values when creating a standard datasheet model (e.g. a capacitor)</description> <description>Do not apply any user-default property values when creating a standard datasheet model (e.g. a capacitor)</description>
Binary file not shown.
@@ -1,23 +1,20 @@
/* /*
*
DIY Layout Creator (DIYLC). * DIY Layout Creator (DIYLC). Copyright (c) 2009-2018 held jointly by the individual authors.
Copyright (c) 2009-2018 held jointly by the individual authors. *
* This file is part of DIYLC.
This file is part of DIYLC. *
* DIYLC is free software: you can redistribute it and/or modify it under the terms of the GNU
DIYLC is free software: you can redistribute it and/or modify * General Public License as published by the Free Software Foundation, either version 3 of the
it under the terms of the GNU General Public License as published by * License, or (at your option) any later version.
the Free Software Foundation, either version 3 of the License, or *
(at your option) any later version. * DIYLC is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
DIYLC is distributed in the hope that it will be useful, * Public License for more details.
but WITHOUT ANY WARRANTY; without even the implied warranty of *
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * You should have received a copy of the GNU General Public License along with DIYLC. If not, see
GNU General Public License for more details. * <http://www.gnu.org/licenses/>.
*
You should have received a copy of the GNU General Public License
along with DIYLC. If not, see <http://www.gnu.org/licenses/>.
*/ */
package org.diylc.components.boards; package org.diylc.components.boards;
@@ -52,7 +49,8 @@ import org.diylc.utils.Constants;
@ComponentDescriptor(name = "Terminal Strip", author = "Branislav Stojkovic", category = "Boards", @ComponentDescriptor(name = "Terminal Strip", author = "Branislav Stojkovic", category = "Boards",
instanceNamePrefix = "TS", description = "Row of terminals for point-to-point construction", instanceNamePrefix = "TS", description = "Row of terminals for point-to-point construction",
zOrder = IDIYComponent.BOARD, keywordPolicy = KeywordPolicy.SHOW_TYPE_NAME, transformer = TerminalStripTransformer.class) zOrder = IDIYComponent.BOARD, keywordPolicy = KeywordPolicy.SHOW_TYPE_NAME,
transformer = TerminalStripTransformer.class)
public class TerminalStrip extends AbstractTransparentComponent<String> implements IContinuity { public class TerminalStrip extends AbstractTransparentComponent<String> implements IContinuity {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
@@ -117,7 +115,8 @@ public class TerminalStrip extends AbstractTransparentComponent<String> implemen
body = null; body = null;
} }
@EditableProperty(name = "Terminal Spacing", validatorClass = PositiveNonZeroMeasureValidator.class) @EditableProperty(name = "Terminal Spacing",
validatorClass = PositiveNonZeroMeasureValidator.class)
public Size getTerminalSpacing() { public Size getTerminalSpacing() {
return terminalSpacing; return terminalSpacing;
} }
@@ -241,15 +240,17 @@ public class TerminalStrip extends AbstractTransparentComponent<String> implemen
throw new RuntimeException("Unexpected orientation: " + orientation); throw new RuntimeException("Unexpected orientation: " + orientation);
} }
controlPoints[i] = new Point2D.Double(firstPoint.getX() + dx1, firstPoint.getY() + dy1); controlPoints[i] = new Point2D.Double(firstPoint.getX() + dx1, firstPoint.getY() + dy1);
controlPoints[i + getTerminalCount()] = new Point2D.Double(firstPoint.getX() + dx2, firstPoint.getY() + dy2); controlPoints[i + getTerminalCount()] =
new Point2D.Double(firstPoint.getX() + dx2, firstPoint.getY() + dy2);
if (centerHole) if (centerHole)
controlPoints[i + 2 * getTerminalCount()] = new Point2D.Double(firstPoint.getX() + cx, firstPoint.getY() + cy); controlPoints[i + 2 * getTerminalCount()] =
new Point2D.Double(firstPoint.getX() + cx, firstPoint.getY() + cy);
} }
} }
public Area[] getBody() { public Area[] getBody() {
if (body == null) { if (body == null) {
body = new Area[1 + getTerminalCount()]; body = new Area[1 + getTerminalCount() * 2];
double x = controlPoints[0].getX(); double x = controlPoints[0].getX();
double y = controlPoints[0].getY(); double y = controlPoints[0].getY();
int width; int width;
@@ -268,49 +269,46 @@ public class TerminalStrip extends AbstractTransparentComponent<String> implemen
height = boardLength; height = boardLength;
x += holeSpacing / 2 - boardWidth / 2; x += holeSpacing / 2 - boardWidth / 2;
y -= boardWidth; y -= boardWidth;
indentation = indentation = new Area(new Ellipse2D.Double(x + boardWidth / 2 - mountingHoleSize / 2,
new Area(new Ellipse2D.Double(x + boardWidth / 2 - mountingHoleSize / 2, y + boardWidth / 2 y + boardWidth / 2 - mountingHoleSize / 2, mountingHoleSize, mountingHoleSize));
- mountingHoleSize / 2, mountingHoleSize, mountingHoleSize)); indentation.add(new Area(new Ellipse2D.Double(x + boardWidth / 2 - mountingHoleSize / 2,
indentation.add(new Area(new Ellipse2D.Double(x + boardWidth / 2 - mountingHoleSize / 2, y + boardLength y + boardLength - boardWidth / 2, mountingHoleSize, mountingHoleSize)));
- boardWidth / 2, mountingHoleSize, mountingHoleSize)));
break; break;
case _90: case _90:
width = boardLength; width = boardLength;
height = boardWidth; height = boardWidth;
x += boardWidth - boardLength; x += boardWidth - boardLength;
y += holeSpacing / 2 - boardWidth / 2; y += holeSpacing / 2 - boardWidth / 2;
indentation = indentation = new Area(new Ellipse2D.Double(x + boardWidth / 2 - mountingHoleSize,
new Area(new Ellipse2D.Double(x + boardWidth / 2 - mountingHoleSize, y + boardWidth / 2 y + boardWidth / 2 - mountingHoleSize / 2, mountingHoleSize, mountingHoleSize));
- mountingHoleSize / 2, mountingHoleSize, mountingHoleSize)); indentation.add(new Area(new Ellipse2D.Double(x + boardLength - boardWidth / 2,
indentation.add(new Area(new Ellipse2D.Double(x + boardLength - boardWidth / 2, y + boardWidth / 2 y + boardWidth / 2 - mountingHoleSize / 2, mountingHoleSize, mountingHoleSize)));
- mountingHoleSize / 2, mountingHoleSize, mountingHoleSize)));
break; break;
case _180: case _180:
width = boardWidth; width = boardWidth;
height = boardLength; height = boardLength;
x -= holeSpacing / 2 + boardWidth / 2; x -= holeSpacing / 2 + boardWidth / 2;
y += boardWidth - boardLength; y += boardWidth - boardLength;
indentation = indentation = new Area(new Ellipse2D.Double(x + boardWidth / 2 - mountingHoleSize / 2,
new Area(new Ellipse2D.Double(x + boardWidth / 2 - mountingHoleSize / 2, y + boardWidth / 2 y + boardWidth / 2 - mountingHoleSize / 2, mountingHoleSize, mountingHoleSize));
- mountingHoleSize / 2, mountingHoleSize, mountingHoleSize)); indentation.add(new Area(new Ellipse2D.Double(x + boardWidth / 2 - mountingHoleSize / 2,
indentation.add(new Area(new Ellipse2D.Double(x + boardWidth / 2 - mountingHoleSize / 2, y + boardLength y + boardLength - boardWidth / 2, mountingHoleSize, mountingHoleSize)));
- boardWidth / 2, mountingHoleSize, mountingHoleSize)));
break; break;
case _270: case _270:
width = boardLength; width = boardLength;
height = boardWidth; height = boardWidth;
x -= boardWidth; x -= boardWidth;
y -= holeSpacing / 2 + boardWidth / 2; y -= holeSpacing / 2 + boardWidth / 2;
indentation = indentation = new Area(new Ellipse2D.Double(x + boardWidth / 2 - mountingHoleSize,
new Area(new Ellipse2D.Double(x + boardWidth / 2 - mountingHoleSize, y + boardWidth / 2 y + boardWidth / 2 - mountingHoleSize / 2, mountingHoleSize, mountingHoleSize));
- mountingHoleSize / 2, mountingHoleSize, mountingHoleSize)); indentation.add(new Area(new Ellipse2D.Double(x + boardLength - boardWidth / 2,
indentation.add(new Area(new Ellipse2D.Double(x + boardLength - boardWidth / 2, y + boardWidth / 2 y + boardWidth / 2 - mountingHoleSize / 2, mountingHoleSize, mountingHoleSize)));
- mountingHoleSize / 2, mountingHoleSize, mountingHoleSize)));
break; break;
default: default:
throw new RuntimeException("Unexpected orientation: " + orientation); throw new RuntimeException("Unexpected orientation: " + orientation);
} }
Area bodyArea = new Area(new RoundRectangle2D.Double(x, y, width, height, EDGE_RADIUS, EDGE_RADIUS)); Area bodyArea =
new Area(new RoundRectangle2D.Double(x, y, width, height, EDGE_RADIUS, EDGE_RADIUS));
bodyArea.subtract(indentation); bodyArea.subtract(indentation);
body[0] = bodyArea; body[0] = bodyArea;
@@ -324,21 +322,28 @@ public class TerminalStrip extends AbstractTransparentComponent<String> implemen
p2 = p; p2 = p;
} }
Area terminal = Area terminal = new Area(new RoundRectangle2D.Double(p1.getX() - holeSize,
new Area(new RoundRectangle2D.Double(p1.getX() - holeSize, p1.getY() - holeSize, p2.getX() - p1.getX() + holeSize * 2, p2.getY() p1.getY() - holeSize, p2.getX() - p1.getX() + holeSize * 2,
- p1.getY() + holeSize * 2, holeSize, holeSize)); p2.getY() - p1.getY() + holeSize * 2, holeSize, holeSize));
terminal.subtract(new Area(new Ellipse2D.Double(p1.getX() - holeSize / 2, p1.getY() - holeSize / 2, holeSize, holeSize))); terminal.subtract(new Area(new Ellipse2D.Double(p1.getX() - holeSize / 2,
terminal.subtract(new Area(new Ellipse2D.Double(p2.getX() - holeSize / 2, p2.getY() - holeSize / 2, holeSize, holeSize))); p1.getY() - holeSize / 2, holeSize, holeSize)));
terminal.subtract(new Area(new Ellipse2D.Double(p2.getX() - holeSize / 2,
p2.getY() - holeSize / 2, holeSize, holeSize)));
if (centerHole) { if (centerHole) {
Point2D p3 = getControlPoint(i + 2 * getTerminalCount()); Point2D p3 = getControlPoint(i + 2 * getTerminalCount());
Area centerHole = Area centerHole = new Area(new Ellipse2D.Double(p3.getX() - holeSize / 2,
new Area(new Ellipse2D.Double(p3.getX() - holeSize / 2, p3.getY() - holeSize / 2, holeSize, holeSize)); p3.getY() - holeSize / 2, holeSize, holeSize));
terminal.subtract(centerHole); terminal.subtract(centerHole);
bodyArea.subtract(centerHole); bodyArea.subtract(centerHole);
} }
body[1 + i] = terminal; body[1 + i] = terminal;
body[1 + i + getTerminalCount()] =
new Area(new RoundRectangle2D.Double(p1.getX() - holeSize, p1.getY() - holeSize,
p2.getX() - p1.getX() + holeSize * 2, p2.getY() - p1.getY() + holeSize * 2,
holeSize, holeSize)); // save the terminal without holes for continuity tracking
} }
} }
@@ -346,8 +351,8 @@ public class TerminalStrip extends AbstractTransparentComponent<String> implemen
} }
@Override @Override
public void draw(Graphics2D g2d, ComponentState componentState, boolean outlineMode, Project project, public void draw(Graphics2D g2d, ComponentState componentState, boolean outlineMode,
IDrawingObserver drawingObserver) { Project project, IDrawingObserver drawingObserver) {
if (checkPointsClipped(g2d.getClip())) { if (checkPointsClipped(g2d.getClip())) {
return; return;
} }
@@ -363,14 +368,16 @@ public class TerminalStrip extends AbstractTransparentComponent<String> implemen
Color finalBorderColor; Color finalBorderColor;
if (outlineMode) { if (outlineMode) {
Theme theme = Theme theme = (Theme) ConfigurationManager.getInstance().readObject(IPlugInPort.THEME_KEY,
(Theme) ConfigurationManager.getInstance().readObject(IPlugInPort.THEME_KEY, Constants.DEFAULT_THEME); Constants.DEFAULT_THEME);
finalBorderColor = finalBorderColor =
componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING ? SELECTION_COLOR componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING
? SELECTION_COLOR
: theme.getOutlineColor(); : theme.getOutlineColor();
} else { } else {
finalBorderColor = finalBorderColor =
componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING ? SELECTION_COLOR componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING
? SELECTION_COLOR
: getBoardColor().darker(); : getBoardColor().darker();
} }
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(1)); g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(1));
@@ -378,22 +385,31 @@ public class TerminalStrip extends AbstractTransparentComponent<String> implemen
g2d.setColor(finalBorderColor); g2d.setColor(finalBorderColor);
g2d.draw(mainArea); g2d.draw(mainArea);
g2d.setColor(outlineMode ? Constants.TRANSPARENT_COLOR : TERMINAL_COLOR);
g2d.setColor(Constants.TRANSPARENT_COLOR);
drawingObserver.startTrackingContinuityArea(true); drawingObserver.startTrackingContinuityArea(true);
for (int i = 1; i < body.length; i++) for (int i = 0; i < getTerminalCount(); i++)
g2d.fill(body[i]); g2d.fill(body[i + getTerminalCount() + 1]);
drawingObserver.stopTrackingContinuityArea(); drawingObserver.stopTrackingContinuityArea();
if (!outlineMode) {
g2d.setColor(TERMINAL_COLOR);
for (int i = 0; i < getTerminalCount(); i++)
g2d.fill(body[i + 1]);
}
Color finalTerminalBorderColor; Color finalTerminalBorderColor;
if (outlineMode) { if (outlineMode) {
Theme theme = Theme theme = (Theme) ConfigurationManager.getInstance().readObject(IPlugInPort.THEME_KEY,
(Theme) ConfigurationManager.getInstance().readObject(IPlugInPort.THEME_KEY, Constants.DEFAULT_THEME); Constants.DEFAULT_THEME);
finalTerminalBorderColor = finalTerminalBorderColor =
componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING ? SELECTION_COLOR componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING
? SELECTION_COLOR
: theme.getOutlineColor(); : theme.getOutlineColor();
} else { } else {
finalTerminalBorderColor = finalTerminalBorderColor =
componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING ? SELECTION_COLOR componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING
? SELECTION_COLOR
: TERMINAL_BORDER_COLOR; : TERMINAL_BORDER_COLOR;
} }
@@ -413,11 +429,12 @@ public class TerminalStrip extends AbstractTransparentComponent<String> implemen
g2d.setColor(BOARD_COLOR.darker()); g2d.setColor(BOARD_COLOR.darker());
g2d.drawRect(width / 4, 1, width / 2, height - 4); g2d.drawRect(width / 4, 1, width / 2, height - 4);
int terminalSize = getClosestOdd(height / 5); int terminalSize = getClosestOdd(height / 5);
Area terminal = Area terminal = new Area(new RoundRectangle2D.Double(2 * width / 32, height / 5,
new Area(new RoundRectangle2D.Double(2 * width / 32, height / 5, width - 4 * width / 32, terminalSize, radius, width - 4 * width / 32, terminalSize, radius, radius));
radius)); terminal.subtract(new Area(new Ellipse2D.Double(2 * width / 32 + holeSize,
terminal.subtract(new Area(new Ellipse2D.Double(2 * width / 32 + holeSize, height * 3 / 10 - holeSize / 2, holeSize, holeSize))); height * 3 / 10 - holeSize / 2, holeSize, holeSize)));
terminal.subtract(new Area(new Ellipse2D.Double(width - 2 * width / 32 - holeSize * 2, height * 3 / 10 - holeSize / 2, holeSize, holeSize))); terminal.subtract(new Area(new Ellipse2D.Double(width - 2 * width / 32 - holeSize * 2,
height * 3 / 10 - holeSize / 2, holeSize, holeSize)));
g2d.setColor(TERMINAL_COLOR); g2d.setColor(TERMINAL_COLOR);
g2d.fill(terminal); g2d.fill(terminal);
Binary file not shown.
Binary file not shown.