mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-10 17:22:09 +10:00
netlist analyzer enhancements
This commit is contained in:
@@ -22,6 +22,7 @@
|
|||||||
package org.diylc.common;
|
package org.diylc.common;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import org.diylc.netlist.Netlist;
|
import org.diylc.netlist.Netlist;
|
||||||
import org.diylc.netlist.Node;
|
import org.diylc.netlist.Node;
|
||||||
@@ -59,4 +60,9 @@ public interface INetlistAnalyzer {
|
|||||||
* @return name of the font to be used for display.
|
* @return name of the font to be used for display.
|
||||||
*/
|
*/
|
||||||
String getFontName();
|
String getFontName();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return ability to process netlists with or without switches included.
|
||||||
|
*/
|
||||||
|
Set<NetlistSwitchPreference> getSwitchPreference();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
package org.diylc.common;
|
||||||
|
|
||||||
|
public enum NetlistSwitchPreference {
|
||||||
|
WITH, WITHOUT;
|
||||||
|
}
|
||||||
@@ -69,7 +69,7 @@ public class NetlistBuilder {
|
|||||||
.extractComponentTypeFrom((Class<? extends IDIYComponent<?>>) c.getClass());
|
.extractComponentTypeFrom((Class<? extends IDIYComponent<?>>) c.getClass());
|
||||||
|
|
||||||
// extract nodes
|
// extract nodes
|
||||||
if (!(c instanceof IContinuity) && !(c instanceof ICommonNode)) {
|
if (!(c instanceof IContinuity && !(c instanceof ISwitch)) && !(c instanceof ICommonNode)) {
|
||||||
// regular components, create a node per control point
|
// regular components, create a node per control point
|
||||||
for (int i = 0; i < c.getControlPointCount(); i++) {
|
for (int i = 0; i < c.getControlPointCount(); i++) {
|
||||||
String nodeName = c.getControlPointNodeName(i);
|
String nodeName = c.getControlPointNodeName(i);
|
||||||
@@ -415,8 +415,10 @@ public class NetlistBuilder {
|
|||||||
IDIYComponent<?> c = project.getComponents().get(z);
|
IDIYComponent<?> c = project.getComponents().get(z);
|
||||||
ComponentType type = ComponentProcessor.getInstance()
|
ComponentType type = ComponentProcessor.getInstance()
|
||||||
.extractComponentTypeFrom((Class<? extends IDIYComponent<?>>) c.getClass());
|
.extractComponentTypeFrom((Class<? extends IDIYComponent<?>>) c.getClass());
|
||||||
// handle direct connections
|
// handle direct connections or connections through a switch
|
||||||
if (c instanceof IContinuity) {
|
// when not using "includeSwitches" flag
|
||||||
|
if (c instanceof IContinuity &&
|
||||||
|
(!(c instanceof ISwitch) || switchPositions.isEmpty())) {
|
||||||
for (int i = 0; i < c.getControlPointCount() - 1; i++)
|
for (int i = 0; i < c.getControlPointCount() - 1; i++)
|
||||||
for (int j = i + 1; j < c.getControlPointCount(); j++)
|
for (int j = i + 1; j < c.getControlPointCount(); j++)
|
||||||
if (((IContinuity) c).arePointsConnected(i, j))
|
if (((IContinuity) c).arePointsConnected(i, j))
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ import java.util.stream.Collectors;
|
|||||||
import javax.swing.JLabel;
|
import javax.swing.JLabel;
|
||||||
|
|
||||||
import org.diylc.common.INetlistAnalyzer;
|
import org.diylc.common.INetlistAnalyzer;
|
||||||
|
import org.diylc.common.NetlistSwitchPreference;
|
||||||
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;
|
||||||
import org.diylc.components.guitar.AbstractGuitarPickup;
|
import org.diylc.components.guitar.AbstractGuitarPickup;
|
||||||
@@ -89,6 +90,10 @@ public class GuitarDiagramAnalyzer extends AbstractNetlistAnalyzer implements IN
|
|||||||
RC_TYPES.addAll(RESISTOR_TYPES);
|
RC_TYPES.addAll(RESISTOR_TYPES);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private int positiveCount;
|
||||||
|
private int negativeCount;
|
||||||
|
private int noiseCount;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return "Analyze Guitar Diagrams";
|
return "Analyze Guitar Diagrams";
|
||||||
@@ -109,10 +114,10 @@ public class GuitarDiagramAnalyzer extends AbstractNetlistAnalyzer implements IN
|
|||||||
return new JLabel().getFont().getName();
|
return new JLabel().getFont().getName();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
private int positiveCount;
|
public Set<NetlistSwitchPreference> getSwitchPreference() {
|
||||||
private int negativeCount;
|
return Set.of(NetlistSwitchPreference.WITH);
|
||||||
private int noiseCount;
|
}
|
||||||
|
|
||||||
protected Summary summarize(Netlist netlist, Node preferredOutput) throws TreeException {
|
protected Summary summarize(Netlist netlist, Node preferredOutput) throws TreeException {
|
||||||
List<String> notes = new ArrayList<String>();
|
List<String> notes = new ArrayList<String>();
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ package org.diylc.netlist;
|
|||||||
import java.util.*;
|
import java.util.*;
|
||||||
import javax.swing.JLabel;
|
import javax.swing.JLabel;
|
||||||
import org.diylc.common.INetlistAnalyzer;
|
import org.diylc.common.INetlistAnalyzer;
|
||||||
|
import org.diylc.common.NetlistSwitchPreference;
|
||||||
import org.diylc.components.connectivity.MultimeterProbe;
|
import org.diylc.components.connectivity.MultimeterProbe;
|
||||||
|
|
||||||
public class MultimeterAnalyzer extends AbstractNetlistAnalyzer implements INetlistAnalyzer {
|
public class MultimeterAnalyzer extends AbstractNetlistAnalyzer implements INetlistAnalyzer {
|
||||||
@@ -45,6 +46,11 @@ public class MultimeterAnalyzer extends AbstractNetlistAnalyzer implements INetl
|
|||||||
return new JLabel().getFont().getName();
|
return new JLabel().getFont().getName();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Set<NetlistSwitchPreference> getSwitchPreference() {
|
||||||
|
return EnumSet.allOf(NetlistSwitchPreference.class);
|
||||||
|
}
|
||||||
|
|
||||||
protected Summary summarize(Netlist netlist, Node preferredOutput) throws TreeException {
|
protected Summary summarize(Netlist netlist, Node preferredOutput) throws TreeException {
|
||||||
Tree tree = constructTree(netlist);
|
Tree tree = constructTree(netlist);
|
||||||
|
|
||||||
|
|||||||
@@ -21,11 +21,15 @@
|
|||||||
*/
|
*/
|
||||||
package org.diylc.netlist;
|
package org.diylc.netlist;
|
||||||
|
|
||||||
|
import java.lang.reflect.ParameterizedType;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.EnumSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import org.diylc.common.INetlistAnalyzer;
|
import org.diylc.common.INetlistAnalyzer;
|
||||||
|
import org.diylc.common.NetlistSwitchPreference;
|
||||||
import org.diylc.core.IDIYComponent;
|
import org.diylc.core.IDIYComponent;
|
||||||
import org.diylc.netlist.Group;
|
import org.diylc.netlist.Group;
|
||||||
import org.diylc.netlist.Netlist;
|
import org.diylc.netlist.Netlist;
|
||||||
@@ -33,6 +37,7 @@ import org.diylc.netlist.NetlistAnalyzer;
|
|||||||
import org.diylc.netlist.Node;
|
import org.diylc.netlist.Node;
|
||||||
import org.diylc.netlist.Summary;
|
import org.diylc.netlist.Summary;
|
||||||
import org.diylc.netlist.TreeException;
|
import org.diylc.netlist.TreeException;
|
||||||
|
import org.diylc.presenter.ComponentProcessor;
|
||||||
|
|
||||||
public class SpiceAnalyzer extends AbstractNetlistAnalyzer implements INetlistAnalyzer {
|
public class SpiceAnalyzer extends AbstractNetlistAnalyzer implements INetlistAnalyzer {
|
||||||
|
|
||||||
@@ -59,6 +64,11 @@ public class SpiceAnalyzer extends AbstractNetlistAnalyzer implements INetlistAn
|
|||||||
return "Courier New";
|
return "Courier New";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Set<NetlistSwitchPreference> getSwitchPreference() {
|
||||||
|
return EnumSet.allOf(NetlistSwitchPreference.class);
|
||||||
|
}
|
||||||
|
|
||||||
protected Summary summarize(Netlist netlist, Node preferredOutput) throws TreeException {
|
protected Summary summarize(Netlist netlist, Node preferredOutput) throws TreeException {
|
||||||
// grab all components that are in the netlist
|
// grab all components that are in the netlist
|
||||||
List<Group> groups = netlist.getSortedGroups();
|
List<Group> groups = netlist.getSortedGroups();
|
||||||
@@ -121,7 +131,7 @@ public class SpiceAnalyzer extends AbstractNetlistAnalyzer implements INetlistAn
|
|||||||
sb.append(" ");
|
sb.append(" ");
|
||||||
}
|
}
|
||||||
|
|
||||||
sb.append(c.getValue());
|
sb.append(formatValue(c));
|
||||||
|
|
||||||
if (c instanceof ISpiceMapper) {
|
if (c instanceof ISpiceMapper) {
|
||||||
String comment = ((ISpiceMapper)c).getComment();
|
String comment = ((ISpiceMapper)c).getComment();
|
||||||
@@ -138,6 +148,26 @@ public class SpiceAnalyzer extends AbstractNetlistAnalyzer implements INetlistAn
|
|||||||
.collect(Collectors.joining("\n")));
|
.collect(Collectors.joining("\n")));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static Object formatValue(IDIYComponent<?> c) {
|
||||||
|
if (c.getValue() == null || c.getValue().toString().trim().isEmpty()) {
|
||||||
|
String typeName = ComponentProcessor.getInstance()
|
||||||
|
.extractComponentTypeFrom((Class<? extends IDIYComponent<?>>) c.getClass()).getName();
|
||||||
|
// if (
|
||||||
|
// Void.class.equals(((ParameterizedType) c.getClass()
|
||||||
|
// .getGenericSuperclass()).getActualTypeArguments()[0])) {
|
||||||
|
// return typeName;
|
||||||
|
// }
|
||||||
|
if (typeName.contains(" ")) {
|
||||||
|
return "\"" + typeName + "\"";
|
||||||
|
}
|
||||||
|
return typeName;
|
||||||
|
}
|
||||||
|
if (c.getValue().toString().contains(" ")) {
|
||||||
|
return "\"" + c.getValue() + "\"";
|
||||||
|
}
|
||||||
|
return c.getValue();
|
||||||
|
}
|
||||||
|
|
||||||
private static String formatSpiceNode(int i) {
|
private static String formatSpiceNode(int i) {
|
||||||
return String.format("N%03d" , i);
|
return String.format("N%03d" , i);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -280,8 +280,8 @@ public class ActionFactory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public SummarizeNetlistAction createSummarizeNetlistAction(IPlugInPort plugInPort,
|
public SummarizeNetlistAction createSummarizeNetlistAction(IPlugInPort plugInPort,
|
||||||
ISwingUI swingUI, INetlistAnalyzer summarizer) {
|
ISwingUI swingUI, INetlistAnalyzer summarizer, boolean includeSwitches) {
|
||||||
return new SummarizeNetlistAction(plugInPort, swingUI, summarizer);
|
return new SummarizeNetlistAction(plugInPort, swingUI, summarizer, includeSwitches);
|
||||||
}
|
}
|
||||||
|
|
||||||
public CheckProximityAction createCheckProximityAction(IPlugInPort plugInPort, ISwingUI swingUI) {
|
public CheckProximityAction createCheckProximityAction(IPlugInPort plugInPort, ISwingUI swingUI) {
|
||||||
|
|||||||
+10
-3
@@ -22,14 +22,21 @@ public class SummarizeNetlistAction extends AbstractAction {
|
|||||||
private IPlugInPort plugInPort;
|
private IPlugInPort plugInPort;
|
||||||
private ISwingUI swingUI;
|
private ISwingUI swingUI;
|
||||||
private INetlistAnalyzer summarizer;
|
private INetlistAnalyzer summarizer;
|
||||||
|
private final boolean includeSwitches;
|
||||||
|
|
||||||
public SummarizeNetlistAction(IPlugInPort plugInPort, ISwingUI swingUI,
|
public SummarizeNetlistAction(IPlugInPort plugInPort, ISwingUI swingUI,
|
||||||
INetlistAnalyzer summarizer) {
|
INetlistAnalyzer summarizer, boolean includeSwitches) {
|
||||||
super();
|
super();
|
||||||
this.plugInPort = plugInPort;
|
this.plugInPort = plugInPort;
|
||||||
this.swingUI = swingUI;
|
this.swingUI = swingUI;
|
||||||
this.summarizer = summarizer;
|
this.summarizer = summarizer;
|
||||||
putValue(AbstractAction.NAME, summarizer.getName());
|
this.includeSwitches = includeSwitches;
|
||||||
|
String name = summarizer.getName();
|
||||||
|
if (summarizer.getSwitchPreference().size() > 1) {
|
||||||
|
name += includeSwitches ?
|
||||||
|
" (incl. Switches)" : " (excl. Switches)";
|
||||||
|
}
|
||||||
|
putValue(AbstractAction.NAME, name);
|
||||||
putValue(AbstractAction.SMALL_ICON,
|
putValue(AbstractAction.SMALL_ICON,
|
||||||
Enum.valueOf(IconLoader.class, summarizer.getIconName()).getIcon());
|
Enum.valueOf(IconLoader.class, summarizer.getIconName()).getIcon());
|
||||||
}
|
}
|
||||||
@@ -41,7 +48,7 @@ public class SummarizeNetlistAction extends AbstractAction {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Summary> doInBackground() throws Exception {
|
public List<Summary> doInBackground() throws Exception {
|
||||||
List<Netlist> netlists = plugInPort.extractNetlists(true);
|
List<Netlist> netlists = plugInPort.extractNetlists(includeSwitches);
|
||||||
if (netlists == null || netlists.isEmpty()) {
|
if (netlists == null || netlists.isEmpty()) {
|
||||||
throw new Exception("The generated netlist is empty, nothing to show.");
|
throw new Exception("The generated netlist is empty, nothing to show.");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,13 +24,9 @@ import java.util.EnumSet;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
import org.diylc.appframework.miscutils.ConfigurationManager;
|
import org.diylc.appframework.miscutils.ConfigurationManager;
|
||||||
|
import org.diylc.common.*;
|
||||||
import org.diylc.swing.IDynamicSubmenuHandler;
|
import org.diylc.swing.IDynamicSubmenuHandler;
|
||||||
|
|
||||||
import org.diylc.common.EventType;
|
|
||||||
import org.diylc.common.INetlistAnalyzer;
|
|
||||||
import org.diylc.common.IPlugIn;
|
|
||||||
import org.diylc.common.IPlugInPort;
|
|
||||||
import org.diylc.common.ITask;
|
|
||||||
import org.diylc.swing.ActionFactory;
|
import org.diylc.swing.ActionFactory;
|
||||||
import org.diylc.swing.ISwingUI;
|
import org.diylc.swing.ISwingUI;
|
||||||
import org.diylc.utils.IconLoader;
|
import org.diylc.utils.IconLoader;
|
||||||
@@ -108,11 +104,19 @@ public class FileMenuPlugin implements IPlugIn, IDynamicSubmenuHandler {
|
|||||||
|
|
||||||
List<INetlistAnalyzer> summarizers = plugInPort.getNetlistAnalyzers();
|
List<INetlistAnalyzer> summarizers = plugInPort.getNetlistAnalyzers();
|
||||||
if (summarizers != null) {
|
if (summarizers != null) {
|
||||||
for (INetlistAnalyzer summarizer : summarizers)
|
for (INetlistAnalyzer summarizer : summarizers) {
|
||||||
|
if (summarizer.getSwitchPreference().contains(NetlistSwitchPreference.WITH)) {
|
||||||
swingUI.injectMenuAction(
|
swingUI.injectMenuAction(
|
||||||
actionFactory.createSummarizeNetlistAction(plugInPort, swingUI, summarizer),
|
actionFactory.createSummarizeNetlistAction(plugInPort, swingUI, summarizer, true),
|
||||||
ANALYZE_TITLE);
|
ANALYZE_TITLE);
|
||||||
}
|
}
|
||||||
|
if (summarizer.getSwitchPreference().contains(NetlistSwitchPreference.WITHOUT)) {
|
||||||
|
swingUI.injectMenuAction(
|
||||||
|
actionFactory.createSummarizeNetlistAction(plugInPort, swingUI, summarizer, false),
|
||||||
|
ANALYZE_TITLE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
swingUI.injectMenuAction(null, FILE_TITLE);
|
swingUI.injectMenuAction(null, FILE_TITLE);
|
||||||
swingUI.injectSubmenu(INTEGRATION_TITLE, IconLoader.Node.getIcon(), FILE_TITLE);
|
swingUI.injectSubmenu(INTEGRATION_TITLE, IconLoader.Node.getIcon(), FILE_TITLE);
|
||||||
|
|||||||
Reference in New Issue
Block a user