Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic How to make the links attach to the shape sides only? (Read 3358 times)
mihai
Junior Member
**
Offline



Posts: 86
Joined: Jul 29th, 2009
How to make the links attach to the shape sides only?
Aug 11th, 2014 at 1:01pm
Print Post  
Hi,

I have several rectangle ShapeNodes that are connected through links. How do I allow the links to only anchor to the sides of the rectangles (e.g. not the center)? I know I could define anchor points, but maybe there is a better way.

Thanks,
-Mihai
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: How to make the links attach to the shape sides only?
Reply #1 - Aug 12th, 2014 at 2:12pm
Print Post  
Hi,

Set the links' AutoSnapToNode property. If you don't want the snap-from-distance feature that it also enables, assign a small value to Diagram.AutoSnapDistance.

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



Posts: 86
Joined: Jul 29th, 2009
Re: How to make the links attach to the shape sides only?
Reply #2 - Aug 26th, 2014 at 9:24am
Print Post  
This only works if I set the Anchoring to Reassign.

The origin node has no anchor points defined, and I'm fine there with the re-assign. However, the destination node has anchor points defined, and the link is initially connected to a specific anchor point, and I want them to stay there.

Is there a way for the Reassign option to only operate on the side of the link where there is no anchor specified? Say Anchoring.ReassignOriginButKeepDestination, or vice-versa, Anchoring.ReassignDestinationButKeepOrigin.
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: How to make the links attach to the shape sides only?
Reply #3 - Aug 26th, 2014 at 10:20am
Print Post  
AutoSnapToNode is for interactive drawing of links. Since there's Anchoring property in layout classes and RoutingOptions, are we talking about link alignments when calling layout.Arrange() or link routing methods?
  
Back to top
 
IP Logged
 
mihai
Junior Member
**
Offline



Posts: 86
Joined: Jul 29th, 2009
Re: How to make the links attach to the shape sides only?
Reply #4 - Aug 26th, 2014 at 10:30am
Print Post  
It's about the OrthogonalRouter.Arrange (so for links). Sorry I forgot to mention.

PS: Given this, what are your thoughts on having support for Anchoring.ReassignOriginButKeepDestination/ReassignDestinationButKeepOrigin?
« Last Edit: Aug 26th, 2014 at 12:30pm by mihai »  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: How to make the links attach to the shape sides only?
Reply #5 - Aug 27th, 2014 at 6:53am
Print Post  
We'll have it in mind for next version. For time being you could arrange links between node columns as in the sample file you emailed me like this:

Code
Select All
void ArrangeLinks()
{
	foreach (var link in diagram.Links)
	{
		if (link.OriginAnchor != -1 &&
			link.DestinationAnchor != -1)
		{
			link.Route();
			continue;
		}
		var end = link.EndPoint;
		var start = end;
		start.X = link.Origin.Bounds.Right;
		SetLinkPoints(link, start, end);

		var intersectedNode = IntersectedNode(link);
		if (intersectedNode == null)
			continue;
		var bend1 = end;
		var bend2 = end;
		var r = intersectedNode.Bounds;
		bend1.X = bend2.X = (end.X + r.Right) / 2;
		if (start.Y < intersectedNode.GetCenter().Y)
			bend1.Y = r.Top - 10;
		else
			bend1.Y = r.Bottom + 10;
		start.Y = bend1.Y;
		SetLinkPoints(link, start, bend1, bend2, end);
	}
}

private void SetLinkPoints(DiagramLink link, params Point[] points)
{
	link.AutoRoute = false;
	link.SegmentCount = (short)(points.Length - 1);
	link.Shape = LinkShape.Polyline;
	link.ControlPoints.Clear();
	link.ControlPoints.AddRange(points);
	link.UpdateFromPoints();
}

DiagramNode IntersectedNode(DiagramLink link)
{
	foreach (var node in diagram.Nodes)
	{
		if (node == link.Origin ||
			node == link.Destination ||
			node is ContainerNode)
			continue;
		if (link.Intersects(node))
			return node;
	}
	return null;
} 



If you need to support more than two columns of small nodes on the right of the large one, you can enclose the code that assigns bend1 and bend2 points within a loop over all inner columns, adding two bends if the link intersects a node from the column.

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