diff --git a/diylc/diylc-core/src/org/diylc/netlist/Tree.java b/diylc/diylc-core/src/org/diylc/netlist/Tree.java index e10fd484..e99b36d2 100644 --- a/diylc/diylc-core/src/org/diylc/netlist/Tree.java +++ b/diylc/diylc-core/src/org/diylc/netlist/Tree.java @@ -227,6 +227,11 @@ public class Tree { } public Tree findCommonParent(Tree t1, Tree t2) { + if (t1 == null) + return t2; + if (t2 == null) + return t1; + if (children == null) return null; @@ -248,6 +253,25 @@ public class Tree { return p1.findCommonParent(t1, t2); } + public Tree findCommonParent(List t) { + if (t.contains(null)) + { + while(t.contains(null)) + t.remove(null); + return findCommonParent(t); + } + + if (t.size() == 0) + return null; + if (t.size() == 1) + return t.get(0); + if (t.size() == 2) + return findCommonParent(t.get(0), t.get(1)); + + List remainder = t.subList(1, t.size()); + return findCommonParent(t.get(0), findCommonParent(remainder)); + } + public boolean contains(Tree t) { if (this == t) return true; diff --git a/diylc/diylc-core/src/org/diylc/presenter/Presenter.java b/diylc/diylc-core/src/org/diylc/presenter/Presenter.java index e5150a4c..5c5ee046 100644 --- a/diylc/diylc-core/src/org/diylc/presenter/Presenter.java +++ b/diylc/diylc-core/src/org/diylc/presenter/Presenter.java @@ -2755,7 +2755,7 @@ public class Presenter implements IPlugInPort { List connections = getConnections(switchPositions); Netlist graph = constructNetlist(nodes, connections, continuity); - // merge graphs that are effectivelly the same + // merge graphs that are effectively the same if (result.containsKey(graph)) { result.get(graph).getSwitchSetup().add(new SwitchSetup(posList)); } else { @@ -2827,6 +2827,29 @@ public class Presenter implements IPlugInPort { } } + // merge overlapping groups if needed + boolean reduce = true; + while (reduce) { + reduce = false; + List groups = netlist.getSortedGroups(); + Iterator i = groups.iterator(); + while (i.hasNext()) { + Group g1 = i.next(); + for (Group g2 : groups) { + if (g1 != g2 && !Collections.disjoint(g1.getNodes(), g2.getNodes())) { + i.remove(); + g2.getNodes().addAll(g1.getNodes()); + reduce = true; + break; + } + } + } + if (reduce) { + netlist.getGroups().clear(); + netlist.getGroups().addAll(groups); + } + } + Collections.sort(netlist.getSwitchSetup()); return netlist; diff --git a/diylc/diylc-library/lib/diylc-core.jar b/diylc/diylc-library/lib/diylc-core.jar index 7cf26f21..ad329e17 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/components/guitar/AbstractGuitarPickup.java b/diylc/diylc-library/src/org/diylc/components/guitar/AbstractGuitarPickup.java index 3bdbfa98..2d2bc123 100644 --- a/diylc/diylc-library/src/org/diylc/components/guitar/AbstractGuitarPickup.java +++ b/diylc/diylc-library/src/org/diylc/components/guitar/AbstractGuitarPickup.java @@ -120,7 +120,7 @@ public abstract class AbstractGuitarPickup extends AbstractTransparentComponent< } g2d.translate(0, getMainLabelYOffset()); - drawCenteredText(g2d, value, 0, 0, HorizontalAlignment.CENTER, VerticalAlignment.CENTER); + drawCenteredText(g2d, getName(), 0, 0, HorizontalAlignment.CENTER, VerticalAlignment.CENTER); g2d.setTransform(originalTx); } diff --git a/diylc/diylc-library/src/org/diylc/components/guitar/LeverSwitch.java b/diylc/diylc-library/src/org/diylc/components/guitar/LeverSwitch.java index 5ba9d7d0..7d09e05a 100644 --- a/diylc/diylc-library/src/org/diylc/components/guitar/LeverSwitch.java +++ b/diylc/diylc-library/src/org/diylc/components/guitar/LeverSwitch.java @@ -238,8 +238,8 @@ public class LeverSwitch extends AbstractTransparentComponent implements // Rotate if needed if (theta != 0) { AffineTransform rotation = AffineTransform.getRotateInstance(theta, x, y); - // Skip the last one because it's already rotated - for (int i = 0; i < body.length - 1; i++) { + // Skip the last two because terminals are already rotated + for (int i = 0; i < body.length - 2; i++) { Shape shape = body[i]; Area area = (Area) shape; area.transform(rotation); @@ -460,14 +460,14 @@ public class LeverSwitch extends AbstractTransparentComponent implements public boolean arePointsConnected(int index1, int index2, int position) { switch (type) { case DP3T: - return (index2 == 6 || index1 == 1) && index2 == index1 + 2 * (position + 1); + return (index1 == 1 && index2 == index1 + 2 * (position + 1)) || (index2 == 6 && index2 == index1 + 2 * (3 - position)); case DP4T: - return (index2 == 8 || index1 == 1) && index2 == index1 + 2 * (position + 1); + return (index1 == 1 && index2 == index1 + 2 * (position + 1)) || (index2 == 8 && index2 == index1 + 2 * (3 - position)); case DP3T_5pos: if (position % 2 == 0) - return (index2 == 6 || index1 == 1) && index2 == index1 + position + 2; + return (index1 == 1 && index2 == index1 + position + 2) || (index2 == 6 && index2 == index1 + 6 - position); else - return (index2 == 6 && (index1 == 2 || (index1 == 4 && position == 1) || (index1 == 0 && position == 3))) || + return (index2 == 6 && (index1 == 2 || (index1 == 0 && position == 1) || (index1 == 4 && position == 3))) || (index1 == 1 && (index2 == 5 || (index2 == 3 && position == 1) || (index2 == 7 && position == 3))); case DP5T: return (index1 == 0 || index2 == 11) && index2 - index1 == position + 1; diff --git a/diylc/diylc-library/src/org/diylc/netlist/GuitarDiagramAnalyzer.java b/diylc/diylc-library/src/org/diylc/netlist/GuitarDiagramAnalyzer.java index 83cf1d3f..e435f4ce 100644 --- a/diylc/diylc-library/src/org/diylc/netlist/GuitarDiagramAnalyzer.java +++ b/diylc/diylc-library/src/org/diylc/netlist/GuitarDiagramAnalyzer.java @@ -22,8 +22,10 @@ package org.diylc.netlist; import java.util.ArrayList; +import java.util.HashMap; import java.util.HashSet; import java.util.List; +import java.util.Map; import java.util.Set; import org.diylc.common.INetlistAnalyzer; @@ -92,6 +94,8 @@ public class GuitarDiagramAnalyzer extends NetlistAnalyzer implements INetlistAn positiveCount = 0; negativeCount = 0; noiseCount = 0; + + // analyze hum-cancellation and phase pickupTree.walk(new ITreeWalker() { @Override @@ -115,6 +119,9 @@ public class GuitarDiagramAnalyzer extends NetlistAnalyzer implements INetlistAn }); Set> pickups = tree.extractComponents(PICKUP_TYPES); + Map, Tree> pickupRoots = new HashMap, Tree>(); + + // analyze each pickup separately to see how each coil is wired for (IDIYComponent c : pickups) { if (c instanceof AbstractGuitarPickup) { AbstractGuitarPickup pickup = (AbstractGuitarPickup)c; @@ -124,14 +131,39 @@ public class GuitarDiagramAnalyzer extends NetlistAnalyzer implements INetlistAn Tree nTree = tree.locate(nLeaf, false); Tree sTree = tree.locate(sLeaf, false); Tree parent = tree.findCommonParent(nTree, sTree); + if (parent != null) + pickupRoots.put(pickup, parent); if (nTree != null && sTree != null && parent != null) { - notes.add(pickup.getName() + " pickup engaged in humbucking mode with coils wired in " + parent.getConnectionType().name().toLowerCase()); + notes.add("'" + pickup.getName() + "' pickup wired in humbucking mode with " + parent.getConnectionType().name().toLowerCase() + " coils"); } else if ((nTree == null && sTree != null) || (nTree != null && sTree == null)) { - notes.add(pickup.getName() + " pickup engaged in coil-split mode"); + notes.add("'" + pickup.getName() + "' pickup wired in coil-split mode"); } + } else { + TreeLeaf leaf = new TreeLeaf(pickup, 1, 2); + Tree t = tree.locate(leaf, false); + if (t != null) + pickupRoots.put(pickup, t); } } } + + // figure out how pickups are wired between them + if (pickupRoots.size() > 1) { + Tree root = tree.findCommonParent(new ArrayList(pickupRoots.values())); + StringBuilder sb = new StringBuilder(); + boolean first = true; + for (IDIYComponent c : pickupRoots.keySet()) { + if (!first) + sb.append(pickupRoots.size() == 2 ? " and " : ", "); + first = false; + sb.append("'").append(c.getName()).append("'"); + } + sb.append(" pickups engaged, wired in " ).append(root.getConnectionType().name().toLowerCase()); + notes.add(sb.toString()); + } else if (pickupRoots.size() == 1) { + AbstractGuitarPickup pickup = (AbstractGuitarPickup) pickupRoots.keySet().iterator().next(); + notes.add("'" + pickup.getName() + "' is the only engaged pickup"); + } boolean humCancelling = noiseCount == 0; @@ -143,9 +175,9 @@ public class GuitarDiagramAnalyzer extends NetlistAnalyzer implements INetlistAn 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"); + notes.add("Pickup coils are wired in-phase"); else - notes.add("This pickups are wired out-of-phase"); + notes.add("Pickup coils are wired OUT-of-phase"); } } diff --git a/diylc/diylc-swing/lib/diylc-core.jar b/diylc/diylc-swing/lib/diylc-core.jar index 7cf26f21..ad329e17 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 8b6c01cb..a741a0a5 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/update.xml b/diylc/diylc-swing/update.xml index 8210bed6..62905697 100644 --- a/diylc/diylc-swing/update.xml +++ b/diylc/diylc-swing/update.xml @@ -2534,10 +2534,18 @@ IMPROVEMENT Increase the range of zoom slider for images to 500% + + BUG_FIX + Netlist algorithm would sometimes create overlapping groups of nodes which are supposed to be merged + BUG_FIX Fixed bug with "Highlight Connected Areas" that makes random components conductive + + BUG_FIX + Fixed rendering issue with "Lever Switch" when rotated + https://github.com/bancika/diy-layout-creator/releases