Page Index Toggle Pages: [1] 2 3  Send TopicPrint
Very Hot Topic (More than 25 Replies) Dragging links (Read 17870 times)
Hunter
Full Member
***
Offline



Posts: 194
Location: Sevastopol
Joined: Dec 1st, 2009
Dragging links
Dec 28th, 2009 at 1:28pm
Print Post  
Can I drag the link by mouse when cursor is in the middle of control points? For example I want to add some control points when user presses the left button and I want to allow him drag the link between these control points. I use this code
Code
Select All
	  /// <summary>
	  /// Occurs when mouse pointer is over the link and left button is down
	  /// </summary>
	  /// <param name="sender">Sender object</param>
	  /// <param name="e">Provides arguments for this event</param>
	  private void OnLinkMouseLeftButtonDown(object sender, MouseEventArgs e)
	  {
		DiagramLink link = sender as DiagramLink;
		Point mousePos = e.MouseDevice.GetPosition(m_Diagram);
		//foreach(Point ctrlPnt in link.ControlPoints)
		for (int i = 0; i < link.ControlPoints.Count; ++i)
		{
		    Point ctrlPnt = link.ControlPoints[i];
		    if (Math.Abs(mousePos.X - ctrlPnt.X) < 0.5)
		    {
			  Point nextCtrlPnt = link.ControlPoints[i + 1];
			  Point newPnt = new Point();
			  newPnt.X = ctrlPnt.X;
			  Point nextNewPnt = new Point();
			  nextNewPnt.X = ctrlPnt.X;
			  if (ctrlPnt.Y < nextCtrlPnt.Y)
			  {
				newPnt.Y = ctrlPnt.Y + 15;
				nextNewPnt.Y = nextCtrlPnt.Y - 15;
				link.ControlPoints.Insert(i + 1, newPnt);
				link.ControlPoints.Insert(i + 2, nextNewPnt);
			  }
			  else
			  {
				newPnt.Y = ctrlPnt.Y - 15;
				nextNewPnt.Y = nextCtrlPnt.Y + 15;
				link.ControlPoints.Insert(i + 2, newPnt);
				link.ControlPoints.Insert(i + 1, nextNewPnt);
			  }
			  link.UpdateFromPoints(false, false);
			  break;
		    }
		    else if (Math.Abs(mousePos.Y - ctrlPnt.Y) < 0.5)
		    {
			  //To do: Add horisontal segment
		    }
		}
	  } 


But now link drags only when cursor is over one of control points.
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Dragging links
Reply #1 - Dec 28th, 2009 at 1:53pm
Print Post  
There's a built-in feature that does something similar. Check if diagram.AllowSplitLinks = true works for you.

Stoyan
  
Back to top
 
IP Logged
 
Hunter
Full Member
***
Offline



Posts: 194
Location: Sevastopol
Joined: Dec 1st, 2009
Re: Dragging links
Reply #2 - Dec 28th, 2009 at 2:08pm
Print Post  
Yes. It works similiar as I need. Thank you very much
  
Back to top
 
IP Logged
 
Hunter
Full Member
***
Offline



Posts: 194
Location: Sevastopol
Joined: Dec 1st, 2009
Re: Dragging links
Reply #3 - Dec 29th, 2009 at 8:54am
Print Post  
I have a question. After I convince my technical director to buy your library could I reckon that you will add the behavior of dragging links as in the Matlab->Simulink?
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Dragging links
Reply #4 - Dec 29th, 2009 at 11:15am
Print Post  
In what manner are links dragged in Matlab->Simulink? It is possible to customize much of the drawing behavior using a custom BehaviorBase -derived class and possibly a derived DiagramLink.

Stoyan
  
Back to top
 
IP Logged
 
Hunter
Full Member
***
Offline



Posts: 194
Location: Sevastopol
Joined: Dec 1st, 2009
Re: Dragging links
Reply #5 - Dec 30th, 2009 at 10:50am
Print Post  
Are there any examples, exclude example in help file, how to implement  public override CursorHint SetMouseCursor(Point point, out bool startInteraction)?
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Dragging links
Reply #6 - Dec 30th, 2009 at 1:52pm
Print Post  
This method should do some hit-testing and return which of the diagram's Cursor properties to set as the current cursor. What exactly are you trying to achieve? You might also check the Diagram.OverrideCursor property - it will display your custom cursor until you set it back to null.

