Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Recreating rectangle while moving nodes attached to master node (Group) (Read 1727 times)
PiotrMakowiec
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 12
Joined: Jul 26th, 2017
Recreating rectangle while moving nodes attached to master node (Group)
Jul 26th, 2017 at 4:09pm
Print Post  
Hi, I've got some issue :/
I have created group of nodes, by creating ShapeNode and attache other Nodes to it and create rectangle, which is around the group. I wanna mention, that I want to modify nodes inside the group, so that's why their Lock property is set to false.

Code
Select All
 private void CreateGroupButton_Click(object sender, RoutedEventArgs e)
      {
         if (FlowChart.Selection.Nodes.Count > 1)
         {
            var groupNode = FlowChart.Factory.CreateShapeNode(0, 0, 1, 1);
            groupNode.ZBottom(false);
            groupNode.Transparent = true;
            groupNode.HandlesStyle = HandlesStyle.MoveOnly;

            CreateGroup(groupNode, FlowChart.Selection.Nodes);

            foreach (DiagramNode node in groupNode.SubordinateGroup.AttachedNodes)
            {
               node.Locked = false;

            }
            groupNode.SubordinateGroup.AutoDeleteItems = true;
            FlowChart.Selection.Change(groupNode);
         }

      }

      private static void CreateGroup(DiagramNode node, DiagramNodeCollection children)
      {
         Rect r = Rect.Empty;

         foreach (var 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 (var child in children)
         {
            child.AttachTo(node, AttachToNode.TopLeft);
         }
      }
 



And my problem is, when I am modifying nodes inside the group. I'd like rectangle is adjusting to the position of the nodes. That's why I am creating rectangle every time node is modifying, but I don't know the node starts changing its size, when I only move it. Below it's the code:

Code
Select All
private void FlowChart_NodeModifying(object sender, NodeValidationEventArgs e)
      {

         var nodes = FlowChart.Selection.Nodes;

         var masterGroup = nodes.First().MasterGroup;

         if (masterGroup != null)
         {
            var children2 = masterGroup.AttachedNodes.Cast<DiagramNode>();

            var diagramCollection = new DiagramNodeCollection();

            foreach (var diagramNode in children2)
            {
               diagramCollection.Add(diagramNode);
            }

            var masterNode = masterGroup.MainItem;

            if (masterNode != null)
            {
               Regroup(masterNode as DiagramNode, diagramCollection);
            }
         }

      }

      private void Regroup(DiagramNode node, DiagramNodeCollection children)
      {


         Rect r = Rect.Empty;
         foreach (var child in children)
         {
            Rect cb = child.Bounds;
            if (r.IsEmpty)
            {
               r = cb;
            }
            else
            {
               r = Rect.Union(r, cb);
            }
         }

         double margin = 5;
         r.Inflate(margin, margin);

         node.Bounds = r;

      }
 



I wonder if you know, what issue it can be.
Thanks for your help.
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3152
Joined: Oct 19th, 2005
Re: Recreating rectangle while moving nodes attached to master node (Group)
Reply #1 - Jul 26th, 2017 at 5:18pm
Print Post  
Hi,

The Bounds setter also moves related links and subordinate nodes. Try replacing it with this instead -

Code
Select All
private void Regroup(DiagramNode node, DiagramNodeCollection children)
{
    ....
    node.SetBounds(r, false, false); 



If the group node stays invisible, maybe do that just once from NodeModified handler.

Regards,
Slavcho
Mindfusion
  
Back to top
 
IP Logged
 
PiotrMakowiec
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 12
Joined: Jul 26th, 2017
Re: Recreating rectangle while moving nodes attached to master node (Group)
Reply #2 - Jul 26th, 2017 at 7:30pm
Print Post  
Slavcho thank you so much  Smiley Quote:
node.SetBounds(r, false, false);
solved the problem.

Best regards
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint