Stoyo wrote on May 2
nd, 2012 at 10:55am:
You can find several versions of it by searching the forum. Here's what I have currently in my test app:
private DiagramItemCollection GetContainerItems(ContainerNode container)
{
DiagramItemCollection items = new DiagramItemCollection();
foreach (DiagramNode node in container.SubordinateGroup.AttachedNodes)
{
items.Add(node);
foreach (DiagramLink link in node.GetAllLinks())
{
DiagramNode node2 = GetOtherEnd(link, node);
if (ContainerNode.GetContainer(node2) == container && !items.Contains(link))
items.Add(link);
}
}
return items;
}
private void ArrangeContainers(ContainerNode parent, Layout layout)
{
DiagramItemCollection children = GetContainerItems(parent);
foreach (DiagramItem child in children)
{
if (child is ContainerNode)
ArrangeContainers((ContainerNode)child, layout);
}
layout.Arrange(diagram, GetContainerItems(parent));
parent.UpdateBounds(true);
}
private void miLayoutContainersRecursively_Click(object sender, EventArgs e)
{
LayeredLayout layout = new LayeredLayout();
layout.MultipleGraphsPlacement = MultipleGraphsPlacement.MinimalArea;
ArrangeContainers(diagram.Nodes[0] as ContainerNode, layout);
}
private void Arrange(Diagram diagram, Layout outerLayout, Layout innerLayout)
{
foreach (DiagramNode node in diagram.Nodes)
{
ContainerNode container = node as ContainerNode;
if (container == null)
continue;
innerLayout.Arrange(diagram, GetContainerItems(container));
container.UpdateBounds();
}
outerLayout.Arrange(diagram);
/*foreach (DiagramLink link in diagram.Links)
{
if (ContainerNode.GetContainer(link.Origin) != ContainerNode.GetContainer(link.Destination))
link.Route();
}*/
diagram.ResizeToFitItems(5);
}
Yeah, I found that just minute ago.. (took me around 8min to find it).
(I was wondering if you people could add tags to this forum, so that finding what users are looking may come a bit easier..? or something like FAQ; this scenario/post may sound like one)
I just have now problem with second containers nodes link... the anchor point is wrong... (do not understand, yet why)
(see attachment..)
Also your shown sample _had_ the:
autoshrink = false && container.UpdateBounds()
results: (containers get larger and larger every update)
Other than those... this seemed to solve my problem..