Page Index Toggle Pages: [1] 2  Send TopicPrint
Hot Topic (More than 10 Replies) Stop avoiding overlapping Nodes on Canvas (Read 8647 times)
kelum
Full Member
***
Offline


I Love MindFusion!

Posts: 100
Joined: Mar 25th, 2017
Stop avoiding overlapping Nodes on Canvas
Apr 5th, 2017 at 6:23am
Print Post  
Currently mind-fusion canvas can overlap Nodes(Objects) . how to avoid that ?

  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3157
Joined: Oct 19th, 2005
Re: Stop avoiding overlapping Nodes on Canvas
Reply #1 - Apr 5th, 2017 at 8:06am
Print Post  
  
Back to top
 
IP Logged
 
kelum
Full Member
***
Offline


I Love MindFusion!

Posts: 100
Joined: Mar 25th, 2017
Re: Stop avoiding overlapping Nodes on Canvas
Reply #2 - Apr 5th, 2017 at 8:17am
Print Post  
but where I need to register that `OnNodeModified` method and how to do it ?

Do I need register it on constructor of window like this ?

public MainWindow()
{
   InitializeComponent();

   flowchart.MouseLeave += OnNodeModified;
}

  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3157
Joined: Oct 19th, 2005
Re: Stop avoiding overlapping Nodes on Canvas
Reply #3 - Apr 5th, 2017 at 8:35am
Print Post  
That's a handler for the NodeModified event.
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3157
Joined: Oct 19th, 2005
Re: Stop avoiding overlapping Nodes on Canvas
Reply #4 - Apr 5th, 2017 at 9:32am
Print Post  
It's raised once you drop a modified mode. You could do the same from NodeCreated handler for new nodes. If you need to move nearby nodes during mouse movement before dropping a modified node, also handle NodeModifying.
  
Back to top
 
IP Logged
 
kelum
Full Member
***
Offline


I Love MindFusion!

Posts: 100
Joined: Mar 25th, 2017
Re: Stop avoiding overlapping Nodes on Canvas
Reply #5 - Apr 5th, 2017 at 9:36am
Print Post  
but its not triggering once I drag and overlap node items on the canvas,  this is not triggering once I Drop directly Node form Node list

How can I trigger this event when select item from node list and drop it like overlapping ?
  
Back to top
 
IP Logged
 
kelum
Full Member
***
Offline


I Love MindFusion!

Posts: 100
Joined: Mar 25th, 2017
Re: Stop avoiding overlapping Nodes on Canvas
Reply #6 - Apr 5th, 2017 at 9:39am
Print Post  
Now Oky I define it like following

Code
Select All
<diag:Diagram x:Name="dia" AllowDrop="True" RotateCursor="Hand" ShowGrid="True" NodeCreated="OnNodeCreated" NodeModified="OnNodeModified"/>

        private void OnNodeModified(object sender, NodeEventArgs e)
        {
            RemoveOverlaps(e.Node, 20);
        }

        private void OnNodeCreated(object sender, NodeEventArgs e)
        {
            RemoveOverlaps(e.Node, 20);
        }
 



Thanks lot
  
Back to top
 
IP Logged
 
kelum
Full Member
***
Offline


I Love MindFusion!

Posts: 100
Joined: Mar 25th, 2017
Re: Stop avoiding overlapping Nodes on Canvas
Reply #7 - Apr 5th, 2017 at 9:42am
Print Post  
is there any method, If overlapping dragging Node with existing Node, by giving Waring message and reset dragging object to on its previous location ?
  
Back to top
 
IP Logged
 
kelum
Full Member
***
Offline


I Love MindFusion!

Posts: 100
Joined: Mar 25th, 2017
Re: Stop avoiding overlapping Nodes on Canvas
Reply #8 - Apr 5th, 2017 at 9:53am
Print Post  
I have another question here,

By rotating Node , I can overlap Nodes

So I tried override Hand event like following

Code
Select All
diag:Diagram x:Name="flowchart" AllowDrop="True" RotateCursor="Hand" ShowGrid="True" NodeCreated="OnNodeCreated" NodeModified="OnNodeModified"/>

        private void Hand(object sender, NodeEventArgs e)
        {
            RemoveOverlaps(e.Node, 2);
        } 




