コード例 #1
0
        private Bitmap GetBoxBitmapFromDesc(PalletSolutionDesc desc)
        {
            bool showDimensions = false;

            // load document
            Document document = new Document(desc.FullFilePath, null);

            if (document.Analyses.Count != 1)
            {
                throw new Exception("Failed to load analysis.");
            }
            // get analysis and solution
            CasePalletAnalysis analysis = document.Analyses[0];
            Graphics3DImage    graphics = new Graphics3DImage(new Size(50, 50));

            graphics.CameraPosition = Graphics3D.Corner_0;
            graphics.Target         = Vector3D.Zero;
            Box box = new Box(0, analysis.BProperties);

            graphics.AddBox(box);
            if (showDimensions)
            {
                graphics.AddDimensions(new DimensionCube(box.Length, box.Width, box.Height));
            }
            graphics.Flush();
            return(graphics.Bitmap);
        }
コード例 #2
0
 protected void InsertImage(Analysis analysis, int colIndex)
 {
     try
     {
         if (analysis is AnalysisLayered analysisHomo)
         {
             var stackImagePath = Path.Combine(Path.ChangeExtension(Path.GetTempFileName(), "png"));
             var graphics       = new Graphics3DImage(new Size(768, 768))
             {
                 FontSizeRatio  = 0.01f,
                 CameraPosition = Graphics3D.Corner_0
             };
             using (ViewerSolution sv = new ViewerSolution(analysisHomo.SolutionLay))
                 sv.Draw(graphics, Transform3D.Identity);
             graphics.Flush();
             Bitmap bmp = graphics.Bitmap;
             bmp.Save(stackImagePath, System.Drawing.Imaging.ImageFormat.Png);
             Range imageCell = (Range)WSheet.Cells[RowIndex, colIndex];
             imageCell.RowHeight   = 128;
             imageCell.ColumnWidth = 24;
             WSheet.Shapes.AddPicture(stackImagePath,
                                      LinkToFile: MsoTriState.msoFalse,
                                      SaveWithDocument: MsoTriState.msoCTrue,
                                      Left: float.Parse(imageCell.Left.ToString()) + 1,
                                      Top: float.Parse(imageCell.Top.ToString()) + 1,
                                      Width: float.Parse(imageCell.Width.ToString()) - 2,
                                      Height: float.Parse(imageCell.Height.ToString()) - 2
                                      );
         }
     }
     catch (Exception ex)
     {
         _log.Error($"Failed to insert image in Excel sheet with error:{ex.Message}");
     }
 }
コード例 #3
0
 private void DrawBox()
 {
     try
     {
         // get horizontal angle
         double angle = trackBarHorizAngle.Value;
         // instantiate graphics
         Graphics3DImage graphics = new Graphics3DImage(pictureBox.Size);
         graphics.CameraPosition = new Vector3D(
             Math.Cos(angle * Math.PI / 180.0) * Math.Sqrt(2.0) * 10000.0
             , Math.Sin(angle * Math.PI / 180.0) * Math.Sqrt(2.0) * 10000.0
             , 10000.0);
         graphics.Target = Vector3D.Zero;
         graphics.SetViewport(-500.0f, -500.0f, 500.0f, 500.0f);
         // draw
         BoxProperties boxProperties = new BoxProperties(null, _boxProperties.Length, _boxProperties.Width, _boxProperties.Height);
         boxProperties.SetAllColors(_boxProperties.Colors);
         boxProperties.TextureList = _textures;
         Box box = new Box(0, boxProperties);
         graphics.AddBox(box);
         graphics.Flush();
         // set to picture box
         pictureBox.Image = graphics.Bitmap;
     }
     catch (Exception ex)
     {
         _log.Error(ex.ToString());
     }
 }
コード例 #4
0
        protected void InsertImage(Analysis analysis, int colIndex)
        {
            if (!(analysis is AnalysisLayered analysisHomo))
            {
                return;
            }
            var stackImagePath = Path.Combine(Path.ChangeExtension(Path.GetTempFileName(), "png"));
            var graphics       = new Graphics3DImage(new Size(768, 768))
            {
                FontSizeRatio  = 0.01f,
                CameraPosition = Graphics3D.Corner_0
            };

            using (ViewerSolution sv = new ViewerSolution(analysisHomo.SolutionLay))
                sv.Draw(graphics, Transform3D.Identity);
            graphics.Flush();
            Bitmap bmp = graphics.Bitmap;

            bmp.Save(stackImagePath, System.Drawing.Imaging.ImageFormat.Png);
            Range imageCell = (Range)WSheet.Cells[RowIndex, colIndex];

            imageCell.RowHeight   = 128;
            imageCell.ColumnWidth = 24;
            WSheet.Shapes.AddPicture(stackImagePath,
                                     LinkToFile: MsoTriState.msoFalse, SaveWithDocument: MsoTriState.msoCTrue,
                                     Left: (int)imageCell.Left + 1, Top: (int)imageCell.Top + 1, Width: (int)imageCell.Width - 2, Height: (int)imageCell.Height - 2);
        }
コード例 #5
0
        public static bool GetHSolutionPart(
            List <ContentItem> items,
            PalletProperties palletProperties,
            HConstraintSetPallet constraintSet,
            int solIndex, int binIndex,
            Vector3D cameraPosition, bool showCotations, float fontSizeRatio,
            Size sz,
            ref double weightLoad, ref double weightTotal,
            ref Vector3D bbLoad, ref Vector3D bbGlob,
            ref byte[] imageBytes,
            ref string[] errors
            )
        {
            List <string> lErrors = new List <string>();

            try
            {
                var analysis = new HAnalysisPallet(null)
                {
                    Pallet        = palletProperties,
                    ConstraintSet = constraintSet,
                    Content       = items,
                };
                HSolver solver    = new HSolver();
                var     solutions = solver.BuildSolutions(analysis);

                if (solIndex < solutions.Count)
                {
                    var sol = solutions[solIndex];
                    bbGlob      = sol.BBoxGlobal(binIndex).DimensionsVec;
                    bbLoad      = sol.BBoxLoad(binIndex).DimensionsVec;
                    weightLoad  = sol.LoadWeight(binIndex);
                    weightTotal = sol.Weight(binIndex);

                    Graphics3DImage graphics = new Graphics3DImage(sz)
                    {
                        FontSizeRatio  = fontSizeRatio,
                        CameraPosition = cameraPosition,
                        ShowDimensions = showCotations
                    };
                    ViewerHSolution sv = new ViewerHSolution(sol, binIndex);
                    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 valid solution found");
                }
            }
            catch (Exception ex)
            {
                lErrors.Add(ex.Message);
            }
            errors = lErrors.ToArray();
            return(0 == lErrors.Count);
        }
コード例 #6
0
        public static bool GetHSolutionBestCasePallet(
            List <ContentItem> items,
            PalletProperties palletProperties,
            HConstraintSetPallet constraintSet,
            Vector3D cameraPosition,
            bool showCotations, float fontSizeRatio, Size sz,
            ref int palletCount,
            ref string algorithm,
            ref byte[] imageBytes,
            ref string[] errors)
        {
            List <string> lErrors = new List <string>();

            try
            {
                var analysis = new HAnalysisPallet(null)
                {
                    Pallet        = palletProperties,
                    ConstraintSet = constraintSet,
                    Content       = items,
                };
                HSolver solver    = new HSolver();
                var     solutions = solver.BuildSolutions(analysis);

                // best solution is most likely : 5
                if (solutions.Count > 0)
                {
                    var sol = solutions[solutions.Count - 1];
                    algorithm   = sol.Algorithm;
                    palletCount = sol.SolItemCount;

                    Graphics3DImage graphics = new Graphics3DImage(sz)
                    {
                        FontSizeRatio  = fontSizeRatio,
                        CameraPosition = cameraPosition,
                        ShowDimensions = showCotations
                    };
                    ViewerHSolution sv = new ViewerHSolution(sol, 0);
                    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 valid solution found");
                }
            }
            catch (Exception ex)
            {
                lErrors.Add(ex.Message);
            }

            errors = lErrors.ToArray();
            return(0 == lErrors.Count);
        }
コード例 #7
0
        private void Draw()
        {
            try
            {
                // get current descriptor
                PalletSolutionDesc desc = CurrentSolutionDesc;
                // sanity check
                if (null == desc ||
                    pictureBoxCase.Size.Width < 1 || pictureBoxCase.Size.Height < 1 ||
                    pictureBoxSolution.Size.Width < 1 || pictureBoxSolution.Size.Height < 1)
                {
                    return;
                }

                // load document
                Document document = new Document(desc.FullFilePath, null);
                if (!document.AnalysesCasePallet.Any())
                {
                    return;
                }
                // get analysis and solution
                CasePalletAnalysis analysis = document.AnalysesCasePallet.First() as CasePalletAnalysis;
                {
                    Graphics3DImage graphics = new Graphics3DImage(pictureBoxCase.Size)
                    {
                        CameraPosition = Graphics3D.Corner_0,
                        Target         = Vector3D.Zero
                    };
                    Box box = new Box(0, analysis.BProperties);
                    graphics.AddBox(box);
                    graphics.AddDimensions(new DimensionCube(box.Length, box.Width, box.Height));
                    graphics.Flush();
                    pictureBoxCase.Image = graphics.Bitmap;
                }

                {
                    // instantiate graphics
                    Graphics3DImage graphics = new Graphics3DImage(pictureBoxSolution.Size)
                    {
                        // set camera position
                        CameraPosition = Graphics3D.Corner_0,
                        Target         = Vector3D.Zero
                    };
                    // instantiate solution viewer
                    CasePalletSolutionViewer sv = new CasePalletSolutionViewer(analysis.Solutions[0]);
                    sv.Draw(graphics);
                    graphics.Flush();
                    // show generated bitmap on picture box control
                    pictureBoxSolution.Image = graphics.Bitmap;
                }
            }
            catch (Exception ex)
            {
                _log.Error(ex.ToString());
            }
        }
コード例 #8
0
        private void FinalizeImageFromViewParameters(viewParameters vParam, Graphics3DImage graphics)
        {
            graphics.Flush();
            // attempt to create directory
            string dirPath = Path.GetDirectoryName(vParam.path);

            try { Directory.CreateDirectory(dirPath); }
            catch (Exception ex) { _log.Error(ex.Message); }
            // check that directory exists
            if (!Directory.Exists(dirPath))
            {
                throw new Exception(string.Format("Directory {0} does not exist!\n Can not generate output file!", Path.GetDirectoryName(vParam.path)));
            }
            // save image
            graphics.SaveAs(vParam.path);
            _log.Info(string.Format("Successfully saved file {0}", vParam.path));
        }
コード例 #9
0
        private void DrawBoxPosition(BProperties boxProperties, HalfAxis.HAxis axis, PictureBox pictureBox)
        {
            // get horizontal angle
            double angle = 45;
            // instantiate graphics
            Graphics3DImage graphics = new Graphics3DImage(pictureBox.Size)
            {
                CameraPosition = new Vector3D(
                    Math.Cos(angle * Math.PI / 180.0) * Math.Sqrt(2.0) * 100000.0
                    , Math.Sin(angle * Math.PI / 180.0) * Math.Sqrt(2.0) * 100000.0
                    , 10000.0),
                Target = Vector3D.Zero
            };

            graphics.SetViewport(-500.0f, -500.0f, 500.0f, 500.0f);
            // draw
            Box box = new Box(0, boxProperties);

            // set axes
            HalfAxis.HAxis lengthAxis = HalfAxis.HAxis.AXIS_X_P;
            HalfAxis.HAxis widthAxis  = HalfAxis.HAxis.AXIS_Y_P;
            switch (axis)
            {
            case HalfAxis.HAxis.AXIS_X_P: lengthAxis = HalfAxis.HAxis.AXIS_Z_P; widthAxis = HalfAxis.HAxis.AXIS_X_P; break;

            case HalfAxis.HAxis.AXIS_Y_P: lengthAxis = HalfAxis.HAxis.AXIS_X_P; widthAxis = HalfAxis.HAxis.AXIS_Z_N; break;

            case HalfAxis.HAxis.AXIS_Z_P: lengthAxis = HalfAxis.HAxis.AXIS_X_P; widthAxis = HalfAxis.HAxis.AXIS_Y_P; break;

            default: break;
            }
            box.HLengthAxis = lengthAxis;
            box.HWidthAxis  = widthAxis;

            // draw box
            graphics.AddBox(box);
            graphics.Flush();
            // set to picture box
            pictureBox.Image = graphics.Bitmap;
        }
コード例 #10
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());
            }
        }
コード例 #11
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);
            }
            // ###
        }
コード例 #12
0
        public static void GetSolution(
            Vector3D caseDim, double caseWeight, Bitmap bmpTexture,
            int palletIndex, double palletWeight,
            double maxPalletHeight,
            List <BoxPositionIndexed> boxPositions,
            bool mirrorLength, bool mirrorWidth,
            List <bool> interlayers,
            double angle,
            Size sz,
            ref byte[] imageBytes,
            ref int caseCount, ref int layerCount,
            ref double weightLoad, ref double weightTotal,
            ref Vector3D bbLoad, ref Vector3D bbGlob
            )
        {
            SolutionLayered.SetSolver(new LayerSolver());
            // case
            var boxProperties = new BoxProperties(null, caseDim.X, caseDim.Y, caseDim.Z)
            {
                TapeColor = Color.Tan,
                TapeWidth = new OptDouble(true, 50.0)
            };

            if (null != bmpTexture)
            {
                double ratio = (double)bmpTexture.Height / bmpTexture.Width;

                boxProperties.AddTexture(HalfAxis.HAxis.AXIS_X_N, TexturePosition(caseDim.Y, caseDim.Z, ratio), TextureSize(caseDim.Y, caseDim.Z, ratio), 0.0, bmpTexture);
                boxProperties.AddTexture(HalfAxis.HAxis.AXIS_X_P, TexturePosition(caseDim.Y, caseDim.Z, ratio), TextureSize(caseDim.Y, caseDim.Z, ratio), 0.0, bmpTexture);
                boxProperties.AddTexture(HalfAxis.HAxis.AXIS_Y_N, TexturePosition(caseDim.X, caseDim.Z, ratio), TextureSize(caseDim.X, caseDim.Z, ratio), 0.0, bmpTexture);
                boxProperties.AddTexture(HalfAxis.HAxis.AXIS_Y_P, TexturePosition(caseDim.X, caseDim.Z, ratio), TextureSize(caseDim.X, caseDim.Z, ratio), 0.0, bmpTexture);
            }
            boxProperties.SetWeight(caseWeight);
            boxProperties.SetAllColors(Enumerable.Repeat(Color.Beige, 6).ToArray());
            // pallet
            Vector3D palletDim        = PalletIndexToDim3D(palletIndex);
            var      palletProperties = new PalletProperties(null, PalletIndexToPalletType(palletIndex), palletDim.X, palletDim.Y, palletDim.Z)
            {
                Weight = palletWeight,
                Color  = Color.Yellow
            };
            // constraint set
            var constraintSet = new ConstraintSetCasePallet();

            constraintSet.SetAllowedOrientations(new bool[] { false, false, true });
            constraintSet.SetMaxHeight(new OptDouble(true, maxPalletHeight));
            // layer 2D
            var layer2D = new Layer2DBrickExpIndexed(caseDim, new Vector2D(), "", HalfAxis.HAxis.AXIS_Z_P);

            layer2D.SetPositions(boxPositions);
            // analysis
            var analysis = new AnalysisCasePallet(boxProperties, palletProperties, constraintSet);

            analysis.AddInterlayer(new InterlayerProperties(null, "interlayer", "", palletDim.X, palletDim.Y, 1.0, 0.0, Color.LightYellow));
            analysis.AddSolution(layer2D, mirrorLength, mirrorWidth);
            // solution
            SolutionLayered sol           = analysis.SolutionLay;
            var             solutionItems = sol.SolutionItems;
            int             iCount        = solutionItems.Count;

            for (int i = 0; i < iCount; ++i)
            {
                solutionItems[i].InterlayerIndex = ((i < interlayers.Count) && interlayers[i]) ? 0 : -1;
            }
            if (iCount < interlayers.Count && interlayers[iCount])
            {
                analysis.PalletCapProperties = new PalletCapProperties(null, "palletcap", "", palletDim.X, palletDim.Y, 1, palletDim.X, palletDim.Y, 0.0, 0.0, Color.LightYellow);
            }
            layerCount  = analysis.SolutionLay.LayerCount;
            caseCount   = analysis.Solution.ItemCount;
            weightLoad  = analysis.Solution.LoadWeight;
            weightTotal = analysis.Solution.Weight;
            bbGlob      = analysis.Solution.BBoxGlobal.DimensionsVec;
            bbLoad      = analysis.Solution.BBoxLoad.DimensionsVec;

            // generate image path
            Graphics3DImage graphics = new Graphics3DImage(sz)
            {
                BackgroundColor = Color.Transparent,
                FontSizeRatio   = ConfigSettings.FontSizeRatio,
                ShowDimensions  = true
            };

            graphics.SetCameraPosition(10000.0, angle, 45.0);

            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[]));
        }
コード例 #13
0
        public static void Export(
            Vector3D caseDim, double caseWeight,
            int palletIndex, double palletWeight,
            int noLayers,
            List <BoxPositionIndexed> listBoxPositionIndexed,
            bool mirrorLength, bool mirrorWidth,
            List <bool> interlayers,
            ref byte[] fileBytes,
            System.Drawing.Imaging.ImageFormat imageFormat,
            ref byte[] imageFileBytes)
        {
            SolutionLayered.SetSolver(new LayerSolver());

            // case
            var boxProperties = new BoxProperties(null, caseDim.X, caseDim.Y, caseDim.Z)
            {
                TapeColor = Color.LightGray,
                TapeWidth = new OptDouble(true, 50.0)
            };

            boxProperties.SetWeight(caseWeight);
            boxProperties.SetAllColors(Enumerable.Repeat(Color.Beige, 6).ToArray());
            // pallet
            Vector3D palletDim        = PalletIndexToDim3D(palletIndex);
            var      palletProperties = new PalletProperties(null, PalletIndexToPalletType(palletIndex), palletDim.X, palletDim.Y, palletDim.Z)
            {
                Weight = palletWeight,
                Color  = Color.Yellow
            };
            // constraint set
            var constraintSet = new ConstraintSetCasePallet();

            constraintSet.SetAllowedOrientations(new bool[] { false, false, true });
            constraintSet.OptMaxLayerNumber = noLayers;

            // layer
            var layer2D = new Layer2DBrickExpIndexed(caseDim, new Vector2D(palletDim.X, palletDim.Y), "", HalfAxis.HAxis.AXIS_Z_P);

            layer2D.SetPositions(listBoxPositionIndexed);
            // analysis
            var analysis = new AnalysisCasePallet(boxProperties, palletProperties, constraintSet);

            analysis.AddInterlayer(new InterlayerProperties(null, "interlayer", "", palletDim.X, palletDim.Y, 1.0, 0.0, Color.LightYellow));
            analysis.AddSolution(layer2D, mirrorLength, mirrorWidth);


            SolutionLayered sol           = analysis.SolutionLay;
            var             solutionItems = sol.SolutionItems;
            int             iCount        = solutionItems.Count;

            for (int i = 0; i < iCount; ++i)
            {
                solutionItems[i].InterlayerIndex = ((i < interlayers.Count) && interlayers[i]) ? 0 : -1;
            }
            if (iCount < interlayers.Count && interlayers[iCount])
            {
                analysis.PalletCapProperties = new PalletCapProperties(
                    null, "palletCap", "", palletDim.X, palletDim.Y, 1, palletDim.X, palletDim.Y, 0.0, 0.0, Color.LightYellow);
            }

            // export
            var exporter = ExporterFactory.GetExporterByName("csv (TechnologyBSA)");

            exporter.PositionCoordinateMode = Exporter.CoordinateMode.CM_COG;
            Stream stream = new MemoryStream();

            exporter.ExportIndexed(analysis, ref stream);
            // save stream to file
            using (var br = new BinaryReader(stream))
                fileBytes = br.ReadBytes((int)stream.Length);

            // image
            var graphics = new Graphics3DImage(ConfigSettings.ExportImageSize)
            {
                CameraPosition = Graphics3D.Corner_0,
                ShowDimensions = ConfigSettings.ExportShowDimensions
            };

            using (ViewerSolution sv = new ViewerSolution(analysis.SolutionLay))
                sv.Draw(graphics, Transform3D.Identity);
            graphics.Flush();

            imageFileBytes = ImageToByteArray(graphics.Bitmap, imageFormat);
        }
コード例 #14
0
ファイル: DocumentSB.cs プロジェクト: maoguoxus/StackBuilder
        public void ExportAnalysesToExcel()
        {
            // open excel file
            Microsoft.Office.Interop.Excel.Application xlApp = new Microsoft.Office.Interop.Excel.Application
            {
                Visible       = true,
                DisplayAlerts = false
            };
            Workbooks xlWorkBooks           = xlApp.Workbooks;
            Workbook  xlWorkBook            = xlWorkBooks.Add(Type.Missing);
            Worksheet xlWorkSheetCasePallet = xlWorkBook.Worksheets.get_Item(1);

            // create header
            xlWorkSheetCasePallet.Cells[1, 1]  = "Analysis name";
            xlWorkSheetCasePallet.Cells[1, 2]  = "Case name";
            xlWorkSheetCasePallet.Cells[1, 3]  = "Case description";
            xlWorkSheetCasePallet.Cells[1, 4]  = "Ext. length";
            xlWorkSheetCasePallet.Cells[1, 5]  = "Ext. width";
            xlWorkSheetCasePallet.Cells[1, 6]  = "Ext. height";
            xlWorkSheetCasePallet.Cells[1, 7]  = "Max pallet height";
            xlWorkSheetCasePallet.Cells[1, 8]  = "Solution case count";
            xlWorkSheetCasePallet.Cells[1, 9]  = "Layers";
            xlWorkSheetCasePallet.Cells[1, 10] = "Cases per layer";
            xlWorkSheetCasePallet.Cells[1, 11] = "Load weight";
            xlWorkSheetCasePallet.Cells[1, 12] = "Weight";
            xlWorkSheetCasePallet.Cells[1, 13] = "Volume efficiency";
            xlWorkSheetCasePallet.Cells[1, 14] = "Image";

            Range headerRange = xlWorkSheetCasePallet.get_Range("A1", "N1");

            headerRange.Font.Bold = true;
            xlWorkSheetCasePallet.Columns.AutoFit();


            // *** get all users from Azure database and write them down
            int iRowCasePallet = 2;

            foreach (var analysis in Analyses)
            {
                try
                {
                    if (analysis is AnalysisCasePallet analysisCasePallet)
                    {
                        // analysis name
                        xlWorkSheetCasePallet.Cells[iRowCasePallet, 1] = analysisCasePallet.Name;
                        // case
                        BoxProperties caseProperties = analysisCasePallet.Content as BoxProperties;
                        xlWorkSheetCasePallet.Cells[iRowCasePallet, 2] = caseProperties.Name;
                        xlWorkSheetCasePallet.Cells[iRowCasePallet, 3] = caseProperties.Description;
                        xlWorkSheetCasePallet.Cells[iRowCasePallet, 4] = caseProperties.Length;
                        xlWorkSheetCasePallet.Cells[iRowCasePallet, 5] = caseProperties.Width;
                        xlWorkSheetCasePallet.Cells[iRowCasePallet, 6] = caseProperties.Height;
                        // constraints
                        ConstraintSetCasePallet constraintSet = analysisCasePallet.ConstraintSet as ConstraintSetCasePallet;
                        xlWorkSheetCasePallet.Cells[iRowCasePallet, 7] = constraintSet.OptMaxHeight.Value;
                        // solution
                        Solution sol = analysisCasePallet.Solution;
                        xlWorkSheetCasePallet.Cells[iRowCasePallet, 8]  = sol.ItemCount;
                        xlWorkSheetCasePallet.Cells[iRowCasePallet, 9]  = sol.LayerCount;
                        xlWorkSheetCasePallet.Cells[iRowCasePallet, 10] = sol.LayerBoxCount(0);
                        xlWorkSheetCasePallet.Cells[iRowCasePallet, 11] = sol.LoadWeight;
                        xlWorkSheetCasePallet.Cells[iRowCasePallet, 12] = sol.Weight;
                        xlWorkSheetCasePallet.Cells[iRowCasePallet, 13] = sol.VolumeEfficiency;

                        var stackImagePath = Path.Combine(Path.ChangeExtension(Path.GetTempFileName(), "png"));
                        var graphics       = new Graphics3DImage(new Size(768, 768))
                        {
                            FontSizeRatio  = 0.01f,
                            CameraPosition = Graphics3D.Corner_0
                        };
                        using (ViewerSolution sv = new ViewerSolution(analysis.Solution))
                            sv.Draw(graphics, Transform3D.Identity);
                        graphics.Flush();
                        Bitmap bmp = graphics.Bitmap;
                        bmp.Save(stackImagePath, System.Drawing.Imaging.ImageFormat.Png);
                        Range imageCell = (Range)xlWorkSheetCasePallet.Cells[iRowCasePallet, 14];
                        imageCell.RowHeight   = 128;
                        imageCell.ColumnWidth = 24;
                        xlWorkSheetCasePallet.Shapes.AddPicture(stackImagePath,
                                                                LinkToFile: MsoTriState.msoFalse, SaveWithDocument: MsoTriState.msoCTrue,
                                                                Left: imageCell.Left + 1, Top: imageCell.Top + 1, Width: imageCell.Width - 2, Height: imageCell.Height - 2);

                        ++iRowCasePallet;
                    }
                    else if (analysis is AnalysisBoxCase analysisBoxCase)
                    {
                    }
                    else if (analysis is AnalysisCaseTruck analysisCaseTruck)
                    {
                    }
                    else if (analysis is AnalysisCylinderPallet analysisCylinderPallet)
                    {
                    }
                    else if (analysis is AnalysisCylinderCase analysisCylinderCase)
                    {
                    }
                    else if (analysis is AnalysisCylinderTruck analysisCylinderTruck)
                    {
                    }
                }
                catch (Exception ex)
                {
                    _log.Error(ex.ToString());
                }
            }
        }
コード例 #15
0
        static void Main(string[] args)
        {
            ILog log = LogManager.GetLogger(typeof(Program));

            XmlConfigurator.Configure();

            try
            {
                // instantiate graphics
                Graphics3DImage graphics = new Graphics3DImage(new Size(512, 512));
                graphics.CameraPosition = new Vector3D(-10000.0, -10000.0, 10000.0);
                graphics.Target         = Vector3D.Zero;
                graphics.SetViewport(-500.0f, -500.0f, 500.0f, 500.0f);
                // load Bitmap
                string         imageFilePath = @"..\..\Image16.bmp";
                Bitmap         bmp           = new Bitmap(imageFilePath);
                Texture        texture       = new Texture(bmp, new Vector2D(100.0, 20.0), new Vector2D(40.0 * bmp.Size.Width / bmp.Size.Height, 40.0), 10.0);
                List <Texture> listTexture   = new List <Texture>();
                listTexture.Add(texture);
                // instantiate box and draw
                List <Box> boxList = new List <Box>();
                Box        box0    = new Box(0, 200.0, 160.0, 100.0);
                box0.Position = Vector3D.Zero;
                box0.SetAllFacesColor(Color.Chocolate);
                box0.SetFaceTextures(HalfAxis.HAxis.AXIS_X_P, listTexture);
                box0.SetFaceTextures(HalfAxis.HAxis.AXIS_Y_P, listTexture);
                box0.SetFaceTextures(HalfAxis.HAxis.AXIS_Z_P, listTexture);
                box0.SetFaceTextures(HalfAxis.HAxis.AXIS_X_N, listTexture);
                box0.SetFaceTextures(HalfAxis.HAxis.AXIS_Y_N, listTexture);
                box0.SetFaceTextures(HalfAxis.HAxis.AXIS_Z_N, listTexture);
                boxList.Add(box0);
                Box box1 = new Box(1, 200.0, 160.0, 100.0);
                box1.Position = new Vector3D(210.0, 0.0, 0.0);
                box1.SetAllFacesColor(Color.Chocolate);
                box1.SetFaceTextures(HalfAxis.HAxis.AXIS_Y_P, listTexture);
                boxList.Add(box1);

                Box box2 = new Box(2, 200.0, 160.0, 100.0);
                box2.Position = new Vector3D(0.0, 170.0, 0.0);
                box2.SetAllFacesColor(Color.Chocolate);
                boxList.Add(box2);

                Box box3 = new Box(3, 200.0, 160.0, 100.0);
                box3.Position = new Vector3D(0.0, 0.0, 110.0);
                box3.SetAllFacesColor(Color.Chocolate);
                boxList.Add(box3);

                // draw
                foreach (Box box in boxList)
                {
                    graphics.AddBox(box);
                }
                graphics.Flush();
                // Save as %TEMP%\Pallet.jpg
                string filePath = Path.Combine(Path.GetTempPath(), "Pallet.bmp");
                graphics.SaveAs(filePath);

                bmp.Dispose();

                // open file
                using (System.Diagnostics.Process proc = new System.Diagnostics.Process())
                {
                    proc.StartInfo.FileName  = "mspaint.exe";
                    proc.StartInfo.Arguments = filePath;
                    proc.Start();
                }
            }
            catch (System.Exception ex)
            {
                log.Error(ex.ToString());
            }
        }
コード例 #16
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);
        }
コード例 #17
0
        public static bool GetHSolutionBestCasePallet(
            List <ContentItem> items,
            PalletProperties palletProperties,
            HConstraintSetPallet constraintSet,
            Vector3D cameraPosition,
            bool showCotations, float fontSizeRatio, Size sz,
            ref int palletCount,
            ref string algorithm,
            ref byte[] imageBytes,
            ref string[] errors)
        {
            List <string> lErrors = new List <string>();

            try
            {
                var analysis = new HAnalysisPallet(null)
                {
                    Pallet        = palletProperties,
                    ConstraintSet = constraintSet,
                    Content       = items,
                };
                HSolver solver    = new HSolver();
                var     solutions = solver.BuildSolutions(analysis);

                // get first solution (Sharp3DBin packing)
                if (solutions.Count > 0)
                {
                    var sol = solutions[0];
                    algorithm   = sol.Algorithm;
                    palletCount = sol.SolItemCount;

                    var tileSize  = ImageTiling.TileSize(sz, palletCount);
                    var listTiles = new List <Bitmap>();

                    for (int i = 0; i < palletCount; ++i)
                    {
                        Graphics3DImage graphics = new Graphics3DImage(tileSize)
                        {
                            FontSizeRatio  = fontSizeRatio,
                            CameraPosition = cameraPosition,
                            ShowDimensions = showCotations
                        };
                        ViewerHSolution sv = new ViewerHSolution(sol, i);
                        sv.Draw(graphics, Transform3D.Identity);
                        graphics.Flush();
                        listTiles.Add(graphics.Bitmap);
                    }

                    var            bmp       = ImageTiling.TileImage(sz, listTiles);
                    ImageConverter converter = new ImageConverter();
                    imageBytes = (byte[])converter.ConvertTo(bmp, typeof(byte[]));
                }
                else
                {
                    lErrors.Add("No valid solution found");
                }
            }
            catch (Exception ex)
            {
                lErrors.Add(ex.Message);
            }

            errors = lErrors.ToArray();
            return(0 == lErrors.Count);
        }
コード例 #18
0
    public static void GetSolution(
        Vector3D caseDim, double caseWeight,
        Vector3D palletDim, double palletWeight,
        double maxPalletHeight,
        List <BoxPosition> boxPositions,
        bool alternateLayer,
        bool interlayerBottom, bool interlayerIntermediate, bool interlayerTop,
        double angle,
        ref byte[] imageBytes,
        ref int caseCount, ref int layerCount,
        ref double weightLoad, ref double weightTotal,
        ref Vector3D bbLoad, ref Vector3D bbGlob
        )
    {
        SolutionLayered.SetSolver(new LayerSolver());
        // case
        var boxProperties = new BoxProperties(null, caseDim.X, caseDim.Y, caseDim.Z)
        {
            TapeColor = Color.LightGray,
            TapeWidth = new OptDouble(true, 50.0)
        };

        boxProperties.SetWeight(caseWeight);
        boxProperties.SetAllColors(Enumerable.Repeat(Color.Beige, 6).ToArray());
        // pallet
        var palletProperties = new PalletProperties(null, "EUR2", palletDim.X, palletDim.Y, palletDim.Z)
        {
            Weight = palletWeight,
            Color  = Color.Yellow
        };
        // constraint set
        var constraintSet = new ConstraintSetCasePallet();

        constraintSet.SetAllowedOrientations(new bool[] { false, false, true });
        constraintSet.SetMaxHeight(new OptDouble(true, maxPalletHeight));
        // layer 2D
        var layer2D = new Layer2DBrickExp(caseDim, new Vector2D(), "", HalfAxis.HAxis.AXIS_Z_P);

        layer2D.SetPositions(boxPositions);
        // analysis
        var analysis = new AnalysisCasePallet(boxProperties, palletProperties, constraintSet);

        analysis.AddInterlayer(new InterlayerProperties(null, "interlayer", "", palletDim.X, palletDim.Y, 1.0, 0.0, Color.LightYellow));
        analysis.AddSolution(layer2D, alternateLayer);
        if (interlayerTop)
        {
            analysis.PalletCapProperties = new PalletCapProperties(null, "palletcap", "", palletDim.X, palletDim.Y, 1, palletDim.X, palletDim.Y, 0.0, 0.0, Color.LightYellow);
        }
        // solution
        SolutionLayered sol           = analysis.SolutionLay;
        var             solutionItems = sol.SolutionItems;
        int             iCount        = solutionItems.Count;

        for (int i = 0; i < iCount; ++i)
        {
            bool hasInterlayer = (i == 0 && interlayerBottom) ||
                                 (i != 0 && interlayerIntermediate);
            solutionItems[i].InterlayerIndex = hasInterlayer ? 0 : -1;
        }
        layerCount  = analysis.SolutionLay.LayerCount;
        caseCount   = analysis.Solution.ItemCount;
        weightLoad  = analysis.Solution.LoadWeight;
        weightTotal = analysis.Solution.Weight;
        bbGlob      = analysis.Solution.BBoxGlobal.DimensionsVec;
        bbLoad      = analysis.Solution.BBoxLoad.DimensionsVec;

        // generate image path
        Graphics3DImage graphics = new Graphics3DImage(new Size(500, 500))
        {
            FontSizeRatio  = ConfigSettings.FontSizeRatio,
            ShowDimensions = true
        };

        graphics.SetCameraPosition(10000.0, angle, 45.0);

        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[]));
    }
コード例 #19
0
ファイル: Program.cs プロジェクト: zanxueyan/StackBuilder
        private static void RunBoxTest(bool useSingleColor, Document doc, PalletProperties palletProperties)
        {
            // define box properties
            var boxProperties = new BoxProperties(doc, 162, 210, 250);

            //boxProperties.Name = "Box1";
            boxProperties.SetWeight(3.0);
            if (!useSingleColor)
            {
                boxProperties.SetColor(HalfAxis.HAxis.AXIS_X_N, Color.Red);
                boxProperties.SetColor(HalfAxis.HAxis.AXIS_X_P, Color.Red);
                boxProperties.SetColor(HalfAxis.HAxis.AXIS_Y_N, Color.Green);
                boxProperties.SetColor(HalfAxis.HAxis.AXIS_Y_P, Color.Green);
                boxProperties.SetColor(HalfAxis.HAxis.AXIS_Z_N, Color.Blue);
                boxProperties.SetColor(HalfAxis.HAxis.AXIS_Z_P, Color.Blue);
            }
            else
            {
                boxProperties.SetColor(Color.Chocolate);
            }

            Console.WriteLine(boxProperties.ToString());


            InterlayerProperties interlayerProperties = null;

            // define constraints
            var constraintSet = new CasePalletConstraintSet();

            constraintSet.SetAllowedOrthoAxis(HalfAxis.HAxis.AXIS_X_N, true);
            constraintSet.SetAllowedOrthoAxis(HalfAxis.HAxis.AXIS_X_P, true);
            constraintSet.SetAllowedOrthoAxis(HalfAxis.HAxis.AXIS_Y_N, true);
            constraintSet.SetAllowedOrthoAxis(HalfAxis.HAxis.AXIS_Y_P, true);
            constraintSet.SetAllowedOrthoAxis(HalfAxis.HAxis.AXIS_Z_N, true);
            constraintSet.SetAllowedOrthoAxis(HalfAxis.HAxis.AXIS_Z_P, true);

            constraintSet.SetAllowedPattern("Trilock");

            constraintSet.AllowAlignedLayers   = true;
            constraintSet.AllowAlternateLayers = false;

            constraintSet.MaximumPalletWeight             = 2000;
            constraintSet.MaximumNumberOfItems            = 2000;
            constraintSet.MaximumHeight                   = 2000.0;
            constraintSet.UseMaximumHeight                = true;
            constraintSet.UseMaximumPalletWeight          = true;
            constraintSet.UseMaximumWeightOnBox           = false;
            constraintSet.AllowLastLayerOrientationChange = true;
            Console.WriteLine("=== Constraint set ===");
            Console.WriteLine(constraintSet.ToString());

            // initialize analysis
            var analysis = new CasePalletAnalysis(
                boxProperties, palletProperties, interlayerProperties,
                null, null, null, null,
                constraintSet);

            // initialize solver
            var solver = new CasePalletSolver();

            solver.ProcessAnalysis(analysis);

            Console.WriteLine("=== Solutions ===");
            int solIndex = 0;

            foreach (CasePalletSolution sol in analysis.Solutions)
            {
                // instantiate graphics
                Graphics3DImage graphics = new Graphics3DImage(new Size(1000, 1000));
                graphics.CameraPosition = new Vector3D(10000.0, 10000.0, 10000.0);
                graphics.Target         = Vector3D.Zero;
                graphics.SetViewport(-500.0f, -500.0f, 500.0f, 500.0f);
                // instantiate solution viewer
                CasePalletSolutionViewer sv = new CasePalletSolutionViewer(sol);
                sv.Draw(graphics);
                graphics.Flush();
                // save
                string fileName = string.Format("Pallet_{0}.bmp", solIndex++);
                string filePath = Path.Combine(Path.GetTempPath(), fileName);
                Console.WriteLine("Saving file " + filePath + "...");
                graphics.SaveAs(filePath);
            }
        }
コード例 #20
0
ファイル: Program.cs プロジェクト: wkumanuvong/StackBuilder
        static int Main(string[] args)
        {
            ILog log = LogManager.GetLogger(typeof(Program));

            XmlConfigurator.Configure();

            try
            {
                bool useSingleColor = false;
                // instantiate document
                Document doc = new Document("Test", "Test", "fga", DateTime.Now, null);

                // define pallet properties
                PalletProperties palletProperties = new PalletProperties(doc, "EUR2", 1200, 1000, 150);
                Console.WriteLine("=== Pallet properties ===");
                Console.WriteLine(palletProperties.ToString());

                bool testCylinder = false;
                if (!testCylinder)
                {
                    // define box properties
                    BoxProperties boxProperties = new BoxProperties(doc, 162, 210, 250);
                    boxProperties.Name   = "Box1";
                    boxProperties.Weight = 3.0;
                    if (!useSingleColor)
                    {
                        boxProperties.SetColor(HalfAxis.HAxis.AXIS_X_N, Color.Red);
                        boxProperties.SetColor(HalfAxis.HAxis.AXIS_X_P, Color.Red);
                        boxProperties.SetColor(HalfAxis.HAxis.AXIS_Y_N, Color.Green);
                        boxProperties.SetColor(HalfAxis.HAxis.AXIS_Y_P, Color.Green);
                        boxProperties.SetColor(HalfAxis.HAxis.AXIS_Z_N, Color.Blue);
                        boxProperties.SetColor(HalfAxis.HAxis.AXIS_Z_P, Color.Blue);
                    }
                    else
                    {
                        boxProperties.SetColor(Color.Chocolate);
                    }

                    Console.WriteLine(boxProperties.ToString());


                    InterlayerProperties interlayerProperties = null;

                    // define constraints
                    CasePalletConstraintSet constraintSet = new CasePalletConstraintSet();
                    constraintSet.SetAllowedOrthoAxis(HalfAxis.HAxis.AXIS_X_N, true);
                    constraintSet.SetAllowedOrthoAxis(HalfAxis.HAxis.AXIS_X_P, true);
                    constraintSet.SetAllowedOrthoAxis(HalfAxis.HAxis.AXIS_Y_N, true);
                    constraintSet.SetAllowedOrthoAxis(HalfAxis.HAxis.AXIS_Y_P, true);
                    constraintSet.SetAllowedOrthoAxis(HalfAxis.HAxis.AXIS_Z_N, true);
                    constraintSet.SetAllowedOrthoAxis(HalfAxis.HAxis.AXIS_Z_P, true);

                    constraintSet.SetAllowedPattern("Trilock");

                    constraintSet.AllowAlignedLayers   = true;
                    constraintSet.AllowAlternateLayers = false;

                    constraintSet.MaximumPalletWeight             = 2000;
                    constraintSet.MaximumNumberOfItems            = 2000;
                    constraintSet.MaximumHeight                   = 2000.0;
                    constraintSet.UseMaximumHeight                = true;
                    constraintSet.UseMaximumPalletWeight          = true;
                    constraintSet.UseMaximumWeightOnBox           = false;
                    constraintSet.AllowLastLayerOrientationChange = true;
                    Console.WriteLine("=== Constraint set ===");
                    Console.WriteLine(constraintSet.ToString());

                    // initialize analysis
                    CasePalletAnalysis analysis = new CasePalletAnalysis(
                        boxProperties, palletProperties, interlayerProperties,
                        null, null, null, null,
                        constraintSet);

                    // initialize solver
                    CasePalletSolver solver = new CasePalletSolver();
                    solver.ProcessAnalysis(analysis);

                    Console.WriteLine("=== Solutions ===");
                    int solIndex = 0;
                    foreach (CasePalletSolution sol in analysis.Solutions)
                    {
                        // instantiate graphics
                        Graphics3DImage graphics = new Graphics3DImage(new Size(1000, 1000));
                        graphics.CameraPosition = new Vector3D(10000.0, 10000.0, 10000.0);
                        graphics.Target         = Vector3D.Zero;
                        graphics.SetViewport(-500.0f, -500.0f, 500.0f, 500.0f);
                        // instantiate solution viewer
                        CasePalletSolutionViewer sv = new CasePalletSolutionViewer(sol);
                        sv.Draw(graphics);
                        graphics.Flush();
                        // save
                        string fileName = string.Format("Pallet_{0}.bmp", solIndex++);
                        string filePath = Path.Combine(Path.GetTempPath(), fileName);
                        Console.WriteLine("Saving file " + filePath + "...");
                        graphics.SaveAs(filePath);
                    }
                }
                else
                {
                    // cylinder
                    Console.WriteLine("=== Cylinder properties ===");
                    CylinderProperties cylProperties = new CylinderProperties(doc, "Cylinder", "Default cylinder",
                                                                              90, 45.0, 100, 1.5, Color.Gray, Color.SkyBlue, Color.SkyBlue);
                    Console.WriteLine(cylProperties.ToString());
                    // constraint set
                    Console.WriteLine("=== Constraint set ===");
                    CylinderPalletConstraintSet constraintSet = new CylinderPalletConstraintSet();
                    constraintSet.UseMaximumPalletHeight  = true;
                    constraintSet.MaximumPalletHeight     = 1200.0;
                    constraintSet.UseMaximumPalletWeight  = true;
                    constraintSet.MaximumPalletWeight     = 2000;
                    constraintSet.UseMaximumNumberOfItems = true;
                    constraintSet.MaximumNumberOfItems    = 2000;
                    Console.WriteLine(constraintSet.ToString());
                    // cylinder analysis
                    CylinderPalletAnalysis analysis = new CylinderPalletAnalysis(cylProperties, palletProperties, null, null, constraintSet);
                    // initialize solver
                    CylinderSolver solver = new CylinderSolver();
                    solver.ProcessAnalysis(analysis);
                    Console.WriteLine("=== Solutions ===");
                    int solIndex = 0;
                    foreach (CylinderPalletSolution sol in analysis.Solutions)
                    {
                        // instantiate graphics
                        Graphics3DImage graphics = new Graphics3DImage(new Size(512, 512));
                        graphics.CameraPosition = new Vector3D(10000.0, 10000.0, 10000.0);
                        graphics.Target         = Vector3D.Zero;
                        graphics.SetViewport(-500.0f, -500.0f, 500.0f, 500.0f);
                        // instantiate solution viewer
                        CylinderPalletSolutionViewer sv = new CylinderPalletSolutionViewer(sol);
                        sv.Draw(graphics);
                        string fileName = string.Format("Pallet_{0}.jpg", solIndex++);
                        string filePath = Path.Combine(Path.GetTempPath(), fileName);
                        Console.WriteLine("Saving file " + filePath + "...");
                        graphics.SaveAs(filePath);
                    }
                }
            }
            catch (Exception ex)
            {
                log.Error(ex.ToString());
            }
            return(0);
        }
