Exemplo n.º 1
0
        /// <summary>
        /// Check whether two labels overlap. Also calculate the horizontal and vertical offsets
        /// to overcome the overlap.
        /// </summary>
        /// <param name="labelInfo">Information of the label</param>
        /// <param name="verticalOffset">How much need to move vertically to overcome overlap</param>
        /// <param name="horizontalOffset">How much need to move horizontally to overcome overlap</param>
        /// <returns>OverlapTypes</returns>
        private OverlapTypes CheckOverlap(CircularLabel label, out Double verticalOffset, out Double horizontalOffset)
        {
            OverlapTypes retValue = OverlapTypes.None; // Type of overlap

            verticalOffset   = 0;                      // How much need to move vertically to overcome overlap
            horizontalOffset = 0;                      // How much need to move horizontally to overcome overlap

            CircularLabel A = this;
            CircularLabel B = label;

            if (B.Position.Y > A.Position.Y)
            {
                if (B.Position.Y < A.Position.Y + A.Height)
                {
                    // Calculate how much need to move vertically to overcome overlap
                    verticalOffset = A.Position.Y + A.Height - B.Position.Y;
                    retValue       = OverlapTypes.Vertical;
                }
            }
            else if (A.Position.Y > B.Position.Y)
            {
                if (A.Position.Y < B.Position.Y + B.Height)
                {
                    // Calculate how much need to move vertically to overcome overlap
                    verticalOffset = B.Position.Y + B.Height - A.Position.Y;
                    retValue       = OverlapTypes.Vertical;
                }
            }

            if (B.Position.X > A.Position.X)
            {
                if (B.Position.X < A.Position.X + A.Width)
                {
                    // Calculate how much need to move horizontally to overcome overlap
                    horizontalOffset = A.Position.X + A.Width - B.Position.X;
                    retValue         = (retValue == OverlapTypes.Vertical) ? OverlapTypes.Both : OverlapTypes.Horizontal;
                }
            }
            else if (A.Position.X > B.Position.X)
            {
                if (A.Position.X < B.Position.X + B.Width)
                {
                    // Calculate how much need to move horizontally to overcome overlap
                    horizontalOffset = B.Position.X + B.Width - A.Position.X;
                    retValue         = (retValue == OverlapTypes.Vertical) ? OverlapTypes.Both : OverlapTypes.Horizontal;
                }
            }

            return(retValue);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Ask for space to NextLabel if NextLabel can leave the space.
        /// NextLabel B asks for space to the next label C.. and so on.
        /// So this CircularLabel is looking for space.
        /// </summary>
        public void PlaceLabel(Boolean skip)
        {
            Double  verticalOffset, horizontalOffset;
            Boolean placedTowardsTop;
            Boolean placedTowardsBottom;
            Boolean isPlaced = false;

            Int32 noOfIteration = 2;

            OverlapTypes overlapTypesBottom = CheckOverLap(SweepDirection.Clockwise, out verticalOffset, out horizontalOffset);

            if (overlapTypesBottom == OverlapTypes.Both)
            {
                placedTowardsTop    = AskSpaceToPreviusLabel(this, verticalOffset / 2, noOfIteration);
                placedTowardsBottom = AskSpaceToNextLabel(this, verticalOffset / 2, noOfIteration);

                if (placedTowardsTop && placedTowardsBottom)
                {
                    isPlaced = true;
                }
                else if (placedTowardsTop && !placedTowardsBottom)
                {
                    placedTowardsTop = AskSpaceToPreviusLabel(this, verticalOffset / 2, noOfIteration);
                    isPlaced         = placedTowardsTop;
                }
                else if (!placedTowardsTop && placedTowardsBottom)
                {
                    placedTowardsBottom = AskSpaceToNextLabel(this, verticalOffset / 2, noOfIteration);
                    isPlaced            = placedTowardsTop;
                }
                else
                {
                    isPlaced = false;
                }
            }
            else
            {
                OverlapTypes overlapTypesTop = CheckOverLap(SweepDirection.Counterclockwise, out verticalOffset, out horizontalOffset);

                if (overlapTypesTop == OverlapTypes.Both)
                {
                    placedTowardsBottom = AskSpaceToNextLabel(this, verticalOffset / 2, noOfIteration);
                    placedTowardsTop    = AskSpaceToPreviusLabel(this, verticalOffset / 2, noOfIteration);

                    if (placedTowardsTop && placedTowardsBottom)
                    {
                        isPlaced = true;
                    }
                    else if (placedTowardsTop && !placedTowardsBottom)
                    {
                        placedTowardsTop = AskSpaceToNextLabel(this, verticalOffset / 2, noOfIteration);
                        isPlaced         = placedTowardsTop;
                    }
                    else if (!placedTowardsTop && placedTowardsBottom)
                    {
                        placedTowardsBottom = AskSpaceToPreviusLabel(this, verticalOffset / 2, noOfIteration);
                        isPlaced            = placedTowardsBottom;
                    }
                    else
                    {
                        isPlaced = false;
                    }
                }
                else
                {
                    isPlaced = true;
                }
            }

            if (isPlaced)
            {
                //ColorIt(Colors.Green);
            }
            else
            {
                //ColorIt(Colors.Red);
                if (skip)
                {
                    SkipLabel();
                }
            }
        }