mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-11 01:32:08 +10:00
generate connectivity tree
This commit is contained in:
@@ -534,6 +534,13 @@ public abstract class AbstractLeadedComponent<T> extends AbstractTransparentComp
|
||||
public void setLabelOriantation(LabelOriantation labelOriantation) {
|
||||
this.labelOriantation = labelOriantation;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getInternalLinkName(int index1, int index2) {
|
||||
if ((index1 == 0 && index2 == getControlPointCount() - 1) || (index2 == 0 && index1 == getControlPointCount() - 1))
|
||||
return getName();
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Override this method with @EditableProperty annotation in child classes where standing mode is
|
||||
|
||||
@@ -39,6 +39,7 @@ import org.diylc.common.ObjectCache;
|
||||
import org.diylc.common.Orientation;
|
||||
import org.diylc.common.VerticalAlignment;
|
||||
import org.diylc.components.AbstractTransparentComponent;
|
||||
import org.diylc.components.guitar.SingleCoilPickup.Polarity;
|
||||
import org.diylc.core.ComponentState;
|
||||
import org.diylc.core.IDIYComponent;
|
||||
import org.diylc.core.IDrawingObserver;
|
||||
@@ -667,6 +668,20 @@ public class HumbuckerPickup extends AbstractTransparentComponent<String> {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getInternalLinkName(int index1, int index2) {
|
||||
if (index1 == 0 && index2 == 1)
|
||||
return Polarity.North.toString() + "->";
|
||||
else if (index1 == 2 && index2 == 3)
|
||||
return Polarity.South.toString() + "->";
|
||||
else if (index1 == 1 && index2 == 0)
|
||||
return Polarity.North.toString() + "<-";
|
||||
else if (index1 == 3 && index2 == 2)
|
||||
return Polarity.South.toString() + "<-";
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static enum HumbuckerType {
|
||||
|
||||
|
||||
@@ -607,6 +607,30 @@ public class SingleCoilPickup extends AbstractTransparentComponent<String> {
|
||||
return null;
|
||||
return "South Finish";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getInternalLinkName(int index1, int index2) {
|
||||
switch (getPolarity()) {
|
||||
case Humbucking:
|
||||
if (index1 == 0 && index2 == 1)
|
||||
return Polarity.North.toString() + "->";
|
||||
else if (index1 == 1 && index2 == 0)
|
||||
return Polarity.North.toString() + "<-";
|
||||
else if (index1 == 2 && index2 == 3)
|
||||
return Polarity.South.toString() + "->";
|
||||
else if (index1 == 3 && index2 == 2)
|
||||
return Polarity.South.toString() + "<-";
|
||||
break;
|
||||
case North:
|
||||
case South:
|
||||
if (index1 == 1 && index2 == 2)
|
||||
return getPolarity().toString() + "->";
|
||||
else if (index1 == 2 && index2 == 1)
|
||||
return getPolarity().toString() + "<-";
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -457,6 +457,17 @@ public class PotentiometerPanel extends AbstractPotentiometer {
|
||||
|
||||
public void setWaferColor(Color waferColor) {
|
||||
this.waferColor = waferColor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getInternalLinkName(int index1, int index2) {
|
||||
if (index1 > index2)
|
||||
return getInternalLinkName(index2, index1);
|
||||
|
||||
if (index2 - index1 == 1)
|
||||
return (index1 + 1) + "-" + (index2 + 1);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public enum Type {
|
||||
|
||||
@@ -0,0 +1,362 @@
|
||||
/*
|
||||
|
||||
DIY Layout Creator (DIYLC).
|
||||
Copyright (c) 2009-2018 held jointly by the individual authors.
|
||||
|
||||
This file is part of DIYLC.
|
||||
|
||||
DIYLC is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
DIYLC is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with DIYLC. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
*/
|
||||
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 AbstractNetlistAnalyzer {
|
||||
|
||||
public AbstractNetlistAnalyzer() {
|
||||
}
|
||||
|
||||
protected Tree constructTree(Netlist netlist, Node nodeA, Node nodeB) {
|
||||
Tree tree = new Tree(new ArrayList<Tree>(), TreeConnectionType.Parallel);
|
||||
connectNodes(netlist, nodeA, nodeB, tree.getChildren(), null, new HashSet<Node>());
|
||||
// System.out.println(netlist.getSwitchSetup());
|
||||
// System.out.println(tree);
|
||||
return tree;
|
||||
}
|
||||
|
||||
protected void connectNodes(Netlist netlist, Node nodeA, Node nodeB, List<Tree> concurrentPaths, Tree currentPath, Set<Node> visited) {
|
||||
if (nodeA == nodeB) {
|
||||
concurrentPaths.add(currentPath);
|
||||
return;
|
||||
}
|
||||
|
||||
Group groupA = findGroup(netlist, nodeA);
|
||||
|
||||
if (groupA == null)
|
||||
return;
|
||||
|
||||
if (groupA.getNodes().contains(nodeB)) {
|
||||
concurrentPaths.add(currentPath);
|
||||
return;
|
||||
}
|
||||
|
||||
visited.add(nodeA);
|
||||
|
||||
for (Node n : groupA.getNodes()) {
|
||||
IDIYComponent<?> c = n.getComponent();
|
||||
for (int i = 0; i < c.getControlPointCount(); i++) {
|
||||
if (i != n.getPointIndex() && c.getInternalLinkName(i, n.getPointIndex()) != null) {
|
||||
TreeLeaf l = new TreeLeaf(c, i, n.getPointIndex());
|
||||
Node newNodeA = new Node(c, i);
|
||||
if (!visited.contains(newNodeA)) {
|
||||
visited.add(n);
|
||||
Tree newCurrentPath = null;
|
||||
try {
|
||||
if (currentPath == null)
|
||||
newCurrentPath = new Tree(new ArrayList<Tree>(), TreeConnectionType.Series);
|
||||
else
|
||||
newCurrentPath = (Tree) currentPath.clone();
|
||||
} catch (CloneNotSupportedException e) {
|
||||
}
|
||||
Tree newItem = new Tree(l);
|
||||
if (!newCurrentPath.getChildren().contains(newItem))
|
||||
newCurrentPath.getChildren().add(newItem);
|
||||
// if (!currentPath.contains(l))
|
||||
// newCurrentPath.add(l);
|
||||
Set<Node> newVisited = new HashSet<Node>(visited);
|
||||
connectNodes(netlist, newNodeA, nodeB, concurrentPaths, newCurrentPath, newVisited);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (concurrentPaths.size() < 2)
|
||||
return;
|
||||
|
||||
Tree jointSection = new Tree(new ArrayList<Tree>(), TreeConnectionType.Series);
|
||||
for (int i = 0; i < concurrentPaths.get(0).getChildren().size(); i++) {
|
||||
Tree unique = concurrentPaths.get(0).getChildren().get(i);
|
||||
boolean canMerge = true;
|
||||
for (Tree t : concurrentPaths) {
|
||||
if (t.getConnectionType() != TreeConnectionType.Series || t.getChildren().size() <= i || !t.getChildren().get(i).equals(unique)) {
|
||||
canMerge = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (canMerge)
|
||||
jointSection.getChildren().add(unique);
|
||||
else
|
||||
break;
|
||||
}
|
||||
if (!jointSection.getChildren().isEmpty()) {
|
||||
Tree mergedTree = new Tree(new ArrayList<Tree>(), TreeConnectionType.Series);
|
||||
mergedTree.getChildren().add(jointSection);
|
||||
Tree parallelSection = new Tree(new ArrayList<Tree>(concurrentPaths), TreeConnectionType.Parallel);
|
||||
for (Tree t : parallelSection.getChildren()) {
|
||||
t.trimChildren(jointSection.getChildren().size());
|
||||
}
|
||||
mergedTree.getChildren().add(parallelSection);
|
||||
concurrentPaths.clear();
|
||||
concurrentPaths.add(mergedTree);
|
||||
}
|
||||
}
|
||||
|
||||
protected void findAllPaths(Netlist netlist, Node nodeA, Node nodeB, List<TreeLeaf> currentPath, List<List<TreeLeaf>> allPaths, Set<Node> visited) {
|
||||
if (nodeA == nodeB) {
|
||||
allPaths.add(currentPath);
|
||||
return;
|
||||
}
|
||||
|
||||
// System.out.println("Finding path between " + nodeA + " and " + nodeB);
|
||||
|
||||
Group groupA = findGroup(netlist, nodeA);
|
||||
|
||||
if (groupA == null)
|
||||
return;
|
||||
|
||||
if (groupA.getNodes().contains(nodeB)) {
|
||||
allPaths.add(currentPath);
|
||||
return;
|
||||
}
|
||||
|
||||
for (Node n : groupA.getNodes()) {
|
||||
IDIYComponent<?> c = n.getComponent();
|
||||
for (int i = 0; i < c.getControlPointCount(); i++) {
|
||||
if (i != n.getPointIndex() && c.getInternalLinkName(i, n.getPointIndex()) != null) {
|
||||
TreeLeaf l = new TreeLeaf(c, i, n.getPointIndex());
|
||||
Node newNodeA = new Node(c, i);
|
||||
if (!visited.contains(newNodeA)) {
|
||||
List<TreeLeaf> newCurrentPath = new ArrayList<TreeLeaf>(currentPath);
|
||||
if (!currentPath.contains(l))
|
||||
newCurrentPath.add(l);
|
||||
Set<Node> newVisited = new HashSet<Node>(visited);
|
||||
newVisited.add(nodeA);
|
||||
newVisited.add(newNodeA);
|
||||
findAllPaths(netlist, newNodeA, nodeB, newCurrentPath, allPaths, newVisited);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected Group findGroup(Netlist netlist, Node node) {
|
||||
for (Group g : netlist.getGroups())
|
||||
if (g.getNodes().contains(node))
|
||||
return g;
|
||||
return null;
|
||||
}
|
||||
|
||||
protected List<Group> trace(Set<String> typeNames, String nodeName, Netlist netlist) {
|
||||
List<Group> res = new ArrayList<Group>();
|
||||
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(g);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
protected List<Node> find(Set<String> typeNames, String nodeName, Group group) {
|
||||
List<Node> res = new ArrayList<Node>();
|
||||
|
||||
for (Node n : group.getNodes()) {
|
||||
if (typeNames.contains(n.getComponent().getClass().getCanonicalName()) &&
|
||||
(nodeName == null || n.getDisplayName().equalsIgnoreCase(nodeName))) {
|
||||
res.add(n);
|
||||
}
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
protected List<Group> findGroups(Set<String> typeNames, String nodeName, Netlist netlist) {
|
||||
List<Group> res = new ArrayList<Group>();
|
||||
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(g);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
protected List<Group> findGroups(Set<String> typeNames, String nodeName, Netlist netlist, Collection<IDIYComponent<?>> belongTo) {
|
||||
List<Group> res = new ArrayList<Group>();
|
||||
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(g);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
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()) {
|
||||
|
||||
boolean inGroup;
|
||||
if (inGroupWith == null) {
|
||||
inGroup = true;
|
||||
} else {
|
||||
inGroup = true;
|
||||
for (Node n1 : inGroupWith)
|
||||
if (!g.getNodes().contains(n1)) {
|
||||
inGroup = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for (Node n : g.getNodes()) {
|
||||
if (inGroup && 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, 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 String extractName(IDIYComponent<?> c) {
|
||||
return c.getName() + " " + c.getValueForDisplay();
|
||||
}
|
||||
|
||||
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 : nodesToMerge) {
|
||||
if (g.getNodes().contains(n)) {
|
||||
needsMerging = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (needsMerging) {
|
||||
for (Node n : g.getNodes()) {
|
||||
if (!nodesToMerge.contains(n))
|
||||
merged.getNodes().add(n);
|
||||
}
|
||||
} else {
|
||||
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;
|
||||
}
|
||||
|
||||
protected boolean intersect(List<Group> groups, Node node) {
|
||||
for (Group g : groups)
|
||||
if (g.getNodes().contains(node))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
protected Node intersect(List<Group> groups, Group group) {
|
||||
for (Group g : groups)
|
||||
for (Node node : group.getNodes())
|
||||
if (g.getNodes().contains(node))
|
||||
return node;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -1,186 +0,0 @@
|
||||
/*
|
||||
|
||||
DIY Layout Creator (DIYLC).
|
||||
Copyright (c) 2009-2018 held jointly by the individual authors.
|
||||
|
||||
This file is part of DIYLC.
|
||||
|
||||
DIYLC is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
DIYLC is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with DIYLC. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
*/
|
||||
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() {
|
||||
}
|
||||
|
||||
protected List<Group> trace(Set<String> typeNames, String nodeName, Netlist netlist) {
|
||||
List<Group> res = new ArrayList<Group>();
|
||||
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(g);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
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()) {
|
||||
|
||||
boolean inGroup;
|
||||
if (inGroupWith == null) {
|
||||
inGroup = true;
|
||||
} else {
|
||||
inGroup = true;
|
||||
for (Node n1 : inGroupWith)
|
||||
if (!g.getNodes().contains(n1)) {
|
||||
inGroup = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for (Node n : g.getNodes()) {
|
||||
if (inGroup && 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, 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 : nodesToMerge) {
|
||||
if (g.getNodes().contains(n)) {
|
||||
needsMerging = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (needsMerging) {
|
||||
for (Node n : g.getNodes()) {
|
||||
if (!nodesToMerge.contains(n))
|
||||
merged.getNodes().add(n);
|
||||
}
|
||||
} else {
|
||||
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;
|
||||
}
|
||||
|
||||
protected boolean intersect(List<Group> groups, Node node) {
|
||||
for (Group g : groups)
|
||||
if (g.getNodes().contains(node))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
protected Node intersect(List<Group> groups, Group group) {
|
||||
for (Group g : groups)
|
||||
for (Node node : group.getNodes())
|
||||
if (g.getNodes().contains(node))
|
||||
return node;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,170 @@
|
||||
/*
|
||||
|
||||
DIY Layout Creator (DIYLC).
|
||||
Copyright (c) 2009-2018 held jointly by the individual authors.
|
||||
|
||||
This file is part of DIYLC.
|
||||
|
||||
DIYLC is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
DIYLC is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with DIYLC. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
*/
|
||||
package org.diylc.netlist;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.diylc.common.INetlistAnalyzer;
|
||||
import org.diylc.components.electromechanical.ClosedJack1_4;
|
||||
import org.diylc.components.electromechanical.OpenJack1_4;
|
||||
import org.diylc.components.guitar.HumbuckerPickup;
|
||||
import org.diylc.components.guitar.JazzBassPickup;
|
||||
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 GuitarDiagramAnalyzer extends AbstractNetlistAnalyzer implements INetlistAnalyzer {
|
||||
|
||||
private static Set<String> JACK_TYPES = new HashSet<String>();
|
||||
private static Set<String> POT_TYPES = new HashSet<String>();
|
||||
private static Set<String> PICKUP_TYPES = new HashSet<String>();
|
||||
static {
|
||||
JACK_TYPES.add(OpenJack1_4.class.getCanonicalName());
|
||||
JACK_TYPES.add(ClosedJack1_4.class.getCanonicalName());
|
||||
|
||||
POT_TYPES.add(PotentiometerPanel.class.getCanonicalName());
|
||||
|
||||
PICKUP_TYPES.add(SingleCoilPickup.class.getCanonicalName());
|
||||
PICKUP_TYPES.add(HumbuckerPickup.class.getCanonicalName());
|
||||
PICKUP_TYPES.add(P90Pickup.class.getCanonicalName());
|
||||
PICKUP_TYPES.add(JazzBassPickup.class.getCanonicalName());
|
||||
PICKUP_TYPES.add(PBassPickup.class.getCanonicalName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "Guitar Diagrams";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIconName() {
|
||||
return "Guitar";
|
||||
}
|
||||
|
||||
public List<Summary> summarize(List<Netlist> netlists, Node preferredOutput) {
|
||||
List<Summary> summaries = new ArrayList<Summary>();
|
||||
for (Netlist n : netlists)
|
||||
summaries.add(summarize(n, preferredOutput));
|
||||
|
||||
return summaries;
|
||||
}
|
||||
|
||||
private Summary summarize(Netlist netlist, Node preferredOutput) {
|
||||
List<String> notes = new ArrayList<String>();
|
||||
List<Group> jackTipGroups = findGroups(JACK_TYPES, "Tip", netlist);
|
||||
List<Group> jackSleeveGroups = findGroups(JACK_TYPES, "Sleeve", netlist);
|
||||
|
||||
// if (jackTipGroups.size() == 0 || jackSleeveGroups.size() == 0) {
|
||||
// notes.add("Could not find anything connected to a jack tip terminal.");
|
||||
// } else if (jackTipGroups.size() > 1 || jackSleeveGroups.size() > 1) {
|
||||
// notes.add("Multiple jacks found, could not proceed.");
|
||||
// } else {
|
||||
// Group jackTipGroup = jackTipGroups.get(0);
|
||||
// Group jackSleeveGroup = jackSleeveGroups.get(0);
|
||||
// netlist = findAndEliminatePots(netlist, jackTipGroup, jackSleeveGroup, notes);
|
||||
// // find jack tip group again after eliminating pots, it should be connecter straight to the pickups
|
||||
// jackTipGroups = findGroups(JACK_TYPES, "Tip", netlist);
|
||||
// if (jackTipGroups.size() == 1) {
|
||||
// jackTipGroup = jackTipGroups.get(0);
|
||||
// List<Node> pickupTipNodes = find(PICKUP_TYPES, null, jackTipGroup);
|
||||
// List<Node> pickupSleeveNodes = find(PICKUP_TYPES, null, jackSleeveGroup);
|
||||
// notes.add("test");
|
||||
// }
|
||||
// }
|
||||
|
||||
try {
|
||||
return new Summary(netlist, notes, constructTree(netlist));
|
||||
} catch (TreeException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private Netlist findAndEliminatePots(Netlist netlist, Group jackTipGroup, Group jackSleeveGroup, List<String> notes) {
|
||||
// try to find any pots that have connections to jack tip or sleeve
|
||||
List<Node> potTipNodes = find(POT_TYPES, null, jackTipGroup);
|
||||
List<Node> potSleeveNodes = find(POT_TYPES, null, jackSleeveGroup);
|
||||
|
||||
if (!potTipNodes.isEmpty() && !potSleeveNodes.isEmpty()) {
|
||||
|
||||
Set<IDIYComponent<?>> pots = extractComponents(potTipNodes);
|
||||
List<Node> potInputNodes = find(POT_TYPES, "1", netlist, pots);
|
||||
// List<Group> potInputGroups = findGroups(POT_TYPES, "1", netlist, pots);
|
||||
|
||||
// if (allMatch(potTipNodes, "2") && allMatch(potSleeveNodes, "3")) {
|
||||
//
|
||||
// for (Group g : potInputGroups) {
|
||||
// List<Node> potNodes = find(POT_TYPES, null, g);
|
||||
// List<Node> pickupNodes = find(PICKUP_TYPES, null, g);
|
||||
// if (potNodes.size() != 1) {
|
||||
// notes.add("Detected control potentiometer wiring issue.");
|
||||
// } else {
|
||||
// StringBuilder sb = new StringBuilder("Detected volume potentiometer [");
|
||||
// sb.append(extractName(potNodes.get(0).getComponent())).append("] controlling: ");
|
||||
// Set<String> pickups = new HashSet<String>();
|
||||
// for (Node n : pickupNodes) {
|
||||
// pickups.add(n.getComponent().getName());
|
||||
// }
|
||||
// List<String> pickupList = new ArrayList<String>(pickups);
|
||||
// Collections.sort(pickupList);
|
||||
// sb.append(pickupList.toString());
|
||||
// notes.add(sb.toString());
|
||||
// }
|
||||
// }
|
||||
// List<String> potNames = extractNames(pots);
|
||||
// notes.add("Detected volume control(s): " + potNames);
|
||||
|
||||
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 controls detected.");
|
||||
return netlist;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Tree constructTree(Netlist netlist) throws TreeException {
|
||||
List<Node> jackTipNodes = find(JACK_TYPES, "Tip", netlist);
|
||||
List<Node> jackSleeveNodes = find(JACK_TYPES, "Sleeve", netlist);
|
||||
|
||||
if (jackTipNodes.size() == 0 || jackSleeveNodes.size() == 0) {
|
||||
throw new TreeException("Could not find anything connected to a jack tip terminal.");
|
||||
} else if (jackTipNodes.size() > 1 || jackSleeveNodes.size() > 1) {
|
||||
throw new TreeException("Multiple jacks found, could not proceed.");
|
||||
} else {
|
||||
Node jackTip = jackTipNodes.get(0);
|
||||
Node jackSleeve = jackSleeveNodes.get(0);
|
||||
return constructTree(netlist, jackTip, jackSleeve);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,109 +0,0 @@
|
||||
/*
|
||||
|
||||
DIY Layout Creator (DIYLC).
|
||||
Copyright (c) 2009-2018 held jointly by the individual authors.
|
||||
|
||||
This file is part of DIYLC.
|
||||
|
||||
DIYLC is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
DIYLC is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with DIYLC. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
*/
|
||||
package org.diylc.netlist;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.diylc.common.INetlistSummarizer;
|
||||
import org.diylc.components.electromechanical.ClosedJack1_4;
|
||||
import org.diylc.components.electromechanical.OpenJack1_4;
|
||||
import org.diylc.components.guitar.HumbuckerPickup;
|
||||
import org.diylc.components.guitar.JazzBassPickup;
|
||||
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 {
|
||||
|
||||
private static Set<String> JACK_TYPES = new HashSet<String>();
|
||||
private static Set<String> POT_TYPES = new HashSet<String>();
|
||||
private static Set<String> PICKUP_TYPES = new HashSet<String>();
|
||||
static {
|
||||
JACK_TYPES.add(OpenJack1_4.class.getCanonicalName());
|
||||
JACK_TYPES.add(ClosedJack1_4.class.getCanonicalName());
|
||||
|
||||
POT_TYPES.add(PotentiometerPanel.class.getCanonicalName());
|
||||
|
||||
PICKUP_TYPES.add(SingleCoilPickup.class.getCanonicalName());
|
||||
PICKUP_TYPES.add(HumbuckerPickup.class.getCanonicalName());
|
||||
PICKUP_TYPES.add(P90Pickup.class.getCanonicalName());
|
||||
PICKUP_TYPES.add(JazzBassPickup.class.getCanonicalName());
|
||||
PICKUP_TYPES.add(PBassPickup.class.getCanonicalName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "Guitar Diagrams";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIconName() {
|
||||
return "Guitar";
|
||||
}
|
||||
|
||||
public List<Summary> summarize(List<Netlist> netlists, Node preferredOutput) {
|
||||
List<Summary> summaries = new ArrayList<Summary>();
|
||||
for (Netlist n : netlists)
|
||||
summaries.add(summarize(n, preferredOutput));
|
||||
|
||||
return summaries;
|
||||
}
|
||||
|
||||
private Summary summarize(Netlist netlist, Node preferredOutput) {
|
||||
List<String> notes = new ArrayList<String>();
|
||||
List<Node> jackTipNodes = find(JACK_TYPES, "Tip", netlist);
|
||||
List<Node> jackSleeveNodes = find(JACK_TYPES, "Sleeve", netlist);
|
||||
|
||||
netlist = findAndEliminateVolumeControls(netlist, jackTipNodes, jackSleeveNodes, notes);
|
||||
|
||||
return new Summary(netlist, 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()) {
|
||||
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> 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 controls detected.");
|
||||
return netlist;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user