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



Posts: 147
Joined: Nov 11th, 2008
Link creation - toggling anchor point
Mar 2nd, 2009 at 9:26pm
Print Post  
Hi,

I have set RoutingOptions.Anchoring=keep.
However, while creating a link, the anchor point used gets changed. By example, if I have tableNode1 (with text1 & text2) & tableNode2 (with text3 & text4):
 
________________________________________________
| |
| _______________________ |
-------| text1 text 2| |
|_______________________| |
|
|
|
_______________________ |
| text 3 text 4|<----------------
|_______________________|
I want to create a link from text1 to text4. I press the mouse down on text1's anchor point and move the mouse in order to release the button when I'm over text4. However, as soon as my mouse pointer crosses the middle of tableNode1 (horizontaly), the starting point of my link jumps to the anchor point located besides text2. So I end up with this instead:
 
_______________________
| text1 text 2|-----------------
|_______________________| |
|
|
|
_______________________ |
| text 3 text 4|<----------------
|_______________________|
How can I prevent that? When the user chooses an anchor point as the start or end of a link, I want to keep it.

Thanks!
Marie
« Last Edit: Mar 10th, 2009 at 3:25pm by 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 #1 - Mar 3rd, 2009 at 6:24am
Print Post  
Hi,

I could not make it work like that at all, so I suppose there's some property that enables this. I've tried drawing links with many combinations of the properties below:

Code
Select All
private void Form1_Load(object sender, System.EventArgs e)
{
	AnchorPattern ptn = new AnchorPattern("x");
	ptn.Points.Add(new AnchorPoint(0, 50, true, true));
	ptn.Points.Add(new AnchorPoint(100, 50, true, true));

	TableNode snBase = diagram.Factory.CreateTableNode(10, 30, 45, 65);
	snBase.RowAnchorPattern = ptn;

	TableNode snRemote = diagram.Factory.CreateTableNode(200, 10, 45, 65);
	snRemote.RowAnchorPattern = ptn;

	diagram.DynamicLinks = true;
	diagram.LinksSnapToBorders = false;
	diagram.ShowAnchors = ShowAnchors.Always;
	diagram.RouteLinks = true;
	diagram.RoutingOptions.TriggerRerouting |= RerouteLinks.WhileCreating;
}
 



Could you check what settings of your diagram enables this?

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



Posts: 147
Joined: Nov 11th, 2008
Re: Link creation - toggling anchor point
Reply #2 - Mar 3rd, 2009 at 6:56pm
Print Post  
Hello!

After disabling all the diagram.SOMETHING initializations from my .designer file and re-enabling them all one after the other, I found out that it's crazy!
When I set diagram.RoutingOptions.Anchoring = Keep, the anchor point changes. When I set it to Anchoring=Reassign, it changes too (this one is as expected). When it is set to Ignore, it is fine (I can do the link as I want it). How strange! It used to be fine, but something changed it. Could you fix this?

Thanks
Marie
  
Back to top
 
IP Logged
 
marie
Full Member
***
Offline



Posts: 147
Joined: Nov 11th, 2008
Re: Link creation - toggling anchor point
Reply #3 - Mar 3rd, 2009 at 8:31pm
Print Post  
Hi again!

I forgot to mention. When Anchoring = Ignore, I can't access to my anchor point anymore because link.DestinationAnchor is -1 instead of pointing towards the good index as in
Code
Select All
AnchorPoint originAnchorPt = ((TableNode)link.Destination).Rows[link.DestinationIndex].AnchorPattern.Points[link.DestinationAnchor]; 

The origin is fine.

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 #4 - Mar 4th, 2009 at 9:46am
Print Post  
Hi Marie,

I think RoutingOptions.Anchoring is not considered at all while the link is being drawn, and the link Origin/Destination Anchor property is not set before LinkCreated.

Currently you could implement what you need by handling the ValidateAnchorPoint event. Return true just for the anchor point that is nearest to ControlPoints[0], and the link should not change its anchor point.

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



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

RoutingOptions.Anchoring is used somehow while the link is being drawn since the anchor jumps occur when I'm making a new link and only if Anchoring=Keep or Anchoring=Reassign. When Anchoring=Ignore, it is fine but then link.DestinationAnchor is incorrect once the link has been created (in LinkCreated event). So there definitely is a problem somewhere. Any ideas why?
If I create the links programatically, it's working as it should.

I tried to use ValidateAnchorPoint, but I don't how I am supposed to use this to fix my problem. I thought something like this would work:
Code
Select All
void diagram_ValidateAnchorPoint(object sender, LinkValidationEventArgs e)
{
    if (e.ChangingOrigin)
        e.Cancel = true;
} 

However, e.ChangingOrigin always seems to be true. I can't create links at all anymore. How can I use this to solve my problem?

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 #6 - Mar 4th, 2009 at 3:07pm
Print Post  
Hi Marie,

Let's suppose the anchor point on the left has index 0, and the one on the right has index 1. If e.AnchorIndex == 0 and e.Link.ControlPoints[0].X is closer to the right side of the table than to the left side, set e.Cancel = true. If e.AnchorIndex == 1 and e.Link.ControlPoints[0].X is closer to the left side of the table, again set e.Cancel = true.

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 #7 - Mar 4th, 2009 at 7:30pm
Print Post  
Hi Stoyan,

Maybe I don't understand what you mean, but it doesn't work ???

I did the following:
Code
Select All
void diagram_ValidateAnchorPoint(object sender, LinkValidationEventArgs e)
{
    if (e.ChangingOrigin)
    {
        TableNode node = e.Link.Origin as TableNode;
        float linkOriginX = e.Link.ControlPoints[0].X;
        float nodeMiddleHorizontalPt = node.Bounds.Width / 2 + node.Bounds.X;
        // I use a different technique for those two, but let's assume your example:
        bool isLeftAnchorPt = e.Link.OriginIndex == 0;
        bool isRightAnchorPt = e.Link.OriginIndex == 1;

        // Left anchor point but link starting from the node's right
        if (isLeftAnchorPt && linkOriginX > nodeMiddleHorizontalPt)
            e.Cancel = true;
        // Right anchor point but link starting from the node's left
        else if (isRightAnchorPt && linkOriginX < nodeMiddleHorizontalPt)
            e.Cancel = true;
    }
} 


