private void OnEditLayer(object sender, EventArgs e)
 {
     try
     {
         // get content
         if (!(cbCases.SelectedType is Packable packable))
         {
             return;
         }
         // get container
         var      constraintSet = BuildConstraintSet();
         Vector2D layerDim      = new Vector2D(SelectedPallet.Length, SelectedPallet.Width) + 2 * constraintSet.Overhang;
         // get selected layer
         ILayer2D[] layers = uCtrlLayerList.Selected;
         if (layers.Length != 1)
         {
             return;
         }
         Layer2DBrickImp layer = layers[0] as Layer2DBrickImp;
         using (var form = new FormEditLayer(layer.GenerateLayer2DEdited(), packable))
         {
             form.TopMost = true;
             if (DialogResult.OK == form.ShowDialog())
             {
                 _layersEditable.Add(form.Layer);
                 FillEditedLayerList();
             }
         }
     }
     catch (Exception ex)
     {
         _log.Error(ex.ToString());
     }
 }
Пример #2
0
        public override void OnNext()
        {
            try
            {
                Layer2DBrickImp selLayer = SelectedLayer;
                var layerEncaps = new List<LayerEncap>() { new LayerEncap(selLayer.LayerDescriptor) };
                SolutionLayered.SetSolver(new LayerSolver());
                AnalysisCasePallet analysis = AnalysisCast;
                if (null == analysis)
                    _item = _document.CreateNewAnalysisCasePallet(
                        ItemName, ItemDescription
                        , SelectedPackable, SelectedPallet
                        , new List<InterlayerProperties>()
                        , null, null, null
                        , BuildConstraintSet()
                        , layerEncaps
                        );
                else
                {
                    analysis.ID.SetNameDesc(ItemName, ItemDescription);
                    analysis.Content = SelectedPackable;
                    analysis.PalletProperties = SelectedPallet;
                    analysis.ConstraintSet = BuildConstraintSet();
                    analysis.AddSolution(layerEncaps);

                    _document.UpdateAnalysis(analysis);
                }
                Close();
            }
            catch (Exception ex)
            {
                _log.Error(ex.ToString());
            }
        }
Пример #3
0
        public ILayer2D BuildLayer(Packable packable, Vector2D dimContainer, LayerDesc layerDesc, Vector2D actualDimensions, double minSpace)
        {
            ILayer2D     layer   = null;
            LayerPattern pattern = null;

            if (packable.IsBrick)
            {
                LayerDescBox layerDescBox = layerDesc as LayerDescBox;
                // instantiate layer
                layer = new Layer2DBrickImp(packable.OuterDimensions, dimContainer, layerDescBox.PatternName, layerDescBox.AxisOrtho, layerDesc.Swapped)
                {
                    ForcedSpace = minSpace
                };
                // get layer pattern
                pattern = LayerPatternBox.GetByName(layerDesc.PatternName);
            }
            else if (packable.IsCylinder)
            {
                var cylProperties = packable as RevSolidProperties;
                layer = new Layer2DCylImp(cylProperties.RadiusOuter, cylProperties.Height, dimContainer, layerDesc.Swapped);
                // get layer pattern
                pattern = LayerPatternCyl.GetByName(layerDesc.PatternName);
            }
            else
            {
                throw new EngineException(string.Format("Unexpected packable {0} (Type = {1})", packable.Name, packable.GetType().ToString()));
            }

            pattern.GenerateLayer(
                layer
                , layer.Swapped ? actualDimensions.Y : actualDimensions.X
                , layer.Swapped ? actualDimensions.X : actualDimensions.Y
                );
            return(layer);
        }
Пример #4
0
 private void FillLayerControls()
 {
     try
     {
         // get solution
         SolutionLayered solution = _analysis.SolutionLay;
         // packable
         cbLayerType.Packable = _analysis.Content;
         // build layers and fill CCtrl
         foreach (var layerEncap in solution.LayerEncaps)
         {
             if (null != layerEncap.Layer2D)
             {
                 cbLayerType.Items.Add(layerEncap.Layer2D);
             }
             else if (null != layerEncap.LayerDesc)
             {
                 LayerSolver     solver = new LayerSolver();
                 Layer2DBrickImp layer  = solver.BuildLayer(_analysis.ContentDimensions, _analysis.ContainerDimensions, layerEncap.LayerDesc as LayerDescBox, 0.0);
                 cbLayerType.Items.Add(layer);
             }
         }
         if (cbLayerType.Items.Count > 0)
         {
             cbLayerType.SelectedIndex = 0;
         }
     }
     catch (Exception ex)
     {
         _log.Error(ex.Message);
     }
 }
Пример #5
0
        public void Draw(Graphics3DControl ctrl, Graphics3D graphics)
        {
            Layer2DBrickImp selLayer = SelectedLayer;
            PalletProperties pallet = SelectedPallet;
            Packable packable = SelectedPackable;
            if (null == selLayer || null == packable || null == pallet)
                return;
            var analysis = new AnalysisCasePallet(packable, pallet, BuildConstraintSet(), true /*temporary*/);
            analysis.AddSolution(new List<LayerDesc> { selLayer.LayerDescriptor });

            ViewerSolution sv = new ViewerSolution(analysis.SolutionLay);
            sv.Draw(graphics, Transform3D.Identity);
        }
Пример #6
0
        /// <summary>
        /// Used to compute load dimension
        /// </summary>
        public bool GetDimensions(List <LayerDesc> layers, Packable packable, Vector2D dimContainer, double minSpace, ref Vector2D actualDimensions)
        {
            foreach (LayerDesc layerDesc in layers)
            {
                // dimensions
                double actualLength = 0.0, actualWidth = 0.0;

                if (packable.IsBrick)
                {
                    LayerDescBox layerDescBox = layerDesc as LayerDescBox;
                    // instantiate layer
                    var layer = new Layer2DBrickImp(packable.OuterDimensions, dimContainer, layerDescBox.PatternName, layerDescBox.AxisOrtho, layerDesc.Swapped)
                    {
                        ForcedSpace = minSpace
                    };
                    // get layer pattern
                    LayerPatternBox pattern = LayerPatternBox.GetByName(layerDesc.PatternName);
                    // dimensions
                    if (!pattern.GetLayerDimensionsChecked(layer, out actualLength, out actualWidth))
                    {
                        _log.Error(string.Format("Failed to get layer dimension : {0}", pattern.Name));
                        break;
                    }
                }
                else if (packable.IsCylinder)
                {
                    var cylProp = packable as RevSolidProperties;
                    // instantiate layer
                    var layer = new Layer2DCylImp(cylProp.RadiusOuter, cylProp.Height, dimContainer, layerDesc.Swapped);
                    // get layer pattern
                    LayerPatternCyl pattern = LayerPatternCyl.GetByName(layerDesc.PatternName);
                    // dimensions
                    if (!pattern.GetLayerDimensions(layer, out actualLength, out actualWidth))
                    {
                        _log.Error(string.Format("Failed to get layer dimension : {0}", pattern.Name));
                        break;
                    }
                }
                else
                {
                    throw new EngineException(string.Format("Unexpected packable {0} (Type = {1})", packable.Name, packable.GetType().ToString()));
                }

                actualDimensions.X = Math.Max(actualDimensions.X, layerDesc.Swapped ? actualWidth : actualLength);
                actualDimensions.Y = Math.Max(actualDimensions.Y, layerDesc.Swapped ? actualLength : actualWidth);
            }
            return(true);
        }
Пример #7
0
        public ILayer2D BuildLayer(Packable packable, Vector2D dimContainer, LayerDesc layerDesc, double minSpace)
        {
            ILayer2D layer = null;

            if (packable.IsBrick)
            {
                if (layerDesc is LayerDescBox layerDescBox)
                {
                    // layer instantiation
                    layer = new Layer2DBrickImp(packable.OuterDimensions, dimContainer, layerDesc.PatternName, layerDescBox.AxisOrtho, layerDesc.Swapped)
                    {
                        ForcedSpace = minSpace
                    };
                    // get layer pattern
                    LayerPatternBox pattern = LayerPatternBox.GetByName(layerDesc.PatternName);
                    // dimensions
                    if (!pattern.GetLayerDimensionsChecked(layer as Layer2DBrickImp, out double actualLength, out double actualWidth))
                    {
                        return(null);
                    }
                    pattern.GenerateLayer(
                        layer as Layer2DBrickImp
                        , actualLength
                        , actualWidth);
                }
                return(layer);
            }
            else if (packable.IsCylinder)
            {
                // casts
                var cylProperties = packable as RevSolidProperties;
                // layer instantiation
                layer = new Layer2DCylImp(cylProperties.RadiusOuter, cylProperties.Height, dimContainer, layerDesc.Swapped);
                // get layer pattern
                LayerPatternCyl pattern = LayerPatternCyl.GetByName(layerDesc.PatternName);
                if (!pattern.GetLayerDimensions(layer as Layer2DCylImp, out double actualLength, out double actualWidth))
                {
                    return(null);
                }
                pattern.GenerateLayer(layer as Layer2DCylImp, actualLength, actualWidth);
            }
            else
            {
                throw new EngineException(string.Format("Unexpected packable {0} (Type = {1})", packable.Name, packable.GetType().ToString()));
            }
            return(layer);
        }
