Page Index Toggle Pages: 1 Send TopicPrint
Hot Topic (More than 10 Replies) Resize root node (Read 5679 times)
Vincent
Junior Member
**
Offline


I Love MindFusion!

Posts: 62
Joined: Oct 3rd, 2013
Resize root node
Nov 12th, 2013 at 7:45am
Print Post  
Hi,

If I have an E-shape (root), place another E-shape in the upper half and want to add a third shape to the child E-shape, how can I (preferably recursively) resize the root node?

Thanks in advance!

Vincent
  

Capture_035.PNG (Attachment deleted)
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Resize root node
Reply #1 - Nov 12th, 2013 at 1:35pm
Print Post  
Hi,

Make your resizeHeight method recursive, ending with something like this:

Code
Select All
if (parent_node != null)
    parent_node.resizeHeight(...); 



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


I Love MindFusion!

Posts: 62
Joined: Oct 3rd, 2013
Re: Resize root node
Reply #2 - Nov 12th, 2013 at 2:06pm
Print Post  
Hi,

When I try the very same example from the first post, I get the result which can be seen in the image.

I changed resizeHeight to:
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;

                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);
                //this.Resize(r.Width, r.Height + height_to_add);
                lastInflatedNode = this;

                if (getParentIfExists() != null)
                {
                    if (getParentIfExists() is If_Shape)
                    {
                        If_Shape parentToResize = getParentIfExists() as If_Shape;
                        if (parentToResize.Then_connected_node == this)
                            parentToResize.resizeHeight(this.Bounds.Height - parentToResize.ifHeight);
                        if (parentToResize.Else_connected_node == this)
                            parentToResize.resizeHeight(this.Bounds.Height - parentToResize.elseHeight);
                    }
                }
            }
        }
 

  

Capture_036.PNG (Attachment deleted)
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Resize root node
Reply #3 - Nov 12th, 2013 at 6:39pm
Print Post  
The getParentIfExists method you are calling returns null in last test project I have from you. In the diagram you are showing, connected_node is null, getParentIfExists returns null, and resizeHeight never calls its parents recursively, not entering the if (getParentIfExists() != null) block:

Code
Select All
protected BR_Shape getParentIfExists()
{
    if (connected_node != null)
        return parent_node;
    return null;
} 



You guys should learn how to use a debugger.

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


I Love MindFusion!

Posts: 62
Joined: Oct 3rd, 2013
Re: Resize root node
Reply #4 - Nov 13th, 2013 at 7:21am
Print Post  
I fixed the method since the last project indeed. The image is from after that method checks for parent_node.

Greets,
Vincent
  
Back to top
 
IP Logged
 
Waterfiets
Junior Member
**
Offline


I Love MindFusion!

Posts: 78
Joined: Sep 27th, 2013
Re: Resize root node
Reply #5 - Nov 13th, 2013 at 9:24am
Print Post  
Stoyo wrote on Nov 12th, 2013 at 6:39pm:
You guys should learn how to use a debugger.

I hope that helps,
Stoyan


You're right, we should use the debugger more. I guess we're still in the learning phase of using C#.  Embarrassed
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Resize root node
Reply #6 - Nov 13th, 2013 at 12:16pm
Print Post  
Assuming the method now looks like this:

Code
Select All
protected BR_Shape getParentIfExists()
{
    if (parent_node != null)
        return parent_node;
    return null;
} 



recursion still does not work because parent_node is set only on the temporary drag indicator node, and not on the actual node remaining in the diagram. When this handler in MC_Diagram runs, dragIndicator.parent_node is set, but not e.Node.parent_node.

Code
Select All
private void OnNodeCreated(object sender, NodeEventArgs e)
{
    if (dragIndicator != null)
    {
        this.ModificationEffect = ModificationEffect.MoveShades;
        e.Node.Bounds = dragIndicator.Bounds;
        this.Nodes.Remove(dragIndicator);
        dragIndicator = null;
        BR_Shape.lastInflatedNode = null;
    }
} 



You will have to update all parent/child references replacing dragIndicator with e.Node, e.g. add something like:

Code
Select All
((BR_Shape)e.Node).parent_node = ((BR_Shape)dragIndicator).parent_node;
// and also replace parent_node's child reference from dragIndicator to e.Node
 



