private void BuildAnalyses(object status)
        {
            try
            {
                IProgressCallback callback = status as IProgressCallback;
                callback.SetRange(0, CheckedIndices.Count - 1);
                callback.Begin();

                int           expectedCount = uCtrlNumberPerCase.Value.Activated ? uCtrlNumberPerCase.Value.Value : -1;
                PackableBrick packable      = cbBoxes.SelectedType as PackableBrick;

                // build list of analyses
                for (int i = 0; i < CheckedIndices.Count; ++i)
                {
                    try
                    {
                        if (callback.IsAborting)
                        {
                            break;
                        }
                        callback.StepTo(i);
                        callback.SetText(string.Format(Resources.ID_EVALUATINGCASE, i + 1, CheckedIndices.Count));

                        if ((chklbCases.Items[CheckedIndices[i]] as ItemBaseCB).Item is BoxProperties caseProperties)
                        {
                            // build constraint set
                            ConstraintSetBoxCase constraintSet = new ConstraintSetBoxCase(caseProperties);
                            constraintSet.SetAllowedOrientations(uCtrlCaseOrient.AllowedOrientations);
                            if (uCtrlNumberPerCase.Value.Activated)
                            {
                                constraintSet.SetMaxNumber(uCtrlNumberPerCase.Value.Value);
                            }
                            // build solver + get analyses
                            SolverBoxCase solver       = new SolverBoxCase(packable, caseProperties);
                            var           listAnalyses = solver.BuildAnalyses(constraintSet, false);
                            foreach (var analysis in listAnalyses)
                            {
                                if ((-1 == expectedCount) || (expectedCount == analysis.Solution.ItemCount))
                                {
                                    Analyses.Add(analysis);
                                }
                            }
                        }
                    }
                    catch (Exception) {}
                }
                callback.SetText(Resources.ID_SORTINGSOLUTIONS);
                // sort analysis
                Analyses.Sort(new AnalysisComparer());
                callback.End();
            }
            catch (Exception) {}
        }
예제 #2
0
        protected void ComputeSolutions()
        {
            // sanity checks
            if (cbBoxes.Items.Count == 0 || chklbCases.Items.Count == 0)
            {
                return;
            }
            // clear existing analyses
            _analyses.Clear();

            int expectedCount = uCtrlNumberPerCase.Value.Activated ? uCtrlNumberPerCase.Value.Value : -1;

            try
            {
                PackableBrick packable = cbBoxes.SelectedType as PackableBrick;

                // build list of analyses
                for (int i = 0; i < _checkedIndices.Count; ++i)
                {
                    if ((chklbCases.Items[_checkedIndices[i]] as ItemBaseCB).Item is BoxProperties caseProperties)
                    {
                        // build constraint set
                        ConstraintSetBoxCase constraintSet = new ConstraintSetBoxCase(caseProperties);
                        constraintSet.SetAllowedOrientations(uCtrlCaseOrient.AllowedOrientations);
                        if (uCtrlNumberPerCase.Value.Activated)
                        {
                            constraintSet.SetMaxNumber(uCtrlNumberPerCase.Value.Value);
                        }
                        // build solver + get analyses
                        SolverBoxCase solver       = new SolverBoxCase(packable, caseProperties);
                        var           listAnalyses = solver.BuildAnalyses(constraintSet, false);
                        foreach (var analysis in listAnalyses)
                        {
                            if ((-1 == expectedCount) || (expectedCount == analysis.Solution.ItemCount))
                            {
                                _analyses.Add(analysis);
                            }
                        }
                    }
                }
                // sort analysis
                _analyses.Sort(new AnalysisComparer());
                // fill grid
                FillGrid();
            }
            catch (Exception ex)
            {
                _log.Error(ex.Message);
            }
        }
예제 #3
0
        protected void ComputeSolutions()
        {
            // sanity checks
            if (cbBoxes.Items.Count == 0 || chklbCases.Items.Count == 0)
            {
                return;
            }
            // clear existing analyses
            _analyses.Clear();

            try
            {
                PackableBrick packable = cbBoxes.SelectedType as PackableBrick;

                // build list of analyses
                for (int i = 0; i < _checkedIndices.Count; ++i)
                {
                    BoxProperties caseProperties = (chklbCases.Items[_checkedIndices[i]] as ItemBaseCB).Item as BoxProperties;
                    if (null != caseProperties)
                    {
                        // build constraint set
                        ConstraintSetBoxCase constraintSet = new ConstraintSetBoxCase(caseProperties);
                        constraintSet.SetAllowedOrientations(uCtrlCaseOrient.AllowedOrientations);
                        // build solver + get analyses
                        SolverBoxCase solver = new SolverBoxCase(packable, caseProperties);
                        _analyses.AddRange(solver.BuildAnalyses(constraintSet));
                    }
                }
                // sort analysis
                _analyses.Sort(new AnalysisComparer());
                // fill grid
                FillGrid();
            }
            catch (Exception ex)
            {
                _log.Error(ex.Message);
            }
        }
예제 #4
0
        public static bool GetBestSolution(PackableBrick packableProperties, BoxProperties caseProperties, InterlayerProperties interlayer
                                           , ConstraintSetBoxCase constraintSet, bool allowMultipleLayerOrientations
                                           , Vector3D cameraPosition, bool showCotations, float fontSizeRatio, Size sz
                                           , ref int layerCount, ref int caseCount, ref int interlayerCount
                                           , ref double weightTotal, ref double weightLoad, ref double?weightNet
                                           , ref Vector3D bbLoad, ref Vector3D bbGlob
                                           , ref double volumeEfficency, ref double?weightEfficiency
                                           , ref byte[] imageBytes
                                           , ref string[] errors
                                           )
        {
            List <string> lErrors = new List <string>();

            if (!packableProperties.FitsIn(caseProperties, constraintSet))
            {
                lErrors.Add($"{packableProperties.Name} does not fit in {caseProperties.Name} with given constraint set!");
                return(false);
            }
            try
            {
                SolverBoxCase   solver   = new SolverBoxCase(packableProperties, caseProperties);
                List <Analysis> analyses = solver.BuildAnalyses(constraintSet, allowMultipleLayerOrientations);
                if (analyses.Count > 0)
                {
                    Analysis analysis = analyses[0];
                    layerCount      = analysis.Solution.LayerCount;
                    caseCount       = analysis.Solution.ItemCount;
                    interlayerCount = analysis.Solution.LayerCount;

                    weightLoad  = analysis.Solution.LoadWeight;
                    weightTotal = analysis.Solution.Weight;

                    OptDouble optNetWeight = analysis.Solution.NetWeight;
                    weightNet        = optNetWeight.Activated ? optNetWeight.Value : (double?)null;
                    bbGlob           = analysis.Solution.BBoxGlobal.DimensionsVec;
                    bbLoad           = analysis.Solution.BBoxLoad.DimensionsVec;
                    volumeEfficency  = analysis.Solution.VolumeEfficiency;
                    weightEfficiency = null;
                    if (analysis.Solution.WeightEfficiency.Activated)
                    {
                        weightEfficiency = analysis.Solution.WeightEfficiency.Value;
                    }

                    // generate image path
                    Graphics3DImage graphics = new Graphics3DImage(sz)
                    {
                        FontSizeRatio  = fontSizeRatio,
                        CameraPosition = cameraPosition,
                        ShowDimensions = showCotations
                    };
                    ViewerSolution sv = new ViewerSolution(analysis.Solution);
                    sv.Draw(graphics, Transform3D.Identity);
                    graphics.Flush();
                    Bitmap         bmp       = graphics.Bitmap;
                    ImageConverter converter = new ImageConverter();
                    imageBytes = (byte[])converter.ConvertTo(bmp, typeof(byte[]));
                }
                else
                {
                    lErrors.Add("No solution found!");
                }
            }
            catch (Exception ex)
            {
                lErrors.Add(ex.Message);
            }
            errors = lErrors.ToArray();
            return(0 == lErrors.Count);
        }
