Capturing NLineShape FromShape/ToShape changed


Author
Message
Ryan Dodd
Ryan Dodd
Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)
Group: Forum Members
Posts: 1, Visits: 1
I am looking to capture this event in the drawing document. I'm sure this is something simple I overlooked in the documentation but if I use the BoundsChanged or PropertyChanged events on the NLineShape it seems to fire them off many times instead of just once. The property changed event captures on the size change. Is there another event I can subscribe to that would capture the simple drop event of that shape when either one of those properties change?

Thanks!

EDIT: As a follow up, is there any way I can force the line to never let the ToShape or FromShape be null - meaning when disconnected from a shape, force the line to either be connected to another shape or go back to the original shape if dropped disconnected?
Ivo Milanov
Ivo Milanov
Forum Member (35 reputation)Forum Member (35 reputation)Forum Member (35 reputation)Forum Member (35 reputation)Forum Member (35 reputation)Forum Member (35 reputation)Forum Member (35 reputation)Forum Member (35 reputation)Forum Member (35 reputation)
Group: Forum Members
Posts: 35, Visits: 32

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


Martin Bradfrd
Martin Bradfrd
Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)
Group: Forum Members
Posts: 5, Visits: 1
Hi there,
I was wondering if there was a code example of the third part of your explanation?

'3. On timer tick check the integrity of the diagram by going through the list of 1D shapes that need to be reconnected.'

Thanks,
Martin BG
GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search