Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic PathGeometry doesnt give correct points for anchor (Read 3429 times)
rajesh_patil74
Full Member
***
Offline


I love YaBB 1G - SP1!

Posts: 220
Joined: Sep 3rd, 2009
PathGeometry doesnt give correct points for anchor
Feb 28th, 2011 at 7:54am
Print Post  
Hi Stoyo

To achive one end of link dynamic and another end fixed ( using the OnValidateAnchorPoint event provided in internal build) I need to place invisible anchor point for shapes.

These anchor points needs to be displayed according to the shape and I am using PathGeometry segments to add proper anchor points on shape. The algorithm works properly for all of the segments of the shape except "RoundRect" shape.

For shape with "RoundRect" the anchor points are not added at its proper position. The algorithm works properly when the bounds of shape is (0,0,100,100) but fails for all other bounds.

I am re-assigning anchor points when nodes are resized (depending on the dimension and scale factor the anchor points gets assinged)

so, just wanted to know is there any specific algorithm applied to the RoundRect shape which changes its dimention?

Can you help me to generate correct anchor points.

Following is the result of assinging anchor for roundrect shape -
http://4nic6g.bay.livefilestore.com/y1pvwuYO5-gvdUWySzQIdk323zt8b4xWKZ7JZ9MrOnmu...

Regards
Rajesh

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


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: PathGeometry doesnt give correct points for an
Reply #1 - Feb 28th, 2011 at 11:47am
Print Post  
Hi Rajesh,

Are you getting these segments from the ShapeGeometry property of nodes?

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


I love YaBB 1G - SP1!

Posts: 220
Joined: Sep 3rd, 2009
Re: PathGeometry doesnt give correct points for an
Reply #2 - Mar 1st, 2011 at 5:17am
Print Post  
Hi Stoyo

Yes, we are using ShapeGeometry to get all the segments. Here is the code for the same

Code
Select All
 foreach (PathFigure figure in node.ShapeGeometry as PathGeometry).Figures)
                {
                    try
                    {
                        Point startPoint = figure.StartPoint;
                        Point endPoint = figure.StartPoint;
                        foreach (PathSegment segment in figure.Segments)
                        {
                            switch (segment.GetType().Name)
                            {
                                case "LineSegment":
                                    endPoint = (segment as LineSegment).Point;
                                    AddLineAnchorPoints(startPoint, endPoint, factor, anchors); //Process for Line Segments
                                    break;
                                case "ArcSegment":
                                    endPoint = (segment as ArcSegment).Point;
                                    AddArcAnchorPoints(startPoint, endPoint, (segment as ArcSegment), factor, anchors); //Process for Arc Segments
                                    break;
                                case "PolyLineSegment":
                                    foreach (Point point in (segment as PolyLineSegment).Points)
                                    {
                                        endPoint = point;
                                        AddLineAnchorPoints(startPoint, endPoint, factor, anchors); //Process for Line Segments
                                        startPoint = endPoint;
                                    }
                                    break;
                                case "BezierSegment":
                                    endPoint = (segment as BezierSegment).Point3;
                                    var controlPoint1 = (segment as BezierSegment).Point1;
                                    var controlPoint2 = (segment as BezierSegment).Point2;
                                    AddBezierAnchorPoints(startPoint, endPoint, controlPoint1, controlPoint2, factor, anchors); //Process for Bezier Segment
                                    break;
                                default:
                                    break;
                            }
                            startPoint = endPoint;
                        }
                    }
                    catch (Exception) { }
                }
 

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


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: PathGeometry doesnt give correct points for an
Reply #3 - Mar 1st, 2011 at 8:49am
Print Post  
Hi Rajesh,

The Path element in the ShapeNode's template binds directly to this ShapeGeometry property, so it's not possible the geometry values inside to be different from what you see on the screen. What does the 'factor' variable in your code do?

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


I love YaBB 1G - SP1!

Posts: 220
Joined: Sep 3rd, 2009
Re: PathGeometry doesnt give correct points for an
Reply #4 - Mar 1st, 2011 at 10:27am
Print Post  
Hi Stoyo

Even I believe that the ShapeGeometry should not give improper points. the Shape Geometry is providing proper data for all other shapes except Roundrect.

Please find the attached sample code which calculates the anchor points for various shape nodes. The code might provide you more insight about the requirement.

https://cid-2b9bf77533900b84.office.live.com/self.aspx/.Public/Anchors.zip


The factor is the distance between two anchor points on a shape.

Regards,
Rajesh
  
Back to top
WWW  
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: PathGeometry doesnt give correct points for an
Reply #5 - Mar 2nd, 2011 at 9:11am
Print Post  
Hi Rajesh,

Your code must also consider ShapeGeometry.Transform. Most shapes set it so they automatically scale the original path segments to fill node.Bounds. RoundedRect does not set it but assigns different segment coordinates, because it cannot scale uniformly without distorting the shape. Its line segments' lengths should change disproportionally in order to keep the corner radiuses fixed.

So this will return the actual positions of points you get from segment definitions, relative to the node:

point = ShapeGeometry.Transform.Transform(point);

and then you must rescale them to the 0-100 range to get AnchorPoint percent coordinates.

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