예제 #5
0
        private void GenerateResult(
            string name
            , double length, double width, double height
            , double?weight
            , ref int stackCount, ref double stackWeight, ref double stackEfficiency
            , ref string stackImagePath)
        {
            stackCount     = 0;
            stackWeight    = 0.0;
            stackImagePath = string.Empty;

            // generate case
            BoxProperties bProperties = new BoxProperties(null, length, width, height);

            if (weight.HasValue)
            {
                bProperties.SetWeight(weight.Value);
            }
            bProperties.SetColor(Color.Chocolate);
            bProperties.TapeWidth = new OptDouble(true, Math.Min(50.0, 0.5 * width));
            bProperties.TapeColor = Color.Beige;

            Graphics3DImage graphics = null;

            if (GenerateImage || GenerateImageInFolder)
            {
                // generate image path
                stackImagePath = Path.Combine(Path.ChangeExtension(Path.GetTempFileName(), "png"));

                if (GenerateImageInFolder)
                {
                    stackImagePath = Path.ChangeExtension(Path.Combine(Path.Combine(DirectoryPathImages, name)), "png");
                }

                graphics = new Graphics3DImage(new Size(ImageSize, ImageSize))
                {
                    FontSizeRatio  = this.FontSizeRatio,
                    CameraPosition = Graphics3D.Corner_0
                };
            }

            // compute analysis
            if (0 == Mode)
            {
                ConstraintSetCasePallet constraintSet = new ConstraintSetCasePallet();
                constraintSet.SetAllowedOrientations(new bool[] { !AllowOnlyZOrientation, !AllowOnlyZOrientation, true });
                constraintSet.SetMaxHeight(new OptDouble(true, PalletMaximumHeight));

                SolverCasePallet       solver   = new SolverCasePallet(bProperties, PalletProperties, constraintSet);
                List <AnalysisLayered> analyses = solver.BuildAnalyses(false);
                if (analyses.Count > 0)
                {
                    AnalysisLayered analysis = analyses[0];
                    stackCount      = analysis.Solution.ItemCount;
                    stackWeight     = analysis.Solution.Weight;
                    stackEfficiency = analysis.Solution.VolumeEfficiency;

                    if (stackCount <= StackCountMax)
                    {
                        if (GenerateImage || GenerateImageInFolder)
                        {
                            ViewerSolution sv = new ViewerSolution(analysis.Solution as SolutionLayered);
                            sv.Draw(graphics, Transform3D.Identity);
                            graphics.Flush();
                        }
                        if (GenerateReport)
                        {
                            ReportDataAnalysis inputData      = new ReportDataAnalysis(analysis);
                            string             outputFilePath = Path.ChangeExtension(Path.Combine(Path.GetDirectoryName(OutputFilePath), string.Format("Report_{0}_on_{1}", analysis.Content.Name, analysis.Container.Name)), "doc");

                            ReportNode rnRoot   = null;
                            Margins    margins  = new Margins();
                            Reporter   reporter = new ReporterMSWord(inputData, ref rnRoot, Reporter.TemplatePath, outputFilePath, margins);
                        }
                    }
                }
            }
            else
            {
                BoxProperties container = new BoxProperties(null, TruckLength, TruckWidth, TruckHeight, TruckLength, TruckWidth, TruckHeight);
                Color         lblue     = Color.LightBlue;
                container.SetAllColors(new Color[] { lblue, lblue, lblue, lblue, lblue, lblue });
                container.SetWeight(0.0);
                ConstraintSetBoxCase constraintSet = new ConstraintSetBoxCase(container);
                constraintSet.SetAllowedOrientations(new bool[] { !AllowOnlyZOrientation, !AllowOnlyZOrientation, true });

                SolverBoxCase          solver   = new SolverBoxCase(bProperties, container, constraintSet);
                List <AnalysisLayered> analyses = solver.BuildAnalyses(false);
                if (analyses.Count > 0)
                {
                    AnalysisLayered analysis = analyses[0];
                    stackCount  = analysis.Solution.ItemCount;
                    stackWeight = analysis.Solution.Weight;

                    if ((GenerateImage || GenerateImageInFolder) && stackCount <= StackCountMax)
                    {
                        ViewerSolution sv = new ViewerSolution(analysis.Solution as SolutionLayered);
                        sv.Draw(graphics, Transform3D.Identity);
                        graphics.Flush();
                    }
                }
            }
            if (GenerateImage)
            {
                Bitmap bmp = graphics.Bitmap;
                bmp.Save(stackImagePath, System.Drawing.Imaging.ImageFormat.Png);
            }
        }
예제 #6
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);
            }
        }