Page Index Toggle Pages: 1 Send TopicPrint
Hot Topic (More than 10 Replies) Self-Link Styling (Read 8652 times)
sydneyos
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 28
Joined: Mar 7th, 2009
Self-Link Styling
Mar 30th, 2009 at 5:58pm
Print Post  
Is there a way to force a Self-Link to link to a particular anchor point?  I have a node that has incoming links at the top, outgoing at the bottom (not using AnchorPattern) and I'd like the self-link to be on the right.  As it is, it's on the top and overlaps w/ the node above it and, more importantly, the text associated w/the link is above the link and looks like it belongs to the above node.

In the attached screen shot, the self-link and it's text (an asterisk) are in red. [Insert image not working, so you'll have to use your imagination]

[img][/img]
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Self-Link Styling
Reply #1 - Mar 31st, 2009 at 9:45am
Print Post  
After creating the link, set its OriginAnchor and DestinationAnchor properties and call its Route() method.

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


I love YaBB 1G - SP1!

Posts: 28
Joined: Mar 7th, 2009
Re: Self-Link Styling
Reply #2 - Mar 31st, 2009 at 5:51pm
Print Post  
To what do I set it? NOthing seems to make a difference? The xml help for OriginAnchor seems to suggest it requires an AnchorPattern, but if I choose TopInBottomOut, can I then set the self-link on an anchor that is not top or bottom? [Late Update:  Setting an AnchorPattern also doesn't seem to make a difference].

Also, this approach seems to make the self-loop really tiny and then invisible after the node loses focus.

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


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Self-Link Styling
Reply #3 - Apr 1st, 2009 at 8:14am
Print Post  
If not using AnchorPatterns, set the position of ControlPoints[0] and ControlPoints[ControlPoints.Count - 1] before calling Route(). Also check the Diagram.RoutingOptions.Anchoring property; you might have to set it to Keep for the routing algorithm to preserve your end points.

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


I love YaBB 1G - SP1!

Posts: 28
Joined: Mar 7th, 2009
Re: Self-Link Styling
Reply #4 - Apr 1st, 2009 at 9:37pm
Print Post  
Umm, again, please say more. Set ControlPoints to what? Can you post or point me to an example of how to do this? Tried this - just gives me a line pointing out. Really not sure what you mean. Note, I am not using the layout engine - everything is positioned manually.
[code]
Rect r = link.Origin.Bounds;
link.Style = LinkStyle.Polyline;
link.ControlPoints[0] = new Point(r.Right, r.Top + (r.Height / 2));
link.ControlPoints[1] = new Point(r.Right + 25, r.Top + (r.Height / 2) + 20);
link.ControlPoints[2] = new Point(r.Right + 25, r.Top + (r.Height / 2) - 20);
link.ControlPoints[3] = new Point(r.Right + 50, r.Top + (r.Height / 2));
[/code]
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Self-Link Styling
Reply #5 - Apr 2nd, 2009 at 9:25am
Print Post  
Try this:

Code
Select All
Rect r = node.Bounds;
float centerx = r.Left + r.Width / 2;
float dist = 10;
SetLinkPoints(link,
	new Point(centerx, r.Top),
	new Point(centerx, r.Top - dist),
	new Point(r.Right + dist, r.Top - dist),
	new Point(r.Right + dist, r.Bottom + dist),
	new Point(centerx, r.Bottom + dist),
	new Point(centerx, r.Bottom));

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



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


I love YaBB 1G - SP1!

Posts: 28
Joined: Mar 7th, 2009
Re: Self-Link Styling
Reply #6 - Apr 2nd, 2009 at 6:28pm
Print Post  
I get an IndexOutOfRangeException on UpdateFromPoints...
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Self-Link Styling
Reply #7 - Apr 3rd, 2009 at 7:42am
Print Post  
Change the method code as below if calling from the LinkCreated handler while the link.Style is Bezier:

Code
Select All
private void SetLinkPoints(DiagramLink link, params Point[] points)
{
	link.AutoRoute = false;
	link.SegmentCount = (short)(points.Length - 1);
	link.Style = LinkStyle.Cascading;
	link.ControlPoints.Clear();
	link.ControlPoints.AddRange(points);
	link.UpdateFromPoints();
}
 



Otherwise the Style = Cascading assignment is ignored while SegmentCount == 1 for the self-loop link.

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


I love YaBB 1G - SP1!

Posts: 28
Joined: Mar 7th, 2009
Re: Self-Link Styling
Reply #8 - Apr 9th, 2009 at 10:08pm
Print Post  
This gets me closer exept:

1.  It goes from the bottom anchor to the top anchor, where I am explicitly trying to avoid those anchors and use the Right sided anchor.

2.  The first and second segments appear invisible, so the link seems to start out in the middle of nowhere, for some reason.

I've tried these settings, which are closer still, but they don't start and end on the node, for some reason that is probably obvious but I can't see.  Plus, the first segment is still invisible:

float centery = (float)(r.Bottom + (r.Height / 2));
float dist = 20;
SetLinkPoints(link,
    new Point(r.Right, centery),
    new Point(r.Right + dist, centery - dist),
    new Point(r.Right + (dist * 2), centery - dist),
    new Point(r.Right + (dist * 2), centery + dist),
    new Point(r.Right + dist, centery + dist),
    new Point(r.Right, centery));

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


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Self-Link Styling
Reply #9 - Apr 10th, 2009 at 7:48am
Print Post  
Try with centery = (float)(r.Top + r.Height / 2);

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


I love YaBB 1G - SP1!

Posts: 28
Joined: Mar 7th, 2009
Re: Self-Link Styling
Reply #10 - Apr 10th, 2009 at 5:17pm
Print Post  
That works for the position - thanks.  However, I still have the problem of the last (not firsttwo segments being invisible - any ideas on that?  Also, I would love the link to be circular, as it seems to be by default, rather than segmented - just attached to a different anchor.  I guess this isn't possible?  The default size and shape are fine, just not the anchor location.

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


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Self-Link Styling
Reply #11 - Apr 12th, 2009 at 11:04am
Print Post  
This moves and rotates the loop-like shape already set for the link:

Code
Select All
private void OnLinkCreated(object sender, LinkEventArgs e)
{
	if (e.Link.Origin == e.Link.Destination)
	{
		Rect r = e.Link.Origin.Bounds;
		float centery = (float)(r.Top + (r.Height / 2));
		var link = e.Link;
		var points = link.ControlPoints.Clone();

		var newO = new Point(r.Right, centery);
		var rt = new RotateTransform(90, newO.X, newO.Y);
		var o = points[0];
		var offset = newO - o;

		for (int i = 0; i < points.Count; ++i)
			points[i] = rt.Transform(points[i] + offset);

		link.ControlPoints.Clear();
		link.ControlPoints.AddRange(points);
		link.UpdateFromPoints();
	}
}
 



You will only have to use a different RotateTransform angle when the link is attached to another side of the node.

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


I love YaBB 1G - SP1!

Posts: 28
Joined: Mar 7th, 2009
Re: Self-Link Styling
Reply #12 - Apr 13th, 2009 at 9:12pm
Print Post  
Perfect!  Thank you, thank you, thank you! Smiley
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Self-Link Styling
Reply #13 - Apr 14th, 2009 at 7:33am
Print Post  
8)
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint