Adjusting links when locn of junction port changed


I have customized GoDiagram Node with a port. There will be many instances of this class that can be drawn on the view and these can be connected with each other.
I have a requirement that when Node1 is conncted to Node2 and node2 connected to node3, I have to redraw the links and a junction point has to be created and all node1, node2, node3 connected to this junction point.
To do this, I have custom GoToolLinkingNew and I am intercepting this scenario and creating an instance of CustomizedNode with a port which acts as a junction port and breaking the existing links and relinking them to this junction port. This is working fine.
Now the problem is When I adjust/change the location of this junction port programmatically so that it comes exaclty between the participating nodes connected to this junction port, I am seeing unwanted behavior. What I see is links are not properly connected to the junction port. Some times links stay at origianal location or sometimes half visible. I am not able to understand what is happening. Do I have to do anything extra here to make connected links properly drawn after the location of junction port is changed.

That should just work. The reason links appear to stay connected with their ports, for example when a person drags a node, is because movement of a port will notify all connected links, which will cause GoLink.CalculateRoute to be called. This calls CalculateStroke to actually figure out what new stroke path (i.e. points) the link should have.

So the first question is whether dragging any of the first three nodes causes any problems with links not adjusting or appearing properly.
Secondly, have you overridden any Paint methods? Or any ComputeBounds methods? A GoView requires knowledge of where each object might paint, so that it can figure out which objects should repaint in order to update part of the screen.

Hello Walter,

My Default location of junction port is (0,0). So all the links connected to this junction port stay connected to this point. When I do calculation and change the location of junction port to some other point say (100,100), Only the port is drawn at new point but in the view I could see links still connected at (0,0) location. Even If I move participating nodes, Links look same and behave as if junction port is at (0,0).
All the insatnces of port are CustomPort derived from GoPort. I have overriden paint method of GoLink but still calling base class paint method.
Am I blocking default notification of movement of ports to connected links. Can I explicitly do this whenever I change location of junction port.

Could you check the Bounds of the links before and after moving the port?

Could you set a breakpoint on GoLink.CalculateStroke, to see if it is being called at all when you move the port?
It requires some programming effort to get the normal functionality to break. Just doing the simple things should work fine. Make sure you don't set SuspendsUpdates or override any Changed method without calling the base method.

Hello Walter,

I checked the bounds of links before and after moving the junction port, surprisingly they remain same. Also I put a break point at GoLink.CalculateStroke and found that it is not being called after location of junction port is changed. I think I am missing something. I am still trying to figure out what went wrong but so far didn't have luck. Do you have any pointers to root cause of this problem by seeing above symptoms?

GoObject.OnBoundsChanged is called when the Bounds of the object changes. So GoPort.OnBoundsChanged is overridden to call GoPort.LinksOnPortChanged.

GoPort.LinksOnPortChanged is called whenever any change happens to a port that might be interesting to the links connected to it. Besides the Bounds changing, changing the FromSpot or the ToSpot would naturally cause the links to need to be rerouted.
GoPort.LinksOnPortChanged calls GoLink.OnPortChanged on each link connected at the port.
GoLink.OnPortChanged calls GoLink.UpdateRoute. This calls GoDocument.UpdateRoute.
GoDocument.UpdateRoute calls GoLink.CalculateRoute, which just calls CalculateStroke.
However, GoDocument.UpdateRoute delays calls to GoLink.CalculateRoute depending on the value of GoDocument.RoutingTime and on the value of GoDocument.SuspendsRouting.
You haven't set SuspendsRouting, have you? The documentation recommends against using that property, just like it recommends against using the SuspendsUpdate property.
Another possibility is that you have incorrectly overridden the GoDocument.DoDelayedRouting method, or that you are improperly clearing the GoDocument.DelayedRoutings collection.

Hello Walter,
Thanks for the input. I found that I am adding new links as a child of Node containing junction port. But when I added links to view’s document instead of Node, it solved this painting problem. Is it compulsory to add links as Child to GoDocument? I remember having read in user guide that links are always added to document’s linkslayer.

I have a question regarding monitoring the links connected to a junction port:
Is there a way to get notified of movement/deletion...etc of links connected to junction port as a result of movement/deletion of nodes connected by them. This is required to update the location of junction port. I would like to localize the handling code to the Node containg junction port. All I have here is the reference to junction port and I am interested only in changes with links connected to junction port.I know that this can be handled in the eventhandlers of GoView and but I just wanted to know whether there is in-built support for delegating the events or adding observers for changes to specific set of GoDiagram objects. Thnaks and Bye,
  1. No – in fact it’s standard for links that are “part” of a GoSubGraphBase to be a child of that node. However, your nodes aren’t “subgraphs”, so it’s standard to have the links be owned as top-level objects in some layer of the document.
2) It sounds like this functionality belongs with the document, not with any port or any link. In other words, you can implement a GoDocument.Changed event handler (or GoDocument.OnChanged override) to check for Hint == GoLayer.InsertedObject or GoLayer.RemovedObject for the kinds of object you care about.
If you only care about doing these updates when the user performs some action, not when programmatic code inserts/removes/moves nodes or links, then you can implement GoView event handlers for SelectionDeleted and SelectionMoved.