Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Matching Start and End points of Links - is it possible (Read 2639 times)
AR
Junior Member
**
Offline


I Love MindFusion!

Posts: 65
Joined: Jan 23rd, 2015
Matching Start and End points of Links - is it possible
May 7th, 2015 at 4:56pm
Print Post  
When the user creates a link on one layer of the diagram, I am automatically creating one or more links on the other layer.

Is it possible to tell the links I create to start/end in the same place on the nodes as the one the user created? As illustrated in top pair of layers in attachment.

Also if I have to create multiple links is it possible to tell them to start\end near to but not on top of one another. As illustrated in the bottom pair layers in attachment.
  

LayerLinks.png ( 10 KB | 149 Downloads )
LayerLinks.png
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Matching Start and End points of Links - is it possible
Reply #1 - May 8th, 2015 at 8:32am
Print Post  
Hi,

You could copy point coordinates from original link's ControlPoints to new link's ControlPoints. This should be done automatically if you use the DiagramLink(prototype, src, dest) constructor.

You can offset the cloned links using some vector math, adding normal left-hand or right-hand vector to each of their points:

Code
Select All
import com.mindfusion.common.Vector;

void offsetPoints(DiagramLink link, float dist)
{
	Point2D.Float[] points = link.getControlPoints().getArray();
	int last = points.length - 1;
	Vector current = normal(points[0], points[1], dist);
	link.getControlPoints().set(0, Vector.add(current, points[0]));
	for (int i = 1; i < last; i++)
	{
		Vector next = normal(points[i], points[i + 1], dist);
		Vector nv = Vector.add(current,  next);
		link.getControlPoints().set(i, Vector.add(nv, points[i]));
		current = next;
	}
	link.getControlPoints().set(last, Vector.add(current, points[last]));
	link.updateFromPoints();
}

Vector normal(Point2D p1, Point2D p2, float len)
{
	Vector v = new Vector(p1, p2);
	return Vector.divide(
		Vector.left(v),
		v.length() / len);
} 



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