diff --git a/diylc/diylc-core/src/org/diylc/netlist/Group.java b/diylc/diylc-core/src/org/diylc/netlist/Group.java index 5cb3f844..52423eb4 100644 --- a/diylc/diylc-core/src/org/diylc/netlist/Group.java +++ b/diylc/diylc-core/src/org/diylc/netlist/Group.java @@ -27,6 +27,8 @@ import java.util.HashSet; import java.util.List; import java.util.Set; +import org.diylc.core.IDIYComponent; + /** * Represents a group of {@link Node}s that are connected together. * @@ -44,6 +46,11 @@ public class Group implements Comparable { nodes.add(node1); nodes.add(node2); } + + public Group connect(IDIYComponent component, int index) { + getNodes().add(new Node(component, index)); + return this; + } public Set getNodes() { return nodes; diff --git a/diylc/diylc-library/src/org/diylc/netlist/AbstractNetlistAnalyzer.java b/diylc/diylc-core/src/org/diylc/netlist/NetlistAnalyzer.java similarity index 96% rename from diylc/diylc-library/src/org/diylc/netlist/AbstractNetlistAnalyzer.java rename to diylc/diylc-core/src/org/diylc/netlist/NetlistAnalyzer.java index b4ec4a2f..ae892835 100644 --- a/diylc/diylc-library/src/org/diylc/netlist/AbstractNetlistAnalyzer.java +++ b/diylc/diylc-core/src/org/diylc/netlist/NetlistAnalyzer.java @@ -28,11 +28,11 @@ import java.util.Set; import org.diylc.core.IDIYComponent; -public abstract class AbstractNetlistAnalyzer { +public class NetlistAnalyzer { - public AbstractNetlistAnalyzer() {} + public NetlistAnalyzer() {} - protected Tree constructTreeBetween(Netlist netlist, Node nodeA, Node nodeB) { + public Tree constructTreeBetween(Netlist netlist, Node nodeA, Node nodeB) { Tree tree = new Tree(TreeConnectionType.Parallel); connectNodes(netlist, nodeA, nodeB, tree.getChildren(), new Tree(TreeConnectionType.Series), new HashSet()); diff --git a/diylc/diylc-core/src/org/diylc/netlist/Tree.java b/diylc/diylc-core/src/org/diylc/netlist/Tree.java index 33dc26f3..fad41e30 100644 --- a/diylc/diylc-core/src/org/diylc/netlist/Tree.java +++ b/diylc/diylc-core/src/org/diylc/netlist/Tree.java @@ -22,6 +22,8 @@ package org.diylc.netlist; import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; import java.util.List; public class Tree { @@ -97,6 +99,19 @@ public class Tree { return false; return true; } + + private List getOrderedChildren() { + if (getConnectionType() == TreeConnectionType.Series) + return children; + List ordered = new ArrayList(children); + Collections.sort(ordered, new Comparator() { + + @Override + public int compare(Tree o1, Tree o2) { + return o1.toString().compareToIgnoreCase(o2.toString()); + }}); + return ordered; + } @Override public String toString() { @@ -105,7 +120,7 @@ public class Tree { StringBuilder sb = new StringBuilder("("); boolean first = true; - for(Tree child : children) { + for(Tree child : getOrderedChildren()) { if (!first) sb.append(" " ).append(connectionType).append(" "); first = false; @@ -119,6 +134,8 @@ public class Tree { if (leaf != null) return leaf.toHTML(); + List children = getOrderedChildren(); + StringBuilder sb = new StringBuilder(); if (depth > 0 && children.size() > 1) sb.append("("); diff --git a/diylc/diylc-library/.classpath b/diylc/diylc-library/.classpath index 490517cd..2fcda798 100644 --- a/diylc/diylc-library/.classpath +++ b/diylc/diylc-library/.classpath @@ -1,6 +1,7 @@ + @@ -8,5 +9,6 @@ + diff --git a/diylc/diylc-library/lib/diylc-core.jar b/diylc/diylc-library/lib/diylc-core.jar index 23ae8116..b7edbed5 100644 Binary files a/diylc/diylc-library/lib/diylc-core.jar and b/diylc/diylc-library/lib/diylc-core.jar differ diff --git a/diylc/diylc-library/src/org/diylc/netlist/GuitarDiagramAnalyzer.java b/diylc/diylc-library/src/org/diylc/netlist/GuitarDiagramAnalyzer.java index 58c8e350..0999dfc9 100644 --- a/diylc/diylc-library/src/org/diylc/netlist/GuitarDiagramAnalyzer.java +++ b/diylc/diylc-library/src/org/diylc/netlist/GuitarDiagramAnalyzer.java @@ -37,7 +37,7 @@ import org.diylc.components.guitar.SingleCoilPickup; import org.diylc.components.passive.PotentiometerPanel; import org.diylc.core.IDIYComponent; -public class GuitarDiagramAnalyzer extends AbstractNetlistAnalyzer implements INetlistAnalyzer { +public class GuitarDiagramAnalyzer extends NetlistAnalyzer implements INetlistAnalyzer { private static Set JACK_TYPES = new HashSet(); private static Set POT_TYPES = new HashSet(); diff --git a/diylc/diylc-library/test/org/diylc/netlist/NetlistAnalyzerTests.java b/diylc/diylc-library/test/org/diylc/netlist/NetlistAnalyzerTests.java new file mode 100644 index 00000000..55a7362a --- /dev/null +++ b/diylc/diylc-library/test/org/diylc/netlist/NetlistAnalyzerTests.java @@ -0,0 +1,126 @@ +/* + + 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 . + +*/ +package org.diylc.netlist; + +import static org.junit.Assert.assertEquals; + +import org.diylc.components.electromechanical.OpenJack1_4; +import org.diylc.components.guitar.HumbuckerPickup; +import org.diylc.components.guitar.SingleCoilPickup; +import org.junit.Test; + +public class NetlistAnalyzerTests { + + @Test + public void testOneSinglePickup() throws TreeException { + OpenJack1_4 jack = new OpenJack1_4(); + SingleCoilPickup pickup = new SingleCoilPickup(); + pickup.setName("Pickup"); + Netlist netlist = new Netlist(); + Group tipGroup = new Group().connect(jack, 0).connect(pickup, 1); + Group sleeveGroup = new Group().connect(jack, 1).connect(pickup, 2); + netlist.getGroups().add(tipGroup); + netlist.getGroups().add(sleeveGroup); + Tree tree = new GuitarDiagramAnalyzer().constructTree(netlist); + String s = tree.toString(); + assertEquals("((Pickup.North<-))", s); + } + + @Test + public void testOneSinglePickupReverse() throws TreeException { + OpenJack1_4 jack = new OpenJack1_4(); + SingleCoilPickup pickup = new SingleCoilPickup(); + pickup.setName("Pickup"); + Netlist netlist = new Netlist(); + Group tipGroup = new Group().connect(jack, 0).connect(pickup, 2); + Group sleeveGroup = new Group().connect(jack, 1).connect(pickup, 1); + netlist.getGroups().add(tipGroup); + netlist.getGroups().add(sleeveGroup); + Tree tree = new GuitarDiagramAnalyzer().constructTree(netlist); + String s = tree.toString(); + assertEquals("((Pickup.North->))", s); + } + + @Test + public void testOneHumbuckerSeries() throws TreeException { + OpenJack1_4 jack = new OpenJack1_4(); + HumbuckerPickup pickup = new HumbuckerPickup(); + pickup.setName("Pickup"); + Netlist netlist = new Netlist(); + Group tipGroup = new Group().connect(jack, 0).connect(pickup, 0); + Group coilTapGroup = new Group().connect(pickup, 1).connect(pickup, 2); + Group sleeveGroup = new Group().connect(jack, 1).connect(pickup, 3); + netlist.getGroups().add(tipGroup); + netlist.getGroups().add(coilTapGroup); + netlist.getGroups().add(sleeveGroup); + Tree tree = new GuitarDiagramAnalyzer().constructTree(netlist); + String s = tree.toString(); + assertEquals("((Pickup.North<- + Pickup.South<-))", s); + } + + @Test + public void testOneHumbuckerSeriesReverse() throws TreeException { + OpenJack1_4 jack = new OpenJack1_4(); + HumbuckerPickup pickup = new HumbuckerPickup(); + pickup.setName("Pickup"); + Netlist netlist = new Netlist(); + Group tipGroup = new Group().connect(jack, 0).connect(pickup, 3); + Group coilTapGroup = new Group().connect(pickup, 1).connect(pickup, 2); + Group sleeveGroup = new Group().connect(jack, 1).connect(pickup, 0); + netlist.getGroups().add(tipGroup); + netlist.getGroups().add(coilTapGroup); + netlist.getGroups().add(sleeveGroup); + Tree tree = new GuitarDiagramAnalyzer().constructTree(netlist); + String s = tree.toString(); + assertEquals("((Pickup.South-> + Pickup.North->))", s); + } + + @Test + public void testOneHumbuckerParallel() throws TreeException { + OpenJack1_4 jack = new OpenJack1_4(); + HumbuckerPickup pickup = new HumbuckerPickup(); + pickup.setName("Pickup"); + Netlist netlist = new Netlist(); + Group tipGroup = new Group().connect(jack, 0).connect(pickup, 0).connect(pickup, 2); + Group sleeveGroup = new Group().connect(jack, 1).connect(pickup, 1).connect(pickup, 3); + netlist.getGroups().add(tipGroup); + netlist.getGroups().add(sleeveGroup); + Tree tree = new GuitarDiagramAnalyzer().constructTree(netlist); + String s = tree.toString(); + assertEquals("((Pickup.South<-) || (Pickup.North<-))", s); + } + + @Test + public void testOneHumbuckerParallelOutOfPhase() throws TreeException { + OpenJack1_4 jack = new OpenJack1_4(); + HumbuckerPickup pickup = new HumbuckerPickup(); + pickup.setName("Pickup"); + Netlist netlist = new Netlist(); + Group tipGroup = new Group().connect(jack, 0).connect(pickup, 0).connect(pickup, 3); + Group sleeveGroup = new Group().connect(jack, 1).connect(pickup, 1).connect(pickup, 2); + netlist.getGroups().add(tipGroup); + netlist.getGroups().add(sleeveGroup); + Tree tree = new GuitarDiagramAnalyzer().constructTree(netlist); + String s = tree.toString(); + assertEquals("((Pickup.North<-) || (Pickup.South->))", s); + } +} diff --git a/diylc/diylc-swing/lib/diylc-core.jar b/diylc/diylc-swing/lib/diylc-core.jar index 23ae8116..b7edbed5 100644 Binary files a/diylc/diylc-swing/lib/diylc-core.jar and b/diylc/diylc-swing/lib/diylc-core.jar differ diff --git a/diylc/diylc-swing/library/main.jar b/diylc/diylc-swing/library/main.jar index cad29881..bff905e7 100644 Binary files a/diylc/diylc-swing/library/main.jar and b/diylc/diylc-swing/library/main.jar differ diff --git a/diylc/diylc-swing/update.xml b/diylc/diylc-swing/update.xml index a8d7b22d..01f57091 100644 --- a/diylc/diylc-swing/update.xml +++ b/diylc/diylc-swing/update.xml @@ -2470,6 +2470,18 @@ 2019-02-03 00:00:00.000 CET + + NEW_FEATURE + "Create Netlist" feature added under File -> Analyze + + + NEW_FEATURE + "Analyze Guitar Wiring" feature added under File -> Analyze + + + NEW_FEATURE + Guitar pickups now have separate terminals for start and finish point of each coil. Single coil pickups have polarity property added + NEW_FEATURE Added center-OFF options for "Mini Toggle Switch"