Beispiel #1
0
        /// <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));
                }
            }
        }
        /// <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...
        }
        /// <summary>
        /// Use this method when drawing a solution that belongs an analysis
        /// </summary>
        /// <param name="graphics"></param>
        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);
            }
            // load bounding box
            BBox3D loadBBox      = _solution.LoadBoundingBox;
            BBox3D loadBBoxWDeco = _solution.LoadBoundingBoxWDeco;

            #region Pallet film : begin
            // draw film
            Film film = null;
            if (_solution.Analysis.HasPalletFilm)
            {
                PalletFilmProperties palletFilmProperties = _solution.Analysis.PalletFilmProperties;
                film = new Film(
                    palletFilmProperties.Color,
                    palletFilmProperties.UseTransparency,
                    palletFilmProperties.UseHatching,
                    palletFilmProperties.HatchSpacing,
                    palletFilmProperties.HatchAngle);
                film.AddRectangle(new FilmRectangle(loadBBoxWDeco.PtMin,
                                                    HalfAxis.HAxis.AXIS_X_P, HalfAxis.HAxis.AXIS_Z_P, new Vector2D(loadBBoxWDeco.Length, loadBBoxWDeco.Height), 0.0));
                film.AddRectangle(new FilmRectangle(loadBBoxWDeco.PtMin + loadBBoxWDeco.Length * Vector3D.XAxis,
                                                    HalfAxis.HAxis.AXIS_Y_P, HalfAxis.HAxis.AXIS_Z_P, new Vector2D(loadBBoxWDeco.Width, loadBBoxWDeco.Height), 0.0));
                film.AddRectangle(new FilmRectangle(loadBBoxWDeco.PtMin + loadBBoxWDeco.Length * Vector3D.XAxis + loadBBoxWDeco.Width * Vector3D.YAxis,
                                                    HalfAxis.HAxis.AXIS_X_N, HalfAxis.HAxis.AXIS_Z_P, new Vector2D(loadBBoxWDeco.Length, loadBBoxWDeco.Height), 0.0));
                film.AddRectangle(new FilmRectangle(loadBBoxWDeco.PtMin + loadBBoxWDeco.Width * Vector3D.YAxis,
                                                    HalfAxis.HAxis.AXIS_Y_N, HalfAxis.HAxis.AXIS_Z_P, new Vector2D(loadBBoxWDeco.Width, loadBBoxWDeco.Height), 0.0));
                film.AddRectangle(new FilmRectangle(loadBBoxWDeco.PtMin + loadBBoxWDeco.Height * Vector3D.ZAxis,
                                                    HalfAxis.HAxis.AXIS_X_P, HalfAxis.HAxis.AXIS_Y_P, new Vector2D(loadBBoxWDeco.Length, loadBBoxWDeco.Width),
                                                    UnitsManager.ConvertLengthFrom(200.0, UnitsManager.UnitSystem.UNIT_METRIC1)));
                film.DrawBegin(graphics);
            }
            #endregion

            #region Pallet corners
            // *** pallet corners
            // positions
            Vector3D[] cornerPositions =
            {
                loadBBox.PtMin
                , new Vector3D(loadBBox.PtMax.X, loadBBox.PtMin.Y, loadBBox.PtMin.Z)
                , new Vector3D(loadBBox.PtMax.X, loadBBox.PtMax.Y, loadBBox.PtMin.Z)
                , new Vector3D(loadBBox.PtMin.X, loadBBox.PtMax.Y, loadBBox.PtMin.Z)
            };
            // length axes
            HalfAxis.HAxis[] lAxes =
            {
                HalfAxis.HAxis.AXIS_X_P,
                HalfAxis.HAxis.AXIS_Y_P,
                HalfAxis.HAxis.AXIS_X_N,
                HalfAxis.HAxis.AXIS_Y_N
            };
            // width axes
            HalfAxis.HAxis[] wAxes =
            {
                HalfAxis.HAxis.AXIS_Y_P,
                HalfAxis.HAxis.AXIS_X_N,
                HalfAxis.HAxis.AXIS_Y_N,
                HalfAxis.HAxis.AXIS_X_P
            };
            // corners
            Corner[] corners = new Corner[4];
            if (_solution.Analysis.HasPalletCorners)
            {
                for (int i = 0; i < 4; ++i)
                {
                    corners[i]        = new Corner(0, _solution.Analysis.PalletCornerProperties);
                    corners[i].Height = Math.Min(_solution.Analysis.PalletCornerProperties.Length, loadBBox.Height);
                    corners[i].SetPosition(cornerPositions[i], lAxes[i], wAxes[i]);
                    corners[i].DrawBegin(graphics);
                }
            }
            // *** pallet corners : end
            #endregion

            // 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++, _analysis.BProperties, bPosition));
                    }
                }

                InterlayerPos interlayerPos = layer as InterlayerPos;
                if (null != interlayerPos)
                {
                    InterlayerProperties currInterlayerProperties = (0 == interlayerPos.TypeId)
                        ? _analysis.InterlayerProperties : _analysis.InterlayerPropertiesAntiSlip;
                    Box box = new Box(pickId++, currInterlayerProperties);
                    // set position
                    box.Position = new Vector3D(
                        0.5 * (_analysis.PalletProperties.Length - currInterlayerProperties.Length)
                        , 0.5 * (_analysis.PalletProperties.Width - currInterlayerProperties.Width)
                        , interlayerPos.ZLow);
                    // draw
                    graphics.AddBox(box);
                }
            }

            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));
            }

            // pallet corners
            if (_solution.Analysis.HasPalletCorners)
            {
                for (int i = 0; i < 4; ++i)
                {
                    corners[i].DrawEnd(graphics);
                }
            }
            // pallet cap
            if (_solution.HasPalletCap)
            {
                PalletCapProperties capProperties = _solution.Analysis.PalletCapProperties;
                Vector3D            pos           = new Vector3D(
                    0.5 * (_analysis.PalletProperties.Length - capProperties.Length),
                    0.5 * (_analysis.PalletProperties.Width - capProperties.Width),
                    loadBBox.PtMax.Z - capProperties.InsideHeight);
                PalletCap cap = new PalletCap(0, capProperties, pos);
                cap.DrawEnd(graphics);
            }
            // pallet film
            if (_solution.Analysis.HasPalletFilm)
            {
                film.DrawEnd(graphics);
            }
            graphics.EnableFaceSorting = false;
        }
