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



Posts: 194
Location: Sevastopol
Joined: Dec 1st, 2009
Re: Dragging links
Reply #15 - Jan 5th, 2010 at 7:49am
Print Post  
Hello again Smiley. I need to use the property MergeThreshold and in my init function I implement:
Code
Select All
m_Diagram.MergeThreshold = 3;
 


But the behavior is so strange as for me. I send you the avi-file on the email: support@mindfusion.eu. Can you advise me something about it?

P.S.: I tried to set values from 1 to 3 for the MergeThreshold and had the same effect.
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Dragging links
Reply #16 - Jan 5th, 2010 at 10:13am
Print Post  
That happens because the standard link modification code is designed for moving a single control point, and the merge function only merges the segments incident with that point. Since the custom behavior reuses that code, only the points that coincide with the first point of the dragged segment are removed. So unfortunately you can't reuse the base code for merging, but will have to check all triples of consecutive points in the link and remove ones that coincide or lie on the same straight line. Here is an example:

Code
Select All
// in MyBehavior.cs
protected override void OnMouseUp(Point mousePosition, MouseButton mouseButton)
{
	DiagramLink link = Diagram.Interaction != null && Diagram.Interaction.Action == Action.Modify ?
		Diagram.Interaction.CurrentItem as DiagramLink : null;

	if (Diagram.Interaction != null && dragSegment == DragLinkSegment.Horizontal)
		mousePosition.X = startPoint.X;

	if (Diagram.Interaction != null && dragSegment == DragLinkSegment.Vertical)
		mousePosition.Y = startPoint.Y;

	base.OnMouseUp(mousePosition, mouseButton);

	if (link != null)
		CleanupLink(link, 2);
}

private void CleanupLink(DiagramLink link, double threshold)
{
	var points = link.ControlPoints;
	for (int i = 0; i < points.Count - 2; ++i)
	{
		if (PointsColinear(points, i, threshold))
		{
			points.RemoveAt(i + 1);
			i--;
		}
	}
	link.UpdateFromPoints(false, true);
}

private bool PointsColinear(PointCollection points, int index, double threshold)
{
	Point p0 = points[index + 0];
	Point p1 = points[index + 1];
	Point p2 = points[index + 2];

	if (Math.Abs(p0.X - p1.X) <= threshold &&
Math.Abs(p1.X - p2.X) <= threshold)
		return true;

	if (Math.Abs(p0.Y - p1.Y) <= threshold &&
Math.Abs(p1.Y - p2.Y) <= threshold)
		return true;

	return false;
} 



Now you should keep AllowSplitLinks disabled.

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 #17 - Jan 5th, 2010 at 10:30am
Print Post  
Thank you. It works, but some new features now are present Smiley. When I drag link it adds new control points and segment (horizontal segment). After that I drag it on it's old place (return to previous state). And in this case after that I can't repeat these operations while I am not drag any vertical segment or not click left button outside the links and nodes...
  
Back to top
 
IP Logged
 
Hunter
Full Member
***
Offline



Posts: 194
Location: Sevastopol
Joined: Dec 1st, 2009
Re: Dragging links
Reply #18 - Jan 5th, 2010 at 11:33am
Print Post  
In another words the the condition:
Code
Select All
		    m_DragSegment = points[segment].Y == points[segment + 1].Y ?
			  DragLinkSegment.Horizontal : DragLinkSegment.Vertical;
 


in function StartDraw starts work incorrect after merging. The new points add as need but Y-coordinates are different approximately on 1 point and this condition detects vertical segment instead horizontal...
  
Back to top
 
IP Logged
 
Hunter
Full Member
***
Offline



Posts: 194
Location: Sevastopol
Joined: Dec 1st, 2009
Re: Dragging links
Reply #19 - Jan 5th, 2010 at 12:16pm
Print Post  
May be I am mistake but if I change this condition on:
Code
Select All
		    m_DragSegment = Math.Abs(points[segment].Y - points[segment + 1].Y) < 1.5 ?
			  DragLinkSegment.Horizontal : DragLinkSegment.Vertical;
 


where 1.5 is a threshold in CleanupLink function all works...
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Dragging links
Reply #20 - Jan 5th, 2010 at 1:17pm
Print Post  
I couldn't reproduce the new features, but if the threshold solution works for you, you are certainly not mistaken 8)

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



Posts: 194
Location: Sevastopol
Joined: Dec 1st, 2009
Re: Dragging links
Reply #21 - Jan 5th, 2010 at 1:39pm
Print Post  
If you interested I can produce the new video film for you  Grin
  
Back to top
 
IP Logged
 
Hunter
Full Member
***
Offline



Posts: 194
Location: Sevastopol
Joined: Dec 1st, 2009
Re: Dragging links
Reply #22 - Jan 5th, 2010 at 1:56pm
Print Post  
I found the new feature which I can't resolve yet. Can you give some advises? I sent you the new video Smiley
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Dragging links
Reply #23 - Jan 5th, 2010 at 2:02pm
Print Post  
I suppose you should add some guard condition never to leave the link with less than three points - cascading links always require at least two segments.

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



Posts: 194
Location: Sevastopol
Joined: Dec 1st, 2009
Re: Dragging links
Reply #24 - Jan 5th, 2010 at 2:24pm
Print Post  
I will check it Smiley. Thank you. May be this is the solution of the problem.
  
Back to top
 
IP Logged
 
Hunter
Full Member
***
Offline



Posts: 194
Location: Sevastopol
Joined: Dec 1st, 2009
Re: Dragging links
Reply #25 - Jan 5th, 2010 at 4:01pm
Print Post  
I saw an interesting effect. When I create a cascading link between 2 nodes which have the same Y-coordinates of anchor points (link like as linear) and after that I start to move any of the nodes by keyboard, the link "automatically" divides in the middle and adds 2 new control points. And the appearance of arrowhead as need: from left to right in my case. But when I try to drag the node by mouse only 1 control point added to the link  and it's Y- coordinate isn't in the middle of the link. It's Y-coordinate is the same as Y-coordinate as Y-coordinate of the last control point. I tested the left to right link. And I want make the behavior the same as keyboard moving. What is the difference might be?
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Dragging links
Reply #26 - Jan 5th, 2010 at 4:23pm
Print Post  
What are you doing to move nodes with the keyboard? Perhaps the link routing function runs in that case and places the points as you described.
  
Back to top
 
IP Logged
 
Hunter
Full Member
***
Offline



Posts: 194
Location: Sevastopol
Joined: Dec 1st, 2009
Re: Dragging links
Reply #27 - Jan 6th, 2010 at 5:59am
Print Post  
Thanks! Really, in the function which implements moving I call for each link of the node Route()
  
Back to top
 
IP Logged
 
Hunter
Full Member
***
Offline



Posts: 194
Location: Sevastopol
Joined: Dec 1st, 2009
Re: Dragging links
Reply #28 - Jan 6th, 2010 at 10:39am
Print Post  
Is there any way to determine when the mouse cursor is over the link and link can be dragged to change it's cursor? The solution of the problem might be the following:
1) Derive class from DiagramLink
2) Override the function OnIsMouseDirectlyOverChanged.
But I can't understand how to change DiagramLink objects on derived class objects.
« Last Edit: Jan 6th, 2010 at 12:15pm by Hunter »  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Dragging links
Reply #29 - Jan 6th, 2010 at 2:07pm
Print Post  
You could override the behavior's SetMouseCursor method. Use the same hit-testing code from StartDraw to determine if a link will be modified.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1 [2] 3 
Send TopicPrint