Пример #8
0
        public Layer2DBrickImp BuildLayer(Vector3D dimBox, Vector2D dimContainer, LayerDescBox layerDesc, Vector2D actualDimensions, double minSpace)
        {
            // instantiate layer
            var layer = new Layer2DBrickImp(dimBox, dimContainer, layerDesc.PatternName, layerDesc.AxisOrtho, layerDesc.Swapped)
            {
                ForcedSpace = minSpace
            };
            // get layer pattern
            LayerPatternBox pattern = LayerPatternBox.GetByName(layerDesc.PatternName);

            // build layer
            pattern.GenerateLayer(
                layer
                , layer.Swapped ? actualDimensions.Y : actualDimensions.X
                , layer.Swapped ? actualDimensions.X : actualDimensions.Y);
            return(layer);
        }
Пример #9
0
        private static bool GetCount(Vector3D dimContent, double length, double width, LayerPattern pattern, bool swapped, double forcedSpace
                                     , ref int iCount, ref Vector2D actualDimensions)
        {
            // instantiate layer
            var layer = new Layer2DBrickImp(new Vector3D(dimContent.X, dimContent.Y, 0.0), Vector3D.Zero, new Vector2D(length, width), pattern.Name, HalfAxis.HAxis.AXIS_Z_P, swapped)
            {
                ForcedSpace = forcedSpace
            };

            if (!pattern.GetLayerDimensionsChecked(layer, out double actualLength, out double actualWidth))
            {
                return(false);
            }
            pattern.GenerateLayer(layer, actualLength, actualWidth);
            iCount           = layer.Count;
            actualDimensions = new Vector2D(actualLength, actualWidth);
            return(true);
        }
Пример #10
0
        private static bool GetBoxPositions(Vector3D dimContent, Vector2D dimContainer, LayerPattern pattern, bool swapped, double forcedSpace
                                            , out List <BoxPosition> boxPositions)
        {
            boxPositions = null;
            // instantiate layer
            var layer = new Layer2DBrickImp(new Vector3D(dimContent.X, dimContent.Y, 0.0), Vector3D.Zero, dimContainer, pattern.Name, HalfAxis.HAxis.AXIS_Z_P, swapped)
            {
                ForcedSpace = forcedSpace
            };

            if (!pattern.GetLayerDimensionsChecked(layer, out double actualLength, out double actualWidth))
            {
                return(false);
            }
            pattern.GenerateLayer(layer, actualLength, actualWidth);
            boxPositions = layer.Positions;
            return(true);
        }
Пример #11
0
        public Layer2DBrickImp BuildLayer(Vector3D dimBox, Vector2D dimContainer, LayerDescBox layerDesc, double minSpace)
        {
            LayerDescBox layerDescBox = layerDesc as LayerDescBox;
            // instantiate layer
            var layer = new Layer2DBrickImp(dimBox, dimContainer, layerDescBox.PatternName, layerDescBox.AxisOrtho, layerDesc.Swapped)
            {
                ForcedSpace = minSpace
            };
            // get layer pattern
            LayerPatternBox pattern = LayerPatternBox.GetByName(layerDesc.PatternName);

            // dimensions
            if (!pattern.GetLayerDimensionsChecked(layer, out double actualLength, out double actualWidth))
            {
                return(null);
            }
            pattern.GenerateLayer(
                layer
                , actualLength
                , actualWidth);
            return(layer);
        }
 private void OnEditLayer(object sender, EventArgs e)
 {
     try
     {
         if (!Program.IsSubscribed)
         {
             MessageBox.Show(Resources.ID_WARNINGEDITLAYER, Application.ProductName, MessageBoxButtons.OK);
         }
         // get content
         if (!(cbCases.SelectedType is Packable packable))
         {
             return;
         }
         // get container
         var      constraintSet = BuildConstraintSet();
         Vector2D layerDim      = new Vector2D(SelectedPallet.Length, SelectedPallet.Width) + 2 * constraintSet.Overhang;
         // get selected layer
         ILayer2D[] layers = uCtrlLayerList.Selected;
         if (layers.Length != 1)
         {
             return;
         }
         Layer2DBrickImp layer = layers[0] as Layer2DBrickImp;
         using (var form = new FormEditLayer(layer.GenerateLayer2DEdited(), packable))
         {
             form.TopMost = true;
             if (DialogResult.OK == form.ShowDialog())
             {
                 _layersEdited.Add(form.Layer);
                 FillEditedLayerList();
             }
         }
     }
     catch (Exception ex)
     {
         _log.Error(ex.ToString());
     }
 }
Пример #13
0
        public void AddPosition(ILayer2D layer, Vector2D vPosition, HalfAxis.HAxis lengthAxis, HalfAxis.HAxis widthAxis)
        {
            Matrix4D matRot       = Matrix4D.Identity;
            Vector3D vTranslation = Vector3D.Zero;

            if (layer.Swapped)
            {
                matRot = new Matrix4D(
                    0.0, -1.0, 0.0, 0.0
                    , 1.0, 0.0, 0.0, 0.0
                    , 0.0, 0.0, 1.0, 0.0
                    , 0.0, 0.0, 0.0, 1.0
                    );
                vTranslation = new Vector3D(layer.Length, 0.0, 0.0);
            }
            Transform3D transfRot = new Transform3D(matRot);

            HalfAxis.HAxis lengthAxisSwapped = HalfAxis.ToHalfAxis(transfRot.transform(HalfAxis.ToVector3D(lengthAxis)));
            HalfAxis.HAxis widthAxisSwapped  = HalfAxis.ToHalfAxis(transfRot.transform(HalfAxis.ToVector3D(widthAxis)));

            matRot.M14 = vTranslation[0];
            matRot.M24 = vTranslation[1];
            matRot.M34 = vTranslation[2];

            Transform3D transfRotTranslation = new Transform3D(matRot);
            Vector3D    vPositionSwapped     = transfRotTranslation.transform(new Vector3D(vPosition.X, vPosition.Y, 0.0));

            Layer2DBrickImp layerBox = layer as Layer2DBrickImp;

            if (!layerBox.IsValidPosition(new Vector2D(vPositionSwapped.X, vPositionSwapped.Y), lengthAxisSwapped, widthAxisSwapped))
            {
                _log.Warn(string.Format("Attempt to add an invalid position in pattern = {0}, Swapped = {1}", Name, layer.Swapped));
                return;
            }
            layerBox.AddPosition(new Vector2D(vPositionSwapped.X, vPositionSwapped.Y), lengthAxisSwapped, widthAxisSwapped);
        }
