Exemple #1
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 <AnalysisHomo> analyses = solver.BuildAnalyses(constraintSet, allowMultipleLayerOrientations);
                if (analyses.Count > 0)
                {
                    // first solution
                    AnalysisHomo 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);
        }
Exemple #2
0
        public DCSBSolution SB_GetBoxCaseBestSolution(
            DCSBCase sbBox, DCSBCase sbCase, DCSBInterlayer sbInterlayer
            , DCSBConstraintSet sbConstraintSet
            , DCCompFormat expectedFormat, bool showCotations)
        {
            List <string> lErrors = new List <string>();

            try
            {
                BoxProperties boxProperties = new BoxProperties(null
                                                                , sbBox.DimensionsOuter.M0, sbBox.DimensionsOuter.M1, sbBox.DimensionsOuter.M2)
                {
                };
                boxProperties.SetWeight(sbBox.Weight);
                boxProperties.SetNetWeight(new OptDouble(sbBox.NetWeight.HasValue, sbBox.NetWeight.Value));
                if (null != sbBox.Colors && sbBox.Colors.Length >= 6)
                {
                    for (int i = 0; i < 6; ++i)
                    {
                        boxProperties.SetColor((HalfAxis.HAxis)i, Color.FromArgb(sbBox.Colors[i]));
                    }
                }
                else
                {
                    boxProperties.SetAllColors(Enumerable.Repeat <Color>(Color.Turquoise, 6).ToArray());
                }
                BoxProperties caseProperties = new BoxProperties(null)
                {
                    InsideLength = null != sbCase.DimensionsInner ? sbCase.DimensionsInner.M0 : 0.0,
                    InsideWidth  = null != sbCase.DimensionsInner ? sbCase.DimensionsInner.M1 : 0.0,
                    InsideHeight = null != sbCase.DimensionsInner ? sbCase.DimensionsInner.M2 : 0.0,
                    TapeColor    = Color.FromArgb(sbCase.TapeColor),
                    TapeWidth    = new OptDouble(sbCase.TapeWidth != 0.0, sbCase.TapeWidth)
                };
                caseProperties.SetWeight(sbCase.Weight);
                if (null != sbCase.Colors && sbCase.Colors.Length >= 6)
                {
                    for (int i = 0; i < 6; ++i)
                    {
                        caseProperties.SetColor((HalfAxis.HAxis)i, Color.FromArgb(sbCase.Colors[i]));
                    }
                }
                else
                {
                    caseProperties.SetAllColors(Enumerable.Repeat <Color>(Color.Chocolate, 6).ToArray());
                }

                OptDouble            oMaxWeight    = null != sbConstraintSet.MaxWeight ? new OptDouble(sbConstraintSet.MaxWeight.Active, sbConstraintSet.MaxWeight.Value_d) : OptDouble.Zero;
                OptInt               oMaxNumber    = null != sbConstraintSet.MaxNumber ? new OptInt(sbConstraintSet.MaxNumber.Active, sbConstraintSet.MaxNumber.Value_i) : OptInt.Zero;
                ConstraintSetBoxCase constraintSet = new ConstraintSetBoxCase(caseProperties)
                {
                    OptMaxWeight = oMaxWeight,
                    OptMaxNumber = oMaxNumber
                };
                constraintSet.SetAllowedOrientations(new bool[] { false, false, true });
                if (!constraintSet.Valid)
                {
                    throw new Exception("Invalid constraint set");
                }

                Vector3D cameraPosition = Graphics3D.Corner_0;
                int      layerCount = 0, caseCount = 0, interlayerCount = 0;
                double   weightTotal = 0.0, weightLoad = 0.0, volumeEfficiency = 0.0;
                double?  weightEfficiency = 0.0;
                double?  weightNet        = (double?)null;
                Vector3D bbLoad           = new Vector3D();
                Vector3D bbGlob           = new Vector3D();
                byte[]   imageBytes       = null;
                string[] errors           = null;

                if (StackBuilderProcessor.GetBestSolution(
                        boxProperties, caseProperties, null,
                        constraintSet, sbConstraintSet.AllowMultipleLayerOrientations,
                        cameraPosition, showCotations, 0.03f,
                        new Size(expectedFormat.Size.CX, expectedFormat.Size.CY),
                        ref layerCount, ref caseCount, ref interlayerCount,
                        ref weightTotal, ref weightLoad, ref weightNet,
                        ref bbLoad, ref bbGlob,
                        ref volumeEfficiency, ref weightEfficiency,
                        ref imageBytes, ref errors))
                {
                    foreach (string err in errors)
                    {
                        lErrors.Add(err);
                    }
                    return(new DCSBSolution()
                    {
                        LayerCount = layerCount,
                        CaseCount = caseCount,
                        InterlayerCount = interlayerCount,
                        WeightLoad = weightLoad,
                        WeightTotal = weightTotal,
                        NetWeight = weightNet,
                        BBoxLoad = new DCSBDim3D(bbLoad.X, bbLoad.Y, bbLoad.Z),
                        BBoxTotal = new DCSBDim3D(bbGlob.X, bbGlob.Y, bbGlob.Z),
                        Efficiency = volumeEfficiency,
                        OutFile = new DCCompFileOutput()
                        {
                            Bytes = imageBytes,
                            Format = new DCCompFormat()
                            {
                                Format = EOutFormat.IMAGE,
                                Size = new DCCompSize()
                                {
                                    CX = expectedFormat.Size.CX,
                                    CY = expectedFormat.Size.CY
                                }
                            }
                        },
                        Errors = lErrors.ToArray()
                    });
                }
            }
            catch (Exception ex)
            {
                lErrors.Add(ex.Message);
                _log.Error(ex.ToString());
            }
            return(new DCSBSolution()
            {
                Errors = lErrors.ToArray()
            });
        }
