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:
Branislav Stojkovic
2019-03-02 09:11:00 +01:00
parent cc0f698c8b
commit b3497cdca8
9 changed files with 99 additions and 12 deletions
@@ -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);
}
@@ -238,8 +238,8 @@ public class LeverSwitch extends AbstractTransparentComponent<String> 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<String> 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;
@@ -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<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) {
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<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;
@@ -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");
}
}