Fix blocks, add tests, fix bounding box calc of some components

This commit is contained in:
Bane Stojkovic
2022-03-18 09:23:03 +01:00
parent d513cb2667
commit bf89b07cea
81 changed files with 41887 additions and 6426 deletions
Binary file not shown.
@@ -3,7 +3,7 @@ package org.diylc.components;
import java.awt.Graphics2D;
import java.awt.Shape;
import java.awt.geom.Area;
import java.awt.geom.Rectangle2D;
import org.diylc.common.ObjectCache;
import org.diylc.core.ComponentState;
import org.diylc.core.IDrawingObserver;
@@ -33,4 +33,28 @@ public abstract class AbstractMultiPartComponent<T> extends AbstractLabeledCompo
outline.add((Area)b);
return outline;
}
@Override
public Rectangle2D getCachingBounds() {
Shape[] body = getBody();
int margin = 20;
double minX = 0;
double minY = 0;
double maxX = 0;
double maxY = 0;
for (Shape a : body) {
if (a != null) {
Rectangle2D bounds2d = a.getBounds2D();
if (bounds2d.getMinX() < minX)
minX = bounds2d.getMinX();
if (bounds2d.getMinY() < minY)
minY = bounds2d.getMinY();
if (bounds2d.getMaxX() > maxX)
maxX = bounds2d.getMaxX();
if (bounds2d.getMaxY() > maxY)
maxY = bounds2d.getMaxY();
}
}
return new Rectangle2D.Double(minX - margin, minY - margin, maxX - minX + 2 * margin, maxY - minY + 2 * margin);
}
}
@@ -351,17 +351,5 @@ public class CliffJack1_4 extends AbstractMultiPartComponent<String> {
@Override
public boolean canPointMoveFreely(int pointIndex) {
return false;
}
@Override
public Rectangle2D getCachingBounds() {
Area area = new Area();
Area[] body = getBody();
int margin = 20;
for (Area a : body)
if (a != null)
area.add(a);
Rectangle2D bounds = area.getBounds2D();
return new Rectangle2D.Double(bounds.getX() - margin, bounds.getY() - margin, bounds.getWidth() + 2 * margin, bounds.getHeight() + 2 * margin);
}
}
@@ -375,17 +375,5 @@ public class ClosedJack1_4 extends AbstractMultiPartComponent<String> {
@Override
public boolean canPointMoveFreely(int pointIndex) {
return false;
}
@Override
public Rectangle2D getCachingBounds() {
Area area = new Area();
Shape[] body = getBody();
int margin = 20;
for (Shape a : body)
if (a != null)
area.add(new Area(a));
Rectangle2D bounds = area.getBounds2D();
return new Rectangle2D.Double(bounds.getX() - margin, bounds.getY() - margin, bounds.getWidth() + 2 * margin, bounds.getHeight() + 2 * margin);
}
}
@@ -376,19 +376,7 @@ public class NeutrikJack1_4 extends AbstractMultiPartComponent<String> {
public boolean canPointMoveFreely(int pointIndex) {
return false;
}
@Override
public Rectangle2D getCachingBounds() {
Area area = new Area();
Area[] body = getBody();
int margin = 20;
for (Area a : body)
if (a != null)
area.add(a);
Rectangle2D bounds = area.getBounds2D();
return new Rectangle2D.Double(bounds.getX() - margin, bounds.getY() - margin, bounds.getWidth() + 2 * margin, bounds.getHeight() + 2 * margin);
}
enum Mount {
PCB, Panel
}
@@ -31,9 +31,7 @@ import java.awt.geom.AffineTransform;
import java.awt.geom.Area;
import java.awt.geom.Ellipse2D;
import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;
import java.awt.geom.RoundRectangle2D;
import org.diylc.appframework.miscutils.ConfigurationManager;
import org.diylc.awt.StringUtils;
import org.diylc.common.HorizontalAlignment;
@@ -425,18 +423,6 @@ public class OpenJack1_4 extends AbstractMultiPartComponent<String> {
return false;
}
@Override
public Rectangle2D getCachingBounds() {
Area area = new Area();
Area[] body = getBody();
int margin = 20;
for (Area a : body)
if (a != null)
area.add(a);
Rectangle2D bounds = area.getBounds2D();
return new Rectangle2D.Double(bounds.getX() - margin, bounds.getY() - margin, bounds.getWidth() + 2 * margin, bounds.getHeight() + 2 * margin);
}
public enum OpenJackType {
MONO, STEREO, SWITCHED;
@@ -31,9 +31,7 @@ import java.awt.geom.AffineTransform;
import java.awt.geom.Area;
import java.awt.geom.Ellipse2D;
import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;
import java.awt.geom.RoundRectangle2D;
import org.diylc.appframework.miscutils.ConfigurationManager;
import org.diylc.awt.StringUtils;
import org.diylc.common.HorizontalAlignment;
@@ -425,18 +423,6 @@ public class OpenJack1_8 extends AbstractMultiPartComponent<String> {
return false;
}
@Override
public Rectangle2D getCachingBounds() {
Area area = new Area();
Area[] body = getBody();
int margin = 20;
for (Area a : body)
if (a != null)
area.add(a);
Rectangle2D bounds = area.getBounds2D();
return new Rectangle2D.Double(bounds.getX() - margin, bounds.getY() - margin, bounds.getWidth() + 2 * margin, bounds.getHeight() + 2 * margin);
}
public enum OpenJackType {
MONO, STEREO, SWITCHED;
@@ -411,17 +411,5 @@ public class PilotLampHolder extends AbstractMultiPartComponent<String> {
protected double getTheta() {
return Math.toRadians(getAngle());
}
@Override
public Rectangle2D getCachingBounds() {
Area area = new Area();
Area[] body = getBody();
int margin = 20;
for (Area a : body)
if (a != null)
area.add(a);
Rectangle2D bounds = area.getBounds2D();
return new Rectangle2D.Double(bounds.getX() - margin, bounds.getY() - margin, bounds.getWidth() + 2 * margin, bounds.getHeight() + 2 * margin);
}
}
@@ -363,20 +363,6 @@ public class RotarySelectorSwitch extends AbstractMultiPartComponent<String> {
return false;
}
@Override
public Rectangle2D getCachingBounds() {
Area area = new Area();
Area[] body = getBody();
int margin = 20;
for (Area a : body)
if (a != null)
area.add(a);
Rectangle2D bounds = area.getBounds2D();
return new Rectangle2D.Double(bounds.getX() - margin, bounds.getY() - margin,
bounds.getWidth() + 2 * margin, bounds.getHeight() + 2 * margin);
}
public static enum RotaryPositionCount {
TWO(2), THREE(3), FOUR(4);
@@ -1,33 +1,31 @@
/*
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/>.
*/
*
* 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.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import javax.swing.JLabel;
import org.diylc.common.INetlistAnalyzer;
@@ -47,7 +45,7 @@ import org.diylc.core.IDIYComponent;
import org.diylc.netlist.Tree.ITreeWalker;
public class GuitarDiagramAnalyzer extends NetlistAnalyzer 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>();
@@ -55,84 +53,92 @@ public class GuitarDiagramAnalyzer extends NetlistAnalyzer implements INetlistAn
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());
CAP_TYPES.add(RadialCeramicDiskCapacitor.class.getCanonicalName());
CAP_TYPES.add(RadialFilmCapacitor.class.getCanonicalName());
CAP_TYPES.add(AxialFilmCapacitor.class.getCanonicalName());
}
@Override
public String getName() {
public String getName() {
return "Analyze Guitar Diagrams";
}
@Override
public String getShortName() {
return "guitar-diagrams";
}
@Override
public String getIconName() {
return "Guitar";
}
@Override
public String getFontName() {
public String getFontName() {
return new JLabel().getFont().getName();
}
private int positiveCount;
private int negativeCount;
private int noiseCount;
protected Summary summarize(Netlist netlist, Node preferredOutput) throws TreeException {
List<String> notes = new ArrayList<String>();
Tree tree = constructTree(netlist);
Tree pickupTree = tree.filter(PICKUP_TYPES);
if (pickupTree == null || pickupTree.getChildren().isEmpty()) {
notes.add("No pickups are detected in this switch configuration");
} else {
positiveCount = 0;
negativeCount = 0;
noiseCount = 0;
// analyze hum-cancellation and phase
pickupTree.walk(new ITreeWalker() {
@Override
public void visit(Tree t) {
}
public void visit(Tree t) {}
@Override
public void visit(TreeLeaf l) {
if ((l.toString().toLowerCase().contains("north") && (l.toString().toLowerCase().contains("->"))) ||
(l.toString().toLowerCase().contains("south") && (l.toString().toLowerCase().contains("<-"))))
if ((l.toString().toLowerCase().contains("north")
&& (l.toString().toLowerCase().contains("->")))
|| (l.toString().toLowerCase().contains("south")
&& (l.toString().toLowerCase().contains("<-"))))
noiseCount++;
if ((l.toString().toLowerCase().contains("north") && (l.toString().toLowerCase().contains("<-"))) ||
(l.toString().toLowerCase().contains("south") && (l.toString().toLowerCase().contains("->"))))
if ((l.toString().toLowerCase().contains("north")
&& (l.toString().toLowerCase().contains("<-")))
|| (l.toString().toLowerCase().contains("south")
&& (l.toString().toLowerCase().contains("->"))))
noiseCount--;
if (l.toString().toLowerCase().contains("->"))
positiveCount++;
if (l.toString().toLowerCase().contains("<-"))
negativeCount++;
}
}
});
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;
AbstractGuitarPickup pickup = (AbstractGuitarPickup) c;
if (((AbstractGuitarPickup) c).isHumbucker()) {
TreeLeaf nLeaf = new TreeLeaf(pickup, 0, 1);
TreeLeaf sLeaf = new TreeLeaf(pickup, 2, 3);
@@ -141,8 +147,9 @@ public class GuitarDiagramAnalyzer extends NetlistAnalyzer implements INetlistAn
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 wired in humbucking mode with " + parent.getConnectionType().name().toLowerCase() + " coils");
if (nTree != null && sTree != null && parent != null) {
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 wired in coil-split mode");
}
@@ -154,53 +161,59 @@ public class GuitarDiagramAnalyzer extends NetlistAnalyzer implements INetlistAn
}
}
}
// 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;
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());
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;
if (humCancelling)
notes.add("This configuration is hum-cancelling");
else
notes.add("This configuration is NOT hum-cancelling");
if (positiveCount > 1 || negativeCount > 1 || (positiveCount == 1 && negativeCount == 1)) {
boolean inPhase = (positiveCount == 0 && negativeCount > 0) || (positiveCount > 0 && negativeCount == 0);
boolean inPhase =
(positiveCount == 0 && negativeCount > 0) || (positiveCount > 0 && negativeCount == 0);
if (inPhase)
notes.add("All pickup coils are wired in-phase");
else
notes.add("Some pickup coils are wired OUT-of-phase");
notes.add("Some pickup coils are wired OUT-of-phase");
}
// locate volume and tone pots
Map<IDIYComponent<?>, List<IDIYComponent<?>>> volPotPickupMap = new HashMap<IDIYComponent<?>, List<IDIYComponent<?>>>();
Map<IDIYComponent<?>, List<IDIYComponent<?>>> tonePotPickupMap = new HashMap<IDIYComponent<?>, List<IDIYComponent<?>>>();
Map<IDIYComponent<?>, List<IDIYComponent<?>>> tonePotPickupReverseMap = new HashMap<IDIYComponent<?>, List<IDIYComponent<?>>>();
Map<IDIYComponent<?>, List<IDIYComponent<?>>> volPotPickupReverseMap = new HashMap<IDIYComponent<?>, List<IDIYComponent<?>>>();
Map<IDIYComponent<?>, List<IDIYComponent<?>>> volPotPickupMap =
new HashMap<IDIYComponent<?>, List<IDIYComponent<?>>>();
Map<IDIYComponent<?>, List<IDIYComponent<?>>> tonePotPickupMap =
new HashMap<IDIYComponent<?>, List<IDIYComponent<?>>>();
Map<IDIYComponent<?>, List<IDIYComponent<?>>> tonePotPickupReverseMap =
new HashMap<IDIYComponent<?>, List<IDIYComponent<?>>>();
Map<IDIYComponent<?>, List<IDIYComponent<?>>> volPotPickupReverseMap =
new HashMap<IDIYComponent<?>, List<IDIYComponent<?>>>();
Set<IDIYComponent<?>> pots = tree.extractComponents(POT_TYPES);
for (IDIYComponent<?> pot : pots) {
TreeLeaf leaf1 = new TreeLeaf(pot, 0, 1);
TreeLeaf leaf2 = new TreeLeaf(pot, 1, 2);
Tree tree1 = tree.locate(leaf1, false);
Tree tree2 = tree.locate(leaf2, false);
if ((tree1 == null && tree2 != null) || (tree1 != null && tree2 == null)) {
boolean tonePotReversed = tree1 != null;
Tree t = tree1 == null ? tree2 : tree1;
@@ -210,7 +223,8 @@ public class GuitarDiagramAnalyzer extends NetlistAnalyzer implements INetlistAn
if (caps != null && caps.size() == 1) {
for (Map.Entry<IDIYComponent<?>, Tree> r : pickupRoots.entrySet()) {
Tree toneParent = tree.findCommonParent(p, r.getValue());
if (toneParent != null && toneParent.getConnectionType() == TreeConnectionType.Parallel) {
if (toneParent != null
&& toneParent.getConnectionType() == TreeConnectionType.Parallel) {
if (tonePotReversed) {
List<IDIYComponent<?>> pickupList = tonePotPickupReverseMap.get(pot);
if (pickupList == null) {
@@ -231,23 +245,25 @@ public class GuitarDiagramAnalyzer extends NetlistAnalyzer implements INetlistAn
}
}
}
// volume
if (tree1 == null || tree2 == null)
continue;
for (Map.Entry<IDIYComponent<?>, Tree> r : pickupRoots.entrySet()) {
Tree parent1 = tree.findCommonParent(tree1, r.getValue());
Tree parent2 = tree.findCommonParent(tree2, r.getValue());
if (parent1 != null && parent2 != null && parent1.getConnectionType() == TreeConnectionType.Series && parent2.getConnectionType() == TreeConnectionType.Parallel)
{
if (parent1 != null && parent2 != null
&& parent1.getConnectionType() == TreeConnectionType.Series
&& parent2.getConnectionType() == TreeConnectionType.Parallel) {
List<IDIYComponent<?>> pickupList = volPotPickupMap.get(pot);
if (pickupList == null) {
pickupList = new ArrayList<IDIYComponent<?>>();
volPotPickupMap.put(pot, pickupList);
}
pickupList.add(r.getKey());
} else if (parent1 != null && parent2 != null && parent1.getConnectionType() == TreeConnectionType.Parallel && parent2.getConnectionType() == TreeConnectionType.Series)
{
} else if (parent1 != null && parent2 != null
&& parent1.getConnectionType() == TreeConnectionType.Parallel
&& parent2.getConnectionType() == TreeConnectionType.Series) {
List<IDIYComponent<?>> pickupList = volPotPickupReverseMap.get(pot);
if (pickupList == null) {
pickupList = new ArrayList<IDIYComponent<?>>();
@@ -257,81 +273,97 @@ public class GuitarDiagramAnalyzer extends NetlistAnalyzer implements INetlistAn
}
}
}
for (Map.Entry<IDIYComponent<?>, List<IDIYComponent<?>>> e : volPotPickupMap.entrySet()) {
StringBuilder sb = new StringBuilder("'" + e.getKey().getName() + "' potentiometer acts as a volume control for ");
boolean first = true;
for (IDIYComponent<?> c : e.getValue()) {
StringBuilder sb = new StringBuilder(
"'" + e.getKey().getName() + "' potentiometer acts as a volume control for ");
boolean first = true;
List<String> pickupNames =
e.getValue().stream().map(x -> x.getName()).sorted().collect(Collectors.toList());
for (String pickupName : pickupNames) {
if (!first)
sb.append(e.getValue().size() == 2 ? " and " : ", ");
sb.append(pickupNames.size() == 2 ? " and " : ", ");
first = false;
sb.append("'").append(c.getName()).append("'");
sb.append("'").append(pickupName).append("'");
}
notes.add(sb.toString());
notes.add(sb.toString());
}
for (Map.Entry<IDIYComponent<?>, List<IDIYComponent<?>>> e : volPotPickupReverseMap.entrySet()) {
StringBuilder sb = new StringBuilder("'" + e.getKey().getName() + "' potentiometer acts as a volume control for ");
boolean first = true;
for (IDIYComponent<?> c : e.getValue()) {
for (Map.Entry<IDIYComponent<?>, List<IDIYComponent<?>>> e : volPotPickupReverseMap
.entrySet()) {
StringBuilder sb = new StringBuilder(
"'" + e.getKey().getName() + "' potentiometer acts as a volume control for ");
boolean first = true;
List<String> pickupNames =
e.getValue().stream().map(x -> x.getName()).sorted().collect(Collectors.toList());
for (String pickupName : pickupNames) {
if (!first)
sb.append(e.getValue().size() == 2 ? " and " : ", ");
sb.append(pickupNames.size() == 2 ? " and " : ", ");
first = false;
sb.append("'").append(c.getName()).append("'");
sb.append("'").append(pickupName).append("'");
}
sb.append(", but is wired in REVERSE!");
notes.add(sb.toString());
}
}
for (Map.Entry<IDIYComponent<?>, List<IDIYComponent<?>>> e : tonePotPickupMap.entrySet()) {
StringBuilder sb = new StringBuilder("'" + e.getKey().getName() + "' potentiometer acts as a tone control for ");
boolean first = true;
for (IDIYComponent<?> c : e.getValue()) {
StringBuilder sb = new StringBuilder(
"'" + e.getKey().getName() + "' potentiometer acts as a tone control for ");
boolean first = true;
List<String> pickupNames =
e.getValue().stream().map(x -> x.getName()).sorted().collect(Collectors.toList());
for (String pickupName : pickupNames) {
if (!first)
sb.append(e.getValue().size() == 2 ? " and " : ", ");
sb.append(pickupNames.size() == 2 ? " and " : ", ");
first = false;
sb.append("'").append(c.getName()).append("'");
sb.append("'").append(pickupName).append("'");
}
notes.add(sb.toString());
notes.add(sb.toString());
}
for (Map.Entry<IDIYComponent<?>, List<IDIYComponent<?>>> e : tonePotPickupReverseMap.entrySet()) {
StringBuilder sb = new StringBuilder("'" + e.getKey().getName() + "' potentiometer acts as a tone control for ");
boolean first = true;
for (IDIYComponent<?> c : e.getValue()) {
for (Map.Entry<IDIYComponent<?>, List<IDIYComponent<?>>> e : tonePotPickupReverseMap
.entrySet()) {
StringBuilder sb = new StringBuilder(
"'" + e.getKey().getName() + "' potentiometer acts as a tone control for ");
boolean first = true;
List<String> pickupNames =
e.getValue().stream().map(x -> x.getName()).sorted().collect(Collectors.toList());
for (String pickupName : pickupNames) {
if (!first)
sb.append(e.getValue().size() == 2 ? " and " : ", ");
sb.append(pickupNames.size() == 2 ? " and " : ", ");
first = false;
sb.append("'").append(c.getName()).append("'");
sb.append("'").append(pickupName).append("'");
}
sb.append(", but is wired in REVERSE!");
notes.add(sb.toString());
}
}
}
StringBuilder sb = new StringBuilder();
sb.append("Parallel/Series connectivity tree:<br><br>").append(tree.toHTML(0));
if (!notes.isEmpty())
if (!notes.isEmpty()) {
Collections.sort(notes);
sb.append("<br><br>Notes:<br>");
for (String v : notes) {
sb.append("&nbsp;&nbsp;").append(v).append("<br>");
for (String v : notes) {
sb.append("&nbsp;&nbsp;").append(v).append("<br>");
}
}
return new Summary(netlist, sb.toString());
}
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 {
} else {
Node jackTip = jackTipNodes.get(0);
Node jackSleeve = jackSleeveNodes.get(0);
Node jackSleeve = jackSleeveNodes.get(0);
return constructTreeBetween(netlist, jackTip, jackSleeve);
}
}
@@ -21,11 +21,11 @@
*/
package org.diylc.netlist;
import java.text.Collator;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;
import org.diylc.common.INetlistAnalyzer;
import org.diylc.core.IDIYComponent;
@@ -38,6 +38,11 @@ public class SpiceAnalyzer extends NetlistAnalyzer implements INetlistAnalyzer {
public String getName() {
return "Generate Spice Netlist";
}
@Override
public String getShortName() {
return "spice";
}
@Override
public String getIconName() {
@@ -51,16 +56,7 @@ public class SpiceAnalyzer extends NetlistAnalyzer implements INetlistAnalyzer {
protected Summary summarize(Netlist netlist, Node preferredOutput) throws TreeException {
// grab all components that are in the netlist
List<IDIYComponent<?>> allComponents = new ArrayList<IDIYComponent<?>>(extractComponents(netlist));
Collections.sort(allComponents, new Comparator<IDIYComponent<?>>() {
@Override
public int compare(IDIYComponent<?> o1, IDIYComponent<?> o2) {
return o1.getName().compareToIgnoreCase(o2.getName());
}
});
StringBuilder sb = new StringBuilder();
List<IDIYComponent<?>> allComponents = netlist.getComponents();
List<Group> groups = netlist.getSortedGroups();
int unconnectedIndex = groups.size();
@@ -71,7 +67,10 @@ public class SpiceAnalyzer extends NetlistAnalyzer implements INetlistAnalyzer {
maxLen = c.getName().length();
}
for (IDIYComponent<?> c : allComponents) {
List<String> lines = new ArrayList<String>();
for (IDIYComponent<?> c : allComponents) {
StringBuilder sb = new StringBuilder();
// change the prefix to match spice convention if needed
String name = c.getName();
String prefix = null;
@@ -90,18 +89,18 @@ public class SpiceAnalyzer extends NetlistAnalyzer implements INetlistAnalyzer {
if (c.getControlPointNodeName(i) == null)
continue;
int pointIndex = i;
int pointIndex = i;
// remap if needed
if (c instanceof ISpiceMapper)
pointIndex = ((ISpiceMapper)c).mapToSpiceNode(pointIndex);
int nodeIndex = find(new Node(c, pointIndex), groups);
if (nodeIndex < 0)
nodeIndex = unconnectedIndex++;
// 1-based convention
nodeIndex++;
// remap if needed
if (c instanceof ISpiceMapper)
pointIndex = ((ISpiceMapper)c).mapToSpiceNode(pointIndex);
nodeIndex++;
nodeIndices.add(nodeIndex);
}
@@ -120,9 +119,13 @@ public class SpiceAnalyzer extends NetlistAnalyzer implements INetlistAnalyzer {
sb.append(" ; ").append(comment);
}
sb.append("<br>");
lines.add(sb.toString());
}
return new Summary(netlist, sb.toString());
return new Summary(netlist, lines
.stream()
.sorted()
.collect(Collectors.joining("\n")));
}
private static String formatSpiceNode(int i) {
@@ -43,7 +43,7 @@ public class GuitarNetlistAnalyzerTests {
OpenJack1_4 jack = new OpenJack1_4();
SingleCoilPickup pickup = new SingleCoilPickup();
pickup.setName("Pickup");
Netlist netlist = new Netlist();
Netlist netlist = new Netlist(Arrays.asList(jack, pickup));
Group tipGroup = new Group().connect(jack, 0).connect(pickup, 1);
Group sleeveGroup = new Group().connect(jack, 1).connect(pickup, 2);
netlist.add(tipGroup).add(sleeveGroup);
@@ -59,7 +59,7 @@ public class GuitarNetlistAnalyzerTests {
pickup.setName("Pickup");
PotentiometerPanel vol = new PotentiometerPanel();
vol.setName("Volume");
Netlist netlist = new Netlist();
Netlist netlist = new Netlist(Arrays.asList(jack, pickup, vol));
Group hotGroup = new Group().connect(pickup, 1).connect(vol, 0);
Group tipGroup = new Group().connect(jack, 0).connect(vol, 1);
Group sleeveGroup = new Group().connect(jack, 1).connect(pickup, 2).connect(vol, 2);
@@ -80,7 +80,7 @@ public class GuitarNetlistAnalyzerTests {
tone.setName("Tone");
RadialCeramicDiskCapacitor cap = new RadialCeramicDiskCapacitor();
cap.setName("Cap");
Netlist netlist = new Netlist();
Netlist netlist = new Netlist(Arrays.asList(jack, pickup, vol, tone, cap));
Group hotGroup = new Group().connect(pickup, 1).connect(vol, 0).connect(tone, 2);
Group tipGroup = new Group().connect(jack, 0).connect(vol, 1);
Group sleeveGroup = new Group().connect(jack, 1).connect(pickup, 2).connect(vol, 2).connect(cap, 0);
@@ -108,7 +108,7 @@ public class GuitarNetlistAnalyzerTests {
cap1.setName("Cap1");
RadialCeramicDiskCapacitor cap2 = new RadialCeramicDiskCapacitor();
cap2.setName("Cap2");
Netlist netlist = new Netlist();
Netlist netlist = new Netlist(Arrays.asList(jack, pickup1, pickup2, vol, tone1, tone2, cap1, cap2));
Group hotGroup = new Group().connect(pickup1, 1).connect(vol, 0).connect(tone1, 2).connect(pickup2, 1).connect(tone2, 2);
Group tipGroup = new Group().connect(jack, 0).connect(vol, 1);
Group sleeveGroup = new Group().connect(jack, 1).connect(pickup1, 2).connect(pickup2, 2).connect(vol, 2).connect(cap1, 0).connect(cap2, 0);
@@ -125,7 +125,7 @@ public class GuitarNetlistAnalyzerTests {
OpenJack1_4 jack = new OpenJack1_4();
SingleCoilPickup pickup = new SingleCoilPickup();
pickup.setName("Pickup");
Netlist netlist = new Netlist();
Netlist netlist = new Netlist(Arrays.asList(jack, pickup));
Group tipGroup = new Group().connect(jack, 0).connect(pickup, 2);
Group sleeveGroup = new Group().connect(jack, 1).connect(pickup, 1);
netlist.add(tipGroup).add(sleeveGroup);
@@ -139,7 +139,7 @@ public class GuitarNetlistAnalyzerTests {
OpenJack1_4 jack = new OpenJack1_4();
HumbuckerPickup pickup = new HumbuckerPickup();
pickup.setName("Pickup");
Netlist netlist = new Netlist();
Netlist netlist = new Netlist(Arrays.asList(jack, pickup));
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);
@@ -154,7 +154,7 @@ public class GuitarNetlistAnalyzerTests {
OpenJack1_4 jack = new OpenJack1_4();
HumbuckerPickup pickup = new HumbuckerPickup();
pickup.setName("Pickup");
Netlist netlist = new Netlist();
Netlist netlist = new Netlist(Arrays.asList(jack, pickup));
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);
@@ -169,7 +169,7 @@ public class GuitarNetlistAnalyzerTests {
OpenJack1_4 jack = new OpenJack1_4();
HumbuckerPickup pickup = new HumbuckerPickup();
pickup.setName("Pickup");
Netlist netlist = new Netlist();
Netlist netlist = new Netlist(Arrays.asList(jack, pickup));
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.add(tipGroup).add(sleeveGroup);
@@ -183,7 +183,7 @@ public class GuitarNetlistAnalyzerTests {
OpenJack1_4 jack = new OpenJack1_4();
HumbuckerPickup pickup = new HumbuckerPickup();
pickup.setName("Pickup");
Netlist netlist = new Netlist();
Netlist netlist = new Netlist(Arrays.asList(jack, pickup));
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.add(tipGroup).add(sleeveGroup);
@@ -199,7 +199,7 @@ public class GuitarNetlistAnalyzerTests {
pickup1.setName("Pickup1");
HumbuckerPickup pickup2 = new HumbuckerPickup();
pickup2.setName("Pickup2");
Netlist netlist = new Netlist();
Netlist netlist = new Netlist(Arrays.asList(jack, pickup1, pickup2));
Group tipGroup = new Group().connect(jack, 0).connect(pickup1, 0);
Group coilTapGroup1 = new Group().connect(pickup1, 1).connect(pickup1, 2);
Group coilTapGroup2 = new Group().connect(pickup2, 1).connect(pickup2, 2);
@@ -218,7 +218,7 @@ public class GuitarNetlistAnalyzerTests {
pickup1.setName("Pickup1");
HumbuckerPickup pickup2 = new HumbuckerPickup();
pickup2.setName("Pickup2");
Netlist netlist = new Netlist();
Netlist netlist = new Netlist(Arrays.asList(jack, pickup1, pickup2));
Group tipGroup = new Group().connect(jack, 0).connect(pickup1, 0).connect(pickup2, 0);
Group coilTapGroup1 = new Group().connect(pickup1, 1).connect(pickup1, 2);
Group coilTapGroup2 = new Group().connect(pickup2, 1).connect(pickup2, 2);
@@ -236,7 +236,7 @@ public class GuitarNetlistAnalyzerTests {
pickup1.setName("Pickup1");
HumbuckerPickup pickup2 = new HumbuckerPickup();
pickup2.setName("Pickup2");
Netlist netlist = new Netlist();
Netlist netlist = new Netlist(Arrays.asList(jack, pickup1, pickup2));
Group tipGroup = new Group().connect(jack, 0).connect(pickup1, 0).connect(pickup2, 3);
Group coilTapGroup1 = new Group().connect(pickup1, 1).connect(pickup1, 2);
Group coilTapGroup2 = new Group().connect(pickup2, 1).connect(pickup2, 2);
@@ -264,7 +264,7 @@ public class GuitarNetlistAnalyzerTests {
cap1.setName("Cap1");
RadialCeramicDiskCapacitor cap2 = new RadialCeramicDiskCapacitor();
cap2.setName("Cap2");
Netlist netlist = new Netlist();
Netlist netlist = new Netlist(Arrays.asList(jack, pickup1, pickup2, vol, tone1, tone2, cap1, cap2));
Group hotGroup = new Group().connect(pickup1, 0).connect(vol, 0).connect(tone1, 2).connect(pickup2, 0).connect(tone2, 2);
Group tipGroup = new Group().connect(jack, 0).connect(vol, 1);
Group sleeveGroup = new Group().connect(jack, 1).connect(pickup1, 3).connect(pickup2, 3).connect(vol, 2).connect(cap1, 0).connect(cap2, 0);