mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-11 01:32:08 +10:00
improved netlist display
minor component updates
This commit is contained in:
@@ -22,12 +22,10 @@
|
||||
package org.diylc.common;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.diylc.netlist.Netlist;
|
||||
import org.diylc.netlist.SwitchSetup;
|
||||
|
||||
public interface INetlistProcessor {
|
||||
|
||||
Map<Netlist, List<SwitchSetup>> extractNetlists();
|
||||
List<Netlist> extractNetlists();
|
||||
}
|
||||
|
||||
@@ -21,7 +21,10 @@
|
||||
*/
|
||||
package org.diylc.netlist;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
@@ -29,7 +32,7 @@ import java.util.Set;
|
||||
*
|
||||
* @author Branislav Stojkovic
|
||||
*/
|
||||
public class Group {
|
||||
public class Group implements Comparable<Group> {
|
||||
|
||||
private Set<Node> nodes = new HashSet<Node>();
|
||||
|
||||
@@ -41,6 +44,12 @@ public class Group {
|
||||
public Set<Node> getNodes() {
|
||||
return nodes;
|
||||
}
|
||||
|
||||
public List<Node> getSortedNodes() {
|
||||
List<Node> list = new ArrayList<Node>(nodes);
|
||||
Collections.sort(list);
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
@@ -70,11 +79,17 @@ public class Group {
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (Node n : nodes) {
|
||||
List<Node> list = getSortedNodes();
|
||||
for (Node n : list) {
|
||||
if (sb.length() > 0)
|
||||
sb.append(" <-> ");
|
||||
sb.append(n);
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(Group o) {
|
||||
return toString().compareToIgnoreCase(o.toString());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,24 +21,38 @@
|
||||
*/
|
||||
package org.diylc.netlist;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class Netlist {
|
||||
public class Netlist implements Comparable<Netlist> {
|
||||
|
||||
private Set<Group> groups = new HashSet<Group>();
|
||||
private List<SwitchSetup> switchSetup = new ArrayList<SwitchSetup>();
|
||||
|
||||
public Netlist() {
|
||||
public Netlist() {
|
||||
}
|
||||
|
||||
public Set<Group> getGroups() {
|
||||
return groups;
|
||||
}
|
||||
|
||||
public boolean verticesMatch(Netlist other) {
|
||||
return this.groups.equals(other.groups);
|
||||
public List<Group> getSortedGroups() {
|
||||
List<Group> list = new ArrayList<Group>(groups);
|
||||
Collections.sort(list);
|
||||
return list;
|
||||
}
|
||||
|
||||
public List<SwitchSetup> getSwitchSetup() {
|
||||
return switchSetup;
|
||||
}
|
||||
|
||||
public void done() {
|
||||
Collections.sort(switchSetup);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
@@ -67,9 +81,15 @@ public class Netlist {
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (Group v : groups) {
|
||||
sb.append("\t").append(v).append("\n");
|
||||
List<Group> list = getSortedGroups();
|
||||
for (Group g : list) {
|
||||
sb.append("\t").append(g).append("\n");
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(Netlist o) {
|
||||
return switchSetup.toString().compareToIgnoreCase(o.switchSetup.toString());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ import org.diylc.core.IDIYComponent;
|
||||
*
|
||||
* @author Branislav Stojkovic
|
||||
*/
|
||||
public class Node {
|
||||
public class Node implements Comparable<Node> {
|
||||
|
||||
private IDIYComponent<?> component;
|
||||
private int pointIndex;
|
||||
@@ -79,4 +79,9 @@ public class Node {
|
||||
public String toString() {
|
||||
return component.getName() + "." + component.getControlPointNodeName(pointIndex) /*+ " @ (" + component.getControlPoint(pointIndex).getX() + ":" + component.getControlPoint(pointIndex).getY() + ")"*/;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(Node o) {
|
||||
return toString().compareToIgnoreCase(o.toString());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ import org.diylc.core.ISwitch;
|
||||
*
|
||||
* @author Branislav Stojkovic
|
||||
*/
|
||||
public class Position {
|
||||
public class Position implements Comparable<Position> {
|
||||
|
||||
private ISwitch theSwitch;
|
||||
private int position;
|
||||
@@ -80,4 +80,11 @@ public class Position {
|
||||
public String toString() {
|
||||
return (theSwitch instanceof IDIYComponent<?> ? ((IDIYComponent<?>) theSwitch).getName() + "." : "") + theSwitch.getPositionName(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(Position o) {
|
||||
if (theSwitch instanceof IDIYComponent<?> && o.theSwitch instanceof IDIYComponent<?>)
|
||||
return ((IDIYComponent<?>) theSwitch).getName().compareToIgnoreCase(((IDIYComponent<?>) o.theSwitch).getName());
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
*/
|
||||
package org.diylc.netlist;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -28,13 +29,14 @@ import java.util.List;
|
||||
*
|
||||
* @author Branislav Stojkovic
|
||||
*/
|
||||
public class SwitchSetup {
|
||||
public class SwitchSetup implements Comparable<SwitchSetup> {
|
||||
|
||||
private List<Position> positions;
|
||||
|
||||
public SwitchSetup(List<Position> positions) {
|
||||
super();
|
||||
this.positions = positions;
|
||||
Collections.sort(this.positions);
|
||||
}
|
||||
|
||||
public List<Position> getPositions() {
|
||||
@@ -77,4 +79,9 @@ public class SwitchSetup {
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(SwitchSetup o) {
|
||||
return toString().compareToIgnoreCase(o.toString());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2687,8 +2687,8 @@ public class Presenter implements IPlugInPort {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public Map<Netlist, List<SwitchSetup>> extractNetlists() {
|
||||
Map<Netlist, List<SwitchSetup>> result = new HashMap<Netlist, List<SwitchSetup>>();
|
||||
public List<Netlist> extractNetlists() {
|
||||
Map<Netlist, Netlist> result = new HashMap<Netlist, Netlist>();
|
||||
List<Node> nodes = new ArrayList<Node>();
|
||||
|
||||
List<ISwitch> switches = new ArrayList<ISwitch>();
|
||||
@@ -2756,11 +2756,10 @@ public class Presenter implements IPlugInPort {
|
||||
|
||||
// merge graphs that are effectivelly the same
|
||||
if (result.containsKey(graph)) {
|
||||
result.get(graph).add(new SwitchSetup(posList));
|
||||
} else {
|
||||
List<SwitchSetup> list = new ArrayList<SwitchSetup>();
|
||||
list.add(new SwitchSetup(posList));
|
||||
result.put(graph, list);
|
||||
result.get(graph).getSwitchSetup().add(new SwitchSetup(posList));
|
||||
} else {
|
||||
graph.getSwitchSetup().add(new SwitchSetup(posList));
|
||||
result.put(graph, graph);
|
||||
}
|
||||
|
||||
// find the next combination if possible
|
||||
@@ -2777,13 +2776,18 @@ public class Presenter implements IPlugInPort {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
// sort everything alphabetically
|
||||
List<Netlist> netlists = new ArrayList<Netlist>(result.keySet());
|
||||
Collections.sort(netlists);
|
||||
|
||||
return netlists;
|
||||
}
|
||||
|
||||
private Netlist constructGraph(List<Node> nodes, List<Line2D> connections, List<Area> continuityAreas) {
|
||||
Netlist graph = new Netlist();
|
||||
Netlist netlist = new Netlist();
|
||||
|
||||
// debugging code
|
||||
// StringBuilder sb = new StringBuilder();
|
||||
// sb.append("Nodes:").append("\n");
|
||||
// for (Node n : nodes) {
|
||||
@@ -2809,20 +2813,22 @@ public class Presenter implements IPlugInPort {
|
||||
checkGraphConnection(point2, point1, connections, continuityAreas, new boolean[connections.size()])) {
|
||||
boolean added = false;
|
||||
// add to an existing vertex if possible
|
||||
for (Group v :graph.getGroups())
|
||||
if (v.getNodes().contains(node1)) {
|
||||
v.getNodes().add(node2);
|
||||
for (Group g : netlist.getGroups())
|
||||
if (g.getNodes().contains(node1)) {
|
||||
g.getNodes().add(node2);
|
||||
added = true;
|
||||
} else if (v.getNodes().contains(node2)) {
|
||||
v.getNodes().add(node1);
|
||||
} else if (g.getNodes().contains(node2)) {
|
||||
g.getNodes().add(node1);
|
||||
added = true;
|
||||
}
|
||||
if (!added)
|
||||
graph.getGroups().add(new Group(node1, node2));
|
||||
netlist.getGroups().add(new Group(node1, node2));
|
||||
}
|
||||
}
|
||||
|
||||
return graph;
|
||||
netlist.done();
|
||||
|
||||
return netlist;
|
||||
}
|
||||
|
||||
private boolean checkGraphConnection(Point2D point1, Point2D point2, List<Line2D> connections,
|
||||
|
||||
Reference in New Issue
Block a user