/// <summary> /// Draw layers /// Images are used during report generation /// </summary> public void DrawLayers(Graphics3D graphics, bool showPallet, int layerIndex) { if (null == _solution) { throw new Exception("No solution defined!"); } if (!graphics.ShowBoxIds) // -> if box ids are drawn, we do not draw pallet { // draw pallet Pallet pallet = new Pallet(_analysis.PalletProperties); pallet.Draw(graphics, Transform3D.Identity); } // draw solution uint pickId = 0; CylinderLayer cylLayer = _solution.CylinderLayerFirst; if (cylLayer != null) { foreach (Vector3D pos in cylLayer) { graphics.AddCylinder(new Cylinder(pickId++, _analysis.CylinderProperties, new CylPosition(pos, HalfAxis.HAxis.AXIS_Z_P))); } } // flush graphics.Flush(); }
/// <summary> /// Use this method when drawing a solution that belongs an analysis /// </summary> public void Draw(Graphics3D graphics) { if (null == _solution) { return; } // initialize Graphics3D object if (!graphics.ShowBoxIds) { // draw pallet Pallet pallet = new Pallet(_analysis.PalletProperties); pallet.Draw(graphics, Transform3D.Identity); } // draw solution uint pickId = 0; foreach (ILayer layer in _solution) { CylinderLayer cylLayer = layer as CylinderLayer; if (null != cylLayer) { foreach (Vector3D pos in cylLayer) { graphics.AddCylinder( new Cylinder(pickId++, _analysis.CylinderProperties, new CylPosition(pos, HalfAxis.HAxis.AXIS_Z_P)) ); } } InterlayerPos interlayerPos = layer as InterlayerPos; if (null != interlayerPos) { Box box = new Box(pickId++, _analysis.InterlayerProperties); // set position box.Position = new Vector3D( 0.5 * (_analysis.PalletProperties.Length - _analysis.InterlayerProperties.Length) , 0.5 * (_analysis.PalletProperties.Width - _analysis.InterlayerProperties.Width) , interlayerPos.ZLow); // draw graphics.AddBox(box); } } if (_showDimensions) { if (_showDimensions) { graphics.AddDimensions( new DimensionCube(BoundingBoxDim(Properties.Settings.Default.DimCasePalletSol1) , Color.Black, false)); graphics.AddDimensions( new DimensionCube(BoundingBoxDim(Properties.Settings.Default.DimCasePalletSol2) , Color.Red, true)); } } }
public void Draw(Graphics2D graphics) { if (null == _solution || _solution.Count == 0) { return; } bool showAxis = false; // initialize Graphics2D object graphics.NumberOfViews = 1; graphics.SetViewport(0.0f, 0.0f, (float)_solution.PalletLength, (float)_solution.PalletWidth); CylinderLayer cylLayer = _solution.CylinderLayerFirst; if (cylLayer != null) { graphics.SetCurrentView(0); graphics.DrawRectangle(Vector2D.Zero, new Vector2D(_analysis.PalletProperties.Length, _analysis.PalletProperties.Width), Color.Black); uint pickId = 0; foreach (Vector3D pos in cylLayer) { graphics.DrawCylinder( new Cylinder(pickId++, _analysis.CylinderProperties, new CylPosition(pos, HalfAxis.HAxis.AXIS_Z_P)) ); } // draw axes if (showAxis) { // draw axis X graphics.DrawLine(Vector2D.Zero, new Vector2D(_analysis.PalletProperties.Length, 0.0), Color.Red); // draw axis Y graphics.DrawLine(Vector2D.Zero, new Vector2D(0.0, _analysis.PalletProperties.Width), Color.Green); } } }
private List <CylinderPalletSolution> GenerateSolutions() { List <CylinderPalletSolution> solutions = new List <CylinderPalletSolution>(); // loop through all patterns foreach (CylinderLayerPattern pattern in _patterns) { for (int iDir = 0; iDir < (pattern.CanBeSwapped ? 2 : 1); ++iDir) { // alternate pallet direction LayerCyl layer = new LayerCyl(_cylProperties, _palletProperties, _constraintSet); string title = string.Format("{0}-{1}", pattern.Name, iDir); CylinderPalletSolution sol = new CylinderPalletSolution(null, title, true); double actualLength = 0.0, actualWidth = 0.0; pattern.Swapped = (iDir % 2 != 0); pattern.GetLayerDimensions(layer, out actualLength, out actualWidth); try { pattern.GenerateLayer(layer, actualLength, actualWidth); } catch (NotImplementedException ex) { _log.Debug(ex.Message); continue; } catch (Exception ex) { _log.Error(ex.Message); continue; } // stop double zLayer = _palletProperties.Height; bool maxWeightReached = _constraintSet.UseMaximumPalletWeight && (_palletProperties.Weight + _cylProperties.Weight > _constraintSet.MaximumPalletWeight); bool maxHeightReached = _constraintSet.UseMaximumPalletHeight && (zLayer + _cylProperties.Height > _constraintSet.MaximumPalletHeight); bool maxNumberReached = false; int iCount = 0; // insert anti-slip interlayer if (_constraintSet.HasInterlayerAntiSlip) { sol.CreateNewInterlayer(zLayer, 1); zLayer += _interlayerPropertiesAntiSlip.Thickness; } while (!maxWeightReached && !maxHeightReached && !maxNumberReached) { // interlayer if (_constraintSet.HasInterlayer && (sol.Count > 0)) { sol.CreateNewInterlayer(zLayer, 0); zLayer += _interlayerProperties.Thickness; } // select current layer type CylinderLayer cylLayer = sol.CreateNewLayer(zLayer); foreach (Vector2D layerPos in layer) { ++iCount; maxWeightReached = _constraintSet.UseMaximumPalletWeight && ((iCount * _cylProperties.Weight + _palletProperties.Weight) > _constraintSet.MaximumPalletWeight); maxNumberReached = _constraintSet.UseMaximumNumberOfItems && (iCount > _constraintSet.MaximumNumberOfItems); if (!maxWeightReached && !maxNumberReached) { cylLayer.Add( new Vector3D( layerPos.X - 0.5 * _constraintSet.OverhangX, layerPos.Y - 0.5 * _constraintSet.OverhangY, zLayer)); } } // increment zLayer zLayer += _cylProperties.Height; maxHeightReached = _constraintSet.UseMaximumPalletHeight && (zLayer + _cylProperties.Height > _constraintSet.MaximumPalletHeight); } // limit reached if (maxWeightReached) { sol.LimitReached = Limit.LIMIT_MAXWEIGHTREACHED; } else if (maxNumberReached) { sol.LimitReached = Limit.LIMIT_MAXNUMBERREACHED; } else if (maxHeightReached) { sol.LimitReached = Limit.LIMIT_MAXHEIGHTREACHED; } else { sol.LimitReached = Limit.LIMIT_UNKNOWN; } solutions.Add(sol); } } // sort solutions solutions.Sort(); return(solutions); }
private ILayer LoadLayer(XmlElement eltLayer) { ILayer layer = null; double zLow = UnitsManager.ConvertLengthFrom( Convert.ToDouble(eltLayer.Attributes["ZLow"].Value, System.Globalization.CultureInfo.InvariantCulture) , _unitSystem); double maxSpace = 0.0; if (eltLayer.HasAttribute("MaximumSpace")) maxSpace = UnitsManager.ConvertLengthFrom( Convert.ToDouble(eltLayer.Attributes["MaximumSpace"].Value, System.Globalization.CultureInfo.InvariantCulture) , _unitSystem); string patternName = string.Empty; if (eltLayer.HasAttribute("PatternName")) patternName = eltLayer.Attributes["PatternName"].Value; if (string.Equals(eltLayer.Name, "BoxLayer", StringComparison.CurrentCultureIgnoreCase)) { BoxLayer boxLayer = new BoxLayer(UnitsManager.ConvertLengthFrom(zLow, _unitSystem), patternName); boxLayer.MaximumSpace = maxSpace; foreach (XmlNode nodeBoxPosition in eltLayer.ChildNodes) { XmlElement eltBoxPosition = nodeBoxPosition as XmlElement; string sPosition = eltBoxPosition.Attributes["Position"].Value; string sAxisLength = eltBoxPosition.Attributes["AxisLength"].Value; string sAxisWidth = eltBoxPosition.Attributes["AxisWidth"].Value; try { boxLayer.AddPosition(UnitsManager.ConvertLengthFrom(Vector3D.Parse(sPosition), _unitSystem), HalfAxis.Parse(sAxisLength), HalfAxis.Parse(sAxisWidth)); } catch (Exception /*ex*/) { _log.Error(string.Format("Exception thrown: Position = {0} | AxisLength = {1} | AxisWidth = {2}", sPosition, sAxisLength, sAxisWidth )); } } layer = boxLayer; } else if (string.Equals(eltLayer.Name, "CylLayer", StringComparison.CurrentCultureIgnoreCase)) { CylinderLayer cylLayer = new CylinderLayer(UnitsManager.ConvertLengthFrom(zLow, _unitSystem)); foreach (XmlNode nodePosition in eltLayer.ChildNodes) { XmlElement eltBoxPosition = nodePosition as XmlElement; string sPosition = eltBoxPosition.Attributes["Position"].Value; cylLayer.Add(UnitsManager.ConvertLengthFrom(Vector3D.Parse(sPosition), _unitSystem)); layer = cylLayer; } } else if (string.Equals(eltLayer.Name, "InterLayer", StringComparison.CurrentCultureIgnoreCase)) { int typeId = 0; if (eltLayer.HasAttribute("TypeId")) typeId = Convert.ToInt32(eltLayer.Attributes["TypeId"].Value); layer = new InterlayerPos(UnitsManager.ConvertLengthFrom(zLow, _unitSystem), typeId); } return layer; }
public void Save(CylinderLayer cylLayer, XmlElement layersElt, XmlDocument xmlDoc) { // BoxLayer XmlElement cylLayerElt = xmlDoc.CreateElement("CylLayer"); layersElt.AppendChild(cylLayerElt); // ZLow XmlAttribute zlowAttribute = xmlDoc.CreateAttribute("ZLow"); zlowAttribute.Value = string.Format(System.Globalization.CultureInfo.InvariantCulture, "{0}", cylLayer.ZLow); cylLayerElt.Attributes.Append(zlowAttribute); foreach (Vector3D boxPosition in cylLayer) { // BoxPosition XmlElement cylPositionElt = xmlDoc.CreateElement("CylPosition"); cylLayerElt.AppendChild(cylPositionElt); // Position XmlAttribute positionAttribute = xmlDoc.CreateAttribute("Position"); positionAttribute.Value = boxPosition.ToString(); cylPositionElt.Attributes.Append(positionAttribute); } }