Page Index Toggle Pages: 1 Send TopicPrint
Hot Topic (More than 10 Replies) Shape connectivity restriction for specific shapes (Read 7064 times)
ashar11
Junior Member
**
Offline


I Love MindFusion!

Posts: 56
Joined: Jun 29th, 2017
Shape connectivity restriction for specific shapes
Jun 30th, 2017 at 11:17am
Print Post  
Hello,
          I am working on winforms and using a flowcharter from the samples in c#, I want to restrict specific shape connectivity like in the image url given below i want to restrict the connectivity of shape A and shape C how can i do that.

https://imagebin.ca/v/3RkcP2F80Wof

The code from which i am getting images right now is :

   // nodeListView1
            //
            this.nodeListView1.Location = new System.Drawing.Point(-3, 210);
            this.nodeListView1.Name = "nodeListView1";
            this.nodeListView1.Size = new System.Drawing.Size(200, 343);
            this.nodeListView1.TabIndex = 0;
            this.nodeListView1.AddNode(new ShapeNode
            {
                Transparent = true,
                Image = Image.FromFile(@"C:/Imgs/bitmap1.bmp")
            }, "A");
            this.nodeListView1.AddNode(new ShapeNode
            {
                Transparent = true,
                Image = Image.FromFile(@"C:/Imgs/bitmap2.bmp")
            }, "B");
            this.nodeListView1.AddNode(new ShapeNode
            {
                Transparent = true,
                Image = Image.FromFile(@"C:/Imgs/bitmap3.bmp")
            }, "C");

Thanks
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3154
Joined: Oct 19th, 2005
Re: Shape connectivity restriction for specific shapes
Reply #1 - Jun 30th, 2017 at 12:23pm
Print Post  
Hi,

If you mean some nodes should not accepts links, set their AllowIncomingLinks and / or AllowOutgoingLinks properties.

Regards,
Slavcho
  
Back to top
 
IP Logged
 
ashar11
Junior Member
**
Offline


I Love MindFusion!

Posts: 56
Joined: Jun 29th, 2017
Re: Shape connectivity restriction for specific shapes
Reply #2 - Jun 30th, 2017 at 12:50pm
Print Post  
thanks slavcho ,it is similar to what i need but actually what i want is, like shape C can be connected to shape A but not with shape B,so how can i apply condition with in the given code i post before.
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3154
Joined: Oct 19th, 2005
Re: Shape connectivity restriction for specific shapes
Reply #3 - Jun 30th, 2017 at 1:19pm
Print Post  
Hi,

You will need to handle the LinkCreating validation event and set e.Cancel to true if the pair of nodes is not allowed by your criteria. For example this will not let users draw if source node is on the right side of destination node.

Code
Select All
void diagram_LinkCreating(object sender, LinkValidationEventArgs e)
{
	if (e.Origin != null && e.Destination != null)
		if (e.Origin.Bounds.X > e.Destination.Bounds.X)
			e.Cancel = true;
} 



Regards,
Slavcho
  
Back to top
 
IP Logged
 
ashar11
Junior Member
**
Offline


I Love MindFusion!

Posts: 56
Joined: Jun 29th, 2017
Re: Shape connectivity restriction for specific shapes
Reply #4 - Jul 3rd, 2017 at 8:52am
Print Post  
With this code below which is in Mainform.Designer.cs where to apply the changes ?i even can't initialize the function its giving me errors

   // nodeListView1
            //
            this.nodeListView1.Location = new System.Drawing.Point(-3, 210);
            this.nodeListView1.Name = "nodeListView1";
            this.nodeListView1.Size = new System.Drawing.Size(200, 343);
            this.nodeListView1.TabIndex = 0;
            this.nodeListView1.AddNode(new ShapeNode
            {
                Transparent = true,
                Image = Image.FromFile(@"C:/Imgs/bitmap1.bmp")
            }, "A");
            this.nodeListView1.AddNode(new ShapeNode
            {
                Transparent = true,
                Image = Image.FromFile(@"C:/Imgs/bitmap2.bmp")
            }, "B");
            this.nodeListView1.AddNode(new ShapeNode
            {
                Transparent = true,
                Image = Image.FromFile(@"C:/Imgs/bitmap3.bmp")
            }, "C");

I am not that expert so can you define it more please,I dont have the indexing of nodes here, just the label A,B,C so how to differentiate between nodes if i want to apply condition for restricting connection among nodes.Thanks
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3154
Joined: Oct 19th, 2005
Re: Shape connectivity restriction for specific shapes
Reply #5 - Jul 3rd, 2017 at 9:47am
Print Post  
Select the Diagram instance in form designer and in property window's events tab double click on LinkCreating event to add the event handler. Alternatively add event handler from code -

Code
Select All
diagram.LinkCreating += diagram_LinkCreating; 



