optimized net creation if nested models are used

This commit is contained in:
hneemann 2016-03-26 20:14:45 +01:00
parent c919d824fc
commit 6b7b778313
4 changed files with 28 additions and 9 deletions

View File

@ -7,22 +7,25 @@ import de.neemann.digital.core.element.Element;
import de.neemann.digital.gui.draw.elements.Circuit; import de.neemann.digital.gui.draw.elements.Circuit;
import de.neemann.digital.gui.draw.elements.PinException; import de.neemann.digital.gui.draw.elements.PinException;
import de.neemann.digital.gui.draw.model.ModelDescription; import de.neemann.digital.gui.draw.model.ModelDescription;
import de.neemann.digital.gui.draw.model.NetList;
/** /**
* @author hneemann * @author hneemann
*/ */
public class CustomElement implements Element { public class CustomElement implements Element {
private Circuit circuit; private final NetList netList;
private ElementLibrary library; private final Circuit circuit;
private final ElementLibrary library;
public CustomElement(Circuit circuit, ElementLibrary library) { public CustomElement(Circuit circuit, ElementLibrary library) {
this.circuit = circuit; this.circuit = circuit;
this.library = library; this.library = library;
netList = new NetList(circuit.getWires());
} }
public ModelDescription getModelDescription() throws PinException, NodeException { public ModelDescription getModelDescription() throws PinException, NodeException {
return new ModelDescription(circuit, library, true); return new ModelDescription(circuit, library, true, new NetList(netList));
} }
@Override @Override

View File

@ -37,10 +37,13 @@ public class ModelDescription implements Iterable<ModelEntry> {
public ModelDescription(Circuit circuit, ElementLibrary library) throws PinException, NodeException { public ModelDescription(Circuit circuit, ElementLibrary library) throws PinException, NodeException {
this(circuit, library, false); this(circuit, library, false);
} }
public ModelDescription(Circuit circuit, ElementLibrary library, boolean readAsCustom) throws PinException, NodeException { public ModelDescription(Circuit circuit, ElementLibrary library, boolean readAsCustom) throws PinException, NodeException {
this(circuit, library, readAsCustom, new NetList(circuit.getWires()));
}
public ModelDescription(Circuit circuit, ElementLibrary library, boolean readAsCustom, NetList netList) throws PinException, NodeException {
this.netList = netList;
entries = new ArrayList<>(); entries = new ArrayList<>();
netList = new NetList(circuit.getWires());
if (readAsCustom) if (readAsCustom)
ioMap = new HashMap<>(); ioMap = new HashMap<>();
else else
@ -73,7 +76,6 @@ public class ModelDescription implements Iterable<ModelEntry> {
for (Pin p : pins) for (Pin p : pins)
netList.add(p); netList.add(p);
} }

View File

@ -24,6 +24,12 @@ public class Net {
private final ArrayList<Pin> pins; private final ArrayList<Pin> pins;
private final ArrayList<Wire> wires; private final ArrayList<Wire> wires;
public Net(Net toCopy) {
points = toCopy.points; // no deep copy of points necessary
wires = null; // wires not needed
pins = new ArrayList<>(toCopy.pins); // Pins are changed so create a deep copy
}
public Net(Wire w) { public Net(Wire w) {
points = new HashSet<>(); points = new HashSet<>();
points.add(w.p1); points.add(w.p1);
@ -87,12 +93,13 @@ public class Net {
for (Pin i : inputs) for (Pin i : inputs)
i.setValue(value); i.setValue(value);
if (bindWiresToValues) if (bindWiresToValues && wires != null)
for (Wire w : wires) for (Wire w : wires)
w.setValue(value); w.setValue(value);
} }
public void setHighLight(boolean highLight) { public void setHighLight(boolean highLight) {
if (wires != null)
for (Wire w : wires) for (Wire w : wires)
w.setHighLight(highLight); w.setHighLight(highLight);
} }

View File

@ -21,6 +21,13 @@ public class NetList implements Iterable<Net> {
add(w); add(w);
} }
public NetList(NetList toCopy) {
netList = new ArrayList<>();
for (Net net : toCopy)
netList.add(new Net(net));
}
public void add(NetList netList) { public void add(NetList netList) {
this.netList.addAll(netList.netList); this.netList.addAll(netList.netList);
} }