Ejemplo n.º 1
0
        public void UpdatePaths()
        {
            //catch for when the node is removed and layout update is still triggered
            try
            {
                if (this.Parent == null)
                {
                    return;
                }

                if (!this.HasAncestor(graph.ViewPort))
                {
                    return;
                }

                Point r1 = this.TransformToAncestor(graph.ViewPort).Transform(new Point(ActualWidth, 8f));

                //need to add a text drawing of Order for lines
                //as the order is important
                //to know when connecting for functions
                int i = 1;
                foreach (UINodePoint n in to)
                {
                    if (n.Parent == null)
                    {
                        continue;
                    }

                    if (!n.HasAncestor(graph.ViewPort))
                    {
                        continue;
                    }

                    Point r2 = n.TransformToAncestor(graph.ViewPort).Transform(new Point(0f, 8f));

                    Path path = null;

                    paths.TryGetValue(n, out path);

                    double dy = r2.Y - r1.Y;

                    Point mid = new Point((r2.X + r1.X) * 0.5f, (r2.Y + r1.Y) * 0.5f + dy * 0.5f);

                    TextBlock num = null;

                    numbers.TryGetValue(n, out num);

                    if (path != null)
                    {
                        path.IsHitTestVisible = false;
                        Canvas.SetZIndex(path, -1);
                        if (path.Data == null)
                        {
                            path.VerticalAlignment   = VerticalAlignment.Top;
                            path.HorizontalAlignment = HorizontalAlignment.Left;
                            PathGeometry p  = new PathGeometry();
                            PathFigure   pf = new PathFigure();
                            pf.IsClosed   = false;
                            pf.StartPoint = r1;

                            BezierSegment seg = new BezierSegment(r1, mid, r2, true);
                            pf.Segments.Add(seg);
                            p.Figures.Add(pf);
                            path.Data = p;
                        }
                        else
                        {
                            PathGeometry p  = (PathGeometry)path.Data;
                            PathFigure   pf = p.Figures[0];
                            pf.StartPoint = r1;
                            BezierSegment seg = (BezierSegment)pf.Segments[0];
                            seg.Point1 = r1;
                            seg.Point2 = mid;
                            seg.Point3 = r2;
                        }
                    }

                    if (num != null)
                    {
                        Point p = CatmullRomSpline.GetPointOnBezierCurve(r1, mid, r2, 0.25f);
                        num.Text             = i.ToString();
                        num.IsHitTestVisible = false;
                        Canvas.SetZIndex(num, -1);
                        Canvas.SetLeft(num, p.X);
                        Canvas.SetTop(num, p.Y);
                    }

                    i++;
                }
            }
            catch { }
        }