Exemple #3
0
        /// <summary>
        /// FormNewBox constructor used when defining a new BoxProperties item
        /// </summary>
        /// <param name="document">Document in which the BoxProperties item is to be created</param>
        /// <param name="mode">Mode is either Mode.MODE_CASE or Mode.MODE_BOX</param>
        public FormNewBox(Document document, Mode mode)
            : base(document, null)
        {
            InitializeComponent();
            if (!DesignMode)
            {
                // set unit labels
                UnitsManager.AdaptUnitLabels(this);
                // save document reference
                _document = document;

                switch (mode)
                {
                case Mode.CASE:
                    tbName.Text = _document.GetValidNewTypeName(Resources.ID_CASE);
                    uCtrlDimensionsOuter.ValueX  = UnitsManager.ConvertLengthFrom(400.0, UnitsManager.UnitSystem.UNIT_METRIC1);
                    uCtrlDimensionsOuter.ValueY  = UnitsManager.ConvertLengthFrom(300.0, UnitsManager.UnitSystem.UNIT_METRIC1);
                    uCtrlDimensionsOuter.ValueZ  = UnitsManager.ConvertLengthFrom(200.0, UnitsManager.UnitSystem.UNIT_METRIC1);
                    uCtrlDimensionsInner.Checked = true;
                    uCtrlDimensionsInner.Value   = new Vector3D(
                        uCtrlDimensionsOuter.ValueX - UnitsManager.ConvertLengthFrom(6.0, UnitsManager.UnitSystem.UNIT_METRIC1),
                        uCtrlDimensionsOuter.ValueY - UnitsManager.ConvertLengthFrom(6.0, UnitsManager.UnitSystem.UNIT_METRIC1),
                        uCtrlDimensionsOuter.ValueZ - UnitsManager.ConvertLengthFrom(6.0, UnitsManager.UnitSystem.UNIT_METRIC1));
                    uCtrlTapeWidth.Value = new OptDouble(true, UnitsManager.ConvertLengthFrom(50, UnitsManager.UnitSystem.UNIT_METRIC1));
                    break;

                case Mode.BOX:
                    tbName.Text = _document.GetValidNewTypeName(Resources.ID_BOX);
                    uCtrlDimensionsOuter.ValueX = UnitsManager.ConvertLengthFrom(120.0, UnitsManager.UnitSystem.UNIT_METRIC1);
                    uCtrlDimensionsOuter.ValueY = UnitsManager.ConvertLengthFrom(60.0, UnitsManager.UnitSystem.UNIT_METRIC1);
                    uCtrlDimensionsOuter.ValueZ = UnitsManager.ConvertLengthFrom(30.0, UnitsManager.UnitSystem.UNIT_METRIC1);
                    uCtrlDimensionsInner.Value  = new Vector3D(
                        uCtrlDimensionsOuter.ValueX - UnitsManager.ConvertLengthFrom(6.0, UnitsManager.UnitSystem.UNIT_METRIC1),
                        uCtrlDimensionsOuter.ValueY - UnitsManager.ConvertLengthFrom(6.0, UnitsManager.UnitSystem.UNIT_METRIC1),
                        uCtrlDimensionsOuter.ValueZ - UnitsManager.ConvertLengthFrom(6.0, UnitsManager.UnitSystem.UNIT_METRIC1));
                    uCtrlDimensionsInner.Checked = false;
                    uCtrlTapeWidth.Value         = new OptDouble(false, UnitsManager.ConvertLengthFrom(10, UnitsManager.UnitSystem.UNIT_METRIC1));
                    break;

                default:
                    break;
                }
                cbTapeColor.Color = Color.Beige;
                ModeInit          = mode;
                // description (same as name)
                tbDescription.Text = tbName.Text;
                // color : all faces set together / face by face
                chkAllFaces.Checked = false;
                OnAllFacesColorCheckedChanged(this, null);
                // set colors
                for (int i = 0; i < 6; ++i)
                {
                    _faceColors[i] = mode == Mode.BOX ? Color.Turquoise : Color.Chocolate;
                }
                // set textures
                _textures = new List <Pair <HalfAxis.HAxis, Texture> >();
                // set default face
                cbFace.SelectedIndex = 0;
                // weight
                Weight = UnitsManager.ConvertMassFrom(1.0, UnitsManager.UnitSystem.UNIT_METRIC1);
                // net weight
                NetWeight = new OptDouble(false, UnitsManager.ConvertMassFrom(0.0, UnitsManager.UnitSystem.UNIT_METRIC1));

                StrapperSet = new StrapperSet();
                ctrlStrapperSet.StrapperSet = StrapperSet;

                // disable Ok button
                UpdateStatus(string.Empty);
            }
        }