You might want to set the nodes' Id or Tag property to your "A", "B" etc values and do checks based on them in the validation code -

Code
Select All
if ("A".Equals(e.Origin.Tag) && "B".Equals(e.Destination.Tag))
... 



If you have a lot of pairs you'll need to check, consider creating a matrix of Boolean values to hold information what pairings are allowed; then LinkCreating could return information from the matrix directly.

Regards,
Slavcho
  
Back to top
 
IP Logged
 
ashar11
Junior Member
**
Offline


I Love MindFusion!

Posts: 56
Joined: Jun 29th, 2017
Re: Shape connectivity restriction for specific shapes
Reply #6 - Jul 3rd, 2017 at 10:24am
Print Post  
Thanks slavcho for detailed description. This is now what i am using but still i am able to connect both nodes...how to stop them from connecting

private void diagram_LinkCreating(object sender, LinkValidationEventArgs e)
{
diagram.LinkCreating += diagram_LinkCreating;
if ("A".Equals(e.Origin.Tag) && "B".Equals(e.Destination.Tag))
{
e.Cancel = true;

}
}
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3154
Joined: Oct 19th, 2005
Re: Shape connectivity restriction for specific shapes
Reply #7 - Jul 3rd, 2017 at 10:31am
Print Post  
Have you set the nodes' Tag property when populating your NodeListView?
  
Back to top
 
IP Logged
 
ashar11
Junior Member
**
Offline


I Love MindFusion!

Posts: 56
Joined: Jun 29th, 2017
Re: Shape connectivity restriction for specific shapes
Reply #8 - Jul 3rd, 2017 at 10:35am
Print Post  
This is how i am getting the images ,you talking about these tags(A,B,C)?

   // nodeListView1
            //
            this.nodeListView1.Location = new System.Drawing.Point(-3, 210);
            this.nodeListView1.Name = "nodeListView1";
            this.nodeListView1.Size = new System.Drawing.Size(200, 343);
            this.nodeListView1.TabIndex = 0;
            this.nodeListView1.AddNode(new ShapeNode
            {
                Transparent = true,
                Image = Image.FromFile(@"C:/Imgs/bitmap1.bmp")
            }, "A");
            this.nodeListView1.AddNode(new ShapeNode
            {
                Transparent = true,
                Image = Image.FromFile(@"C:/Imgs/bitmap2.bmp")
            }, "B");
            this.nodeListView1.AddNode(new ShapeNode
            {
                Transparent = true,
                Image = Image.FromFile(@"C:/Imgs/bitmap3.bmp")
            }, "C");
  
Back to top
 
IP Logged
 
ashar11
Junior Member
**
Offline


I Love MindFusion!

Posts: 56
Joined: Jun 29th, 2017
Re: Shape connectivity restriction for specific shapes
Reply #9 - Jul 3rd, 2017 at 11:21am
Print Post  
Thanks Slavcho you are great, Issue is resolved now Smiley
  
Back to top
 
IP Logged
 
ashar11
Junior Member
**
Offline


I Love MindFusion!

Posts: 56
Joined: Jun 29th, 2017
Re: Shape connectivity restriction for specific shapes
Reply #10 - Jul 3rd, 2017 at 12:48pm
Print Post  
Slavcho one thing more if you can tell me, how to limit links for a specific node within this code, like i want Node A to create only 2 links and accept only 1 link. Thanks

  if ("A".Equals(e.Origin.Tag) )
            {
                e.Cancel = true;

            }
  
Back to top
 
IP Logged
 
ashar11
Junior Member
**
Offline


I Love MindFusion!

Posts: 56
Joined: Jun 29th, 2017
Re: Shape connectivity restriction for specific shapes
Reply #11 - Jul 3rd, 2017 at 12:49pm
Print Post  
This will be second condition for node A
private void diagram_LinkCreating(object sender, LinkValidationEventArgs e)
        {
            //diagram.LinkCreating += diagram_LinkCreating;
            if ("A".Equals(e.Origin.Tag) && "B".Equals(e.Destination.Tag))
            {
                e.Cancel = true;

            }

            if ("A".Equals(e.Origin.Tag))
            {
                e.Cancel = true;

            }
        }
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3154
Joined: Oct 19th, 2005
Re: Shape connectivity restriction for specific shapes
Reply #12 - Jul 3rd, 2017 at 1:09pm
Print Post  
Check the Count property of nodes' OutgoingLinks and IncomingLinks collections. Keeping in mind that the currently drawn link is not yet there.

Regards,
Slavcho
  
Back to top
 
IP Logged
 
ashar11
Junior Member
**
Offline


I Love MindFusion!

Posts: 56
Joined: Jun 29th, 2017
Re: Shape connectivity restriction for specific shapes
Reply #13 - Jul 4th, 2017 at 5:02am
Print Post  
Its fixed now thanks Slavcho.
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint