From: Daniel Kirschten Date: Sun, 15 Sep 2019 19:31:35 +0000 (+0200) Subject: Fixed a crashbug in Editor when deleting selections with wires and comps X-Git-Url: https://mograsim.net/gitweb/?a=commitdiff_plain;h=6af791df52c447197af6dcccf9e8c5ccfdd6d805;p=Mograsim.git Fixed a crashbug in Editor when deleting selections with wires and comps --- diff --git a/net.mograsim.logic.model.editor/src/net/mograsim/logic/model/editor/handles/WireHandle.java b/net.mograsim.logic.model.editor/src/net/mograsim/logic/model/editor/handles/WireHandle.java index 61fd0a6f..839c2b5b 100644 --- a/net.mograsim.logic.model.editor/src/net/mograsim/logic/model/editor/handles/WireHandle.java +++ b/net.mograsim.logic.model.editor/src/net/mograsim/logic/model/editor/handles/WireHandle.java @@ -71,7 +71,9 @@ public class WireHandle extends Handle @Override public void reqDelete() { - model.destroyWire(parent); + // this wire could already be removed implicitly when removing a selection containing both wires and components + if (model.getWireByName(parent.name) != null) + model.destroyWire(parent); } @Override diff --git a/net.mograsim.logic.model/src/net/mograsim/logic/model/model/LogicModel.java b/net.mograsim.logic.model/src/net/mograsim/logic/model/model/LogicModel.java index f9eef5db..17d0a44e 100644 --- a/net.mograsim.logic.model/src/net/mograsim/logic/model/model/LogicModel.java +++ b/net.mograsim.logic.model/src/net/mograsim/logic/model/model/LogicModel.java @@ -117,24 +117,24 @@ public class LogicModel return wiresUnmodifiable; } - public T getComponentByName(String name, Class expectedComponentClass) - { - return getByName(name, expectedComponentClass, components); - } - - public ModelWire getWireByName(String name) + public ModelComponent getComponentByName(String name) { - return getByName(name, ModelWire.class, wires); + return components.get(name); } @SuppressWarnings("unchecked") - private static T getByName(String name, Class expectedClass, Map map) + public T getComponentByName(String name, Class expectedComponentClass) { - Object comp = map.get(name); + ModelComponent comp = components.get(name); Objects.requireNonNull(comp, "Invaild path, component " + name + " not found"); - if (expectedClass.isInstance(comp)) + if (expectedComponentClass.isInstance(comp)) return (T) comp; - throw new IllegalArgumentException("The component " + name + " is not an instance of " + expectedClass); + throw new IllegalArgumentException("The component " + name + " is not an instance of " + expectedComponentClass); + } + + public ModelWire getWireByName(String name) + { + return wires.get(name); } public T getComponentBySubmodelPath(String path, Class modelClass)