Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic how to make the any anchorpoint of the node just exist only one DiagramLink in the LinkCreating meth (Read 2342 times)
heyx
Junior Member
**
Offline


I Love MindFusion!

Posts: 69
Joined: Oct 9th, 2014
how to make the any anchorpoint of the node just exist only one DiagramLink in the LinkCreating meth
Feb 13th, 2015 at 6:46am
Print Post  
hi,
  I want that there is only one DiagramLink between Two shapeNodes's each anchorpoint.
  could you give me some help?
  thanks.
  

effect.png ( 4 KB | 68 Downloads )
effect.png
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: how to make the any anchorpoint of the node just exist only one DiagramLink in the LinkCreating meth
Reply #1 - Feb 13th, 2015 at 9:08am
Print Post  
Hi,

Try handling ValidateAnchorPoint event:

Code
Select All
void OnValidateAnchorPoint(object sender, LinkValidationEventArgs e)
{
	e.Cancel = CountLinks(e.Node, e.AnchorIndex) > 0;
}

int CountLinks(DiagramNode node, int anchorPoint)
{
	return
		node.IncomingLinks.Count(link => link.DestinationAnchor == anchorPoint) +
		node.OutgoingLinks.Count(link => link.OriginAnchor == anchorPoint);
} 



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


I Love MindFusion!

Posts: 69
Joined: Oct 9th, 2014
Re: how to make the any anchorpoint of the node just exist only one DiagramLink in the LinkCreating meth
Reply #2 - Feb 15th, 2015 at 1:50am
Print Post  
hi Stoyan,

Thanks for your help,but maybe I haven't described my effect clearly.That I want this:
any of the OriginNode‘s AnchorPoint can link some Nodes(more than two).
It just haven't this link like that the link's OriginAnchorPoint
and DestinationAnchor is same as one of the links between OriginAnchorPoint and DestinationAnchor.
  

effect_002.png ( 12 KB | 58 Downloads )
effect_002.png
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: how to make the any anchorpoint of the node just exist only one DiagramLink in the LinkCreating meth
Reply #3 - Feb 16th, 2015 at 11:01am
Print Post  
Hi,

Try this:

Code
Select All
void OnValidateAnchorPoint(object sender, LinkValidationEventArgs e)
{
	e.Cancel = CountLinks(e) > 0;
}

int CountLinks(LinkValidationEventArgs e)
{
	var link = e.Link;
	if (e.ChangingOrigin)
	{
		return e.Node.GetAllLinks().Count(l => l != link &&
			SameOrgAndDest(l, e.Node, e.AnchorIndex, link.Destination, link.DestinationAnchor));
	}
	else
	{
		return e.Node.GetAllLinks().Count(l => l != link &&
			SameOrgAndDest(l, link.Origin, link.OriginAnchor, e.Node, e.AnchorIndex));
	}
}

bool SameOrgAndDest(DiagramLink link,
	DiagramNode originNode, int originAnchor,
	DiagramNode destNode, int destAnchor)
{
	return
		originNode == link.Origin &&
		originAnchor == link.OriginAnchor &&
		destNode == link.Destination &&
		destAnchor == link.DestinationAnchor;
} 



I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint