mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-10 09:12:09 +10:00
wiring analysis improvements
This commit is contained in:
@@ -96,4 +96,11 @@ public class Group implements Comparable<Group> {
|
||||
public int compareTo(Group o) {
|
||||
return toString().compareToIgnoreCase(o.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Group clone() {
|
||||
Group g = new Group();
|
||||
g.nodes.addAll(nodes);
|
||||
return g;
|
||||
}
|
||||
}
|
||||
|
||||
Binary file not shown.
@@ -22,9 +22,14 @@
|
||||
package org.diylc.netlist;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.diylc.core.IDIYComponent;
|
||||
|
||||
public abstract class AbstractNetlistSummarizer {
|
||||
|
||||
public AbstractNetlistSummarizer() {
|
||||
@@ -44,6 +49,19 @@ public abstract class AbstractNetlistSummarizer {
|
||||
return res;
|
||||
}
|
||||
|
||||
protected List<Node> find(Set<String> typeNames, String nodeName, Netlist netlist) {
|
||||
List<Node> res = new ArrayList<Node>();
|
||||
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(n);
|
||||
}
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
protected List<Node> find(Set<String> typeNames, String nodeName, Netlist netlist, List<Node> inGroupWith) {
|
||||
List<Node> res = new ArrayList<Node>();
|
||||
for (Group g : netlist.getGroups()) {
|
||||
@@ -70,15 +88,58 @@ public abstract class AbstractNetlistSummarizer {
|
||||
return res;
|
||||
}
|
||||
|
||||
protected Netlist eliminate(Netlist netlist, Set<Node> nodes) {
|
||||
protected List<Node> find(Set<String> typeNames, String nodeName, Netlist netlist, Collection<IDIYComponent<?>> belongTo) {
|
||||
List<Node> res = new ArrayList<Node>();
|
||||
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<Node> nodes, String name) {
|
||||
for (Node n : nodes)
|
||||
if (!n.getDisplayName().equalsIgnoreCase(name))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
protected boolean allComponentsMatch(Collection<Node> nodes, Set<IDIYComponent<?>> components) {
|
||||
Set<IDIYComponent<?>> extracted = extractComponents(nodes);
|
||||
return extracted.containsAll(components);
|
||||
}
|
||||
|
||||
protected Set<IDIYComponent<?>> extractComponents(Collection<Node> nodes) {
|
||||
Set<IDIYComponent<?>> components = new HashSet<IDIYComponent<?>>();
|
||||
for (Node n : nodes)
|
||||
components.add(n.getComponent());
|
||||
return components;
|
||||
}
|
||||
|
||||
protected List<String> extractNames(Collection<IDIYComponent<?>> components) {
|
||||
List<String> names = new ArrayList<String>();
|
||||
for (IDIYComponent<?> c : components)
|
||||
names.add(c.getName() + " " + c.getValueForDisplay());
|
||||
Collections.sort(names);
|
||||
return names;
|
||||
}
|
||||
|
||||
protected Netlist simplify(Netlist netlist, Set<Node> nodesToMerge, Collection<Node> 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 : nodes) {
|
||||
for (Node n : nodesToMerge) {
|
||||
if (g.getNodes().contains(n)) {
|
||||
needsMerging = true;
|
||||
break;
|
||||
@@ -86,17 +147,25 @@ public abstract class AbstractNetlistSummarizer {
|
||||
}
|
||||
if (needsMerging) {
|
||||
for (Node n : g.getNodes()) {
|
||||
if (!nodes.contains(n))
|
||||
if (!nodesToMerge.contains(n))
|
||||
merged.getNodes().add(n);
|
||||
}
|
||||
} else {
|
||||
res.getGroups().add(g);
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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.core.IDIYComponent;
|
||||
|
||||
public class GuitarDiagramSummarizer extends AbstractNetlistSummarizer implements INetlistSummarizer {
|
||||
|
||||
@@ -74,32 +75,35 @@ public class GuitarDiagramSummarizer extends AbstractNetlistSummarizer implement
|
||||
|
||||
private Summary summarize(Netlist netlist, Node preferredOutput) {
|
||||
List<String> notes = new ArrayList<String>();
|
||||
List<Node> jackTipNodes = find(JACK_TYPES, "Tip", netlist, null);
|
||||
List<Node> jackSleeveNodes = find(JACK_TYPES, "Sleeve", netlist, null);
|
||||
List<Node> jackTipNodes = find(JACK_TYPES, "Tip", netlist);
|
||||
List<Node> jackSleeveNodes = find(JACK_TYPES, "Sleeve", netlist);
|
||||
|
||||
netlist = findAndEliminateVolumePot(netlist, jackTipNodes, jackSleeveNodes, notes);
|
||||
netlist = findAndEliminateVolumeControls(netlist, jackTipNodes, jackSleeveNodes, notes);
|
||||
|
||||
return new Summary(netlist, notes);
|
||||
}
|
||||
|
||||
private Netlist findAndEliminateVolumePot(Netlist netlist, List<Node> jackTipGroups, List<Node> jackSleeveGroups, List<String> notes) {
|
||||
private Netlist findAndEliminateVolumeControls(Netlist netlist, List<Node> jackTipGroups, List<Node> jackSleeveGroups, List<String> notes) {
|
||||
List<Node> potTipNodes = find(POT_TYPES, null, netlist, jackTipGroups);
|
||||
List<Node> potSleeveNodes = find(POT_TYPES, null, netlist, jackSleeveGroups);
|
||||
if (!potTipNodes.isEmpty() && !potSleeveNodes.isEmpty()) {
|
||||
if (potTipNodes.size() == 1 && potTipNodes.get(0).getDisplayName().equals("2") &&
|
||||
potSleeveNodes.size() == 1 && potSleeveNodes.get(0).getDisplayName().equals("3")) {
|
||||
notes.add("Volume pot detected: " + potTipNodes.get(0).getComponent().getName());
|
||||
if (!potTipNodes.isEmpty() && !potSleeveNodes.isEmpty()) {
|
||||
Set<IDIYComponent<?>> pots = extractComponents(potTipNodes);
|
||||
List<Node> potInputNodes = find(POT_TYPES, "1", netlist, pots);
|
||||
|
||||
if (allMatch(potTipNodes, "2") && allMatch(potSleeveNodes, "3") && allComponentsMatch(potInputNodes, pots)) {
|
||||
List<String> potNames = extractNames(pots);
|
||||
notes.add("Detected volume control(s): " + potNames);
|
||||
|
||||
Set<Node> toEliminate = new HashSet<Node>(potTipNodes);
|
||||
toEliminate.addAll(potSleeveNodes);
|
||||
return eliminate(netlist, toEliminate);
|
||||
} else if (potTipNodes.size() > 1 || potSleeveNodes.size() > 1) {
|
||||
notes.add("Detected multiple volume pots, test inconclusive.");
|
||||
Set<Node> toMerge = new HashSet<Node>(potTipNodes);
|
||||
toMerge.addAll(potInputNodes);
|
||||
return simplify(netlist, toMerge, potSleeveNodes);
|
||||
} else {
|
||||
notes.add("Detected incorrectly wired volume control(s).");
|
||||
return netlist;
|
||||
}
|
||||
}
|
||||
|
||||
notes.add("No volume pot detected.");
|
||||
notes.add("No volume controls detected.");
|
||||
return netlist;
|
||||
}
|
||||
}
|
||||
|
||||
Binary file not shown.
Binary file not shown.
@@ -1695,7 +1695,7 @@ public class ActionFactory {
|
||||
this.plugInPort = plugInPort;
|
||||
this.swingUI = swingUI;
|
||||
this.summarizer = summarizer;
|
||||
putValue(AbstractAction.NAME, "Analyze " + summarizer.getName());
|
||||
putValue(AbstractAction.NAME, "Analyze " + summarizer.getName() + " (beta)");
|
||||
putValue(AbstractAction.SMALL_ICON, Enum.valueOf(IconLoader.class, summarizer.getIconName()).getIcon());
|
||||
}
|
||||
|
||||
@@ -1703,26 +1703,26 @@ public class ActionFactory {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
List<Netlist> netlists = plugInPort.extractNetlists();
|
||||
if (netlists == null || netlists.isEmpty()) {
|
||||
swingUI.showMessage("The generated netlist is empty, nothing to show.", "Netlist", ISwingUI.INFORMATION_MESSAGE);
|
||||
swingUI.showMessage("The generated netlist is empty, nothing to show.", "Analyze " + summarizer.getName(), ISwingUI.INFORMATION_MESSAGE);
|
||||
return;
|
||||
}
|
||||
|
||||
List<Summary> res = summarizer.summarize(netlists, null);
|
||||
if (res == null) {
|
||||
swingUI.showMessage("The generated summary is empty, nothing to show.", "Analyze", ISwingUI.INFORMATION_MESSAGE);
|
||||
swingUI.showMessage("The generated summary is empty, nothing to show.", "Analyze " + summarizer.getName(), ISwingUI.INFORMATION_MESSAGE);
|
||||
return;
|
||||
}
|
||||
StringBuilder sb = new StringBuilder("<html>");
|
||||
|
||||
for (Summary summary : res) {
|
||||
sb.append("<p style=\"font-family: " + new JLabel().getFont().getName() + "; font-size: 9px\"><b>Switch configuration: ").append(summary.getNetlist().getSwitchSetup()).append("</b><br><br>Notes:<br><br>");
|
||||
sb.append("<p style=\"font-family: " + new JLabel().getFont().getName() + "; font-size: 9px\"><b>Switch configuration: ").append(summary.getNetlist().getSwitchSetup()).append("</b><br><br>");
|
||||
for (String v : summary.getNotes()) {
|
||||
sb.append(" ").append(v).append("<br>");
|
||||
}
|
||||
sb.append("</p><br><hr>");
|
||||
}
|
||||
sb.append("</html>");
|
||||
new TextDialog(swingUI.getOwnerFrame().getRootPane(), sb.toString(), "Netlist", new Dimension(600, 480)).setVisible(true);
|
||||
new TextDialog(swingUI.getOwnerFrame().getRootPane(), sb.toString(), "Analyze " + summarizer.getName(), new Dimension(600, 480)).setVisible(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user