This project has moved and is read-only. For the latest updates, please go here.

Disconnect a Model object when removing a shape

Mar 28, 2014 at 9:52 AM
I'm trying to call the Disconnect() method of my model object when one of its connected (linear) shapes is removed but can't get to it.

I currently have a custom planar shape (with an associated model object) that can be connected to the different linear shapes available in the existing libraries (Polyline, RectangularLine, ...). I created a model object for the connector (whatever linear shapes) in order to use the Connect() and Disconnect() methods of the model object.
The Connect() method is properly called when the shapes are connected however the Disconnect() method is not called when I delete the linear shape that connects 2 planar shapes.

I found out that in the Execute() method of the DeleteShapesCommand command, the model object of all the targeted shapes is cleaned before calling the Disconnect() method of the appropriate shape:
public override void Execute() {
  if (modelObjectAssignments != null) {
    foreach (KeyValuePair<Shape, IModelObject> item in modelObjectAssignments) {
      item.Key.ModelObject = null;
But then in the DetachGluePointFromConnectionPoint() (called by the ShapeBase.Disconnect() method) method of the ShapeBase class, you check whether the model object of the shape and its connector is not null before calling the Disconnect() method of the associated model object:
if (this.ModelObject != null && otherShape.ModelObject != null && otherShape.Template != null) {
    ModelObject.Disconnect(Template.GetMappedTerminalId(ownPointId), otherShape.ModelObject, otherShape.Template.GetMappedTerminalId(gluePointId));
Because of this, the Disconnect() method of the model object associated to the shape is never called. Is there a possible workaround or am I looking in the wrong direction?
Mar 28, 2014 at 12:08 PM
You are right, this is a bug.
Please send an email to support (at) dataweb (dot) de so I can send you a corrected version of "Commands.cs".
Marked as answer by roux1max on 3/28/2014 at 6:22 AM