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
@@ -26,7 +26,6 @@ import java.util.List;
import org.diylc.netlist.Netlist; import org.diylc.netlist.Netlist;
import org.diylc.netlist.Node; import org.diylc.netlist.Node;
import org.diylc.netlist.Summary; import org.diylc.netlist.Summary;
import org.diylc.netlist.Tree;
import org.diylc.netlist.TreeException; import org.diylc.netlist.TreeException;
public interface INetlistAnalyzer { public interface INetlistAnalyzer {
@@ -50,12 +49,9 @@ public interface INetlistAnalyzer {
* @throws TreeException * @throws TreeException
*/ */
List<Summary> summarize(List<Netlist> netlists, Node preferredOutput) throws TreeException; List<Summary> summarize(List<Netlist> netlists, Node preferredOutput) throws TreeException;
/** /**
* * @return name of the font to be used for display.
* @param netlist
* @return
* @throws TreeException
*/ */
Tree constructTree(Netlist netlist) throws TreeException; String getFontName();
} }
@@ -381,6 +381,21 @@ public class NetlistAnalyzer {
protected String extractName(IDIYComponent<?> c) { protected String extractName(IDIYComponent<?> c) {
return c.getName() + " " + c.getValueForDisplay(); return c.getName() + " " + c.getValueForDisplay();
} }
protected Set<IDIYComponent<?>> extractComponents(Netlist netlist) {
Set<IDIYComponent<?>> res = new HashSet<IDIYComponent<?>>();
for (Group g : netlist.getGroups())
for (Node n : g.getNodes())
res.add(n.getComponent());
return res;
}
protected int find(Node node, List<Group> groups) {
for (int i = 0; i < groups.size(); i++)
if (groups.get(i).getNodes().contains(node))
return i;
return -1;
}
protected List<String> extractNames(Collection<IDIYComponent<?>> components) { protected List<String> extractNames(Collection<IDIYComponent<?>> components) {
List<String> names = new ArrayList<String>(); List<String> names = new ArrayList<String>();
@@ -21,31 +21,24 @@
*/ */
package org.diylc.netlist; package org.diylc.netlist;
import java.util.List;
public class Summary { public class Summary {
private Netlist netlist; private Netlist netlist;
private List<String> notes; private String summary;
private Tree tree;
public Summary(Netlist netlist, List<String> notes, Tree tree) { public Summary(Netlist netlist, String summary) {
super(); super();
this.netlist = netlist; this.netlist = netlist;
this.notes = notes; this.summary = summary;
this.tree = tree;
} }
public Netlist getNetlist() { public Netlist getNetlist() {
return netlist; return netlist;
} }
public List<String> getNotes() { public String getSummary() {
return notes; return summary;
}
public Tree getTree() {
return tree;
} }
@Override @Override
@@ -53,7 +46,7 @@ public class Summary {
final int prime = 31; final int prime = 31;
int result = 1; int result = 1;
result = prime * result + ((netlist == null) ? 0 : netlist.hashCode()); result = prime * result + ((netlist == null) ? 0 : netlist.hashCode());
result = prime * result + ((notes == null) ? 0 : notes.hashCode()); result = prime * result + ((summary == null) ? 0 : summary.hashCode());
return result; return result;
} }
@@ -71,16 +64,16 @@ public class Summary {
return false; return false;
} else if (!netlist.equals(other.netlist)) } else if (!netlist.equals(other.netlist))
return false; return false;
if (notes == null) { if (summary == null) {
if (other.notes != null) if (other.summary != null)
return false; return false;
} else if (!notes.equals(other.notes)) } else if (!summary.equals(other.summary))
return false; return false;
return true; return true;
} }
@Override @Override
public String toString() { public String toString() {
return notes.toString(); return summary.toString();
} }
} }
@@ -2930,6 +2930,15 @@ public class Presenter implements IPlugInPort {
result.add((INetlistAnalyzer) clazz.newInstance()); result.add((INetlistAnalyzer) clazz.newInstance());
} }
} }
Collections.sort(result, new Comparator<INetlistAnalyzer>() {
@Override
public int compare(INetlistAnalyzer o1, INetlistAnalyzer o2) {
return o1.getName().compareToIgnoreCase(o2.getName());
}
});
return result; return result;
} catch (Exception e) { } catch (Exception e) {
LOG.error("Could not load INetlistSummarizer implementations", e); LOG.error("Could not load INetlistSummarizer implementations", e);
Binary file not shown.
@@ -28,6 +28,8 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import javax.swing.JLabel;
import org.diylc.common.INetlistAnalyzer; import org.diylc.common.INetlistAnalyzer;
import org.diylc.components.electromechanical.ClosedJack1_4; import org.diylc.components.electromechanical.ClosedJack1_4;
import org.diylc.components.electromechanical.OpenJack1_4; import org.diylc.components.electromechanical.OpenJack1_4;
@@ -69,13 +71,18 @@ public class GuitarDiagramAnalyzer extends NetlistAnalyzer implements INetlistAn
@Override @Override
public String getName() { public String getName() {
return "Guitar Diagrams"; return "Analyze Guitar Diagrams (beta)";
} }
@Override @Override
public String getIconName() { public String getIconName() {
return "Guitar"; return "Guitar";
} }
@Override
public String getFontName() {
return new JLabel().getFont().getName();
}
public List<Summary> summarize(List<Netlist> netlists, Node preferredOutput) throws TreeException { public List<Summary> summarize(List<Netlist> netlists, Node preferredOutput) throws TreeException {
List<Summary> summaries = new ArrayList<Summary>(); 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 { public Tree constructTree(Netlist netlist) throws TreeException {
List<Node> jackTipNodes = find(JACK_TYPES, "Tip", netlist); List<Node> jackTipNodes = find(JACK_TYPES, "Tip", netlist);
List<Node> jackSleeveNodes = find(JACK_TYPES, "Sleeve", 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;
}
}
Binary file not shown.
Binary file not shown.
@@ -63,7 +63,8 @@ public enum IconLoader {
"component_add.png"), History("history.png"), DocumentPlain("document_plain.png"), FitToSize("fit_to_size.png"), DocumentsGear( "component_add.png"), History("history.png"), DocumentPlain("document_plain.png"), FitToSize("fit_to_size.png"), DocumentsGear(
"documents_gear.png"), SplashResistor("splash_resistor.png"), SplashCeramic("splash_ceramic.png"), SplashElectrolytic( "documents_gear.png"), SplashResistor("splash_resistor.png"), SplashCeramic("splash_ceramic.png"), SplashElectrolytic(
"splash_electrolytic.png"), SplashFilm("splash_film.png"), Splash("splash.png"), Help("help2.png"), ScrollInformation("scroll_information.png"), "splash_electrolytic.png"), SplashFilm("splash_film.png"), Splash("splash.png"), Help("help2.png"), ScrollInformation("scroll_information.png"),
Node("node.png"), Web("web.png"), Guitar("guitar.png"), Scientist("scientist.png"), StarGrey("star_grey.png"), StarBlue("star_blue.png"); Node("node.png"), Web("web.png"), Guitar("guitar.png"), Scientist("scientist.png"), StarGrey("star_grey.png"), StarBlue("star_blue.png"),
JarBeanInto("jar_bean_into.png");
protected String name; protected String name;
Binary file not shown.

After

Width:  |  Height:  |  Size: 978 B

@@ -1657,7 +1657,7 @@ public class ActionFactory {
super(); super();
this.plugInPort = plugInPort; this.plugInPort = plugInPort;
this.swingUI = swingUI; this.swingUI = swingUI;
putValue(AbstractAction.NAME, "Create Netlist (beta)"); putValue(AbstractAction.NAME, "Create DIYLC Netlist");
putValue(AbstractAction.SMALL_ICON, IconLoader.Web.getIcon()); putValue(AbstractAction.SMALL_ICON, IconLoader.Web.getIcon());
} }
@@ -1665,7 +1665,7 @@ public class ActionFactory {
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
List<Netlist> res = plugInPort.extractNetlists(); List<Netlist> res = plugInPort.extractNetlists();
if (res == null) { if (res == null) {
swingUI.showMessage("The generated netlist is empty, nothing to show.", "Netlist", ISwingUI.INFORMATION_MESSAGE); swingUI.showMessage("The generated netlist is empty, nothing to show.", "DIYLC Netlist", ISwingUI.INFORMATION_MESSAGE);
return; return;
} }
StringBuilder sb = new StringBuilder("<html>"); StringBuilder sb = new StringBuilder("<html>");
@@ -1678,7 +1678,7 @@ public class ActionFactory {
sb.append("</p><br><hr>"); sb.append("</p><br><hr>");
} }
sb.append("</html>"); sb.append("</html>");
new TextDialog(swingUI.getOwnerFrame().getRootPane(), sb.toString(), "Netlist", new Dimension(600, 480)).setVisible(true); new TextDialog(swingUI.getOwnerFrame().getRootPane(), sb.toString(), "DIYLC Netlist", new Dimension(600, 480)).setVisible(true);
} }
} }
@@ -1695,7 +1695,7 @@ public class ActionFactory {
this.plugInPort = plugInPort; this.plugInPort = plugInPort;
this.swingUI = swingUI; this.swingUI = swingUI;
this.summarizer = summarizer; this.summarizer = summarizer;
putValue(AbstractAction.NAME, "Analyze " + summarizer.getName() + " (beta)"); putValue(AbstractAction.NAME, summarizer.getName());
putValue(AbstractAction.SMALL_ICON, Enum.valueOf(IconLoader.class, summarizer.getIconName()).getIcon()); putValue(AbstractAction.SMALL_ICON, Enum.valueOf(IconLoader.class, summarizer.getIconName()).getIcon());
} }
@@ -1703,7 +1703,7 @@ public class ActionFactory {
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
List<Netlist> netlists = plugInPort.extractNetlists(); List<Netlist> netlists = plugInPort.extractNetlists();
if (netlists == null || netlists.isEmpty()) { if (netlists == null || netlists.isEmpty()) {
swingUI.showMessage("The generated netlist is empty, nothing to show.", "Analyze " + summarizer.getName(), ISwingUI.INFORMATION_MESSAGE); swingUI.showMessage("The generated netlist is empty, nothing to show.", summarizer.getName(), ISwingUI.INFORMATION_MESSAGE);
return; return;
} }
@@ -1711,29 +1711,35 @@ public class ActionFactory {
try { try {
res = summarizer.summarize(netlists, null); res = summarizer.summarize(netlists, null);
} catch (Exception ex) { } catch (Exception ex) {
swingUI.showMessage(ex.getMessage(), "Analyze " + summarizer.getName(), ISwingUI.ERROR_MESSAGE); swingUI.showMessage(ex.getMessage(), summarizer.getName(), ISwingUI.ERROR_MESSAGE);
return; return;
} }
if (res == null) { if (res == null) {
swingUI.showMessage("The generated summary is empty, nothing to show.", "Analyze " + summarizer.getName(), ISwingUI.INFORMATION_MESSAGE); swingUI.showMessage("The generated summary is empty, nothing to show.", summarizer.getName(), ISwingUI.INFORMATION_MESSAGE);
return; return;
} }
StringBuilder sb = new StringBuilder("<html>"); StringBuilder sb = new StringBuilder("<html>");
for (Summary summary : res) { for (Summary summary : res) {
sb.append("<p style=\"font-family: " + new JLabel().getFont().getName() + "; font-size: 9px\"><b>Switch configuration: ").append(summary.getNetlist().getSwitchSetup()).append("</b><br><br>"); sb.append("<p style=\"font-family: ").
append(summarizer.getFontName()).
append("; font-size: 9px\">");
sb.append("Parallel/Series connectivity tree:<br><br>").append(summary.getTree().toHTML(0)); if (res.size() > 1)
if (!summary.getNotes().isEmpty()) sb.append("<b>Switch configuration: ").
sb.append("<br><br>Notes:<br>"); append(summary.getNetlist().getSwitchSetup()).
for (String v : summary.getNotes()) { append("</b><br><br>");
sb.append("&nbsp;&nbsp;").append(v).append("<br>");
} sb.append(summary.getSummary());
sb.append("</p><br><hr>");
sb.append("</p><br>");
if (res.size() > 1)
sb.append("<hr>");
} }
sb.append("</html>"); sb.append("</html>");
new TextDialog(swingUI.getOwnerFrame().getRootPane(), sb.toString(), "Analyze " + summarizer.getName(), new Dimension(600, 480)).setVisible(true); new TextDialog(swingUI.getOwnerFrame().getRootPane(), sb.toString(), summarizer.getName(), new Dimension(600, 480)).setVisible(true);
} }
} }
} }