Restore Collapsed GoSubGraph

Is there any demo code that would show saving and restoring a
GoSubGraph in its collapsed state? I can save and restore
subgraphs that are in the expanded state ok, but when I restore a
collapsed subgraph and then expand it, the bounds remain the same as
the collapsed version (with children placed on top of each
other). I’ve tried saving and restoring ExpandPaintBounds, but
that doesn’t seem to help.

ExpandPaintBounds is just used for figuring out what areas need to be repainted when something changes, so you don’t need to save/restore that.

What you are missing is the state saved in the GoSubGraph.SavedBounds and SavedPaths properties. When the subgraph is expanded those hashtables don't matter, but when collapsed they hold the original positions and routes for the nodes and links.

I can save SavedBounds and SavePaths, but they are read-only. How do I handle the restore?

Clear, then modify them.

I’m using XML to save/restore my document. I’m not sure how to go
about saving/restoring the hashtables . Do you have any
demo code that does that? Do I just need to save/restore the
rectangles stored in the hashtable values (assume that bucket order
remains the same)?

Here’s an idea: save all subgraphs in expanded state, and just remember for each one whether you need to collapse them when restoring.

I’ve tried that approach, but couldn’t get it to work. I
tried sequence of 1)Expand (if collapsed) 2) save all the
children of the subgraph 3)Collapse (if originally collapsed) but the
children still seemed to have the collapsed bounds and positions in the
output XML. Do I need to invalidate each of the children?
Can I do all this in transaction so user does not have to see all the
subgraphs expanding and collapsing?

That should have worked – I’ve done that in the past. You need to Expand everything recursively first, before you save anything. If you continue with this strategy, you can always call GoDocument.BeginUpdateViews and then EndUpdateViews.

An alternative is for each node and link to save any information found in the parent subgraph's SavedBounds (a RectangleF) or SavedPaths (a PointF[]). If you are using GoXml, that's convenient because you can call GoXmlTransformer.WriteAttrVal for both data types when writing, and RectangleFAttr and PointFArrayAttr when reading.