basic implementation of spice exporter

This commit is contained in:
Branislav Stojkovic
2019-03-09 14:46:00 +01:00
parent c893b37fdf
commit 54ff518438
12 changed files with 188 additions and 46 deletions
@@ -28,6 +28,8 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.swing.JLabel;
import org.diylc.common.INetlistAnalyzer;
import org.diylc.components.electromechanical.ClosedJack1_4;
import org.diylc.components.electromechanical.OpenJack1_4;
@@ -69,13 +71,18 @@ public class GuitarDiagramAnalyzer extends NetlistAnalyzer implements INetlistAn
@Override
public String getName() {
return "Guitar Diagrams";
return "Analyze Guitar Diagrams (beta)";
}
@Override
public String getIconName() {
return "Guitar";
}
@Override
public String getFontName() {
return new JLabel().getFont().getName();
}
public List<Summary> summarize(List<Netlist> netlists, Node preferredOutput) throws TreeException {
List<Summary> summaries = new ArrayList<Summary>();
@@ -309,11 +316,18 @@ public class GuitarDiagramAnalyzer extends NetlistAnalyzer implements INetlistAn
}
}
return new Summary(netlist, notes, tree);
StringBuilder sb = new StringBuilder();
sb.append("Parallel/Series connectivity tree:<br><br>").append(tree.toHTML(0));
if (!notes.isEmpty())
sb.append("<br><br>Notes:<br>");
for (String v : notes) {
sb.append("&nbsp;&nbsp;").append(v).append("<br>");
}
return new Summary(netlist, sb.toString());
}
@Override
public Tree constructTree(Netlist netlist) throws TreeException {
List<Node> jackTipNodes = find(JACK_TYPES, "Tip", netlist);
List<Node> jackSleeveNodes = find(JACK_TYPES, "Sleeve", netlist);
@@ -0,0 +1,108 @@
/*
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.Comparator;
import java.util.List;
import org.diylc.common.INetlistAnalyzer;
import org.diylc.core.IDIYComponent;
public class SpiceAnalyzer extends NetlistAnalyzer implements INetlistAnalyzer {
public SpiceAnalyzer() {
}
@Override
public String getName() {
return "Generate Spice Netlist (beta)";
}
@Override
public String getIconName() {
return "JarBeanInto";
}
@Override
public String getFontName() {
return "Courier New";
}
@Override
public List<Summary> summarize(List<Netlist> netlists, Node preferredOutput) throws TreeException {
List<Summary> summaries = new ArrayList<Summary>();
for (Netlist n : netlists)
summaries.add(summarize(n, preferredOutput));
return summaries;
}
private 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<Group> groups = netlist.getSortedGroups();
int unconnectedIndex = groups.size() + 1;
int maxLen = 0;
for (IDIYComponent<?> c : allComponents) {
if (c.getName().length() > maxLen)
maxLen = c.getName().length();
}
for (IDIYComponent<?> c : allComponents) {
sb.append(fill(c.getName(), (int) (Math.ceil(maxLen / 5.0) * 5)));
sb.append(" ");
for (int i = 0; i < c.getControlPointCount(); i++) {
int index = find(new Node(c, i), groups);
if (index < 0)
index = unconnectedIndex++;
else
index++;
sb.append(fill(Integer.toString(index), 5));
sb.append(" ");
}
sb.append(c.getValueForDisplay());
sb.append("<br>");
}
return new Summary(netlist, sb.toString());
}
private String fill(String source, int desiredLength) {
String res = source;
for (int i = 0; i < desiredLength - source.length(); i++)
res += "&nbsp;";
return res;
}
}