Пример #14
0
        public List <Layer2DBrickImp> BuildLayers(
            Vector3D dimBox, Vector2D dimContainer,
            double offsetZ, /* e.g. pallet height */
            ConstraintSetAbstract constraintSet, bool keepOnlyBest)
        {
            // instantiate list of layers
            var listLayers0 = new List <Layer2DBrickImp>();

            // loop through all patterns
            foreach (LayerPatternBox pattern in LayerPatternBox.All)
            {
                // loop through all orientation
                HalfAxis.HAxis[] patternAxes = pattern.IsSymetric ? HalfAxis.Positives : HalfAxis.All;
                foreach (HalfAxis.HAxis axisOrtho in patternAxes)
                {
                    // is orientation allowed
                    if (!constraintSet.AllowOrientation(Layer2DBrickImp.VerticalAxis(axisOrtho)))
                    {
                        continue;
                    }
                    // not swapped vs swapped pattern
                    for (int iSwapped = 0; iSwapped < 2; ++iSwapped)
                    {
                        try
                        {
                            // does swapping makes sense for this layer pattern ?
                            if (!pattern.CanBeSwapped && (iSwapped == 1))
                            {
                                continue;
                            }
                            // instantiate layer
                            var layer = new Layer2DBrickImp(dimBox, dimContainer, pattern.Name, axisOrtho, iSwapped == 1)
                            {
                                ForcedSpace = constraintSet.MinimumSpace.Value
                            };
                            if (layer.NoLayers(constraintSet.OptMaxHeight.Value) < 1)
                            {
                                continue;
                            }
                            if (!pattern.GetLayerDimensionsChecked(layer, out double actualLength, out double actualWidth))
                            {
                                continue;
                            }
                            pattern.GenerateLayer(layer, actualLength, actualWidth);
                            if (0 == layer.Count)
                            {
                                continue;
                            }
                            if (layer.CountInHeight(constraintSet.OptMaxHeight.Value - offsetZ) > 0)
                            {
                                listLayers0.Add(layer);
                            }
                        }
                        catch (Exception ex)
                        {
                            _log.ErrorFormat("Pattern: {0} Orient: {1} Swapped: {2} Message: {3}"
                                             , pattern.Name
                                             , axisOrtho.ToString()
                                             , iSwapped == 1 ? "true" : "false"
                                             , ex.Message);
                        }
                    }
                }
            }
            // keep only best layers
            if (keepOnlyBest)
            {
                // 1. get best count
                int bestCount = 0;
                foreach (Layer2DBrickImp layer in listLayers0)
                {
                    bestCount = Math.Max(layer.CountInHeight(constraintSet.OptMaxHeight.Value - offsetZ), bestCount);
                }

                // 2. remove any layer that does not match the best count given its orientation
                var listLayers1 = new List <Layer2DBrickImp>();
                foreach (Layer2DBrickImp layer in listLayers0)
                {
                    if (layer.CountInHeight(constraintSet.OptMaxHeight.Value - offsetZ) >= bestCount)
                    {
                        listLayers1.Add(layer);
                    }
                }
                // 3. copy back in original list
                listLayers0.Clear();
                listLayers0.AddRange(listLayers1);
            }
            if (constraintSet.OptMaxHeight.Activated)
            {
                listLayers0.Sort(new LayerComparerCount(constraintSet, offsetZ));
            }

            return(listLayers0);
        }
 public override int GetNumberOfVariants(Layer2DBrickImp layer) => 1;