e.Cancel = true never gets called and my link keeps jumping from one anchor point to another as I move my mouse from one side of the table to the other. I'm guessing it's because when ValidateAnchorPoint gets called, the jump has already totally occured. So let's say I'm jumping from text1 anchorPoint to text2 anchorPoint (as above), then (isRightAnchorPt && linkOriginX < nodeMiddleHorizontalPt) is false because the jump has already occured (it's too late to cancel it).

How can I fix my problem? Did you successfully reproduce it?

Thanks,
Marie
« Last Edit: Mar 5th, 2009 at 6:09pm by 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 #8 - Mar 5th, 2009 at 6:05pm
Print Post  
Perhaps you should remove the e.ChangingOrigin condition. I think it is true only when modifying an existing link and the first control point is being dragged.

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



Posts: 147
Joined: Nov 11th, 2008
Re: Link creation - toggling anchor point
Reply #9 - Mar 5th, 2009 at 6:09pm
Print Post  
Doesn't work either. My code gets called when the swap has already occured (just after, but still too late).
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

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

e.Link.OriginIndex is not set at the time this event is raised. The event is raised once for each suitable anchor point, and you receive its index through e.AnchorIndex:

Code
Select All
private void diagram_ValidateAnchorPoint(object sender, LinkValidationEventArgs e)
{
	TableNode node = e.Link.Origin as TableNode;
	float linkOriginX = e.Link.ControlPoints[0].X;
	float nodeMiddleHorizontalPt = node.Bounds.Width / 2 + node.Bounds.X;
	// I use a different technique for those two, but let's assume your example:
	bool isLeftAnchorPt = e.AnchorIndex == 0;
	bool isRightAnchorPt = e.AnchorIndex == 1;

	// Left anchor point but link starting from the node's right
	if (isLeftAnchorPt && linkOriginX > nodeMiddleHorizontalPt)
		e.Cancel = true;
	// Right anchor point but link starting from the node's left
	else if (isRightAnchorPt && linkOriginX < nodeMiddleHorizontalPt)
		e.Cancel = true;
}
 



Adding diagram.RoutingOptions.Anchoring = Anchoring.Keep; to the code above and handling this event made this work as you expect it to.

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 #11 - Mar 6th, 2009 at 4:03pm
Print Post  
Hi Stoyan,

I'm mixed up with parameters. First, e.Link.OriginIndex sometimes seems to have an assigned value (but not e.Link.DestinationIndex). I tried your technique but can't get it to work. I'm not 100% sure what the parameters mean, but I tried different combinaisons. Apparently, parameters in LinkValidationEventArgs are not always used and not in the same way in Diagram.ValidateAnchorPoint than in Diagram.LinkCreating.

Here is the code I used, which doesn't use your left=0/right=1 assumption (I can't use e.AnchorIndex == 0 to assume it's the left anchor point in my case because it varies. Instead, I came up with some other code):
Code
Select All
void diagram_ValidateAnchorPoint(object sender, LinkValidationEventArgs e)
{
    diagram.RoutingOptions.Anchoring = Anchoring.Keep;  // Just in case ;)

    try
    {
        // Tried this:
        //TableNode node = e.Node as TableNode;
        //AnchorPoint originAnchorPt = node.Rows[e.TableRow].AnchorPattern.Points[e.AnchorIndex];

        // Also tried this:
        TableNode node = e.Link.Origin as TableNode;
        AnchorPoint originAnchorPt = node.Rows[e.Link.OriginIndex].AnchorPattern.Points[e.Link.OriginAnchor];

        // Also tried different random combinaisons just in case...

        float linkX = e.Link.ControlPoints[0].X;
        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) { }
} 



Now I can have strange behavior, but no solution that works.

How can I fix my problem? Did you successfully reproduce it?

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 #12 - Mar 6th, 2009 at 5:01pm
Print Post  
I reproduced it with the two tables and initialization code shown a few posts above, and then that Validate handler did prevent using the other point. In ValidateAnchorPoint handlers you should use e.AnchorIndex - it specifies the point for which the control asks your permission to use it. Additionally, you can simply check originAnchorPt.X to know where it's a left or right point. Now I can't guess which of the many possible settings could still cause a problem for you; if you can't make it work, email a sample project that shows the problem to support@mindfusion.eu.

Stoyan

edit: if the anchor points are in different cells, you can check originAnchorPt.Column to know if they are on the left or right of the table.
  
Back to top
 
IP Logged
 
marie
Full Member
***
Offline



Posts: 147
Joined: Nov 11th, 2008
Re: Link creation - toggling anchor point
Reply #13 - Mar 6th, 2009 at 6:09pm
Print Post  
Hi Stoyan,

I have a "few" questions:
-1- Why does this jumping problem occur only when Anchoring=Keep and not when Anchoring=Ignore?
-2- When ValidateAnchorPoint is fired, has the jump already occured?
-3- Since e.AnchorIndex specifies the AnchorPoint position before the jump,
    a) Does e.Link.Origin, e.Link.AnchorIndex and e.Link.OriginIndex specify the origin of the link before or after the jump?
    b) Do the row & table can change (e.Link.Origin & e.Link.OriginIndex) for the same link origin?
    c) If no, then am I safely allowed to use: AnchorPoint originAnchorPt = e.Link.Origin.Rows[e.Link.OriginIndex].AnchorPattern.Points[e.AnchorIndex]; (if row or table can change, than this is invalid)?
    d) In Diagram.ValidateAnchorPoint, does LinkValidationEventArgs.node specify the node holding the anchor point before or after the jump? Should I use e.Node.Rows[e.Link.OriginIndex].AnchorPattern.Points[e.AnchorIndex]; instead to get the anchor point?
-4- Since this jumping problem can also occur for the destination anchor point, can I use e.Link.Destination as the node (if it is not set/available, what can I use instead)?

I failed to reproduce the jumping problem in a sample project... I'll try again if the 7 questions don't help.

Thanks a lot!
Marie

n.b. If some questions are not clear, just mention it and I'll try to explain them better...
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

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

1. The link is not connected to an anchor point until the user finish drawing it, by releasing the mouse button, or at least that's how it had worked before we implemented routing a couple of years ago. Now what seems to happen here is that setting Anchoring = Keep forces the routing function to choose anchor points, but it chooses them based on the node positions, and not on where the user started drawing. So in that case you get ValidateAnchorPoint events raised while the routing algorithms looks for appropriate anchor points. On the other hand, Anchoring=Ignore makes it find a route between the current end points of the link, which are not yet connected to an anchor point.

2. It should be raised before the jump, when deciding for the first time which anchor point should be used.

3. For validation events you should use the members of the LinkEventArgs object, and not the ones of 'args.Link'.

4. You should use e.Node.

Stoyan
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: [1] 2 
Send TopicPrint