Troubles with links not re-routing

Hi. I’m having a variety of problems, all related to links not rerouting properly.

The first problem is relatively minor: If I have a link between two nodes and move another node over the link, the link re-routes itself around the obstacle. That’s good. But then, if I move the obstacle out of the way, the link does not re-route to a straight line.

More seriously, if I programmatically create a node on top of the link, the link does not re-route. If I then move the node, the link will re-route.

I’ve implemented my own undo mechanism. If I delete a node and its incoming link, then do Undo so that the node and link reappear, the link does not go to the node’s port; it goes to the center of the node. If I then force the link to re-route (by moving the node or moving another node on top of the link) the link re-routes and connects to the node.

I’ve fiddled with calling diagram.Layout.Invalidate, but that’s not solving any of these problems. What else can I try?

Thanks,
Bob

Oh, yeah, one other issue: when I load data into my diagram, I see the nodes and links appear, but all the links are offset vertically from their proper position; they’re about 25 pixels too high. A fraction of a second later, they all jump down into their correct position. Any idea why they start off in the wrong position?

Thanks,
Bob

The first case is intentional. When a node is moved or deleted, it is hard to know which links ought to be re-routed. Potentially all of the remaining links in the diagram might need to be re-routed.

The second case is intentional also. Just because a node is (perhaps temporarily) located somewhere doesn’t mean that any AvoidsNodes links should be rerouted. However, I think it would be a good idea to make public the method to achieve what you are looking for.

Regarding the third issue – are you using Silverlight or WPF? Which version? I suspect you are using Silverlight and you are encountering a “feature” of Silverlight that we have found very frustrating to work-around. You might need to explicitly re-route the links connected to the node.

What do you mean that you have implemented your own undo mechanism? I’m wondering if you used the one that GoXam provides if you would still encounter this problem.

It seems unlikely that anything to do with Diagram.Layout will affect the behavior you are seeing with your own undo.

Finally, for the fourth issue, how are loading data into your diagram? Have you seen this behavior in any of the sample applications? Are you storing/loading the Points of the link routes? If so, have you checked that the saved values are actually correct with respect to the saved positions of the nodes?

Actually, for the second issue, you can just call:

public void InvalidateAvoidsNodesLinks(Diagram diagram, Rect region) { diagram.StartTransaction("reroutings"); foreach (Link l in diagram.Panel.FindPartsIn<Link>(region, SearchFlags.Links, SearchInclusion.Intersects, SearchLayers.Links)) { if (l.Route.Routing == LinkRouting.AvoidsNodes) l.Route.InvalidateRoute(); } diagram.CommitTransaction("reroutings"); }

Hi Walter,

I’m loading the model from a data file. It’s fully loaded by the time it gets data-bound to the diagram. I am not loading the Points. I haven’t provided a way for the user to manually route the links, so I’ve assumed there’s no point in persisting the Points ( :-) ) since I just let GoXam do its automatic routing.

I do not see the behavior in the sample apps.

  • Bob

How are you undoing the deletion of a node with a connected link? Are you adding a node data (and if you are using a GraphLinksModel, a link data) to the model within a transaction?

If you’re not using GoXam’s UndoManager, then what you are doing really shouldn’t be any different from dynamically adding and removing parts and modifying their properties.

Regarding the fourth issue, that’s odd, because I don’t understand how what you are doing is different from every sample that initializes a diagram by building a model in code (either explicitly or by reading some XML) and then assigning it to Diagram.Model.

At least everything looks right at the end, true? Perhaps you are seeing the effects of an animated diagram layout. What kind of Diagram.Layout do you have, and have you set its Conditions?

I’ve fixed problems 1 and 2 (re-routing when a new node is added, and straightening a link when a node is moved out of the way) using the code you posted. Thank you.

[QUOTE=walter]How are you undoing the deletion of a node with a connected link? Are you adding a node data (and if you are using a GraphLinksModel, a link data) to the model within a transaction?

If you’re not using GoXam’s UndoManager, then what you are doing really shouldn’t be any different from dynamically adding and removing parts and modifying their properties.[/quote]

Yes, I’m adding a node and a link to their respective ObservableCollections.

[quote]Regarding the fourth issue, that’s odd, because I don’t understand how what you are doing is different from every sample that initializes a diagram by building a model in code (either explicitly or by reading some XML) and then assigning it to Diagram.Model.

At least everything looks right at the end, true? Perhaps you are seeing the effects of an animated diagram layout. What kind of Diagram.Layout do you have, and have you set its Conditions?
[/quote]

Yes, it looks right in the end. I’m using the default DiagramLayout (not any of its subclasses) and setting Conditions to NodeAdded | NodeRemoved | LinkAdded | LinkRemoved | MemberAdded | MemberRemoved | DiagramLayoutChanged | GroupLayoutChanged | NodeSizeChanged | NodeLocationChanged.

  • Bob