Пример #16
0
        public static bool GetBestCombination(Vector3D dimBox, Vector3D dimContainer
                                              , ConstraintSetAbstract constraintSet
                                              , ref List <KeyValuePair <LayerEncap, int> > listLayer)
        {
            var layDescs = new LayerEncap[3];
            var counts   = new int[3] {
                0, 0, 0
            };
            var heights = new double[3] {
                0.0, 0.0, 0.0
            };
            Vector2D layerDim = new Vector2D(dimContainer.X, dimContainer.Y);

            // loop through all patterns
            foreach (LayerPatternBox pattern in LayerPatternBox.All)
            {
                // loop through all orientation
                HalfAxis.HAxis[] patternAxes = pattern.IsSymetric ? HalfAxis.Positives : HalfAxis.All;
                foreach (HalfAxis.HAxis axisOrtho in patternAxes)
                {
                    // is orientation allowed
                    if (!constraintSet.AllowOrientation(Layer2DBrickImp.VerticalAxis(axisOrtho)))
                    {
                        continue;
                    }
                    // not swapped vs swapped pattern
                    for (int iSwapped = 0; iSwapped < 2; ++iSwapped)
                    {
                        try
                        {
                            // does swapping makes sense for this layer pattern ?
                            if (!pattern.CanBeSwapped && (iSwapped == 1))
                            {
                                continue;
                            }
                            // instantiate layer
                            var layer = new Layer2DBrickImp(dimBox, layerDim, pattern.Name, axisOrtho, iSwapped == 1)
                            {
                                ForcedSpace = constraintSet.MinimumSpace.Value
                            };
                            if (layer.NoLayers(constraintSet.OptMaxHeight.Value) < 1)
                            {
                                continue;
                            }
                            if (!pattern.GetLayerDimensionsChecked(layer, out double actualLength, out double actualWidth))
                            {
                                continue;
                            }
                            pattern.GenerateLayer(layer, actualLength, actualWidth);
                            if (0 == layer.Count)
                            {
                                continue;
                            }
                            int iAxisIndex = layer.VerticalDirection;
                            if (layer.Count > counts[iAxisIndex])
                            {
                                counts[iAxisIndex]   = layer.Count;
                                layDescs[iAxisIndex] = new LayerEncap(layer.LayerDescriptor);
                                heights[iAxisIndex]  = layer.BoxHeight;
                            }
                        }
                        catch (Exception ex)
                        {
                            _log.Error($"Pattern: {pattern.Name} Orient: {axisOrtho.ToString()} Swapped: {iSwapped == 1} Message: {ex.Message}");
                        }
                    }
                }
            }
            double stackingHeight = dimContainer.Z;

            // single layer
            int indexIMax = 0, indexJMax = 0, noIMax = 0, noJMax = 0, iCountMax = 0;

            for (int i = 0; i < 3; ++i)
            {
                int noLayers = 0;
                if (counts[i] > 0)
                {
                    noLayers = (int)Math.Floor(stackingHeight / heights[i]);
                }
                if (counts[i] * noLayers > iCountMax)
                {
                    iCountMax = counts[i] * noLayers;
                    indexIMax = i;
                    noIMax    = noLayers;
                }
            }
            // layer combinations
            int[] comb1 = { 0, 1, 2 };
            int[] comb2 = { 1, 2, 0 };
            for (int i = 0; i < 3; ++i)
            {
                int iComb1 = comb1[i];
                int iComb2 = comb2[i];
                // --swap layers so that the thickest stays at the bottom
                if (heights[iComb2] > heights[iComb1])
                {
                    int iTemp = iComb1;
                    iComb1 = iComb2;
                    iComb2 = iTemp;
                }
                // --
                int noI = 0;
                if (counts[iComb1] != 0)
                {
                    noI = (int)Math.Floor(stackingHeight / heights[iComb1]);
                }
                // search all index
                while (noI > 0)
                {
                    double remainingHeight = stackingHeight - noI * heights[iComb1];
                    int    noJ             = 0;
                    if (counts[iComb2] != 0)
                    {
                        noJ = (int)Math.Floor(remainingHeight / heights[iComb2]);
                    }
                    if (noI * counts[iComb1] + noJ * counts[iComb2] > iCountMax)
                    {
                        indexIMax = iComb1;  indexJMax = iComb2;
                        noIMax    = noI;   noJMax = noJ;
                        iCountMax = noI * counts[iComb1] + noJ * counts[iComb2];
                    }
                    --noI;
                } // while
            }
            if (noIMax > 0)
            {
                listLayer.Add(new KeyValuePair <LayerEncap, int>(layDescs[indexIMax], noIMax));
            }
            if (noJMax > 0)
            {
                listLayer.Add(new KeyValuePair <LayerEncap, int>(layDescs[indexJMax], noJMax));
            }
            return(true);
        }
Пример #17
0
 public abstract int GetNumberOfVariants(Layer2DBrickImp layer);
