Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic ContainerNode moves when changing size (Read 2761 times)
Sim
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 10
Joined: Oct 8th, 2014
ContainerNode moves when changing size
Jan 7th, 2015 at 12:28pm
Print Post  
I'm implementing a feature where multiple ContainerNode objects can be placed inside one another to create a layered swim lane.

One part of this functionality is changing the size of the parent ContainerNode to fit the child ContainerNodes. However, something strange happens. When a second ContainerNode is added to the parent, the parent moves. The image which I have attached to this post contains an example. A parent ContainerNode is placed on the corner of another node and then a second child is added to the parent. This moves the parent, while the children stay in the right spot.

The code that is causing the issue is the following:
Code (C++)
Select All
public void ChildAdded()
{
    if (!this.OldBounds.IsEmpty)
    {
        float totalHeight = 0.0f;
        foreach (DiagramNode connectedNode in this.SubordinateGroup.AttachedNodes)
        {
            MyContainerNode connectedContainer = connectedNode as MyContainerNode;
            if (null != connectedContainer)
            {
                totalHeight += connectedContainer.Bounds.Width;
            }
        }

        PointF location = new PointF(this.OldBounds.X, this.OldBounds.Y);
        SizeF size = new SizeF(totalHeight, this.OldBounds.Height);
        RectangleF bounds = new RectangleF(location, size);
        this.SetBounds(bounds, true, true);
    }
} 



This method is a part of the MyContainerNode class and the OldBounds property is a copy of the Bounds of the ContainerNode before the child was added. Note: the MyContainerNode objects are rotated 270 degrees, which is why 'totalHeight' actually containers the width of the children.

Using the code above, the Bounds.Location of the parent does not change when the second child is added.

If I remove the call 'this.SetBounds(bounds, true, true);'  the parent will not move.

What could be causing the parent lane to move?
  

container_behavior.png ( 7 KB | 85 Downloads )
container_behavior.png
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: ContainerNode moves when changing size
Reply #1 - Jan 7th, 2015 at 2:29pm
Print Post  
The Bounds property specifies the rectangle coordinates for 0 rotation angle, so you will actually have to also change Bounds.Location if you want the corner to remain at same position after rotation center moves (due to size change). Our auto-sizing code already takes this into account, so try this instead:

Code
Select All
container.AutoGrow = true;
container.Margin = 0;
container.UpdateBounds(); 



That should not change parent's top-left position if the newly added node is aligned below old nodes.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Sim
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 10
Joined: Oct 8th, 2014
Re: ContainerNode moves when changing size
Reply #2 - Jan 7th, 2015 at 3:03pm
Print Post  
I am currently using MindFusion.Diagramming version 6.1.2 which does not seem to support the AutoGrow property just yet. Would it be possible to keep the corner in the same position in version 6.1.2?
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: ContainerNode moves when changing size
Reply #3 - Jan 8th, 2015 at 11:51am
Print Post  
Try this:

Code
Select All
// 270 degree rotation bring Bounds top-right point to top-left
var corners = new[]
{
	new PointF(OldBounds.Right, OldBounds.Top),
	new PointF(OldBounds.Left, OldBounds.Bottom)
};
var rotation = new Matrix();
rotation.RotateAt(270, GetCenter());
rotation.TransformPoints(corners);
corners[1].Y = corners[0].Y + totalHeight;

// rotate back around new center to get 0-degree corner locations
var inverse = new Matrix();
inverse.RotateAt(-270,
	InternalUtils.MidPoint(corners[0], corners[1]));
inverse.TransformPoints(corners);

RectangleF bounds = RectangleF.FromLTRB(
	corners[0].X, corners[0].Y, corners[1].X, corners[1].Y);
 



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