mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-10 09:12:09 +10:00
Fix lever switch rotation issue
Render pickup name instead of model Netlist algorithm would sometimes create overlapping groups of nodes which are supposed to be merged
This commit is contained in:
@@ -227,6 +227,11 @@ public class Tree {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Tree findCommonParent(Tree t1, Tree t2) {
|
public Tree findCommonParent(Tree t1, Tree t2) {
|
||||||
|
if (t1 == null)
|
||||||
|
return t2;
|
||||||
|
if (t2 == null)
|
||||||
|
return t1;
|
||||||
|
|
||||||
if (children == null)
|
if (children == null)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
@@ -248,6 +253,25 @@ public class Tree {
|
|||||||
return p1.findCommonParent(t1, t2);
|
return p1.findCommonParent(t1, t2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Tree findCommonParent(List<Tree> 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<Tree> remainder = t.subList(1, t.size());
|
||||||
|
return findCommonParent(t.get(0), findCommonParent(remainder));
|
||||||
|
}
|
||||||
|
|
||||||
public boolean contains(Tree t) {
|
public boolean contains(Tree t) {
|
||||||
if (this == t)
|
if (this == t)
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -2755,7 +2755,7 @@ public class Presenter implements IPlugInPort {
|
|||||||
List<Line2D> connections = getConnections(switchPositions);
|
List<Line2D> connections = getConnections(switchPositions);
|
||||||
Netlist graph = constructNetlist(nodes, connections, continuity);
|
Netlist graph = constructNetlist(nodes, connections, continuity);
|
||||||
|
|
||||||
// merge graphs that are effectivelly the same
|
// merge graphs that are effectively the same
|
||||||
if (result.containsKey(graph)) {
|
if (result.containsKey(graph)) {
|
||||||
result.get(graph).getSwitchSetup().add(new SwitchSetup(posList));
|
result.get(graph).getSwitchSetup().add(new SwitchSetup(posList));
|
||||||
} else {
|
} else {
|
||||||
@@ -2827,6 +2827,29 @@ public class Presenter implements IPlugInPort {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// merge overlapping groups if needed
|
||||||
|
boolean reduce = true;
|
||||||
|
while (reduce) {
|
||||||
|
reduce = false;
|
||||||
|
List<Group> groups = netlist.getSortedGroups();
|
||||||
|
Iterator<Group> 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());
|
Collections.sort(netlist.getSwitchSetup());
|
||||||
|
|
||||||
return netlist;
|
return netlist;
|
||||||
|
|||||||
Binary file not shown.
@@ -120,7 +120,7 @@ public abstract class AbstractGuitarPickup extends AbstractTransparentComponent<
|
|||||||
}
|
}
|
||||||
g2d.translate(0, getMainLabelYOffset());
|
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);
|
g2d.setTransform(originalTx);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -238,8 +238,8 @@ public class LeverSwitch extends AbstractTransparentComponent<String> implements
|
|||||||
// Rotate if needed
|
// Rotate if needed
|
||||||
if (theta != 0) {
|
if (theta != 0) {
|
||||||
AffineTransform rotation = AffineTransform.getRotateInstance(theta, x, y);
|
AffineTransform rotation = AffineTransform.getRotateInstance(theta, x, y);
|
||||||
// Skip the last one because it's already rotated
|
// Skip the last two because terminals are already rotated
|
||||||
for (int i = 0; i < body.length - 1; i++) {
|
for (int i = 0; i < body.length - 2; i++) {
|
||||||
Shape shape = body[i];
|
Shape shape = body[i];
|
||||||
Area area = (Area) shape;
|
Area area = (Area) shape;
|
||||||
area.transform(rotation);
|
area.transform(rotation);
|
||||||
@@ -460,14 +460,14 @@ public class LeverSwitch extends AbstractTransparentComponent<String> implements
|
|||||||
public boolean arePointsConnected(int index1, int index2, int position) {
|
public boolean arePointsConnected(int index1, int index2, int position) {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case DP3T:
|
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:
|
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:
|
case DP3T_5pos:
|
||||||
if (position % 2 == 0)
|
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
|
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)));
|
(index1 == 1 && (index2 == 5 || (index2 == 3 && position == 1) || (index2 == 7 && position == 3)));
|
||||||
case DP5T:
|
case DP5T:
|
||||||
return (index1 == 0 || index2 == 11) && index2 - index1 == position + 1;
|
return (index1 == 0 || index2 == 11) && index2 - index1 == position + 1;
|
||||||
|
|||||||
@@ -22,8 +22,10 @@
|
|||||||
package org.diylc.netlist;
|
package org.diylc.netlist;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.diylc.common.INetlistAnalyzer;
|
import org.diylc.common.INetlistAnalyzer;
|
||||||
@@ -92,6 +94,8 @@ public class GuitarDiagramAnalyzer extends NetlistAnalyzer implements INetlistAn
|
|||||||
positiveCount = 0;
|
positiveCount = 0;
|
||||||
negativeCount = 0;
|
negativeCount = 0;
|
||||||
noiseCount = 0;
|
noiseCount = 0;
|
||||||
|
|
||||||
|
// analyze hum-cancellation and phase
|
||||||
pickupTree.walk(new ITreeWalker() {
|
pickupTree.walk(new ITreeWalker() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -115,6 +119,9 @@ public class GuitarDiagramAnalyzer extends NetlistAnalyzer implements INetlistAn
|
|||||||
});
|
});
|
||||||
|
|
||||||
Set<IDIYComponent<?>> pickups = tree.extractComponents(PICKUP_TYPES);
|
Set<IDIYComponent<?>> pickups = tree.extractComponents(PICKUP_TYPES);
|
||||||
|
Map<IDIYComponent<?>, Tree> pickupRoots = new HashMap<IDIYComponent<?>, Tree>();
|
||||||
|
|
||||||
|
// analyze each pickup separately to see how each coil is wired
|
||||||
for (IDIYComponent<?> c : pickups) {
|
for (IDIYComponent<?> c : pickups) {
|
||||||
if (c instanceof AbstractGuitarPickup) {
|
if (c instanceof AbstractGuitarPickup) {
|
||||||
AbstractGuitarPickup pickup = (AbstractGuitarPickup)c;
|
AbstractGuitarPickup pickup = (AbstractGuitarPickup)c;
|
||||||
@@ -124,15 +131,40 @@ public class GuitarDiagramAnalyzer extends NetlistAnalyzer implements INetlistAn
|
|||||||
Tree nTree = tree.locate(nLeaf, false);
|
Tree nTree = tree.locate(nLeaf, false);
|
||||||
Tree sTree = tree.locate(sLeaf, false);
|
Tree sTree = tree.locate(sLeaf, false);
|
||||||
Tree parent = tree.findCommonParent(nTree, sTree);
|
Tree parent = tree.findCommonParent(nTree, sTree);
|
||||||
|
if (parent != null)
|
||||||
|
pickupRoots.put(pickup, parent);
|
||||||
if (nTree != null && sTree != null && parent != null) {
|
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)) {
|
} 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<Tree>(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;
|
boolean humCancelling = noiseCount == 0;
|
||||||
|
|
||||||
if (humCancelling)
|
if (humCancelling)
|
||||||
@@ -143,9 +175,9 @@ public class GuitarDiagramAnalyzer extends NetlistAnalyzer implements INetlistAn
|
|||||||
if (positiveCount > 1 || negativeCount > 1) {
|
if (positiveCount > 1 || negativeCount > 1) {
|
||||||
boolean inPhase = (positiveCount == 0 && negativeCount > 0) || (positiveCount > 0 && negativeCount == 0);
|
boolean inPhase = (positiveCount == 0 && negativeCount > 0) || (positiveCount > 0 && negativeCount == 0);
|
||||||
if (inPhase)
|
if (inPhase)
|
||||||
notes.add("The pickups are wired in-phase");
|
notes.add("Pickup coils are wired in-phase");
|
||||||
else
|
else
|
||||||
notes.add("This pickups are wired out-of-phase");
|
notes.add("Pickup coils are wired OUT-of-phase");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
@@ -2534,10 +2534,18 @@
|
|||||||
<changeType>IMPROVEMENT</changeType>
|
<changeType>IMPROVEMENT</changeType>
|
||||||
<description>Increase the range of zoom slider for images to 500%</description>
|
<description>Increase the range of zoom slider for images to 500%</description>
|
||||||
</org.diylc.appframework.update.Change>
|
</org.diylc.appframework.update.Change>
|
||||||
|
<org.diylc.appframework.update.Change>
|
||||||
|
<changeType>BUG_FIX</changeType>
|
||||||
|
<description>Netlist algorithm would sometimes create overlapping groups of nodes which are supposed to be merged</description>
|
||||||
|
</org.diylc.appframework.update.Change>
|
||||||
<org.diylc.appframework.update.Change>
|
<org.diylc.appframework.update.Change>
|
||||||
<changeType>BUG_FIX</changeType>
|
<changeType>BUG_FIX</changeType>
|
||||||
<description>Fixed bug with "Highlight Connected Areas" that makes random components conductive</description>
|
<description>Fixed bug with "Highlight Connected Areas" that makes random components conductive</description>
|
||||||
</org.diylc.appframework.update.Change>
|
</org.diylc.appframework.update.Change>
|
||||||
|
<org.diylc.appframework.update.Change>
|
||||||
|
<changeType>BUG_FIX</changeType>
|
||||||
|
<description>Fixed rendering issue with "Lever Switch" when rotated</description>
|
||||||
|
</org.diylc.appframework.update.Change>
|
||||||
</changes>
|
</changes>
|
||||||
<url>https://github.com/bancika/diy-layout-creator/releases</url>
|
<url>https://github.com/bancika/diy-layout-creator/releases</url>
|
||||||
</org.diylc.appframework.update.Version>
|
</org.diylc.appframework.update.Version>
|
||||||
|
|||||||
Reference in New Issue
Block a user