Пример #1
0
        public static bool GetSolutionList(
            PackableBrick packableProperties, PalletProperties palletProperties, InterlayerProperties interlayerProperties
            , ConstraintSetCasePallet constraintSet
            , ref List <AnalysisLayered> analyses)
        {
            SolverCasePallet solver = new SolverCasePallet(packableProperties, palletProperties, constraintSet);

            analyses = solver.BuildAnalyses(false);
            return(analyses.Count > 0);
        }
Пример #2
0
        public static bool GetBestSolution(
            PackableBrick packableProperties, PalletProperties palletProperties, InterlayerProperties interlayer
            , ConstraintSetCasePallet 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 string palletMapPhrase
            , ref byte[] imageBytes
            , ref string[] errors)
        {
            List <string> lErrors = new List <string>();

            if (!packableProperties.FitsIn(palletProperties, constraintSet))
            {
                lErrors.Add($"{packableProperties.Name} does not fit in {palletProperties.Name} with given constraint set!");
                return(false);
            }
            try
            {
                // use a solver and get a list of sorted analyses + select the best one
                SolverCasePallet solver   = new SolverCasePallet(packableProperties, palletProperties);
                List <Analysis>  analyses = solver.BuildAnalyses(constraintSet, allowMultipleLayerOrientations);
                if (analyses.Count > 0)
                {
                    // first solution
                    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;
                    }
                    palletMapPhrase = BuildPalletMapPhrase(analysis.Solution);

                    Graphics3DImage graphics = null;
                    // generate image path
                    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);
        }
