diff --git a/diylc/diylc-core/src/org/diylc/common/INetlistProcessor.java b/diylc/diylc-core/src/org/diylc/common/INetlistProcessor.java index fb1c5a4d..3f539d0c 100644 --- a/diylc/diylc-core/src/org/diylc/common/INetlistProcessor.java +++ b/diylc/diylc-core/src/org/diylc/common/INetlistProcessor.java @@ -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 extractNetlists(boolean includeSwitches); + List extractNetlists(boolean includeSwitches) throws NetlistException; /** * Finds all available {@link INetlistAnalyzer} implementations. diff --git a/diylc/diylc-core/src/org/diylc/netlist/NetlistException.java b/diylc/diylc-core/src/org/diylc/netlist/NetlistException.java new file mode 100644 index 00000000..60082357 --- /dev/null +++ b/diylc/diylc-core/src/org/diylc/netlist/NetlistException.java @@ -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 . + +*/ +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 + } + + +} diff --git a/diylc/diylc-core/src/org/diylc/presenter/Presenter.java b/diylc/diylc-core/src/org/diylc/presenter/Presenter.java index fab81d1e..120cb675 100644 --- a/diylc/diylc-core/src/org/diylc/presenter/Presenter.java +++ b/diylc/diylc-core/src/org/diylc/presenter/Presenter.java @@ -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> 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 netlists = extractNetlists(false); + List 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 extractNetlists(boolean includeSwitches) { + public List extractNetlists(boolean includeSwitches) throws NetlistException { Map result = new HashMap(); List nodes = new ArrayList(); @@ -3194,6 +3202,15 @@ public class Presenter implements IPlugInPort { List 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 switchPositions = new HashMap();