Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Determine Target AnchorPoint (Read 3248 times)
stoneCold
YaBB Newbies
*
Offline



Posts: 3
Joined: Feb 4th, 2006
Determine Target AnchorPoint
Feb 4th, 2006 at 11:09am
Print Post  
Hi all,
I'm new to the forums, and the first thing I want to do is to thank and to congratulate mindfusion.org for their great products, escpecially flowchart.net, which I'm exploring at the moment.

But you might think...."does he only want to "honor" the great software here on the forums? ???"

Roll Eyes No I don't, and so I come to my first question here at the forums =).

At the moment I play arround a bit with flowchart.net as said, and now I have come to a point where I don't know how to approach something I'd need. Is there a possibility to get the destination AnchorPoint of a arrow while drawing it??

I already started to try some things out in the "ValidateAnchorPoint" event but I can't figure out how to determine the target anchor point, only the origin with the "AnchorIndex" property of the "AttachConfirmArgs". It's important for me to get the target node's AnchorPoint WHILE moving/drawing an arrow, and not after the creation/change of it.....that is too late  Wink.

Many thanks in advance for all help,
greetings from stoneCold
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Determine Target AnchorPoint
Reply #1 - Feb 4th, 2006 at 4:19pm
Print Post  
Hi there,

Welcome to our humble forum ;)

The ValidateAnchor event won't help you with that. It is raised for each anchor point of a node to let you filter the possible points to which an arrow can connect. From the validated points, the one closest to the arrow end point is used. So at the moment when ValidateAnchor is raised, it is not yet known which point will be used as a destination.

If you don't filter out any anchor points, you can safely assume the arrow would connect to the one closest to its end point. The type of the anchor point, incoming or outgoing, should match the end of the arrow is being moved too. The Node class uses this code to select the anchor point (the rotation stuff is skipped):

[code]
for (int i = 0; i < anchorPattern.Points.Count; i++)
{
  AnchorPoint ap = anchorPattern.Points[i];
  if (incoming && !ap.AllowIncoming) continue;
  if (!incoming && !ap.AllowOutgoing) continue;
  if (!fcParent.validateAnchor(arrow, !incoming, this, i)) continue;

  PointF pos = ap.getPos(nodeRect);
  float dx = pos.X - pt.X;
  float dy = pos.Y - pt.Y;
  float ptDist = (float)Math.Sqrt(dx*dx + dy*dy);
  if (ptDist < nearestDist)
  {
    nearestDist = ptDist;
    nearestPt = pos;
    anchorIdx = i;
  }
}

return nearestPt;
[/code]

The getPos method looks like

internal PointF getPos(RectangleF nodeRect)
{
  return new PointF(
    nodeRect.X + nodeRect.Width * x / 100,
    nodeRect.Y + nodeRect.Height * y / 100);
}

The 'nearestPt' and 'anchorIdx' found above will let you know to which point the arrow would connect. If you have troubles with that code, we can make the Node method that contains it public, so you can use the FC.NET implementation.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
stoneCold
YaBB Newbies
*
Offline



Posts: 3
Joined: Feb 4th, 2006
Re: Determine Target AnchorPoint
Reply #2 - Feb 5th, 2006 at 10:32am
Print Post  
Many thanks, I took the basic idea of your code and wrapped it into my application with success, but there are still some optimizations on my task list...

1) at the moment the whole code is executed in realtime (realtime+"for" loop = 10% cpu  Grin)... I think I will put the code into the tick event of a timer and tick it each second or 1/2 second to save cpu time. That's not the problem, but..

2) in the current code i have to calculate from pixel coordinates (mouse cursor) to millimeter coordinates (FlowChart.net)......because I want to have it resolution independent.

Currently I calculate it like this
Code
Select All
millimeter = pixel / 3.77; 

please don't ask why I took "3.77"  Wink, I just played arround a bit with the value and 3.77 worked best Roll Eyes.

Can you give me a correct value for my calculation, because then I would have a better feeling when using the code......I think you know what I mean Smiley.

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


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Determine Target AnchorPoint
Reply #3 - Feb 5th, 2006 at 1:27pm
Print Post  
Hi,

1) if that's some code dependent on the mouse position, you could handle the MouseMove event instead of using a timer.

2) That's a good guess Wink Usually display settings use a 96 pixels per inch resolution, and an inch has 25.4 millimeters, so 1mm would have 96/25.4 pixels. The MS Calculator gives 3.7795275590551181102362204724409 as a result.

Better use the ClientToDoc method to convert pixel coordinates to logical ones. ClientToDoc uses the "Graphics.TransformPoints" method, which uses the DPI value set in the display adapter settings page.

Stoyan
  
Back to top
 
IP Logged
 
stoneCold
YaBB Newbies
*
Offline



Posts: 3
Joined: Feb 4th, 2006
Re: Determine Target AnchorPoint
Reply #4 - Feb 5th, 2006 at 7:18pm
Print Post  
@ 1) LOL, guess how I do it at the moment  Roll Eyes
but since it is not important to update it in realtime (MouseMove), I will use a timer with a half second tick.

@ 2) Thanks, wow I estimated it pretty right, didn't I  Grin

Thanks stoyo for your help
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint