Esempio n. 1
0
        private void Preview_selected_material()
        {
            // get the select material object.
            ListView.SelectedListViewItemCollection selItems = matListView.SelectedItems;
            if (selItems.Count == 0)
            {
                return;
            }
            ListViewItem item   = selItems[0];
            long         iMatID = (long)item.Tag;
            MatEx        mat    = m_matList.GetMatByID(iMatID);

            if (mat != null)
            {
                GeomItemListEx matGeomItems = mat.GetGeomItemList();

                // fit the geom to window.
                DrawHelper.FitWindow(matGeomItems.GetRectBox(), matViewPort, matPreviewWnd);

                // clear screen and set the background color.
                matViewPort.BindRendContext();
                matViewPort.ClearScreen();
                matViewPort.SetBackgroundColor(Color.Black);

                // set the draw params.
                matViewPort.SetDrawColor(Color.White);
                matViewPort.SetLineWidth(1);

                matViewPort.DrawGeomItemList(matGeomItems);

                // swap buffer to display the geometry.
                matViewPort.SwapBuffers();
            }
        }
Esempio n. 2
0
        // draw the material.
        static public void DrawMat(MatEx mat, GlViewPortEx viewPort)
        {
            viewPort.SetDrawColor(Color.White);
            viewPort.SetLineWidth(1);

            if (mat.GetMatType() == MAT_TYPE_EX.MAT_EX_RECT)
            {
                RectMatEx   rectMat = (RectMatEx)mat;
                Rect2DEx    rect2D  = rectMat.GetBoundaryRect();
                Polygon2DEx poly    = new Polygon2DEx();
                poly.AddPoint(new Point2DEx(rect2D.GetXMin(), rect2D.GetYMin()));
                poly.AddPoint(new Point2DEx(rect2D.GetXMax(), rect2D.GetYMin()));
                poly.AddPoint(new Point2DEx(rect2D.GetXMax(), rect2D.GetYMax()));
                poly.AddPoint(new Point2DEx(rect2D.GetXMin(), rect2D.GetYMax()));
                viewPort.DrawPolygon(poly);
            }
            else if (mat.GetMatType() == MAT_TYPE_EX.MAT_EX_POLY)
            {
                PolyMatEx   polyMat = (PolyMatEx)mat;
                Polygon2DEx poly    = polyMat.GetMatPolygon();
                viewPort.DrawPolygon(poly);

                // draw the useless holes.
                Poly2DListEx uselessHoles = polyMat.GetUselessHoleList();
                for (int i = 0; i < uselessHoles.Size(); i++)
                {
                    viewPort.DrawPolygon(uselessHoles.GetPolygonByIndex(i));
                }
            }
        }
Esempio n. 3
0
        // add material to list control.
        private void AddMat(MatEx mat)
        {
            // the boundary rect of the material.
            Rect2DEx boundaryRect = null;

            if (mat.GetMatType() == MAT_TYPE_EX.MAT_EX_RECT)
            {
                RectMatEx rectMat = (RectMatEx)mat;
                boundaryRect = rectMat.GetBoundaryRect();
            }
            else if (mat.GetMatType() == MAT_TYPE_EX.MAT_EX_POLY)
            {
                PolyMatEx   polyMat = (PolyMatEx)mat;
                Polygon2DEx polygon = polyMat.GetMatPolygon();
                boundaryRect = polygon.GetBoundaryRect();
            }

            /************************************************************************/
            // add a row to list control.

            // insert a row.
            int          iCount = matListView.Items.Count + 1;
            ListViewItem item   = matListView.Items.Add(iCount.ToString());

            // name column.
            item.SubItems.Add(mat.GetName());

            // material type column.
            if (mat.GetMatType() == MAT_TYPE_EX.MAT_EX_RECT)
            {
                item.SubItems.Add("矩形材料");
            }
            else if (mat.GetMatType() == MAT_TYPE_EX.MAT_EX_POLY)
            {
                item.SubItems.Add("不规则材料");
            }

            // the material height.
            item.SubItems.Add(boundaryRect.GetHeight().ToString("0.000"));

            // the material width.
            item.SubItems.Add(boundaryRect.GetWidth().ToString("0.000"));

            // the material count.
            item.SubItems.Add(mat.GetCount().ToString());

            // hold the ID.
            item.Tag = mat.GetID();
            /************************************************************************/

            // select the last row.
            matListView.SelectedItems.Clear();
            matListView.Items[matListView.Items.Count - 1].Selected = true;
            matListView.Items[matListView.Items.Count - 1].Focused  = true;
            matListView.Items[matListView.Items.Count - 1].EnsureVisible();
        }
Esempio n. 4
0
        private void editMatBtn_Click(object sender, EventArgs e)
        {
            ListView.SelectedListViewItemCollection selItems = matListView.SelectedItems;
            if (selItems.Count != 1)
            {
                MessageBox.Show("Please select one row to edit.", "NestProfessor DEMO");
                return;
            }
            else
            {
                ListViewItem item   = selItems[0];
                long         iMatID = (long)item.Tag;
                MatEx        mat    = m_matList.GetMatByID(iMatID);
                if (mat != null)
                {
                    if (mat.GetMatType() == MAT_TYPE_EX.MAT_EX_POLY)
                    {
                        MessageBox.Show("For irregular material, its width and height can be edited here.", "NestProfessor DEMO");
                    }

                    MaterialForm matForm = new MaterialForm(mat);
                    if (matForm.ShowDialog() == DialogResult.OK)
                    {
                        /************************************************************************/
                        // update the list control.

                        // name column.
                        item.SubItems[1].Text = mat.GetName();

                        if (mat.GetMatType() == MAT_TYPE_EX.MAT_EX_RECT)
                        {
                            RectMatEx rectMat = (RectMatEx)(mat);
                            Rect2DEx  rect    = rectMat.GetBoundaryRect();

                            // the material width.
                            item.SubItems[3].Text = rect.GetWidth().ToString("0.000");

                            // the material height.
                            item.SubItems[4].Text = rect.GetHeight().ToString("0.000");
                        }

                        // count.
                        item.SubItems[5].Text = mat.GetCount().ToString();
                        /************************************************************************/

                        matPreviewWnd.Invalidate();
                    }
                }
            }
        }
Esempio n. 5
0
        private void loadMatBtn_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();

            openFileDialog.Filter           = "DXF Files|*.dxf|DWG Files|*.dwg";
            openFileDialog.RestoreDirectory = true;
            openFileDialog.FilterIndex      = 1;
            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                String strFilePath = openFileDialog.FileName;
                MatEx  mat         = NestHelper.LoadMatFromDxfdwg(strFilePath, m_nestParam);
                if (mat != null)
                {
                    m_matList.AddMat(mat);

                    // add material to list control.
                    AddMat(mat);
                }
            }
        }
Esempio n. 6
0
        static private void SaveMats(XmlDocument xmlDoc, XmlNode matListNode, MatListEx mats, List <KeyValuePair <long, string> > matDxfPath)
        {
            for (int i = 0; i < mats.Size(); i++)
            {
                MatEx mat = mats.GetMatByIndex(i);

                XmlElement materialNode = xmlDoc.CreateElement("Material");
                matListNode.AppendChild(materialNode);

                bool bFromDxf = false;
                for (int j = 0; i < matDxfPath.Count; j++)
                {
                    if (matDxfPath[j].Key == mat.GetID())
                    {
                        XmlElement matPathNode = xmlDoc.CreateElement("MatPath");
                        matPathNode.InnerText = matDxfPath[j].Value;
                        materialNode.AppendChild(matPathNode);

                        // Count
                        {
                            XmlElement countNode = xmlDoc.CreateElement("Count");
                            countNode.InnerText = mat.GetCount().ToString();
                            materialNode.AppendChild(countNode);
                        }

                        bFromDxf = true;
                        break;
                    }
                }

                // material is not from dxf.
                if (!bFromDxf)
                {
                    RectMatEx rectMat = (RectMatEx)(mat);

                    // name
                    {
                        XmlElement nameNode = xmlDoc.CreateElement("Name");
                        nameNode.InnerText = mat.GetName();
                        materialNode.AppendChild(nameNode);
                    }

                    // Width
                    {
                        XmlElement widthNode = xmlDoc.CreateElement("Width");
                        widthNode.InnerText = rectMat.GetBoundaryRect().GetWidth().ToString("0.000000");
                        materialNode.AppendChild(widthNode);
                    }

                    // Height
                    {
                        XmlElement heightNode = xmlDoc.CreateElement("Height");
                        heightNode.InnerText = rectMat.GetBoundaryRect().GetHeight().ToString("0.000000");
                        materialNode.AppendChild(heightNode);
                    }

                    // Count
                    {
                        XmlElement countNode = xmlDoc.CreateElement("Count");
                        countNode.InnerText = rectMat.GetCount().ToString();
                        materialNode.AppendChild(countNode);
                    }
                }
            }
        }
