Page Index Toggle Pages: 1 [2]  Send TopicPrint
Hot Topic (More than 10 Replies) Link creation - toggling anchor point (Read 7568 times)
marie
Full Member
***
Offline



Posts: 147
Joined: Nov 11th, 2008
Re: Link creation - toggling anchor point
Reply #15 - Mar 9th, 2009 at 2:40pm
Print Post  
Hi Stoyan,

1. It seems weird that Anchoring.Keep changes the anchor points, but now at least I know it Wink.
3. & 4. That was the problem. I got the jumping problem almost solved using LinkValidationEventArgs directly.

I also had to use e.ChangingOrigin & e.ChangingDestination to set linkX.

A) You suggested me that I don't use e.ChangingOrigin before... Is this advice still valid? If so, what can I use instead?

B) There is still a problem. When I create a link from the left anchor point, everything is fine. There is no jump possible to the right one as it should.
However, when I create a link from the right anchor point, it immediately jumps to the left one. Of course, after that my code prevents it from going back to the right anchorPt. Why can't my code catch the first jump and how can I fix this? There is no problem in regards to destination points.

Thanks a lot!
Marie

N.B. This is the code I've got so far:
Code
Select All
void diagram_ValidateAnchorPoint(object sender, LinkValidationEventArgs e)
{
    try
    {
        TableNode node = e.Node as TableNode;
        AnchorPoint originAnchorPt = node.Rows[e.TableRow].AnchorPattern.Points[e.AnchorIndex];

        float linkX;
        if (e.ChangingOrigin)
            linkX = e.Link.ControlPoints[0].X;
        else if (e.ChangingDestination)
        {
            PointCollection ptColl = e.Link.ControlPoints;
            linkX = ptColl[ptColl.Count - 1].X;
        }
        else
            return;
        float nodeMiddleHorizontalPt = node.Bounds.Width / 2 + node.Bounds.X;

        if ((int)originAnchorPt.Tag == ANCHOR_LEFT && linkX > nodeMiddleHorizontalPt)
            e.Cancel = true;
        else if ((int)originAnchorPt.Tag == ANCHOR_RIGHT && linkX < nodeMiddleHorizontalPt)
            e.Cancel = true;
    }
    catch (System.Exception) { }
} 

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


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Link creation - toggling anchor point
Reply #16 - Mar 9th, 2009 at 8:38pm
Print Post  
Hi Marie,

I think I got it now 8) Try setting linkX = e.MousePosition.X instead of that if-else statement. This corresponds to the position of the control point currently being dragged. The ChangingOrigin and ChangingDestination properties are used only for the Modified event.

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



Posts: 147
Joined: Nov 11th, 2008
Re: Link creation - toggling anchor point
Reply #17 - Mar 9th, 2009 at 8:59pm
Print Post  
Hi Stoyan,

This doesn't work. I'm guessing it is because e.MousePosition always represents the end of the arrow being drawn and that it doesn't have anything to do with the start anchor point position.

A) Using ChangingOrigin/destination seems to work...
B) Anything else I should try for B)? Could it be somehow caused by A)?

Thanks,
Marie
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Link creation - toggling anchor point
Reply #18 - Mar 10th, 2009 at 10:53am
Print Post  
Hi Marie,

Indeed they work, even if not intentional. However the anchor point validation events could be raised before the link points are set, e.g. when starting to draw a new link. In that case you can use the MousePosition argument. MousePosition might not be set in other situations, e.g. when reassigning anchor points from a layout function. We'll add some new argument to let you know the coordinates of the point that should be aligned to the anchor point, until then this should work:

Code
Select All
float linkX;
if (e.MousePosition == PointF.Empty)
{
	if (e.ChangingOrigin)
		linkX = e.Link.ControlPoints[0].X;
	else if (e.ChangingDestination)
	{
		PointCollection ptColl = e.Link.ControlPoints;
		linkX = ptColl[ptColl.Count - 1].X;
	}
	else
		return;
}
else
	linkX = e.MousePosition.X;
 



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



Posts: 147
Joined: Nov 11th, 2008
Re: Link creation - toggling anchor point
Reply #19 - Mar 10th, 2009 at 1:40pm
Print Post  
Hi Stoyan,

When I use your code, the jumping problem is not solved (it's the same than when there is no validateAnchorPoint code at all), probably because I'm using the mouse position most of the times. This corresponds to the link's end when I should be using the link's beginning (just talking about the link's origin that jumps from an anchor point to another according to the mouse's position).

If you think that those new arguments will solve my last problem (no more jumping except for the right anchor point that jumps to the left one for some reason right when I start drawing a link), then I think I'll wait Wink.

Thanks a lot!
Marie
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Link creation - toggling anchor point
Reply #20 - Mar 10th, 2009 at 3:12pm
Print Post  
Hi Marie,

Both this and the older method worked in my test, and since you couldn't send me a project that reproduces it, I can't guess what else might go wrong.

You could try that the other way around, first compare e.Link.ControlPoints[0] with PointF.Empty, use ControlPoints if not empty, otherwise use MousePosition.

The new argument will help if the problem comes from determining which point is being aligned to the anchor position. It won't help if something's wrong with the originAnchorPt.Tag values. Can't you use the Column or X property there to determine if it's left or right?

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



Posts: 147
Joined: Nov 11th, 2008
Re: Link creation - toggling anchor point
Reply #21 - Mar 10th, 2009 at 3:24pm
Print Post  
Hi Stoyan!

That was it Cheesy! Reversing the tests worked.

I now have
Code
Select All
float linkX;
PointCollection ptColl = e.Link.ControlPoints;
if (e.ChangingOrigin)
{
    PointF pt = ptColl[0];
    if (pt == PointF.Empty)
        linkX = e.MousePosition.X;
    else
        linkX = pt.X;
}
else if (e.ChangingDestination)
{
    PointF pt = ptColl[ptColl.Count - 1];
    if (pt == PointF.Empty)
        linkX = e.MousePosition.X;
    else
        linkX = pt.X;
}
else
    return; 



Thanks a lot for your help & patience
Marie
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1 [2] 
Send TopicPrint