示例#1
0
        public ILayer2D BuildLayer(Packable packable, Vector2D dimContainer, LayerDesc layerDesc, Vector2D actualDimensions, double minSpace)
        {
            ILayer2D     layer   = null;
            LayerPattern pattern = null;

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

            pattern.GenerateLayer(
                layer
                , layer.Swapped ? actualDimensions.Y : actualDimensions.X
                , layer.Swapped ? actualDimensions.X : actualDimensions.Y
                );
            return(layer);
        }
示例#2
0
        public Layer2D BuildLayer(Vector3D dimBox, Vector2D dimContainer, LayerDesc layerDesc, Vector2D actualDimensions)
        {
            // instantiate layer
            Layer2D layer = new Layer2D(dimBox, dimContainer, layerDesc.AxisOrtho, false);
            // get layer pattern
            LayerPattern pattern = LayerPattern.GetByName(layerDesc.PatternName);

            // build layer
            pattern.GenerateLayer(layer, actualDimensions.X, actualDimensions.Y);
            return(layer);
        }
示例#3
0
 public Layer2D BuildLayer(Vector3D dimBox, Vector2D dimContainer, LayerDesc layerDesc)
 {
     // instantiate layer
     Layer2D layer = new Layer2D(dimBox, dimContainer, layerDesc.AxisOrtho, false);
     // get layer pattern
     LayerPattern pattern = LayerPattern.GetByName(layerDesc.PatternName);
     // dimensions
     double actualLength = 0.0, actualWidth = 0.0;
     if (!pattern.GetLayerDimensionsChecked(layer, out actualLength, out actualWidth))
         return null;
     pattern.GenerateLayer(layer, actualLength, actualWidth);
     return layer;
 }
示例#4
0
        public Layer2D BuildLayer(Vector3D dimBox, Vector2D dimContainer, LayerDesc layerDesc)
        {
            // instantiate layer
            Layer2D layer = new Layer2D(dimBox, dimContainer, layerDesc.AxisOrtho, false);
            // get layer pattern
            LayerPattern pattern = LayerPattern.GetByName(layerDesc.PatternName);
            // dimensions
            double actualLength = 0.0, actualWidth = 0.0;

            if (!pattern.GetLayerDimensionsChecked(layer, out actualLength, out actualWidth))
            {
                return(null);
            }
            pattern.GenerateLayer(layer, actualLength, actualWidth);
            return(layer);
        }
示例#5
0
        public ILayer2D BuildLayer(Packable packable, Vector2D dimContainer, LayerDesc layerDesc, double minSpace)
        {
            ILayer2D layer = null;

            if (packable.IsBrick)
            {
                // casts
                LayerDescBox layerDescBox = layerDesc as LayerDescBox;
                // layer instantiation
                layer = new Layer2D(packable.OuterDimensions, dimContainer, layerDesc.PatternName, layerDescBox.AxisOrtho, layerDesc.Swapped)
                {
                    ForcedSpace = minSpace
                };
                // get layer pattern
                LayerPatternBox pattern = LayerPatternBox.GetByName(layerDesc.PatternName);
                // dimensions
                if (!pattern.GetLayerDimensionsChecked(layer as Layer2D, out double actualLength, out double actualWidth))
                {
                    return(null);
                }
                pattern.GenerateLayer(
                    layer as Layer2D
                    , actualLength
                    , actualWidth);
                return(layer);
            }
            else if (packable.IsCylinder)
            {
                // casts
                CylinderProperties cylProperties = packable as CylinderProperties;
                // layer instantiation
                layer = new Layer2DCyl(cylProperties.RadiusOuter, cylProperties.Height, dimContainer, layerDesc.Swapped);
                // get layer pattern
                LayerPatternCyl pattern = LayerPatternCyl.GetByName(layerDesc.PatternName);
                double          actualLength = 0.0, actualWidth = 0.0;
                if (!pattern.GetLayerDimensions(layer as Layer2DCyl, out actualLength, out actualWidth))
                {
                    return(null);
                }
                pattern.GenerateLayer(layer as Layer2DCyl, actualLength, actualWidth);
            }
            else
            {
                throw new EngineException(string.Format("Unexpected packable {0} (Type = {1})", packable.Name, packable.GetType().ToString()));
            }
            return(layer);
        }
示例#6
0
        public static bool GetBestCombination(Vector3D dimBox, Vector3D dimContainer
                                              , ConstraintSetAbstract constraintSet
                                              , ref List <KeyValuePair <LayerDesc, int> > listLayer)
        {
            var layDescs = new LayerDesc[3];
            var counts   = new int[3] {
                0, 0, 0
            };
            var heights = new double[3] {
                0.0, 0.0, 0.0
            };
            Vector2D layerDim = new Vector2D(dimContainer.X, dimContainer.Y);

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

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

            for (int i = 0; i < 3; ++i)
            {
                int noLayers = 0;
                if (counts[i] > 0)
                {
                    noLayers = (int)Math.Floor(stackingHeight / heights[i]);
                }
                if (counts[i] * noLayers > iCountMax)
                {
                    iCountMax = counts[i] * noLayers;
                    indexIMax = i;
                    noIMax    = noLayers;
                }
            }
            // layer combinations
            int[] comb1 = { 0, 1, 2 };
            int[] comb2 = { 1, 2, 0 };
            for (int i = 0; i < 3; ++i)
            {
                int iComb1 = comb1[i];
                int iComb2 = comb2[i];
                // --swap layers so that the thickest stays at the bottom
                if (heights[iComb2] > heights[iComb1])
                {
                    int iTemp = iComb1;
                    iComb1 = iComb2;
                    iComb2 = iTemp;
                }
                // --
                int noI = 0;
                if (counts[iComb1] != 0)
                {
                    noI = (int)Math.Floor(stackingHeight / heights[iComb1]);
                }
                // search all index
                while (noI > 0)
                {
                    double remainingHeight = stackingHeight - noI * heights[iComb1];
                    int    noJ             = 0;
                    if (counts[iComb2] != 0)
                    {
                        noJ = (int)Math.Floor(remainingHeight / heights[iComb2]);
                    }
                    if (noI * counts[iComb1] + noJ * counts[iComb2] > iCountMax)
                    {
                        indexIMax = iComb1;  indexJMax = iComb2;
                        noIMax    = noI;   noJMax = noJ;
                        iCountMax = noI * counts[iComb1] + noJ * counts[iComb2];
                    }
                    --noI;
                } // while
            }
            if (noIMax > 0)
            {
                listLayer.Add(new KeyValuePair <LayerDesc, int>(layDescs[indexIMax], noIMax));
            }
            if (noJMax > 0)
            {
                listLayer.Add(new KeyValuePair <LayerDesc, int>(layDescs[indexJMax], noJMax));
            }
            return(true);
        }
示例#7
0
        public static bool GetBestCombination(Vector3D dimBox, Vector2D dimContainer,
                                              ConstraintSetAbstract constraintSet, ref List <KeyValuePair <LayerDesc, int> > listLayer)
        {
            var layDescs = new LayerDesc[3];
            var counts   = new int[3] {
                0, 0, 0
            };
            var heights = new double[3] {
                0.0, 0.0, 0.0
            };

            // loop through all patterns
            foreach (LayerPatternBox pattern in LayerPatternBox.All)
            {
                // loop through all orientation
                HalfAxis.HAxis[] patternAxes = pattern.IsSymetric ? HalfAxis.Positives : HalfAxis.All;
                foreach (HalfAxis.HAxis axisOrtho in patternAxes)
                {
                    // is orientation allowed
                    if (!constraintSet.AllowOrientation(Layer2D.VerticalAxis(axisOrtho)))
                    {
                        continue;
                    }
                    // not swapped vs swapped pattern
                    for (int iSwapped = 0; iSwapped < 2; ++iSwapped)
                    {
                        // does swapping makes sense for this layer pattern ?
                        if (!pattern.CanBeSwapped && (iSwapped == 1))
                        {
                            continue;
                        }
                        // instantiate layer
                        var layer = new Layer2D(dimBox, dimContainer, axisOrtho, iSwapped == 1);
                        layer.PatternName = pattern.Name;
                        double actualLength = 0.0, actualWidth = 0.0;
                        if (!pattern.GetLayerDimensionsChecked(layer, out actualLength, out actualWidth))
                        {
                            continue;
                        }
                        pattern.GenerateLayer(layer, actualLength, actualWidth);
                        if (0 == layer.Count)
                        {
                            continue;
                        }

                        int iAxisIndex = HalfAxis.Direction(axisOrtho);
                        if (layer.Count > counts[iAxisIndex])
                        {
                            counts[iAxisIndex]   = layer.Count;
                            layDescs[iAxisIndex] = layer.LayerDescriptor;
                            heights[iAxisIndex]  = layer.BoxHeight;
                        }
                    }
                }
            }

            // get list of values
            int indexIMax = 0, indexJMax = 0, noIMax = 0, noJMax = 0, iCountMax = 0;

            for (int i = 0; i < 2; ++i)
            {
                int j = i + 1;
                // search best count
                double palletHeight = constraintSet.OptMaxHeight.Value;
                int    noI          = (int)Math.Floor(palletHeight / heights[i]);
                // search all index
                while (noI > 0)
                {
                    double remainingHeight = palletHeight - noI * heights[i];
                    int    noJ             = (int)Math.Floor(remainingHeight / heights[j]);
                    if (noI * counts[i] + noJ * counts[j] > iCountMax)
                    {
                        indexIMax = i;  indexJMax = j;
                        noIMax    = noI;   noJMax = noJ;
                        iCountMax = noI * counts[i] + noJ * counts[j];
                    }
                    --noI;
                } // while
            }

            listLayer.Add(new KeyValuePair <LayerDesc, int>(layDescs[indexIMax], noIMax));
            listLayer.Add(new KeyValuePair <LayerDesc, int>(layDescs[indexJMax], noJMax));
            return(true);
        }
