Port similar to GoGeneralNodePort

Hello,

I have created a port similar to GoGeneralNodePort, the main difference is that it is to be used as a port on a multi-port SubGraphNode.

I have a problem when doing any modification on the node that changes the port position : I update the label attached to the port, but the link, that is positionned on the label, is not moved correctly, it seems to be placed on the previous position of the label.

I tried to add a call to LayoutLabel(); in GetFromLinkPoint and GetToLinkPoint, it improved the situation in some cases (changing the size of the SubGraphNode), but not in others (moving the node).

Is there something simple to do to solve this problem ?

Thank you,

GoPort.GetFromLinkPoint and GetToLinkPoint shouldn’t be modifying the port or associated objects (such as a label). You probably ought to be positioning the label at the same time that you position the port. If the link point depends on the bounds of the label (as it does for GoGeneralNodePort) then maybe it would be easiest if you first moved the label and then moved the port.
Changing the Bounds of a GoPort will call GoLink.CalculateStroke() on all of the links that are connected to that port, which should address the behavior you see.

[QUOTE=walter]

GoPort.GetFromLinkPoint and GetToLinkPoint shouldn’t be modifying the port or associated objects (such as a label). You probably ought to be positioning the label at the same time that you position the port.[/quote]

I do not have problems positionning the label, it is always positionned at the right place, even when I do nothing in GetFromLinkPoint. So I guess that I move the label correctly each time the port is moved.

[QUOTE=walter] If the link point depends on the bounds of the label (as it does for GoGeneralNodePort) then maybe it would be easiest if you first moved the label and then moved the port.[/quote]

I do not manually position the port: it is moved by my moving the corresponding SubGraphNode. I have in my SubGraphNode a method called LayoutPort (same model as MultiPortSubGraph in the sample), in whiched I moved the port than called port.LayoutLabel. I modified this function so that I moved the label before moving the port, but it did not change anything.

I tried to see which function to override in the port itself, in order to trap all modification of positions of the port, and move the label previously, but am a little bit confused. Which function shoud I override ?

OnBoundsChanged, Bounds.set, Location.set, DoMove, another one ?

Regards,

Actually, none of those. In fact, you shouldn’t need to override any methods except for GetFromLinkPoint and GetToLinkPoint if you just want to tell links to terminate at a different point than normal.
GoPort.OnBoundsChanged is already defined to call GoPort.LinksOnPortChanged, which in turn iterates over all of the connected links and to call IGoLink.OnPortChanged on each one, which in turn calls GoLink.CalculateStroke in order to produce a new path or route for the link to take to connect its two ports.
When one moves a node, its children naturally get moved too. You say that when you move the node, the ports get moved correctly, right? And the labels do too? Maybe GetFromLinkPoint and GetToLinkPoint are returning the wrong values because they are returning points on the label and the label hasn’t been moved yet.
The implementation of GoGeneralNodePort.GetLinkPoint (called by the two Get[From/To]LinkPoint methods) returns a point relative to a point on the port, plus or minus the width/height of the label plus the LabelSpacing distance.

In my previous code, I used for the Get[From/To]LinkPoint functions:

return myLabel.GetSpotLocation(MiddleRight);

With your advice, I replace such code by:

PointF linkPos = GetSpotLocation(MiddleRight); linkPos.X += LabelSpacing; linkPos.X += myLabel.Width; return linkPos;

And now the problem is solved !
Thank you for your help !