Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Dont Allow Link Creation (Read 1760 times)
Nedor
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 16
Joined: Aug 6th, 2010
Dont Allow Link Creation
Sep 17th, 2010 at 8:54am
Print Post  
In my program, I want to allow LinkCreation for some special Types of node
for Example:
linktype1 can connect nodes of nodetyoe1 with nodetype2.
linktype2 can connect only nodetype2 to nodetype2.

I want to disable the linkdrawing if the mouse is on a not supported type. If the drawing stops on a not supported type, i dont want to add this link.

Currently i do this by handling the Link Events (LinkCreated, LinkCreating) but now i have some problems:

If i disable the AllowUnconnectedLinks property. The LinkCreating event is only called if the mouse draws over a node. If the creation of the link starts close to the border of the node. The LinkInitialized event ist called but not the LinkCreating event for the node. In this case i can't cancel the running Paint-Link-Action.
So is enabled AllowUnconnectedLinks.
Now, if i start drawing not on a node. I make e.CancelDrag(). In this case, all new incoming DiagramLinkCreating events won't have the correct e.MousePosition property (The Mouse Position is always set to the position of the event where i called CancelDrag()).
The second problem in this case is, i see the Draw event for a short time.
Maybe there are some better ways to implement the wanted behavior.
I have this goal:
1. The Diagram is in a CreationMode where it knows which LinkType should be created next.
2. If the user starts drawing in an empty area nothing should happen
3. If he starts drawing on a non supported nodetype nothing should happen
4. If he starts drawing on a supported NodeType the drawing should happen.
5. If he stops drawing (release the left mouse button) on an empty area. Nothing should happen (Drawing should be canceled).
6. If he stops drawing on a not supported Node. Nothing should be happen.
7. If he stops drawing on a supported node, a function is called which creates the link
Currently i have no clue how to solve my problems:
1. If i allow only connected links, i cant cancel the creation in LinkInitialized
2. If i allow unconnected links, i cant cancel the creation on empty areas, in this cases the mouse aren't set correctly on the next LinkCreating event + i see the drawing event for a short amount of time.


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


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Dont Allow Link Creation
Reply #1 - Sep 17th, 2010 at 11:13am
Print Post  
You can implement the "nothing should happen" cases by returning null from the StartDraw override of a custom behavior class. Our developer will check what happens with the events next week.

Stoyan
  
Back to top
 
IP Logged
 
Nedor
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 16
Joined: Aug 6th, 2010
Re: Dont Allow Link Creation
Reply #2 - Sep 17th, 2010 at 11:22am
Print Post  
Thanks. With an own "LinkAddBehavior", it works well.
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Dont Allow Link Creation
Reply #3 - Sep 27th, 2010 at 5:45am
Print Post  
Were you doing something like the following in the AllowUnconnectedLinks case? This prints correct coordinates in our test project ...

Code
Select All
private void diagram_LinkCreating(object sender, MindFusion.Diagramming.LinkValidationEventArgs e)
{
	if (e.Link.Origin == null)
		e.CancelDrag();
	Debug.WriteLine(e.MousePosition);
} 



Indeed the event is not raised with AllowUnconnectedLinks disabled. This made sense in older versions when CancelDrag wasn't available, but only the Cancel property. It seems it would be useful to raise it now, when it's possible to immediately cancel the drag operation.
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint