Exemplo n.º 1
0
        private BarrelLineList SortBarrels(BarrelLine barList)
        {
            List <Barrel> bars = barList.OrderByDescending(b => b.Volume).ToList();

            BarrelLineList barsPack = new BarrelLineList();

            while (bars.Count > 0)
            {
                Barrel     currbar  = null;
                BarrelLine barsLine = new BarrelLine();
                foreach (Barrel bar in bars)
                {
                    if ((currbar == null) ||//First barrel in line
                        (bar.Diameter < currbar.Diameter && bar.Height < currbar.Height) ||//fit vertically
                        (bar.Diagonal < currbar.Diameter && bar.Diameter < currbar.Height && canRotate.Checked))    //fit horizontally (with rotate)
                    {
                        currbar = bar;
                        barsLine.Add(currbar);
                    }
                }
                foreach (Barrel bar in barsLine)
                {
                    bars.Remove(bar);
                }
                barsPack.Add(barsLine);
            }
            return(barsPack);
        }
Exemplo n.º 2
0
        private void SortBtn_Click(object sender, EventArgs e)
        {
            BarrelLineList sortedBars = SortBarrels(BarrelList);

            double totalval = 0;

            SortResultBox.Clear();
            foreach (BarrelLine brl in sortedBars)
            {
                totalval += brl[0].Volume;
                foreach (Barrel br in brl)
                {
                    SortResultBox.AppendText(br.ID + " ");
                }
                SortResultBox.AppendText(Environment.NewLine);
            }
            TotalVolume.Text = Math.Round(totalval, 2).ToString();
        }