Page Index Toggle Pages: 1 2 [3]  Send TopicPrint
Very Hot Topic (More than 25 Replies) Autosnap diagram nodes if within certain distance? (Read 16392 times)
Vincent
Junior Member
**
Offline


I Love MindFusion!

Posts: 62
Joined: Oct 3rd, 2013
Re: Autosnap diagram nodes if within certain distance?
Reply #30 - Oct 11th, 2013 at 1:57pm
Print Post  
Hi Stoyan,

I believe so. I use the following 2 methods to achieve that.

Code
Select All
public void assignNodeToPart(BR_Shape child_shape, Point coord_then, Point coord_else, Point coord_bottom, Point snapPoint)
        {
            double height_to_add = child_shape.Bounds.Height - 20;
            if (snapPoint.Equals(coord_then))
            {
                this.Then_connected_node = child_shape;
                resizeHeight(height_to_add);
            }
            else if (snapPoint.Equals(coord_else))
            {
                this.Else_connected_node = child_shape;
                resizeHeight(height_to_add);
            }
            else
                this.connected_node = child_shape;
        }

        private 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;
                this.Bounds = new Rect(r.X, r.Y, r.Width, r.Height + height_to_add);
                lastInflatedNode = this;
            }
        }
 



In the code, double height_to_add = child_shape.Bounds.Height - 20; I use 20 because that's the initial height of the if-part and else-part.

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


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Autosnap diagram nodes if within certain distance?
Reply #31 - Oct 11th, 2013 at 5:04pm
Print Post  
It should be something easy to spot if you trace with the debugger. Add a conditional breakpoint to Draw with an ifNode != null && elseNode != null condition, and step line by line to see what values you get for local variables when you attach both child nodes. If you can't find the problem, attach a test project that reproduces it and our developer will check it.

Stoyan
  
Back to top
 
IP Logged
 
Vincent
Junior Member
**
Offline


I Love MindFusion!

Posts: 62
Joined: Oct 3rd, 2013
Re: Autosnap diagram nodes if within certain distance?
Reply #32 - Oct 14th, 2013 at 1:02pm
Print Post  
Hi Stoyan,

I can't seem to find the source of the problem... I've added a debug part in the code of draw and tried to find it but alas Shocked

Thanks in advance!

Vincent

  

DragDropExample_-_Copy_001.zip (Attachment deleted)
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Autosnap diagram nodes if within certain distance?
Reply #33 - Oct 14th, 2013 at 1:46pm
Print Post  
Hi,

The problem is that resizeHeight works only first time because you never set lastInflatedNode back to null:

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



lastInflatedNode flags that you should not resize the parent anymore for the currently dragged child, but once the child is dropped, you should set it to null to allow resizing for next child. E.g. you could make it static:

static internal BR_Shape lastInflatedNode = null;

Reset it from MC_Diagram.OnNodeCreated:
BR_Shape.lastInflatedNode = null;

and from BR_Mode.CompleteModify:
lastInflatedNode = null;

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


I Love MindFusion!

Posts: 62
Joined: Oct 3rd, 2013
Re: Autosnap diagram nodes if within certain distance?
Reply #34 - Oct 14th, 2013 at 2:43pm
Print Post  
You...are a hero!  Grin

Thanks, it works!!

Vincent
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1 2 [3] 
Send TopicPrint