Prevent draw new connection

In my code a user can make a new connection eigther by draw directly from the port or by drag/drop a connection from the pallette.

But how do I prevent the user from 

Draw a connection from a port?

Connect a connection to a port?


In both cases I want to check for excisting connections in the code and in some cases cancel a new connection or prevent connect to a port


5 Replies

GG Gowtham Gunashekar Syncfusion Team July 29, 2021 04:30 PM UTC

Hi Torben, 
 
Please refer to the following sample for how to restrict the connector connection using port constraints and node constraints. We can restrict the addition of connector by including and exclude the port’s draw constraints from the Default port constraints and add the connection restriction by include and exclude the InConnect , OutConnect constraints of node and port. If we exclude the InConnect , OutConnect constraints from node and port Constraints means we cannot connect a connector to the respective node and port. In the sample, we have added four buttons, one for disable the port draw and second one is for disable the port draw, third one for enable the connection on nodes and port and fourth one is for disable the connection on node and ports.  
 
Code snippet: 
 
    public void RemovePortConnect() 
    { 
        var node = Diagram.GetNode("node1"); 
// To disable the port draw functionality 
        node.Ports[0].Constraints = PortConstraints.Default; 
    } 
    public void AddPortConnect() 
    { 
        var node = Diagram.GetNode("node1"); 
// To enable the port draw functionality 
        node.Ports[0].Constraints = PortConstraints.Default | PortConstraints.Draw; 
    } 
    public void DisablePortConnect() 
    { 
        var node = Diagram.GetNode("node1"); 
// To disable the connector connection functionality from node 
        node.Constraints = NodeConstraints.Default & ~(NodeConstraints.InConnect | NodeConstraints.OutConnect); 
 
// To disable the connector connection functionality from port 
        node.Ports[0].Constraints = PortConstraints.Default &~(PortConstraints.InConnect|PortConstraints.OutConnect); 
    } 
    public void EnablePortConnect() 
    { 
        var node = Diagram.GetNode("node1"); 
// To enable the connector connection functionality from node 
        node.Constraints = NodeConstraints.Default; 
// To enable the connector connection functionality from port 
        node.Ports[0].Constraints = PortConstraints.Default ; 
    } 
 
 
Regards, 
Gowtham  



TL Torben Laursen August 30, 2021 07:39 AM UTC

Hi, 

Sorry for my slow response time.

It seems like a lot of code for a simple feature. 

Does the control not offer a simple property like "MaximumConnectionCount" that I can simply set to 1.

Then all this code could be reduced to a few lines?



GG Gowtham Gunashekar Syncfusion Team August 31, 2021 12:13 PM UTC

 
Hi Torben, 
 
On the further analysis of the shared details, we understood that you expects a property like property "MaximumConnectionCount"  that add the restriction of number of connection. We don’t have any support for that property in connector. We have constraints ( InConnect  and OutConnect) in both node and port that restricts the connector in-connection and out-connection and by include the draw constraints to the port constraints we can able the port draw functionality and by setting the port constraints as “Default” we can restrict the port draw functionality. 
 
 

Code snippet:
  
  
    public void RemovePortConnect()  
    {  
        var node = Diagram.GetNode("node1");  
// To disable the port draw functionality  
        node.Ports[0].Constraints = PortConstraints.Default;  
    }  
    public void AddPortConnect()  
    {  
        var node = Diagram.GetNode("node1");  
// To enable the port draw functionality  
        node.Ports[0].Constraints = PortConstraints.Default | PortConstraints.Draw;  
    }  
    public void DisablePortConnect()  
    {  
        var node = Diagram.GetNode("node1");  
// To disable the connector connection functionality from node  
        node.Constraints = NodeConstraints.Default & ~(NodeConstraints.InConnect | NodeConstraints.OutConnect);  
  
// To disable the connector connection functionality from port  
        node.Ports[0].Constraints = PortConstraints.Default &~(PortConstraints.InConnect|PortConstraints.OutConnect);  
    }  
    public void EnablePortConnect()  
    {  
        var node = Diagram.GetNode("node1");  
// To enable the connector connection functionality from node  
        node.Constraints = NodeConstraints.Default;  
// To enable the connector connection functionality from port  
        node.Ports[0].Constraints = PortConstraints.Default ;  
    }  
  
Regards,  
Gowtham   
 
 



TL Torben Laursen August 31, 2021 02:07 PM UTC

Thanks, I will try your example



GG Gowtham Gunashekar Syncfusion Team September 1, 2021 12:20 PM UTC

Hi Torben, 
 
Thanks for your update. Please let us know whether you need any further assistance on this. 
 
 
Regards  
Gowtham 


Loader.
Up arrow icon