diff --git a/diylc/diylc-core/src/org/diylc/netlist/Tree.java b/diylc/diylc-core/src/org/diylc/netlist/Tree.java index fad41e30..b970a7c8 100644 --- a/diylc/diylc-core/src/org/diylc/netlist/Tree.java +++ b/diylc/diylc-core/src/org/diylc/netlist/Tree.java @@ -25,6 +25,7 @@ import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.List; +import java.util.Set; public class Tree { @@ -158,6 +159,44 @@ public class Tree { protected Object clone() throws CloneNotSupportedException { if (leaf != null) return new Tree(leaf); - return new Tree(new ArrayList(children), connectionType); + List newChildren = new ArrayList(); + for (Tree t : children) + newChildren.add((Tree) t.clone()); + return new Tree(newChildren, connectionType); + } + + public Tree filter(Set types) { + if (leaf != null) { + if (types.contains(leaf.getComponent().getClass().getCanonicalName())) + return new Tree(leaf); + return null; + } + List newChildren = new ArrayList(); + for (Tree t : children) { + Tree child = t.filter(types); + if (child != null) + newChildren.add(child); + } + if (newChildren.isEmpty()) + return null; + return new Tree(newChildren, connectionType); + } + + public void walk(ITreeWalker walker) { + if (leaf != null) { + walker.visit(leaf); + } else { + for (Tree t : children) { + walker.visit(t); + t.walk(walker); + } + } + } + + public interface ITreeWalker { + + void visit(Tree t); + + void visit(TreeLeaf l); } } diff --git a/diylc/diylc-library/lib/diylc-core.jar b/diylc/diylc-library/lib/diylc-core.jar index d44183a2..56c9dec1 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 9a2cc718..0062c42d 100644 --- a/diylc/diylc-library/src/org/diylc/netlist/GuitarDiagramAnalyzer.java +++ b/diylc/diylc-library/src/org/diylc/netlist/GuitarDiagramAnalyzer.java @@ -35,6 +35,7 @@ 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.netlist.Tree.ITreeWalker; public class GuitarDiagramAnalyzer extends NetlistAnalyzer implements INetlistAnalyzer { @@ -72,13 +73,64 @@ public class GuitarDiagramAnalyzer extends NetlistAnalyzer implements INetlistAn return summaries; } + private int positiveCount; + private int negativeCount; + private int noiseCount; + private Summary summarize(Netlist netlist, Node preferredOutput) throws TreeException { List notes = new ArrayList(); Tree tree = constructTree(netlist); + Tree pickupTree = tree.filter(PICKUP_TYPES); + + if (pickupTree == null || pickupTree.getChildren().isEmpty()) { + notes.add("No pickups are detected in this switch configuration"); + } else { + positiveCount = 0; + negativeCount = 0; + noiseCount = 0; + pickupTree.walk(new ITreeWalker() { + + @Override + public void visit(Tree t) { + } + + @Override + public void visit(TreeLeaf l) { + if ((l.toString().toLowerCase().contains("north") && (l.toString().toLowerCase().contains("->"))) || + (l.toString().toLowerCase().contains("south") && (l.toString().toLowerCase().contains("<-")))) + noiseCount++; + if ((l.toString().toLowerCase().contains("north") && (l.toString().toLowerCase().contains("<-"))) || + (l.toString().toLowerCase().contains("south") && (l.toString().toLowerCase().contains("->")))) + noiseCount--; + + if (l.toString().toLowerCase().contains("->")) + positiveCount++; + if (l.toString().toLowerCase().contains("<-")) + negativeCount++; + } + }); + + boolean humCancelling = noiseCount == 0; + + if (humCancelling) + notes.add("This position is hum-cancelling"); + else + notes.add("This position is NOT hum-cancelling"); + + if (positiveCount > 1 || negativeCount > 1) { + boolean inPhase = (positiveCount == 0 && negativeCount > 0) || (positiveCount > 0 && negativeCount == 0); + if (inPhase) + notes.add("The pickups are wired in-phase"); + else + notes.add("This pickups are wired out-of-phase"); + } + } + return new Summary(netlist, notes, tree); } + @Override public Tree constructTree(Netlist netlist) throws TreeException { diff --git a/diylc/diylc-swing/lib/diylc-core.jar b/diylc/diylc-swing/lib/diylc-core.jar index d44183a2..56c9dec1 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 e7d2c9ba..9ef5922d 100644 Binary files a/diylc/diylc-swing/library/main.jar and b/diylc/diylc-swing/library/main.jar differ diff --git a/diylc/diylc-swing/src/org/diylc/swing/ActionFactory.java b/diylc/diylc-swing/src/org/diylc/swing/ActionFactory.java index bb98f0bd..e6177c6e 100644 --- a/diylc/diylc-swing/src/org/diylc/swing/ActionFactory.java +++ b/diylc/diylc-swing/src/org/diylc/swing/ActionFactory.java @@ -1725,6 +1725,8 @@ public class ActionFactory { sb.append("

Switch configuration: ").append(summary.getNetlist().getSwitchSetup()).append("

"); sb.append("Parallel/Series connectivity tree:

").append(summary.getTree().toHTML(0)); + if (!summary.getNotes().isEmpty()) + sb.append("

Notes:
"); for (String v : summary.getNotes()) { sb.append("  ").append(v).append("
"); } diff --git a/diylc/diylc-swing/update.xml b/diylc/diylc-swing/update.xml index c9cdfca5..1bf0eea8 100644 --- a/diylc/diylc-swing/update.xml +++ b/diylc/diylc-swing/update.xml @@ -2526,6 +2526,10 @@ NEW_FEATURE Added 4-position Tele switch type to the "Lever Switch" component + + NEW_FEATURE + "Analyze Guitar Wiring" can figure out if wiring is hum-cancelling and in or out of phase for each position + IMPROVEMENT Increase the range of zoom slider for images to 500%