Exemplo n.º 1
0
        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;
        }
        private void FillGrid()
        {
            // fill grid solution
            gridSolutions.Rows.Clear();

            // border
            DevAge.Drawing.BorderLine border = new DevAge.Drawing.BorderLine(Color.DarkBlue, 1);
            DevAge.Drawing.RectangleBorder cellBorder = new DevAge.Drawing.RectangleBorder(border, border);

            // views
            CellBackColorAlternate viewNormal = new CellBackColorAlternate(Color.LightBlue, Color.White);
            viewNormal.Border = cellBorder;
            CheckboxBackColorAlternate viewNormalCheck = new CheckboxBackColorAlternate(Color.LightBlue, Color.White);
            viewNormalCheck.Border = cellBorder;

            // column header view
            SourceGrid.Cells.Views.ColumnHeader viewColumnHeader = new SourceGrid.Cells.Views.ColumnHeader();
            DevAge.Drawing.VisualElements.ColumnHeader backHeader = new DevAge.Drawing.VisualElements.ColumnHeader();
            backHeader.BackColor = Color.LightGray;
            backHeader.Border = DevAge.Drawing.RectangleBorder.NoBorder;
            viewColumnHeader.Background = backHeader;
            viewColumnHeader.ForeColor = Color.White;
            viewColumnHeader.Font = new Font("Arial", 10, FontStyle.Bold);
            viewColumnHeader.ElementSort.SortStyle = DevAge.Drawing.HeaderSortStyle.None;

            // create the grid
            gridSolutions.BorderStyle = BorderStyle.FixedSingle;

            gridSolutions.ColumnsCount = 8;
            gridSolutions.FixedRows = 1;
            gridSolutions.Rows.Insert(0);

            // header
            SourceGrid.Cells.ColumnHeader columnHeader;

            columnHeader = new SourceGrid.Cells.ColumnHeader(Resources.ID_INDEX);
            columnHeader.AutomaticSortEnabled = false;
            columnHeader.View = viewColumnHeader;
            gridSolutions[0, 0] = columnHeader;

            columnHeader = new SourceGrid.Cells.ColumnHeader(Resources.ID_LAYERPATTERN);
            columnHeader.AutomaticSortEnabled = false;
            columnHeader.View = viewColumnHeader;
            gridSolutions[0, 1] = columnHeader;

            columnHeader = new SourceGrid.Cells.ColumnHeader(Resources.ID_CASECOUNT);
            columnHeader.AutomaticSortEnabled = false;
            columnHeader.View = viewColumnHeader;
            gridSolutions[0, 2] = columnHeader;

            columnHeader = new SourceGrid.Cells.ColumnHeader(Resources.ID_VOLUMEEFFICIENCY);
            columnHeader.AutomaticSortEnabled = false;
            columnHeader.View = viewColumnHeader;
            gridSolutions[0, 3] = columnHeader;

            columnHeader = new SourceGrid.Cells.ColumnHeader(string.Format(Resources.ID_PALLETWEIGHT, UnitsManager.MassUnitString));
            columnHeader.AutomaticSortEnabled = false;
            columnHeader.View = viewColumnHeader;
            gridSolutions[0, 4] = columnHeader;

            columnHeader = new SourceGrid.Cells.ColumnHeader(string.Format(Resources.ID_PALLETHEIGHT, UnitsManager.LengthUnitString));
            columnHeader.AutomaticSortEnabled = false;
            columnHeader.View = viewColumnHeader;
            gridSolutions[0, 5] = columnHeader;

            columnHeader = new SourceGrid.Cells.ColumnHeader(Resources.ID_PALLETLIMIT);
            columnHeader.AutomaticSortEnabled = false;
            columnHeader.View = viewColumnHeader;
            gridSolutions[0, 6] = columnHeader;

            columnHeader = new SourceGrid.Cells.ColumnHeader(Resources.ID_SELECTED);
            columnHeader.AutomaticSortEnabled = false;
            columnHeader.View = viewColumnHeader;
            gridSolutions[0, 7] = columnHeader;

            // handling check box click
            SourceGrid.Cells.Controllers.CustomEvents solCheckboxClickEvent = new SourceGrid.Cells.Controllers.CustomEvents();
            solCheckboxClickEvent.Click += new EventHandler(clickEvent_Click);

            // data rows
            int iIndex = 0;
            foreach (CylinderPalletSolution sol in _analysis.Solutions)
            {
                // build case count string
                string sCaseCount = string.Empty;
                if (sol.HasSameCountLayers && sol.LimitReached == Limit.LIMIT_MAXHEIGHTREACHED)
                    sCaseCount = string.Format("{0}\n({1} * {2})", sol.CylinderCount, sol.CylinderPerLayerCount, sol.CylinderLayersCount);
                else
                    sCaseCount = string.Format("{0}", sol.CylinderCount);

                // insert row
                gridSolutions.Rows.Insert(++iIndex);

                // filling columns
                gridSolutions[iIndex, 0] = new SourceGrid.Cells.Cell(string.Format("{0}", iIndex));
                {
                    Graphics2DImage graphics = new Graphics2DImage(new Size(100, 50));
                    CylinderPalletSolutionViewer sv = new CylinderPalletSolutionViewer(sol);
                    sv.Draw(graphics);
                    gridSolutions[iIndex, 1] = new SourceGrid.Cells.Image(graphics.Bitmap);
                }
                gridSolutions[iIndex, 2] = new SourceGrid.Cells.Cell(sCaseCount);
                gridSolutions[iIndex, 3] = new SourceGrid.Cells.Cell(string.Format("{0:F}", sol.VolumeEfficiency));
                gridSolutions[iIndex, 4] = new SourceGrid.Cells.Cell(string.Format("{0:F}", sol.PalletWeight));
                gridSolutions[iIndex, 5] = new SourceGrid.Cells.Cell(string.Format("{0:F}", sol.PalletHeight));
                gridSolutions[iIndex, 6] = new SourceGrid.Cells.Cell(PalletSolutionLimitToString(sol.LimitReached));
                gridSolutions[iIndex, 7] = new SourceGrid.Cells.CheckBox(null, _analysis.HasSolutionSelected(iIndex - 1));

                gridSolutions[iIndex, 0].View = viewNormal;
                gridSolutions[iIndex, 1].View = viewNormal;
                gridSolutions[iIndex, 2].View = viewNormal;
                gridSolutions[iIndex, 3].View = viewNormal;
                gridSolutions[iIndex, 4].View = viewNormal;
                gridSolutions[iIndex, 5].View = viewNormal;
                gridSolutions[iIndex, 6].View = viewNormal;
                gridSolutions[iIndex, 7].View = viewNormalCheck;

                gridSolutions[iIndex, 7].AddController(solCheckboxClickEvent);
            }
            gridSolutions.AutoStretchColumnsToFitWidth = true;
            gridSolutions.AutoSizeCells();
            gridSolutions.Columns.StretchToFit();

            // select first solution
            gridSolutions.Selection.SelectRow(1, true);
            graphCtrlSolution.Invalidate();
        }
