Expanding an hidden subgraph

Hello again,

I have a subGraph B that is inside of a subgraph A. I’d like to be able to expand B through code, even when A is collapsed.

When I do that currently, B appears on the screen, just like if A was expanded. The behaviour I’d expect would be that nothing happens immediatly, but next time I expand A, B will be expanded.

Is there a way to get this behaviour ?

Regards,

I think so, but with two caveats: I haven’t tried this, and the relevant property is private.
GoSubGraph.CollapseChild collapses all child subgraphs. When it does so, it sets the private GoSubGraph.WasExpanded property to true.
Then when GoSubGraph.ExpandChild restores the position of each node, if the node is a subgraph and if WasExpanded is true, it calls GoSubGraph.Expand on that subgraph.
So maybe you can do:
GoChangedEventArgs e = new GoChangedEventArgs();
e.Hint = GoLayer.ChangedObject;
e.SubHint = GoSubGraph.ChangedWasExpanded;
e.NewValue = true;
B.ChangeValue(e, false);
where B is that subgraph node that you want to automatically expand when its Parent A is expanded.

Thank you, it worked fine. However, it just led me to another problem.

I detect somehow when a subgraph is expanded/collapsed (I’ve overridden PrepareCollapse and PrepareExpand).

In the same situation, when both A and B are expanded, and I collapse A, I get the information that B is collapsed. Is there a way to detect that this is not a “real” collapse ?

In your override of PrepareCollapse you can check if B.IsExpanded is true. PrepareCollapse is called before SaveChildBounds and CollapseChild are called on each subgraph child object.

Still one problem with woking with collapsed subgraphs : I add programmatically a link between nodes inside of a collapsed subgraph, or between one such node and the subgraph itself.

Is there something I can do to make this node not visible, but that will become visible when the graph will be expanded ? Maybe adding something to the savedPath of the subgraph ?

Best regards,

If the subgraph is collapsed, you could certainly set Visible to false for any nodes or links that you add to that subgraph.
BTW, I assume you know about the static method GoSubGraphBase.ReparentToCommonSubGraph, which is useful for making sure a link is added to the proper subgraph, or to a layer as a top-level object, as appropriate given the nodes that the link connects.

This is what I tried first, but at that time, some of my links were not parented to the good subgraph, just as you guessed…

I tried again, and it works now.