public void Draw(Graphics3DControl ctrl, Graphics3D graphics)
 {
     // instantiate solution viewer
     BoxCaseSolutionViewer sv = new BoxCaseSolutionViewer(GetCurrentSolution());
     sv.Draw(graphics);
 }
Exemplo n.º 2
0
 private void AppendBoxCaseSolutionElement(BoxCaseSolution solution, XmlElement elemBoxCaseAnalysis, XmlDocument xmlDoc)
 {
     BoxCaseAnalysis analysis = solution.Analysis;
     string ns = xmlDoc.DocumentElement.NamespaceURI;
     // solution
     XmlElement elemSolution = xmlDoc.CreateElement("boxCaseSolution", ns);
     elemBoxCaseAnalysis.AppendChild(elemSolution);
     // title
     XmlElement elemTitle = xmlDoc.CreateElement("title", ns);
     elemTitle.InnerText = solution.Title;
     elemSolution.AppendChild(elemTitle);
     // boxPerLayerCount
     XmlElement elemBoxPerLayerCount = xmlDoc.CreateElement("boxPerLayerCount", ns);
     elemBoxPerLayerCount.InnerText = solution.BoxPerLayerCount.ToString();
     elemSolution.AppendChild(elemBoxPerLayerCount);
     // boxPerCaseCount
     XmlElement elemBoxPerCaseCount = xmlDoc.CreateElement("boxPerCaseCount", ns);
     elemBoxPerCaseCount.InnerText = solution.BoxPerCaseCount.ToString();
     elemSolution.AppendChild(elemBoxPerCaseCount);
     // BoxLayersCount
     XmlElement elemBoxLayersCount = xmlDoc.CreateElement("boxLayersCount", ns);
     elemBoxLayersCount.InnerText = solution.BoxLayersCount.ToString();
     elemSolution.AppendChild(elemBoxLayersCount);
     // criterions
     // load weight
     AppendElementValue(xmlDoc, elemSolution, "LoadWeight", UnitsManager.UnitType.UT_MASS, solution.BoxPerCaseCount * analysis.BProperties.Weight);
     // case weight
     AppendElementValue(xmlDoc, elemSolution, "CaseWeight", UnitsManager.UnitType.UT_MASS, solution.CaseWeight);
     // EfficiencyWeight
     XmlElement elemEfficiencyWeight = xmlDoc.CreateElement("EfficiencyWeight", ns);
     if (solution.CaseWeight > 0)
         elemEfficiencyWeight.InnerText = string.Format("{0:F}", solution.EfficiencyWeight);
     else
         elemEfficiencyWeight.InnerText = string.Empty;
     elemSolution.AppendChild(elemEfficiencyWeight);
     // EfficiencyVolume
     XmlElement elemEfficiencyVolume = xmlDoc.CreateElement("EfficiencyVolume", ns);
     elemEfficiencyVolume.InnerText = string.Format("{0:F}", solution.EfficiencyVolume);
     elemSolution.AppendChild(elemEfficiencyVolume);
     // LimitReached
     string limitReached = string.Empty;
     switch (solution.LimitReached)
     {
         case BoxCaseSolution.Limit.LIMIT_MAXHEIGHTREACHED: limitReached="Maximum height"; break;
         case BoxCaseSolution.Limit.LIMIT_MAXNUMBERREACHED: limitReached="Maximum number"; break;
         case BoxCaseSolution.Limit.LIMIT_MAXWEIGHTREACHED: limitReached="Maximum weight"; break;
         default: break;
     }
     XmlElement elemLimitReached = xmlDoc.CreateElement("LimitReached", ns);
     elemLimitReached.InnerText = limitReached;
     elemSolution.AppendChild(elemLimitReached);
     // --- case 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_caseSolution_front"; cameraPos = Graphics3D.Front; imageWidth = ImageSizeDetail; break;
             case 1: viewName = "view_caseSolution_left"; cameraPos = Graphics3D.Left; imageWidth = ImageSizeDetail; break;
             case 2: viewName = "view_caseSolution_right"; cameraPos = Graphics3D.Right; imageWidth = ImageSizeDetail; break;
             case 3: viewName = "view_caseSolution_back"; cameraPos = Graphics3D.Back; imageWidth = ImageSizeDetail; break;
             case 4:  viewName = "view_caseSolution_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
         BoxCaseSolutionViewer sv = new BoxCaseSolutionViewer(solution);
         sv.ShowDimensions = showDimensions;
         sv.Draw(graphics);
         graphics.Flush();
         // ---
         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");
     }
 }
        private void FillGrid()
        {
            // fill grid solutions
            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 = 7;
            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_BOXCOUNT);
            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(Resources.ID_CASEWEIGHT);
            columnHeader.AutomaticSortEnabled = false;
            columnHeader.View = viewColumnHeader;
            gridSolutions[0, 4] = columnHeader;

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

            columnHeader = new SourceGrid.Cells.ColumnHeader(Resources.ID_SELECTED);
            columnHeader.AutomaticSortEnabled = false;
            columnHeader.View = viewColumnHeader;
            gridSolutions[0, 6] = 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 (BoxCaseSolution sol in _analysis.Solutions)
            {
                // build case count string
                string sBoxCount = string.Empty;
                sBoxCount = string.Format("{0}\n({1} * {2})", sol.BoxPerCaseCount, sol.BoxPerLayerCount, sol.Count);
                // 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(50, 50));
                    BoxCaseSolutionViewer sv = new BoxCaseSolutionViewer(sol);
                    sv.Draw(graphics);
                    gridSolutions[iIndex, 1] = new SourceGrid.Cells.Image(graphics.Bitmap);
                }
                gridSolutions[iIndex, 2] = new SourceGrid.Cells.Cell(sBoxCount);
                gridSolutions[iIndex, 3] = new SourceGrid.Cells.Cell(string.Format("{0:F}", sol.VolumeEfficiencyBoxes));
                gridSolutions[iIndex, 4] = new SourceGrid.Cells.Cell(string.Format("{0:F}", sol.CaseWeight));
                gridSolutions[iIndex, 5] = new SourceGrid.Cells.Cell(BoxCaseSolutionLimitToString(sol.LimitReached));
                gridSolutions[iIndex, 6] = new SourceGrid.Cells.CheckBox(null, _analysis.HasSolutionSelected(iIndex - 1));

                gridSolutions[iIndex, 6].AddController(solCheckboxClickEvent);
            }

            gridSolutions.AutoStretchColumnsToFitWidth = true;
            gridSolutions.AutoSizeCells();
            gridSolutions.Columns.StretchToFit();

            // select first solution
            gridSolutions.Selection.SelectRow(1, true);
            // redraw
            graphCtrlSolution.Invalidate();
        }
 public void Draw(Graphics3DControl ctrl, Graphics3D graphics)
 {
     if (null == CurrentSolution) return;
     BoxCaseSolutionViewer sv = new BoxCaseSolutionViewer(CurrentSolution);
     sv.Draw(graphics);
 }