diff --git a/diylc/diylc-core/src/org/diylc/netlist/NetlistAnalyzer.java b/diylc/diylc-core/src/org/diylc/netlist/NetlistAnalyzer.java index b8bba904..183ac549 100644 --- a/diylc/diylc-core/src/org/diylc/netlist/NetlistAnalyzer.java +++ b/diylc/diylc-core/src/org/diylc/netlist/NetlistAnalyzer.java @@ -18,7 +18,6 @@ package org.diylc.netlist; import java.util.ArrayList; -import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; @@ -28,9 +27,26 @@ import java.util.Set; import org.diylc.core.IDIYComponent; -public class NetlistAnalyzer { +public abstract class NetlistAnalyzer { public NetlistAnalyzer() {} + + public List summarize(List netlists, Node preferredOutput) throws TreeException { + Map summaries = new HashMap(); + for (Netlist n : netlists) { + Summary s = summarize(n, preferredOutput); + if (summaries.containsKey(s.getSummary())) + summaries.get(s.getSummary()).append(n); + else + summaries.put(s.getSummary(), s); + } + + List res = new ArrayList(summaries.values()); + Collections.sort(res); + return res; + } + + protected abstract Summary summarize(Netlist netlist, Node preferredOutput) throws TreeException; public Tree constructTreeBetween(Netlist netlist, Node nodeA, Node nodeB) { Tree tree = new Tree(TreeConnectionType.Parallel); @@ -199,45 +215,45 @@ public class NetlistAnalyzer { paths.addAll(unmerged); } } - - protected void findAllPaths(Netlist netlist, Node nodeA, Node nodeB, List currentPath, - List> allPaths, Set 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 newCurrentPath = new ArrayList(currentPath); - if (!currentPath.contains(l)) - newCurrentPath.add(l); - Set newVisited = new HashSet(visited); - newVisited.add(nodeA); - newVisited.add(newNodeA); - findAllPaths(netlist, newNodeA, nodeB, newCurrentPath, allPaths, newVisited); - } - } - } - } - } +// +// protected void findAllPaths(Netlist netlist, Node nodeA, Node nodeB, List currentPath, +// List> allPaths, Set 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 newCurrentPath = new ArrayList(currentPath); +// if (!currentPath.contains(l)) +// newCurrentPath.add(l); +// Set newVisited = new HashSet(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()) @@ -246,62 +262,62 @@ public class NetlistAnalyzer { return null; } - protected List trace(Set typeNames, String nodeName, Netlist netlist) { - List res = new ArrayList(); - 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 trace(Set typeNames, String nodeName, Netlist netlist) { +// List res = new ArrayList(); +// 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 find(Set typeNames, String nodeName, Group group) { - List res = new ArrayList(); +// protected List find(Set typeNames, String nodeName, Group group) { +// List res = new ArrayList(); +// +// for (Node n : group.getNodes()) { +// if (typeNames.contains(n.getComponent().getClass().getCanonicalName()) +// && (nodeName == null || n.getDisplayName().equalsIgnoreCase(nodeName))) { +// res.add(n); +// } +// } +// +// return res; +// } - for (Node n : group.getNodes()) { - if (typeNames.contains(n.getComponent().getClass().getCanonicalName()) - && (nodeName == null || n.getDisplayName().equalsIgnoreCase(nodeName))) { - res.add(n); - } - } +// protected List findGroups(Set typeNames, String nodeName, Netlist netlist) { +// List res = new ArrayList(); +// 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; +// } - return res; - } - - protected List findGroups(Set typeNames, String nodeName, Netlist netlist) { - List res = new ArrayList(); - 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 findGroups(Set typeNames, String nodeName, Netlist netlist, - Collection> belongTo) { - List res = new ArrayList(); - 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 findGroups(Set typeNames, String nodeName, Netlist netlist, +// Collection> belongTo) { +// List res = new ArrayList(); +// 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 find(Set typeNames, String nodeName, Netlist netlist) { List res = new ArrayList(); @@ -316,67 +332,67 @@ public class NetlistAnalyzer { return res; } - protected List find(Set typeNames, String nodeName, Netlist netlist, List inGroupWith) { - List res = new ArrayList(); - for (Group g : netlist.getGroups()) { +// protected List find(Set typeNames, String nodeName, Netlist netlist, List inGroupWith) { +// List res = new ArrayList(); +// 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; +// } - boolean inGroup; - if (inGroupWith == null) { - inGroup = true; - } else { - inGroup = true; - for (Node n1 : inGroupWith) - if (!g.getNodes().contains(n1)) { - inGroup = false; - break; - } - } +// protected List find(Set typeNames, String nodeName, Netlist netlist, +// Collection> belongTo) { +// List res = new ArrayList(); +// 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; +// } - 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 boolean allMatch(Collection nodes, String name) { +// for (Node n : nodes) +// if (!n.getDisplayName().equalsIgnoreCase(name)) +// return false; +// +// return true; +// } - protected List find(Set typeNames, String nodeName, Netlist netlist, - Collection> belongTo) { - List res = new ArrayList(); - 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 nodes, String name) { - for (Node n : nodes) - if (!n.getDisplayName().equalsIgnoreCase(name)) - return false; - - return true; - } - - protected boolean allComponentsMatch(Collection nodes, Set> components) { - Set> extracted = extractComponents(nodes); - return extracted.containsAll(components); - } - - protected Set> extractComponents(Collection nodes) { - Set> components = new HashSet>(); - for (Node n : nodes) - components.add(n.getComponent()); - return components; - } +// protected boolean allComponentsMatch(Collection nodes, Set> components) { +// Set> extracted = extractComponents(nodes); +// return extracted.containsAll(components); +// } +// +// protected Set> extractComponents(Collection nodes) { +// Set> components = new HashSet>(); +// for (Node n : nodes) +// components.add(n.getComponent()); +// return components; +// } protected String extractName(IDIYComponent c) { return c.getName() + " " + c.getValueForDisplay(); @@ -397,53 +413,53 @@ public class NetlistAnalyzer { return -1; } - protected List extractNames(Collection> components) { - List names = new ArrayList(); - for (IDIYComponent c : components) - names.add(c.getName() + " " + c.getValueForDisplay()); - Collections.sort(names); - return names; - } - - protected Netlist simplify(Netlist netlist, Set nodesToMerge, Collection 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 List extractNames(Collection> components) { +// List names = new ArrayList(); +// for (IDIYComponent c : components) +// names.add(c.getName() + " " + c.getValueForDisplay()); +// Collections.sort(names); +// return names; +// } +// +// protected Netlist simplify(Netlist netlist, Set nodesToMerge, Collection 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 groups, Node node) { for (Group g : groups) if (g.getNodes().contains(node)) diff --git a/diylc/diylc-library/lib/diylc-core.jar b/diylc/diylc-library/lib/diylc-core.jar index ce73d5f2..19b852f8 100644 Binary files a/diylc/diylc-library/lib/diylc-core.jar and b/diylc/diylc-library/lib/diylc-core.jar differ diff --git a/diylc/diylc-library/src/org/diylc/netlist/GuitarDiagramAnalyzer.java b/diylc/diylc-library/src/org/diylc/netlist/GuitarDiagramAnalyzer.java index 7cc7151e..b78c42ae 100644 --- a/diylc/diylc-library/src/org/diylc/netlist/GuitarDiagramAnalyzer.java +++ b/diylc/diylc-library/src/org/diylc/netlist/GuitarDiagramAnalyzer.java @@ -22,7 +22,6 @@ package org.diylc.netlist; import java.util.ArrayList; -import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.List; @@ -84,27 +83,13 @@ public class GuitarDiagramAnalyzer extends NetlistAnalyzer implements INetlistAn public String getFontName() { return new JLabel().getFont().getName(); } - - public List summarize(List netlists, Node preferredOutput) throws TreeException { - Map summaries = new HashMap(); - for (Netlist n : netlists) { - Summary s = summarize(n, preferredOutput); - if (summaries.containsKey(s.getSummary())) - summaries.get(s.getSummary()).append(n); - else - summaries.put(s.getSummary(), s); - } - - List res = new ArrayList(summaries.values()); - Collections.sort(res); - return res; - } + private int positiveCount; private int negativeCount; private int noiseCount; - private Summary summarize(Netlist netlist, Node preferredOutput) throws TreeException { + protected Summary summarize(Netlist netlist, Node preferredOutput) throws TreeException { List notes = new ArrayList(); Tree tree = constructTree(netlist); diff --git a/diylc/diylc-library/src/org/diylc/netlist/SpiceAnalyzer.java b/diylc/diylc-library/src/org/diylc/netlist/SpiceAnalyzer.java index ee195056..dfff70c4 100644 --- a/diylc/diylc-library/src/org/diylc/netlist/SpiceAnalyzer.java +++ b/diylc/diylc-library/src/org/diylc/netlist/SpiceAnalyzer.java @@ -48,17 +48,8 @@ public class SpiceAnalyzer extends NetlistAnalyzer implements INetlistAnalyzer { public String getFontName() { return "Courier New"; } - - @Override - public List summarize(List netlists, Node preferredOutput) throws TreeException { - List summaries = new ArrayList(); - for (Netlist n : netlists) - summaries.add(summarize(n, preferredOutput)); - - return summaries; - } - private Summary summarize(Netlist netlist, Node preferredOutput) throws TreeException { + protected Summary summarize(Netlist netlist, Node preferredOutput) throws TreeException { // grab all components that are in the netlist List> allComponents = new ArrayList>(extractComponents(netlist)); Collections.sort(allComponents, new Comparator>() { diff --git a/diylc/diylc-swing/lib/diylc-core.jar b/diylc/diylc-swing/lib/diylc-core.jar index ce73d5f2..19b852f8 100644 Binary files a/diylc/diylc-swing/lib/diylc-core.jar and b/diylc/diylc-swing/lib/diylc-core.jar differ diff --git a/diylc/diylc-swing/library/main.jar b/diylc/diylc-swing/library/main.jar index 7c78c131..156db406 100644 Binary files a/diylc/diylc-swing/library/main.jar and b/diylc/diylc-swing/library/main.jar differ