示例#1
0
        private Point GetNearestNeighborSource(ConnectorInfo source, Point endPoint, Rect rectSource, out bool flag)
        {
            Point n1, n2; // neighbors

            this.GetNeighborCorners(source.Orientation, rectSource, out n1, out n2);

            if ((this.Distance(n1, endPoint) <= this.Distance(n2, endPoint)))
            {
                flag = true;
                return(n1);
            }
            else
            {
                flag = false;
                return(n2);
            }
        }
示例#2
0
        /// <summary>
        /// Adds a new connection.
        /// </summary>
        /// <param name="connection">The connection.</param>
        private void AddConnection(TileConnection connection)
        {
            ConnectableViewItem connectableFrom = this.GetConnectable(connection.FromId);

            if (connectableFrom == null)
            {
                return;
            }
            ConnectableViewItem connectableTo = this.GetConnectable(connection.ToId);

            if (connectableTo == null)
            {
                return;
            }


            //From
            HitTestInfo       hitTestInfo         = this.GetHitTestInfo(connection.FromOrientation);
            ConnectorInfo     originConnectorInfo = connectableFrom.CreateDiagramConnection(hitTestInfo);
            DiagramConnection newConnection       = new DiagramConnection(connectableFrom, originConnectorInfo, 0)
            {
                Id             = connection.Id,
                ConnectionType = connection.ConnectionType,
                RoutingMode    = connection.RoutingMode
            };

            newConnection.EditOperationRequested += this.OnConnectionEditRequested;
            //newConnection.CreateConnection(connection.Color, this.scatterView.DiagramSelectedConnectionColor, this.scatterView.DiagramConnectionHighlightColor, connection.Thickness, connection.Opacity);

            //To
            hitTestInfo = this.GetHitTestInfo(connection.ToOrientation);
            ConnectorInfo targetConnectorInfo = connectableTo.CreateDiagramConnection(hitTestInfo);

            //newConnection.CompletePendingConnection(connectableTo, targetConnectorInfo, this.scatterView.ControlTileScale);

            //Adds connection to related tiles
            newConnection.Origin.DiagramConnections.Add(newConnection);
            newConnection.Destination.DiagramConnections.Add(newConnection);

            connection.DiagramConnection = newConnection;

            //this.scatterView.AddVisualConnection(newConnection, false);
        }
示例#3
0
        /// <summary>
        /// Gets the connection line.
        /// </summary>
        /// <param name="source">The source.</param>
        /// <param name="sink">The sink.</param>
        /// <param name="showLastLine">if set to <c>true</c> [show last line].</param>
        /// <returns></returns>
        public List <Point> GetConnectionLine(ConnectorInfo source, ConnectorInfo sink, bool showLastLine)
        {
            List <Point> linePoints = new List <Point>();

            Rect rectSource = this.GetRectWithMargin(source, Margin);
            Rect rectSink   = this.GetRectWithMargin(sink, Margin);

            Point startPoint = this.GetOffsetPoint(source, rectSource);
            Point endPoint   = this.GetOffsetPoint(sink, rectSink);

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

            if (!rectSink.Contains(currentPoint) && !rectSource.Contains(endPoint))
            {
                while (true)
                {
                    #region source node

                    if (this.IsPointVisible(currentPoint, endPoint, new Rect[] { rectSource, rectSink }))
                    {
                        linePoints.Add(endPoint);
                        currentPoint = endPoint;
                        break;
                    }

                    Point neighbour = this.GetNearestVisibleNeighborSink(currentPoint, endPoint, sink, rectSource, rectSink);
                    if (!double.IsNaN(neighbour.X))
                    {
                        linePoints.Add(neighbour);
                        linePoints.Add(endPoint);
                        currentPoint = endPoint;
                        break;
                    }

                    if (currentPoint == startPoint)
                    {
                        bool  flag;
                        Point n = this.GetNearestNeighborSource(source, endPoint, rectSource, rectSink, out flag);
                        linePoints.Add(n);
                        currentPoint = n;

                        if (!this.IsRectVisible(currentPoint, rectSink, new Rect[] { rectSource }))
                        {
                            Point n1, n2;
                            this.GetOppositeCorners(source.Orientation, rectSource, out n1, out n2);
                            if (flag)
                            {
                                linePoints.Add(n1);
                                currentPoint = n1;
                            }
                            else
                            {
                                linePoints.Add(n2);
                                currentPoint = n2;
                            }
                            if (!this.IsRectVisible(currentPoint, rectSink, new Rect[] { rectSource }))
                            {
                                if (flag)
                                {
                                    linePoints.Add(n2);
                                    currentPoint = n2;
                                }
                                else
                                {
                                    linePoints.Add(n1);
                                    currentPoint = n1;
                                }
                            }
                        }
                    }

                    #endregion

                    #region sink node

                    else // from here on we jump to the sink node
                    {
                        Point n1, n2; // neighbour corner
                        Point s1, s2; // opposite corner
                        this.GetNeighborCorners(sink.Orientation, rectSink, out s1, out s2);
                        this.GetOppositeCorners(sink.Orientation, rectSink, out n1, out n2);

                        bool n1Visible = this.IsPointVisible(currentPoint, n1, new Rect[] { rectSource, rectSink });
                        bool n2Visible = this.IsPointVisible(currentPoint, n2, new Rect[] { rectSource, rectSink });

                        if (n1Visible && n2Visible)
                        {
                            if (rectSource.Contains(n1))
                            {
                                linePoints.Add(n2);
                                if (rectSource.Contains(s2))
                                {
                                    linePoints.Add(n1);
                                    linePoints.Add(s1);
                                }
                                else
                                {
                                    linePoints.Add(s2);
                                }

                                linePoints.Add(endPoint);
                                currentPoint = endPoint;
                                break;
                            }

                            if (rectSource.Contains(n2))
                            {
                                linePoints.Add(n1);
                                if (rectSource.Contains(s1))
                                {
                                    linePoints.Add(n2);
                                    linePoints.Add(s2);
                                }
                                else
                                {
                                    linePoints.Add(s1);
                                }

                                linePoints.Add(endPoint);
                                currentPoint = endPoint;
                                break;
                            }

                            if ((this.Distance(n1, endPoint) <= this.Distance(n2, endPoint)))
                            {
                                linePoints.Add(n1);
                                if (rectSource.Contains(s1))
                                {
                                    linePoints.Add(n2);
                                    linePoints.Add(s2);
                                }
                                else
                                {
                                    linePoints.Add(s1);
                                }
                                linePoints.Add(endPoint);
                                currentPoint = endPoint;
                                break;
                            }
                            else
                            {
                                linePoints.Add(n2);
                                if (rectSource.Contains(s2))
                                {
                                    linePoints.Add(n1);
                                    linePoints.Add(s1);
                                }
                                else
                                {
                                    linePoints.Add(s2);
                                }
                                linePoints.Add(endPoint);
                                currentPoint = endPoint;
                                break;
                            }
                        }
                        else if (n1Visible)
                        {
                            linePoints.Add(n1);
                            if (rectSource.Contains(s1))
                            {
                                linePoints.Add(n2);
                                linePoints.Add(s2);
                            }
                            else
                            {
                                linePoints.Add(s1);
                            }
                            linePoints.Add(endPoint);
                            currentPoint = endPoint;
                            break;
                        }
                        else
                        {
                            linePoints.Add(n2);
                            if (rectSource.Contains(s2))
                            {
                                linePoints.Add(n1);
                                linePoints.Add(s1);
                            }
                            else
                            {
                                linePoints.Add(s2);
                            }
                            linePoints.Add(endPoint);
                            currentPoint = endPoint;
                            break;
                        }
                    }

                    #endregion
                }
            }
            else
            {
                linePoints.Add(endPoint);
            }

            linePoints = this.OptimizeLinePoints(linePoints, new Rect[] { rectSource, rectSink }, source.Orientation, sink.Orientation);

            this.CheckPathEnd(source, sink, showLastLine, linePoints);
            return(linePoints);
        }
