Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Custom self linking (Read 1201 times)
SavyCat
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 38
Joined: Sep 4th, 2007
Custom self linking
Apr 7th, 2009 at 2:20pm
Print Post  
Hi guys, I've come accross something that might be a future request, as I dont think its currently possible.

Basically, I have a node with a number of inputs and outputs. The node is a square, and all input anchors are on the left and the output ones are on the right. I want the option to be available for the user to link of the outputs back onto one of the inputs of the node. Currently, if I do that and AllowSelfLoops is true, it automatically makes the link a bezier, originating from the top centre opf the node. If I turn AllowSelfLoops  off, the link remains bezier, is still positioned on the top centre but its destination anchor is correct.

Basically I need it so that the link acts like the other links and leaves its origin anchor point - keeps its current style and connect back to the node at the entry anchor.

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


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Custom self linking
Reply #1 - Apr 7th, 2009 at 2:36pm
Print Post  
Try this:

Code
Select All
private void diagram_LinkCreated(object sender, LinkEventArgs e)
{
	if (e.Link.Origin == e.Link.Destination)
		SetSelfLoopShape(e.Link);
}

private void SetSelfLoopShape(DiagramLink link)
{
	link.SegmentCount = 3;
	link.Style = LinkStyle.Cascading;
	diagram.RoutingOptions.Anchoring = Anchoring.Reassign;
	link.Route();
}
 



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


I love YaBB 1G - SP1!

Posts: 38
Joined: Sep 4th, 2007
Re: Custom self linking
Reply #2 - Apr 7th, 2009 at 3:34pm
Print Post  
I managed to get a good effect by doing this:

Code
Select All
/// <summary>
        /// This function is used for setting up self looped links
        /// </summary>
        /// <param name="link"></param>
        private void SetSelfLoopShape(DiagramLink link)
        {
            int oAnchor = link.OriginAnchor;
            int dAnchor = link.DestinationAnchor;

            link.OriginAnchor = -1;
            link.DestinationAnchor = -1;

            link.OriginAnchor = oAnchor;
            link.DestinationAnchor = dAnchor;

            AnchorPoint oAnchorPointO = link.Origin.AnchorPattern.Points[link.OriginIndex];
            float anchorOriginPosX = link.Origin.Bounds.Width * (oAnchorPointO.X / 100.0f) + link.Origin.Bounds.X;
            float anchorOriginPosY = link.Origin.Bounds.Height * (oAnchorPointO.Y / 100.0f) + link.Origin.Bounds.Y;

            AnchorPoint oAnchorPointD = link.Destination.AnchorPattern.Points[link.DestinationIndex];
            float anchorDestinationPosX = link.Destination.Bounds.Width * (oAnchorPointD.X / 100.0f) + link.Destination.Bounds.X;
            float anchorDestinationPosY = link.Destination.Bounds.Height * (oAnchorPointD.Y / 100.0f) + link.Destination.Bounds.Y;

            link.ControlPoints.Clear();
            link.ControlPoints.Add(new PointF(anchorOriginPosX, anchorOriginPosY));
            link.ControlPoints.Add(new PointF(anchorOriginPosX + 3, anchorOriginPosY));

            link.ControlPoints.Add(new PointF(anchorOriginPosX + 3, anchorOriginPosY - link.Destination.Bounds.Height));
            link.ControlPoints.Add(new PointF(anchorDestinationPosX - 3, anchorOriginPosY - link.Destination.Bounds.Height));

            link.ControlPoints.Add(new PointF(anchorDestinationPosX - 3, anchorDestinationPosY));
            link.ControlPoints.Add(new PointF(anchorDestinationPosX, anchorDestinationPosY));

            link.RetainForm = true;
        } 

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