Пример #3
0
        private void OnCompute(object sender, EventArgs e)
        {
            try
            {
                if (Globals.StackBuilderAddIn.Application.ActiveSheet is Excel.Worksheet xlSheet)
                {
                    Console.WriteLine(string.Format("Sheet name = {0}", xlSheet.Name));

                    double caseLength = ReadDouble(xlSheet, Settings.Default.CellCaseLength, Resources.ID_CASE_LENGTH);
                    double caseWidth  = ReadDouble(xlSheet, Settings.Default.CellCaseWidth, Resources.ID_CASE_WIDTH);
                    double caseHeight = ReadDouble(xlSheet, Settings.Default.CellCaseHeight, Resources.ID_CASE_HEIGHT);
                    double caseWeight = ReadDouble(xlSheet, Settings.Default.CellCaseWeight, Resources.ID_CASE_WEIGHT);

                    double palletLength = ReadDouble(xlSheet, Settings.Default.CellPalletLength, Resources.ID_PALLET_LENGTH);
                    double palletWidth  = ReadDouble(xlSheet, Settings.Default.CellPalletWidth, Resources.ID_PALLET_WIDTH);
                    double palletHeight = ReadDouble(xlSheet, Settings.Default.CellPalletHeight, Resources.ID_PALLET_HEIGHT);
                    double palletWeight = ReadDouble(xlSheet, Settings.Default.CellPalletWeight, Resources.ID_PALLET_WEIGHT);

                    double palletMaximumHeight = ReadDouble(xlSheet, Settings.Default.CellMaxPalletHeight, Resources.ID_CONSTRAINTS_PALLETMAXIHEIGHT);
                    double palletMaximumWeight = ReadDouble(xlSheet, Settings.Default.CellMaxPalletWeight, Resources.ID_CONSTRAINTS_PALLETMAXIWEIGHT);

                    // ### actually compute result ###
                    // build a case
                    BoxProperties bProperties = new BoxProperties(null, caseLength, caseWidth, caseHeight);
                    bProperties.SetWeight(caseWeight);
                    bProperties.SetColor(Color.Chocolate);
                    bProperties.TapeWidth = new OptDouble(true, UnitsManager.ConvertLengthFrom(50.0, UnitsManager.UnitSystem.UNIT_METRIC1));
                    bProperties.TapeColor = Color.Beige;

                    // build a pallet
                    PalletProperties palletProperties = new PalletProperties(null, PalletTypeName, palletLength, palletWidth, palletHeight)
                    {
                        Weight = palletWeight,
                        Color  = Color.Yellow
                    };

                    // build a constraint set
                    ConstraintSetCasePallet constraintSet = new ConstraintSetCasePallet();
                    constraintSet.SetAllowedOrientations(new bool[] { false, false, true });
                    constraintSet.SetMaxHeight(new OptDouble(true, palletMaximumHeight));
                    constraintSet.OptMaxWeight = new OptDouble(true, palletMaximumWeight);

                    // use a solver and get a list of sorted analyses + select the best one
                    SolverCasePallet    solver   = new SolverCasePallet(bProperties, palletProperties);
                    List <AnalysisHomo> analyses = solver.BuildAnalyses(constraintSet, true);
                    if (analyses.Count > 0)
                    {
                        AnalysisHomo analysis    = analyses[0];
                        int          caseCount   = analysis.Solution.ItemCount; // <- your case count
                        double       loadWeight  = analysis.Solution.LoadWeight;
                        double       totalWeight = analysis.Solution.Weight;    // <- your pallet weight

                        Graphics3DImage graphics = null;
                        // generate image path
                        string stackImagePath = Path.Combine(Path.ChangeExtension(Path.GetTempFileName(), "png"));
                        graphics = new Graphics3DImage(new Size(Settings.Default.ImageSize, Settings.Default.ImageSize))
                        {
                            FontSizeRatio  = Settings.Default.FontSizeRatio,
                            CameraPosition = Graphics3D.Corner_0
                        };
                        ViewerSolution sv = new ViewerSolution(analysis.Solution);
                        sv.Draw(graphics, Transform3D.Identity);
                        graphics.Flush();
                        Bitmap bmp = graphics.Bitmap;
                        bmp.Save(stackImagePath);


                        WriteInt(xlSheet, Settings.Default.CellNoCases, Resources.ID_RESULT_NOCASES, caseCount);
                        WriteDouble(xlSheet, Settings.Default.CellLoadWeight, Resources.ID_RESULT_LOADWEIGHT, loadWeight);
                        WriteDouble(xlSheet, Settings.Default.CellTotalPalletWeight, Resources.ID_RESULT_TOTALPALLETWEIGHT, totalWeight);

                        string filePath = string.Empty;

                        Globals.StackBuilderAddIn.Application.ActiveSheet.Shapes.AddPicture(
                            stackImagePath,
                            Microsoft.Office.Core.MsoTriState.msoFalse,
                            Microsoft.Office.Core.MsoTriState.msoCTrue,
                            Settings.Default.ImageLeft / 0.035, Settings.Default.ImageTop / 0.035,
                            Settings.Default.ImageWidth / 0.035, Settings.Default.ImageHeight / 0.035);
                    }
                    // ###
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }
Пример #4
0
        public void Compute()
        {
            if (!(Globals.StackBuilderAddIn.Application.ActiveSheet is Excel.Worksheet xlSheet))
            {
                return;
            }
            Console.WriteLine($"Sheet name = {xlSheet.Name}");

            var caseLength = ReadDouble(xlSheet, Settings.Default.CellCaseLength, Resources.ID_CASE_LENGTH);
            var caseWidth  = ReadDouble(xlSheet, Settings.Default.CellCaseWidth, Resources.ID_CASE_WIDTH);
            var caseHeight = ReadDouble(xlSheet, Settings.Default.CellCaseHeight, Resources.ID_CASE_HEIGHT);
            var caseWeight = ReadDouble(xlSheet, Settings.Default.CellCaseWeight, Resources.ID_CASE_WEIGHT);

            var palletLength = ReadDouble(xlSheet, Settings.Default.CellPalletLength, Resources.ID_PALLET_LENGTH);
            var palletWidth  = ReadDouble(xlSheet, Settings.Default.CellPalletWidth, Resources.ID_PALLET_WIDTH);
            var palletHeight = ReadDouble(xlSheet, Settings.Default.CellPalletHeight, Resources.ID_PALLET_HEIGHT);
            var palletWeight = ReadDouble(xlSheet, Settings.Default.CellPalletWeight, Resources.ID_PALLET_WEIGHT);

            var palletMaximumHeight = ReadDouble(xlSheet, Settings.Default.CellMaxPalletHeight, Resources.ID_CONSTRAINTS_PALLETMAXIHEIGHT);
            var palletMaximumWeight = ReadDouble(xlSheet, Settings.Default.CellMaxPalletWeight, Resources.ID_CONSTRAINTS_PALLETMAXIWEIGHT);

            var imageLeft = UnitsManager.ConvertLengthTo(Settings.Default.ImageLeft, UnitsManager.UnitSystem.UNIT_METRIC2) / 0.035;
            var imageTop  = UnitsManager.ConvertLengthTo(Settings.Default.ImageTop, UnitsManager.UnitSystem.UNIT_METRIC2) / 0.035;

            // delete any existing image with same position
            foreach (Excel.Shape s in xlSheet.Shapes)
            {
                if (Math.Abs(s.Left - imageLeft) < 0.001 &&
                    Math.Abs(s.Top - imageTop) < 0.001)
                {
                    s.Delete();
                }
            }
            // initialize units
            UnitsManager.CurrentUnitSystem = (UnitsManager.UnitSystem)Settings.Default.UnitSystem;

            // ###
            // build a case
            var bProperties = new BoxProperties(null, caseLength, caseWidth, caseHeight);

            bProperties.SetWeight(caseWeight);
            bProperties.SetColor(Color.Chocolate);
            bProperties.TapeWidth = new OptDouble(true, 5);
            bProperties.TapeColor = Color.Beige;

            // build a pallet
            var palletProperties = new PalletProperties(null, PalletTypeName, palletLength, palletWidth, palletHeight);

            palletProperties.Weight = palletWeight;
            palletProperties.Color  = Color.Yellow;

            // build a constraint set
            var constraintSet = new ConstraintSetCasePallet();

            constraintSet.SetAllowedOrientations(new bool[] { false, false, true });
            constraintSet.SetMaxHeight(new OptDouble(true, palletMaximumHeight));
            constraintSet.OptMaxWeight = new OptDouble(true, palletMaximumWeight);

            // use a solver and get a list of sorted analyses + select the best one
            var solver   = new SolverCasePallet(bProperties, palletProperties, constraintSet);
            var analyses = solver.BuildAnalyses(true);

            if (analyses.Count > 0)
            {
                var analysis    = analyses[0];
                var caseCount   = analysis.Solution.ItemCount; // <- your case count
                var loadWeight  = analysis.Solution.LoadWeight;
                var totalWeight = analysis.Solution.Weight;    // <- your pallet weight

                // generate image
                Graphics3DImage graphics = null;
                // generate image path
                var stackImagePath = Path.Combine(Path.ChangeExtension(Path.GetTempFileName(), "png"));
                graphics = new Graphics3DImage(new Size(Settings.Default.ImageSize, Settings.Default.ImageSize))
                {
                    FontSizeRatio  = Settings.Default.FontSizeRatio,
                    CameraPosition = Graphics3D.Corner_0
                };
                var sv = new ViewerSolution(analysis.SolutionLay);
                sv.Draw(graphics, Transform3D.Identity);
                graphics.Flush();
                Bitmap bmp = graphics.Bitmap;
                bmp.Save(stackImagePath);

                // write values
                WriteInt(xlSheet, Settings.Default.CellNoCases, Resources.ID_RESULT_NOCASES, caseCount);
                WriteDouble(xlSheet, Settings.Default.CellLoadWeight, Resources.ID_RESULT_LOADWEIGHT, loadWeight);
                WriteDouble(xlSheet, Settings.Default.CellTotalPalletWeight, Resources.ID_RESULT_TOTALPALLETWEIGHT, totalWeight);

                // write picture
                Globals.StackBuilderAddIn.Application.ActiveSheet.Shapes.AddPicture(
                    stackImagePath,
                    Microsoft.Office.Core.MsoTriState.msoFalse,
                    Microsoft.Office.Core.MsoTriState.msoCTrue,
                    imageLeft,
                    imageTop,
                    UnitsManager.ConvertLengthTo(Settings.Default.ImageWidth, UnitsManager.UnitSystem.UNIT_METRIC2) / 0.035,
                    UnitsManager.ConvertLengthTo(Settings.Default.ImageHeight, UnitsManager.UnitSystem.UNIT_METRIC2) / 0.035);
            }
            else
            {
                MessageBox.Show(Resources.ID_RESULT_NOSOLUTIONFOUND,
                                AppDomain.CurrentDomain.FriendlyName,
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Warning);
            }
            // ###
        }
Пример #5
0
        private void GenerateResult(
            string name, string description
            , double length, double width, double height
            , double?weight
            , PalletProperties palletProperties
            , ref int stackCount, ref double loadWeight, ref double totalWeight
            , ref double stackEfficiency
            , ref string stackImagePath)
        {
            stackCount     = 0;
            totalWeight    = 0.0;
            stackImagePath = string.Empty;

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

            bProperties.ID.SetNameDesc(name, description);
            if (weight.HasValue)
            {
                bProperties.SetWeight(weight.Value);
            }
            bProperties.SetColor(Color.Chocolate);
            bProperties.TapeWidth = new OptDouble(true, Math.Min(UnitsManager.ConvertLengthFrom(50.0, UnitsManager.UnitSystem.UNIT_METRIC1), 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  = Settings.Default.FontSizeRatio,
                    CameraPosition = Graphics3D.Corner_0
                };
            }

            // compute analysis
            ConstraintSetCasePallet constraintSet = new ConstraintSetCasePallet();

            constraintSet.SetAllowedOrientations(new bool[] { !AllowOnlyZOrientation, !AllowOnlyZOrientation, true });
            constraintSet.SetMaxHeight(new OptDouble(true, PalletMaximumHeight));
            constraintSet.Overhang = Overhang;

            SolverCasePallet solver   = new SolverCasePallet(bProperties, palletProperties);
            List <Analysis>  analyses = solver.BuildAnalyses(constraintSet, false);

            if (analyses.Count > 0)
            {
                Analysis analysis = analyses[0];
                stackCount      = analysis.Solution.ItemCount;
                loadWeight      = analysis.Solution.LoadWeight;
                totalWeight     = analysis.Solution.Weight;
                stackEfficiency = analysis.Solution.VolumeEfficiency;

                if (stackCount <= StackCountMax)
                {
                    if (GenerateImage || GenerateImageInFolder)
                    {
                        ViewerSolution sv = new ViewerSolution(analysis.Solution);
                        sv.Draw(graphics, Transform3D.Identity);
                        graphics.Flush();
                    }
                    if (GenerateReport)
                    {
                        ReportData inputData      = new ReportData(analysis);
                        string     outputFilePath = Path.ChangeExtension(Path.Combine(DirectoryPathReports, 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);
                    }
                }
            }
            if (GenerateImage)
            {
                Bitmap bmp = graphics.Bitmap;
                bmp.Save(stackImagePath, System.Drawing.Imaging.ImageFormat.Png);
            }
        }
Пример #6
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);
            }
        }
