public Point3D CalculateMassCenterRow(RowBlock rBlock) { double nLength = 0; double nWidth = 0; double nHeight = 0; var massCenterPoint = new Point3D(0, 0, 0); if (rBlock.Mass == 0) { return massCenterPoint; } foreach (var v in rBlock.Blocks) { foreach (var c in v.Blocks) { nLength = nLength + c.Mass*(c.FirstPoint.Y + c.Length/2); nWidth = nWidth + c.Mass*(c.FirstPoint.X + c.Width/2); nHeight = nHeight + c.Mass*(c.FirstPoint.Z + c.Height/2); } } massCenterPoint.Y = nLength/rBlock.Mass; massCenterPoint.X = nWidth/rBlock.Mass; massCenterPoint.Z = nHeight/rBlock.Mass; return massCenterPoint; }
private List<Container> UnpackRow(List<Container> tempList, RowBlock rBlock) { foreach (var vBlock in rBlock.Blocks) { tempList = UnpackVerticalBlock(tempList, vBlock); } return tempList; }
private void AddRow(Table tab, RowBlock rowBlock, Vehicle currentVehicle, int i, int i2) { //MessageBox.Show("Количество вертикальных блоков " + rowBlock.Blocks.Count.ToString()); var b = new BlockUIContainer(); var canvas = new Canvas(); canvas.Width = currentVehicle.Width / scale; canvas.Height = currentVehicle.Height / scale + 20; //Рисуем рамку вокруг canvas var r = new Rectangle(); r.Width = currentVehicle.Width / scale; r.Height = currentVehicle.Height / scale; Brush brush = new SolidColorBrush(); brush = Brushes.White; r.Stroke = new SolidColorBrush(Colors.Red); r.Fill = brush; Canvas.SetLeft(r, 0); Canvas.SetTop(r, 20); canvas.Children.Add(r); //пишем заголовок tab.RowGroups[0].Rows.Add(new TableRow()); var currentRow = tab.RowGroups[0].Rows[i2 - 1]; currentRow.Background = Brushes.White; currentRow.FontSize = 18; currentRow.FontWeight = FontWeights.Normal; currentRow.Cells.Add( new TableCell( new Paragraph( new Run("Шаг " + i + ": " + rowBlock.Name + "контейнеров: " + rowBlock.Count + ", вес: " + rowBlock.Mass + ", плотность: " + rowBlock.Fullness + "(" + rowBlock.FullnessWidth + ")")))); currentRow.Cells[0].ColumnSpan = 2; //пишем схему ряда var t2 = new TextBlock(); t2.FontSize = 14; var t = new TextBlock(); //рисуем контейнеры foreach (var v in rowBlock.Blocks) { //MessageBox.Show("Количество ящиков в вертикальном блоке " + v.Blocks.Count.ToString()); foreach (Object p in v.Blocks) { var c = (Container)p; r = new Rectangle(); r.Width = c.Length / scale; r.Height = c.Height / scale; brush = new SolidColorBrush(); brush = Brushes.White; r.Stroke = new SolidColorBrush(Colors.Black); r.Fill = brush; Canvas.SetLeft(r, (c.FirstPoint.Y - currentVehicle.FirstPoint.Y) / scale); Canvas.SetTop(r, canvas.Height - c.Height / scale - c.FirstPoint.Z / scale); canvas.Children.Add(r); t = new TextBlock(); t.Text = c.Name; if (c.Kind == "VerticalPallet") { t.FontSize = 14; } else { t.FontSize = 20; } Canvas.SetLeft(t, (c.FirstPoint.Y - currentVehicle.FirstPoint.Y) / scale + 2); var delta = 2; Canvas.SetTop(t, canvas.Height - c.Height / scale - c.FirstPoint.Z / scale + 2); canvas.Children.Add(t); t = new TextBlock(); t.Text = "Габ: " + c.Vgh; t.FontSize = 14; Canvas.SetLeft(t, (c.FirstPoint.Y - currentVehicle.FirstPoint.Y) / scale + 2); delta = delta + 22; Canvas.SetTop(t, canvas.Height - c.Height / scale - c.FirstPoint.Z / scale + delta); canvas.Children.Add(t); t = new TextBlock(); t.Text = "Вес:" + c.Mass; t.FontSize = 14; Canvas.SetLeft(t, (c.FirstPoint.Y - currentVehicle.FirstPoint.Y) / scale + 2); delta = delta + 22; Canvas.SetTop(t, canvas.Height - c.Height / scale - c.FirstPoint.Z / scale + delta); canvas.Children.Add(t); if (p is VerticalBlock) { t2.Text = t2.Text + "\n" + c.Name + "\n"; t2.Text = t2.Text + " Габариты:" + c.Vgh + "\n"; t2.Text = t2.Text + " Вес:" + c.Mass + "\n"; var vB = (VerticalBlock)p; foreach (var cont in vB.Blocks) { t2.Text = t2.Text + " * " + cont.Name + " (" + cont.ContainerType + ")" + " \n"; t = new TextBlock(); t.Text = cont.Name; t.FontSize = 16; Canvas.SetLeft(t, (c.FirstPoint.Y - currentVehicle.FirstPoint.Y) / scale + 2); delta = delta + 22; Canvas.SetTop(t, canvas.Height - c.Height / scale - c.FirstPoint.Z / scale + delta); canvas.Children.Add(t); } } else if (p is HorizontalBlock) { t2.Text = t2.Text + "\n" + c.Name + " \n"; t2.Text = t2.Text + " Габариты:" + c.Vgh + "\n"; t2.Text = t2.Text + " Вес:" + c.Mass + "\n"; var vB = (HorizontalBlock)p; foreach (var cont in vB.Blocks) { t2.Text = t2.Text + " * " + cont.Name + " (" + cont.ContainerType + ")" + " \n"; t = new TextBlock(); t.Text = cont.Name; t.FontSize = 16; Canvas.SetLeft(t, (c.FirstPoint.Y - currentVehicle.FirstPoint.Y) / scale + 2); delta = delta + 22; Canvas.SetTop(t, canvas.Height - c.Height / scale - c.FirstPoint.Z / scale + delta); canvas.Children.Add(t); } } else { t2.Text = t2.Text + "\n" + c.Name + " (" + c.ContainerType + ")" + "\n"; t2.Text = t2.Text + " Габариты:" + c.Vgh + "\n"; t2.Text = t2.Text + " Вес:" + c.Mass + "\n"; } } } b.Child = canvas; tab.RowGroups[0].Rows.Add(new TableRow()); currentRow = tab.RowGroups[0].Rows[i2]; currentRow.Background = Brushes.White; currentRow.FontSize = 14; currentRow.FontWeight = FontWeights.Normal; currentRow.Cells.Add(new TableCell(new Paragraph(new Run(t2.Text)))); currentRow.Cells[0].ColumnSpan = 1; currentRow.Cells.Add(new TableCell(b)); currentRow.Cells[1].ColumnSpan = 1; }
private void AddCanvas2(FlowDocument doc, RowBlock rowBlock, int cWidth, int cHeight) { var b = new BlockUIContainer(); var canvas = new Canvas(); canvas.Width = cWidth / scale; canvas.Height = cHeight / scale + 20; //Рисуем рамку вокруг canvas var r = new Rectangle(); r.Width = cWidth / scale; r.Height = cHeight / scale; Brush brush = new SolidColorBrush(); brush = Brushes.White; r.Stroke = new SolidColorBrush(Colors.Red); r.Fill = brush; Canvas.SetLeft(r, 0); Canvas.SetTop(r, 20); canvas.Children.Add(r); //пишем заголовок var t = new TextBlock(); t.Text = rowBlock.Name + "Количество контейнеров: " + rowBlock.Count + " общий вес: " + rowBlock.Mass + "; плотность загрузки - " + rowBlock.Fullness + "(" + rowBlock.FullnessWidth + ")"; t.FontSize = 14; Canvas.SetLeft(t, 20); Canvas.SetTop(t, 2); canvas.Children.Add(t); //рисуем контейнеры foreach (var v in rowBlock.Blocks) { foreach (Object p in v.Blocks) { var c = (Container)p; r = new Rectangle(); r.Width = c.Length / scale; r.Height = c.Height / scale; brush = new SolidColorBrush(); brush = Brushes.White; r.Stroke = new SolidColorBrush(Colors.Black); r.Fill = brush; Canvas.SetLeft(r, c.FirstPoint.Y / scale); Canvas.SetTop(r, canvas.Height - c.Height / scale - c.FirstPoint.Z / scale); canvas.Children.Add(r); t = new TextBlock(); t.Text = c.Name; t.FontSize = 20; Canvas.SetLeft(t, c.FirstPoint.Y / scale + 2); var delta = 2; Canvas.SetTop(t, canvas.Height - c.Height / scale - c.FirstPoint.Z / scale + 2); canvas.Children.Add(t); t = new TextBlock(); t.Text = "Габ: " + c.Length + "x" + c.Width + "x" + c.Height; t.FontSize = 18; Canvas.SetLeft(t, c.FirstPoint.Y / scale + 2); delta = delta + 22; Canvas.SetTop(t, canvas.Height - c.Height / scale - c.FirstPoint.Z / scale + delta); canvas.Children.Add(t); t = new TextBlock(); t.Text = "Вес:" + c.Mass; t.FontSize = 18; Canvas.SetLeft(t, c.FirstPoint.Y / scale + 2); delta = delta + 22; Canvas.SetTop(t, canvas.Height - c.Height / scale - c.FirstPoint.Z / scale + delta); canvas.Children.Add(t); if (p is VerticalBlock) { var vB = (VerticalBlock)p; foreach (var cont in vB.Blocks) { t = new TextBlock(); t.Text = cont.Name; t.FontSize = 16; Canvas.SetLeft(t, c.FirstPoint.Y / scale + 2); delta = delta + 22; Canvas.SetTop(t, canvas.Height - c.Height / scale - c.FirstPoint.Z / scale + delta); canvas.Children.Add(t); } } else if (p is HorizontalBlock) { var vB = (HorizontalBlock)p; foreach (var cont in vB.Blocks) { t = new TextBlock(); t.Text = cont.Name; t.FontSize = 16; Canvas.SetLeft(t, c.FirstPoint.Y / scale + 2); delta = delta + 22; Canvas.SetTop(t, canvas.Height - c.Height / scale - c.FirstPoint.Z / scale + delta); canvas.Children.Add(t); } } } } b.Child = canvas; doc.Blocks.Add(b); }
private List<VerticalBlock> AddExtraBlock(RowBlock rBlock, List<VerticalBlock> vBlocks) { int length = rBlock.MaxLength - rBlock.Length; List<VerticalBlock> extraBlocks = vBlocks.Where( v => (v.Length <= length & v.Width <= rBlock.Width) | (v.Length <= rBlock.Width & v.Width <= length)) .OrderByDescending(v => v.RealVolume) .ToList(); List<VerticalBlock> tempBlocks = vBlocks.Where( v => ((v.Length <= length & v.Width <= rBlock.Width) | (v.Length <= rBlock.Width & v.Width <= length)) == false).ToList(); if (extraBlocks.Count() + tempBlocks.Count() != vBlocks.Count()) { MessageBox.Show("Ошибка при фильтрации блоков. AddExtraBlock"); } if (extraBlocks.Any()) { VerticalBlock extraBlock = extraBlocks[0]; //MessageBox.Show("Подобрано дополнительных блоков: " + extraBlocks.Count().ToString()); if (extraBlock.Length > (rBlock.MaxLength - rBlock.Length) | extraBlock.Width > rBlock.Width) { extraBlock.RotateH(); } rBlock.Add(extraBlock, vehicle.Width); tempBlocks.AddRange(extraBlocks.Where(v => v != extraBlock)); } return tempBlocks; }
private void AddRowToVehicle(RowBlock rBlock) { vehicle.Blocks.Add(rBlock); vehicle.MaxLength = vehicle.MaxLength - rBlock.Width; vehicle.Mass = vehicle.Mass + rBlock.Mass; vehicle.Count = vehicle.Count + rBlock.Count; }
private void AddCabinToRow(Container c) { VerticalBlock vBlock = new VerticalBlock(); if (vBlock.Add(c, 10000) == false) { MessageBox.Show("Ошибка добавления кабины в вертикальный блок.Сообщите администратору"); return; } //добавляем вертикальный ряд в горизонтальный ряд RowBlock rBlock = new RowBlock(); rBlock.Add(vBlock, vehicle.MaxLength); if (vehicle.MaxLength >= rBlock.Width & vehicle.Tonnage >= rBlock.Mass + vehicle.Mass) { AddRowToVehicle(rBlock); } else { //помещаем кабину в список невместившихся контейнеров wasteList.Add(c); } }
private void CreateRows(List<VerticalBlock> vBlocks, int sameWidth, List<RowBlock> rBlocks) { List<VerticalBlock> sameBlock = vBlocks.Where(s => s.IsSuitableWidth(sameWidth)).OrderByDescending(s => s.Width).ToList(); while (sameBlock.Any()) { List<VerticalBlock> tempBlocks = new List<VerticalBlock>(); RowBlock rBlock = new RowBlock(); foreach (VerticalBlock s in sameBlock) { VerticalBlock tempS; if (s.Length <= sameWidth & s.Length > sameWidth - 100) //если нужно, то поворачиваем блок { tempS = s.Clone() as VerticalBlock; tempS.RotateH(); } else { tempS = s; } if (tempS.Length > vehicle.Width) { /*пропускаем блок т.к. он не подходит по ширине и длине*/ } else if (rBlock.Add(tempS, vehicle.Width) == false) { tempBlocks.Add(tempS); } } if (rBlock.Count > 0) { rBlocks.Add(rBlock); } sameBlock = tempBlocks.ToList(); } }
private List<Container> ProcessingChassis(List<Container> tempList, int maxTonnage) { List<Container> tempRama = tempList.Where(s => s.Length > 1500 & s.Width > 6000).OrderBy(s => s.Width).ToList(); tempList = tempList.Where(s => s.Length <= 1500 | s.Width <= 6000).ToList(); if (!tempRama.Any()) { return tempList; } HorizontalBlock hBlock = new HorizontalBlock(); hBlock.RowCount = 2; hBlock.Width = tempRama[0].Width + 800; hBlock.Length = 2400; //добавляем в подушку ящики размеров 1200х800х800 List<Container> temp500 = tempList.Where(s => s.Length == 1200 & s.Width == 800 & s.Height == 800).ToList(); if (temp500.Count() >= 6) { tempList = tempList.Where(s => s.Length != 1200 | s.Width != 800 | s.Height != 800).ToList(); foreach (Container c in temp500) { if (hBlock.Add(c)) { /*продолжаем*/ } else { tempList.Add(c); } } } //добавляем в подушку ящики размеров 1100х800х720 temp500 = tempList.Where(s => s.Length == 1100 & s.Width == 800 & s.Height == 720).ToList(); if (NotEmpty() | temp500.Count() >= 6) { tempList = tempList.Where(s => s.Length != 1100 | s.Width != 800 | s.Height != 720).ToList(); foreach (Container c in temp500) { if (!hBlock.Add(c)) { tempList.Add(c); } } } VerticalBlock vBlock = new VerticalBlock(); if (hBlock.NotEmpty() & (vehicle.Mass + hBlock.Mass) <= maxTonnage) { vBlock.Add(hBlock, vehicle.Height - 250); } else { hBlock.ToContainerList(tempList); } foreach (Container r in tempRama) { if ((vehicle.Mass + r.Mass) <= maxTonnage) { if (vBlock.Add(r, vehicle.Height - 350) == false) { MessageBox.Show("не удалось добавить раму в вертикальный блок.Сообщите администратору"); tempList.Add(r); } } } RowBlock rBlock = new RowBlock(); rBlock.Add(vBlock, vehicle.Width); AddRowToVehicle(rBlock); return tempList; }