added ability to include or exclude switches from netlist analyzer

This commit is contained in:
Branislav Stojkovic
2019-03-23 18:05:28 +01:00
parent b85b93404b
commit 5c47ff1ef0
10 changed files with 31 additions and 29 deletions
@@ -35,9 +35,10 @@ public interface INetlistProcessor {
/** /**
* Finds all {@link Netlist}s for each switch position combination. * Finds all {@link Netlist}s for each switch position combination.
* *
* @param includeSwitches
* @return * @return
*/ */
List<Netlist> extractNetlists(); List<Netlist> extractNetlists(boolean includeSwitches);
/** /**
* Finds all available {@link INetlistAnalyzer} implementations. * Finds all available {@link INetlistAnalyzer} implementations.
@@ -1906,7 +1906,7 @@ public class Presenter implements IPlugInPort {
public void expandSelection(ExpansionMode expansionMode) { public void expandSelection(ExpansionMode expansionMode) {
LOG.info(String.format("expandSelection(%s)", expansionMode)); LOG.info(String.format("expandSelection(%s)", expansionMode));
List<IDIYComponent<?>> newSelection = new ArrayList<IDIYComponent<?>>(this.selectedComponents); List<IDIYComponent<?>> newSelection = new ArrayList<IDIYComponent<?>>(this.selectedComponents);
List<Netlist> netlists = extractNetlists(); List<Netlist> netlists = extractNetlists(false);
List<Set<IDIYComponent<?>>> allGroups = NetlistAnalyzer.extractComponentGroups(netlists); List<Set<IDIYComponent<?>>> allGroups = NetlistAnalyzer.extractComponentGroups(netlists);
// Find control points of all selected components and all types // Find control points of all selected components and all types
Set<String> selectedNamePrefixes = new HashSet<String>(); Set<String> selectedNamePrefixes = new HashSet<String>();
@@ -2699,11 +2699,12 @@ public class Presenter implements IPlugInPort {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Override @Override
public List<Netlist> extractNetlists() { public List<Netlist> extractNetlists(boolean includeSwitches) {
Map<Netlist, Netlist> result = new HashMap<Netlist, Netlist>(); Map<Netlist, Netlist> result = new HashMap<Netlist, Netlist>();
List<Node> nodes = new ArrayList<Node>(); List<Node> nodes = new ArrayList<Node>();
List<ISwitch> switches = new ArrayList<ISwitch>(); List<ISwitch> switches = new ArrayList<ISwitch>();
for (IDIYComponent<?> c : currentProject.getComponents()) { for (IDIYComponent<?> c : currentProject.getComponents()) {
ComponentType type = ComponentType type =
ComponentProcessor.getInstance().extractComponentTypeFrom((Class<? extends IDIYComponent<?>>) c.getClass()); ComponentProcessor.getInstance().extractComponentTypeFrom((Class<? extends IDIYComponent<?>>) c.getClass());
@@ -2712,14 +2713,14 @@ public class Presenter implements IPlugInPort {
if (!(c instanceof IContinuity)) { if (!(c instanceof IContinuity)) {
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);
if (nodeName != null) { if (nodeName != null && (!includeSwitches || !ISwitch.class.isAssignableFrom(type.getInstanceClass()))) {
nodes.add(new Node(c, i)); nodes.add(new Node(c, i));
} }
} }
} }
// extract switches // extract switches
if (ISwitch.class.isAssignableFrom(type.getInstanceClass())) if (includeSwitches && ISwitch.class.isAssignableFrom(type.getInstanceClass()))
switches.add((ISwitch) c); switches.add((ISwitch) c);
} }
Binary file not shown.
@@ -338,7 +338,7 @@ public abstract class AbstractLeadedComponent<T> extends AbstractTransparentComp
drawCenteredText(g2d, label, offset, 0, HorizontalAlignment.CENTER, VerticalAlignment.CENTER); drawCenteredText(g2d, label, offset, 0, HorizontalAlignment.CENTER, VerticalAlignment.CENTER);
g2d.setTransform(oldTransform); g2d.setTransform(oldTransform);
} else { } else {
if (getLabelOriantation() == LabelOriantation.Horizontal) { if (isStanding() || getLabelOriantation() == LabelOriantation.Horizontal) {
g2d.setTransform(oldTransform); g2d.setTransform(oldTransform);
double x = (getNewPoints()[0].x + getNewPoints()[1].x - length) / 2.0; double x = (getNewPoints()[0].x + getNewPoints()[1].x - length) / 2.0;
double y = (getNewPoints()[0].y + getNewPoints()[1].y - width) / 2.0; double y = (getNewPoints()[0].y + getNewPoints()[1].y - width) / 2.0;
@@ -393,12 +393,12 @@ public class MiniToggleSwitch extends AbstractTransparentComponent<ToggleSwitchT
} }
// switch stuff // switch stuff
//
@Override // @Override
public String getControlPointNodeName(int index) { // public String getControlPointNodeName(int index) {
// we don't want the switch to produce any nodes, it just makes connections // // we don't want the switch to produce any nodes, it just makes connections
return null; // return null;
} // }
@Override @Override
public boolean canPointMoveFreely(int pointIndex) { public boolean canPointMoveFreely(int pointIndex) {
@@ -328,12 +328,12 @@ public class LPSwitch extends AbstractTransparentComponent<String> implements IS
body = null; body = null;
} }
@Override // @Override
public String getControlPointNodeName(int index) { // public String getControlPointNodeName(int index) {
// we don't want the switch to produce any nodes, it just makes connections // // we don't want the switch to produce any nodes, it just makes connections
return null; // return null;
} // }
//
// switch stuff // switch stuff
@Override @Override
@@ -428,11 +428,11 @@ public class LeverSwitch extends AbstractTransparentComponent<String> implements
} }
} }
@Override // @Override
public String getControlPointNodeName(int index) { // public String getControlPointNodeName(int index) {
// we don't want the switch to produce any nodes, it just makes connections // // we don't want the switch to produce any nodes, it just makes connections
return null; // return null;
} // }
// switch stuff // switch stuff
Binary file not shown.
Binary file not shown.
@@ -1667,7 +1667,7 @@ public class ActionFactory {
@Override @Override
public List<Netlist> doInBackground() throws Exception { public List<Netlist> doInBackground() throws Exception {
return plugInPort.extractNetlists(); return plugInPort.extractNetlists(true);
} }
@Override @Override
@@ -1722,7 +1722,7 @@ public class ActionFactory {
@Override @Override
public List<Summary> doInBackground() throws Exception { public List<Summary> doInBackground() throws Exception {
List<Netlist> netlists = plugInPort.extractNetlists(); List<Netlist> netlists = plugInPort.extractNetlists(true);
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.");
} }