Esempio n. 7
0
        static private MatListEx LoadMats_V1(string strTaskFilePath, XmlNode matListNode, List <KeyValuePair <long, string> > matDxfPath, NestParamEx nestParam)
        {
            MatListEx mats = new MatListEx();

            for (int i = 0; i < matListNode.ChildNodes.Count; i++)
            {
                XmlNode matNode = matListNode.ChildNodes.Item(i);

                // whether load material from file.
                XmlNode pathNode = matNode.SelectSingleNode("MatPath");
                if (pathNode != null)
                {
                    string strMaterialFileFullPath = pathNode.InnerText;
                    if (!File.Exists(strMaterialFileFullPath))
                    {
                        // the new file path.
                        string strTaskFileFolder          = strTaskFilePath.Substring(0, strTaskFilePath.LastIndexOf("\\"));
                        string strMaterialFileName        = strMaterialFileFullPath.Substring(strMaterialFileFullPath.LastIndexOf("\\") + 1, strMaterialFileFullPath.Length - strMaterialFileFullPath.LastIndexOf("\\") - 1);
                        string strNewMaterialFileFullPath = strTaskFileFolder + "\\" + strMaterialFileName;

                        // try again.
                        if (!File.Exists(strNewMaterialFileFullPath))
                        {
                            string strMessage = "Cannot find material file: ";
                            MessageBox.Show(strMessage + strMaterialFileFullPath, "NestProfessor DEMO");
                            continue;
                        }
                        else
                        {
                            strMaterialFileFullPath = strNewMaterialFileFullPath;
                        }
                    }

                    MatEx mat = NestHelper.LoadMatFromDxfdwg(strMaterialFileFullPath, nestParam);
                    mats.AddMat(mat);
                    matDxfPath.Add(new KeyValuePair <long, string>(mat.GetID(), strMaterialFileFullPath));

                    // count.
                    mat.SetCount(Convert.ToInt32(matNode.SelectSingleNode("Count").InnerText));
                }
                else
                {
                    RectMatEx rectMat = new RectMatEx();
                    mats.AddMat(rectMat);

                    // name
                    rectMat.SetName(matNode.SelectSingleNode("Name").InnerText);

                    // width.
                    double dWidth = Convert.ToDouble(matNode.SelectSingleNode("Width").InnerText);

                    // height.
                    double dHeight = Convert.ToDouble(matNode.SelectSingleNode("Height").InnerText);

                    // the material rect.
                    Rect2DEx matRect = new Rect2DEx(0, dWidth, 0, dHeight);
                    rectMat.SetMatRect(matRect);

                    // count.
                    rectMat.SetCount(Convert.ToInt32(matNode.SelectSingleNode("Count").InnerText));
                }
            }

            return(mats);
        }
