We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.

Preventing placement of unconnected connectors

Thread ID:

Created:

Updated:

Platform:

Replies:

119107 May 11,2015 10:41 AM May 13,2015 01:01 AM Windows Forms 3
loading
Tags: Diagram
Andrew Le Couteur Bisson
Asked On May 11, 2015 10:41 AM

I wish to prevent the placement of unconnected connectors.  My best guess at how to achieve this is as shown below.

internal class MyLineConnectorTool : LineConnectorTool
    {
        public MyLineConnectorTool(DiagramController controller)
            : base(controller)
        {
            HeadDecorator.DecoratorShape = DecoratorShape.Filled45Arrow;
        }

        public override Tool ProcessMouseDown(MouseEventArgs evtArgs)
        {

            PointF mouseLocation = Controller.ConvertToModelCoordinates(evtArgs.Location);
            var nd = Controller.GetNodeAtPoint(mouseLocation);

            if(nd != null)
            {
                var cp = HandlesHitTesting.GetConnectionPointAtPoint(nd, mouseLocation);
                if(cp == null) return null;
                if(cp.ConnectionPointType == ConnectionPointType.Outgoing)
                    return base.ProcessMouseDown(evtArgs);
            }
            return null;
        }

        public override Tool ProcessMouseUp(MouseEventArgs evtArgs)
        {
            PointF mouseLocation = Controller.ConvertToModelCoordinates(evtArgs.Location);
            var nd = Controller.GetNodeAtPoint(mouseLocation);

            if(nd != null)
            {
                var cp = HandlesHitTesting.GetConnectionPointAtPoint(nd, mouseLocation);
                if(cp == null) return null;
                if(cp.ConnectionPointType == ConnectionPointType.Incoming)
                    return base.ProcessMouseUp(evtArgs);
            }
            return null;
        }
    }

This works for an invalid initial point but an invalid final point leaves the connection line drawn even though it seems clear that no connector has been placed.  As this code is mostly guesswork I am surprised that it works as well as it does :)
What is the official method to do this?

Thanks,
Andy

Naganathan Ganesh Babu [Syncfusion]
Replied On May 12, 2015 03:15 AM

Hi Andrew,

Thanks for using Syncfusion product.

We are glad to inform you that we have modified your code snippet to achieve your requirement. You were using Connector’s “ConnectionType” to identifying connection type is incoming/outgoing while connecting the nodes. We suggest you to use Node.CentralPort’s “ConnectionType” instead of Connector.ConnectionType while connecting the Nodes using connector tool to achieve your requirement. Please refer the below modified code snippet and sample for your references.

Here is the code snippet:

[C#]

public class MyLineConnectorTool : LineConnectorTool

{

public MyLineConnectorTool(DiagramController controller)

: base(controller)

{

HeadDecorator.DecoratorShape = DecoratorShape.Filled45Arrow;

Name = "LineConnectorTool";

}


public override Tool ProcessMouseDown(MouseEventArgs evtArgs)

{

PointF mouseLocation = Controller.ConvertToModelCoordinates(evtArgs.Location);

var nd = Controller.GetNodeAtPoint(mouseLocation);

if (nd != null && (nd.CentralPort.ConnectionPointType == ConnectionPointType.Outgoing

|| nd.CentralPort.ConnectionPointType == ConnectionPointType.IncomingOutgoing))

{

return base.ProcessMouseDown(evtArgs);

}

else

return null;

}


public override Tool ProcessMouseUp(MouseEventArgs evtArgs)

{

PointF mouseLocation = Controller.ConvertToModelCoordinates(evtArgs.Location);

var nd = Controller.GetNodeAtPoint(mouseLocation);

if (nd != null && (nd.CentralPort.ConnectionPointType == ConnectionPointType.Incoming

|| nd.CentralPort.ConnectionPointType == ConnectionPointType.IncomingOutgoing))

{

return base.ProcessMouseUp(evtArgs);

}

else

{

this.Controller.Model.BeginUpdate();

this.InAction = false;

this.Controller.Model.EndUpdate();

return null;

}

}
}


Here is the Sample:

Sample

Please let us know if any concerns.

Regards,

Naganathan K G


Andrew Le Couteur Bisson
Replied On May 12, 2015 05:22 AM

Thanks for your very quick and complete response. 
I am actually using custom symbols with distinct inputs and outputs so the centre port is disabled.
The important detail that I was unaware of is the else clause in ProcessMouseUp()
Adding these three lines to my code fixed it perfectly.

Thanks again,
Andy

Naganathan Ganesh Babu [Syncfusion]
Replied On May 13, 2015 01:01 AM

Hi Andrew,

Thanks for your update.

Please let us know if you need further assistance.

Regards,

Naganathan K G


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;