Пример #1
0
        private static eLinkOrientation GetOpositeOrientation(eLinkOrientation eLinkOrientation)
        {
            switch (eLinkOrientation)
            {
            case eLinkOrientation.Left:
                return(eLinkOrientation.Right);

            case eLinkOrientation.Top:
                return(eLinkOrientation.Bottom);

            case eLinkOrientation.Right:
                return(eLinkOrientation.Left);

            case eLinkOrientation.Bottom:
                return(eLinkOrientation.Top);

            default:
                return(eLinkOrientation.Top);
            }
        }
Пример #2
0
        private static Orientation GetOrientation(eLinkOrientation sourceOrientation)
        {
            switch (sourceOrientation)
            {
            case eLinkOrientation.Left:
                return(Orientation.Horizontal);

            case eLinkOrientation.Top:
                return(Orientation.Vertical);

            case eLinkOrientation.Right:
                return(Orientation.Horizontal);

            case eLinkOrientation.Bottom:
                return(Orientation.Vertical);

            default:
                throw new Exception("Unknown eLinkOrientation");
            }
        }
Пример #3
0
        private static void GetNeighborCorners(eLinkOrientation orientation, Rect rect, out Point n1, out Point n2)
        {
            switch (orientation)
            {
            case eLinkOrientation.Left:
                n1 = rect.TopLeft; n2 = rect.BottomLeft;
                break;

            case eLinkOrientation.Top:
                n1 = rect.TopLeft; n2 = rect.TopRight;
                break;

            case eLinkOrientation.Right:
                n1 = rect.TopRight; n2 = rect.BottomRight;
                break;

            case eLinkOrientation.Bottom:
                n1 = rect.BottomLeft; n2 = rect.BottomRight;
                break;

            default:
                throw new Exception("No neighour corners found!");
            }
        }
Пример #4
0
        private static List <Point> OptimizeLinePoints(List <Point> linePoints, Rect[] rectangles, eLinkOrientation sourceOrientation, eLinkOrientation sinkOrientation)
        {
            List <Point> points = new List <Point>();
            int          cut    = 0;

            for (int i = 0; i < linePoints.Count; i++)
            {
                if (i >= cut)
                {
                    for (int k = linePoints.Count - 1; k > i; k--)
                    {
                        if (IsPointVisible(linePoints[i], linePoints[k], rectangles))
                        {
                            cut = k;
                            break;
                        }
                    }
                    points.Add(linePoints[i]);
                }
            }

            #region Line
            for (int j = 0; j < points.Count - 1; j++)
            {
                if (points[j].X != points[j + 1].X && points[j].Y != points[j + 1].Y)
                {
                    eLinkOrientation orientationFrom;
                    eLinkOrientation orientationTo;

                    // orientation from point
                    if (j == 0)
                    {
                        orientationFrom = sourceOrientation;
                    }
                    else
                    {
                        orientationFrom = GetOrientation(points[j], points[j - 1]);
                    }

                    // orientation to pint
                    if (j == points.Count - 2)
                    {
                        orientationTo = sinkOrientation;
                    }
                    else
                    {
                        orientationTo = GetOrientation(points[j + 1], points[j + 2]);
                    }


                    if ((orientationFrom == eLinkOrientation.Left || orientationFrom == eLinkOrientation.Right) &&
                        (orientationTo == eLinkOrientation.Left || orientationTo == eLinkOrientation.Right))
                    {
                        double centerX = Math.Min(points[j].X, points[j + 1].X) + Math.Abs(points[j].X - points[j + 1].X) / 2;
                        points.Insert(j + 1, new Point(centerX, points[j].Y));
                        points.Insert(j + 2, new Point(centerX, points[j + 2].Y));
                        if (points.Count - 1 > j + 3)
                        {
                            points.RemoveAt(j + 3);
                        }
                        return(points);
                    }

                    if ((orientationFrom == eLinkOrientation.Top || orientationFrom == eLinkOrientation.Bottom) &&
                        (orientationTo == eLinkOrientation.Top || orientationTo == eLinkOrientation.Bottom))
                    {
                        double centerY = Math.Min(points[j].Y, points[j + 1].Y) + Math.Abs(points[j].Y - points[j + 1].Y) / 2;
                        points.Insert(j + 1, new Point(points[j].X, centerY));
                        points.Insert(j + 2, new Point(points[j + 2].X, centerY));
                        if (points.Count - 1 > j + 3)
                        {
                            points.RemoveAt(j + 3);
                        }
                        return(points);
                    }

                    if ((orientationFrom == eLinkOrientation.Left || orientationFrom == eLinkOrientation.Right) &&
                        (orientationTo == eLinkOrientation.Top || orientationTo == eLinkOrientation.Bottom))
                    {
                        points.Insert(j + 1, new Point(points[j + 1].X, points[j].Y));
                        return(points);
                    }

                    if ((orientationFrom == eLinkOrientation.Top || orientationFrom == eLinkOrientation.Bottom) &&
                        (orientationTo == eLinkOrientation.Left || orientationTo == eLinkOrientation.Right))
                    {
                        points.Insert(j + 1, new Point(points[j].X, points[j + 1].Y));
                        return(points);
                    }
                }
            }
            #endregion

            return(points);
        }
Пример #5
0
        public static List <Point> GetConnectionLine(ConnectorInfo source, Point sinkPoint, eLinkOrientation preferredOrientation)
        {
            List <Point> linePoints = new List <Point>();
            Rect         rectSource = GetRectWithMargin(source, 10);
            Point        startPoint = GetOffsetPoint(source, rectSource);
            Point        endPoint   = sinkPoint;

            linePoints.Add(startPoint);
            Point currentPoint = startPoint;

            if (!rectSource.Contains(endPoint))
            {
                while (true)
                {
                    if (IsPointVisible(currentPoint, endPoint, new Rect[] { rectSource }))
                    {
                        linePoints.Add(endPoint);
                        break;
                    }

                    bool  sideFlag;
                    Point n = GetNearestNeighborSource(source, endPoint, rectSource, out sideFlag);
                    linePoints.Add(n);
                    currentPoint = n;

                    if (IsPointVisible(currentPoint, endPoint, new Rect[] { rectSource }))
                    {
                        linePoints.Add(endPoint);
                        break;
                    }
                    else
                    {
                        Point n1, n2;
                        GetOppositeCorners(source.Orientation, rectSource, out n1, out n2);
                        if (sideFlag)
                        {
                            linePoints.Add(n1);
                        }
                        else
                        {
                            linePoints.Add(n2);
                        }

                        linePoints.Add(endPoint);
                        break;
                    }
                }
            }
            else
            {
                linePoints.Add(endPoint);
            }

            if (preferredOrientation != eLinkOrientation.None)
            {
                linePoints = OptimizeLinePoints(linePoints, new Rect[] { rectSource }, source.Orientation, preferredOrientation);
            }
            else
            {
                linePoints = OptimizeLinePoints(linePoints, new Rect[] { rectSource }, source.Orientation, GetOpositeOrientation(source.Orientation));
            }

            return(linePoints);
        }