mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-11 01:32:08 +10:00
generate connectivity tree
This commit is contained in:
+12
-2
@@ -26,8 +26,10 @@ import java.util.List;
|
||||
import org.diylc.netlist.Netlist;
|
||||
import org.diylc.netlist.Node;
|
||||
import org.diylc.netlist.Summary;
|
||||
import org.diylc.netlist.Tree;
|
||||
import org.diylc.netlist.TreeException;
|
||||
|
||||
public interface INetlistSummarizer {
|
||||
public interface INetlistAnalyzer {
|
||||
|
||||
/**
|
||||
* @return summarizer name
|
||||
@@ -37,7 +39,7 @@ public interface INetlistSummarizer {
|
||||
/**
|
||||
* @return name of the icon to use
|
||||
*/
|
||||
String getIconName();
|
||||
String getIconName();
|
||||
|
||||
/**
|
||||
* Summarizes all {@link Netlist}s provided.
|
||||
@@ -47,4 +49,12 @@ public interface INetlistSummarizer {
|
||||
* @return
|
||||
*/
|
||||
List<Summary> summarize(List<Netlist> netlists, Node preferredOutput);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param netlist
|
||||
* @return
|
||||
* @throws TreeException
|
||||
*/
|
||||
Tree constructTree(Netlist netlist) throws TreeException;
|
||||
}
|
||||
@@ -40,9 +40,11 @@ public interface INetlistProcessor {
|
||||
List<Netlist> extractNetlists();
|
||||
|
||||
/**
|
||||
* Finds all available {@link INetlistSummarizer} implementations.
|
||||
* Finds all available {@link INetlistAnalyzer} implementations.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
List<INetlistSummarizer> getNetlistSummarizers();
|
||||
List<INetlistAnalyzer> getNetlistAnalyzers();
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -284,5 +284,10 @@ public abstract class AbstractComponent<T> implements IDIYComponent<T> {
|
||||
@Override
|
||||
public String getControlPointNodeName(int index) {
|
||||
return Integer.toString(index + 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getInternalLinkName(int index1, int index2) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -121,7 +121,14 @@ public interface IDIYComponent<T> extends Serializable {
|
||||
* @param index
|
||||
* @return name of the control point node, if the control point represents a graph node, null otherwise.
|
||||
*/
|
||||
String getControlPointNodeName(int index);
|
||||
String getControlPointNodeName(int index);
|
||||
|
||||
/**
|
||||
* @param index1
|
||||
* @param index2
|
||||
* @return name of the internal linked formed by the two control points, null if they do not form an internal link
|
||||
*/
|
||||
String getInternalLinkName(int index1, int index2);
|
||||
|
||||
/**
|
||||
* Draws the component onto the {@link Graphics2D}.
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
|
||||
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.netlist;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface ITree {
|
||||
|
||||
List<ITree> getChildren();
|
||||
|
||||
TreeConnectionType getConnectionType();
|
||||
}
|
||||
@@ -27,11 +27,13 @@ public class Summary {
|
||||
|
||||
private Netlist netlist;
|
||||
private List<String> notes;
|
||||
private Tree tree;
|
||||
|
||||
public Summary(Netlist netlist, List<String> notes) {
|
||||
public Summary(Netlist netlist, List<String> notes, Tree tree) {
|
||||
super();
|
||||
this.netlist = netlist;
|
||||
this.notes = notes;
|
||||
this.tree = tree;
|
||||
}
|
||||
|
||||
public Netlist getNetlist() {
|
||||
@@ -41,6 +43,10 @@ public class Summary {
|
||||
public List<String> getNotes() {
|
||||
return notes;
|
||||
}
|
||||
|
||||
public Tree getTree() {
|
||||
return tree;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
|
||||
@@ -0,0 +1,137 @@
|
||||
/*
|
||||
|
||||
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.netlist;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class Tree {
|
||||
|
||||
private List<Tree> children;
|
||||
private TreeConnectionType connectionType;
|
||||
private TreeLeaf leaf;
|
||||
|
||||
public Tree(TreeLeaf leaf) {
|
||||
this.leaf = leaf;
|
||||
}
|
||||
|
||||
public Tree(List<Tree> children, TreeConnectionType connectionType) {
|
||||
this.children = children;
|
||||
this.connectionType = connectionType;
|
||||
}
|
||||
|
||||
public List<Tree> getChildren() {
|
||||
return children;
|
||||
}
|
||||
|
||||
public void trimChildren(int count) {
|
||||
children = children.subList(count, children.size());
|
||||
}
|
||||
|
||||
public TreeConnectionType getConnectionType() {
|
||||
return connectionType;
|
||||
}
|
||||
|
||||
public TreeLeaf getLeaf() {
|
||||
return leaf;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((children == null) ? 0 : children.hashCode());
|
||||
result = prime * result + ((connectionType == null) ? 0 : connectionType.hashCode());
|
||||
result = prime * result + ((leaf == null) ? 0 : leaf.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
Tree other = (Tree) obj;
|
||||
if (children == null) {
|
||||
if (other.children != null)
|
||||
return false;
|
||||
} else if (!children.equals(other.children))
|
||||
return false;
|
||||
if (connectionType != other.connectionType)
|
||||
return false;
|
||||
if (leaf == null) {
|
||||
if (other.leaf != null)
|
||||
return false;
|
||||
} else if (!leaf.equals(other.leaf))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
if (leaf != null)
|
||||
return leaf.toString();
|
||||
|
||||
StringBuilder sb = new StringBuilder("(");
|
||||
boolean first = true;
|
||||
for(Tree child : children) {
|
||||
if (!first)
|
||||
sb.append(" " ).append(connectionType).append(" ");
|
||||
first = false;
|
||||
sb.append(child);
|
||||
}
|
||||
sb.append(")");
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public String toHTML(int depth) {
|
||||
if (leaf != null)
|
||||
return leaf.toHTML();
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
if (depth > 0 && children.size() > 1)
|
||||
sb.append("(");
|
||||
boolean first = true;
|
||||
for(Tree child : children) {
|
||||
if (!first) {
|
||||
sb.append(" ").append(connectionType.toHTML()).append(" ");
|
||||
if (depth == 0)
|
||||
sb.append("<br>");
|
||||
}
|
||||
first = false;
|
||||
sb.append(child.toHTML(depth + children.size() > 1 ? 1 : 0));
|
||||
}
|
||||
if (depth > 0 && children.size() > 1)
|
||||
sb.append(")");
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object clone() throws CloneNotSupportedException {
|
||||
if (leaf != null)
|
||||
return new Tree(leaf);
|
||||
return new Tree(new ArrayList<Tree>(children), connectionType);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
|
||||
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.netlist;
|
||||
|
||||
public enum TreeConnectionType {
|
||||
|
||||
Series("+", "red"), Parallel("||", "blue");
|
||||
|
||||
private String label;
|
||||
private String color;
|
||||
|
||||
private TreeConnectionType(String label, String color) {
|
||||
this.label = label;
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return label;
|
||||
}
|
||||
|
||||
public String toHTML() {
|
||||
return "<b><font color='" + color + "'>" + label + "</font></b>";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package org.diylc.netlist;
|
||||
|
||||
public class TreeException extends Exception {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public TreeException() {
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
public TreeException(String message) {
|
||||
super(message);
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
public TreeException(Throwable cause) {
|
||||
super(cause);
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
public TreeException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
/*
|
||||
|
||||
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.netlist;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.diylc.core.IDIYComponent;
|
||||
|
||||
public class TreeLeaf implements ITree {
|
||||
|
||||
private IDIYComponent<?> component;
|
||||
private int pointIndex1;
|
||||
private int pointIndex2;
|
||||
|
||||
public TreeLeaf(IDIYComponent<?> component, int pointIndex1, int pointIndex2) {
|
||||
this.component = component;
|
||||
this.pointIndex1 = pointIndex1;
|
||||
this.pointIndex2 = pointIndex2;
|
||||
}
|
||||
|
||||
public IDIYComponent<?> getComponent() {
|
||||
return component;
|
||||
}
|
||||
|
||||
public int getPointIndex1() {
|
||||
return pointIndex1;
|
||||
}
|
||||
|
||||
public int getPointIndex2() {
|
||||
return pointIndex2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ITree> getChildren() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TreeConnectionType getConnectionType() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((component == null) ? 0 : component.hashCode());
|
||||
result = prime * result + pointIndex1;
|
||||
result = prime * result + pointIndex2;
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
TreeLeaf other = (TreeLeaf) obj;
|
||||
if (component == null) {
|
||||
if (other.component != null)
|
||||
return false;
|
||||
} else if (!component.equals(other.component))
|
||||
return false;
|
||||
if (pointIndex1 != other.pointIndex1)
|
||||
return false;
|
||||
if (pointIndex2 != other.pointIndex2)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return component.getName() + "." + component.getInternalLinkName(pointIndex1, pointIndex2);
|
||||
}
|
||||
|
||||
public String toHTML() {
|
||||
return toString().replace("<", "<").replace(">", ">");
|
||||
}
|
||||
}
|
||||
@@ -62,7 +62,7 @@ import org.diylc.common.EventType;
|
||||
import org.diylc.common.IComponentFiler;
|
||||
import org.diylc.common.IComponentTransformer;
|
||||
import org.diylc.common.IKeyProcessor;
|
||||
import org.diylc.common.INetlistSummarizer;
|
||||
import org.diylc.common.INetlistAnalyzer;
|
||||
import org.diylc.common.IPlugIn;
|
||||
import org.diylc.common.IPlugInPort;
|
||||
import org.diylc.common.PropertyWrapper;
|
||||
@@ -2753,7 +2753,7 @@ public class Presenter implements IPlugInPort {
|
||||
posList.add(new Position(switches.get(j), positions[j]));
|
||||
}
|
||||
List<Line2D> connections = getConnections(switchPositions);
|
||||
Netlist graph = constructGraph(nodes, connections, continuity);
|
||||
Netlist graph = constructNetlist(nodes, connections, continuity);
|
||||
|
||||
// merge graphs that are effectivelly the same
|
||||
if (result.containsKey(graph)) {
|
||||
@@ -2785,7 +2785,7 @@ public class Presenter implements IPlugInPort {
|
||||
return netlists;
|
||||
}
|
||||
|
||||
private Netlist constructGraph(List<Node> nodes, List<Line2D> connections, List<Area> continuityAreas) {
|
||||
private Netlist constructNetlist(List<Node> nodes, List<Line2D> connections, List<Area> continuityAreas) {
|
||||
Netlist netlist = new Netlist();
|
||||
|
||||
// debugging code
|
||||
@@ -2827,7 +2827,7 @@ public class Presenter implements IPlugInPort {
|
||||
}
|
||||
}
|
||||
|
||||
netlist.done();
|
||||
Collections.sort(netlist.getSwitchSetup());
|
||||
|
||||
return netlist;
|
||||
}
|
||||
@@ -2889,15 +2889,15 @@ public class Presenter implements IPlugInPort {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<INetlistSummarizer> getNetlistSummarizers() {
|
||||
public List<INetlistAnalyzer> getNetlistAnalyzers() {
|
||||
Set<Class<?>> classes;
|
||||
try {
|
||||
classes = Utils.getClasses("org.diylc.netlist");
|
||||
List<INetlistSummarizer> result = new ArrayList<INetlistSummarizer>();
|
||||
List<INetlistAnalyzer> result = new ArrayList<INetlistAnalyzer>();
|
||||
|
||||
for (Class<?> clazz : classes) {
|
||||
if (!Modifier.isAbstract(clazz.getModifiers()) && INetlistSummarizer.class.isAssignableFrom(clazz)) {
|
||||
result.add((INetlistSummarizer) clazz.newInstance());
|
||||
if (!Modifier.isAbstract(clazz.getModifiers()) && INetlistAnalyzer.class.isAssignableFrom(clazz)) {
|
||||
result.add((INetlistAnalyzer) clazz.newInstance());
|
||||
}
|
||||
}
|
||||
return result;
|
||||
|
||||
Reference in New Issue
Block a user