generate connectivity tree

This commit is contained in:
Branislav Stojkovic
2019-02-23 17:40:15 +01:00
parent ec7244042d
commit c0dac1a1db
24 changed files with 981 additions and 316 deletions
@@ -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("&nbsp;").append(connectionType.toHTML()).append("&nbsp;");
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("<", "&lt;").replace(">", "&gt");
}
}
@@ -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;
Binary file not shown.
@@ -534,6 +534,13 @@ public abstract class AbstractLeadedComponent<T> extends AbstractTransparentComp
public void setLabelOriantation(LabelOriantation labelOriantation) {
this.labelOriantation = labelOriantation;
}
@Override
public String getInternalLinkName(int index1, int index2) {
if ((index1 == 0 && index2 == getControlPointCount() - 1) || (index2 == 0 && index1 == getControlPointCount() - 1))
return getName();
return null;
}
/**
* Override this method with @EditableProperty annotation in child classes where standing mode is
@@ -39,6 +39,7 @@ import org.diylc.common.ObjectCache;
import org.diylc.common.Orientation;
import org.diylc.common.VerticalAlignment;
import org.diylc.components.AbstractTransparentComponent;
import org.diylc.components.guitar.SingleCoilPickup.Polarity;
import org.diylc.core.ComponentState;
import org.diylc.core.IDIYComponent;
import org.diylc.core.IDrawingObserver;
@@ -667,6 +668,20 @@ public class HumbuckerPickup extends AbstractTransparentComponent<String> {
}
return null;
}
@Override
public String getInternalLinkName(int index1, int index2) {
if (index1 == 0 && index2 == 1)
return Polarity.North.toString() + "->";
else if (index1 == 2 && index2 == 3)
return Polarity.South.toString() + "->";
else if (index1 == 1 && index2 == 0)
return Polarity.North.toString() + "<-";
else if (index1 == 3 && index2 == 2)
return Polarity.South.toString() + "<-";
return null;
}
public static enum HumbuckerType {
@@ -607,6 +607,30 @@ public class SingleCoilPickup extends AbstractTransparentComponent<String> {
return null;
return "South Finish";
}
return null;
}
@Override
public String getInternalLinkName(int index1, int index2) {
switch (getPolarity()) {
case Humbucking:
if (index1 == 0 && index2 == 1)
return Polarity.North.toString() + "->";
else if (index1 == 1 && index2 == 0)
return Polarity.North.toString() + "<-";
else if (index1 == 2 && index2 == 3)
return Polarity.South.toString() + "->";
else if (index1 == 3 && index2 == 2)
return Polarity.South.toString() + "<-";
break;
case North:
case South:
if (index1 == 1 && index2 == 2)
return getPolarity().toString() + "->";
else if (index1 == 2 && index2 == 1)
return getPolarity().toString() + "<-";
}
return null;
}
@@ -457,6 +457,17 @@ public class PotentiometerPanel extends AbstractPotentiometer {
public void setWaferColor(Color waferColor) {
this.waferColor = waferColor;
}
@Override
public String getInternalLinkName(int index1, int index2) {
if (index1 > index2)
return getInternalLinkName(index2, index1);
if (index2 - index1 == 1)
return (index1 + 1) + "-" + (index2 + 1);
return null;
}
public enum Type {
@@ -0,0 +1,362 @@
/*
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.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.diylc.core.IDIYComponent;
public abstract class AbstractNetlistAnalyzer {
public AbstractNetlistAnalyzer() {
}
protected Tree constructTree(Netlist netlist, Node nodeA, Node nodeB) {
Tree tree = new Tree(new ArrayList<Tree>(), TreeConnectionType.Parallel);
connectNodes(netlist, nodeA, nodeB, tree.getChildren(), null, new HashSet<Node>());
// System.out.println(netlist.getSwitchSetup());
// System.out.println(tree);
return tree;
}
protected void connectNodes(Netlist netlist, Node nodeA, Node nodeB, List<Tree> concurrentPaths, Tree currentPath, Set<Node> visited) {
if (nodeA == nodeB) {
concurrentPaths.add(currentPath);
return;
}
Group groupA = findGroup(netlist, nodeA);
if (groupA == null)
return;
if (groupA.getNodes().contains(nodeB)) {
concurrentPaths.add(currentPath);
return;
}
visited.add(nodeA);
for (Node n : groupA.getNodes()) {
IDIYComponent<?> c = n.getComponent();
for (int i = 0; i < c.getControlPointCount(); i++) {
if (i != n.getPointIndex() && c.getInternalLinkName(i, n.getPointIndex()) != null) {
TreeLeaf l = new TreeLeaf(c, i, n.getPointIndex());
Node newNodeA = new Node(c, i);
if (!visited.contains(newNodeA)) {
visited.add(n);
Tree newCurrentPath = null;
try {
if (currentPath == null)
newCurrentPath = new Tree(new ArrayList<Tree>(), TreeConnectionType.Series);
else
newCurrentPath = (Tree) currentPath.clone();
} catch (CloneNotSupportedException e) {
}
Tree newItem = new Tree(l);
if (!newCurrentPath.getChildren().contains(newItem))
newCurrentPath.getChildren().add(newItem);
// if (!currentPath.contains(l))
// newCurrentPath.add(l);
Set<Node> newVisited = new HashSet<Node>(visited);
connectNodes(netlist, newNodeA, nodeB, concurrentPaths, newCurrentPath, newVisited);
}
}
}
}
if (concurrentPaths.size() < 2)
return;
Tree jointSection = new Tree(new ArrayList<Tree>(), TreeConnectionType.Series);
for (int i = 0; i < concurrentPaths.get(0).getChildren().size(); i++) {
Tree unique = concurrentPaths.get(0).getChildren().get(i);
boolean canMerge = true;
for (Tree t : concurrentPaths) {
if (t.getConnectionType() != TreeConnectionType.Series || t.getChildren().size() <= i || !t.getChildren().get(i).equals(unique)) {
canMerge = false;
break;
}
}
if (canMerge)
jointSection.getChildren().add(unique);
else
break;
}
if (!jointSection.getChildren().isEmpty()) {
Tree mergedTree = new Tree(new ArrayList<Tree>(), TreeConnectionType.Series);
mergedTree.getChildren().add(jointSection);
Tree parallelSection = new Tree(new ArrayList<Tree>(concurrentPaths), TreeConnectionType.Parallel);
for (Tree t : parallelSection.getChildren()) {
t.trimChildren(jointSection.getChildren().size());
}
mergedTree.getChildren().add(parallelSection);
concurrentPaths.clear();
concurrentPaths.add(mergedTree);
}
}
protected void findAllPaths(Netlist netlist, Node nodeA, Node nodeB, List<TreeLeaf> currentPath, List<List<TreeLeaf>> allPaths, Set<Node> visited) {
if (nodeA == nodeB) {
allPaths.add(currentPath);
return;
}
// System.out.println("Finding path between " + nodeA + " and " + nodeB);
Group groupA = findGroup(netlist, nodeA);
if (groupA == null)
return;
if (groupA.getNodes().contains(nodeB)) {
allPaths.add(currentPath);
return;
}
for (Node n : groupA.getNodes()) {
IDIYComponent<?> c = n.getComponent();
for (int i = 0; i < c.getControlPointCount(); i++) {
if (i != n.getPointIndex() && c.getInternalLinkName(i, n.getPointIndex()) != null) {
TreeLeaf l = new TreeLeaf(c, i, n.getPointIndex());
Node newNodeA = new Node(c, i);
if (!visited.contains(newNodeA)) {
List<TreeLeaf> newCurrentPath = new ArrayList<TreeLeaf>(currentPath);
if (!currentPath.contains(l))
newCurrentPath.add(l);
Set<Node> newVisited = new HashSet<Node>(visited);
newVisited.add(nodeA);
newVisited.add(newNodeA);
findAllPaths(netlist, newNodeA, nodeB, newCurrentPath, allPaths, newVisited);
}
}
}
}
}
protected Group findGroup(Netlist netlist, Node node) {
for (Group g : netlist.getGroups())
if (g.getNodes().contains(node))
return g;
return null;
}
protected List<Group> trace(Set<String> typeNames, String nodeName, Netlist netlist) {
List<Group> res = new ArrayList<Group>();
for (Group g : netlist.getGroups()) {
for (Node n : g.getNodes()) {
if (typeNames.contains(n.getComponent().getClass().getCanonicalName()) &&
(nodeName == null || n.getDisplayName().equalsIgnoreCase(nodeName))) {
res.add(g);
break;
}
}
}
return res;
}
protected List<Node> find(Set<String> typeNames, String nodeName, Group group) {
List<Node> res = new ArrayList<Node>();
for (Node n : group.getNodes()) {
if (typeNames.contains(n.getComponent().getClass().getCanonicalName()) &&
(nodeName == null || n.getDisplayName().equalsIgnoreCase(nodeName))) {
res.add(n);
}
}
return res;
}
protected List<Group> findGroups(Set<String> typeNames, String nodeName, Netlist netlist) {
List<Group> res = new ArrayList<Group>();
for (Group g : netlist.getGroups()) {
for (Node n : g.getNodes()) {
if (typeNames.contains(n.getComponent().getClass().getCanonicalName()) &&
(nodeName == null || n.getDisplayName().equalsIgnoreCase(nodeName))) {
res.add(g);
break;
}
}
}
return res;
}
protected List<Group> findGroups(Set<String> typeNames, String nodeName, Netlist netlist, Collection<IDIYComponent<?>> belongTo) {
List<Group> res = new ArrayList<Group>();
for (Group g : netlist.getGroups()) {
for (Node n : g.getNodes()) {
if ((belongTo == null || belongTo.contains(n.getComponent())) &&
(typeNames.contains(n.getComponent().getClass().getCanonicalName())) &&
(nodeName == null || n.getDisplayName().equalsIgnoreCase(nodeName))) {
res.add(g);
break;
}
}
}
return res;
}
protected List<Node> find(Set<String> typeNames, String nodeName, Netlist netlist) {
List<Node> res = new ArrayList<Node>();
for (Group g : netlist.getGroups()) {
for (Node n : g.getNodes()) {
if (typeNames.contains(n.getComponent().getClass().getCanonicalName()) &&
(nodeName == null || n.getDisplayName().equalsIgnoreCase(nodeName))) {
res.add(n);
}
}
}
return res;
}
protected List<Node> find(Set<String> typeNames, String nodeName, Netlist netlist, List<Node> inGroupWith) {
List<Node> res = new ArrayList<Node>();
for (Group g : netlist.getGroups()) {
boolean inGroup;
if (inGroupWith == null) {
inGroup = true;
} else {
inGroup = true;
for (Node n1 : inGroupWith)
if (!g.getNodes().contains(n1)) {
inGroup = false;
break;
}
}
for (Node n : g.getNodes()) {
if (inGroup && typeNames.contains(n.getComponent().getClass().getCanonicalName()) &&
(nodeName == null || n.getDisplayName().equalsIgnoreCase(nodeName))) {
res.add(n);
}
}
}
return res;
}
protected List<Node> find(Set<String> typeNames, String nodeName, Netlist netlist, Collection<IDIYComponent<?>> belongTo) {
List<Node> res = new ArrayList<Node>();
for (Group g : netlist.getGroups()) {
for (Node n : g.getNodes()) {
if ((belongTo == null || belongTo.contains(n.getComponent())) && typeNames.contains(n.getComponent().getClass().getCanonicalName()) &&
(nodeName == null || n.getDisplayName().equalsIgnoreCase(nodeName))) {
res.add(n);
}
}
}
return res;
}
protected boolean allMatch(Collection<Node> nodes, String name) {
for (Node n : nodes)
if (!n.getDisplayName().equalsIgnoreCase(name))
return false;
return true;
}
protected boolean allComponentsMatch(Collection<Node> nodes, Set<IDIYComponent<?>> components) {
Set<IDIYComponent<?>> extracted = extractComponents(nodes);
return extracted.containsAll(components);
}
protected Set<IDIYComponent<?>> extractComponents(Collection<Node> nodes) {
Set<IDIYComponent<?>> components = new HashSet<IDIYComponent<?>>();
for (Node n : nodes)
components.add(n.getComponent());
return components;
}
protected String extractName(IDIYComponent<?> c) {
return c.getName() + " " + c.getValueForDisplay();
}
protected List<String> extractNames(Collection<IDIYComponent<?>> components) {
List<String> names = new ArrayList<String>();
for (IDIYComponent<?> c : components)
names.add(c.getName() + " " + c.getValueForDisplay());
Collections.sort(names);
return names;
}
protected Netlist simplify(Netlist netlist, Set<Node> nodesToMerge, Collection<Node> nodesToPurge) {
Netlist res = new Netlist();
res.getSwitchSetup().addAll(netlist.getSwitchSetup());
Group merged = new Group();
// merge
for (Group g : netlist.getGroups()) {
boolean needsMerging = false;
for (Node n : nodesToMerge) {
if (g.getNodes().contains(n)) {
needsMerging = true;
break;
}
}
if (needsMerging) {
for (Node n : g.getNodes()) {
if (!nodesToMerge.contains(n))
merged.getNodes().add(n);
}
} else {
res.getGroups().add(g.clone());
}
}
if (!merged.getNodes().isEmpty())
res.getGroups().add(merged);
// purge
for (Group g : res.getGroups()) {
g.getNodes().removeAll(nodesToPurge);
}
System.out.println("Before:\n" + netlist);
System.out.println("After:\n" + res);
return res;
}
protected boolean intersect(List<Group> groups, Node node) {
for (Group g : groups)
if (g.getNodes().contains(node))
return true;
return false;
}
protected Node intersect(List<Group> groups, Group group) {
for (Group g : groups)
for (Node node : group.getNodes())
if (g.getNodes().contains(node))
return node;
return null;
}
}
@@ -1,186 +0,0 @@
/*
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.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.diylc.core.IDIYComponent;
public abstract class AbstractNetlistSummarizer {
public AbstractNetlistSummarizer() {
}
protected List<Group> trace(Set<String> typeNames, String nodeName, Netlist netlist) {
List<Group> res = new ArrayList<Group>();
for (Group g : netlist.getGroups()) {
for (Node n : g.getNodes()) {
if (typeNames.contains(n.getComponent().getClass().getCanonicalName()) &&
(nodeName == null || n.getDisplayName().equalsIgnoreCase(nodeName))) {
res.add(g);
break;
}
}
}
return res;
}
protected List<Node> find(Set<String> typeNames, String nodeName, Netlist netlist) {
List<Node> res = new ArrayList<Node>();
for (Group g : netlist.getGroups()) {
for (Node n : g.getNodes()) {
if (typeNames.contains(n.getComponent().getClass().getCanonicalName()) &&
(nodeName == null || n.getDisplayName().equalsIgnoreCase(nodeName))) {
res.add(n);
}
}
}
return res;
}
protected List<Node> find(Set<String> typeNames, String nodeName, Netlist netlist, List<Node> inGroupWith) {
List<Node> res = new ArrayList<Node>();
for (Group g : netlist.getGroups()) {
boolean inGroup;
if (inGroupWith == null) {
inGroup = true;
} else {
inGroup = true;
for (Node n1 : inGroupWith)
if (!g.getNodes().contains(n1)) {
inGroup = false;
break;
}
}
for (Node n : g.getNodes()) {
if (inGroup && typeNames.contains(n.getComponent().getClass().getCanonicalName()) &&
(nodeName == null || n.getDisplayName().equalsIgnoreCase(nodeName))) {
res.add(n);
}
}
}
return res;
}
protected List<Node> find(Set<String> typeNames, String nodeName, Netlist netlist, Collection<IDIYComponent<?>> belongTo) {
List<Node> res = new ArrayList<Node>();
for (Group g : netlist.getGroups()) {
for (Node n : g.getNodes()) {
if ((belongTo == null || belongTo.contains(n.getComponent())) && typeNames.contains(n.getComponent().getClass().getCanonicalName()) &&
(nodeName == null || n.getDisplayName().equalsIgnoreCase(nodeName))) {
res.add(n);
}
}
}
return res;
}
protected boolean allMatch(Collection<Node> nodes, String name) {
for (Node n : nodes)
if (!n.getDisplayName().equalsIgnoreCase(name))
return false;
return true;
}
protected boolean allComponentsMatch(Collection<Node> nodes, Set<IDIYComponent<?>> components) {
Set<IDIYComponent<?>> extracted = extractComponents(nodes);
return extracted.containsAll(components);
}
protected Set<IDIYComponent<?>> extractComponents(Collection<Node> nodes) {
Set<IDIYComponent<?>> components = new HashSet<IDIYComponent<?>>();
for (Node n : nodes)
components.add(n.getComponent());
return components;
}
protected List<String> extractNames(Collection<IDIYComponent<?>> components) {
List<String> names = new ArrayList<String>();
for (IDIYComponent<?> c : components)
names.add(c.getName() + " " + c.getValueForDisplay());
Collections.sort(names);
return names;
}
protected Netlist simplify(Netlist netlist, Set<Node> nodesToMerge, Collection<Node> nodesToPurge) {
Netlist res = new Netlist();
res.getSwitchSetup().addAll(netlist.getSwitchSetup());
Group merged = new Group();
// merge
for (Group g : netlist.getGroups()) {
boolean needsMerging = false;
for (Node n : nodesToMerge) {
if (g.getNodes().contains(n)) {
needsMerging = true;
break;
}
}
if (needsMerging) {
for (Node n : g.getNodes()) {
if (!nodesToMerge.contains(n))
merged.getNodes().add(n);
}
} else {
res.getGroups().add(g.clone());
}
}
if (!merged.getNodes().isEmpty())
res.getGroups().add(merged);
// purge
for (Group g : res.getGroups()) {
g.getNodes().removeAll(nodesToPurge);
}
System.out.println("Before:\n" + netlist);
System.out.println("After:\n" + res);
return res;
}
protected boolean intersect(List<Group> groups, Node node) {
for (Group g : groups)
if (g.getNodes().contains(node))
return true;
return false;
}
protected Node intersect(List<Group> groups, Group group) {
for (Group g : groups)
for (Node node : group.getNodes())
if (g.getNodes().contains(node))
return node;
return null;
}
}
@@ -0,0 +1,170 @@
/*
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.HashSet;
import java.util.List;
import java.util.Set;
import org.diylc.common.INetlistAnalyzer;
import org.diylc.components.electromechanical.ClosedJack1_4;
import org.diylc.components.electromechanical.OpenJack1_4;
import org.diylc.components.guitar.HumbuckerPickup;
import org.diylc.components.guitar.JazzBassPickup;
import org.diylc.components.guitar.P90Pickup;
import org.diylc.components.guitar.PBassPickup;
import org.diylc.components.guitar.SingleCoilPickup;
import org.diylc.components.passive.PotentiometerPanel;
import org.diylc.core.IDIYComponent;
public class GuitarDiagramAnalyzer extends AbstractNetlistAnalyzer implements INetlistAnalyzer {
private static Set<String> JACK_TYPES = new HashSet<String>();
private static Set<String> POT_TYPES = new HashSet<String>();
private static Set<String> PICKUP_TYPES = new HashSet<String>();
static {
JACK_TYPES.add(OpenJack1_4.class.getCanonicalName());
JACK_TYPES.add(ClosedJack1_4.class.getCanonicalName());
POT_TYPES.add(PotentiometerPanel.class.getCanonicalName());
PICKUP_TYPES.add(SingleCoilPickup.class.getCanonicalName());
PICKUP_TYPES.add(HumbuckerPickup.class.getCanonicalName());
PICKUP_TYPES.add(P90Pickup.class.getCanonicalName());
PICKUP_TYPES.add(JazzBassPickup.class.getCanonicalName());
PICKUP_TYPES.add(PBassPickup.class.getCanonicalName());
}
@Override
public String getName() {
return "Guitar Diagrams";
}
@Override
public String getIconName() {
return "Guitar";
}
public List<Summary> summarize(List<Netlist> netlists, Node preferredOutput) {
List<Summary> summaries = new ArrayList<Summary>();
for (Netlist n : netlists)
summaries.add(summarize(n, preferredOutput));
return summaries;
}
private Summary summarize(Netlist netlist, Node preferredOutput) {
List<String> notes = new ArrayList<String>();
List<Group> jackTipGroups = findGroups(JACK_TYPES, "Tip", netlist);
List<Group> jackSleeveGroups = findGroups(JACK_TYPES, "Sleeve", netlist);
// if (jackTipGroups.size() == 0 || jackSleeveGroups.size() == 0) {
// notes.add("Could not find anything connected to a jack tip terminal.");
// } else if (jackTipGroups.size() > 1 || jackSleeveGroups.size() > 1) {
// notes.add("Multiple jacks found, could not proceed.");
// } else {
// Group jackTipGroup = jackTipGroups.get(0);
// Group jackSleeveGroup = jackSleeveGroups.get(0);
// netlist = findAndEliminatePots(netlist, jackTipGroup, jackSleeveGroup, notes);
// // find jack tip group again after eliminating pots, it should be connecter straight to the pickups
// jackTipGroups = findGroups(JACK_TYPES, "Tip", netlist);
// if (jackTipGroups.size() == 1) {
// jackTipGroup = jackTipGroups.get(0);
// List<Node> pickupTipNodes = find(PICKUP_TYPES, null, jackTipGroup);
// List<Node> pickupSleeveNodes = find(PICKUP_TYPES, null, jackSleeveGroup);
// notes.add("test");
// }
// }
try {
return new Summary(netlist, notes, constructTree(netlist));
} catch (TreeException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return null;
}
}
private Netlist findAndEliminatePots(Netlist netlist, Group jackTipGroup, Group jackSleeveGroup, List<String> notes) {
// try to find any pots that have connections to jack tip or sleeve
List<Node> potTipNodes = find(POT_TYPES, null, jackTipGroup);
List<Node> potSleeveNodes = find(POT_TYPES, null, jackSleeveGroup);
if (!potTipNodes.isEmpty() && !potSleeveNodes.isEmpty()) {
Set<IDIYComponent<?>> pots = extractComponents(potTipNodes);
List<Node> potInputNodes = find(POT_TYPES, "1", netlist, pots);
// List<Group> potInputGroups = findGroups(POT_TYPES, "1", netlist, pots);
// if (allMatch(potTipNodes, "2") && allMatch(potSleeveNodes, "3")) {
//
// for (Group g : potInputGroups) {
// List<Node> potNodes = find(POT_TYPES, null, g);
// List<Node> pickupNodes = find(PICKUP_TYPES, null, g);
// if (potNodes.size() != 1) {
// notes.add("Detected control potentiometer wiring issue.");
// } else {
// StringBuilder sb = new StringBuilder("Detected volume potentiometer [");
// sb.append(extractName(potNodes.get(0).getComponent())).append("] controlling: ");
// Set<String> pickups = new HashSet<String>();
// for (Node n : pickupNodes) {
// pickups.add(n.getComponent().getName());
// }
// List<String> pickupList = new ArrayList<String>(pickups);
// Collections.sort(pickupList);
// sb.append(pickupList.toString());
// notes.add(sb.toString());
// }
// }
// List<String> potNames = extractNames(pots);
// notes.add("Detected volume control(s): " + potNames);
Set<Node> toMerge = new HashSet<Node>(potTipNodes);
toMerge.addAll(potInputNodes);
return simplify(netlist, toMerge, potSleeveNodes);
// } else {
// notes.add("Detected incorrectly wired volume control(s).");
// return netlist;
// }
}
// notes.add("No volume controls detected.");
return netlist;
}
@Override
public Tree constructTree(Netlist netlist) throws TreeException {
List<Node> jackTipNodes = find(JACK_TYPES, "Tip", netlist);
List<Node> jackSleeveNodes = find(JACK_TYPES, "Sleeve", netlist);
if (jackTipNodes.size() == 0 || jackSleeveNodes.size() == 0) {
throw new TreeException("Could not find anything connected to a jack tip terminal.");
} else if (jackTipNodes.size() > 1 || jackSleeveNodes.size() > 1) {
throw new TreeException("Multiple jacks found, could not proceed.");
} else {
Node jackTip = jackTipNodes.get(0);
Node jackSleeve = jackSleeveNodes.get(0);
return constructTree(netlist, jackTip, jackSleeve);
}
}
}
@@ -1,109 +0,0 @@
/*
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.HashSet;
import java.util.List;
import java.util.Set;
import org.diylc.common.INetlistSummarizer;
import org.diylc.components.electromechanical.ClosedJack1_4;
import org.diylc.components.electromechanical.OpenJack1_4;
import org.diylc.components.guitar.HumbuckerPickup;
import org.diylc.components.guitar.JazzBassPickup;
import org.diylc.components.guitar.P90Pickup;
import org.diylc.components.guitar.PBassPickup;
import org.diylc.components.guitar.SingleCoilPickup;
import org.diylc.components.passive.PotentiometerPanel;
import org.diylc.core.IDIYComponent;
public class GuitarDiagramSummarizer extends AbstractNetlistSummarizer implements INetlistSummarizer {
private static Set<String> JACK_TYPES = new HashSet<String>();
private static Set<String> POT_TYPES = new HashSet<String>();
private static Set<String> PICKUP_TYPES = new HashSet<String>();
static {
JACK_TYPES.add(OpenJack1_4.class.getCanonicalName());
JACK_TYPES.add(ClosedJack1_4.class.getCanonicalName());
POT_TYPES.add(PotentiometerPanel.class.getCanonicalName());
PICKUP_TYPES.add(SingleCoilPickup.class.getCanonicalName());
PICKUP_TYPES.add(HumbuckerPickup.class.getCanonicalName());
PICKUP_TYPES.add(P90Pickup.class.getCanonicalName());
PICKUP_TYPES.add(JazzBassPickup.class.getCanonicalName());
PICKUP_TYPES.add(PBassPickup.class.getCanonicalName());
}
@Override
public String getName() {
return "Guitar Diagrams";
}
@Override
public String getIconName() {
return "Guitar";
}
public List<Summary> summarize(List<Netlist> netlists, Node preferredOutput) {
List<Summary> summaries = new ArrayList<Summary>();
for (Netlist n : netlists)
summaries.add(summarize(n, preferredOutput));
return summaries;
}
private Summary summarize(Netlist netlist, Node preferredOutput) {
List<String> notes = new ArrayList<String>();
List<Node> jackTipNodes = find(JACK_TYPES, "Tip", netlist);
List<Node> jackSleeveNodes = find(JACK_TYPES, "Sleeve", netlist);
netlist = findAndEliminateVolumeControls(netlist, jackTipNodes, jackSleeveNodes, notes);
return new Summary(netlist, notes);
}
private Netlist findAndEliminateVolumeControls(Netlist netlist, List<Node> jackTipGroups, List<Node> jackSleeveGroups, List<String> notes) {
List<Node> potTipNodes = find(POT_TYPES, null, netlist, jackTipGroups);
List<Node> potSleeveNodes = find(POT_TYPES, null, netlist, jackSleeveGroups);
if (!potTipNodes.isEmpty() && !potSleeveNodes.isEmpty()) {
Set<IDIYComponent<?>> pots = extractComponents(potTipNodes);
List<Node> potInputNodes = find(POT_TYPES, "1", netlist, pots);
if (allMatch(potTipNodes, "2") && allMatch(potSleeveNodes, "3") && allComponentsMatch(potInputNodes, pots)) {
List<String> potNames = extractNames(pots);
notes.add("Detected volume control(s): " + potNames);
Set<Node> toMerge = new HashSet<Node>(potTipNodes);
toMerge.addAll(potInputNodes);
return simplify(netlist, toMerge, potSleeveNodes);
} else {
notes.add("Detected incorrectly wired volume control(s).");
return netlist;
}
}
notes.add("No volume controls detected.");
return netlist;
}
}
Binary file not shown.
Binary file not shown.
@@ -49,7 +49,7 @@ import org.diylc.appframework.miscutils.ConfigurationManager;
import org.diylc.common.BuildingBlockPackage;
import org.diylc.common.ComponentType;
import org.diylc.common.IComponentTransformer;
import org.diylc.common.INetlistSummarizer;
import org.diylc.common.INetlistAnalyzer;
import org.diylc.common.IPlugInPort;
import org.diylc.common.ITask;
import org.diylc.common.PropertyWrapper;
@@ -258,7 +258,7 @@ public class ActionFactory {
return new GenerateNetlistAction(plugInPort, swingUI);
}
public SummarizeNetlistAction createSummarizeNetlistAction(IPlugInPort plugInPort, ISwingUI swingUI, INetlistSummarizer summarizer) {
public SummarizeNetlistAction createSummarizeNetlistAction(IPlugInPort plugInPort, ISwingUI swingUI, INetlistAnalyzer summarizer) {
return new SummarizeNetlistAction(plugInPort, swingUI, summarizer);
}
@@ -1688,9 +1688,9 @@ public class ActionFactory {
private IPlugInPort plugInPort;
private ISwingUI swingUI;
private INetlistSummarizer summarizer;
private INetlistAnalyzer summarizer;
public SummarizeNetlistAction(IPlugInPort plugInPort, ISwingUI swingUI, INetlistSummarizer summarizer) {
public SummarizeNetlistAction(IPlugInPort plugInPort, ISwingUI swingUI, INetlistAnalyzer summarizer) {
super();
this.plugInPort = plugInPort;
this.swingUI = swingUI;
@@ -1716,6 +1716,8 @@ public class ActionFactory {
for (Summary summary : res) {
sb.append("<p style=\"font-family: " + new JLabel().getFont().getName() + "; font-size: 9px\"><b>Switch configuration: ").append(summary.getNetlist().getSwitchSetup()).append("</b><br><br>");
sb.append("Parallel/Series connectivity tree:<br><br>").append(summary.getTree().toHTML(0));
for (String v : summary.getNotes()) {
sb.append("&nbsp;&nbsp;").append(v).append("<br>");
}
@@ -29,7 +29,7 @@ import java.util.List;
import org.apache.log4j.Logger;
import org.diylc.appframework.miscutils.ConfigurationManager;
import org.diylc.common.EventType;
import org.diylc.common.INetlistSummarizer;
import org.diylc.common.INetlistAnalyzer;
import org.diylc.common.IPlugIn;
import org.diylc.common.IPlugInPort;
import org.diylc.images.IconLoader;
@@ -91,9 +91,9 @@ public class FileMenuPlugin implements IPlugIn, IDynamicSubmenuHandler {
swingUI.injectMenuAction(actionFactory.createBomAction(plugInPort), ANALYZE_TITLE);
swingUI.injectMenuAction(actionFactory.createGenerateNetlistAction(plugInPort, swingUI), ANALYZE_TITLE);
List<INetlistSummarizer> summarizers = plugInPort.getNetlistSummarizers();
List<INetlistAnalyzer> summarizers = plugInPort.getNetlistAnalyzers();
if (summarizers != null) {
for(INetlistSummarizer summarizer : summarizers)
for(INetlistAnalyzer summarizer : summarizers)
swingUI.injectMenuAction(actionFactory.createSummarizeNetlistAction(plugInPort, swingUI, summarizer), ANALYZE_TITLE);
}