Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Prevent a DiagramLink from attaching to TableNode (Read 2305 times)
davidl
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 13
Joined: Dec 3rd, 2007
Prevent a DiagramLink from attaching to TableNode
Dec 5th, 2007 at 11:04pm
Print Post  
Hi All,

Does anybody know if there is an easy way to prevent a link from attaching to a node?

I need to prevent circular references in my diagram: meaning if a link of ShapeA is connected to ShapeB, then ShapeB can not have a link that points back to SHapeA. 

The code to detect the CR (circular reference) is easy enough, but I can't find a way to prevent the link from attaching when I do detect the CR.  It seems like all of the link* event handlers  occur a little too late - the link is already created - and even if I try e.Link.Dispose(), it is not removed from the diagram.

Just wondering if anyone has implemented "custom" link prevention.  Thanks for any help.

-David
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Prevent a DiagramLink from attaching to TableN
Reply #1 - Dec 6th, 2007 at 6:38am
Print Post  
Hi,

Here is an easy way to do that:

Code
Select All
private void diagram_LinkModifying(object sender, MindFusion.Diagramming.LinkValidationEventArgs e)
{
	if (e.ChangingOrigin || e.ChangingDestination)
	{
		PathFinder finder = new PathFinder(diagram, false);
		if (finder.FindShortestPath(e.Destination, e.Origin) != null)
			e.Cancel = true;
	}
}

private void diagram_LinkCreating(object sender, MindFusion.Diagramming.LinkValidationEventArgs e)
{
	PathFinder finder = new PathFinder(diagram, false);
	if (finder.FindShortestPath(e.Destination, e.Origin) != null)
		e.Cancel = true;
}
 



This will prevent all cycles in the graph, and not only simple back references. If you wish to prevent just back-links, you could do that by examining the found path and cancel the creation/modification only when the path is of length 1. Another option is to use your own method that iterates over the OutgoingLinks collection of the destination node and looks for a link to the source node.

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


I love YaBB 1G - SP1!

Posts: 13
Joined: Dec 3rd, 2007
Re: Prevent a DiagramLink from attaching to TableN
Reply #2 - Dec 6th, 2007 at 1:06pm
Print Post  
Stoyo,

Thanks, this looks great.

Is there a help document available where I could have found this information myself ?
So far I have just browsed the classes and the sample to figure things out.   Thanks again.

-David
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Prevent a DiagramLink from attaching to TableN
Reply #3 - Dec 6th, 2007 at 4:22pm
Print Post  
You could skim through the "Programming Interface Overview" section of the help file for a higher level overview of the API. The version we are releasing now also includes a tutorial, which is pretty basic at this time, but we will extend it in the following couple of months.

Stoyan
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint