mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-11 01:32:08 +10:00
Honor "Terminal Strip" connectivity when creating a netlist
This commit is contained in:
@@ -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)));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user