Example #1
0
        public ConnectInfo GetInfo1(ConnectOrientation orient, Point p)
        {
            ConnectInfo info = ConnectInfo.Empty;
            double      w    = this.ActualWidth;
            double      h    = this.ActualHeight;

            info.Position     = new Point((w - 10) * p.X + 5, (h - 10) * p.Y + 5);
            info.DesignerRect = new Rect(0, 0, w, h);
            info.Orient       = orient;
            return(info);
        }
Example #2
0
        private static ConnectOrientation GetOpositeOrientation(ConnectOrientation connectorOrientation)
        {
            switch (connectorOrientation)
            {
            case ConnectOrientation.Left:
                return(ConnectOrientation.Right);

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

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

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

            default:
                return(ConnectOrientation.Top);
            }
        }
Example #3
0
        private static void GetNeighborCorners(ConnectOrientation orientation, Rect rect, out Point n1, out Point n2)
        {
            switch (orientation)
            {
            case ConnectOrientation.Left:
                n1 = rect.TopLeft; n2 = rect.BottomLeft;
                break;

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

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

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

            default:
                throw new Exception("No neighour corners found!");
            }
        }
Example #4
0
 public LinkPosition(Point p, ConnectOrientation o)
 {
     this.Position = p;
     this.Orient   = o;
 }
Example #5
0
        private static List <Point> OptimizeLinePoints(List <Point> linePoints, Rect[] rectangles, ConnectOrientation sourceOrientation, ConnectOrientation 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)
                {
                    ConnectOrientation orientationFrom;
                    ConnectOrientation 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 == ConnectOrientation.Left || orientationFrom == ConnectOrientation.Right) &&
                        (orientationTo == ConnectOrientation.Left || orientationTo == ConnectOrientation.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 == ConnectOrientation.Top || orientationFrom == ConnectOrientation.Bottom) &&
                        (orientationTo == ConnectOrientation.Top || orientationTo == ConnectOrientation.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 == ConnectOrientation.Left || orientationFrom == ConnectOrientation.Right) &&
                        (orientationTo == ConnectOrientation.Top || orientationTo == ConnectOrientation.Bottom))
                    {
                        points.Insert(j + 1, new Point(points[j + 1].X, points[j].Y));
                        return(points);
                    }

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

            return(points);
        }
Example #6
0
        internal static List <Point> GetConnectionLine(ConnectInfo source, Point sinkPoint, ConnectOrientation preferredOrientation)
        {
            List <Point> linePoints = new List <Point>();
            Rect         rectSource = GetRectWithMargin(source, 5);
            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.Orient, rectSource, out n1, out n2);
                        if (sideFlag)
                        {
                            linePoints.Add(n1);
                        }
                        else
                        {
                            linePoints.Add(n2);
                        }

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

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

            return(linePoints);
        }
Example #7
0
 public LinkPin(ConnectOrientation o, Point p)
 {
     this.Cursor           = Cursors.Cross;
     this.RelativePosition = p;
     this.Orientation      = o;
 }