X-Git-Url: https://mograsim.net/gitweb/?a=blobdiff_plain;f=net.mograsim.logic.model%2Fsrc%2Fnet%2Fmograsim%2Flogic%2Fmodel%2Fmodel%2Fwires%2FPin.java;h=11a69082ec717aa5c4f658fec8a30c3243778465;hb=b32414f8406634aca730d724a011023c0da8bf22;hp=eb8df887b99cc3168c758dd83aa8d3dd0a921184;hpb=3a52b6bffe52db5dd5ca907b4b3dfd368a58e14f;p=Mograsim.git
diff --git a/net.mograsim.logic.model/src/net/mograsim/logic/model/model/wires/Pin.java b/net.mograsim.logic.model/src/net/mograsim/logic/model/model/wires/Pin.java
index eb8df887..11a69082 100644
--- a/net.mograsim.logic.model/src/net/mograsim/logic/model/model/wires/Pin.java
+++ b/net.mograsim.logic.model/src/net/mograsim/logic/model/model/wires/Pin.java
@@ -1,11 +1,14 @@
package net.mograsim.logic.model.model.wires;
import java.util.ArrayList;
+import java.util.HashSet;
import java.util.List;
import java.util.Objects;
+import java.util.Set;
import java.util.function.Consumer;
import net.haspamelodica.swt.helper.swtobjectwrappers.Point;
+import net.mograsim.logic.model.model.LogicModelModifiable;
import net.mograsim.logic.model.model.components.ModelComponent;
/**
@@ -18,6 +21,10 @@ import net.mograsim.logic.model.model.components.ModelComponent;
*/
public class Pin
{
+ /**
+ * The {@link LogicModel} the component this pin belongs to is a part of.
+ */
+ private final LogicModelModifiable model;
/**
* The {@link ModelComponent} this pin belongs to.
*/
@@ -56,8 +63,9 @@ public class Pin
*
* @author Daniel Kirschten
*/
- public Pin(ModelComponent component, String name, int logicWidth, PinUsage usage, double relX, double relY)
+ public Pin(LogicModelModifiable model, ModelComponent component, String name, int logicWidth, PinUsage usage, double relX, double relY)
{
+ this.model = model;
this.component = component;
this.name = name;
this.logicWidth = logicWidth;
@@ -71,6 +79,19 @@ public class Pin
component.addComponentMovedListener(c -> callPinMovedListeners());
}
+ /**
+ * Destroys this pin by removing all wires connected to it from the model the component is a part of.
+ * Don't call this method from application code as it is automatically called in {@link ModelComponent#removePin(String)}.
+ */
+ public void destroyed()
+ {
+ Set connectedWires = new HashSet<>();
+ for (ModelWire w : model.getWiresByName().values())
+ if (w.getPin1() == this || w.getPin2() == this)
+ connectedWires.add(w);
+ connectedWires.forEach(model::destroyWire);
+ }
+
// "graphical" operations
/**