How to save GoLabeledLink information

I am implementing a GoLabeledLink object which orthogonal and AvoidsNodes property are both set to true. After the user creates a document and draw the links by using the GoLabeledLink object, I need to save it into the database. The GoLabeledLink information that i saved are its left, right, top and bottom location.
However, when the document is reloaded from the database, the links in the document do not appear to be the same as they are created. This happened only for those links that have been reshaped by the user during their creation. Is it possible for me to get the location of each segments of the links or is there any better way to save the GoLabeledLink object?

You can get the points of the link’s stroke by calling GoLabeledLink.RealLink.CopyPointsArray().
On reloading, you can just call GoLabeledLink.RealLink.SetPoints. Be sure to call SetPoints after you have set the link’s FromPort and ToPort and Orthogonal and AvoidsNodes properties, since those setters will call GoLink.CalculateStroke to figure out the stroke path (again), which would just reset all the points data you just restored.

So I’m doing the above, using GoLabeledLink.RealLink.CopyPointsArray() to get and save the link points and GoLabeledLink.RealLink.SetPoints() to set the link points. On the SetPoints() some of my links refuse to draw as directed. Some not all. Some links behave as expected. I can detect no pattern in the misbehaving links.

I am calling SetPoints after setting the to and from ports. Also after setting the Orthogonal and AvoidsNodes properties. I do not call LayoutDocument after setting the points.

What am I missing? Any suggestions on how to debug this?


What do the links that aren’t correct look like? Does moving the node re-calculate the link?

If you’re using our XML support, Flowgrammer shows how to save/restore “Points” with GoXmlTransformer. And StateCharter shows it for the higher level GoXmlBindingTransformer.

The links look fine, they just are not where they should be.

Yes moving the node re-calculates the links. In fact the position of the links is as if I moved the node there, in other words looks like the SetPoints is being ignored and the link is just being positioned naturally.

Not using XML support. I am using GoDiagram Win 2.6.2 for .Net 2.0.

Well, I guess I’d add an override of GoLink.CalculateStroke (that just calls base.
CalculateStroke) so I could set a breakpoint and see why it’s being called during your Load, since I’m guessing that’s what is happening.

My link is actually a GoLabeledLink. I overrode the following related functions in my class derived from GoLabeledLink:

  public new void CalculateStroke()
} public new void CalculateRoute() {
} public new void UpdateRoute() {

Unless I’m doing this wrong, the break points in those functions were never hit. Any further suggestions?


Found it. link.OnPortChanged() led me to the culprit. For some node shapes I adjust port locations, for no particularity good reason I was doing this after laying out nodes and links. Adjusting port locations causes links to redraw.

Thanks for your help Jake!

Good. For future reference… with GoLabeledLink, when overriding methods on GoLink, you have to derive from GoLink, and then override CreateRealLink() in the GoLabeledLink and return a new instance of your GoLink subclass.

Your methods above aren’t “override”… and the fact that you didn’t get an error when you did that means that GoLabeledLink doesn’t have a “virtual” version of that method.