private void btnCalculate_Click(object sender, EventArgs e) { /* *********************************** * CAPCALC ALGORITHYM achieved by Rectgangels * to hold the cargo size and positions in its container * * Not: * the space property of CargoInfo class uses System.Drawing.Rectangel item * to hold the position and floor area of cargo. Pls, take attention while you * assigning new values as; * * Cargo.Space = new Rectangle(x,y, m,n); * x => Left of Cargo in Container space * y => Top of Cargo in Container space * m => is the Long (x dimention of cargo floor area while you look from top) * n => is the Width (y dimention of cargo floor area while you look from top) * * *********************************** */ var secim = (ContainerInfo)cmbConSelector.SelectedItem; ContainerMatrix Ambar = new ContainerMatrix(secim); CargoInfo[] Kargolar; // Create the cargo list and sort them. if (ds.Tables[0].Rows.Count > 0) { Kargolar = new CargoInfo[ds.Tables[0].Rows.Count]; // size the cargo list // Read the cargoes from data table for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { var crg = new CargoInfo(); crg.Name = ds.Tables[0].Rows[i].Field <string>("Name"); crg.Long = ds.Tables[0].Rows[i].Field <double>("Long"); crg.Width = ds.Tables[0].Rows[i].Field <double>("Width"); crg.Height = ds.Tables[0].Rows[i].Field <double>("Height"); crg.Weight = ds.Tables[0].Rows[i].Field <double>("Weight"); crg.Level = ds.Tables[0].Rows[i].Field <int>("Level"); Kargolar[i] = crg; } // Now Sort a copy of them based on CBM object[] sort = new object[Kargolar.Length]; for (int i = 0; i < sort.Length; i++) { sort[i] = Kargolar[i]; } Helper.QuickSort(ref sort, "CBM"); // Now check the Gravity Offset to start writing in container // (do that later, lets say "Top Left" for now) for (int i = sort.Length - 1; i >= 0; i--) // Big to Small { CargoInfo crg = (CargoInfo)sort[i]; if (Ambar.StartIndexes.Count > 0) { int indx = 0; do { bool chk = Ambar.TestCargo(crg, Ambar.StartIndexes[indx]); if (chk) // cargo is availible to write in { // lets add it to matrix Ambar.AddCargo(crg, Ambar.StartIndexes[indx]); break; } else { // try to rotate or skip to the next index indx++; // skip next index } } while (indx < Ambar.StartIndexes.Count); // so far we just write the posible cargoes, until now. } } // Try to take a snapshot for debug purpose DebuggerDisplay(Ambar); //shows loaded areas on selected cargo container matrix } }
private void btnCalculate_Click(object sender, EventArgs e) { /* *********************************** * CAPCALC ALGORITHYM achieved by Rectgangels * to hold the cargo size and positions in its container * * Not: * the space property of CargoInfo class uses System.Drawing.Rectangel item * to hold the position and floor area of cargo. Pls, take attention while you * assigning new values as; * * Cargo.Space = new Rectangle(x,y, m,n); * x => Left of Cargo in Container space * y => Top of Cargo in Container space * m => is the Long (x dimention of cargo floor area while you look from top) * n => is the Width (y dimention of cargo floor area while you look from top) * * *********************************** */ var secim = (ContainerInfo)cmbConSelector.SelectedItem; ContainerMatrix Ambar = new ContainerMatrix(secim); CargoInfo[] Kargolar; // Create the cargo list and sort them. if (ds.Tables[0].Rows.Count > 0) { Kargolar = new CargoInfo[ds.Tables[0].Rows.Count]; // size the cargo list // Read the cargoes from data table for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { var crg = new CargoInfo(); crg.Name = ds.Tables[0].Rows[i].Field<string>("Name"); crg.Long = ds.Tables[0].Rows[i].Field<double>("Long"); crg.Width = ds.Tables[0].Rows[i].Field<double>("Width"); crg.Height = ds.Tables[0].Rows[i].Field<double>("Height"); crg.Weight = ds.Tables[0].Rows[i].Field<double>("Weight"); crg.Level = ds.Tables[0].Rows[i].Field<int>("Level"); Kargolar[i] = crg; } // Now Sort a copy of them based on CBM object[] sort = new object[Kargolar.Length]; for (int i = 0; i < sort.Length; i++) { sort[i] = Kargolar[i]; } Helper.QuickSort(ref sort, "CBM"); // Now check the Gravity Offset to start writing in container // (do that later, lets say "Top Left" for now) for (int i = sort.Length -1 ; i >= 0; i--) // Big to Small { CargoInfo crg = (CargoInfo)sort[i]; if (Ambar.StartIndexes.Count > 0) { int indx = 0; do { bool chk = Ambar.TestCargo(crg, Ambar.StartIndexes[indx]); if (chk) // cargo is availible to write in { // lets add it to matrix Ambar.AddCargo(crg, Ambar.StartIndexes[indx]); break; } else { // try to rotate or skip to the next index indx++;// skip next index } } while (indx < Ambar.StartIndexes.Count); // so far we just write the posible cargoes, until now. } } // Try to take a snapshot for debug purpose DebuggerDisplay(Ambar); //shows loaded areas on selected cargo container matrix } }