Hi Ryan,
You can hook the Connected/Disconnected events of the document event sink service:
document.EventSinkService.Connected += ...
document.EventSinkService.Disconnected += ...
Since all logical connections between shapes are in fact connections between their connection points (plugs to inward ports and outward ports to inward ports), this will keep you informed about all changes related to shape connections. Both events will receive as argument a class which holds two unique ids - the ids of the two connection points involved in the connection:
public void ConnectionEventHandler(NConnectionEventArgs args)
{
NConnectionPoint point1 = args.Document.GetElementFromUnqiueId(args.UniqueId1) as NConnectionPoint;
NConnectionPoint point2 = args.Document.GetElementFromUnqiueId(args.UniqueId2) as NConnectionPoint;
NShape shape1 = point1.Shape;
NShape shape2 = point2.Shape;
// when connecting a plug to inward port either shape1 or shape2 is a 1D shape
// when connecting a outward port to inward port both shape1 and shape2 can be 2D shapes.
}
Performing the logic that you need - revert to original connection point when disconnected can be tricking since when reconnecting a connection point the diagram executes this sequence:
1. disconnect from current connection point (if any)
2. connect to the new connection point (if any)
This means that you actually do not know that a shape is going to be connected when handling the Disconnected event. I would suggest that you do the following:
1. Handle the Disconnecting event and keep a list of the 1D shapes and the original ports to which they are connected prior to disconnecting.
2. Create a timer
3. On timer tick check the integrity of the diagram by going through the list of 1D shapes that need to be reconnected.
Best regards,
Ivo