Stoyan
  
Back to top
 
IP Logged
 
Hunter
Full Member
***
Offline



Posts: 194
Location: Sevastopol
Joined: Dec 1st, 2009
Re: Dragging links
Reply #7 - Dec 30th, 2009 at 3:48pm
Print Post  
I want to override behavior of dragging links. When I drag a link and mouse is over the link (not over cotrol point) I want that if right-side control can't move then add the control point left and move link. The same according to left-side control point. If it can't be moved the control point must be add left and link link must be moved. To describe this behavior by words is too hard for me. Easier to demonstrate it on Virtual machine example with another software or on video clip
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Dragging links
Reply #8 - Dec 31st, 2009 at 10:45am
Print Post  
Do you need something similar to the AllowSplitLinks behavior, but want to specify yourself where the new control point should be inserted? In such case you can override StartDraw to return new InteractionState(link, segmentToSplit, Action.Split). This will insert the new point so that it divides the specified segment into two new segments.

Otherwise, please send us a link or a video file that shows your requirement to support@mindfusion.eu.

Stoyan
  
Back to top
 
IP Logged
 
Hunter
Full Member
***
Offline



Posts: 194
Location: Sevastopol
Joined: Dec 1st, 2009
Re: Dragging links
Reply #9 - Jan 4th, 2010 at 8:12am
Print Post  
Yes, I need something similiar to the AllowSplitLinks behavior. I try to do it without your assistance but I need to know how to override StartDraw for change only links processing behavior and node processing behavior stay as is. Can you show me an example of StartDraw function for any standard behavior? It will be great to see StartDraw for Behavior.DrawLinks
  
Back to top
 
IP Logged
 
Hunter
Full Member
***
Offline



Posts: 194
Location: Sevastopol
Joined: Dec 1st, 2009
Re: Dragging links
Reply #10 - Jan 4th, 2010 at 9:34am
Print Post  
I sent you the e-mail with avi-files and some comments in the letter
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Dragging links
Reply #11 - Jan 4th, 2010 at 12:45pm
Print Post  
Try diagram.CustomBehavior set to an instance of this class:
http://mindfusion.eu/_samples/MyBehavior2.cs

It might be better to implement the horizontal/vertical segment moving code in UpdateModify override of DiagramLink instead of simulating the mouse moving only vertically/horizontally, but it's easier to inherit from the Behavior class than from diagrmaLink.

This code implements split only for the horizontal segments case and does not check on which side of nodes the segment lies (it will work only for left to right links). You will need to add some checks in the first two if blocks to add new points at the correct offset.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Hunter
Full Member
***
Offline



Posts: 194
Location: Sevastopol
Joined: Dec 1st, 2009
Re: Dragging links
Reply #12 - Jan 4th, 2010 at 1:48pm
Print Post  
Thank you very much! This code is very helpful for me and I try to modify it for implement all features which I need. Now I have one question: after I change
Code
Select All
m_Diagram.Behavior = Behavior.DrawLinks;
 


to
Code
Select All
m_Diagram.Behavior = Behavior.Custom;
m_Diagram.CustomBehavior = new LinkBehavior(m_Diagram);
 


when I try to select the group of nodes and links by mouse it draws me the rounded rectangle. Where I can fix this?
Is it correct to change
Code
Select All
return base.StartDraw(point);
 


on
Code
Select All
            var node = Diagram.GetNodeAt(point);
            if (node == null)
                return new InteractionState(Diagram.Selection, 0, Action.Create);
            return base.StartDraw(point);
 

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


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Dragging links
Reply #13 - Jan 4th, 2010 at 2:11pm
Print Post  
If you were using the standard DrawLinks behavior, derive the custom class from DrawLinksBehavior instead of LinkShapesBehavior to be as close as possible to the previous results. Otherwise - yes, you should be able to start drawing the selection rectangle like that...

Stoyan
  
Back to top
 
IP Logged
 
Hunter
Full Member
***
Offline



Posts: 194
Location: Sevastopol
Joined: Dec 1st, 2009
Re: Dragging links
Reply #14 - Jan 4th, 2010 at 2:23pm
Print Post  
Thanks a lot!
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: [1] 2 3 
Send TopicPrint