Honor "Terminal Strip" connectivity when creating a netlist

This commit is contained in:
Branislav Stojkovic
2019-03-13 20:54:24 +01:00
parent 4de3b6d97c
commit e9a2785344
18 changed files with 115 additions and 53 deletions
@@ -49,12 +49,11 @@ public class ComponentType {
private IComponentTransformer transformer;
private KeywordPolicy keywordPolicy;
private String keywordTag;
private boolean continuity;
public ComponentType(String name, String description, CreationMethod creationMethod, String category,
String namePrefix, String author, Icon icon, Class<? extends IDIYComponent<?>> instanceClass, double zOrder,
boolean flexibleZOrder, boolean stretchable, BomPolicy bomPolicy, boolean autoEdit,
IComponentTransformer transformer, KeywordPolicy keywordPolicy, String keywordTag, boolean continuity) {
IComponentTransformer transformer, KeywordPolicy keywordPolicy, String keywordTag) {
super();
this.name = name;
this.description = description;
@@ -72,7 +71,6 @@ public class ComponentType {
this.transformer = transformer;
this.keywordPolicy = keywordPolicy;
this.keywordTag = keywordTag;
this.continuity = continuity;
}
public String getName() {
@@ -139,10 +137,6 @@ public class ComponentType {
return keywordTag;
}
public boolean isContinuity() {
return continuity;
}
@Override
public String toString() {
return name;
@@ -0,0 +1,34 @@
/*
DIY Layout Creator (DIYLC).
Copyright (c) 2009-2018 held jointly by the individual authors.
This file is part of DIYLC.
DIYLC is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
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 Public License for more details.
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.core;
public interface IContinuity {
/**
* Tests control point connectivity.
*
* @param index1
* @param index2
* @return true if the two points are connected, false otherwise.
*/
boolean arePointsConnected(int index1, int index2);
}
@@ -116,13 +116,5 @@ public @interface ComponentDescriptor {
*
* @return
*/
String keywordTag() default "";
/**
* For components that show continuity between the two ending points, e.d. wires, jumpers, etc.
*
* @return
*/
boolean continuity() default false;
String keywordTag() default "";
}
@@ -72,9 +72,9 @@ public class SwitchSetup implements Comparable<SwitchSetup> {
public String toString() {
StringBuilder sb = new StringBuilder();
for (Position s : positions)
{
{
if (sb.length() > 0)
sb.append(":");
sb.append(":");
sb.append(s.toString());
}
return sb.toString();
@@ -97,8 +97,7 @@ public class ComponentProcessor {
boolean autoEdit;
IComponentTransformer transformer;
KeywordPolicy keywordPolicy;
String keywordTag;
boolean continuity;
String keywordTag;
if (clazz.isAnnotationPresent(ComponentDescriptor.class)) {
ComponentDescriptor annotation = clazz.getAnnotation(ComponentDescriptor.class);
name = annotation.name();
@@ -114,8 +113,7 @@ public class ComponentProcessor {
autoEdit = annotation.autoEdit();
transformer = getComponentTransformer(annotation.transformer());
keywordPolicy = annotation.keywordPolicy();
keywordTag = annotation.keywordTag();
continuity = annotation.continuity();
keywordTag = annotation.keywordTag();
} else { // default
return null;
}
@@ -137,7 +135,7 @@ public class ComponentProcessor {
}
ComponentType componentType =
new ComponentType(name, description, creationMethod, category, namePrefix, author, icon, clazz, zOrder,
flexibleZOrder, stretchable, bomPolicy, autoEdit, transformer, keywordPolicy, keywordTag, continuity);
flexibleZOrder, stretchable, bomPolicy, autoEdit, transformer, keywordPolicy, keywordTag);
componentTypeMap.put(clazz.getName(), componentType);
return componentType;
}
@@ -43,7 +43,6 @@ import java.util.Set;
import org.apache.log4j.Logger;
import org.diylc.appframework.miscutils.ConfigurationManager;
import org.diylc.appframework.simplemq.MessageDispatcher;
import org.diylc.common.ComponentType;
import org.diylc.common.DrawOption;
import org.diylc.common.EventType;
import org.diylc.common.GridType;
@@ -51,6 +50,7 @@ import org.diylc.common.IComponentFiler;
import org.diylc.common.IPlugInPort;
import org.diylc.common.ObjectCache;
import org.diylc.core.ComponentState;
import org.diylc.core.IContinuity;
import org.diylc.core.IDIYComponent;
import org.diylc.core.Project;
import org.diylc.core.Theme;
@@ -505,7 +505,6 @@ public class DrawingManager {
continuityArea = null;
}
@SuppressWarnings("unchecked")
public List<Area> getContinuityAreas(Project project) {
// Find all individual continuity areas for all components
List<Area> preliminaryAreas = new ArrayList<Area>();
@@ -513,11 +512,12 @@ public class DrawingManager {
Set<Connection> connections = new HashSet<Connection>();
for (IDIYComponent<?> c : project.getComponents()) {
ComponentArea a = getComponentArea(c);
ComponentType type =
ComponentProcessor.getInstance().extractComponentTypeFrom((Class<? extends IDIYComponent<?>>) c.getClass());
if (type.isContinuity()) {
connections.add(new Connection(c.getControlPoint(0), c.getControlPoint(c.getControlPointCount() - 1)));
if (c instanceof IContinuity) {
for (int i = 0; i < c.getControlPointCount() - 1; i++)
for (int j = i + 1; j < c.getControlPointCount(); j++)
if (((IContinuity)c).arePointsConnected(i, j))
connections.add(new Connection(c.getControlPoint(i), c.getControlPoint(j)));
}
if (a == null || a.getOutlineArea() == null)
@@ -63,10 +63,10 @@ public class InstantiationManager {
public static final ComponentType clipboardType = new ComponentType("Clipboard contents",
"Components from the clipboard", CreationMethod.SINGLE_CLICK, "Multi", "", "", null, null, 0, false, false, null,
false, null, KeywordPolicy.NEVER_SHOW, null, false);
false, null, KeywordPolicy.NEVER_SHOW, null);
public static final ComponentType blockType = new ComponentType("Building block",
"Components from the building block", CreationMethod.SINGLE_CLICK, "Multi", "", "", null, null, 0, false, false, null,
false, null, KeywordPolicy.NEVER_SHOW, null, false);
false, null, KeywordPolicy.NEVER_SHOW, null);
public InstantiationManager() {}
@@ -24,7 +24,6 @@ import java.awt.Point;
import java.awt.Rectangle;
import java.awt.dnd.DnDConstants;
import java.awt.geom.Area;
import java.awt.geom.Line2D;
import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;
import java.io.BufferedInputStream;
@@ -68,6 +67,7 @@ import org.diylc.common.IPlugInPort;
import org.diylc.common.PropertyWrapper;
import org.diylc.common.VariantPackage;
import org.diylc.core.ExpansionMode;
import org.diylc.core.IContinuity;
import org.diylc.core.IDIYComponent;
import org.diylc.core.ISwitch;
import org.diylc.core.IView;
@@ -2712,8 +2712,9 @@ public class Presenter implements IPlugInPort {
for (IDIYComponent<?> c : currentProject.getComponents()) {
ComponentType type =
ComponentProcessor.getInstance().extractComponentTypeFrom((Class<? extends IDIYComponent<?>>) c.getClass());
// extract nodes
if (!type.isContinuity()) {
if (!(c instanceof IContinuity)) {
for (int i = 0; i < c.getControlPointCount(); i++) {
String nodeName = c.getControlPointNodeName(i);
if (nodeName != null) {
@@ -2768,7 +2769,7 @@ public class Presenter implements IPlugInPort {
switchPositions.put(switches.get(j), positions[j]);
posList.add(new Position(switches.get(j), positions[j]));
}
List<Line2D> connections = getConnections(switchPositions);
List<Connection> connections = getConnections(switchPositions);
Netlist graph = constructNetlist(nodes, connections, continuity);
// merge graphs that are effectively the same
@@ -2801,7 +2802,7 @@ public class Presenter implements IPlugInPort {
return netlists;
}
private Netlist constructNetlist(List<Node> nodes, List<Line2D> connections, List<Area> continuityAreas) {
private Netlist constructNetlist(List<Node> nodes, List<Connection> connections, List<Area> continuityAreas) {
Netlist netlist = new Netlist();
// debugging code
@@ -2875,7 +2876,7 @@ public class Presenter implements IPlugInPort {
return netlist;
}
private boolean checkGraphConnection(Point2D point1, Point2D point2, List<Line2D> connections,
private boolean checkGraphConnection(Point2D point1, Point2D point2, List<Connection> connections,
List<Area> continuityAreas, boolean[] visited) {
double t = DrawingManager.CONTROL_POINT_SIZE;
@@ -2891,7 +2892,7 @@ public class Presenter implements IPlugInPort {
if (visited[i])
continue;
Line2D c = connections.get(i);
Connection c = connections.get(i);
if (point1.distance(c.getP1()) < t) {
visited[i] = true;
if (checkGraphConnection(c.getP2(), point2, connections, continuityAreas, visited))
@@ -2908,14 +2909,17 @@ public class Presenter implements IPlugInPort {
}
@SuppressWarnings("unchecked")
private List<Line2D> getConnections(Map<ISwitch, Integer> switchPositions) {
List<Line2D> connections = new ArrayList<Line2D>();
private List<Connection> getConnections(Map<ISwitch, Integer> switchPositions) {
List<Connection> connections = new ArrayList<Connection>();
for (IDIYComponent<?> c : currentProject.getComponents()) {
ComponentType type =
ComponentProcessor.getInstance().extractComponentTypeFrom((Class<? extends IDIYComponent<?>>) c.getClass());
// handle direct connections
if (type.isContinuity()) {
connections.add(new Line2D.Double(c.getControlPoint(0), c.getControlPoint(c.getControlPointCount() - 1)));
if (c instanceof IContinuity) {
for (int i = 0; i < c.getControlPointCount() - 1; i++)
for (int j = i + 1; j < c.getControlPointCount(); j++)
if (((IContinuity)c).arePointsConnected(i, j))
connections.add(new Connection(c.getControlPoint(i), c.getControlPoint(j)));
}
// handle switches
if (ISwitch.class.isAssignableFrom(type.getInstanceClass()) && switchPositions.containsKey(c)) {
@@ -2924,7 +2928,7 @@ public class Presenter implements IPlugInPort {
for (int i = 0; i < c.getControlPointCount() - 1; i++)
for (int j = i + 1; j < c.getControlPointCount(); j++)
if (s.arePointsConnected(i, j, position))
connections.add(new Line2D.Double(c.getControlPoint(i), c.getControlPoint(j)));
connections.add(new Connection(c.getControlPoint(i), c.getControlPoint(j)));
}
}
Binary file not shown.
@@ -37,6 +37,7 @@ import org.diylc.common.Orientation;
import org.diylc.components.AbstractTransparentComponent;
import org.diylc.components.transform.TerminalStripTransformer;
import org.diylc.core.ComponentState;
import org.diylc.core.IContinuity;
import org.diylc.core.IDIYComponent;
import org.diylc.core.IDrawingObserver;
import org.diylc.core.Project;
@@ -53,7 +54,7 @@ import org.diylc.utils.Constants;
@ComponentDescriptor(name = "Terminal Strip", author = "Branislav Stojkovic", category = "Boards",
instanceNamePrefix = "TS", description = "Row of terminals for point-to-point construction", stretchable = false,
zOrder = IDIYComponent.BOARD, keywordPolicy = KeywordPolicy.SHOW_TYPE_NAME, transformer = TerminalStripTransformer.class)
public class TerminalStrip extends AbstractTransparentComponent<String> {
public class TerminalStrip extends AbstractTransparentComponent<String> implements IContinuity {
private static final long serialVersionUID = 1L;
@@ -454,5 +455,10 @@ public class TerminalStrip extends AbstractTransparentComponent<String> {
@Override
public String getControlPointNodeName(int index) {
return "TerminalStrip" + index;
}
@Override
public boolean arePointsConnected(int index1, int index2) {
return Math.abs(index1 - index2) == getTerminalCount();
}
}
@@ -27,6 +27,7 @@ import org.diylc.common.SimpleComponentTransformer;
import org.diylc.components.AbstractLeadedComponent;
import org.diylc.core.ComponentState;
import org.diylc.core.CreationMethod;
import org.diylc.core.IContinuity;
import org.diylc.core.IDIYComponent;
import org.diylc.core.VisibilityPolicy;
import org.diylc.core.annotations.BomPolicy;
@@ -41,7 +42,7 @@ import org.diylc.core.measures.SizeUnit;
description = "Straight copper trace", zOrder = IDIYComponent.TRACE, bomPolicy = BomPolicy.NEVER_SHOW,
autoEdit = false, keywordPolicy = KeywordPolicy.SHOW_TAG, keywordTag = "PCB",
transformer = SimpleComponentTransformer.class)
public class CopperTrace extends AbstractLeadedComponent<Void> {
public class CopperTrace extends AbstractLeadedComponent<Void> implements IContinuity {
private static final long serialVersionUID = 1L;
@@ -167,4 +168,9 @@ public class CopperTrace extends AbstractLeadedComponent<Void> {
public String getControlPointNodeName(int index) {
return null;
}
@Override
public boolean arePointsConnected(int index1, int index2) {
return Math.abs(index1 - index2) == getControlPointCount() - 1;
}
}
@@ -27,6 +27,7 @@ import org.diylc.common.PCBLayer;
import org.diylc.common.SimpleComponentTransformer;
import org.diylc.components.AbstractCurvedComponent;
import org.diylc.core.ComponentState;
import org.diylc.core.IContinuity;
import org.diylc.core.IDIYComponent;
import org.diylc.core.IDrawingObserver;
import org.diylc.core.annotations.BomPolicy;
@@ -40,7 +41,7 @@ import org.diylc.core.measures.SizeUnit;
instanceNamePrefix = "Trace", description = "Curved copper trace with two control points",
zOrder = IDIYComponent.TRACE, bomPolicy = BomPolicy.NEVER_SHOW, autoEdit = false,
keywordPolicy = KeywordPolicy.SHOW_TAG, keywordTag = "PCB", transformer = SimpleComponentTransformer.class)
public class CurvedTrace extends AbstractCurvedComponent<Void> {
public class CurvedTrace extends AbstractCurvedComponent<Void> implements IContinuity {
private static final long serialVersionUID = 1L;
@@ -116,4 +117,9 @@ public class CurvedTrace extends AbstractCurvedComponent<Void> {
public String getControlPointNodeName(int index) {
return null;
}
@Override
public boolean arePointsConnected(int index1, int index2) {
return Math.abs(index1 - index2) == getControlPointCount() - 1;
}
}
@@ -28,6 +28,7 @@ import org.diylc.common.ObjectCache;
import org.diylc.common.SimpleComponentTransformer;
import org.diylc.components.AbstractCurvedComponent;
import org.diylc.core.ComponentState;
import org.diylc.core.IContinuity;
import org.diylc.core.IDIYComponent;
import org.diylc.core.IDrawingObserver;
import org.diylc.core.annotations.BomPolicy;
@@ -38,8 +39,8 @@ import org.diylc.utils.Constants;
@ComponentDescriptor(name = "Hookup Wire", author = "Branislav Stojkovic", category = "Connectivity",
instanceNamePrefix = "W", description = "Flexible wire with two control points", zOrder = IDIYComponent.COMPONENT,
flexibleZOrder = true, bomPolicy = BomPolicy.NEVER_SHOW, autoEdit = false,
transformer = SimpleComponentTransformer.class, continuity = true)
public class HookupWire extends AbstractCurvedComponent<Void> {
transformer = SimpleComponentTransformer.class)
public class HookupWire extends AbstractCurvedComponent<Void> implements IContinuity {
private static final long serialVersionUID = 1L;
@@ -131,5 +132,10 @@ public class HookupWire extends AbstractCurvedComponent<Void> {
public void setStripeColor(Color stripeColor) {
this.stripeColor = stripeColor;
}
@Override
public boolean arePointsConnected(int index1, int index2) {
return Math.abs(index1 - index2) == getControlPointCount() - 1;
}
}
@@ -32,6 +32,7 @@ import org.diylc.common.SimpleComponentTransformer;
import org.diylc.components.AbstractLeadedComponent;
import org.diylc.core.ComponentState;
import org.diylc.core.CreationMethod;
import org.diylc.core.IContinuity;
import org.diylc.core.IDIYComponent;
import org.diylc.core.annotations.BomPolicy;
import org.diylc.core.annotations.ComponentDescriptor;
@@ -41,8 +42,8 @@ import org.diylc.core.measures.Size;
@ComponentDescriptor(name = "Jumper", author = "Branislav Stojkovic", category = "Connectivity",
creationMethod = CreationMethod.POINT_BY_POINT, instanceNamePrefix = "J", description = "",
zOrder = IDIYComponent.COMPONENT, bomPolicy = BomPolicy.NEVER_SHOW, autoEdit = false,
transformer = SimpleComponentTransformer.class, continuity = true)
public class Jumper extends AbstractLeadedComponent<Void> {
transformer = SimpleComponentTransformer.class)
public class Jumper extends AbstractLeadedComponent<Void> implements IContinuity {
private static final long serialVersionUID = 1L;
@@ -156,5 +157,10 @@ public class Jumper extends AbstractLeadedComponent<Void> {
@Override
public Display getDisplay() {
return super.getDisplay();
}
}
@Override
public boolean arePointsConnected(int index1, int index2) {
return true;
}
}
@@ -37,6 +37,7 @@ import org.diylc.common.ObjectCache;
import org.diylc.common.SimpleComponentTransformer;
import org.diylc.components.AbstractCurvedComponent;
import org.diylc.core.ComponentState;
import org.diylc.core.IContinuity;
import org.diylc.core.IDIYComponent;
import org.diylc.core.IDrawingObserver;
import org.diylc.core.annotations.BomPolicy;
@@ -47,8 +48,8 @@ import org.diylc.utils.Constants;
@ComponentDescriptor(name = "Twisted Leads", author = "Branislav Stojkovic", category = "Connectivity",
instanceNamePrefix = "W", description = "A pair of flexible leads twisted tighly together", zOrder = IDIYComponent.COMPONENT,
flexibleZOrder = true, bomPolicy = BomPolicy.NEVER_SHOW, autoEdit = false,
transformer = SimpleComponentTransformer.class, continuity = true)
public class TwistedWire extends AbstractCurvedComponent<Void> {
transformer = SimpleComponentTransformer.class)
public class TwistedWire extends AbstractCurvedComponent<Void> implements IContinuity {
private static final long serialVersionUID = 1L;
@@ -432,4 +433,9 @@ public class TwistedWire extends AbstractCurvedComponent<Void> {
return calculateLength(left, precision) + calculateLength(right, precision);
}
@Override
public boolean arePointsConnected(int index1, int index2) {
return Math.abs(index1 - index2) == getControlPointCount() - 1;
}
}
Binary file not shown.
Binary file not shown.
+4
View File
@@ -2633,6 +2633,10 @@
<org.diylc.appframework.update.Change>
<changeType>IMPROVEMENT</changeType>
<description>Output SPICE node names in the "Nxxx" format</description>
</org.diylc.appframework.update.Change>
<org.diylc.appframework.update.Change>
<changeType>IMPROVEMENT</changeType>
<description>Honor "Terminal Strip" connectivity when creating a netlist</description>
</org.diylc.appframework.update.Change>
</changes>
<url>https://github.com/bancika/diy-layout-creator/releases</url>