Wires connected to a component now get deleted with the component
[Mograsim.git] / net.mograsim.logic.model / src / net / mograsim / logic / model / model / components / ModelComponent.java
index d2ead74..40ab62f 100644 (file)
@@ -79,7 +79,7 @@ public abstract class ModelComponent implements JSONSerializable
         */
        protected void destroyed()
        {
-               pinsByName.values().forEach(p -> pinRemovedListeners.forEach(l -> l.accept(p)));
+               pinsByName.values().forEach(this::removePinWithoutRedraw);
        }
 
        // pins
@@ -112,11 +112,16 @@ public abstract class ModelComponent implements JSONSerializable
         */
        protected void removePin(String name)
        {
-               Pin pin = pinsByName.remove(name);
-               callPinRemovedListeners(pin);
+               removePinWithoutRedraw(pinsByName.remove(name));
                model.requestRedraw();
        }
 
+       private void removePinWithoutRedraw(Pin pin)
+       {
+               pin.destroyed();
+               callPinRemovedListeners(pin);
+       }
+
        /**
         * Returns a collection of pins of this component.
         *