コード例 #21
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);
        }
コード例 #22
0
ファイル: Program.cs プロジェクト: NayeliRC/StackBuilder
        static void Main(string[] args)
        {
            string        outputDir = @"D:\GitHub\StackBuilder\Sources\Test\treeDiM.StackBuilder.Engine.Heterogeneous3D.Test\Output";
            DirectoryInfo directory = new DirectoryInfo(outputDir);

            directory.Empty();

            var palletProperties = new PalletProperties(null, "EUR2", 1200.0, 1000.0, 140.0)
            {
                Color  = Color.Yellow,
                Weight = 22.0
            };
            bool allowXY = false;

            var items = new List <ContentItem>
            {
                new ContentItem(new BoxProperties(null, 190, 200, 420, 10.0, Color.Red), 2)
                {
                    AllowedOrientations = new bool[] { allowXY, allowXY, true }
                },
                new ContentItem(new BoxProperties(null, 250, 200, 300, 10.0, Color.Blue), 1)
                {
                    AllowedOrientations = new bool[] { allowXY, allowXY, true }
                },
                new ContentItem(new BoxProperties(null, 250, 200, 250, 10.0, Color.Green), 1)
                {
                    AllowedOrientations = new bool[] { allowXY, allowXY, true }
                },
                new ContentItem(new BoxProperties(null, 250, 200, 290, 10.0, Color.Green), 1)
                {
                    AllowedOrientations = new bool[] { allowXY, allowXY, true }
                },
                new ContentItem(new BoxProperties(null, 80, 200, 210, 10.0, Color.White), 4)
                {
                    AllowedOrientations = new bool[] { allowXY, allowXY, true }
                },                                                                                                                                            // 9

                new ContentItem(new BoxProperties(null, 360, 460, 840, 10.0, Color.Purple), 1)
                {
                    AllowedOrientations = new bool[] { allowXY, allowXY, true }
                },
                new ContentItem(new BoxProperties(null, 160, 460, 100, 10.0, Color.AliceBlue), 2)
                {
                    AllowedOrientations = new bool[] { allowXY, allowXY, true }
                },
                new ContentItem(new BoxProperties(null, 160, 460, 320, 10.0, Color.Beige), 2)
                {
                    AllowedOrientations = new bool[] { allowXY, allowXY, true }
                },
                new ContentItem(new BoxProperties(null, 200, 300, 150, 10.0, Color.Brown), 1)
                {
                    AllowedOrientations = new bool[] { allowXY, allowXY, true }
                },
                new ContentItem(new BoxProperties(null, 200, 300, 690, 10.0, Color.Chartreuse), 1)
                {
                    AllowedOrientations = new bool[] { allowXY, allowXY, true }
                },                                                                                                                                                  // 7

                new ContentItem(new BoxProperties(null, 200, 300, 210, 10.0, Color.Cyan), 4)
                {
                    AllowedOrientations = new bool[] { allowXY, allowXY, true }
                },
                new ContentItem(new BoxProperties(null, 120, 300, 70, 10.0, Color.LightPink), 12)
                {
                    AllowedOrientations = new bool[] { allowXY, allowXY, true }
                },
                new ContentItem(new BoxProperties(null, 520, 600, 420, 10.0, Color.LightGray), 2)
                {
                    AllowedOrientations = new bool[] { allowXY, allowXY, true }, PriorityLevel = 0
                },
                new ContentItem(new BoxProperties(null, 260, 360, 210, 10.0, Color.Yellow), 4)
                {
                    AllowedOrientations = new bool[] { allowXY, allowXY, true }
                },
                new ContentItem(new BoxProperties(null, 260, 360, 840, 10.0, Color.Orange), 1)
                {
                    AllowedOrientations = new bool[] { allowXY, allowXY, true }
                }                                                                                                                                              // 23
            };

            var sortedItems = items.OrderBy(i => i.Pack.OuterDimensions.X * i.Pack.OuterDimensions.Y * i.Number).ToList();

            var constraintSet = new HConstraintSetPallet()
            {
                MaximumHeight = 1300.0
            };

            var analysis = new HAnalysisPallet(null)
            {
                Pallet        = palletProperties,
                ConstraintSet = constraintSet,
                Content       = sortedItems
            };
            HSolver solver    = new HSolver();
            var     solutions = solver.BuildSolutions(analysis);

            int solIndex = 0;

            foreach (var sol in solutions)
            {
                Vector3D[] orientations = new Vector3D[] { Graphics3D.Corner_0, Graphics3D.Corner_90, Graphics3D.Corner_180, Graphics3D.Corner_270 };
                for (int iOrientation = 0; iOrientation < 4; ++iOrientation)
                {
                    List <Bitmap> images = new List <Bitmap>();
                    for (int binIndex = 0; binIndex < sol.SolItemCount; ++binIndex)
                    {
                        Vector3D bbGlob      = sol.BBoxGlobal(binIndex).DimensionsVec;
                        Vector3D bbLoad      = sol.BBoxLoad(binIndex).DimensionsVec;
                        double   weightLoad  = sol.LoadWeight(binIndex);
                        double   weightTotal = sol.Weight(binIndex);


                        Graphics3DImage graphics = new Graphics3DImage(ImageTiling.TileSize(new Size(4000, 4000), sol.SolItemCount))
                        {
                            FontSizeRatio  = 0.02f,
                            CameraPosition = orientations[iOrientation],
                            ShowDimensions = false
                        };
                        ViewerHSolution sv = new ViewerHSolution(sol, binIndex);
                        sv.Draw(graphics, Transform3D.Identity);
                        graphics.Flush();
                        images.Add(graphics.Bitmap);
                    }
                    Bitmap gBmp           = ImageTiling.TileImage(new Size(2000, 2000), images);
                    string sbSolutionName = $"sol_{sol.Algorithm}_{solIndex}_{iOrientation}.png";
                    gBmp.Save(Path.Combine(outputDir, sbSolutionName));

                    Console.WriteLine($"Saving {sbSolutionName}...");
                }
                ++solIndex;
            }
        }