Example #1
0
        /// <summary>
        /// Gets the scale which should be used to display the walls.
        /// </summary>
        /// <param name="width">The width of box.</param>
        /// <param name="length">The lenght of box.</param>
        /// <param name="height">The height of box.</param>
        /// <param name="coverHeight">Height of the cover (if cover used &gt; 0; ohterwise 0).</param>
        /// <param name="boxType">Type of the box.</param>
        /// <param name="tableWidth">Size of the table where box will be shown.</param>
        /// <param name="tableHeight">Height of the table.</param>
        /// <returns>
        /// Scale calculated.
        /// </returns>
        /// <remarks>
        /// To calculte is used <see cref="EdgeGap"/>, <see cref="WallGap"/> and <see cref="CoverGap"/>.
        /// </remarks>
        private double GetScale(int width, int length, int height, int coverHeight, BoxType.BoxTypeEnum boxType, int tableWidth = 550, int tableHeight = 550)
        {
            //scale which will be return
              double scale = 1;

              //gaps which apear on length
              int gapsLength = 2 * EdgeGap + 2 * WallGap;
              //gaps which apear on width
              int gapsWidth = 2 * WallGap + 2 * EdgeGap;
              //length of expanded box (only box)
              int boxExpandedLength = 2 * height + length;
              //width of expanded box (only box)
              int boxExpandedWidth = 2 * height + width;

              if (boxType == BoxCreator.BoxType.BoxTypeEnum.Close)
              {
            gapsWidth = 3 * WallGap + 2 * EdgeGap;
            boxExpandedWidth = 2 * height + 2 * width;
              }
              if (boxType == BoxCreator.BoxType.BoxTypeEnum.WithCover)
              {
            boxExpandedWidth = 2 * height + 2 * width + 2 * coverHeight;
            gapsWidth = 4 * WallGap + 2 * EdgeGap + CoverGap;
              }
              //scale should be used only for box not for gap!!!
              if (gapsLength + boxExpandedLength > gapsWidth + boxExpandedWidth)
              {
            if (gapsLength + boxExpandedLength > tableWidth)
            {
              scale = (double)(boxExpandedLength) / (tableWidth - gapsLength);
            }
            else
            {
              scale = (double)(tableWidth - gapsLength) / (boxExpandedLength);
            }
              }
              else
              {
            if (gapsWidth + boxExpandedWidth > tableWidth - gapsWidth)
            {
              scale = (double)(boxExpandedWidth) / (tableWidth - gapsWidth);
            }
            else
            {
              scale = (double)(tableWidth - gapsWidth) / (boxExpandedWidth);
            }
              }
              return scale;
        }
Example #2
0
        /// <summary>
        /// Rebuilds the specified main canvas.
        /// </summary>
        /// <param name="canvasToDisplayBox">The canvas on which walls of box will be displayed.</param>
        /// <param name="realWidth">Width of the real box.</param>
        /// <param name="realLength">Length of the real.</param>
        /// <param name="realHeight">Height of the real.</param>
        /// <param name="realCoverHeight">Height of the real cover.</param>
        /// <param name="boxType">Type of the box.</param>
        public void Rebuild(Canvas canvasToDisplayBox, int realWidth, int realLength, int realHeight, int realCoverHeight, BoxType.BoxTypeEnum boxType)
        {
            BoxCanvas = canvasToDisplayBox;
              BoxCanvas.Children.Clear();

              RealWidth = realWidth;
              RealLength = realLength;
              RealHeight = realHeight;
              RealCoverHeight = realCoverHeight;
              BoxType = boxType;

              Scale = GetScale(realWidth, realLength, realHeight, realCoverHeight, BoxType, MainCanvasHeight, MainCanvasWidth);

              UpWall = new Wall(GetSizeToDisplay(RealLength), GetSizeToDisplay(RealWidth), Colors.Yellow, WallType.WallTypeEnum.Up);
              BackWall = new Wall(GetSizeToDisplay(RealLength), GetSizeToDisplay(RealHeight), Colors.Fuchsia, WallType.WallTypeEnum.Back);
              BottomWall = new Wall(GetSizeToDisplay(RealLength), GetSizeToDisplay(RealWidth), Colors.Black, WallType.WallTypeEnum.Bottom);
              FrontWall = new Wall(GetSizeToDisplay(RealLength), GetSizeToDisplay(RealHeight), Colors.Green, WallType.WallTypeEnum.Front);
              LeftWall = new Wall(GetSizeToDisplay(RealHeight), GetSizeToDisplay(RealWidth), Colors.Lime, WallType.WallTypeEnum.Left);
              RightWall = new Wall(GetSizeToDisplay(RealHeight), GetSizeToDisplay(RealWidth), Colors.Maroon, WallType.WallTypeEnum.Right);

              CoverWall = new Wall(GetSizeToDisplay(RealLength), GetSizeToDisplay(RealWidth), Colors.Yellow, WallType.WallTypeEnum.Cover);
              BackCoverWall = new Wall(GetSizeToDisplay(RealLength), GetSizeToDisplay(RealCoverHeight), Colors.Teal, WallType.WallTypeEnum.BackCover);
              FrontCoverWall = new Wall(GetSizeToDisplay(RealLength), GetSizeToDisplay(RealCoverHeight), Colors.Teal, WallType.WallTypeEnum.FrontCover);
              LeftCoverWall = new Wall(GetSizeToDisplay(RealCoverHeight), GetSizeToDisplay(RealWidth), Colors.Teal, WallType.WallTypeEnum.LeftCover);
              RightCoverWall = new Wall(GetSizeToDisplay(RealCoverHeight), GetSizeToDisplay(RealWidth), Colors.Teal, WallType.WallTypeEnum.RightCover);

              //calculation for displaying on the center the canvas
              int lengthToDisplay = (int)(2 * EdgeGap + 2 * WallGap + GetSizeToDisplay(2 * RealHeight + RealLength));
              int widthToDisplay = (int)(2 * EdgeGap + 2 * WallGap + GetSizeToDisplay(2 * RealHeight + RealWidth));
              if (BoxType == BoxCreator.BoxType.BoxTypeEnum.Close)
              {
            lengthToDisplay = (int)(2 * EdgeGap + 2 * WallGap + GetSizeToDisplay(2 * RealHeight + RealLength));
            widthToDisplay = (int)(2 * EdgeGap + 3 * WallGap + GetSizeToDisplay(2 * RealHeight + 2 * RealWidth));
              }
              if (BoxType == BoxCreator.BoxType.BoxTypeEnum.WithCover)
              {
            lengthToDisplay = (int)(2 * EdgeGap + 2 * WallGap + GetSizeToDisplay(2 * RealHeight + RealLength));
            widthToDisplay = (int)(4 * WallGap + 2 * EdgeGap + CoverGap + GetSizeToDisplay(2 * RealHeight + 2 * RealWidth + 2 * RealCoverHeight));
              }

              LeftShift = (MainCanvasWidth - lengthToDisplay) / 2;
              TopShift = (MainCanvasHeight - widthToDisplay) / 2;

              IsRebuild = true;
        }