Grouping nodes

Hi,

I need to group selected nodes. User selects nodes than right click and selects group. User selects the node to use for grouping.

I have selected nodes and a node to use for grouping but i couldn’t make a group from them. I use the code below.??? I couldn’t find any sample codes.

ISubGraphLinksModel subGraphModel = this.objectDiagram.Model as ISubGraphLinksModel;
 
                if (subGraphModel == null)
                {
                    return;
                }
 
                List<ContainerObject> containers = new List<ContainerObject>();
 
                foreach (var node in this.objectDiagram.Model.NodesSource)
                {
                    if (node is ContainerObject)
                    {
                        containers.Add(node as ContainerObject);
                    }
                }
 
                if (containers.Count <= 0)
                {
                    NatekMessageBox.ShowAlert(Alerts.NoContainer, ApplicationConfiguration.MessageCloseSeconds);
                    return;
                }
 
                SelectContainerChildWindow window =
                                    new SelectContainerChildWindow(containers);
 
            window.Closed += <span style="color: blue;">delegate</span>(<span style="color: blue;">object</span> parent, <span style="color: rgb43, 145, 175;">EventArgs</span> args)
            {
                <span style="color: blue;">if</span> (window.DialogResult == <span style="color: blue;">true</span>)
                {
                    <span style="color: blue;">if</span> (window.SelectedContainer != <span style="color: blue;">null</span>)
                    {
                        window.SelectedContainer.IsSubGraph = <span style="color: blue;">true</span>;

                        subGraphModel.SetGroupNode(window.SelectedContainer, <span style="color: blue;">null</span>);

                        subGraphModel.AddNode(window.SelectedContainer);

                        <span style="color: blue;">foreach</span> (<span style="color: rgb43, 145, 175;">Part</span> part <span style="color: blue;">in</span> <span style="color: blue;">this</span>.objectDiagram.SelectedParts)
                        {
                            <span style="color: blue;">if</span> (part.Data <span style="color: blue;">is</span> <span style="color: rgb43, 145, 175;">BaseNetworkGraphObject</span>)
                            {
                                <span style="color: blue;">if</span> (part.Data <span style="color: blue;">is</span> <span style="color: rgb43, 145, 175;">ContainerObject</span> &&
                                    (part.Data <span style="color: blue;">as</span> <span style="color: rgb43, 145, 175;">ContainerObject</span>).Key == window.SelectedContainer.Key)
                                {
                                    <span style="color: blue;">continue</span>;
                                }

                                <span style="color: rgb43, 145, 175;">BaseNetworkGraphObject</span> node = part.Data <span style="color: blue;">as</span> <span style="color: rgb43, 145, 175;">BaseNetworkGraphObject</span>;

                                node.SubGraphKey = window.SelectedContainer.Key;
                                window.SelectedContainer.MemberKeys.Add(node.Key);
                                subGraphModel.AddMemberNodeKey(window.SelectedContainer, node.Key);
                            }
                        }

                        subGraphModel.DoGroupNodeChanged(window.SelectedContainer);
                        <span style="color: blue;">this</span>.objectDiagram.UpdateLayout();
                    }
                }
            };

            window.Show();</pre>

Just call Diagram.CommandHandler.Group().
Remember to set PrototypeGroup.

Hi,

I made my code worked.

But my problem is now update layout after grouping. when i serialize my grouped diagram and deserialize i see my group but i can’t see my group after my grouping function.

How can i update the layout after grouping???

Fyi, UIElement.UpdateLayout has nothing to do with GoXam and diagram layout.

Do you mean diagram must do it???

By default Goxam will assign positions to all nodes that do not already have one.

But I do not know what values you have given to Diagram.Layout and Group.Layout.

i use Default diagram layout.

If you look at the persisted model data, are all of the nodes, including the new group data there? If you are data-binding the Node.Location, do they all have the right values? Does the group data know that it is a group and not a regular node?

Thanks, I figured it out.

I am a GIS developer and I am new to this API. In GIS you always refresh map after changing it :)

Well, in GoXam you should always make changes to your model or model data inside a transaction.