/// <summary> /// Calculates a location based on the shape dimensions as well as the proposed location. /// </summary> /// <param name="placement">Link placement.</param> /// <param name="shapeDimensions">Dimensions of the shape, this link start/end is created at.</param> /// <param name="proposedLocation">Proposed location of the link start/end.</param> /// <returns>Calculated location.</returns> public static PointD CalculateLocation(LinkPlacement placement, RectangleD shapeDimensions, PointD proposedLocation) { double x = proposedLocation.X; double y = proposedLocation.Y; double itemWidth = 7; double itemHeight = 7; switch (placement) { case LinkPlacement.Left: x = shapeDimensions.Left - itemWidth; if (y <= (shapeDimensions.Top - itemHeight)) y = shapeDimensions.Top - itemHeight; else if (y > shapeDimensions.Bottom) y = shapeDimensions.Bottom; break; case LinkPlacement.Top: y = shapeDimensions.Top - itemHeight; if (x <= (shapeDimensions.Left - itemWidth)) x = shapeDimensions.Left - itemWidth; else if (x > shapeDimensions.Right) x = shapeDimensions.Right; break; case LinkPlacement.Right: x = shapeDimensions.Right + 3.4 * 2; if (y <= (shapeDimensions.Top - itemHeight)) y = shapeDimensions.Top - itemHeight; else if (y > shapeDimensions.Bottom) y = shapeDimensions.Bottom; break; case LinkPlacement.Bottom: y = shapeDimensions.Bottom + 3.4 * 2; if (x <= (shapeDimensions.Left - itemWidth)) x = shapeDimensions.Left - itemWidth; else if (x > shapeDimensions.Right) x = shapeDimensions.Right; break; } return new PointD(x, y); }
/// <summary> /// Update link placement end. /// </summary> public void UpdateLinkPlacementTarget() { if (this.TargetAnchor != null) { if (this.TargetAnchor.ToShape != null) LinkPlacementEnd = GetLinkPlacement(this.TargetAnchor.ToShape.AbsoluteBounds, this.EndPoint); if (this.TargetAnchor.AbsoluteLocation != this.EndPoint) { if (!this.Store.InSerializationTransaction) this.TargetAnchor.DiscardLocationChange = true; this.TargetAnchor.AbsoluteLocation = this.EndPoint; } } }