private void Initialize(CasePalletSolution sol) { switch (_axisOrtho) { case HalfAxis.HAxis.AXIS_Z_N: _boxLength = sol.PalletWidth; _boxWidth = sol.PalletLength; _boxHeight = sol.PalletHeight; _lengthAxis = HalfAxis.HAxis.AXIS_Y_P; _widthAxis = HalfAxis.HAxis.AXIS_X_N; _vecTransf = new Vector3D(_boxLength, 0.0, 0.0); break; case HalfAxis.HAxis.AXIS_Z_P: _boxLength = sol.PalletLength; _boxWidth = sol.PalletWidth; _boxHeight = sol.PalletHeight; _lengthAxis = HalfAxis.HAxis.AXIS_X_P; _widthAxis = HalfAxis.HAxis.AXIS_Y_P; _vecTransf = new Vector3D(0.0, 0.0, 0.0); break; default: break; } }
Layer2D BuildLayer(CasePalletSolution palletSolution, TruckProperties truckProperties, TruckConstraintSet constraintSet , HalfAxis.HAxis axisOrtho, bool swapped) { return(new Layer2D(new Vector3D(palletSolution.PalletLength, palletSolution.PalletWidth, palletSolution.PalletHeight) , new Vector2D(truckProperties.Length, truckProperties.Width) , axisOrtho, swapped)); }
Layer2D BuildLayer(CasePalletSolution palletSolution, TruckProperties truckProperties, TruckConstraintSet constraintSet ,HalfAxis.HAxis axisOrtho, bool swapped) { return new Layer2D(new Vector3D(palletSolution.PalletLength, palletSolution.PalletWidth, palletSolution.PalletHeight) , new Vector2D(truckProperties.Length, truckProperties.Width) , axisOrtho, swapped); }
public SelCasePalletSolution(Document document, CasePalletAnalysis analysis, CasePalletSolution sol) : base(document) { _analysis = analysis; _analysis.AddDependancy(this); _solution = sol; Name = sol.Title; }
private int GetCurrentSolutionIndex() { CasePalletSolution sol = GetCurrentSolution(); if (null == sol) { return(-1); } // find and return index of sol return(_analysis.Solutions.IndexOf(sol, 0)); }
static void Main(string[] args) { ILog log = LogManager.GetLogger(typeof(Program)); XmlConfigurator.Configure(); try { // check arguments if (args.Length != 1) { log.Info("No command argument. Exiting..."); return; } if (!File.Exists(args[0])) { log.Info(string.Format("File {0} could not be found. Exiting...", args[0])); return; } string filePath = args[0]; string outputPath = Path.ChangeExtension(filePath, "dae"); // load document Document doc = new Document(filePath, new DocumentListenerLog()); // get first analysis List <CasePalletAnalysis> analyses = doc.Analyses; if (analyses.Count == 0) { log.Info("Document has no analysis -> Exiting..."); return; } CasePalletAnalysis analysis = analyses[0]; if (analysis.Solutions.Count == 0) { log.Info("Analysis has no solution -> Exiting..."); return; } CasePalletSolution palletSolution = analysis.Solutions[0]; // export collada file ColladaExporter.Exporter exporter = new Exporter(palletSolution); exporter.Export(outputPath); log.Debug(string.Format("Successfully exported {0} ...", outputPath)); // browse file Exporter.BrowseWithGoogleChrome(outputPath); } catch (Exception ex) { log.Error(ex.ToString()); } }
/// <summary> /// Layer truck analysis constructor /// </summary> public Layer(CasePalletSolution sol, TruckProperties truckProperties, TruckConstraintSet constraintSet, int orientation) { switch (orientation) { case 0: _axisOrtho = HalfAxis.HAxis.AXIS_Z_P; break; case 1: _axisOrtho = HalfAxis.HAxis.AXIS_Z_N; break; default: _axisOrtho = HalfAxis.HAxis.AXIS_Z_P; break; } _palletLength = truckProperties.Length - 2.0 * constraintSet.MinDistancePalletTruckWall; _palletWidth = truckProperties.Width - 2.0 * constraintSet.MinDistancePalletTruckWall; Initialize(sol); }
private void onGridSolutionSelectionChanged(object sender, SourceGrid.RangeRegionChangedEventArgs e) { SourceGrid.RangeRegion region = gridSolutions.Selection.GetSelectionRegion(); int[] indexes = region.GetRowsIndex(); // no selection -> exit if (indexes.Length == 0) { return; } // get selected solution _sol = _analysis.Solutions[indexes[0] - 1]; // redraw graphCtrlCase.Invalidate(); graphCtrlPallet.Invalidate(); }
public void Draw(Graphics3DControl ctrl, Graphics3D graphics) { if (graphCtrlCaseSolution == ctrl) { // instantiate solution viewer BoxCasePalletSolutionViewer sv = new BoxCasePalletSolutionViewer(GetCurrentSolution()); sv.Draw(graphics); } else if (graphCtrlPalletSolution == ctrl) { CasePalletSolution sol = GetCurrentSolution().PalletSolutionDesc.LoadPalletSolution(); // instantial solution viewer CasePalletSolutionViewer svPallet = new CasePalletSolutionViewer(sol); svPallet.Draw(graphics); } }
/// <summary> /// overrides IItemListener.Update /// </summary> /// <param name="item"></param> public void Update(ItemBase item) { // update grid FillGrid(); // select first solution if (gridSolutions.RowsCount > 0) { gridSolutions.Selection.SelectRow(1, true); } if (_analysis.Solutions.Count > 0) { _sol = _analysis.Solutions[0]; } // draw Draw(); }
private void onGridSolutionSelectionChanged(object sender, SourceGrid.RangeRegionChangedEventArgs e) { SourceGrid.RangeRegion region = gridSolutions.Selection.GetSelectionRegion(); int[] indexes = region.GetRowsIndex(); // no selection -> exit if (indexes.Length == 0) { return; } // get selected solution _sol = _analysis.Solutions[indexes[0] - 1]; // update select/unselect button text UpdateSelectButtonText(); // redraw Draw(); }
/// <summary> /// overrides IItemListener.Update /// </summary> /// <param name="item"></param> public void Update(ItemBase item) { // update grid FillGrid(); // select first solution if (gridSolutions.RowsCount > 0) { gridSolutions.Selection.SelectRow(1, true); } if (_analysis.Solutions.Count > 0) { _sol = _analysis.Solutions[0]; } // draw graphCtrlCase.Invalidate(); graphCtrlPallet.Invalidate(); }
/// <summary> /// Use this method when solution does not refer an analysis (e.g. when displaying CaseOptimizer result) /// </summary> public static void Draw(Graphics3D graphics , CasePalletSolution solution , BoxProperties boxProperties, InterlayerProperties interlayerProperties, PalletProperties palletProperties) { // draw pallet Pallet pallet = new Pallet(palletProperties); pallet.Draw(graphics, Transform3D.Identity); // draw solution uint pickId = 0; foreach (ILayer layer in solution) { BoxLayer blayer = layer as BoxLayer; if (null != blayer) { foreach (BoxPosition bPosition in blayer) { graphics.AddBox(new Box(pickId++, boxProperties, bPosition)); } } InterlayerPos interlayerPos = layer as InterlayerPos; if (null != interlayerPos && null != interlayerProperties) { Box box = new Box(pickId++, interlayerProperties); // set position box.Position = new Vector3D( 0.5 * (palletProperties.Length - interlayerProperties.Length) , 0.5 * (palletProperties.Width - interlayerProperties.Width) , interlayerPos.ZLow); // draw graphics.AddBox(box); } } // always show dimensions BoxLayer bLayer = solution[solution.Count - 1] as BoxLayer; double palletHeight = solution[solution.Count - 1].ZLow + (null != bLayer ? bLayer.Thickness(boxProperties) : 0.0); // show dimensions graphics.AddDimensions(new DimensionCube(solution.BoundingBox, Color.Black, false)); graphics.AddDimensions(new DimensionCube(solution.LoadBoundingBox, Color.Red, true)); }
// checkbox event handler private void clickEvent_Click(object sender, EventArgs e) { SourceGrid.CellContext context = (SourceGrid.CellContext)sender; int iSel = context.Position.Row; // select row gridSolutions.Selection.SelectRow(iSel, true); // get selected solution CasePalletSolution sol = gridSolutions.Rows[iSel].Tag as CasePalletSolution; if (!_analysis.HasSolutionSelected(sol)) { _analysis.SelectSolutionBySol(sol); } else { _analysis.UnSelectSolutionBySol(sol); } }
/// <summary> /// Use this method when solution does not refer an analysis (e.g. when displaying CaseOptimizer result) /// </summary> public static void Draw(Graphics3D graphics , CasePalletSolution solution , BoxProperties boxProperties, InterlayerProperties interlayerProperties, PalletProperties palletProperties) { // draw pallet Pallet pallet = new Pallet(palletProperties); pallet.Draw(graphics, Transform3D.Identity); // draw solution uint pickId = 0; foreach (ILayer layer in solution) { BoxLayer blayer = layer as BoxLayer; if (null != blayer) { foreach (BoxPosition bPosition in blayer) graphics.AddBox(new Box(pickId++, boxProperties, bPosition)); } InterlayerPos interlayerPos = layer as InterlayerPos; if (null != interlayerPos && null != interlayerProperties) { Box box = new Box(pickId++, interlayerProperties); // set position box.Position = new Vector3D( 0.5 * (palletProperties.Length - interlayerProperties.Length) , 0.5 * (palletProperties.Width - interlayerProperties.Width) , interlayerPos.ZLow); // draw graphics.AddBox(box); } } // always show dimensions BoxLayer bLayer = solution[solution.Count - 1] as BoxLayer; double palletHeight = solution[solution.Count - 1].ZLow + (null != bLayer ? bLayer.Thickness(boxProperties) : 0.0); // show dimensions graphics.AddDimensions(new DimensionCube(solution.BoundingBox, Color.Black, false)); graphics.AddDimensions(new DimensionCube(solution.LoadBoundingBox, Color.Red, true)); }
public void Draw(Graphics3D graphics) { if (null == _truckSolution) { throw new Exception("No trucksolution defined!"); } // draw truck Truck truck = new Truck(_truckSolution.ParentTruckAnalysis.TruckProperties); truck.DrawBegin(graphics); truck.DrawEnd(graphics); // get pallet height CasePalletAnalysis analysis = _truckSolution.ParentTruckAnalysis.ParentAnalysis; double palletLength = _truckSolution.ParentTruckAnalysis.ParentSolution.PalletLength; double palletWidth = _truckSolution.ParentTruckAnalysis.ParentSolution.PalletWidth; double palletHeight = _truckSolution.ParentTruckAnalysis.ParentSolution.PalletHeight; // get parent pallet solution CasePalletSolution sol = _truckSolution.ParentTruckAnalysis.ParentSolution; // draw solution uint pickIdGlobal = 0; for (int i = 0; i < _truckSolution.NoLayers; ++i) { foreach (BoxPosition bPositionLayer in _truckSolution.Layer) { BoxPosition bPalletPosition = new BoxPosition( new Vector3D( bPositionLayer.Position.X , bPositionLayer.Position.Y , bPositionLayer.Position.Z + palletHeight * i) , bPositionLayer.DirectionLength , bPositionLayer.DirectionWidth); if (_showDetails) { // build transformation Transform3D transformPallet = bPalletPosition.Transformation; // draw pallet Pallet pallet = new Pallet(analysis.PalletProperties); pallet.Draw(graphics, transformPallet); // draw solution uint pickId = 0; foreach (ILayer layer in sol) { Layer3DBox bLayer = layer as Layer3DBox; if (null != bLayer) { foreach (BoxPosition bPosition in bLayer) { graphics.AddBox(new Box(pickId++, analysis.BProperties, BoxPosition.Transform(bPosition, transformPallet))); } } InterlayerPos interlayerPos = layer as InterlayerPos; if (null != interlayerPos) { BoxPosition iPos = new BoxPosition(new Vector3D(0.0, 0.0, interlayerPos.ZLow), HalfAxis.HAxis.AXIS_X_P, HalfAxis.HAxis.AXIS_Y_P); graphics.AddBox(new Box(pickId++, analysis.InterlayerProperties, BoxPosition.Transform(iPos, transformPallet))); } } } else { Box b = new Box(pickIdGlobal++, new BoxProperties(null, palletLength, palletWidth, palletHeight), bPalletPosition); b.SetAllFacesColor(Color.Chocolate); graphics.AddBox(b); } } } // fluch graphics.UseBoxelOrderer = false; // can not use boxel orderer for full truck view -> too slow... }
public void UnSelectSolutionBySol(CasePalletSolution sol) { UnSelectSolution(GetSelSolutionBySolution(sol)); }
private List<CasePalletSolution> GenerateSolutions() { // generate best layers Layer[] bestLayers = new Layer[3]; if (_constraintSet.AllowLastLayerOrientationChange) { bestLayers[0] = GenerateBestLayer(_bProperties, _palletProperties, _cornerProperties, _constraintSet, HalfAxis.HAxis.AXIS_X_P); bestLayers[1] = GenerateBestLayer(_bProperties, _palletProperties, _cornerProperties, _constraintSet, HalfAxis.HAxis.AXIS_Y_P); bestLayers[2] = GenerateBestLayer(_bProperties, _palletProperties, _cornerProperties, _constraintSet, HalfAxis.HAxis.AXIS_Z_P); } List<CasePalletSolution> solutions = new List<CasePalletSolution>(); // loop through all patterns foreach (LayerPattern pattern in _patterns) { if (!_constraintSet.AllowPattern(pattern.Name)) continue; // loop through all swap positions (if layer can be swapped) for (int swapPos = 0; swapPos < (pattern.CanBeSwapped ? 2 : 1); ++swapPos) { pattern.Swapped = swapPos == 1; // loop through all vertical axes for (int i = 0; i < 3; ++i) { HalfAxis.HAxis axisOrtho1 = (HalfAxis.HAxis)(2 * i); HalfAxis.HAxis axisOrtho2 = (HalfAxis.HAxis)(2 * i + 1); if (!_constraintSet.AllowOrthoAxis(axisOrtho2)) continue; try { // build 2 layers (pallet length/width) Layer layer1 = new Layer(_bProperties, _palletProperties, _cornerProperties, _constraintSet, axisOrtho1); Layer layer1_inv = new Layer(_bProperties, _palletProperties, _cornerProperties, _constraintSet, axisOrtho1, true); Layer layer2 = new Layer(_bProperties, _palletProperties, _cornerProperties, _constraintSet, axisOrtho2); Layer layer2_inv = new Layer(_bProperties, _palletProperties, _cornerProperties, _constraintSet, axisOrtho2, true); double actualLength1 = 0.0, actualLength2 = 0.0, actualWidth1 = 0.0, actualWidth2 = 0.0; bool bResult1 = pattern.GetLayerDimensionsChecked(layer1, out actualLength1, out actualWidth1); bool bResult2 = pattern.GetLayerDimensionsChecked(layer2, out actualLength2, out actualWidth2); string layerAlignment = string.Empty; for (int j = 0; j < 6; ++j) { Layer layer1T = null, layer2T = null; if (0 == j && _constraintSet.AllowAlignedLayers && bResult1) { pattern.GenerateLayer(layer1, actualLength1, actualWidth1); layer1T = layer1; layer2T = layer1; layerAlignment = "aligned-1"; } else if (1 == j && _constraintSet.AllowAlignedLayers && bResult2) { pattern.GenerateLayer(layer2, actualLength2, actualWidth2); layer1T = layer2; layer2T = layer2; layerAlignment = "aligned-2"; } else if (2 == j && _constraintSet.AllowAlternateLayers && bResult1 && bResult2) { pattern.GenerateLayer(layer1, Math.Max(actualLength1, actualLength2), Math.Max(actualWidth1, actualWidth2)); pattern.GenerateLayer(layer2, Math.Max(actualLength1, actualLength2), Math.Max(actualWidth1, actualWidth2)); layer1T = layer1; layer2T = layer2; layerAlignment = "alternate-12"; } else if (3 == j && _constraintSet.AllowAlternateLayers && bResult1 && bResult2) { pattern.GenerateLayer(layer1, Math.Max(actualLength1, actualLength2), Math.Max(actualWidth1, actualWidth2)); pattern.GenerateLayer(layer2, Math.Max(actualLength1, actualLength2), Math.Max(actualWidth1, actualWidth2)); layer1T = layer2; layer2T = layer1; layerAlignment = "alternate-21"; } else if (4 == j && _constraintSet.AllowAlternateLayers && pattern.CanBeInverted && bResult1) { pattern.GenerateLayer(layer1, actualLength1, actualWidth1); pattern.GenerateLayer(layer1_inv, actualLength1, actualWidth1); layer1T = layer1; layer2T = layer1_inv; layerAlignment = "inv-1"; } else if (5 == j && _constraintSet.AllowAlternateLayers && pattern.CanBeInverted && bResult2) { pattern.GenerateLayer(layer2, actualLength2, actualWidth2); pattern.GenerateLayer(layer2_inv, actualLength2, actualWidth2); layer1T = layer2; layer2T = layer2_inv; layerAlignment = "inv-2"; } if (null == layer1T || null == layer2T || 0 == layer1T.Count || 0 == layer2T.Count) continue; // counters string axisName = string.Empty; switch (i) { case 0: axisName = "X"; break; case 1: axisName = "Y"; break; case 2: axisName = "Z"; break; default: break; } string title = string.Format("{0}-{1}-{2}{3}", pattern.Name, axisName, layerAlignment, swapPos == 1 ? "-swapped" : ""); CasePalletSolution sol = new CasePalletSolution(null, title, layer1T == layer2T); int iLayerIndex = 0; double zLayer = _palletProperties.Height; double capThickness = null != _capProperties ? _capProperties.Thickness : 0; int iInterlayer = 0; int iCount = 0; bool maxWeightReached = _constraintSet.UseMaximumPalletWeight && (_palletProperties.Weight + _bProperties.Weight > _constraintSet.MaximumPalletWeight); bool maxHeightReached = _constraintSet.UseMaximumHeight && (zLayer + capThickness + _bProperties.Dimension(axisOrtho1) > _constraintSet.MaximumHeight); bool maxNumberReached = false; // insert anti-slip interlayer id there is one if (_constraintSet.HasInterlayerAntiSlip) { InterlayerPos interlayerPos = sol.CreateNewInterlayer(zLayer, 1); zLayer += _interlayerPropertiesAntiSlip.Thickness; } while (!maxWeightReached && !maxHeightReached && !maxNumberReached) { if (_constraintSet.HasInterlayer) { if (iInterlayer >= _constraintSet.InterlayerPeriod) { InterlayerPos interlayerPos = sol.CreateNewInterlayer(zLayer, 0); zLayer += _interlayerProperties.Thickness; iInterlayer = 0; } ++iInterlayer; } // select current layer type double cornerThickness = null != _cornerProperties ? _cornerProperties.Thickness : 0.0; Layer currentLayer = iLayerIndex % 2 == 0 ? layer1T : layer2T; BoxLayer layer = sol.CreateNewLayer(zLayer, pattern.Name); layer.MaximumSpace = currentLayer.MaximumSpace; foreach (LayerPosition layerPos in currentLayer) { ++iCount; maxWeightReached = _constraintSet.UseMaximumPalletWeight && ((iCount * _bProperties.Weight + _palletProperties.Weight) > _constraintSet.MaximumPalletWeight); maxNumberReached = _constraintSet.UseMaximumNumberOfCases && (iCount > _constraintSet.MaximumNumberOfItems); if (!maxWeightReached && !maxNumberReached) { LayerPosition layerPosTemp = AdjustLayerPosition(layerPos); BoxPosition boxPos = new BoxPosition( layerPosTemp.Position - (0.5 *_constraintSet.OverhangX - cornerThickness) * Vector3D.XAxis - (0.5 * _constraintSet.OverhangY - cornerThickness)* Vector3D.YAxis + zLayer * Vector3D.ZAxis , layerPosTemp.LengthAxis , layerPosTemp.WidthAxis ); layer.Add(boxPos); } else break; } // increment layer index ++iLayerIndex; zLayer += currentLayer.BoxHeight; // check height maxHeightReached = _constraintSet.UseMaximumHeight && (zLayer + _bProperties.Dimension(axisOrtho1) > _constraintSet.MaximumHeight); // check number maxNumberReached = _constraintSet.UseMaximumNumberOfCases && (iCount + 1 > _constraintSet.MaximumNumberOfItems); // check weight maxWeightReached = _constraintSet.UseMaximumPalletWeight && (((iCount+1) * _bProperties.Weight + _palletProperties.Weight) > _constraintSet.MaximumPalletWeight); } if (maxHeightReached && _constraintSet.AllowLastLayerOrientationChange) { // remaining height double remainingHeight = _constraintSet.MaximumHeight - zLayer; // test to complete with best layer Layer bestLayer = null; int ibestLayerCount = 0; for (int iLayerDir = 0; iLayerDir < 3; ++iLayerDir) { // another direction than the current direction if (iLayerDir == i) continue; Layer layer = bestLayers[iLayerDir]; if (null == layer) continue; int layerCount = Convert.ToInt32(Math.Floor(remainingHeight / layer.BoxHeight)); if (layerCount < 1) continue; if (null == bestLayer || ibestLayerCount * bestLayer.Count < layerCount * layer.Count) { bestLayer = layer; ibestLayerCount = layerCount; } } if (null != bestLayer) { double cornerThickness = null != _cornerProperties ? _cornerProperties.Thickness : 0.0; for (int iAddLayer = 0; iAddLayer < ibestLayerCount; ++iAddLayer) { BoxLayer layer = sol.CreateNewLayer(zLayer, string.Empty); foreach (LayerPosition layerPos in bestLayer) { LayerPosition layerPosTemp = AdjustLayerPosition(layerPos); BoxPosition boxPos = new BoxPosition( layerPosTemp.Position - (0.5 * _constraintSet.OverhangX - cornerThickness)* Vector3D.XAxis - (0.5 * _constraintSet.OverhangY - cornerThickness) * Vector3D.YAxis + zLayer * Vector3D.ZAxis , layerPosTemp.LengthAxis , layerPosTemp.WidthAxis ); layer.Add(boxPos); } zLayer += bestLayer.BoxHeight; } } } // set maximum criterion if (maxNumberReached) sol.LimitReached = CasePalletSolution.Limit.LIMIT_MAXNUMBERREACHED; else if (maxWeightReached) sol.LimitReached = CasePalletSolution.Limit.LIMIT_MAXWEIGHTREACHED; else if (maxHeightReached) sol.LimitReached = CasePalletSolution.Limit.LIMIT_MAXHEIGHTREACHED; // insert solution if (sol.Count > 0) solutions.Add(sol); } } catch (NotImplementedException) { _log.Info(string.Format("Pattern {0} is not implemented", pattern.Name)); } catch (Exception ex) { _log.Error(string.Format("Exception caught: {0}", ex.Message)); } } // loop through all vertical axes } // loop through all swap positions (if layer can be swapped) } // loop through all patterns // sort solutions solutions.Sort(); if (ConstraintSet.AllowTwoLayerOrientations && solutions.Count > 0) { // get best solution count int iBestSolutionCount = solutions[0].CaseCount; // if solutions exceeds List<CasePalletSolution> multiOrientSolution = GenerateOptimizedCombinationOfLayers(); foreach (CasePalletSolution sol in multiOrientSolution) { if (sol.CaseCount > iBestSolutionCount) solutions.Add(sol); } solutions.Sort(); } // remove unwanted solutions if (_constraintSet.UseNumberOfSolutionsKept && solutions.Count > _constraintSet.NumberOfSolutionsKept) { // get minimum box count int minBoxCount = solutions[_constraintSet.NumberOfSolutionsKept].CaseCount; // remove any solution with less boxes than minBoxCount while (solutions[solutions.Count - 1].CaseCount < minBoxCount) solutions.RemoveAt(solutions.Count - 1); } return solutions; }
/// <summary> /// overrides IItemListener.Update /// </summary> /// <param name="item"></param> public void Update(ItemBase item) { // update grid FillGrid(); // select first solution if (gridSolutions.RowsCount > 0) gridSolutions.Selection.SelectRow(1, true); if (_analysis.Solutions.Count > 0) _sol = _analysis.Solutions[0]; // draw graphCtrlCase.Invalidate(); graphCtrlPallet.Invalidate(); }
/// <summary> /// build optimal solutions with 2 layer types /// </summary> /// <returns></returns> private List <CasePalletSolution> GenerateOptimizedCombinationOfLayers() { List <CasePalletSolution> solutions = new List <CasePalletSolution>(); // generate best layers Layer2D[] bestLayers = new Layer2D[3]; bestLayers[0] = GenerateBestLayer(_bProperties, _palletProperties, _cornerProperties, _constraintSet, HalfAxis.HAxis.AXIS_X_P); bestLayers[1] = GenerateBestLayer(_bProperties, _palletProperties, _cornerProperties, _constraintSet, HalfAxis.HAxis.AXIS_Y_P); bestLayers[2] = GenerateBestLayer(_bProperties, _palletProperties, _cornerProperties, _constraintSet, HalfAxis.HAxis.AXIS_Z_P); string[] dir = { "X", "Y", "Z" }; for (int i = 0; i < 3; ++i) { HalfAxis.HAxis axisOrtho = (HalfAxis.HAxis)(2 * i + 1); HalfAxis.HAxis axis0 = (HalfAxis.HAxis)((2 * (i + 1)) % 6 + 1); HalfAxis.HAxis axis1 = (HalfAxis.HAxis)((2 * (i + 2)) % 6 + 1); int noLayer0 = 0, noLayer1 = 0; if (GetOptimalRequest( _bProperties.Dimension(axis0), bestLayers[i % 3].Count , _bProperties.Dimension(axis1), bestLayers[(i + 1) % 3].Count , out noLayer0, out noLayer1)) { Layer2D layer0 = bestLayers[i % 3]; Layer2D layer1 = bestLayers[(i + 1) % 3]; // sol0 CasePalletSolution sol0 = new CasePalletSolution(null, string.Format("combination_{0}{1}", dir[i % 3], dir[(i % 3) + 1]), false); double zLayer = _palletProperties.Height; double cornerThickness = null != _cornerProperties ? _cornerProperties.Thickness : 0.0; for (int j = 0; j < noLayer0; ++j) { Layer3DBox layer = sol0.CreateNewLayer(zLayer, 0); foreach (LayerPosition layerPos in layer0) { LayerPosition layerPosTemp = AdjustLayerPosition(layerPos); BoxPosition boxPos = new BoxPosition( layerPosTemp.Position - 0.5 * _constraintSet.OverhangX * Vector3D.XAxis - 0.5 * _constraintSet.OverhangY * Vector3D.YAxis + zLayer * Vector3D.ZAxis , layerPosTemp.LengthAxis , layerPosTemp.WidthAxis ); layer.Add(boxPos); } zLayer += layer0.BoxHeight; } for (int j = 0; j < noLayer1; ++j) { Layer3DBox layer = sol0.CreateNewLayer(zLayer, 0); foreach (LayerPosition layerPos in layer1) { LayerPosition layerPosTemp = AdjustLayerPosition(layerPos); BoxPosition boxPos = new BoxPosition( layerPosTemp.Position - (0.5 * _constraintSet.OverhangX - cornerThickness) * Vector3D.XAxis - (0.5 * _constraintSet.OverhangY - cornerThickness) * Vector3D.YAxis + zLayer * Vector3D.ZAxis , layerPosTemp.LengthAxis , layerPosTemp.WidthAxis ); layer.Add(boxPos); } zLayer += layer1.BoxHeight; } solutions.Add(sol0); // sol1 CasePalletSolution sol1 = new CasePalletSolution(null, string.Format("combination_{0}{1}", dir[i % 3], dir[(i % 3) + 1]), false); zLayer = _palletProperties.Height; for (int j = 0; j < noLayer0; ++j) { Layer3DBox layer = sol1.CreateNewLayer(zLayer, 0); foreach (LayerPosition layerPos in layer1) { LayerPosition layerPosTemp = AdjustLayerPosition(layerPos); BoxPosition boxPos = new BoxPosition( layerPosTemp.Position - (0.5 * _constraintSet.OverhangX - cornerThickness) * Vector3D.XAxis - (0.5 * _constraintSet.OverhangY - cornerThickness) * Vector3D.YAxis + zLayer * Vector3D.ZAxis , layerPosTemp.LengthAxis , layerPosTemp.WidthAxis ); layer.Add(boxPos); } zLayer += layer1.BoxHeight; } for (int j = 0; j < noLayer1; ++j) { Layer3DBox layer = sol1.CreateNewLayer(zLayer, 0); foreach (LayerPosition layerPos in layer0) { LayerPosition layerPosTemp = AdjustLayerPosition(layerPos); BoxPosition boxPos = new BoxPosition( layerPosTemp.Position - (0.5 * _constraintSet.OverhangX - cornerThickness) * Vector3D.XAxis - (0.5 * _constraintSet.OverhangY - cornerThickness) * Vector3D.YAxis + zLayer * Vector3D.ZAxis , layerPosTemp.LengthAxis , layerPosTemp.WidthAxis ); layer.Add(boxPos); } zLayer += layer0.BoxHeight; } solutions.Add(sol1); } } return(solutions); }
private bool GenerateProject(out Document doc, out CasePalletAnalysis analysis, out CasePalletSolution casePalletSolution) { doc = null; analysis = null; casePalletSolution = null; try { // build solution doc = new Document( _boxName, string.Format(Properties.Resources.ID_OPTDOCUMENTDESCRIPTION, _boxName), string.Empty, DateTime.Now, null); // box BoxProperties boxProperties = doc.CreateNewBox(SelectedBox); // pallet PalletProperties palletProperties = doc.CreateNewPallet(SelectedPallet); // get selected caseOptimSolution CaseOptimSolution sol = SelectedSolution; PackArrangement arrangement = sol.CaseDefinition.Arrangement; // build new case name string arrangName = string.Format("{0}_{1}x{2}x{3}_{4}{5}" , boxProperties.Name , arrangement._iLength , arrangement._iWidth , arrangement._iHeight , sol.CaseDefinition.Dim0 , sol.CaseDefinition.Dim1); // build new case description string description = string.Format( Properties.Resources.ID_OPTCASEDESCRIPTION , boxProperties.Name , palletProperties.Name); // add new case CaseOfBoxesProperties caseProperties = doc.CreateNewCaseOfBoxes( arrangName, description , boxProperties , sol.CaseDefinition , BuildCaseOptimConstraintSet()); // set color caseProperties.SetColor(Color.Chocolate); // add new pallet analysis string analysisName = string.Format( Properties.Resources.ID_OPTANALYSISNAME , boxProperties.Name , boxProperties.Name , arrangement._iLength , arrangement._iWidth , arrangement._iHeight , sol.CaseDefinition.Dim0 , sol.CaseDefinition.Dim1); string analysisDescription = string.Format( Properties.Resources.ID_OPTANALYSISDESCRIPTION , boxProperties.Name , palletProperties.Name); List<CasePalletSolution> palletSolutionList = new List<CasePalletSolution>(); palletSolutionList.Add(sol.PalletSolution); analysis = doc.CreateNewCasePalletAnalysis( analysisName , analysisDescription , caseProperties , palletProperties , null , null , null , null , null , BuildPalletConstraintSet() , palletSolutionList); } catch (Exception ex) { _log.Error(ex.ToString()); return false; } return true; }
private void onGridSolutionSelectionChanged(object sender, SourceGrid.RangeRegionChangedEventArgs e) { SourceGrid.RangeRegion region = gridSolutions.Selection.GetSelectionRegion(); int[] indexes = region.GetRowsIndex(); // no selection -> exit if (indexes.Length == 0) return; // get selected solution _sol = _analysis.Solutions[indexes[0] - 1]; // redraw graphCtrlCase.Invalidate(); graphCtrlPallet.Invalidate(); }
public Exporter(CasePalletSolution palletSolution) { _palletSolution = palletSolution; }
/// <summary> /// overrides IItemListener.Update /// </summary> /// <param name="item"></param> public void Update(ItemBase item) { // update grid FillGrid(); // select first solution if (gridSolutions.RowsCount > 0) gridSolutions.Selection.SelectRow(1, true); if (_analysis.Solutions.Count > 0) _sol = _analysis.Solutions[0]; // draw Draw(); }
private string PalletSolutionLimitToString(CasePalletSolution.Limit limit) { switch (limit) { case CasePalletSolution.Limit.LIMIT_MAXHEIGHTREACHED: return Resources.ID_PALLETMAXHEIGHT; case CasePalletSolution.Limit.LIMIT_MAXWEIGHTREACHED: return Resources.ID_PALLETMAXWEIGHT; case CasePalletSolution.Limit.LIMIT_MAXNUMBERREACHED: return Resources.ID_PALLETMAXNUMBER; default: return string.Empty; } }
private void onGridSolutionSelectionChanged(object sender, SourceGrid.RangeRegionChangedEventArgs e) { SourceGrid.RangeRegion region = gridSolutions.Selection.GetSelectionRegion(); int[] indexes = region.GetRowsIndex(); // no selection -> exit if (indexes.Length == 0) return; // get selected solution _sol = _analysis.Solutions[indexes[0] - 1]; // update select/unselect button text UpdateSelectButtonText(); // redraw Draw(); }
private bool GenerateProject(out Document doc, out CasePalletAnalysis analysis, out CasePalletSolution casePalletSolution) { doc = null; analysis = null; casePalletSolution = null; try { // build solution doc = new Document( _boxName, string.Format(Properties.Resources.ID_OPTDOCUMENTDESCRIPTION, _boxName), string.Empty, DateTime.Now, null); // box BoxProperties boxProperties = doc.CreateNewBox(SelectedBox); // pallet PalletProperties palletProperties = doc.CreateNewPallet(SelectedPallet); // get selected caseOptimSolution CaseOptimSolution sol = SelectedSolution; PackArrangement arrangement = sol.CaseDefinition.Arrangement; // build new case name string arrangName = string.Format("{0}_{1}x{2}x{3}_{4}{5}" , boxProperties.Name , arrangement._iLength , arrangement._iWidth , arrangement._iHeight , sol.CaseDefinition.Dim0 , sol.CaseDefinition.Dim1); // build new case description string description = string.Format( Properties.Resources.ID_OPTCASEDESCRIPTION , boxProperties.Name , palletProperties.Name); // add new case CaseOfBoxesProperties caseProperties = doc.CreateNewCaseOfBoxes( arrangName, description , boxProperties , sol.CaseDefinition , BuildCaseOptimConstraintSet()); // set color caseProperties.SetColor(Color.Chocolate); // add new pallet analysis string analysisName = string.Format( Properties.Resources.ID_OPTANALYSISNAME , boxProperties.Name , boxProperties.Name , arrangement._iLength , arrangement._iWidth , arrangement._iHeight , sol.CaseDefinition.Dim0 , sol.CaseDefinition.Dim1); string analysisDescription = string.Format( Properties.Resources.ID_OPTANALYSISDESCRIPTION , boxProperties.Name , palletProperties.Name); List <CasePalletSolution> palletSolutionList = new List <CasePalletSolution>(); palletSolutionList.Add(sol.PalletSolution); analysis = doc.CreateNewCasePalletAnalysis( analysisName , analysisDescription , caseProperties , palletProperties , null , null , null , null , null , BuildPalletConstraintSet() , palletSolutionList); } catch (Exception ex) { _log.Error(ex.ToString()); return(false); } return(true); }
public SelCasePalletSolution GetSelSolutionBySolution(CasePalletSolution sol) { return _selectedSolutions.Find(delegate(SelCasePalletSolution selSol) { return selSol.Solution == sol; }); }
private void AppendConstraintSet(CasePalletAnalysis analysis, CasePalletSolution sol, XmlElement elemPalletAnalysis, XmlDocument xmlDoc) { string ns = xmlDoc.DocumentElement.NamespaceURI; PalletConstraintSet cs = analysis.ConstraintSet; // solution XmlElement elemConstraintSet = xmlDoc.CreateElement("constraintSet", ns); elemPalletAnalysis.AppendChild(elemConstraintSet); // overhangX, overhangY AppendElementValue(xmlDoc, elemConstraintSet, "overhangX", UnitsManager.UnitType.UT_LENGTH, cs.OverhangX); AppendElementValue(xmlDoc, elemConstraintSet, "overhangY", UnitsManager.UnitType.UT_LENGTH, cs.OverhangY); // allowedPatterns XmlElement elemAllowedPatterns = xmlDoc.CreateElement("allowedPatterns", ns); elemAllowedPatterns.InnerText = cs.AllowedPatternString; elemConstraintSet.AppendChild(elemAllowedPatterns); // allowedBoxAxis XmlElement elemAllowedBoxAxis = xmlDoc.CreateElement("allowedOrthoAxis", ns); elemAllowedBoxAxis.InnerText = cs.AllowOrthoAxisString; elemConstraintSet.AppendChild(elemAllowedBoxAxis); // allowAlternateLayers XmlElement elemAllowAlternateLayers = xmlDoc.CreateElement("allowAlternateLayers", ns); elemAllowAlternateLayers.InnerText = cs.AllowAlternateLayers.ToString(); elemConstraintSet.AppendChild(elemAllowAlternateLayers); // allowAlignedLayers XmlElement elemAllowAlignedLayers = xmlDoc.CreateElement("allowAlignedLayers", ns); elemAllowAlignedLayers.InnerText = cs.AllowAlignedLayers.ToString(); elemConstraintSet.AppendChild(elemAllowAlignedLayers); // interlayerPeriod if (cs.HasInterlayer) { XmlElement elemInterlayerPeriodGroup = xmlDoc.CreateElement("interlayerPeriodGroup", ns); elemConstraintSet.AppendChild(elemInterlayerPeriodGroup); XmlElement elemInterlayerPeriod = xmlDoc.CreateElement("interlayerPeriod", ns); elemInterlayerPeriod.InnerText = string.Format("{0}", cs.InterlayerPeriod); elemInterlayerPeriodGroup.AppendChild(elemInterlayerPeriod); } // stopCriterion if (cs.UseMaximumHeight) { XmlElement maximumPalletHeightGroup = xmlDoc.CreateElement("maximumPalletHeightGroup", ns); elemConstraintSet.AppendChild(maximumPalletHeightGroup); // maximum pallet height AppendElementValue(xmlDoc, maximumPalletHeightGroup, "maximumPalletHeight", UnitsManager.UnitType.UT_LENGTH, cs.MaximumHeight); } if (cs.UseMaximumNumberOfCases) { XmlElement maximumNumberOfItemsGroup = xmlDoc.CreateElement("maximumNumberOfItemsGroup", ns); elemConstraintSet.AppendChild(maximumNumberOfItemsGroup); XmlElement maximumNumberOfItems = xmlDoc.CreateElement("maximumNumberOfItems", ns); maximumNumberOfItems.InnerText = string.Format("{0}", cs.MaximumNumberOfItems); maximumNumberOfItemsGroup.AppendChild(maximumNumberOfItems); } if (cs.UseMaximumPalletWeight) { XmlElement maximumPalletWeightGroup = xmlDoc.CreateElement("maximumPalletWeightGroup", ns); elemConstraintSet.AppendChild(maximumPalletWeightGroup); // pallet weight AppendElementValue(xmlDoc, maximumPalletWeightGroup, "maximumPalletHeight", UnitsManager.UnitType.UT_MASS, cs.MaximumPalletWeight); } if (cs.UseMaximumWeightOnBox) { XmlElement maximumWeightOnBoxGroup = xmlDoc.CreateElement("maximumWeightOnBoxGroup", ns); elemConstraintSet.AppendChild(maximumWeightOnBoxGroup); // admissible load on top AppendElementValue(xmlDoc, maximumWeightOnBoxGroup, "admissibleLoadOnTop", UnitsManager.UnitType.UT_MASS, cs.MaximumWeightOnBox); } }
private List <BoxCasePalletSolution> GenerateSolutions() { List <BoxCasePalletSolution> solutions = new List <BoxCasePalletSolution>(); // loop through all pallet solutions foreach (PalletSolutionDesc desc in _palletSolutionList) { CasePalletSolution palletSolution = desc.LoadPalletSolution(); if (null == palletSolution) { _log.Warn(string.Format("Failed to load pallet solution ")); continue; } BoxProperties caseProperties = palletSolution.Analysis.BProperties as BoxProperties; // loop through all patterns foreach (LayerPattern pattern in _patterns) { if (!_constraintSet.AllowPattern(pattern.Name)) { continue; } // loop through all swap positions (if layer can be swapped) for (int swapPos = 0; swapPos < (pattern.CanBeSwapped ? 2 : 1); ++swapPos) { pattern.Swapped = swapPos == 1; // loop through all vertical axes for (int i = 0; i < 3; ++i) { HalfAxis.HAxis axisOrtho1 = (HalfAxis.HAxis)(2 * i); HalfAxis.HAxis axisOrtho2 = (HalfAxis.HAxis)(2 * i + 1); if (!_constraintSet.AllowOrthoAxis(axisOrtho2)) { continue; } try { // build 2 layers (pallet length/width) Layer layer1 = new Layer(_boxProperties, caseProperties, axisOrtho1); Layer layer2 = new Layer(_boxProperties, caseProperties, axisOrtho2); double actualLength1 = 0.0, actualLength2 = 0.0, actualWidth1 = 0.0, actualWidth2 = 0.0; bool bResult1 = pattern.GetLayerDimensionsChecked(layer1, out actualLength1, out actualWidth1); bool bResult2 = pattern.GetLayerDimensionsChecked(layer2, out actualLength2, out actualWidth2); string layerAlignment = string.Empty; for (int j = 0; j < 4; ++j) { Layer layer1T = null, layer2T = null; if (0 == j && _constraintSet.AllowAlignedLayers && bResult1) { pattern.GenerateLayer(layer1, actualLength1, actualWidth1); layer1T = layer1; layer2T = layer1; layerAlignment = "aligned-1"; } else if (1 == j && _constraintSet.AllowAlignedLayers && bResult2) { pattern.GenerateLayer(layer2, actualLength2, actualWidth2); layer1T = layer2; layer2T = layer2; layerAlignment = "aligned-2"; } else if (2 == j && _constraintSet.AllowAlternateLayers && bResult1 && bResult2) { pattern.GenerateLayer(layer1, Math.Max(actualLength1, actualLength2), Math.Max(actualWidth1, actualWidth2)); pattern.GenerateLayer(layer2, Math.Max(actualLength1, actualLength2), Math.Max(actualWidth1, actualWidth2)); layer1T = layer1; layer2T = layer2; layerAlignment = "alternate-12"; } else if (3 == j && _constraintSet.AllowAlternateLayers && bResult1 && bResult2) { pattern.GenerateLayer(layer1, Math.Max(actualLength1, actualLength2), Math.Max(actualWidth1, actualWidth2)); pattern.GenerateLayer(layer2, Math.Max(actualLength1, actualLength2), Math.Max(actualWidth1, actualWidth2)); layer1T = layer2; layer2T = layer1; layerAlignment = "alternate-21"; } if (null == layer1T || null == layer2T || 0 == layer1T.Count || 0 == layer2T.Count) { continue; } // counters string axisName = string.Empty; switch (i) { case 0: axisName = "X"; break; case 1: axisName = "Y"; break; case 2: axisName = "Z"; break; default: break; } string title = string.Format("{0}-{1}-{2}{3}", pattern.Name, axisName, layerAlignment, swapPos == 1 ? "-swapped" : ""); BoxCasePalletSolution sol = new BoxCasePalletSolution(null, title, desc, layer1T == layer2T); int iLayerIndex = 0; bool innerLoopStop = false; double offsetX = 0.5 * (caseProperties.Length - caseProperties.InsideLength); double offsetY = 0.5 * (caseProperties.Width - caseProperties.InsideWidth); double zLayer = 0.5 * (caseProperties.Height - caseProperties.InsideHeight); int iInterlayer = 0; int boxCount = 0; while ( !innerLoopStop && ((zLayer + _boxProperties.Dimension(axisOrtho1) < caseProperties.InsideHeight)) ) { if (_constraintSet.HasInterlayer) { if (iInterlayer >= _constraintSet.InterlayerPeriod) { InterlayerPos interlayerPos = sol.CreateNewInterlayer(zLayer, 0); zLayer += _interlayerProperties.Thickness; iInterlayer = 0; } ++iInterlayer; } // select current layer type Layer currentLayer = iLayerIndex % 2 == 0 ? layer1T : layer2T; BoxLayer layer = sol.CreateNewLayer(zLayer, pattern.Name); foreach (LayerPosition layerPos in currentLayer) { int iCount = sol.Count + 1; innerLoopStop = (_constraintSet.UseMaximumCaseWeight && ((boxCount + 1) * _boxProperties.Weight + caseProperties.Weight > _constraintSet.MaximumCaseWeight)) || (_constraintSet.UseMaximumNumberOfItems && ((boxCount + 1) > _constraintSet.MaximumNumberOfItems)); if (!innerLoopStop) { BoxPosition boxPos = new BoxPosition( layerPos.Position + offsetX * Vector3D.XAxis + offsetY * Vector3D.YAxis + zLayer * Vector3D.ZAxis , layerPos.LengthAxis , layerPos.WidthAxis ); layer.Add(boxPos); ++boxCount; } else { break; } } // increment layer index ++iLayerIndex; zLayer += currentLayer.BoxHeight; } // insert solution if ( sol.Count > 0 && (!_constraintSet.UseMinimumNumberOfItems || sol.Count >= _constraintSet.MinimumNumberOfItems) ) { solutions.Add(sol); } } } catch (NotImplementedException) { _log.Info(string.Format("Pattern {0} is not implemented", pattern.Name)); } catch (Exception ex) { _log.Error(string.Format("Exception caught: {0}", ex.Message)); } } // loop through all vertical axes } // loop through all swap positions (if layer can be swapped) } // loop through all patterns } // loop through all pallet solutions // sort solutions solutions.Sort(); // return list of solutions return(solutions); }
private void AppendInsideBoxElement(CasePalletAnalysis analysis, CasePalletSolution sol, XmlElement elemPalletAnalysis, XmlDocument xmlDoc) { string ns = xmlDoc.DocumentElement.NamespaceURI; // get caseOfBoxProperties CaseOfBoxesProperties caseOfBoxes = analysis.BProperties as CaseOfBoxesProperties; // get box properties BoxProperties boxProperties = caseOfBoxes.InsideBoxProperties; // elemBoxes XmlElement elemBox = xmlDoc.CreateElement("box", ns); elemPalletAnalysis.AppendChild(elemBox); // name XmlElement elemName = xmlDoc.CreateElement("name", ns); elemName.InnerText = boxProperties.Name; elemBox.AppendChild(elemName); // description XmlElement elemDescription = xmlDoc.CreateElement("description", ns); elemDescription.InnerText = boxProperties.Description; elemBox.AppendChild(elemDescription); AppendElementValue(xmlDoc, elemBox, "length", UnitsManager.UnitType.UT_LENGTH, boxProperties.Length); AppendElementValue(xmlDoc, elemBox, "width", UnitsManager.UnitType.UT_LENGTH, boxProperties.Width); AppendElementValue(xmlDoc, elemBox, "height", UnitsManager.UnitType.UT_LENGTH, boxProperties.Height); AppendElementValue(xmlDoc, elemBox, "weight", UnitsManager.UnitType.UT_MASS, boxProperties.Weight); // --- build image Graphics3DImage graphics = new Graphics3DImage(new Size(ImageSizeDetail, ImageSizeDetail)); graphics.CameraPosition = Graphics3D.Corner_0; graphics.Target = Vector3D.Zero; Box box = new Box(0, boxProperties); graphics.AddBox(box); DimensionCube dc = new DimensionCube(box.Length, box.Width, box.Height); dc.FontSize = 6.0f; graphics.AddDimensions(dc); graphics.Flush(); // --- // view_box_iso XmlElement elemImage = xmlDoc.CreateElement("view_box_iso", ns); TypeConverter converter = TypeDescriptor.GetConverter(typeof(Bitmap)); elemImage.InnerText = Convert.ToBase64String((byte[])converter.ConvertTo(graphics.Bitmap, typeof(byte[]))); XmlAttribute styleAttribute = xmlDoc.CreateAttribute("style"); styleAttribute.Value = string.Format("width:{0}pt;height:{1}pt", graphics.Bitmap.Width / 4, graphics.Bitmap.Height / 4); elemImage.Attributes.Append(styleAttribute); elemBox.AppendChild(elemImage); // save image ? SaveImageAs(graphics.Bitmap, "view_box_iso.png"); }
public CaseOptimSolution(CaseDefinition caseDefinition, CasePalletSolution palletSolution) { _caseDefinition = caseDefinition; _palletSolution = palletSolution; }
public void SelectSolutionBySol(CasePalletSolution sol) { if (HasSolutionSelected(sol)) return; // instantiate new SelSolution SelCasePalletSolution selSolution = new SelCasePalletSolution(ParentDocument, this, sol); // insert in list _selectedSolutions.Add(selSolution); // fire event if (null != SolutionSelected) SolutionSelected(this, selSolution); // set document modified (not analysis, otherwise selected solutions are erased) ParentDocument.Modify(); }
/// <summary> /// Draw case solution /// </summary> public void Draw(Graphics3D graphics) { if (null == _caseSolution) { throw new Exception("No case solution defined!"); } // load pallet solution BoxProperties caseProperties; CasePalletSolution palletSolution = _caseSolution.PalletSolutionDesc.LoadPalletSolution(); if (null == palletSolution) { caseProperties = new BoxProperties(null, _caseSolution.CaseLength, _caseSolution.CaseWidth, _caseSolution.CaseHeight); } else { CasePalletAnalysis palletAnalysis = palletSolution.Analysis; // retrieve case properties caseProperties = palletAnalysis.BProperties as BoxProperties; } if (null == caseProperties) { return; } // draw case (inside) Case case_ = new Case(caseProperties); case_.DrawInside(graphics); // get case analysis BoxCasePalletAnalysis caseAnalysis = _caseSolution.ParentCaseAnalysis; // draw solution uint pickId = 0; foreach (ILayer layer in _caseSolution) { BoxLayer blayer = layer as BoxLayer; if (null != blayer) { foreach (BoxPosition bPosition in blayer) { graphics.AddBox(new Box(pickId++, caseAnalysis.BoxProperties, bPosition)); } } InterlayerPos interlayerPos = layer as InterlayerPos; if (null != interlayerPos) { Box box = new Box(pickId++, caseAnalysis.InterlayerProperties); // set position box.Position = new Vector3D(0.0, 0.0, interlayerPos.ZLow); // draw graphics.AddBox(box); } } // get case analysis if (_showDimensions) { graphics.AddDimensions(new DimensionCube(_caseSolution.CaseLength, _caseSolution.CaseWidth, _caseSolution.CaseHeight)); } }
public bool HasSolutionSelected(CasePalletSolution sol) { return (null != GetSelSolutionBySolution(sol)); }
/// <summary> /// build optimal solutions with 2 layer types /// </summary> /// <returns></returns> private List<CasePalletSolution> GenerateOptimizedCombinationOfLayers() { List<CasePalletSolution> solutions = new List<CasePalletSolution>(); // generate best layers Layer[] bestLayers = new Layer[3]; bestLayers[0] = GenerateBestLayer(_bProperties, _palletProperties, _cornerProperties, _constraintSet, HalfAxis.HAxis.AXIS_X_P); bestLayers[1] = GenerateBestLayer(_bProperties, _palletProperties, _cornerProperties, _constraintSet, HalfAxis.HAxis.AXIS_Y_P); bestLayers[2] = GenerateBestLayer(_bProperties, _palletProperties, _cornerProperties, _constraintSet, HalfAxis.HAxis.AXIS_Z_P); string[] dir = { "X", "Y", "Z" }; for (int i = 0; i < 3; ++i) { HalfAxis.HAxis axisOrtho = (HalfAxis.HAxis)(2 * i + 1); HalfAxis.HAxis axis0 = (HalfAxis.HAxis)((2 * (i + 1)) % 6 + 1); HalfAxis.HAxis axis1 = (HalfAxis.HAxis)((2 * (i + 2)) % 6 + 1); int noLayer0 = 0, noLayer1 = 0; if (GetOptimalRequest( _bProperties.Dimension(axis0), bestLayers[i % 3].Count , _bProperties.Dimension(axis1), bestLayers[(i + 1) % 3].Count , out noLayer0, out noLayer1)) { Layer layer0 = bestLayers[i % 3]; Layer layer1 = bestLayers[(i + 1) % 3]; // sol0 CasePalletSolution sol0 = new CasePalletSolution(null, string.Format("combination_{0}{1}", dir[i % 3], dir[(i % 3) + 1]), false); double zLayer = _palletProperties.Height; double cornerThickness = null != _cornerProperties ? _cornerProperties.Thickness : 0.0; for (int j = 0; j < noLayer0; ++j) { BoxLayer layer = sol0.CreateNewLayer(zLayer, string.Empty); foreach (LayerPosition layerPos in layer0) { LayerPosition layerPosTemp = AdjustLayerPosition(layerPos); BoxPosition boxPos = new BoxPosition( layerPosTemp.Position - 0.5 * _constraintSet.OverhangX * Vector3D.XAxis - 0.5 * _constraintSet.OverhangY * Vector3D.YAxis + zLayer * Vector3D.ZAxis , layerPosTemp.LengthAxis , layerPosTemp.WidthAxis ); layer.Add(boxPos); } zLayer += layer0.BoxHeight; } for (int j = 0; j < noLayer1; ++j) { BoxLayer layer = sol0.CreateNewLayer(zLayer, string.Empty); foreach (LayerPosition layerPos in layer1) { LayerPosition layerPosTemp = AdjustLayerPosition(layerPos); BoxPosition boxPos = new BoxPosition( layerPosTemp.Position - (0.5 * _constraintSet.OverhangX - cornerThickness) * Vector3D.XAxis - (0.5 * _constraintSet.OverhangY - cornerThickness) * Vector3D.YAxis + zLayer * Vector3D.ZAxis , layerPosTemp.LengthAxis , layerPosTemp.WidthAxis ); layer.Add(boxPos); } zLayer += layer1.BoxHeight; } solutions.Add(sol0); // sol1 CasePalletSolution sol1 = new CasePalletSolution(null, string.Format("combination_{0}{1}", dir[i % 3], dir[(i % 3) + 1]), false); zLayer = _palletProperties.Height; for (int j = 0; j < noLayer0; ++j) { BoxLayer layer = sol1.CreateNewLayer(zLayer, string.Empty); foreach (LayerPosition layerPos in layer1) { LayerPosition layerPosTemp = AdjustLayerPosition(layerPos); BoxPosition boxPos = new BoxPosition( layerPosTemp.Position - (0.5 * _constraintSet.OverhangX - cornerThickness) * Vector3D.XAxis - (0.5 * _constraintSet.OverhangY - cornerThickness) * Vector3D.YAxis + zLayer * Vector3D.ZAxis , layerPosTemp.LengthAxis , layerPosTemp.WidthAxis ); layer.Add(boxPos); } zLayer += layer1.BoxHeight; } for (int j = 0; j < noLayer1; ++j) { BoxLayer layer = sol1.CreateNewLayer(zLayer, string.Empty); foreach (LayerPosition layerPos in layer0) { LayerPosition layerPosTemp = AdjustLayerPosition(layerPos); BoxPosition boxPos = new BoxPosition( layerPosTemp.Position - (0.5 * _constraintSet.OverhangX - cornerThickness) * Vector3D.XAxis - (0.5 * _constraintSet.OverhangY - cornerThickness) * Vector3D.YAxis + zLayer * Vector3D.ZAxis , layerPosTemp.LengthAxis , layerPosTemp.WidthAxis ); layer.Add(boxPos); } zLayer += layer0.BoxHeight; } solutions.Add(sol1); } } return solutions; }
public void SaveCasePalletAnalysis(CasePalletAnalysis analysis, CasePalletSolution sol, SelCasePalletSolution selSolution, XmlElement parentElement, XmlDocument xmlDoc) { // create analysis element XmlElement xmlAnalysisElt = xmlDoc.CreateElement("AnalysisPallet"); parentElement.AppendChild(xmlAnalysisElt); // Name XmlAttribute analysisNameAttribute = xmlDoc.CreateAttribute("Name"); analysisNameAttribute.Value = analysis.Name; xmlAnalysisElt.Attributes.Append(analysisNameAttribute); // Description XmlAttribute analysisDescriptionAttribute = xmlDoc.CreateAttribute("Description"); analysisDescriptionAttribute.Value = analysis.Description; xmlAnalysisElt.Attributes.Append(analysisDescriptionAttribute); // BoxId XmlAttribute boxIdAttribute = xmlDoc.CreateAttribute("BoxId"); boxIdAttribute.Value = string.Format("{0}", analysis.BProperties.Guid); xmlAnalysisElt.Attributes.Append(boxIdAttribute); // PalletId XmlAttribute palletIdAttribute = xmlDoc.CreateAttribute("PalletId"); palletIdAttribute.Value = string.Format("{0}", analysis.PalletProperties.Guid); xmlAnalysisElt.Attributes.Append(palletIdAttribute); // InterlayerId if (null != analysis.InterlayerProperties) { XmlAttribute interlayerIdAttribute = xmlDoc.CreateAttribute("InterlayerId"); interlayerIdAttribute.Value = string.Format("{0}", analysis.InterlayerProperties.Guid); xmlAnalysisElt.Attributes.Append(interlayerIdAttribute); } if (null != analysis.InterlayerPropertiesAntiSlip) { XmlAttribute interlayerIdAttribute = xmlDoc.CreateAttribute("InterlayerAntiSlipId"); interlayerIdAttribute.Value = string.Format("{1}", analysis.InterlayerPropertiesAntiSlip.Guid); xmlAnalysisElt.Attributes.Append(interlayerIdAttribute); } // ### // ConstraintSet bool bundleAnalysis = (analysis.ConstraintSet.GetType() == typeof(BundlePalletConstraintSet)); XmlElement constraintSetElement = xmlDoc.CreateElement(bundleAnalysis ? "ConstraintSetBundle" : "ConstraintSetBox"); XmlAttribute alignedLayersAttribute = xmlDoc.CreateAttribute("AlignedLayersAllowed"); alignedLayersAttribute.Value = string.Format("{0}", analysis.ConstraintSet.AllowAlignedLayers); constraintSetElement.Attributes.Append(alignedLayersAttribute); XmlAttribute alternateLayersAttribute = xmlDoc.CreateAttribute("AlternateLayersAllowed"); alternateLayersAttribute.Value = string.Format("{0}", analysis.ConstraintSet.AllowAlternateLayers); constraintSetElement.Attributes.Append(alternateLayersAttribute); if (!bundleAnalysis) { // allowed box positions XmlAttribute allowedAxisAttribute = xmlDoc.CreateAttribute("AllowedBoxPositions"); HalfAxis.HAxis[] axes = { HalfAxis.HAxis.AXIS_X_P, HalfAxis.HAxis.AXIS_Y_P, HalfAxis.HAxis.AXIS_Z_P }; string allowedAxes = string.Empty; foreach (HalfAxis.HAxis axis in axes) if (analysis.ConstraintSet.AllowOrthoAxis(axis)) { if (!string.IsNullOrEmpty(allowedAxes)) allowedAxes += ","; allowedAxes += HalfAxis.ToString(axis); } allowedAxisAttribute.Value = allowedAxes; constraintSetElement.Attributes.Append(allowedAxisAttribute); } // allowed layer patterns XmlAttribute allowedPatternAttribute = xmlDoc.CreateAttribute("AllowedPatterns"); allowedPatternAttribute.Value = analysis.ConstraintSet.AllowedPatternString; constraintSetElement.Attributes.Append(allowedPatternAttribute); // stop criterions if (analysis.ConstraintSet.UseMaximumHeight) { XmlAttribute maximumHeightAttribute = xmlDoc.CreateAttribute("MaximumHeight"); maximumHeightAttribute.Value = string.Format(System.Globalization.CultureInfo.InvariantCulture, "{0}", analysis.ConstraintSet.MaximumHeight); constraintSetElement.Attributes.Append(maximumHeightAttribute); } if (analysis.ConstraintSet.UseMaximumNumberOfCases) { XmlAttribute maximumNumberOfItems = xmlDoc.CreateAttribute("ManimumNumberOfItems"); maximumNumberOfItems.Value = string.Format("{0}", analysis.ConstraintSet.MaximumNumberOfItems); constraintSetElement.Attributes.Append(maximumNumberOfItems); } if (analysis.ConstraintSet.UseMaximumPalletWeight) { XmlAttribute maximumPalletWeight = xmlDoc.CreateAttribute("MaximumPalletWeight"); maximumPalletWeight.Value = string.Format(System.Globalization.CultureInfo.InvariantCulture, "{0}", analysis.ConstraintSet.MaximumPalletWeight); constraintSetElement.Attributes.Append(maximumPalletWeight); } if (analysis.ConstraintSet.UseMaximumWeightOnBox) { XmlAttribute maximumWeightOnBox = xmlDoc.CreateAttribute("MaximumWeightOnBox"); maximumWeightOnBox.Value = string.Format(System.Globalization.CultureInfo.InvariantCulture, "{0}", analysis.ConstraintSet.MaximumWeightOnBox); constraintSetElement.Attributes.Append(maximumWeightOnBox); } // overhang / underhang XmlAttribute overhangX = xmlDoc.CreateAttribute("OverhangX"); overhangX.Value = string.Format("{0}", analysis.ConstraintSet.OverhangX); constraintSetElement.Attributes.Append(overhangX); XmlAttribute overhangY = xmlDoc.CreateAttribute("OverhangY"); overhangY.Value = string.Format("{0}", analysis.ConstraintSet.OverhangY); constraintSetElement.Attributes.Append(overhangY); // number of solutions to keep if (analysis.ConstraintSet.UseNumberOfSolutionsKept) { XmlAttribute numberOfSolutionsKept = xmlDoc.CreateAttribute("NumberOfSolutions"); numberOfSolutionsKept.Value = "1"; constraintSetElement.Attributes.Append(numberOfSolutionsKept); } xmlAnalysisElt.AppendChild(constraintSetElement); // ### // Solutions XmlElement solutionsElt = xmlDoc.CreateElement("Solutions"); xmlAnalysisElt.AppendChild(solutionsElt); SaveCasePalletSolution(analysis, sol, selSolution, true /* unique */, solutionsElt, xmlDoc ); }
private List <CasePalletSolution> GenerateSolutions() { // generate best layers Layer2D[] bestLayers = new Layer2D[3]; if (_constraintSet.AllowLastLayerOrientationChange) { bestLayers[0] = GenerateBestLayer(_bProperties, _palletProperties, _cornerProperties, _constraintSet, HalfAxis.HAxis.AXIS_X_P); bestLayers[1] = GenerateBestLayer(_bProperties, _palletProperties, _cornerProperties, _constraintSet, HalfAxis.HAxis.AXIS_Y_P); bestLayers[2] = GenerateBestLayer(_bProperties, _palletProperties, _cornerProperties, _constraintSet, HalfAxis.HAxis.AXIS_Z_P); } List <CasePalletSolution> solutions = new List <CasePalletSolution>(); // loop through all patterns foreach (LayerPatternBox pattern in LayerPatternBox.All) { if (!_constraintSet.AllowPattern(pattern.Name)) { continue; } // loop through all swap positions (if layer can be swapped) for (int swapPos = 0; swapPos < (pattern.CanBeSwapped ? 2 : 1); ++swapPos) { // loop through all vertical axes for (int i = 0; i < 3; ++i) { HalfAxis.HAxis axisOrtho1 = (HalfAxis.HAxis)(2 * i); HalfAxis.HAxis axisOrtho2 = (HalfAxis.HAxis)(2 * i + 1); if (!_constraintSet.AllowOrthoAxis(axisOrtho2)) { continue; } try { // build 2 layers (pallet length/width) Layer2D layer1 = BuildLayer(_bProperties, _palletProperties, _cornerProperties, _constraintSet, axisOrtho1, swapPos == 1, false); Layer2D layer1_inv = BuildLayer(_bProperties, _palletProperties, _cornerProperties, _constraintSet, axisOrtho1, swapPos == 1, true); Layer2D layer2 = BuildLayer(_bProperties, _palletProperties, _cornerProperties, _constraintSet, axisOrtho2, swapPos == 1, false); Layer2D layer2_inv = BuildLayer(_bProperties, _palletProperties, _cornerProperties, _constraintSet, axisOrtho2, swapPos == 1, true); double actualLength1 = 0.0, actualLength2 = 0.0, actualWidth1 = 0.0, actualWidth2 = 0.0; bool bResult1 = pattern.GetLayerDimensionsChecked(layer1, out actualLength1, out actualWidth1); bool bResult2 = pattern.GetLayerDimensionsChecked(layer2, out actualLength2, out actualWidth2); string layerAlignment = string.Empty; for (int j = 0; j < 6; ++j) { Layer2D layer1T = null, layer2T = null; if (0 == j && _constraintSet.AllowAlignedLayers && bResult1) { pattern.GenerateLayer(layer1, actualLength1, actualWidth1); layer1T = layer1; layer2T = layer1; layerAlignment = "aligned-1"; } else if (1 == j && _constraintSet.AllowAlignedLayers && bResult2) { pattern.GenerateLayer(layer2, actualLength2, actualWidth2); layer1T = layer2; layer2T = layer2; layerAlignment = "aligned-2"; } else if (2 == j && _constraintSet.AllowAlternateLayers && bResult1 && bResult2) { pattern.GenerateLayer(layer1, Math.Max(actualLength1, actualLength2), Math.Max(actualWidth1, actualWidth2)); pattern.GenerateLayer(layer2, Math.Max(actualLength1, actualLength2), Math.Max(actualWidth1, actualWidth2)); layer1T = layer1; layer2T = layer2; layerAlignment = "alternate-12"; } else if (3 == j && _constraintSet.AllowAlternateLayers && bResult1 && bResult2) { pattern.GenerateLayer(layer1, Math.Max(actualLength1, actualLength2), Math.Max(actualWidth1, actualWidth2)); pattern.GenerateLayer(layer2, Math.Max(actualLength1, actualLength2), Math.Max(actualWidth1, actualWidth2)); layer1T = layer2; layer2T = layer1; layerAlignment = "alternate-21"; } else if (4 == j && _constraintSet.AllowAlternateLayers && pattern.CanBeInverted && bResult1) { pattern.GenerateLayer(layer1, actualLength1, actualWidth1); pattern.GenerateLayer(layer1_inv, actualLength1, actualWidth1); layer1T = layer1; layer2T = layer1_inv; layerAlignment = "inv-1"; } else if (5 == j && _constraintSet.AllowAlternateLayers && pattern.CanBeInverted && bResult2) { pattern.GenerateLayer(layer2, actualLength2, actualWidth2); pattern.GenerateLayer(layer2_inv, actualLength2, actualWidth2); layer1T = layer2; layer2T = layer2_inv; layerAlignment = "inv-2"; } if (null == layer1T || null == layer2T || 0 == layer1T.Count || 0 == layer2T.Count) { continue; } // counters string axisName = string.Empty; switch (i) { case 0: axisName = "X"; break; case 1: axisName = "Y"; break; case 2: axisName = "Z"; break; default: break; } string title = string.Format("{0}-{1}-{2}{3}", pattern.Name, axisName, layerAlignment, swapPos == 1 ? "-swapped" : ""); CasePalletSolution sol = new CasePalletSolution(null, title, layer1T == layer2T); int iLayerIndex = 0; double zLayer = _palletProperties.Height; double capThickness = null != _capProperties ? _capProperties.Thickness : 0; int iInterlayer = 0; int iCount = 0; bool maxWeightReached = _constraintSet.UseMaximumPalletWeight && (_palletProperties.Weight + _bProperties.Weight > _constraintSet.MaximumPalletWeight); bool maxHeightReached = _constraintSet.UseMaximumHeight && (zLayer + capThickness + _bProperties.Dimension(axisOrtho1) > _constraintSet.MaximumHeight); bool maxNumberReached = false; // insert anti-slip interlayer id there is one if (_constraintSet.HasInterlayerAntiSlip) { InterlayerPos interlayerPos = sol.CreateNewInterlayer(zLayer, 1); zLayer += _interlayerPropertiesAntiSlip.Thickness; } while (!maxWeightReached && !maxHeightReached && !maxNumberReached) { if (_constraintSet.HasInterlayer) { if (iInterlayer >= _constraintSet.InterlayerPeriod) { InterlayerPos interlayerPos = sol.CreateNewInterlayer(zLayer, 0); zLayer += _interlayerProperties.Thickness; iInterlayer = 0; } ++iInterlayer; } // select current layer type double cornerThickness = null != _cornerProperties ? _cornerProperties.Thickness : 0.0; Layer2D currentLayer = iLayerIndex % 2 == 0 ? layer1T : layer2T; Layer3DBox layer = sol.CreateNewLayer(zLayer, 0); layer.MaximumSpace = currentLayer.MaximumSpace; foreach (LayerPosition layerPos in currentLayer) { ++iCount; maxWeightReached = _constraintSet.UseMaximumPalletWeight && ((iCount * _bProperties.Weight + _palletProperties.Weight) > _constraintSet.MaximumPalletWeight); maxNumberReached = _constraintSet.UseMaximumNumberOfCases && (iCount > _constraintSet.MaximumNumberOfItems); if (!maxWeightReached && !maxNumberReached) { LayerPosition layerPosTemp = AdjustLayerPosition(layerPos); BoxPosition boxPos = new BoxPosition( layerPosTemp.Position - (0.5 * _constraintSet.OverhangX - cornerThickness) * Vector3D.XAxis - (0.5 * _constraintSet.OverhangY - cornerThickness) * Vector3D.YAxis + zLayer * Vector3D.ZAxis , layerPosTemp.LengthAxis , layerPosTemp.WidthAxis ); layer.Add(boxPos); } else { break; } } // increment layer index ++iLayerIndex; zLayer += currentLayer.BoxHeight; // check height maxHeightReached = _constraintSet.UseMaximumHeight && (zLayer + _bProperties.Dimension(axisOrtho1) > _constraintSet.MaximumHeight); // check number maxNumberReached = _constraintSet.UseMaximumNumberOfCases && (iCount + 1 > _constraintSet.MaximumNumberOfItems); // check weight maxWeightReached = _constraintSet.UseMaximumPalletWeight && (((iCount + 1) * _bProperties.Weight + _palletProperties.Weight) > _constraintSet.MaximumPalletWeight); } if (maxHeightReached && _constraintSet.AllowLastLayerOrientationChange) { // remaining height double remainingHeight = _constraintSet.MaximumHeight - zLayer; // test to complete with best layer Layer2D bestLayer = null; int ibestLayerCount = 0; for (int iLayerDir = 0; iLayerDir < 3; ++iLayerDir) { // another direction than the current direction if (iLayerDir == i) { continue; } Layer2D layer = bestLayers[iLayerDir]; if (null == layer) { continue; } int layerCount = Convert.ToInt32(Math.Floor(remainingHeight / layer.BoxHeight)); if (layerCount < 1) { continue; } if (null == bestLayer || ibestLayerCount * bestLayer.Count < layerCount * layer.Count) { bestLayer = layer; ibestLayerCount = layerCount; } } if (null != bestLayer) { double cornerThickness = null != _cornerProperties ? _cornerProperties.Thickness : 0.0; for (int iAddLayer = 0; iAddLayer < ibestLayerCount; ++iAddLayer) { Layer3DBox layer = sol.CreateNewLayer(zLayer, 0); foreach (LayerPosition layerPos in bestLayer) { LayerPosition layerPosTemp = AdjustLayerPosition(layerPos); BoxPosition boxPos = new BoxPosition( layerPosTemp.Position - (0.5 * _constraintSet.OverhangX - cornerThickness) * Vector3D.XAxis - (0.5 * _constraintSet.OverhangY - cornerThickness) * Vector3D.YAxis + zLayer * Vector3D.ZAxis , layerPosTemp.LengthAxis , layerPosTemp.WidthAxis ); layer.Add(boxPos); } zLayer += bestLayer.BoxHeight; } } } // set maximum criterion if (maxNumberReached) { sol.LimitReached = CasePalletSolution.Limit.LIMIT_MAXNUMBERREACHED; } else if (maxWeightReached) { sol.LimitReached = CasePalletSolution.Limit.LIMIT_MAXWEIGHTREACHED; } else if (maxHeightReached) { sol.LimitReached = CasePalletSolution.Limit.LIMIT_MAXHEIGHTREACHED; } // insert solution if (sol.Count > 0) { solutions.Add(sol); } } } catch (NotImplementedException) { _log.Info(string.Format("Pattern {0} is not implemented", pattern.Name)); } catch (Exception ex) { _log.Error(string.Format("Exception caught: {0}", ex.Message)); } } // loop through all vertical axes } // loop through all swap positions (if layer can be swapped) } // loop through all patterns // sort solutions solutions.Sort(); if (ConstraintSet.AllowTwoLayerOrientations && solutions.Count > 0) { // get best solution count int iBestSolutionCount = solutions[0].CaseCount; // if solutions exceeds List <CasePalletSolution> multiOrientSolution = GenerateOptimizedCombinationOfLayers(); foreach (CasePalletSolution sol in multiOrientSolution) { if (sol.CaseCount > iBestSolutionCount) { solutions.Add(sol); } } solutions.Sort(); } // remove unwanted solutions if (_constraintSet.UseNumberOfSolutionsKept && solutions.Count > _constraintSet.NumberOfSolutionsKept) { // get minimum box count int minBoxCount = solutions[_constraintSet.NumberOfSolutionsKept].CaseCount; // remove any solution with less boxes than minBoxCount while (solutions[solutions.Count - 1].CaseCount < minBoxCount) { solutions.RemoveAt(solutions.Count - 1); } } return(solutions); }
public void SaveCasePalletSolution(CasePalletAnalysis analysis, CasePalletSolution sol, SelCasePalletSolution selSolution, bool unique, XmlElement solutionsElt, XmlDocument xmlDoc) { // Solution XmlElement solutionElt = xmlDoc.CreateElement("Solution"); solutionsElt.AppendChild(solutionElt); // title XmlAttribute titleAttribute = xmlDoc.CreateAttribute("Title"); titleAttribute.Value = sol.Title; solutionElt.Attributes.Append(titleAttribute); // homogeneousLayers ? XmlAttribute homogeneousLayersAttribute = xmlDoc.CreateAttribute("HomogeneousLayers"); homogeneousLayersAttribute.Value = sol.HasHomogeneousLayers ? "true" : "false"; solutionElt.Attributes.Append(homogeneousLayersAttribute); // limit XmlAttribute limitReached = xmlDoc.CreateAttribute("LimitReached"); limitReached.Value = string.Format("{0}", (int)sol.LimitReached); solutionElt.Attributes.Append(limitReached); // layers XmlElement layersElt = xmlDoc.CreateElement("Layers"); solutionElt.AppendChild(layersElt); foreach (ILayer layer in sol) { BoxLayer boxLayer = layer as BoxLayer; if (null != boxLayer) Save(boxLayer, layersElt, xmlDoc); InterlayerPos interlayerPos = layer as InterlayerPos; if (null != interlayerPos) { // Interlayer XmlElement interlayerElt = xmlDoc.CreateElement("Interlayer"); layersElt.AppendChild(interlayerElt); // ZLow XmlAttribute zlowAttribute = xmlDoc.CreateAttribute("ZLow"); zlowAttribute.Value = string.Format(System.Globalization.CultureInfo.InvariantCulture, "{0}", interlayerPos.ZLow); interlayerElt.Attributes.Append(zlowAttribute); } } // Is selected ? if (null != selSolution) { // selected attribute XmlAttribute selAttribute = xmlDoc.CreateAttribute("Selected"); selAttribute.Value = "true"; solutionElt.Attributes.Append(selAttribute); // truck analyses XmlElement truckAnalysesElt = xmlDoc.CreateElement("TruckAnalyses"); solutionElt.AppendChild(truckAnalysesElt); foreach (TruckAnalysis truckAnalysis in selSolution.TruckAnalyses) Save(truckAnalysis, unique, truckAnalysesElt, xmlDoc); // ect analyses XmlElement ectAnalysesElt = xmlDoc.CreateElement("EctAnalyses"); solutionElt.AppendChild(ectAnalysesElt); foreach (ECTAnalysis ectAnalysis in selSolution.EctAnalyses) Save(ectAnalysis, unique, ectAnalysesElt, xmlDoc); } }
public CasePalletSolutionViewer(CasePalletSolution solution) { _analysis = null != solution ? solution.Analysis : null; _solution = solution; }
private CasePalletSolution LoadCasePalletSolution(XmlElement eltSolution) { // title -> instantiation string stitle = eltSolution.Attributes["Title"].Value; CasePalletSolution sol = new CasePalletSolution(null, stitle, true); // homogeneous layers if (eltSolution.HasAttribute("HomogeneousLayers")) { string sHomogeneousLayers = eltSolution.Attributes["HomogeneousLayers"].Value; sol.HasHomogeneousLayers = string.Equals(sHomogeneousLayers, "true", StringComparison.CurrentCultureIgnoreCase); } else sol.HasHomogeneousLayers = false; // limit reached if (eltSolution.HasAttribute("LimitReached")) { string sLimitReached = eltSolution.Attributes["LimitReached"].Value; sol.LimitReached = (CasePalletSolution.Limit)(int.Parse(sLimitReached)); } // layers XmlElement eltLayers = eltSolution.ChildNodes[0] as XmlElement; foreach (XmlNode nodeLayer in eltLayers.ChildNodes) sol.Add( LoadLayer(nodeLayer as XmlElement)); return sol; }
private void AppendCaseOfBoxesElement(CasePalletAnalysis analysis, CasePalletSolution sol, XmlElement elemPalletAnalysis, XmlDocument xmlDoc) { string ns = xmlDoc.DocumentElement.NamespaceURI; // get CaseOfBoxProperties CaseOfBoxesProperties caseOfBoxes = analysis.BProperties as CaseOfBoxesProperties; if (null == caseOfBoxes) return; // elemCaseOfBoxes XmlElement elemCaseOfBoxes = xmlDoc.CreateElement("caseOfBoxes", ns); elemPalletAnalysis.AppendChild(elemCaseOfBoxes); // name XmlElement elemName = xmlDoc.CreateElement("name", ns); elemName.InnerText = caseOfBoxes.Name; elemCaseOfBoxes.AppendChild(elemName); // description XmlElement elemDescription = xmlDoc.CreateElement("description", ns); elemDescription.InnerText = caseOfBoxes.Description; elemCaseOfBoxes.AppendChild(elemDescription); // length XmlElement elemNoX = xmlDoc.CreateElement("noX", ns); elemNoX.InnerText = string.Format("{0}", caseOfBoxes.CaseDefinition.Arrangement._iLength); elemCaseOfBoxes.AppendChild(elemNoX); // width XmlElement elemNoY = xmlDoc.CreateElement("noY", ns); elemNoY.InnerText = string.Format("{0}", caseOfBoxes.CaseDefinition.Arrangement._iWidth); elemCaseOfBoxes.AppendChild(elemNoY); // height XmlElement elemNoZ = xmlDoc.CreateElement("noZ", ns); elemNoZ.InnerText = string.Format("{0}", caseOfBoxes.CaseDefinition.Arrangement._iHeight); elemCaseOfBoxes.AppendChild(elemNoZ); // number of boxes XmlElement elemNoBoxes = xmlDoc.CreateElement("numberOfBoxes", ns); elemNoBoxes.InnerText = string.Format("{0}", caseOfBoxes.NumberOfBoxes); elemCaseOfBoxes.AppendChild(elemNoBoxes); // dim0 XmlElement eltDim0 = xmlDoc.CreateElement("dim0", ns); eltDim0.InnerText = string.Format("{0}", caseOfBoxes.CaseDefinition.Dim0); elemCaseOfBoxes.AppendChild(eltDim0); // dim1 XmlElement eltDim1 = xmlDoc.CreateElement("dim1", ns); eltDim1.InnerText = string.Format("{0}", caseOfBoxes.CaseDefinition.Dim1); elemCaseOfBoxes.AppendChild(eltDim1); AppendElementValue(xmlDoc, elemCaseOfBoxes, "innerLength", UnitsManager.UnitType.UT_LENGTH, caseOfBoxes.InsideLength); AppendElementValue(xmlDoc, elemCaseOfBoxes, "innerWidth", UnitsManager.UnitType.UT_LENGTH, caseOfBoxes.InsideWidth); AppendElementValue(xmlDoc, elemCaseOfBoxes, "innerHeight", UnitsManager.UnitType.UT_LENGTH, caseOfBoxes.InsideHeight); AppendElementValue(xmlDoc, elemCaseOfBoxes, "innerVolume", UnitsManager.UnitType.UT_VOLUME, caseOfBoxes.InsideVolume * UnitsManager.FactorCubeLengthToVolume); AppendElementValue(xmlDoc, elemCaseOfBoxes, "outerLength", UnitsManager.UnitType.UT_LENGTH, caseOfBoxes.Length); AppendElementValue(xmlDoc, elemCaseOfBoxes, "outerWidth", UnitsManager.UnitType.UT_LENGTH, caseOfBoxes.Width); AppendElementValue(xmlDoc, elemCaseOfBoxes, "outerHeight", UnitsManager.UnitType.UT_LENGTH, caseOfBoxes.Height); AppendElementValue(xmlDoc, elemCaseOfBoxes, "outerVolume", UnitsManager.UnitType.UT_VOLUME, caseOfBoxes.Volume * UnitsManager.FactorCubeLengthToVolume); AppendElementValue(xmlDoc, elemCaseOfBoxes, "emptyWeight", UnitsManager.UnitType.UT_MASS, caseOfBoxes.WeightEmpty); AppendElementValue(xmlDoc, elemCaseOfBoxes, "weight", UnitsManager.UnitType.UT_MASS, caseOfBoxes.Weight); // type converter TypeConverter converter = TypeDescriptor.GetConverter(typeof(Bitmap)); // view case of boxes iso1 Graphics3DImage graphics1 = new Graphics3DImage(new Size(ImageSizeDetail, ImageSizeDetail)); graphics1.CameraPosition = Graphics3D.Corner_0; CaseDefinitionViewer viewer = new CaseDefinitionViewer(caseOfBoxes.CaseDefinition, caseOfBoxes.InsideBoxProperties, caseOfBoxes.CaseOptimConstraintSet); viewer.CaseProperties = caseOfBoxes; viewer.Orientation = sol.FirstCaseOrientation; viewer.Draw(graphics1); graphics1.Flush(); // view case of boxes iso2 Graphics3DImage graphics2 = new Graphics3DImage(new Size(ImageSizeDetail, ImageSizeDetail)); graphics2.CameraPosition = Graphics3D.Corner_0; Box box = new Box(0, caseOfBoxes); graphics2.AddBox(box); graphics2.AddDimensions(new DimensionCube(caseOfBoxes.Length, caseOfBoxes.Width, caseOfBoxes.Height)); graphics2.Flush(); // view_caseOfBoxes_iso1 XmlElement elemImage1 = xmlDoc.CreateElement("view_caseOfBoxes_iso1", ns); elemImage1.InnerText = Convert.ToBase64String((byte[])converter.ConvertTo(graphics1.Bitmap, typeof(byte[]))); XmlAttribute styleAttribute1 = xmlDoc.CreateAttribute("style"); styleAttribute1.Value = string.Format("width:{0}pt;height:{1}pt", graphics1.Bitmap.Width / 3, graphics1.Bitmap.Height / 3); elemImage1.Attributes.Append(styleAttribute1); elemCaseOfBoxes.AppendChild(elemImage1); // save image SaveImageAs(graphics1.Bitmap, "view_caseOfBoxes_iso1.png"); // view_caseOfBoxes_iso2 XmlElement elemImage2 = xmlDoc.CreateElement("view_caseOfBoxes_iso2", ns); elemImage2.InnerText = Convert.ToBase64String((byte[])converter.ConvertTo(graphics2.Bitmap, typeof(byte[]))); XmlAttribute styleAttribute2 = xmlDoc.CreateAttribute("style"); styleAttribute2.Value = string.Format("width:{0}pt;height:{1}pt", graphics2.Bitmap.Width / 3, graphics2.Bitmap.Height / 3); elemImage2.Attributes.Append(styleAttribute2); elemCaseOfBoxes.AppendChild(elemImage2); // save image SaveImageAs(graphics2.Bitmap, "view_caseOfBoxes_iso2.png"); }