Exemple #1
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();
                }
            }
        }