Esempio n. 8
0
        // display the nesting result.
        private void DisplayNestResult()
        {
            if (m_sheetList == null)
            {
                return;
            }

            m_bDisableEvent = true;

            // display detail info of each sheet.
            shtListView.Items.Clear();
            for (int i = 0; i < m_sheetList.Size(); i++)
            {
                SheetEx sheet = m_sheetList.GetSheetByIndex(i);

                // insert a row.
                int          iCount = shtListView.Items.Count + 1;
                ListViewItem item   = shtListView.Items.Add(iCount.ToString());

                // "name" column.
                item.SubItems.Add(sheet.GetName());

                // "sheet count" column.
                item.SubItems.Add(sheet.GetCount().ToString());

                // "material name" column.
                item.SubItems.Add(sheet.GetMat().GetName());

                // hold the sheet ID.
                item.Tag = sheet.GetID();
            }

            /************************************************************************/
            // part group.

            NestPartListEx nestPartList = m_nestTask.GetNestPartList();

            // submitted part count.
            int iSubmitPartCount = 0;

            for (int i = 0; i < nestPartList.Size(); i++)
            {
                iSubmitPartCount += nestPartList.GetNestPartByIndex(i).GetNestCount();
            }
            subPartTextBox.Text = iSubmitPartCount.ToString();

            // the count of the nested parts.
            int iNestedPartCount = m_sheetList.GetPartInstTotalCount();

            nestPartTextBox.Text = iNestedPartCount.ToString();

            // display detailed info of each part.
            partListView.Items.Clear();
            for (int i = 0; i < nestPartList.Size(); i++)
            {
                NestPartEx nestPart = nestPartList.GetNestPartByIndex(i);
                PartEx     part     = nestPart.GetPart();

                // insert a row.
                int          iCount = partListView.Items.Count + 1;
                ListViewItem item   = partListView.Items.Add(iCount.ToString());

                // "name" column.
                item.SubItems.Add(part.GetName());

                // "submitted count" column.
                item.SubItems.Add(nestPart.GetNestCount().ToString());

                // "nested count" column.
                int iNestedCount = m_sheetList.GetPartInstCount(part.GetID());
                item.SubItems.Add(iNestedCount.ToString());
            }
            /************************************************************************/

            /************************************************************************/
            // material group.

            MatListEx matList = m_nestTask.GetMatList();

            // the utilization of material.
            double dUtilization = NestHelper.CalcMatUtil(m_sheetList, m_nestTask.GetNestParam());

            utilTextBox.Text = dUtilization.ToString("0.00");

            matListView.Items.Clear();
            for (int i = 0; i < matList.Size(); i++)
            {
                MatEx mat = matList.GetMatByIndex(i);

                // insert a row.
                int          iCount = matListView.Items.Count + 1;
                ListViewItem item   = matListView.Items.Add(iCount.ToString());

                // "name" column.
                item.SubItems.Add(mat.GetName());

                // "submitted count" column.
                item.SubItems.Add(mat.GetCount().ToString());

                // "consumed count" column.
                int iConsumedCount = m_sheetList.GetSheetCount(mat.GetID());
                item.SubItems.Add(iConsumedCount.ToString());
            }
            /************************************************************************/

            // preview the first sheet.
            if (shtListView.Items.Count > 0)
            {
                shtListView.Items[0].Selected = true;

                // get the select sheet.
                ListView.SelectedListViewItemCollection selItems = shtListView.SelectedItems;
                ListViewItem item          = selItems[0];
                long         iSheetID      = (long)item.Tag;
                SheetEx      selectedSheet = m_sheetList.GetSheetByID(iSheetID);

                // fit the window.
                DrawHelper.FitWindow(selectedSheet.GetMat().GetBoundaryRect(), m_shtViewPort, shtPreViewWnd);

                PreviewSheet();
            }

            m_bDisableEvent = false;
        }
