Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Auto Align (vertically / horizontally) with other nodes with almost the same (X / Y) position (Read 4507 times)
dossantos
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 21
Joined: Mar 25th, 2013
Auto Align (vertically / horizontally) with other nodes with almost the same (X / Y) position
Jul 23rd, 2014 at 9:26am
Print Post  
Hi,


I'd like to achieve some auto-aligning similar to the WinForms Designer of VS, as in:

when dragging a node, and...

- its current Y-Coordinate is near the Y-Coordinate of some other node, snap to that Y-Coord. and display a helper line across the diagram through the top of that node.
- its current Y-Center is near the Y-Center of some other node, snap the center to that Y-Coord. and display a helper line across the diagram through the Y-Center of that node.
- same for Bottom
- similarly for X-Coordinates (Left, Center, Right).


This will help aligning Nodes horizontally and vertically. Is this implemented? (I think Diagram.AutoAlignNodes works differently, right?). So what would I need to do to achieve this? In the NodeModifying-Event, I seem not to be able to change the bounds of the dragged node:

Code (C++)
Select All
        private void HandlesNodeModifying(object sender, NodeValidationEventArgs args)
        {
                const float Delta = 1f;

                var node = args.Node;
                var db = this.Diagram.Bounds;
                var same = this.Diagram.Nodes.Except(new[] { args.Node })
                                                    .FirstOrDefault(n => Math.Abs(n.Bounds.Y - node.Bounds.Y) < Delta);
                if (same!= null)
                {
                    node.Bounds = new RectangleF(node.Bounds.X, same.Bounds.Y, node.Bounds.Width, node.Bounds.Height);
                }

                same= this.Diagram.Nodes.Except(new[] { args.Node })
                                                .FirstOrDefault(n => Math.Abs(n.Bounds.X - node.Bounds.X) < Delta);
                if (same!= null)
                {
                    node.Bounds = new RectangleF(same.Bounds.X, node.Bounds.Y, node.Bounds.Width, node.Bounds.Height);
                }
        }
 






PS: sorry for the amount of questions lately Smiley
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Auto Align (vertically / horizontally) with other nodes with almost the same (X / Y) position
Reply #1 - Jul 23rd, 2014 at 9:40am
Print Post  
Hi,

That's what AutoAlignNodes does, set it to true.

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


I Love MindFusion!

Posts: 21
Joined: Mar 25th, 2013
Re: Auto Align (vertically / horizontally) with other nodes with almost the same (X / Y) position
Reply #2 - Jul 23rd, 2014 at 2:16pm
Print Post  
Thanks, that kind of works, but what if I (for whatever reason) wish to do it manually.

Is there a possibility to update a node's Bounds while the user is dragging it? (Inside the NodeModifying handler it doesn't seem to work).


Cheers,
Tim
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Auto Align (vertically / horizontally) with other nodes with almost the same (X / Y) position
Reply #3 - Jul 23rd, 2014 at 4:09pm
Print Post  
Why the "kind of"? AutoAlignNodes works fine from what I can see. You can change Diagram.AutoAlignDistance if you want aligning to borders at a larger distance.

NodeModifying is a validation event raised before the control sets actual new node .Bounds value calculated from current mouse position. We could add a Bounds event argument for next release if you want to specify new position from the NodeModifying handler. Or if you are using a custom node type, you could set your preferred position from UpdateModify override.
  
Back to top
 
IP Logged
 
dossantos
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 21
Joined: Mar 25th, 2013
Re: Auto Align (vertically / horizontally) with other nodes with almost the same (X / Y) position
Reply #4 - Jul 25th, 2014 at 8:29am
Print Post  
The "kind of" means that it aligns the nodes, yes, but I want to do some extra steps when aligning, and I may need some custom alignment rules on top of "align to border within AutoAlignDistance".

So, a read/write "bounds"-Property on the NodeValidationEventArgs would help me a lot - thanks for adding this (if you may)!

Thanks,
Tim
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Auto Align (vertically / horizontally) with other nodes with almost the same (X / Y) position
Reply #5 - Jul 29th, 2014 at 5:21pm
Print Post  
This build adds an OverrideBounds member to NodeValidationEventArgs:
https://mindfusion.eu/_beta/fcnet63.zip

If you set it from the NodeModifying event handler, the node will be placed at specified position.

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


I Love MindFusion!

Posts: 21
Joined: Mar 25th, 2013
Re: Auto Align (vertically / horizontally) with other nodes with almost the same (X / Y) position
Reply #6 - Jul 30th, 2014 at 11:14am
Print Post  
Perfect! Thank you!

(btw, convincing my boss to buy MindFusion diagramming is in progress Wink getting this quality of support while still in evaluation is pretty awesome!)
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Auto Align (vertically / horizontally) with other nodes with almost the same (X / Y) position
Reply #7 - Jul 30th, 2014 at 12:01pm
Print Post  
best of luck Cool
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint