示例#1
0
        private static EnumConnectorOrientation GetOpositeOrientation(EnumConnectorOrientation connectorOrientation)
        {
            switch (connectorOrientation)
            {
            case EnumConnectorOrientation.Left:
                return(EnumConnectorOrientation.Right);

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

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

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

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

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

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

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

            default:
                throw new Exception("No neighour corners found!");
            }
        }
示例#3
0
        private static Orientation GetOrientation(EnumConnectorOrientation sourceOrientation)
        {
            switch (sourceOrientation)
            {
            case EnumConnectorOrientation.Left:
                return(Orientation.Horizontal);

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

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

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

            default:
            {
                MessageBox.Show("Bağlantı Noktalarında beklenemeyen bir kordinasyon kayması ! ", "ConnectorOrientation", MessageBoxButton.OK, MessageBoxImage.Warning);
                return(Orientation.Horizontal);
            }
                //throw new Exception("Unknown ConnectorOrientation");
            }
        }
示例#4
0
        private static List <Point> OptimizeLinePoints(List <Point> linePoints, Rect[] rectangles, EnumConnectorOrientation sourceOrientation, EnumConnectorOrientation 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)
                {
                    EnumConnectorOrientation orientationFrom;
                    EnumConnectorOrientation 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 == EnumConnectorOrientation.Left || orientationFrom == EnumConnectorOrientation.Right) &&
                        (orientationTo == EnumConnectorOrientation.Left || orientationTo == EnumConnectorOrientation.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 == EnumConnectorOrientation.Top || orientationFrom == EnumConnectorOrientation.Bottom) &&
                        (orientationTo == EnumConnectorOrientation.Top || orientationTo == EnumConnectorOrientation.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 == EnumConnectorOrientation.Left || orientationFrom == EnumConnectorOrientation.Right) &&
                        (orientationTo == EnumConnectorOrientation.Top || orientationTo == EnumConnectorOrientation.Bottom))
                    {
                        points.Insert(j + 1, new Point(points[j + 1].X, points[j].Y));
                        return(points);
                    }

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

            return(points);
        }
示例#5
0
        internal static List <Point> GetConnectionLine(ModelConnectorInfo source, Point sinkPoint, EnumConnectorOrientation 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 != EnumConnectorOrientation.None)
            {
                linePoints = OptimizeLinePoints(linePoints, new Rect[] { rectSource }, source.Orientation, preferredOrientation);
            }
            else
            {
                linePoints = OptimizeLinePoints(linePoints, new Rect[] { rectSource }, source.Orientation, GetOpositeOrientation(source.Orientation));
            }

            return(linePoints);
        }