Пример #7
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);
            }
        }
Пример #8
0
        private void GenerateResult(
            string name, string description
            , double length, double width, double height, double?weight
            , PalletProperties palletProperties, Vector2D overhang
            , ref int stackCount
            , ref int layerCount, ref int byLayerCount
            , ref double loadWeight, ref double totalWeight
            , ref double stackEfficiency
            , ref string stackImagePath)
        {
            stackCount     = 0;
            totalWeight    = 0.0;
            stackImagePath = string.Empty;

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

            bProperties.ID.SetNameDesc(name, description);
            if (weight.HasValue)
            {
                bProperties.SetWeight(weight.Value);
            }
            bProperties.SetColor(Color.Chocolate);
            bProperties.TapeWidth = new OptDouble(true, Math.Min(UnitsManager.ConvertLengthFrom(50.0, UnitsManager.UnitSystem.UNIT_METRIC1), 0.5 * width));
            bProperties.TapeColor = Color.Beige;

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

            Graphics3DImage graphics = null;

            if (GenerateImage || GenerateImageInFolder)
            {
                graphics = new Graphics3DImage(new Size(ImageSize, ImageSize))
                {
                    FontSizeRatio  = 0.01F,
                    CameraPosition = Graphics3D.Corner_0
                };
            }

            // compute analysis
            ConstraintSetCasePallet constraintSet = new ConstraintSetCasePallet();

            constraintSet.SetAllowedOrientations(new[] { !AllowOnlyZOrientation, !AllowOnlyZOrientation, true });
            constraintSet.SetMaxHeight(new OptDouble(true, MaxPalletHeight));
            constraintSet.Overhang = overhang;

            SolverCasePallet       solver   = new SolverCasePallet(bProperties, palletProperties, constraintSet);
            List <AnalysisLayered> analyzes = solver.BuildAnalyses(false);

            if (analyzes.Count > 0)
            {
                var analysis = analyzes[0];
                stackCount      = analysis.Solution.ItemCount;
                loadWeight      = analysis.Solution.LoadWeight;
                totalWeight     = analysis.Solution.Weight;
                stackEfficiency = analysis.Solution.VolumeEfficiency;

                if (analysis.Solution is SolutionLayered solutionLayered)
                {
                    layerCount = solutionLayered.LayerCount;
                    if (solutionLayered.Layers.Count > 0)
                    {
                        byLayerCount = solutionLayered.Layers[0].BoxCount;
                    }
                }

                if (stackCount <= StackCountMax)
                {
                    if (GenerateImage || GenerateImageInFolder)
                    {
                        var sv = new ViewerSolution(analysis.SolutionLay);
                        sv.Draw(graphics, Transform3D.Identity);
                        graphics.Flush();
                    }
                    if (GenerateReport)
                    {
                        var    inputData      = new ReportDataAnalysis(analysis);
                        string outputFilePath = Path.ChangeExtension(Path.Combine(DirectoryPathReports,
                                                                                  $"Report_{analysis.Content.Name}_on_{analysis.Container.Name}"), "pdf");

                        var rnRoot  = new ReportNode(Resources.ID_REPORT);
                        var margins = new Margins();
                        //Reporter reporter = new ReporterMSWord(inputData, ref rnRoot, Settings.Default.ReportTemplatePath/*Reporter.TemplatePath*/, outputFilePath, margins);
                        Reporter.SetFontSizeRatios(0.015F, 0.05F);
                        Reporter reporter = new ReporterPDF(inputData, ref rnRoot, Reporter.TemplatePath, outputFilePath);
                    }
                }
            }
            if (GenerateImage || GenerateImageInFolder)
            {
                var bmp = graphics.Bitmap;
                bmp.Save(stackImagePath, System.Drawing.Imaging.ImageFormat.Png);
            }
        }