示例#4
0
        private Point GetNearestVisibleNeighborSink(Point currentPoint, Point endPoint, ConnectorInfo sink, Rect rectSource, Rect rectSink)
        {
            Point s1, s2; // neighbors on sink side

            this.GetNeighborCorners(sink.Orientation, rectSink, out s1, out s2);

            bool flag1 = this.IsPointVisible(currentPoint, s1, new Rect[] { rectSource, rectSink });
            bool flag2 = this.IsPointVisible(currentPoint, s2, new Rect[] { rectSource, rectSink });

            if (flag1)     // s1 visible
            {
                if (flag2) // s1 and s2 visible
                {
                    if (rectSink.Contains(s1))
                    {
                        return(s2);
                    }

                    if (rectSink.Contains(s2))
                    {
                        return(s1);
                    }

                    if ((this.Distance(s1, endPoint) <= this.Distance(s2, endPoint)))
                    {
                        return(s1);
                    }
                    else
                    {
                        return(s2);
                    }
                }
                else
                {
                    return(s1);
                }
            }
            else // s1 not visible
            {
                if (flag2) // only s2 visible
                {
                    return(s2);
                }
                else // s1 and s2 not visible
                {
                    return(new Point(double.NaN, double.NaN));
                }
            }
        }
示例#5
0
        /// <summary>
        /// Gets the connection line.
        /// </summary>
        /// <param name="source">The source.</param>
        /// <param name="sinkPoint">The sink point.</param>
        /// <param name="preferredOrientation">The preferred orientation.</param>
        /// <returns></returns>
        public List <Point> GetConnectionLine(ConnectorInfo source, Point sinkPoint, ConnectorOrientation preferredOrientation)
        {
            List <Point> linePoints = new List <Point>();
            Rect         rectSource = this.GetRectWithMargin(source, 1);
            Point        startPoint = this.GetOffsetPoint(source, rectSource);
            Point        endPoint   = sinkPoint;

            linePoints.Add(startPoint);

            //linePoints.Add(endPoint);
            //return linePoints;



            Point currentPoint = startPoint;

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

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

                    if (this.IsPointVisible(currentPoint, endPoint, new Rect[] { rectSource }))
                    {
                        linePoints.Add(endPoint);
                        break;
                    }
                    else
                    {
                        Point n1, n2;
                        this.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 != ConnectorOrientation.None)
            {
                linePoints = this.OptimizeLinePoints(linePoints, new Rect[] { rectSource }, source.Orientation, preferredOrientation);
            }
            else
            {
                linePoints = this.OptimizeLinePoints(linePoints, new Rect[] { rectSource }, source.Orientation, this.GetOpositeOrientation(source.Orientation));
            }

            return(linePoints);
        }