Page Index Toggle Pages: 1 Send TopicPrint
Hot Topic (More than 10 Replies) Reset Node Height (Read 4876 times)
Waterfiets
Junior Member
**
Offline


I Love MindFusion!

Posts: 78
Joined: Sep 27th, 2013
Reset Node Height
Nov 8th, 2013 at 3:26pm
Print Post  
Hi there,

At the moment i have a node which adjusts its size according to the size of the node that has been dragged into it, but it doesn't change back to the original size once i remove the node.

Do you happen to have an easy fix for this and if so could you give me an example?

Here is my code for the resizing.

Code
Select All
  public void assignNodeToPart(BRNode child_shape, Point coord_then, Point coord_else, Point coord_bottom, Point snapPoint)
        {
            double height_to_add = child_shape.Bounds.Height - padding;
            if (snapPoint.Equals(coord_then))
            {
                this.Try_Connected_Node = child_shape;
                if (TryHeight > height_to_add)
                    height_to_add = 0;
                resizeHeight(height_to_add);
                //child_shape.AttachTo(this, AttachToNode.MiddleRight);
            }
            else if (snapPoint.Equals(coord_else))
            {
                this.Catch_Connected_Node = child_shape;
                if (CatchHeight > height_to_add)
                    height_to_add = 0;
                resizeHeight(height_to_add);
                //child_shape.AttachTo(this, AttachToNode.MiddleRight);
            }
            else
            {
                this.connected_node = child_shape;
                child_shape.AttachTo(this, AttachToNode.BottomLeft);
            }
        }

        public void resizeHeight(double height_to_add)
        {
            // Change the bounds of the node according to the size of the child node
            if (lastInflatedNode != this)
            {
                if (lastInflatedNode != null)
                    lastInflatedNode.Bounds = lastBounds;

                Rect r = this.Bounds;
                lastBounds = r;
                Rect newBounds = new Rect(r.X, r.Y, r.Width, r.Height + height_to_add);
                this.SetBounds(newBounds, false, true);
                lastInflatedNode = this;
            }
        } 



Thanks in advance.

Greets,

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


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Reset Node Height
Reply #1 - Nov 11th, 2013 at 8:50am
Print Post  
Hi,

You should be able to calculate the correct height of parent nodes at any time, depending on whether child nodes are assigned to their slots:

Code
Select All
var newHeight = 3 * padding +
    try_node != null ? try_node.Bounds.Height : padding +
    catch_node != null ? catch_node.Bounds.Height : padding;
 



That's assuming you use the E-like shape from previous posts, and padding value designates both thickness of the shape's arms and default spacing between arms when slots are empty.

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


I Love MindFusion!

Posts: 78
Joined: Sep 27th, 2013
Re: Reset Node Height
Reply #2 - Nov 11th, 2013 at 9:11am
Print Post  

Hi there,

We've tried out your solution, but it doesn't seem to work. This is probably caused because the try or catchnode property is not set to null when the node is removed. How can i detect when the node is removed?

Thanks in advance.

Greets,

Sander

Code
Select All
        public void resizeHeight(double height_to_add)
        {
            // Change the bounds of the node according to the size of the child node
            if (lastInflatedNode != this)
            {
                if (lastInflatedNode != null)
                    lastInflatedNode.Bounds = lastBounds;

                double tryHeight = Try_Connected_Node != null ? Try_Connected_Node.Bounds.Height : padding;
                double catchHeight = Catch_Connected_Node != null ? Catch_Connected_Node.Bounds.Height : padding;

                var newHeight = 3 * padding + tryHeight + catchHeight;

                Rect r = this.Bounds;
                lastBounds = r;
                Rect newBounds = new Rect(r.X, r.Y, r.Width, newHeight);
                this.SetBounds(newBounds, false, true);
                lastInflatedNode = this;
            }
        }  

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


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Reset Node Height
Reply #3 - Nov 11th, 2013 at 11:31am
Print Post  
I suppose you should reset it to null from NodeModified handler, when you detect e.Node is a child node and has been moved away from its parent. Or if using custom nodes, you could reset it from an override of the CompleteModify method.

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


I Love MindFusion!

Posts: 78
Joined: Sep 27th, 2013
Re: Reset Node Height
Reply #4 - Nov 11th, 2013 at 12:23pm
Print Post  
Could you give an example of the last example?

Thanks in advace.

Greets,

Sander
« Last Edit: Nov 11th, 2013 at 1:29pm by Waterfiets »  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Reset Node Height
Reply #5 - Nov 11th, 2013 at 5:26pm
Print Post  
If you use the AttachTo method to attach child nodes to parent node, it's actually easier to override OnChildModified in the parent node class:

Code
Select All
// e.g. in If_Shape
protected override void OnChildModified(DiagramNode node, AdjustmentHandles handle)
{
	base.OnChildModified(node, handle);

	if ((node.GetCenter() - this.GetCenter()).Length > 50)
	{
		node.Detach();
		if (node == Then_connected_node)
			Then_connected_node = null;
		resizeHeight(...);
	}
} 



otherwise you will have to make the resizeHeight method public and call it from child's CompleteModify or NodeModified:

Code
Select All
// e.g. in BR_Shape
protected override void CompleteModify(Point end, InteractionState ist)
{
    base.CompleteModify(end, ist);
    AlignToNearestPoint(end, ist);
    lastInflatedNode = null;

	if (parent_node != null)
	{
		if ((parent_node.GetCenter() - this.GetCenter()).Length > 50)
		{
			// call some function to disassociate parent with child and call parent.resizeHeight
		}
		else
		{
			// return node to its slot if user hasn't moved it far enough?
		}
	}
} 



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


I Love MindFusion!

Posts: 78
Joined: Sep 27th, 2013
Re: Reset Node Height
Reply #6 - Nov 12th, 2013 at 12:27pm
Print Post  
Hi there Stoyan,

The solution you suggested worked somewhat. This is what i've tried:

Code
Select All
         protected override void OnChildModified(DiagramNode node, AdjustmentHandles handle)
        {
            base.OnChildModified(node, handle);

            if ((node.GetCenter() - this.GetCenter()).Length > 25)
            {
                node.Detach();
                BRNode childNode = node as BRNode;
                if (node == Try_Connected_Node)
                {
                    Try_Connected_Node = null;
                    resizeHeight(newpadding - node.Bounds.Height);
                    Repaint();
                }
                if (node == Catch_Connected_Node)
                {
                    Catch_Connected_Node = null;
                    resizeHeight(newpadding - node.Bounds.Height);
                    Repaint();
                }
                if (node == connected_node)
                {
                    connected_node = null;
                    childNode.parent_node = null;
                }
            }
        } 



The next problem occurs. When i drag a node into the E shape it will resize. But when i move the node out of the E shape, the resized node stay the same and only centers the mid arm of E but doesnt reset the whole shape to its original size. What am i doing wrong?

Thanks in advance.

Greets,

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


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Reset Node Height
Reply #7 - Nov 12th, 2013 at 1:54pm
Print Post  
The resizeHeight in last test project I have from you doesn't do anything, because lastInflatedNode is set to this:

Code
Select All
version  public void resizeHeight(double height_to_add)
{
    // Change the bounds of the node according to the size of the child node
    if (lastInflatedNode != this)
    ...
 



I suppose you should reset it to null after drag-and-drop operations, or remove the check altogether if you will always be calculating height based on current children.

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


I Love MindFusion!

Posts: 78
Joined: Sep 27th, 2013
Re: Reset Node Height
Reply #8 - Nov 12th, 2013 at 2:08pm
Print Post  
Hi,

resizeHeight is now doing this atm:

Code
Select All
            if (lastInflatedNode != this)
            {
                if (lastInflatedNode != null)
                    lastInflatedNode.Bounds = lastBounds;

                double tryHeight = Try_Connected_Node != null ? Try_Connected_Node.Bounds.Height : padding;
                double catchHeight = Catch_Connected_Node != null ? Catch_Connected_Node.Bounds.Height : padding;


                var newHeight = 3 * padding + tryHeight + catchHeight;

                Rect r = this.Bounds;
                lastBounds = r;

                Rect newBounds = new Rect(r.X, r.Y, r.Width, newHeight);
                this.SetBounds(newBounds, false, true);
                lastInflatedNode = this;
            }  

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


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Reset Node Height
Reply #9 - Nov 12th, 2013 at 6:53pm
Print Post  
That's fine, but does it ever run the code inside that if block when you call it from OnChildModified? Add a breakpoint to the resizeHeight(newpadding - node.Bounds.Height) line and trace with the debugger to see what happens. You should either set lastInflatedNode to null after drag and drop completes, or move the code that calculates height from child nodes out of the if block.

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


I Love MindFusion!

Posts: 78
Joined: Sep 27th, 2013
Re: Reset Node Height
Reply #10 - Nov 13th, 2013 at 9:22am
Print Post  
Hi there,

After tracing it with the debugger i found out the resizeHeight methode did get called in OnChildModified. Also, the lastInflatedNode = null was already set after drag and drop completes. After i moved the code that calculates the height from the child nodes outside of the if block it started to work.  Cheesy

Greets,

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