Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Is possible group and ungroup nodes? (Read 4311 times)
PDM.
Senior Member
****
Offline


I love YaBB 1G - SP1!

Posts: 256
Joined: Dec 2nd, 2010
Is possible group and ungroup nodes?
Jan 9th, 2012 at 2:46am
Print Post  
Is possible select multiple nodes and make the nodes act like one single node, about move, resize, delete, change z axis, etc etc.

Something like if nodes are attached on to other.
What is the way to group and how then ungroup?

Bets regards.

  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Is possible group and ungroup nodes?
Reply #1 - Jan 9th, 2012 at 7:12am
Print Post  
You can use the AttachTo method to create a group; attached nodes move together but do not resize. If you need to resize group members simultaneously, you could enable AllowMultipleResize and select all nodes from the group when one of them is clicked.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
PDM.
Senior Member
****
Offline


I love YaBB 1G - SP1!

Posts: 256
Joined: Dec 2nd, 2010
Re: Is possible group and ungroup nodes?
Reply #2 - Jan 9th, 2012 at 8:46am
Print Post  
Please can show to me with example code how use AttachTo and how disable?
I want nodes attached remain on same position and can be moved like one single node.
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Is possible group and ungroup nodes?
Reply #3 - Jan 9th, 2012 at 9:24am
Print Post  
With AttachTo you will need one node to act as a parent of the group:

Code
Select All
private void OnGroupNodes(object sender, RoutedEventArgs e)
{
      var groupContainer = diagram.Factory.CreateShapeNode(diagram.Selection.Bounds);
      groupContainer.Transparent = true;
      groupContainer.ZBottom();

      foreach (DiagramNode node in diagram.Selection.Nodes)
            node.AttachTo(groupContainer, AttachToNode.TopLeft);
      foreach (DiagramNode node in groupContainer.SubordinateGroup.AttachedNodes)
      node.Locked = true;
}

private void OnUngroupNodes(object sender, RoutedEventArgs e)
{
      var groupContainer = diagram.ActiveItem as ShapeNode;
      if (groupContainer != null &&
            groupContainer.SubordinateGroup != null)
      {
            var attachedNodes = new List<DiagramNode>();
            foreach (DiagramNode node in groupContainer.SubordinateGroup.AttachedNodes)
                  attachedNodes.Add(node);
            foreach (DiagramNode node in attachedNodes)
            {
                  node.Locked = false;
                  node.Detach();
            }
            diagram.Nodes.Remove(groupContainer);
      }
} 



Alternatively, you might try to attach the nodes in a circular manner, where each node is attached to the previous node in the selection.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
PDM.
Senior Member
****
Offline


I love YaBB 1G - SP1!

Posts: 256
Joined: Dec 2nd, 2010
Re: Is possible group and ungroup nodes?
Reply #4 - Jan 9th, 2012 at 9:50am
Print Post  
Stoyan, this work ok, thk for he repply, just i see one problem

If by accident i select grpup and press delete button, only groupContainer is deleted, and nodes remain locked without any possibility of delete, select or do nothing.

How can handle this?
« Last Edit: Jan 9th, 2012 at 11:13am by PDM. »  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Is possible group and ungroup nodes?
Reply #5 - Jan 9th, 2012 at 11:04am
Print Post  
Add this to OnGroupNodes to delete all grouped nodes:
Code
Select All
groupContainer.SubordinateGroup.AutoDeleteItems = true;
 



If you wish to keep the nodes but unlock them, handle NodeDeleting like this:

Code
Select All
if (e.Node is ShapeNode && e.Node.SubordinateGroup != null)
      foreach (DiagramNode node in e.Node.SubordinateGroup.AttachedNodes)
            node.Locked = false; 



I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
PDM.
Senior Member
****
Offline


I love YaBB 1G - SP1!

Posts: 256
Joined: Dec 2nd, 2010
Re: Is possible group and ungroup nodes?
Reply #6 - Jan 9th, 2012 at 11:26am
Print Post  
Perfect !
Thankyou for the help!
  
Back to top
 
IP Logged
 
PDM.
Senior Member
****
Offline


I love YaBB 1G - SP1!

Posts: 256
Joined: Dec 2nd, 2010
Re: Is possible group and ungroup nodes?
Reply #7 - Jan 9th, 2012 at 9:42pm
Print Post  
I have few problems, when copy group all objects attached not copy.

Also when try change z order of group of nodes, only the transparent shape move of order.

Some sugestion please?
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Is possible group and ungroup nodes?
Reply #8 - Jan 10th, 2012 at 9:08am
Print Post  
If you mean copying to the clipboard, use the CopyToClipboard method that takes a 'bool groups' parameter and set it to true. In order to change the group's Z order position, you will have to set ZIndex of all group members.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint