Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic how to set selected nodes as a group like ms-visio? (Read 4796 times)
heyx
Junior Member
**
Offline


I Love MindFusion!

Posts: 69
Joined: Oct 9th, 2014
how to set selected nodes as a group like ms-visio?
Dec 31st, 2014 at 6:22am
Print Post  
how to set selected nodes as a group,so that I can set  the each node's perporty in the group ?
  

group.jpg (Attachment deleted)
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: how to set selected nodes as a group like ms-visio?
Reply #1 - Dec 31st, 2014 at 2:15pm
Print Post  
You could add a transparent ShapeNode behind the child nodes to serve as group master, and call node.AttachTo(master) for each child in the group. Possibly also set Locked = true for the children to prevent selecting them.
  
Back to top
 
IP Logged
 
heyx
Junior Member
**
Offline


I Love MindFusion!

Posts: 69
Joined: Oct 9th, 2014
Re: how to set selected nodes as a group like ms-visio?
Reply #2 - Jan 4th, 2015 at 9:14am
Print Post  
hi,
   thanks for your help.and I have tried as you told, but it isnt' effect.I attach my code there,could you show me how to fix it?
thanks ?
Code
Select All
        public void GroupNodes()
        {
            double sx = 0;
            double sy = 0;
            double ex = 0;
            double ey = 0;
            if (DesignDiagram.Selection.Nodes.Count > 0)
            {
                ShapeNode NewGroup = new ShapeNode();
                int count = 0;
                foreach (var node in DesignDiagram.Selection.Nodes)
                {
                    count++;
                    if (count ==1)
                    {
                        sx = node.Bounds.X;
                        sy = node.Bounds.Y;
                    }
                    node.AttachTo(NewGroup,AttachToNode.TopLeft);
                    if (count == DesignDiagram.Selection.Nodes.Count)
                    {
                        ex = node.Bounds.X +node.ActualWidth;
                        ey = node.Bounds.Y + node.ActualHeight;
                    }
                }
                NewGroup.Locked = true;
                NewGroup.Bounds = new Rect(new Point(sx, sy), new Size(ex-sx,ey-sy));
                DesignDiagram.Nodes.Add(NewGroup);
            }
        }
 

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


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: how to set selected nodes as a group like ms-visio?
Reply #3 - Jan 5th, 2015 at 6:41pm
Print Post  
Hi,

I can't  see anything in your code calculating bounding rectangle for the group node. Check the CreateGroup method here:
http://mindfusion.eu/Forum/YaBB.pl?num=1239007278/10#10

I meant you should lock the child nodes, and not the group node. The group from your method cannot be selected when you set its Locked property. Try this code instead:

Code
Select All
public void GroupNodes()
{
	if (diagram.Selection.Nodes.Count > 1)
	{
		var groupNode = diagram.Factory.CreateShapeNode(0, 0, 1, 1);
		groupNode.ZBottom(false);
		groupNode.Transparent = true;
		groupNode.HandlesStyle = HandlesStyle.MoveOnly;

		CreateGroup(groupNode, diagram.Selection.Nodes);
		foreach (DiagramNode child in groupNode.SubordinateGroup.AttachedNodes)
			child.Locked = true;

		diagram.Selection.Change(groupNode);
	}
}

private void CreateGroup(DiagramNode node, DiagramNodeCollection children)
{
	Rect r = Rect.Empty;
	foreach (DiagramNode child in children)
	{
		Rect cb = child.Bounds;
		r = r.IsEmpty ? cb : Rect.Union(r, cb);
	}
	double margin = 5;
	r.Inflate(margin, margin);
	node.Bounds = r;
	foreach (DiagramNode child in children)
		child.AttachTo(node, AttachToNode.TopLeft);
} 



I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
heyx
Junior Member
**
Offline


I Love MindFusion!

Posts: 69
Joined: Oct 9th, 2014
Re: how to set selected nodes as a group like ms-visio?
Reply #4 - Jan 6th, 2015 at 10:00am
Print Post  
hi Stoyan,
thanks for your help, but I find that your way is not a real group.
for example in MS-Visio the nodes Group which I can group and ungroup nodes and it can set properties of its children node.
could you please give me some help?thanks.
  

effect.jpg ( 36 KB | 88 Downloads )
effect.jpg
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: how to set selected nodes as a group like ms-visio?
Reply #5 - Jan 7th, 2015 at 2:10pm
Print Post  
You can ungroup by deleting the hidden node to which you have attached child nodes.

Setting properties to all nodes in the group could be done by looping over all children and assigning to them individually when you need to set a property. Alternatively, try binding child node properties to parent node properties using WPF's SetBinding method and setting group node as data context for children; then setting a property of the group node should update all child nodes.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
heyx
Junior Member
**
Offline


I Love MindFusion!

Posts: 69
Joined: Oct 9th, 2014
Re: how to set selected nodes as a group like ms-visio?
Reply #6 - Jan 23rd, 2015 at 10:05am
Print Post  
hi Stoyan,
    I have tried the method as you told.and could you tell me how to set the GroupNode's borde like the right of the picture.
  

Result.jpg ( 24 KB | 84 Downloads )
Result.jpg
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: how to set selected nodes as a group like ms-visio?
Reply #7 - Jan 23rd, 2015 at 12:07pm
Print Post  
Hi,

Only the RoundAndSquare2 style draws both handles and dashed frame:

Code
Select All
groupNode.HandlesStyle = HandlesStyle.RoundAndSquare2;
diagram.ActiveItemHandlesStyle.HandleBrush = Brushes.LightBlue;
diagram.ActiveItemHandlesStyle.DashPen.Brush = Brushes.LightBlue; 



however its corner handles are rounded. If you need them exactly as in your image, you will have to custom-draw them by setting HandlesStyle to Custom and handling the DrawAdjustmentHandles event.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
heyx
Junior Member
**
Offline


I Love MindFusion!

Posts: 69
Joined: Oct 9th, 2014
Re: how to set selected nodes as a group like ms-visio?
Reply #8 - Jan 26th, 2015 at 8:25am
Print Post  
hi Stoyan,
  I set the HandlesStyle to Custom,and I change the border of the group-node In DrawAdjustmentHandles  method.
  thanks for your help.
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint