private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            for (int count = 1; count <= quantity; count++)
            {
                if (((height > heightMain) && (height > widthMain)) || ((width > heightMain) && (width > widthMain)))
                {
                    string large = height > width?height.ToString() : width.ToString();

                    MessageBox.Show(String.Format("One side of the rectangle == {0} is too large !", large));

                    this.heightField.Text   = "0";
                    this.widthField.Text    = "0";
                    this.quantityField.Text = "1";
                    break;
                }

                Surface rectangle = new Surface();
                rectangle.Height = height;
                rectangle.Width  = width;
                MyBoxes.Add(rectangle);
            }

            this.heightField.Text   = "0";
            this.widthField.Text    = "0";
            this.quantityField.Text = "1";
        }
Exemple #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            Surface surf = new Surface();

            surf.ContainerHeight = height;
            surf.ContainerWidth  = width;

            for (int i = 0; i < quantity; i++)
            {
                Rectangle f = new Rectangle(i + 1);                 // створюємо об’єкт типу Rectangle
                f.ShowDialog();
                dict.Add(i + 1, f.MyMass);
            }

            foreach (KeyValuePair <int, double[]> keyValue in dict)
            {
                if (((keyValue.Value[0] > surf.ContainerHeight) && (keyValue.Value[0] > surf.ContainerWidth)) || ((keyValue.Value[1] > surf.ContainerHeight) && (keyValue.Value[1] > surf.ContainerWidth)))
                {
                    MessageBox.Show(String.Format("One side of the rectangle № {0} is too large !", keyValue.Key.ToString()));
                    dict.Clear();
                    return;
                }
                areaOfPieces += keyValue.Value[2];
            }

            if (areaOfPieces > surf.MainSquare)
            {
                MessageBox.Show("The area of the pieces is larger than the surface area !");
                dict.Clear();
                return;
            }

            for (int i = 0; i < Math.Pow(2, quantity); i++)
            {
                MyBoxes.Clear();

                string str = Convert.ToString(i, 2).PadLeft(quantity, '0');

                for (int j = 0; j < quantity; j++)
                {
                    MyBoxes.Add(new Surface {
                        Height = dict[j + 1][0], Width = dict[j + 1][1]
                    });

                    if (str[j] == '1')
                    {
                        double width = MyBoxes[j].Width;
                        MyBoxes[j].Width  = MyBoxes[j].Height;
                        MyBoxes[j].Height = width;
                    }
                }

                packer     = new Packer(MyBoxes, surf.ContainerHeight, surf.ContainerWidth);
                resultStr += packer.TextResult;
            }
            Result result = new Result(resultStr);

            result.Show();
        }
Exemple #3
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            Surface surf = new Surface();

            surf.ContainerHeight = heightMain;
            surf.ContainerWidth  = widthMain;

            foreach (var box in MyBoxes)
            {
                sumSqr += (box.Width * box.Height);
            }

            if (sumSqr > surf.MainSquare)
            {
                MessageBox.Show("The area of the pieces is larger than the surface area !");
                MyBoxes.Clear();

                this.mainHeight.Text = "0";
                this.mainWidth.Text  = "0";

                return;
            }

            caunter = MyBoxes.Count();

            for (int i = 0; i < Math.Pow(2, caunter); i++)
            {
                Boxes.Clear();
                string str = Convert.ToString(i, 2).PadLeft(caunter, '0');

                for (int j = 0; j < caunter; j++)
                {
                    Boxes.Add(new Surface {
                        Height = MyBoxes[j].Height, Width = MyBoxes[j].Width
                    });

                    if (str[j] == '1')
                    {
                        double width = Boxes[j].Width;
                        Boxes[j].Width  = Boxes[j].Height;
                        Boxes[j].Height = width;
                    }
                }

                packer = new Packer(Boxes, surf.ContainerHeight, surf.ContainerWidth);

                if (packer.ResBoxes.Count() == caunter)
                {
                    NavigationWindow win = new NavigationWindow();
                    win.Content = new PageResult(surf.ContainerWidth, surf.ContainerHeight, packer.ResBoxes);
                    win.Show();
                }
            }
        }