Esempio n. 9
0
        // load boundary polygon from dxf/dwg file.
        static public MatEx LoadMatFromDxfdwg(String strFilePath, NestParamEx nestParam)
        {
            MatEx mat = null;

            /************************************************************************/
            // load all geometry items from the dxf/dwg file.

            // the file name.
            int    iDotIndex   = strFilePath.LastIndexOf('.');
            int    iSlashIndex = strFilePath.LastIndexOf('\\');
            String strFileName = strFilePath.Substring(iSlashIndex + 1, iDotIndex - iSlashIndex - 1);

            // whether the file is dxf file or dwg file.
            bool   bDwg   = true;
            String strExt = strFilePath.Substring(iDotIndex, strFilePath.Length - iDotIndex);

            strExt = strExt.ToLower();
            if (strExt == ".dxf")
            {
                bDwg = false;
            }
            else if (strExt == ".dwg")
            {
                bDwg = true;
            }
            else
            {
                return(mat);
            }

            // extract geometry items from dxf/dwg file.
            ImpDataEx impData;

            if (!bDwg)
            {
                impData = NestFacadeEx.ExtractGeomItems(strFilePath);
            }
            else
            {
                // the temp folder for dxf.
                String strDxfPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
                strDxfPath += "\\";
                strDxfPath += new Random().Next(1, 100000).ToString();
                strDxfPath += ".dxf";

                // save dxf file in tmp path.
                NestFacadeEx.Dwg2Dxf(strFilePath, strDxfPath);

                // extract geometry items from dxf file.
                impData = NestFacadeEx.ExtractGeomItems(strDxfPath);

                // delete the temp file.
                File.Delete(strDxfPath);
            }
            /************************************************************************/

            /************************************************************************/
            // get the polygons from the dxf/dwg file.

            // build the polygons of all the geometry items.
            GeomItemListEx geomItemList = impData.GetAllGeomItem();
            Poly2DListEx   polyList     = NestFacadeEx.BuildPolyListFromLineArc(geomItemList, nestParam.GetConTol());

            // if no closed polygon found, return.
            if (polyList.Size() == 0)
            {
                MessageBox.Show("No closed boundary found.", "NestProfessor DEMO");
                return(mat);
            }

            // the outer boundary polygon.
            int         iMaxIndex = polyList.GetMaxAreaPoly();
            Polygon2DEx outerPoly = polyList.GetPolygonByIndex(iMaxIndex);

            // the hole polygons.
            polyList.DelPolygonByIndex(iMaxIndex);
            Poly2DListEx holePolyList = polyList;
            /************************************************************************/

            /************************************************************************/
            // build the material object.

            // whether the boundary polygon is a rectangle.
            bool bRectMat = true;

            if (outerPoly.GetPtCount() != 4)
            {
                bRectMat = false;
            }
            else if (holePolyList.Size() > 0)
            {
                bRectMat = false;
            }
            else
            {
                // line items in the polygon.
                ArrayList  lineItems = outerPoly.GetLineList();
                LineItemEx lineItem1 = (LineItemEx)lineItems[0];
                LineItemEx lineItem2 = (LineItemEx)lineItems[1];
                LineItemEx lineItem3 = (LineItemEx)lineItems[2];
                LineItemEx lineItem4 = (LineItemEx)lineItems[3];

                if (Math.Abs(lineItem1.GetLength() - lineItem3.GetLength()) > 0.0001)
                {
                    bRectMat = false;
                }
                if (Math.Abs(lineItem2.GetLength() - lineItem4.GetLength()) > 0.0001)
                {
                    bRectMat = false;
                }

                Vector2DEx vect1 = lineItem1.GetBaseVector();
                Vector2DEx vect2 = lineItem2.GetBaseVector();
                if (!vect1.OrthogonalTo(vect2))
                {
                    bRectMat = false;
                }
            }

            // build the material object.
            if (bRectMat)
            {
                mat = new RectMatEx(strFileName, outerPoly.GetBoundaryRect(), 1);
            }
            else
            {
                PolyMatEx polyMat = new PolyMatEx(strFileName, outerPoly, 1);
                polyMat.SetUselessHoleList(holePolyList);
                mat = polyMat;
            }
            /************************************************************************/

            return(mat);
        }
Esempio n. 10
0
        public MaterialForm(MatEx mat)
        {
            m_mat = mat;

            InitializeComponent();
        }