but its not working ?
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3157
Joined: Oct 19th, 2005
Re: Stop avoiding overlapping Nodes on Canvas
Reply #9 - Apr 5th, 2017 at 5:04pm
Print Post  
Quote:
is there any method,  If overlapping dragging Node with existing Node, by giving Waring message and reset dragging object to on its previous location ?


From NodeModifying handler set e.Cancel = true when FindOverlaps returns any nodes. This will show the stop cursor, and return the node to original location if you drop the node there.


Quote:
By rotating Node , I can overlap Nodes So I tried override Hand event like following


RotateCursor is not an event but a property. You should still get NodeModified event raised when a node is rotated. However you might need to extend FindOverlaps to support rotation - try replacing node.Bounds with node.GetRotatedBounds() there.
  
Back to top
 
IP Logged
 
kelum
Full Member
***
Offline


I Love MindFusion!

Posts: 100
Joined: Mar 25th, 2017
Re: Stop avoiding overlapping Nodes on Canvas
Reply #10 - Apr 6th, 2017 at 3:08am
Print Post  
`OnNodeModified` method calling only `RemoveOverlaps` method. its a void method not return anything, so where should I use this `e.Cancel = true` ?

Once I define use like this

Code
Select All
        private void OnNodeModified(object sender, NodeEventArgs e)
        {
            RemoveOverlaps(e.Node, 2);
            e.Cancel = true;
        } 



Getting following error

`'NodeEventArgs' does not contain a definition for 'Cancel' and no extension method 'Cancel' accepting a first argument of type 'NodeEventArgs' could be found`


« Last Edit: Apr 6th, 2017 at 6:33am by kelum »  
Back to top
 
IP Logged
 
kelum
Full Member
***
Offline


I Love MindFusion!

Posts: 100
Joined: Mar 25th, 2017
Re: Stop avoiding overlapping Nodes on Canvas
Reply #11 - Apr 6th, 2017 at 3:51am
Print Post  
to stop overlap once rotate

as you mentioned I changed `FindOverlap` method following line

Code
Select All
 if (bounds.IntersectsWith(node.Bounds))  


                   
            to

Code
Select All
if (bounds.IntersectsWith(node.GetRotatedBounds())) 



but still I can rotate to overlap objects
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3157
Joined: Oct 19th, 2005
Re: Stop avoiding overlapping Nodes on Canvas
Reply #12 - Apr 6th, 2017 at 7:45am
Print Post  
Quote:
but still I can rotate to overlap objects

Have you also changed the "bounds" variable assignment to use rotated-bounds value?

Quote:
e.Cancel = ...

You can use this in NodeModifying validation event handler; it's different from the NodeModified event you are showing above.
  
Back to top
 
IP Logged
 
kelum
Full Member
***
Offline


I Love MindFusion!

Posts: 100
Joined: Mar 25th, 2017
Re: Stop avoiding overlapping Nodes on Canvas
Reply #13 - Apr 6th, 2017 at 8:30am
Print Post  
to reset to last location if dragging node overlapping with existing node,

I changed xml file like following

Code
Select All
<diag:Diagram x:Name="diagramFile" AllowDrop="True" RotateCursor="Hand" ShowGrid="True" NodeModifying="OnNodeModifiying" NodeCreated="OnNodeCreated"
		NodeModified="OnNodeModified"/>

        private void OnNodeModifiying(object sender, NodeValidationEventArgs e)
        {
            e.Cancel = true;
        } 



But in `OnNodeModifiying` method how to find nodes that overlapping each other ?

can you mention implementation of `OnNodeModifiying` method
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3157
Joined: Oct 19th, 2005
Re: Stop avoiding overlapping Nodes on Canvas
Reply #14 - Apr 6th, 2017 at 1:00pm
Print Post  
Code
Select All
private void OnNodeModifying(object sender, NodeValidationEventArgs e)
{
	e.Cancel = FindOverlaps(e.Node, 5).Count > 0;
} 



FindOverlaps is from thread linked above.

Regards,
Slavcho
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: [1] 2 
Send TopicPrint