Page Index Toggle Pages: 1 Send TopicPrint
Hot Topic (More than 10 Replies) Anchor points changed after using Layout.arrange (Read 5145 times)
lenix
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 31
Joined: Apr 6th, 2011
Anchor points changed after using Layout.arrange
May 4th, 2011 at 8:12am
Print Post  
Hello,

Some specific nodes in my diagrams have links connected to their centers.

Now after I draw all the nodes, connect the links to their positions ( sometimes center, other times border ) and then I call SpringLayout.Arrange(). The anchor points positions changes.

I'd like to keep my original anchor points. In other words I want the layout to handle everything but the links origin / destination anchors.

I tried to set the diagram.RoutingOptions.Anchoring to Keep and the Layout.Anchoring to Keep. No luck. ( I also tried Reassign ).

Any idea how to do this?

Many thanks in advance,
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Anchor points changed after using Layout.arran
Reply #1 - May 4th, 2011 at 8:36am
Print Post  
Hi,

You are calling RouteAllLinks after layout.Arrange, right? You will have to set the AnchorPattern of these nodes to one with an AnchorPoint at (50, 50) for RoutingOptions.Anchoring to work. Otherwise SpringLayout moves the link end point to the node border, and RouteAllLinks will keep it if there are no anchor points defined.

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


I love YaBB 1G - SP1!

Posts: 31
Joined: Apr 6th, 2011
Re: Anchor points changed after using Layout.arran
Reply #2 - May 4th, 2011 at 9:16am
Print Post  
Ok I got it working fine by setting my own AnchorPattern and adding one point (50,50).

I have another questions, remember the functions you gave me before to distribute links on nodes ( so they don't originate from same position )?

Now I understand these functions do well when the links are originating from the border of the node and not the center.
What If I have 4 links originating from the center of a node? Is it possible to distribute these inside the node?

Maybe I'll have to work on the functions you gave me to handle links originating from node center.

Thanks a lot  Roll Eyes
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Anchor points changed after using Layout.arran
Reply #3 - May 4th, 2011 at 10:44am
Print Post  
Yes, those methods will work only from the borders of rectangular nodes. Perhaps you should let SpringLayout place the links at the borders, and move them back to the center after calling Arrange.

Otherwise if the link end points don't lie at the node.Bounds rectangle, you will need to sort them by the angle their end segments make with the node. You can use the CarteseanToPolar method from this post to find the angles:
http://mindfusion.eu/Forum/YaBB.pl?board=diaglite_disc;action=display;num=127061...

and then divide the plane by 90 degree sections starting from 45, and add the links from each section to respectively the top/left/bottom/rightLinks collections in DistributeLinks. Let me know if you need help on this 8)
  
Back to top
 
IP Logged
 
lenix
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 31
Joined: Apr 6th, 2011
Re: Anchor points changed after using Layout.arran
Reply #4 - May 4th, 2011 at 12:37pm
Print Post  
Thanks a lot for the help Stoyo

Option 1 seems easy to implement and I'm trying it now.
Now the diagram is exactly like I want it but I need to move some links inside their nodes.

Now let's say that I have a List<DiagramNode> of all the nodes that their links needs repositioning.

I'll do something like:
Code
Select All
(foreach DiagramNode node in nodes)
{
     (foreach DiagramLink link in node.Links)
     {
	link.ControlPoints[1] = new PointF(link.ControlPoints[1].X + 2, link.ControlPoints[1].Y);


     link.UpdateFromPoints();
     }
}
 



Is this good practice or should I do something else?
And I'm not sure how to determine in which direction I should push the ControlPoint ( X or Y )?

Thanks
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Anchor points changed after using Layout.arran
Reply #5 - May 4th, 2011 at 12:43pm
Print Post  
You should do something like this inside the nodes loop:

Code
Select All
PointF center = node.GetCenter();
foreach (DiagramLink link in node.OutgoingLinks)
{
	link.ControlPoints[0] = center;
	link.UpdateFromPoints();
}
foreach (DiagramLink link in node.IncomingLinks)
{
	link.ControlPoints[last] = center;
	link.UpdateFromPoints();
} 



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


I love YaBB 1G - SP1!

Posts: 31
Joined: Apr 6th, 2011
Re: Anchor points changed after using Layout.arran
Reply #6 - May 4th, 2011 at 1:05pm
Print Post  
Won't that make all the links at a specific node originate from the center?

What I'm intending to do is to push each ControlPoint inside the border of the node its connected to. So then the links are distributed ( vertically/horizontally ) inside the node.

Here is an example:


I have a list of nodes that look like the above node. You can see that links are distributed around the border of the node ( via the Distribute methods you gave me ).

Now I need to push the links points to the red X's so they're inside and not on the border.

Hope it's clearer now

Thanks
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Anchor points changed after using Layout.arran
Reply #7 - May 4th, 2011 at 1:11pm
Print Post  
Yes, that will move them to the center as you wanted, but the other end of the link segment should stay at a position where the links will still be distributed. Alternatively you can keep these points at the borders, and insert the node center points at the beginning and end of ControlPoints. In that case you'd have to call UpdateControlPoints with the updateSegmentCount argument set to true.
  
Back to top
 
IP Logged
 
lenix
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 31
Joined: Apr 6th, 2011
Re: Anchor points changed after using Layout.arran
Reply #8 - May 4th, 2011 at 2:22pm
Print Post  
I think you are misunderstanding me, did you see the example I posted in the above post?

I don't want the links to just originate from the center of the node. I want this them to be distributed inside the node. Just like the example above.

So now the links are distributed fine but they're on the border of the node, they just need to be pushed inside ( keeping their Y coordinate value  or X depending on their position).

Thanks
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Anchor points changed after using Layout.arran
Reply #9 - May 4th, 2011 at 4:29pm
Print Post  
You can offset link points at the end of the DistributeLinks method by iterating over each of the left/top/right/bottomLinks collections, and adding respectively +offset to x / + offset to y / - offset to x / -offset to y  depending on the current collection. The point you need to change is either ControlPoints[0] if link.Origin == node, or ControlPoints[Count-1] if link.Destination == node. For example:

Code
Select All
foreach (DiagramLink link in leftLinks)
	OffsetPoint(link, node, +2, 0);

void OffsetPoint(DiagramLink link, DiagramNode node, float dx, float dy)
{
	var points = link.ControlPoints;
	int i = link.Origin == node ? 0 : points.Count - 1;
	var point = points[i];
	point.X += dx;
	point.Y += dy;
	points[i] = point;
	link.UpdateFromPoints();
} 



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


I love YaBB 1G - SP1!

Posts: 31
Joined: Apr 6th, 2011
Re: Anchor points changed after using Layout.arran
Reply #10 - May 9th, 2011 at 12:39pm
Print Post  
Thanks a lot Stoyo, you're great. Everything is running fine, for now at least.
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint