mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-11 01:32:08 +10:00
Added "Common Node" component that ties all nodes with the same label together, e.g. B+, V+, GND, etc
This commit is contained in:
@@ -266,11 +266,6 @@ public abstract class AbstractComponent<T> implements IDIYComponent<T> {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCommonPointName(int pointIndex) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canPointMoveFreely(int pointIndex) {
|
||||
return true;
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
*
|
||||
* 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 ICommonNode {
|
||||
|
||||
|
||||
/***
|
||||
* @return label of the common node. All nodes with the same labels will be considered as
|
||||
* connected, e.g. B+ or A, B, C
|
||||
*/
|
||||
String getCommonNodeLabel();
|
||||
}
|
||||
@@ -138,12 +138,6 @@ public interface IDIYComponent<T> extends Serializable, Cloneable {
|
||||
*/
|
||||
String[] getSectionNames(int pointIndex);
|
||||
|
||||
/**
|
||||
* @param pointIndex
|
||||
* @return name of the common point that joins all the other points with the same name together, e.g. GND
|
||||
*/
|
||||
String getCommonPointName(int pointIndex);
|
||||
|
||||
/**
|
||||
* @param pointIndex
|
||||
* @return true if the control point can move without affecting other points' position, false otherwise
|
||||
|
||||
@@ -30,6 +30,7 @@ import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
import java.util.stream.Collectors;
|
||||
import org.diylc.common.ComponentType;
|
||||
import org.diylc.core.ICommonNode;
|
||||
import org.diylc.core.IContinuity;
|
||||
import org.diylc.core.IDIYComponent;
|
||||
import org.diylc.core.ISwitch;
|
||||
@@ -60,13 +61,15 @@ public class NetlistBuilder {
|
||||
List<Node> nodes = new ArrayList<Node>();
|
||||
|
||||
List<ISwitch> switches = new ArrayList<ISwitch>();
|
||||
|
||||
Set<String> commonNodes = new HashSet<String>();
|
||||
|
||||
for (IDIYComponent<?> c : project.getComponents()) {
|
||||
ComponentType type = ComponentProcessor.getInstance()
|
||||
.extractComponentTypeFrom((Class<? extends IDIYComponent<?>>) c.getClass());
|
||||
|
||||
// extract nodes
|
||||
if (!(c instanceof IContinuity)) {
|
||||
if (!(c instanceof IContinuity) && !(c instanceof ICommonNode)) {
|
||||
for (int i = 0; i < c.getControlPointCount(); i++) {
|
||||
String nodeName = c.getControlPointNodeName(i);
|
||||
if (nodeName != null
|
||||
@@ -75,6 +78,15 @@ public class NetlistBuilder {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// create only one node per common label to avoid duplications in the netlist, as they will get eventually connected anyways
|
||||
if (c instanceof ICommonNode) {
|
||||
String label = ((ICommonNode)c).getCommonNodeLabel();
|
||||
if (!commonNodes.contains(label)) {
|
||||
commonNodes.add(label);
|
||||
nodes.add(new Node(c, 0));
|
||||
}
|
||||
}
|
||||
|
||||
// extract switches
|
||||
if (includeSwitches && ISwitch.class.isAssignableFrom(type.getInstanceClass()))
|
||||
@@ -342,6 +354,8 @@ public class NetlistBuilder {
|
||||
private static List<Connection> getConnections(Project project, Map<ISwitch, Integer> switchPositions) {
|
||||
Set<Connection> connections = new TreeSet<Connection>();
|
||||
|
||||
Map<String, List<IDIYComponent<?>>> commonNodeMap = new HashMap<String, List<IDIYComponent<?>>>();
|
||||
|
||||
for (IDIYComponent<?> c : project.getComponents()) {
|
||||
ComponentType type =
|
||||
ComponentProcessor.getInstance().extractComponentTypeFrom((Class<? extends IDIYComponent<?>>) c.getClass());
|
||||
@@ -361,6 +375,20 @@ public class NetlistBuilder {
|
||||
if (s.arePointsConnected(i, j, position))
|
||||
connections.add(new Connection(c.getControlPoint(i), c.getControlPoint(j)));
|
||||
}
|
||||
// handle common nodes
|
||||
if (ICommonNode.class.isAssignableFrom(type.getInstanceClass())) {
|
||||
ICommonNode commonNode = (ICommonNode) c;
|
||||
String label = commonNode.getCommonNodeLabel();
|
||||
commonNodeMap.computeIfAbsent(label, (key) -> new ArrayList<IDIYComponent<?>>()).add(c);
|
||||
}
|
||||
}
|
||||
|
||||
// connect common nodes together by chaining them one by one
|
||||
for (List<IDIYComponent<?>> commonPoints : commonNodeMap.values()) {
|
||||
IDIYComponent<?>[] commonPointArr = commonPoints.toArray(new IDIYComponent<?>[0]);
|
||||
for (int i = 0; i < commonPointArr.length - 1; i++) {
|
||||
connections.add(new Connection(commonPointArr[i].getControlPoint(0), commonPointArr[i + 1].getControlPoint(0)));
|
||||
}
|
||||
}
|
||||
|
||||
return new ArrayList<Connection>(connections);
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
package org.diylc.netlist;
|
||||
|
||||
import java.awt.geom.Point2D;
|
||||
import org.diylc.core.ICommonNode;
|
||||
import org.diylc.core.IDIYComponent;
|
||||
|
||||
/**
|
||||
@@ -87,6 +88,9 @@ public class Node implements Comparable<Node> {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
if (component instanceof ICommonNode) {
|
||||
return ((ICommonNode)component).getCommonNodeLabel();
|
||||
}
|
||||
if (component.getControlPointCount() == 1)
|
||||
return component.getName();
|
||||
return component.getName() + "." + getDisplayName() /*+ " @ (" + component.getControlPoint(pointIndex).getX() + ":" + component.getControlPoint(pointIndex).getY() + ")"*/;
|
||||
|
||||
@@ -4062,9 +4062,21 @@
|
||||
<releaseDate>2022-10-23 00:00:00.000 CET</releaseDate>
|
||||
<name></name>
|
||||
<changes>
|
||||
<org.diylc.appframework.update.Change>
|
||||
<changeType>NEW_FEATURE</changeType>
|
||||
<description>Added "Common Node" component that ties all nodes with the same label together, e.g. B+, V+, GND, etc</description>
|
||||
</org.diylc.appframework.update.Change>
|
||||
<org.diylc.appframework.update.Change>
|
||||
<changeType>NEW_FEATURE</changeType>
|
||||
<description>Ground symbol ties all grounded points together for circuit analysis</description>
|
||||
</org.diylc.appframework.update.Change>
|
||||
<org.diylc.appframework.update.Change>
|
||||
<changeType>IMPROVEMENT</changeType>
|
||||
<description>"Snap to Components" features now works when creating new components as well as when moving existing ones</description>
|
||||
</org.diylc.appframework.update.Change>
|
||||
<org.diylc.appframework.update.Change>
|
||||
<changeType>BUG_FIX</changeType>
|
||||
<description>"Snap to" configuration menu does not work properly when using translated UI to any language other than English</description>
|
||||
</org.diylc.appframework.update.Change>
|
||||
</changes>
|
||||
<url>https://github.com/bancika/diy-layout-creator/releases</url>
|
||||
|
||||
Reference in New Issue
Block a user