Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic DiagramLink Intersects check using Node bounds as parameter (Read 1916 times)
beetee
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 23
Location: Switzerland
Joined: Jul 13th, 2017
DiagramLink Intersects check using Node bounds as parameter
Mar 26th, 2018 at 2:25pm
Print Post  
Hello
We allow the user to select a node and move it in the diagram using the Keys(Up/Down/Left/Right). This is implemented in Key Press event handlers. We have to restrict the movement of nodes when it intersects any of the other links in the diagram. We use the DiagramLink.Intersects while moving a node with mouse and it works perfectly. We want to achieve the similar functionality for key press as well.

Is there any API available that take the Bounds of the Node and check if it Intersects with a link? We want to restrict the Key press event in this case so that the node will not intersect the link after it is moved. For that we should know that new Bounds of the Node will not be intersecting with any of the nodes after the movement.

Regards,
BT
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3147
Joined: Oct 19th, 2005
Re: DiagramLink Intersects check using Node bounds as parameter
Reply #1 - Mar 26th, 2018 at 6:57pm
Print Post  
Hi,

Try this approach -

Code
Select All
var hitTester = (DiagramNode)movedNode.Clone(false);
var testRect = movedNode.Bounds;
testRect.Offset(-20, 0);
hitTester.Bounds = testRect;

foreach (var link in diagram.Links)
	if (link.Intersects(hitTester))
	...
 



Regards,
Slavcho
  
Back to top
 
IP Logged
 
beetee
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 23
Location: Switzerland
Joined: Jul 13th, 2017
Re: DiagramLink Intersects check using Node bounds as parameter
Reply #2 - Mar 27th, 2018 at 6:47am
Print Post  
Hello Slavcho,

Thank you for the quick reply.
I have tried your suggestion.
As soon the execution hit the statement

Code
Select All
var hitTester = (DiagramNode)movedNode.Clone(false); 



Application is in break mode.

D:/Delete/2018-03-27_08-37-16.png

Regards,
BT
  

2018-03-27_08-37-16.png ( 14 KB | 98 Downloads )
2018-03-27_08-37-16.png
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3147
Joined: Oct 19th, 2005
Re: DiagramLink Intersects check using Node bounds as parameter
Reply #3 - Mar 27th, 2018 at 7:29am
Print Post  
If it's a custom node class you might have to create a copy constructor. Or just create an instance of rectangular ShapeNode there instead of cloning if you only care about rectangular boundaries.
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint