예제 #1
0
        /// <summary>
        /// This function corrects the given proposed location if the given child shape is a relative shape and
        /// is only allowed to be placed on the edge of its parent.
        /// </summary>
        /// <param name="parentShape">Parent shape.</param>
        /// <param name="childShape">Child shape.</param>
        /// <param name="proposedLocation">Proposed location.</param>
        /// <remarks>
        /// This function needs to be called withing a modeling transaction.
        ///
        /// This function assigns new values to Location and PortPlacement if necessary.
        /// </remarks>
        /// <returns>
        /// Location that was assigned to the shape. It might have the same value as the location
        /// the shape had before calling this function.
        /// </returns>
        public static PointD CorrectPortLocation(NodeShape parentShape, NodeShape childShape, PointD proposedLocation)
        {
            if (parentShape == null)
            {
                throw new ArgumentNullException("parentShape");
            }

            if (childShape == null)
            {
                throw new ArgumentNullException("childShape");
            }

            if (!childShape.IsRelativeChildShape || childShape.MovementBehaviour != ShapeMovementBehaviour.PositionOnEdgeOfParent)
            {
                return(proposedLocation);
            }

            RectangleD rectParent     = parentShape.Bounds;
            RectangleD proposedBounds = new RectangleD(proposedLocation, childShape.Size);

            PortPlacement placement = NodeShape.GetPortPlacement(rectParent, proposedBounds);

            return(CorrectPortLocation(placement, parentShape, childShape, proposedLocation));
        }