Exemplo n.º 3
0
        private void AppendCylinderPalletSolutionElement(ReportData inputData, XmlElement elemPalletAnalysis, XmlDocument xmlDoc)
        {
            if (!inputData.IsCylinderPalletAnalysis) return;

            string ns = xmlDoc.DocumentElement.NamespaceURI;

            SelCylinderPalletSolution selSolution = inputData.SelCylinderPalletSolution;
            CylinderPalletSolution sol = inputData.CylinderPalletSolution;

            // solution
            XmlElement elemSolution = xmlDoc.CreateElement("palletSolution", ns);
            elemPalletAnalysis.AppendChild(elemSolution);
            // title
            XmlElement elemTitle = xmlDoc.CreateElement("title", ns);
            elemTitle.InnerText = sol.Title;
            elemSolution.AppendChild(elemTitle);
            // efficiency
            XmlElement elemEfficiency = xmlDoc.CreateElement("efficiency", ns);
            elemEfficiency.InnerText = string.Format("{0:F}", sol.VolumeEfficiency);
            elemSolution.AppendChild(elemEfficiency);

            AppendElementValue(xmlDoc, elemSolution, "palletWeight", UnitsManager.UnitType.UT_MASS, inputData.ActualPalletWeight);
            AppendElementValue(xmlDoc, elemSolution, "palletHeight", UnitsManager.UnitType.UT_LENGTH, sol.PalletHeight);

            // cylinderCount
            XmlElement elemCaseCount = xmlDoc.CreateElement("cylinderCount", ns);
            elemCaseCount.InnerText = string.Format("{0}", sol.CylinderCount);
            elemSolution.AppendChild(elemCaseCount);
            // layerCount
            XmlElement elemLayerCount = xmlDoc.CreateElement("layerCount", ns);
            elemCaseCount.InnerText = string.Format("{0}", sol.CylinderLayersCount);
            elemSolution.AppendChild(elemCaseCount);
            // interlayer count
            if (sol.Analysis.ConstraintSet.HasInterlayer)
            {
                XmlElement elemInterlayerCount = xmlDoc.CreateElement("interlayerCount", ns);
                elemInterlayerCount.InnerText = string.Format("{0}", sol.InterlayerCount);
                elemSolution.AppendChild(elemInterlayerCount);
            }
            // layer (single)
            {
                // --- layer image
                XmlElement elemLayer = xmlDoc.CreateElement("layer", ns);
                // layerId
                XmlElement xmlLayerId = xmlDoc.CreateElement("layerId", ns);
                xmlLayerId.InnerText = string.Format("{0}", 1);
                elemLayer.AppendChild(xmlLayerId);
                // --- build layer image
                // instantiate graphics
                Graphics3DImage graphics = new Graphics3DImage(new Size(ImageSizeDetail, ImageSizeDetail));
                // set camera position 
                graphics.CameraPosition = Graphics3D.Top;
                // instantiate solution viewer
                CylinderPalletSolutionViewer sv = new CylinderPalletSolutionViewer(sol);
                sv.DrawLayers(graphics, true, 0 /* layer index*/);
                // ---
                // layerImage
                XmlElement elemLayerImage = xmlDoc.CreateElement("layerImage", ns);
                TypeConverter converter = TypeDescriptor.GetConverter(typeof(Bitmap));
                elemLayerImage.InnerText = Convert.ToBase64String((byte[])converter.ConvertTo(graphics.Bitmap, typeof(byte[])));
                XmlAttribute styleAttribute = xmlDoc.CreateAttribute("style");
                styleAttribute.Value = string.Format("width:{0}pt;height:{1}pt", graphics.Bitmap.Width / 2, graphics.Bitmap.Height / 2);
                elemLayerImage.Attributes.Append(styleAttribute);
                elemLayer.AppendChild(elemLayerImage);
                // layerCylinderCount
                XmlElement elemLayerBoxCount = xmlDoc.CreateElement("layerCylinderCount", ns);
                elemLayerBoxCount.InnerText = string.Format("{0}", sol.CylinderPerLayerCount);
                elemLayer.AppendChild(elemLayerBoxCount);
                elemSolution.AppendChild(elemLayer);
                // save image
                SaveImageAs(graphics.Bitmap, string.Format("layerImage{0}.png", 1));
            }
            // --- pallet images
            for (int i = 0; i < 5; ++i)
            {
                // initialize drawing values
                string viewName = string.Empty;
                Vector3D cameraPos = Vector3D.Zero;
                int imageWidth = ImageSizeDetail;
                bool showDimensions = false;
                switch (i)
                {
                    case 0:
                        viewName = "view_palletsolution_front"; cameraPos = Graphics3D.Front; imageWidth = ImageSizeDetail;
                        break;
                    case 1:
                        viewName = "view_palletsolution_left"; cameraPos = Graphics3D.Left; imageWidth = ImageSizeDetail;
                        break;
                    case 2:
                        viewName = "view_palletsolution_right"; cameraPos = Graphics3D.Right; imageWidth = ImageSizeDetail;
                        break;
                    case 3:
                        viewName = "view_palletsolution_back"; cameraPos = Graphics3D.Back; imageWidth = ImageSizeDetail;
                        break;
                    case 4:
                        viewName = "view_palletsolution_iso"; cameraPos = Graphics3D.Corner_0; imageWidth = ImageSizeWide; showDimensions = true;
                        break;
                    default:
                        break;
                }
                // instantiate graphics
                Graphics3DImage graphics = new Graphics3DImage(new Size(imageWidth, imageWidth));
                // set camera position 
                graphics.CameraPosition = cameraPos;
                // instantiate solution viewer
                CylinderPalletSolutionViewer sv = new CylinderPalletSolutionViewer(sol);
                sv.ShowDimensions = showDimensions;
                sv.Draw(graphics);
                // ---
                XmlElement elemImage = xmlDoc.CreateElement(viewName, ns);
                TypeConverter converter = TypeDescriptor.GetConverter(typeof(Bitmap));
                elemImage.InnerText = Convert.ToBase64String((byte[])converter.ConvertTo(graphics.Bitmap, typeof(byte[])));
                XmlAttribute styleAttribute = xmlDoc.CreateAttribute("style");
                styleAttribute.Value = string.Format("width:{0}pt;height:{1}pt", graphics.Bitmap.Width / 3, graphics.Bitmap.Height / 3);
                elemImage.Attributes.Append(styleAttribute);
                elemSolution.AppendChild(elemImage);
                // Save image ?
                SaveImageAs(graphics.Bitmap, viewName + ".png");
            }
        }
 public void Draw(Graphics3DControl ctrl, Graphics3D graphics)
 {
     // instantiate solution viewer
     CylinderPalletSolutionViewer sv = new CylinderPalletSolutionViewer(GetCurrentSolution());
     sv.Draw(graphics);
 }