Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Method for reassigning links to nearest anchor points? (Read 2425 times)
beetee
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 23
Location: Switzerland
Joined: Jul 13th, 2017
Method for reassigning links to nearest anchor points?
Jul 13th, 2017 at 9:15am
Print Post  
Hello,

Is there any method available that reassigns links to nearest anchor points? I know that DiagramNode.ReassignAnchorPoints method evenly distributes the links to anchor points.

Kindly refer the attached document for more details.

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


tech.support

Posts: 3147
Joined: Oct 19th, 2005
Re: Method for reassigning links to nearest anchor points?
Reply #1 - Jul 13th, 2017 at 10:47am
Print Post  
Hi,

Have you tried calling link.ReassignAnchorPoints()?

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


I Love MindFusion!

Posts: 23
Location: Switzerland
Joined: Jul 13th, 2017
Re: Method for reassigning links to nearest anchor points?
Reply #2 - Jul 13th, 2017 at 1:03pm
Print Post  
Hello Slavcho,

I have tried link.ReassignAnchorPoints() and could not get expected behavior. I think this method will reassign anchor points on both sides of the link.

Looking for some API like node.ReassignAnchorPoints() which reassign anchor points only according to the nearest point and does not try to evenly distribute the anchor points.

Thank you
BT
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3147
Joined: Oct 19th, 2005
Re: Method for reassigning links to nearest anchor points?
Reply #3 - Jul 13th, 2017 at 4:43pm
Print Post  
Hi BT,

Try this method -
Code
Select All
Point PositionInDiagram(AnchorPoint ap, DiagramNode node)
{
	var r = node.Bounds;
	return new Point(
		r.X + r.Width * ap.X / 100,
		r.Y + r.Height * ap.Y / 100);
}

int NearestAnchorPoint(DiagramNode node, bool incoming, Point point)
{
	int nearest = -1;
	double minDist = Double.MaxValue;

	for (int i = 0; i < node.AnchorPattern.Points.Count; i++)
	{
		var ap = node.AnchorPattern.Points[i];
		if (ap.AllowIncoming != incoming)
			continue;
		var pos = PositionInDiagram(ap, node);
		var dist = Utilities.Distance(pos, point);
		if (dist < minDist)
		{
			minDist = dist;
			nearest = i;
		}
	}
	return nearest;
}

void AlignEndToAnchorPoint(DiagramLink link)
{
	var destNode = link.Destination;
	var destAnchor = NearestAnchorPoint(
		destNode, true, link.StartPoint);
	if (destAnchor > -1)
	{
		link.EndPoint = PositionInDiagram(
			destNode.AnchorPattern.Points[destAnchor],
			destNode);
		link.DestinationAnchor = destAnchor;
		link.Route();
	}
} 



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


I Love MindFusion!

Posts: 23
Location: Switzerland
Joined: Jul 13th, 2017
Re: Method for reassigning links to nearest anchor points?
Reply #4 - Jul 14th, 2017 at 8:52am
Print Post  
Hello Slavcho,

It works with your code.

Thank you very much.

Regards,
BT
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint