mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-10 17:22:09 +10:00
wiring analysys, ground work
This commit is contained in:
@@ -1,3 +1,24 @@
|
|||||||
|
/*
|
||||||
|
|
||||||
|
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.common;
|
package org.diylc.common;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|||||||
@@ -35,6 +35,10 @@ import java.util.Set;
|
|||||||
public class Group implements Comparable<Group> {
|
public class Group implements Comparable<Group> {
|
||||||
|
|
||||||
private Set<Node> nodes = new HashSet<Node>();
|
private Set<Node> nodes = new HashSet<Node>();
|
||||||
|
|
||||||
|
public Group() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public Group(Node node1, Node node2) {
|
public Group(Node node1, Node node2) {
|
||||||
nodes.add(node1);
|
nodes.add(node1);
|
||||||
|
|||||||
@@ -46,6 +46,10 @@ public class Node implements Comparable<Node> {
|
|||||||
public int getPointIndex() {
|
public int getPointIndex() {
|
||||||
return pointIndex;
|
return pointIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getDisplayName() {
|
||||||
|
return component.getControlPointNodeName(pointIndex);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
@@ -77,7 +81,7 @@ public class Node implements Comparable<Node> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return component.getName() + "." + component.getControlPointNodeName(pointIndex) /*+ " @ (" + component.getControlPoint(pointIndex).getX() + ":" + component.getControlPoint(pointIndex).getY() + ")"*/;
|
return component.getName() + "." + getDisplayName() /*+ " @ (" + component.getControlPoint(pointIndex).getX() + ":" + component.getControlPoint(pointIndex).getY() + ")"*/;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Binary file not shown.
@@ -0,0 +1,117 @@
|
|||||||
|
/*
|
||||||
|
|
||||||
|
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.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
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> 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 Netlist eliminate(Netlist netlist, Set<Node> nodes) {
|
||||||
|
Netlist res = new Netlist();
|
||||||
|
res.getSwitchSetup().addAll(netlist.getSwitchSetup());
|
||||||
|
|
||||||
|
Group merged = new Group();
|
||||||
|
|
||||||
|
for (Group g : netlist.getGroups()) {
|
||||||
|
boolean needsMerging = false;
|
||||||
|
for (Node n : nodes) {
|
||||||
|
if (g.getNodes().contains(n)) {
|
||||||
|
needsMerging = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (needsMerging) {
|
||||||
|
for (Node n : g.getNodes()) {
|
||||||
|
if (!nodes.contains(n))
|
||||||
|
merged.getNodes().add(n);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
res.getGroups().add(g);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!merged.getNodes().isEmpty())
|
||||||
|
res.getGroups().add(merged);
|
||||||
|
|
||||||
|
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,11 +1,58 @@
|
|||||||
|
/*
|
||||||
|
|
||||||
|
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;
|
package org.diylc.netlist;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import org.diylc.common.INetlistSummarizer;
|
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;
|
||||||
|
|
||||||
public class GuitarDiagramSummarizer implements INetlistSummarizer {
|
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
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
@@ -27,8 +74,32 @@ public class GuitarDiagramSummarizer implements INetlistSummarizer {
|
|||||||
|
|
||||||
private Summary summarize(Netlist netlist, Node preferredOutput) {
|
private Summary summarize(Netlist netlist, Node preferredOutput) {
|
||||||
List<String> notes = new ArrayList<String>();
|
List<String> notes = new ArrayList<String>();
|
||||||
notes.add("test");
|
List<Node> jackTipNodes = find(JACK_TYPES, "Tip", netlist, null);
|
||||||
|
List<Node> jackSleeveNodes = find(JACK_TYPES, "Sleeve", netlist, null);
|
||||||
|
|
||||||
|
netlist = findAndEliminateVolumePot(netlist, jackTipNodes, jackSleeveNodes, notes);
|
||||||
|
|
||||||
return new Summary(netlist, notes);
|
return new Summary(netlist, notes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Netlist findAndEliminateVolumePot(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());
|
||||||
|
|
||||||
|
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.");
|
||||||
|
return netlist;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
notes.add("No volume pot detected.");
|
||||||
|
return netlist;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user