Beispiel #1
0
        private void DrawBezier()
        {
            if (point1.Parent == null || point2.Parent == null)
            {
                return;
            }
            if (!point1.HasAncestor(view) || !point2.HasAncestor(view))
            {
                return;
            }

            Point r1 = point1.TransformToAncestor(view).Transform(new Point(point1.ActualWidth, 8f));
            Point r2 = point2.TransformToAncestor(view).Transform(new Point(0f, 8f));

            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);

            if (path != null)
            {
                if (selected)
                {
                    path.Stroke = RedColor;
                }
                else
                {
                    path.Stroke = point1.ColorBrush;
                }

                path.IsHitTestVisible = false;
                Canvas.SetZIndex(path, -1);
                if (path.Data == null || lastType != type)
                {
                    lastType = type;
                    InitBezier(ref r1, ref mid, ref r2);
                }
                else
                {
                    PathGeometry p  = (PathGeometry)path.Data;
                    PathFigure   pf = p.Figures[0];
                    pf.StartPoint = r1;

                    if (pf.Segments.Count > 1)
                    {
                        InitBezier(ref r1, ref mid, ref r2);
                    }
                    else if (pf.Segments[0] is BezierSegment)
                    {
                        BezierSegment seg = (BezierSegment)pf.Segments[0];
                        seg.Point1 = r1;
                        seg.Point2 = mid;
                        seg.Point3 = r2;
                    }
                    else
                    {
                        InitBezier(ref r1, ref mid, ref r2);
                    }
                }
            }

            if (num != null)
            {
                Point p = CatmullRomSpline.GetPointOnBezierCurve(r1, mid, r2, 0.5f);
                num.Text             = (point1.GetOutIndex(point2) + 1).ToString();
                num.IsHitTestVisible = false;
                Canvas.SetZIndex(num, -1);
                Canvas.SetLeft(num, p.X);
                Canvas.SetTop(num, p.Y);
            }
        }
Beispiel #2
0
 static NodePath()
 {
     lastType = type = NodePathType.Line;
 }
Beispiel #3
0
        private void DrawLines()
        {
            if (point1.Parent == null || point2.Parent == null)
            {
                return;
            }
            if (!point1.HasAncestor(view) || !point2.HasAncestor(view))
            {
                return;
            }

            Point r1 = point1.TransformToAncestor(view).Transform(new Point(point1.ActualWidth, 8f));
            Point r2 = point2.TransformToAncestor(view).Transform(new Point(0f, 8f));

            double midy = (r2.Y + r1.Y) * 0.5;
            double midx = (r2.X + r1.X) * 0.5;

            ///calculate distance
            double diffx = r2.X - r1.X;

            diffx *= diffx;
            double diffy = r2.Y - r1.Y;

            diffy *= diffy;

            double dist = Math.Sqrt(diffx + diffy);
            ///

            double distExtra = dist * 0.05;

            double r1Extra = distExtra;
            double r2Extra = -distExtra;

            double r1y = midy;
            double r2y = midy;

            if (path != null)
            {
                if (selected)
                {
                    path.Stroke = RedColor;
                }
                else
                {
                    path.Stroke = point1.ColorBrush;
                }

                path.IsHitTestVisible = false;
                Canvas.SetZIndex(path, -1);
                if (path.Data == null || lastType != type)
                {
                    lastType = type;
                    InitLines(ref r1, r1Extra, r1y, r2Extra, r2y, ref r2);
                }
                else
                {
                    PathGeometry p  = (PathGeometry)path.Data;
                    PathFigure   pf = p.Figures[0];
                    pf.StartPoint = r1;

                    if (pf.Segments.Count < 5)
                    {
                        InitLines(ref r1, r1Extra, r1y, r2Extra, r2y, ref r2);
                    }
                    else if (pf.Segments[0] is LineSegment && pf.Segments[1] is LineSegment &&
                             pf.Segments[2] is LineSegment && pf.Segments[3] is LineSegment &&
                             pf.Segments[4] is LineSegment)
                    {
                        LineSegment seg = (LineSegment)pf.Segments[0];
                        seg.Point = new Point(r1Extra * 0.5 + r1.X, r1.Y);
                        LineSegment seg2 = (LineSegment)pf.Segments[1];
                        seg2.Point = new Point(r1Extra + r1.X, r1y);
                        LineSegment seg3 = (LineSegment)pf.Segments[2];
                        seg3.Point = new Point(r2Extra + r2.X, r2y);
                        LineSegment seg4 = (LineSegment)pf.Segments[3];
                        seg4.Point = new Point(r2Extra * 0.5 + r2.X, r2.Y);
                        LineSegment seg5 = (LineSegment)pf.Segments[4];
                        seg5.Point = r2;
                    }
                    else
                    {
                        InitLines(ref r1, r1Extra, r1y, r2Extra, r2y, ref r2);
                    }
                }
            }

            if (num != null)
            {
                Point p = new Point(midx, midy);
                num.Text             = (point1.GetOutIndex(point2) + 1).ToString();
                num.IsHitTestVisible = false;
                Canvas.SetZIndex(num, -1);
                Canvas.SetLeft(num, p.X);
                Canvas.SetTop(num, p.Y);
            }
        }