Beispiel #5
0
        /// <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));
            }
        }
        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);
        }
Beispiel #7
0
        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;
        }
Beispiel #8
0
        public override void Draw(Graphics3D graphics, Transform3D transform)
        {
            // clear list of picking box
            ClearPickingBoxes();

            if (null == _solution)
            {
                return;
            }
            Analysis               analysis               = _solution.Analysis;
            AnalysisCasePallet     analysisCasePallet     = analysis as AnalysisCasePallet;
            AnalysisBoxCase        analysisBoxCase        = analysis as AnalysisBoxCase;
            AnalysisCylinderCase   analysisCylinderCase   = analysis as AnalysisCylinderCase;
            AnalysisCylinderPallet analysisCylinderPallet = analysis as AnalysisCylinderPallet;
            AnalysisPalletTruck    analysisPalletTruck    = analysis as AnalysisPalletTruck;
            AnalysisCaseTruck      analysisCaseTruck      = analysis as AnalysisCaseTruck;

            if (null != analysisCasePallet)
            {
                // ### draw pallet
                Pallet pallet = new Pallet(analysisCasePallet.PalletProperties);
                pallet.Draw(graphics, transform);
            }
            else if (null != analysisBoxCase)
            {
                // draw case (inside)
                Case case_ = new Case(analysisBoxCase.CaseProperties);
                case_.DrawInside(graphics, transform);
            }
            else if (null != analysisCylinderCase)
            {
                // ### draw case (inside)
                Case case_ = new Case(analysisCylinderCase.CaseProperties);
                case_.DrawInside(graphics, transform);
            }
            else if (null != analysisCylinderPallet)
            {
                // ### draw pallet
                Pallet pallet = new Pallet(analysisCylinderPallet.PalletProperties);
                pallet.Draw(graphics, transform);
            }
            else if (null != analysisPalletTruck)
            {
                // ### draw truck
                Truck truck = new Truck(analysisPalletTruck.TruckProperties);
                truck.DrawBegin(graphics);
            }
            else if (null != analysisCaseTruck)
            {
                // ### draw truck
                Truck truck = new Truck(analysisCaseTruck.TruckProperties);
                truck.DrawBegin(graphics);
            }

            // ### draw solution
            uint          layerId = 0, pickId = 0;
            List <ILayer> layers = _solution.Layers;

            foreach (ILayer layer in layers)
            {
                BBox3D bbox = new BBox3D();
                // ### layer of boxes
                Layer3DBox layerBox = layer as Layer3DBox;
                if (null != layerBox)
                {
                    if (analysis.Content is LoadedPallet)
                    {
                        LoadedPallet loadedPallet = analysis.Content as LoadedPallet;
                        BBox3D       solBBox      = loadedPallet.ParentAnalysis.Solution.BBoxGlobal;
                        foreach (BoxPosition bPosition in layerBox)
                        {
                            bool simplified = false;
                            if (simplified)
                            {
                                BoxProperties bProperties = new BoxProperties(null, solBBox.Dimensions);
                                bProperties.SetColor(Color.Chocolate);
                                Box b = new Box(pickId++, bProperties, bPosition.Transform(transform));
                                graphics.AddBox(b);
                                bbox.Extend(b.BBox);
                            }
                            else
                            {
                                graphics.AddImage(loadedPallet.ParentAnalysis, solBBox.DimensionsVec, bPosition.Transform(transform));
                            }
                        }
                    }
                    else
                    {
                        foreach (BoxPosition bPosition in layerBox)
                        {
                            Box b = null;
                            if (analysis.Content is PackProperties)
                            {
                                b = new Pack(pickId++, analysis.Content as PackProperties, bPosition.Transform(transform));
                            }
                            else
                            {
                                b = new Box(pickId++, analysis.Content as PackableBrick, bPosition.Transform(transform));
                            }
                            graphics.AddBox(b);
                            bbox.Extend(b.BBox);
                        }
                    }
                }
                Layer3DCyl layerCyl = layer as Layer3DCyl;
                if (null != layerCyl)
                {
                    foreach (Vector3D vPos in layerCyl)
                    {
                        Cylinder c = new Cylinder(pickId++, analysis.Content as CylinderProperties, new CylPosition(transform.transform(vPos), HalfAxis.HAxis.AXIS_Z_P));
                        graphics.AddCylinder(c);
                        bbox.Extend(c.BBox);
                    }
                }
                if (null != layerBox || null != layerCyl)
                {
                    // add layer BBox
                    AddPickingBox(bbox, layerId);
                    // draw bounding box around selected layer
                    if (layerId == _solution.SelectedLayerIndex)
                    {
                        DrawLayerBoundingBox(graphics, bbox);
                    }
                    ++layerId;
                }

                // ### interlayer
                InterlayerPos interlayerPos = layer as InterlayerPos;
                if (null != interlayerPos)
                {
                    InterlayerProperties interlayerProp = _solution.Interlayers[interlayerPos.TypeId];
                    if (null != interlayerProp)
                    {
                        BoxPosition bPosition = new BoxPosition(
                            new Vector3D(
                                0.5 * (analysis.ContainerDimensions.X - interlayerProp.Length)
                                , 0.5 * (analysis.ContainerDimensions.Y - interlayerProp.Width)
                                , interlayerPos.ZLow
                                ), HalfAxis.HAxis.AXIS_X_P, HalfAxis.HAxis.AXIS_Y_P);
                        Box box = new Box(pickId++, interlayerProp, bPosition.Transform(transform));
                        graphics.AddBox(box);
                        bbox.Extend(box.BBox);
                    }
                }
            }
            BBox3D loadBBox      = _solution.BBoxLoad;
            BBox3D loadBBoxWDeco = _solution.BBoxLoadWDeco;

            if (null != analysisCasePallet)
            {
                #region Pallet corners
                // ### pallet corners : Begin
                Corner[] corners = new Corner[4];
                if (analysisCasePallet.HasPalletCorners)
                {
                    // positions
                    Vector3D[] cornerPositions =
                    {
                        loadBBox.PtMin
                        , new Vector3D(loadBBox.PtMax.X, loadBBox.PtMin.Y, loadBBox.PtMin.Z)
                        , new Vector3D(loadBBox.PtMax.X, loadBBox.PtMax.Y, loadBBox.PtMin.Z)
                        , new Vector3D(loadBBox.PtMin.X, loadBBox.PtMax.Y, loadBBox.PtMin.Z)
                    };
                    // length axes
                    HalfAxis.HAxis[] lAxes =
                    {
                        HalfAxis.HAxis.AXIS_X_P,
                        HalfAxis.HAxis.AXIS_Y_P,
                        HalfAxis.HAxis.AXIS_X_N,
                        HalfAxis.HAxis.AXIS_Y_N
                    };
                    // width axes
                    HalfAxis.HAxis[] wAxes =
                    {
                        HalfAxis.HAxis.AXIS_Y_P,
                        HalfAxis.HAxis.AXIS_X_N,
                        HalfAxis.HAxis.AXIS_Y_N,
                        HalfAxis.HAxis.AXIS_X_P
                    };
                    // corners
                    if (analysisCasePallet.HasPalletCorners)
                    {
                        for (int i = 0; i < 4; ++i)
                        {
                            corners[i]        = new Corner(0, analysisCasePallet.PalletCornerProperties);
                            corners[i].Height = Math.Min(analysisCasePallet.PalletCornerProperties.Length, loadBBox.Height);
                            corners[i].SetPosition(
                                transform.transform(cornerPositions[i])
                                , HalfAxis.Transform(lAxes[i], transform), HalfAxis.Transform(wAxes[i], transform)
                                );
                            corners[i].DrawBegin(graphics);
                        }
                    }
                }
                #endregion

                #region Pallet film
                // ### pallet film
                Film film = null;
                if (analysisCasePallet.HasPalletFilm)
                {
                    // instantiate film
                    PalletFilmProperties palletFilmProperties = analysisCasePallet.PalletFilmProperties;
                    film = new Film(
                        palletFilmProperties.Color,
                        palletFilmProperties.UseTransparency,
                        palletFilmProperties.UseHatching,
                        palletFilmProperties.HatchSpacing,
                        palletFilmProperties.HatchAngle);
                    film.AddRectangle(new FilmRectangle(transform.transform(loadBBoxWDeco.PtMin)
                                                        , HalfAxis.Transform(HalfAxis.HAxis.AXIS_X_P, transform), HalfAxis.Transform(HalfAxis.HAxis.AXIS_Z_P, transform)
                                                        , new Vector2D(loadBBoxWDeco.Length, loadBBoxWDeco.Height), 0.0));
                    film.AddRectangle(new FilmRectangle(transform.transform(loadBBoxWDeco.PtMin + loadBBoxWDeco.Length * Vector3D.XAxis)
                                                        , HalfAxis.Transform(HalfAxis.HAxis.AXIS_Y_P, transform), HalfAxis.Transform(HalfAxis.HAxis.AXIS_Z_P, transform)
                                                        , new Vector2D(loadBBoxWDeco.Width, loadBBoxWDeco.Height), 0.0));
                    film.AddRectangle(new FilmRectangle(transform.transform(loadBBoxWDeco.PtMin + loadBBoxWDeco.Length * Vector3D.XAxis + loadBBoxWDeco.Width * Vector3D.YAxis)
                                                        , HalfAxis.Transform(HalfAxis.HAxis.AXIS_X_N, transform), HalfAxis.Transform(HalfAxis.HAxis.AXIS_Z_P, transform)
                                                        , new Vector2D(loadBBoxWDeco.Length, loadBBoxWDeco.Height), 0.0));
                    film.AddRectangle(new FilmRectangle(transform.transform(loadBBoxWDeco.PtMin + loadBBoxWDeco.Width * Vector3D.YAxis)
                                                        , HalfAxis.Transform(HalfAxis.HAxis.AXIS_Y_N, transform), HalfAxis.Transform(HalfAxis.HAxis.AXIS_Z_P, transform)
                                                        , new Vector2D(loadBBoxWDeco.Width, loadBBoxWDeco.Height), 0.0));
                    film.AddRectangle(new FilmRectangle(transform.transform(loadBBoxWDeco.PtMin + loadBBoxWDeco.Height * Vector3D.ZAxis)
                                                        , HalfAxis.Transform(HalfAxis.HAxis.AXIS_X_P, transform), HalfAxis.Transform(HalfAxis.HAxis.AXIS_Y_P, transform)
                                                        , new Vector2D(loadBBoxWDeco.Length, loadBBoxWDeco.Width)
                                                        , UnitsManager.ConvertLengthFrom(200.0, UnitsManager.UnitSystem.UNIT_METRIC1)));
                    film.DrawBegin(graphics);
                }
                #endregion

                #region Pallet corners
                // pallet corners : End
                if (analysisCasePallet.HasPalletCorners)
                {
                    for (int i = 0; i < 4; ++i)
                    {
                        corners[i].DrawEnd(graphics);
                    }
                }
                #endregion

                #region Pallet Cap
                // ### pallet cap
                if (analysisCasePallet.HasPalletCap)
                {
                    PalletCapProperties capProperties = analysisCasePallet.PalletCapProperties;
                    BoxPosition         bPosition     = new BoxPosition(new Vector3D(
                                                                            0.5 * (analysisCasePallet.PalletProperties.Length - capProperties.Length),
                                                                            0.5 * (analysisCasePallet.PalletProperties.Width - capProperties.Width),
                                                                            loadBBox.PtMax.Z - capProperties.InsideHeight)
                                                                        , HalfAxis.Transform(HalfAxis.HAxis.AXIS_X_P, transform)
                                                                        , HalfAxis.Transform(HalfAxis.HAxis.AXIS_Y_P, transform)
                                                                        );
                    PalletCap cap = new PalletCap(0, capProperties, bPosition);
                    cap.DrawEnd(graphics);
                }
                #endregion

                #region Pallet film
                // pallet film : End
                if (analysisCasePallet.HasPalletFilm && null != film)
                {
                    film.DrawEnd(graphics);
                }
                #endregion
            }

            if (null != analysisPalletTruck)
            {
                Truck truck = new Truck(analysisPalletTruck.TruckProperties);
                truck.DrawEnd(graphics);
            }
            else if (null != analysisCaseTruck)
            {
                Truck truck = new Truck(analysisCaseTruck.TruckProperties);
                truck.DrawEnd(graphics);
            }

            // ### dimensions
            if (graphics.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 override void Draw(Graphics3D graphics, bool showDimensions)
        {
            // clear list of picking box
            ClearPickingBoxes();

            if (null == _solution)
            {
                return;
            }
            Analysis           analysis           = _solution.Analysis;
            AnalysisCasePallet analysisCasePallet = analysis as AnalysisCasePallet;
            AnalysisBoxCase    analysisBoxCase    = analysis as AnalysisBoxCase;

            if (null != analysisCasePallet)
            {
                // ### draw pallet
                Pallet pallet = new Pallet(analysisCasePallet.PalletProperties);
                pallet.Draw(graphics, Transform3D.Identity);
            }
            else if (null != analysisBoxCase)
            {
                // draw case (inside)
                Case case_ = new Case(analysisBoxCase._caseProperties);
                case_.DrawInside(graphics);
            }

            // ### draw solution
            uint          layerId = 0, pickId = 0;
            List <ILayer> layers = _solution.Layers;

            foreach (ILayer layer in layers)
            {
                // ### layer of boxes
                BoxLayer blayer = layer as BoxLayer;
                if (null != blayer)
                {
                    BBox3D bbox = new BBox3D();
                    foreach (BoxPosition bPosition in blayer)
                    {
                        Box b = null;
                        if (analysis.Content is PackProperties)
                        {
                            b = new Pack(pickId++, analysis.Content as PackProperties, bPosition);
                        }
                        else
                        {
                            b = new Box(pickId++, analysis.Content, bPosition);
                        }
                        graphics.AddBox(b);
                        bbox.Extend(b.BBox);
                    }
                    // add layer BBox
                    AddPickingBox(bbox, layerId);
                    // draw bounding box around selected layer
                    if (layerId == _solution.SelectedLayerIndex)
                    {
                        DrawLayerBoundingBox(graphics, bbox);
                    }
                    ++layerId;
                }
                // ### interlayer
                InterlayerPos interlayerPos = layer as InterlayerPos;
                if (null != interlayerPos)
                {
                    InterlayerProperties interlayerProp = _solution.Interlayers[interlayerPos.TypeId];
                    if (null != interlayerProp)
                    {
                        Box box = new Box(pickId++, interlayerProp);
                        box.Position = new Vector3D(
                            0.5 * (analysis.ContainerDimensions.X - interlayerProp.Length)
                            , 0.5 * (analysis.ContainerDimensions.Y - interlayerProp.Width)
                            , interlayerPos.ZLow
                            );
                        graphics.AddBox(box);
                    }
                }
            }
            BBox3D loadBBox      = _solution.BBoxLoad;
            BBox3D loadBBoxWDeco = _solution.BBoxLoadWDeco;

            if (null != analysisCasePallet)
            {
                #region Pallet corners
                // ### pallet corners : Begin
                Corner[] corners = new Corner[4];
                if (analysisCasePallet.HasPalletCorners)
                {
                    // positions
                    Vector3D[] cornerPositions =
                    {
                        loadBBox.PtMin
                        , new Vector3D(loadBBox.PtMax.X, loadBBox.PtMin.Y, loadBBox.PtMin.Z)
                        , new Vector3D(loadBBox.PtMax.X, loadBBox.PtMax.Y, loadBBox.PtMin.Z)
                        , new Vector3D(loadBBox.PtMin.X, loadBBox.PtMax.Y, loadBBox.PtMin.Z)
                    };
                    // length axes
                    HalfAxis.HAxis[] lAxes =
                    {
                        HalfAxis.HAxis.AXIS_X_P,
                        HalfAxis.HAxis.AXIS_Y_P,
                        HalfAxis.HAxis.AXIS_X_N,
                        HalfAxis.HAxis.AXIS_Y_N
                    };
                    // width axes
                    HalfAxis.HAxis[] wAxes =
                    {
                        HalfAxis.HAxis.AXIS_Y_P,
                        HalfAxis.HAxis.AXIS_X_N,
                        HalfAxis.HAxis.AXIS_Y_N,
                        HalfAxis.HAxis.AXIS_X_P
                    };
                    // corners
                    if (analysisCasePallet.HasPalletCorners)
                    {
                        for (int i = 0; i < 4; ++i)
                        {
                            corners[i]        = new Corner(0, analysisCasePallet.PalletCornerProperties);
                            corners[i].Height = Math.Min(analysisCasePallet.PalletCornerProperties.Length, loadBBox.Height);
                            corners[i].SetPosition(cornerPositions[i], lAxes[i], wAxes[i]);
                            corners[i].DrawBegin(graphics);
                        }
                    }
                }
                #endregion

                #region Pallet film
                // ### pallet film
                Film film = null;
                if (analysisCasePallet.HasPalletFilm)
                {
                    PalletFilmProperties palletFilmProperties = analysisCasePallet.PalletFilmProperties;
                    film = new Film(
                        palletFilmProperties.Color,
                        palletFilmProperties.UseTransparency,
                        palletFilmProperties.UseHatching,
                        palletFilmProperties.HatchSpacing,
                        palletFilmProperties.HatchAngle);
                    film.AddRectangle(new FilmRectangle(loadBBoxWDeco.PtMin,
                                                        HalfAxis.HAxis.AXIS_X_P, HalfAxis.HAxis.AXIS_Z_P, new Vector2D(loadBBoxWDeco.Length, loadBBoxWDeco.Height), 0.0));
                    film.AddRectangle(new FilmRectangle(loadBBoxWDeco.PtMin + loadBBoxWDeco.Length * Vector3D.XAxis,
                                                        HalfAxis.HAxis.AXIS_Y_P, HalfAxis.HAxis.AXIS_Z_P, new Vector2D(loadBBoxWDeco.Width, loadBBoxWDeco.Height), 0.0));
                    film.AddRectangle(new FilmRectangle(loadBBoxWDeco.PtMin + loadBBoxWDeco.Length * Vector3D.XAxis + loadBBoxWDeco.Width * Vector3D.YAxis,
                                                        HalfAxis.HAxis.AXIS_X_N, HalfAxis.HAxis.AXIS_Z_P, new Vector2D(loadBBoxWDeco.Length, loadBBoxWDeco.Height), 0.0));
                    film.AddRectangle(new FilmRectangle(loadBBoxWDeco.PtMin + loadBBoxWDeco.Width * Vector3D.YAxis,
                                                        HalfAxis.HAxis.AXIS_Y_N, HalfAxis.HAxis.AXIS_Z_P, new Vector2D(loadBBoxWDeco.Width, loadBBoxWDeco.Height), 0.0));
                    film.AddRectangle(new FilmRectangle(loadBBoxWDeco.PtMin + loadBBoxWDeco.Height * Vector3D.ZAxis,
                                                        HalfAxis.HAxis.AXIS_X_P, HalfAxis.HAxis.AXIS_Y_P, new Vector2D(loadBBoxWDeco.Length, loadBBoxWDeco.Width),
                                                        UnitsManager.ConvertLengthFrom(200.0, UnitsManager.UnitSystem.UNIT_METRIC1)));
                    film.DrawBegin(graphics);
                }
                #endregion

                #region Pallet corners
                // pallet corners : End
                if (analysisCasePallet.HasPalletCorners)
                {
                    for (int i = 0; i < 4; ++i)
                    {
                        corners[i].DrawEnd(graphics);
                    }
                }
                #endregion

                #region Pallet Cap
                // ### pallet cap
                if (analysisCasePallet.HasPalletCap)
                {
                    PalletCapProperties capProperties = analysisCasePallet.PalletCapProperties;
                    Vector3D            pos           = new Vector3D(
                        0.5 * (analysisCasePallet.PalletProperties.Length - capProperties.Length),
                        0.5 * (analysisCasePallet.PalletProperties.Width - capProperties.Width),
                        loadBBox.PtMax.Z - capProperties.InsideHeight);
                    PalletCap cap = new PalletCap(0, capProperties, pos);
                    cap.DrawEnd(graphics);
                }
                #endregion

                #region Pallet film
                // pallet film : End
                if (analysisCasePallet.HasPalletFilm)
                {
                    film.DrawEnd(graphics);
                }
                #endregion
            }

            // ### dimensions
            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));
            }
        }
Beispiel #10
0
        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);
        }