Пример #18
0
        public bool OnFileNew(ref string fileName)
        {
            // INTEX data are in cms
            UnitsManager.CurrentUnitSystem = UnitsManager.UnitSystem.UNIT_METRIC2;

            string dbPath = Properties.Settings.Default.DatabasePathINTEX;

            if (string.IsNullOrWhiteSpace(dbPath) || !File.Exists(dbPath))
            {
                OpenFileDialog fd = new OpenFileDialog();
                fd.DefaultExt       = "xls";
                fd.AddExtension     = false;
                fd.Filter           = "Microsoft Excel File (*.xls)|*.xls|All files (*.*)|*.*";
                fd.FilterIndex      = 0;
                fd.RestoreDirectory = true;
                fd.CheckFileExists  = true;
                if (DialogResult.OK != fd.ShowDialog())
                {
                    return(false);
                }

                dbPath = fd.FileName;
                Properties.Settings.Default.DatabasePathINTEX = dbPath;
                Properties.Settings.Default.Save();
            }
            // load INTEX excel file
            List <DataItemINTEX>   listItems   = null;
            List <DataPalletINTEX> listPallets = null;
            List <DataCaseINTEX>   listCases   = null;

            try
            {
                // Set cursor as hourglass
                Cursor.Current = Cursors.WaitCursor;
                // load excel file
                if (!ExcelDataReader.ExcelDataReader.LoadIntexFile(dbPath, ref listItems, ref listPallets, ref listCases))
                {
                    Cursor.Current = Cursors.Default;
                    string message = string.Empty;
                    if (null == listItems || listItems.Count < 1)
                    {
                        message = string.Format(Properties.Resources.ID_ERROR_NOITEMFOUND, "article", "Articles");
                    }
                    else if (null == listPallets || listPallets.Count < 1)
                    {
                        message = string.Format(Properties.Resources.ID_ERROR_NOITEMFOUND, "palette", "Palettes");
                    }
                    else
                    {
                        message = string.Format(Properties.Resources.ID_ERROR_INVALIDFILE, dbPath);
                    }
                    if (!string.IsNullOrEmpty(message))
                    {
                        MessageBox.Show(message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    return(false);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(
                    ex.Message
                    , Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
                _log.Error(ex.Message);
            }
            finally
            { Cursor.Current = Cursors.Default; }
            // do we have a valid list
            if (null == listItems || 0 == listItems.Count)
            {
                return(false);
            }
            // proceed : buid project file
            try
            {
                FormNewINTEX form = new FormNewINTEX()
                {
                    ListItems   = listItems,
                    ListPallets = listPallets,
                    ListCases   = listCases
                };
                if (DialogResult.OK != form.ShowDialog())
                {
                    return(false);
                }
                // create document
                DataItemINTEX item     = form._currentItem;
                Document      document = new Document(item._ref, item._description, "INTEX", DateTime.Now, null);
                // create box properties
                Color[] colorsCase = new Color[6];
                for (int i = 0; i < 6; ++i)
                {
                    colorsCase[i] = Color.Chocolate;
                }
                BoxProperties itemProperties = null;
                if (!form.UseIntermediatePacking)
                {
                    itemProperties = document.CreateNewCase(
                        item._ref
                        , $"{item._description};EAN14 : {item._gencode};UPC : {item._UPC};PCB : {item._PCB}"
                        , UnitsManager.ConvertLengthFrom(item._length, UnitsManager.UnitSystem.UNIT_METRIC2)
                        , UnitsManager.ConvertLengthFrom(item._width, UnitsManager.UnitSystem.UNIT_METRIC2)
                        , UnitsManager.ConvertLengthFrom(item._height, UnitsManager.UnitSystem.UNIT_METRIC2)
                        , UnitsManager.ConvertMassFrom(item._weight, UnitsManager.UnitSystem.UNIT_METRIC2)
                        , colorsCase);
                }
                else
                {
                    itemProperties = document.CreateNewBox(
                        item._ref
                        , string.Format("{0};EAN14 : {1};UPC : {2};PCB : {3}", item._description, item._gencode, item._UPC, item._PCB)
                        , UnitsManager.ConvertLengthFrom(item._length, UnitsManager.UnitSystem.UNIT_METRIC2)
                        , UnitsManager.ConvertLengthFrom(item._width, UnitsManager.UnitSystem.UNIT_METRIC2)
                        , UnitsManager.ConvertLengthFrom(item._height, UnitsManager.UnitSystem.UNIT_METRIC2)
                        , UnitsManager.ConvertMassFrom(item._weight, UnitsManager.UnitSystem.UNIT_METRIC2)
                        , colorsCase);
                }
                itemProperties.TapeColor = Color.Beige;
                itemProperties.TapeWidth = new OptDouble(true, 5.0);
                InsertPictogram(ref itemProperties);

                BoxProperties currentCase = null;
                if (form.UseIntermediatePacking)
                {
                    // create cases
                    foreach (DataCaseINTEX dataCase in listCases)
                    {
                        double lengthInt = dataCase._lengthInt > 0 ? dataCase._lengthInt : dataCase._lengthExt - 2 * form.DefaultCaseThickness;
                        double widthInt  = dataCase._widthInt > 0 ? dataCase._widthInt : dataCase._widthExt - 2 * form.DefaultCaseThickness;
                        double heightInt = dataCase._heightInt > 0 ? dataCase._heightInt : dataCase._heightExt - 2 * form.DefaultCaseThickness;

                        BoxProperties intercaseProperties = document.CreateNewCase(
                            dataCase._ref
                            , string.Format("{0:0.0}*{1:0.0}*{2:0.0}", dataCase._lengthExt, dataCase._widthExt, dataCase._heightExt)
                            , UnitsManager.ConvertLengthFrom(dataCase._lengthExt, UnitsManager.UnitSystem.UNIT_METRIC2)
                            , UnitsManager.ConvertLengthFrom(dataCase._widthExt, UnitsManager.UnitSystem.UNIT_METRIC2)
                            , UnitsManager.ConvertLengthFrom(dataCase._heightExt, UnitsManager.UnitSystem.UNIT_METRIC2)
                            , UnitsManager.ConvertLengthFrom(lengthInt, UnitsManager.UnitSystem.UNIT_METRIC2)
                            , UnitsManager.ConvertLengthFrom(widthInt, UnitsManager.UnitSystem.UNIT_METRIC2)
                            , UnitsManager.ConvertLengthFrom(heightInt, UnitsManager.UnitSystem.UNIT_METRIC2)
                            , UnitsManager.ConvertMassFrom(dataCase._weight, UnitsManager.UnitSystem.UNIT_METRIC2)
                            , colorsCase);
                        intercaseProperties.TapeColor = Color.Beige;
                        intercaseProperties.TapeWidth = new OptDouble(true, 5.0);

                        if (string.Equals(form._currentCase._ref, intercaseProperties.Name))
                        {
                            currentCase = intercaseProperties;
                        }
                    }
                }

                // initialize Layer solver
                SolutionLayered.SetSolver(new LayerSolver());

                if (form.UseIntermediatePacking)
                {
                    // Case constraint set
                    ConstraintSetBoxCase constraintSetBoxCase = new ConstraintSetBoxCase(currentCase);
                    constraintSetBoxCase.AllowedOrientationsString = "1,1,1";
                    if (constraintSetBoxCase.Valid)
                    {
                        SolverBoxCase    solver     = new SolverBoxCase(itemProperties, currentCase);
                        Layer2DBrickImp  layer      = solver.BuildBestLayer(constraintSetBoxCase);
                        List <LayerDesc> layerDescs = new List <LayerDesc>();
                        if (null != layer)
                        {
                            layerDescs.Add(layer.LayerDescriptor);
                        }

                        // create case analysis
                        AnalysisLayered analysis = document.CreateNewAnalysisBoxCase(
                            string.Format(Properties.Resources.ID_PACKING, item._ref)
                            , item._description
                            , itemProperties
                            , currentCase
                            , null
                            , constraintSetBoxCase
                            , layerDescs);
                    }
                }

                // create pallets
                PalletProperties currentPallet = null;
                foreach (DataPalletINTEX pallet in listPallets)
                {
                    PalletProperties palletProperties = document.CreateNewPallet(
                        pallet._type, pallet._type, "EUR"
                        , UnitsManager.ConvertLengthFrom(pallet._length, UnitsManager.UnitSystem.UNIT_METRIC2)
                        , UnitsManager.ConvertLengthFrom(pallet._width, UnitsManager.UnitSystem.UNIT_METRIC2)
                        , UnitsManager.ConvertLengthFrom(pallet._height, UnitsManager.UnitSystem.UNIT_METRIC2)
                        , UnitsManager.ConvertMassFrom(pallet._weight, UnitsManager.UnitSystem.UNIT_METRIC2)
                        , Color.Gold);
                    if (string.Equals(form._currentPallet._type, pallet._type))
                    {
                        currentPallet = palletProperties;
                    }
                }

                // *** pallet analysis ***
                // constraint set
                ConstraintSetCasePallet constraintSet = new ConstraintSetCasePallet();
                constraintSet.SetMaxHeight(new OptDouble(true, UnitsManager.ConvertLengthFrom(form.PalletHeight, UnitsManager.UnitSystem.UNIT_METRIC2)));
                constraintSet.SetAllowedOrientations(new bool[] { false, false, true });
                if (constraintSet.Valid)
                {
                    SolverCasePallet solver     = new SolverCasePallet(form.UseIntermediatePacking ? currentCase : itemProperties, currentPallet);
                    Layer2DBrickImp  layer      = solver.BuildBestLayer(constraintSet);
                    List <LayerDesc> layerDescs = new List <LayerDesc>();
                    if (null != layer)
                    {
                        layerDescs.Add(layer.LayerDescriptor);
                    }

                    // create analysis
                    AnalysisLayered palletAnalysis = document.CreateNewAnalysisCasePallet(
                        item._ref, item.ToString()
                        , form.UseIntermediatePacking ? currentCase : itemProperties
                        , currentPallet,
                        null, null,
                        null, null,
                        constraintSet,
                        layerDescs);
                }
                // save document
                fileName = form.FilePath;
                document.Write(form.FilePath);

                if (null != OpenFile)
                {
                    OpenFile(fileName);
                }
                // return true to let application open
                return(File.Exists(fileName));
            }
            catch (Exception ex)
            {
                _log.Error(ex.Message);
                return(false);
            }
        }