Example #1
0
        /// <summary>
        /// Adjusts the endpoints of the link so that they are docked with the
        /// foreign ports they are connected to.
        /// </summary>
        /// <remarks>
        /// <para>
        /// This method iterates through every connection in the link. For each
        /// connection, the location of the local port is updated to match
        /// the location of the foreign port. If the foreign port has its
        /// AttachAtPerimeter flag set to true, then some additional calculations
        /// are made in order to move the local port to the perimeter of the
        /// foreign port's container.
        /// </para>
        /// <seealso cref="Syncfusion.Windows.Forms.Diagram.Port.AttachAtPerimeter"/>
        /// </remarks>
        protected virtual void DockConnections()
        {
            IPoints              shapePts = this.Points;
            LinkPort             curLocalPort;
            Port                 curForeignPort;
            IPortContainer       curForeignObj;
            int                  numPoints            = 0;
            ConnectionCollection perimeterConnections = new ConnectionCollection();

            PointF ptStart;
            int    ptIdx;
            PointF ptBoundary;

            if (shapePts != null)
            {
                numPoints = shapePts.PointCount;
                foreach (Connection curConnection in this.Connections)
                {
                    curLocalPort   = curConnection.GetLocalPort(this) as LinkPort;
                    curForeignPort = curConnection.GetForeignPort(this);

                    if (curLocalPort != null && curForeignPort != null)
                    {
                        curLocalPort.Location = curForeignPort.Location;

                        if (curForeignPort.AttachAtPerimeter)
                        {
                            perimeterConnections.Add(curConnection);
                        }
                    }
                }

                foreach (Connection curConnection in perimeterConnections)
                {
                    curLocalPort   = curConnection.GetLocalPort(this) as LinkPort;
                    curForeignPort = curConnection.GetForeignPort(this);

                    if (curLocalPort != null && curForeignPort != null)
                    {
                        curForeignObj = curForeignPort.Container;
                        if (curForeignObj != null)
                        {
                            ptIdx = curLocalPort.PointIndex;
                            if (ptIdx > 0 && ptIdx == numPoints - 1)
                            {
                                ptStart = shapePts.GetPoint(ptIdx - 1);
                            }
                            else if (ptIdx == 0 && numPoints > 1)
                            {
                                ptStart = shapePts.GetPoint(ptIdx + 1);
                            }
                            else
                            {
                                ptStart = curLocalPort.Location;
                            }

                            IGraphics curForeignObjGraphics = curForeignObj as IGraphics;
                            if (curForeignObjGraphics != null)
                            {
                                if (Geometry.GetBoundaryIntercept(curForeignObjGraphics.CreateRegion(0.0f), curLocalPort.Location, ptStart, out ptBoundary))
                                {
                                    curLocalPort.Location = ptBoundary;
                                }
                            }
                        }
                    }
                }
            }
        }