Exemple #4
0
        public DCSBSolution SB_GetBundlePalletBestSolution(
            DCSBBundle sbBundle, DCSBPallet sbPallet, DCSBInterlayer sbInterlayer
            , DCSBConstraintSet sbConstraintSet
            , DCCompFormat expectedFormat, bool showCotations)
        {
            List <string> lErrors = new List <string>();

            try
            {
                BundleProperties bundleProperties = new BundleProperties(null
                                                                         , sbBundle.Name, sbBundle.Description
                                                                         , sbBundle.DimensionsUnit.M0, sbBundle.DimensionsUnit.M1, sbBundle.DimensionsUnit.M2
                                                                         , sbBundle.UnitWeight, sbBundle.Number
                                                                         , Color.FromArgb(sbBundle.Color));
                PalletProperties palletProperties = null;
                if (null != sbPallet.Dimensions)
                {
                    palletProperties = new PalletProperties(null, sbPallet.PalletType,
                                                            sbPallet.Dimensions.M0, sbPallet.Dimensions.M1, sbPallet.Dimensions.M2)
                    {
                        Weight = sbPallet.Weight,
                        Color  = Color.FromArgb(sbPallet.Color)
                    }
                }
                ;
                else
                {
                    palletProperties = new PalletProperties(null, "EUR2", 1200.0, 1000.0, 150.0);
                }

                InterlayerProperties interlayerProperties = null;
                if (null != sbInterlayer)
                {
                    interlayerProperties = new InterlayerProperties(null,
                                                                    sbInterlayer.Name, sbInterlayer.Description,
                                                                    sbInterlayer.Dimensions.M0, sbInterlayer.Dimensions.M1, sbInterlayer.Dimensions.M2,
                                                                    sbInterlayer.Weight, Color.FromArgb(sbInterlayer.Color));
                }

                OptDouble oMaxWeight = null != sbConstraintSet.MaxWeight ? new OptDouble(sbConstraintSet.MaxWeight.Active, sbConstraintSet.MaxWeight.Value_d) : OptDouble.Zero;
                OptDouble oMaxHeight = null != sbConstraintSet.MaxHeight ? new OptDouble(sbConstraintSet.MaxHeight.Active, sbConstraintSet.MaxHeight.Value_d) : OptDouble.Zero;
                OptInt    oMaxNumber = null != sbConstraintSet.MaxNumber ? new OptInt(sbConstraintSet.MaxNumber.Active, sbConstraintSet.MaxNumber.Value_i) : OptInt.Zero;
                ConstraintSetCasePallet constraintSet = new ConstraintSetCasePallet()
                {
                    OptMaxWeight = oMaxWeight,
                    OptMaxNumber = oMaxNumber
                };
                constraintSet.SetMaxHeight(oMaxHeight);
                constraintSet.SetAllowedOrientations(new bool[] { false, false, true });
                if (!constraintSet.Valid)
                {
                    throw new Exception("Invalid constraint set");
                }

                Vector3D cameraPosition = Graphics3D.Corner_0;
                int      layerCount = 0, caseCount = 0, interlayerCount = 0;
                double   weightTotal = 0.0, weightLoad = 0.0, volumeEfficiency = 0.0;
                double?  weightEfficiency = 0.0;
                double?  weightNet        = (double?)null;
                Vector3D bbLoad           = new Vector3D();
                Vector3D bbGlob           = new Vector3D();
                byte[]   imageBytes       = null;
                string[] errors           = null;
                string   palletMapPhrase  = string.Empty;

                if (StackBuilderProcessor.GetBestSolution(
                        bundleProperties, palletProperties, interlayerProperties,
                        constraintSet, false,
                        cameraPosition, showCotations, 0.03f,
                        new Size(expectedFormat.Size.CX, expectedFormat.Size.CY),
                        ref layerCount, ref caseCount, ref interlayerCount,
                        ref weightTotal, ref weightLoad, ref weightNet,
                        ref bbLoad, ref bbGlob,
                        ref volumeEfficiency, ref weightEfficiency,
                        ref palletMapPhrase,
                        ref imageBytes, ref errors))
                {
                    foreach (string err in errors)
                    {
                        lErrors.Add(err);
                    }
                    return(new DCSBSolution()
                    {
                        LayerCount = layerCount,
                        CaseCount = caseCount,
                        InterlayerCount = interlayerCount,
                        WeightLoad = weightLoad,
                        WeightTotal = weightTotal,
                        NetWeight = weightNet,
                        BBoxLoad = new DCSBDim3D(bbLoad.X, bbLoad.Y, bbLoad.Z),
                        BBoxTotal = new DCSBDim3D(bbGlob.X, bbGlob.Y, bbGlob.Z),
                        Efficiency = volumeEfficiency,
                        OutFile = new DCCompFileOutput()
                        {
                            Bytes = imageBytes,
                            Format = new DCCompFormat()
                            {
                                Format = EOutFormat.IMAGE,
                                Size = new DCCompSize()
                                {
                                    CX = expectedFormat.Size.CX,
                                    CY = expectedFormat.Size.CY
                                }
                            }
                        },
                        Errors = lErrors.ToArray()
                    });
                }
            }
            catch (Exception ex)
            {
                lErrors.Add(ex.Message);
                _log.Error(ex.ToString());
            }
            return(new DCSBSolution()
            {
                Errors = lErrors.ToArray()
            });
        }
        public static bool GetSolutionByLayer(
            PackableBrick packableProperties, PalletProperties palletProperties, InterlayerProperties interlayerProperties
            , ConstraintSetCasePallet constraintSet
            , LayerDesc layerDesc
            , 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>();

            try
            {
                if (!packableProperties.FitsIn(palletProperties, constraintSet))
                {
                    lErrors.Add($"{packableProperties.Name} does not fit in {palletProperties.Name} with given constraint set!");
                    return(false);
                }
                SolutionLayered.SetSolver(new LayerSolver());
                var analysis = new AnalysisCasePallet(packableProperties, palletProperties, constraintSet);
                analysis.AddSolution(new List <LayerDesc>()
                {
                    layerDesc
                });

                layerCount      = analysis.SolutionLay.LayerCount;
                caseCount       = analysis.Solution.ItemCount;
                interlayerCount = analysis.SolutionLay.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
                };
                using (ViewerSolution sv = new ViewerSolution(analysis.SolutionLay))
                    sv.Draw(graphics, Transform3D.Identity);
                graphics.Flush();
                Bitmap         bmp       = graphics.Bitmap;
                ImageConverter converter = new ImageConverter();
                imageBytes = (byte[])converter.ConvertTo(bmp, typeof(byte[]));

                // pallet phrase
                palletMapPhrase = BuildPalletMapPhrase(analysis.SolutionLay);
            }
            catch (Exception ex)
            {
                lErrors.Add(ex.Message);
            }
            errors = lErrors.ToArray();
            return(0 == lErrors.Count);
        }