示例#8
0
        public DCSBSolution SB_GetSolution(DCSBCase sbCase, DCSBPallet sbPallet, DCSBInterlayer sbInterlayer,
                                           DCSBConstraintSet sbConstraintSet, string sLayerDesc,
                                           DCCompFormat expectedFormat, bool showCotations
                                           )
        {
            List <string> lErrors       = new List <string>();
            BoxProperties boxProperties = new BoxProperties(null, sbCase.DimensionsOuter.M0, sbCase.DimensionsOuter.M1, sbCase.DimensionsOuter.M2)
            {
                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)
            };

            boxProperties.SetWeight(sbCase.Weight);
            boxProperties.SetNetWeight(new OptDouble(sbCase.NetWeight.HasValue, sbCase.NetWeight.Value));
            if (null != sbCase.Colors && sbCase.Colors.Length >= 6)
            {
                for (int i = 0; i < 6; ++i)
                {
                    boxProperties.SetColor((HalfAxis.HAxis)i, Color.FromArgb(sbCase.Colors[i]));
                }
            }
            else
            {
                boxProperties.SetAllColors(Enumerable.Repeat(Color.Chocolate, 6).ToArray());
            }

            PalletProperties palletProperties;

            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()
            {
                Overhang     = new Vector2D(sbConstraintSet.Overhang.M0, sbConstraintSet.Overhang.M1),
                OptMaxWeight = oMaxWeight,
                OptMaxNumber = oMaxNumber
            };

            constraintSet.SetMaxHeight(oMaxHeight);
            constraintSet.SetAllowedOrientations(new bool[] { sbConstraintSet.Orientation.X, sbConstraintSet.Orientation.Y, sbConstraintSet.Orientation.Z });
            if (!constraintSet.Valid)
            {
                throw new Exception("Invalid constraint set");
            }

            LayerDesc layerDesc = LayerDescBox.Parse(sLayerDesc);
            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        = null;
            Vector3D  bbLoad           = new Vector3D();
            Vector3D  bbGlob           = new Vector3D();
            string    palletMapPhrase  = string.Empty;

            byte[]   imageBytes    = null;
            string[] errors        = null;
            string[] listLayerDesc = new string[] { layerDesc.ToString() };
            StackBuilderProcessor.GetSolutionByLayer(
                boxProperties, palletProperties, interlayerProperties,
                constraintSet, layerDesc,
                cameraPosition, true, 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
                );

            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 = null,
                LayerDescs = listLayerDesc,
                PalletMapPhrase = palletMapPhrase,
                Errors = lErrors.ToArray()
            });
        }
示例#9
0
 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(LayerDesc obj)
 {
     return((obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr);
 }
示例#10
0
        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);
        }
示例#11
0
 public Layer2D BuildLayer(Vector3D dimBox, Vector2D dimContainer, LayerDesc layerDesc, Vector2D actualDimensions)
 { 
     // instantiate layer
     Layer2D layer = new Layer2D(dimBox, dimContainer, layerDesc.AxisOrtho, false);
     // get layer pattern
     LayerPattern pattern = LayerPattern.GetByName(layerDesc.PatternName);
     // build layer
     pattern.GenerateLayer(layer, actualDimensions.X, actualDimensions.Y);
     return layer;
 }