Limit switch combinations for netlists

This commit is contained in:
Bane Stojkovic
2022-10-22 22:30:54 +02:00
parent c30c8da267
commit 93e0395ac5
3 changed files with 78 additions and 4 deletions
@@ -24,6 +24,7 @@ package org.diylc.common;
import java.util.List;
import org.diylc.netlist.INetlistParser;
import org.diylc.netlist.Netlist;
import org.diylc.netlist.NetlistException;
/**
* Interface for {@link Netlist} related operations.
@@ -37,8 +38,9 @@ public interface INetlistProcessor {
*
* @param includeSwitches
* @return
* @throws NetlistException
*/
List<Netlist> extractNetlists(boolean includeSwitches);
List<Netlist> extractNetlists(boolean includeSwitches) throws NetlistException;
/**
* Finds all available {@link INetlistAnalyzer} implementations.
@@ -0,0 +1,55 @@
/*
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;
public class NetlistException extends Exception {
private static final long serialVersionUID = 1L;
public NetlistException() {
super();
// TODO Auto-generated constructor stub
}
public NetlistException(String message, Throwable cause, boolean enableSuppression,
boolean writableStackTrace) {
super(message, cause, enableSuppression, writableStackTrace);
// TODO Auto-generated constructor stub
}
public NetlistException(String message, Throwable cause) {
super(message, cause);
// TODO Auto-generated constructor stub
}
public NetlistException(String message) {
super(message);
// TODO Auto-generated constructor stub
}
public NetlistException(Throwable cause) {
super(cause);
// TODO Auto-generated constructor stub
}
}
@@ -87,6 +87,7 @@ import org.diylc.netlist.INetlistParser;
import org.diylc.netlist.Netlist;
import org.diylc.netlist.NetlistAnalyzer;
import org.diylc.netlist.NetlistBuilder;
import org.diylc.netlist.NetlistException;
import org.diylc.netlist.Node;
import org.diylc.netlist.Position;
import org.diylc.netlist.SwitchSetup;
@@ -167,7 +168,8 @@ public class Presenter implements IPlugInPort {
public static final int ICON_SIZE = 32;
private static final int MAX_RECENT_FILES = 20;
private static final int MAX_RECENT_FILES = 20;
private static final int MAX_SWITCH_COMBINATIONS = 64;
private Project currentProject;
private Map<String, List<ComponentType>> componentTypes;
@@ -2092,7 +2094,13 @@ public class Presenter implements IPlugInPort {
// experimental mode using netlist to expand selection. Works fine but doesn't include any connectivity components
// like traces and wires, so it's not ideal
if (useNetlistForExpandSelection) {
List<Netlist> netlists = extractNetlists(false);
List<Netlist> netlists = null;
try {
netlists = extractNetlists(false);
} catch (NetlistException e1) {
// should never happen
LOG.warn("Unexpected netlist exception", e1);
}
if (netlists == null)
return;
@@ -3136,7 +3144,7 @@ public class Presenter implements IPlugInPort {
@SuppressWarnings("unchecked")
@Override
public List<Netlist> extractNetlists(boolean includeSwitches) {
public List<Netlist> extractNetlists(boolean includeSwitches) throws NetlistException {
Map<Netlist, Netlist> result = new HashMap<Netlist, Netlist>();
List<Node> nodes = new ArrayList<Node>();
@@ -3194,6 +3202,15 @@ public class Presenter implements IPlugInPort {
List<Area> continuityAreas = drawingManager.getContinuityAreas(currentProject);
int i = switches.size() - 1;
int totalSwitchCombinations = switches.stream()
.map(sw -> sw.getPositionCount())
.reduce(1, (a, b) -> a * b);
if (totalSwitchCombinations > MAX_SWITCH_COMBINATIONS) {
throw new NetlistException("Maximum number of switching combinations exceeded. Allowed: " + MAX_SWITCH_COMBINATIONS + ", actual: " + totalSwitchCombinations);
}
while (i >= 0) {
// process the current combination
Map<ISwitch, Integer> switchPositions = new HashMap<ISwitch, Integer>();