I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Resize root node
Reply #7 - Nov 13th, 2013 at 12:23pm
Print Post  
Or alternatively, remove e.Node but keep the original dragIndicator node, only fixing its opacity. Then all current parent/child references should remain correct.
  
Back to top
 
IP Logged
 
Waterfiets
Junior Member
**
Offline


I Love MindFusion!

Posts: 78
Joined: Sep 27th, 2013
Re: Resize root node
Reply #8 - Nov 13th, 2013 at 2:14pm
Print Post  
I tried your suggestion but it doesn't seem to work.

This is how my method looks like now:

Code
Select All
                  private void OnNodeCreated(object sender, NodeEventArgs e)
        {
            if (dragIndicator != null)
            {
                this.ModificationEffect = ModificationEffect.MoveShades;
                e.Node.Bounds = dragIndicator.Bounds;
                BRNode copy = e.Node as BRNode;
                copy.parent_node = dragIndicator.parent_node;
                if (dragIndicator.parent_node != null)
                {
                 //  if (dragIndicator.parent_node.type != BRNodeType.TRYCATCH)
                        dragIndicator.parent_node.connected_node = copy;
                }
                this.Nodes.Remove(dragIndicator);
                dragIndicator = null;
                BRNode.lastInflatedNode = null;
                foreach (BRNode node in Content)
                {
                    node.DoNotHighlightConnectionPoint();
                }
                this.Focus();
            }
        }  



It looks like its working underwater, but not visually, because if i check the child's of the parent node it seems to be right. But the child nodes aren't moving if the parent(E shape node) is changing shape. Checked it with debugger as well, but it doesn't show anything weird.

Greets,

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


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Resize root node
Reply #9 - Nov 13th, 2013 at 4:23pm
Print Post  
Quote:
But the child nodes aren't moving if the parent(E shape node) is changing shape.


Child nodes will move when parent shape changes (i.e. slot positions change) only if you code them to. The base diagram control code does not know anything about your slot concept, so you will need to take care of offsetting child nodes when other children are inserted or removed somewhere in the hierarchy of E shapes. I can't see anywhere in your code child positions to be updated when you resize parent's slots.

The base diagram can only move child nodes in parallel with their parent, when you call the AttachTo method.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Resize root node
Reply #10 - Nov 14th, 2013 at 7:53am
Print Post  
This is what a full recursive update should look like:

Code
Select All
public class MyNode : ShapeNode
{
	public MyNode Child1
	{
		get { return child1; }
		set
		{
			if (child1 != value)
			{
				if (child1 != null)
					child1.Detach();
				child1 = value;
				child1.parent = this;
				child1.AttachTo(this, AttachToNode.TopLeft);
				UpdateFromRoot();
			}
		}
	}

	public MyNode Child2
	{
		get { return child2; }
		set
		{
			if (child2 != value)
			{
				if (child2 != null)
					child2.Detach();
				child2 = value;
				child2.parent = this;
				child2.AttachTo(this, AttachToNode.TopLeft);
				UpdateFromRoot();
			}
		}
	}

	private void UpdateFromRoot()
	{
		var root = this;
		while (root.parent != null)
			root = root.parent;
		root.ResizeAndUpdateSlots();
	}

	private void ResizeAndUpdateSlots()
	{
		double height = 3 * padding;
		double width = emptyWidth;
		double currentPos = Bounds.Top + padding;

		foreach (var child in Children)
		{
			if (child != null)
			{
				child.ResizeAndUpdateSlots();
				height += child.Bounds.Height;
				width = Math.Max(
					width, child.Bounds.Width + padding);

				// update child position
				child.Move(Bounds.Left + padding, currentPos);
				currentPos += child.Bounds.Height + padding;
			}
			else
			{
				height += padding;
				currentPos += 2 * padding;
			}
		}

		Resize(width, height);
	}

	private IEnumerable<MyNode> Children
	{
		get
		{
			yield return Child1;
			yield return Child2;
		}
	}

	private MyNode child1;
	private MyNode child2;
	private MyNode parent;

	private double padding = 20;
	private double emptyWidth = 80;
} 



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


I Love MindFusion!

Posts: 78
Joined: Sep 27th, 2013
Re: Resize root node
Reply #11 - Nov 14th, 2013 at 8:47am
Print Post  
Thanks, i will give it a try! Smiley
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint