Esempio n. 1
0
        private void AdvParamForm_Load(object sender, EventArgs e)
        {
            tolTextBox.Text  = m_nestParam.GetConTol().ToString("0.000");
            rotTextBox.Text  = m_nestParam.GetPartRotStep().ToString("0.000");
            evalTextBox.Text = m_nestParam.GetEvalFactor().ToString();
            timeTextBox.Text = m_iNestingTime.ToString();

            if (m_nestParam.IsPartInPart())
            {
                partInPartCheckBox.Checked = true;
            }
            else
            {
                partInPartCheckBox.Checked = false;
            }

            if (m_nestParam.EnableOptimization())
            {
                optimizationCheckBox.Checked = true;
            }
            else
            {
                optimizationCheckBox.Checked = false;
            }

            GetConfigHigh();
        }
Esempio n. 2
0
        // calc the utilization of the material.
        static public double CalcMatUtil(SheetListEx sheetList, NestParamEx nestParam)
        {
            double dUtilization = .0;

            // calculate the utilization of material.
            double dMatArea = .0, dNestedArea = .0;

            for (int i = 0; i < sheetList.Size(); i++)
            {
                SheetEx sheet       = sheetList.GetSheetByIndex(i);
                int     iSheetCount = sheet.GetCount();
                dMatArea += sheet.GetMat().GetArea() * iSheetCount;

                // go through each part placement object in the sheet.
                PartPmtListEx partPmtList = sheet.GetPartPmtList();
                for (int j = 0; j < partPmtList.Size(); j++)
                {
                    PartPmtEx partPmt = partPmtList.GetPartPmtByIndex(j);
                    PartEx    part    = partPmt.GetPart();

                    // the area of the part.
                    double dPartArea = NestFacadeEx.GetPartArea(part, nestParam.GetConTol());

                    // part count in the part placement object.
                    int iPartCount = 1;
                    if (partPmt.IsGrid())
                    {
                        iPartCount = partPmt.GetRowCount() * partPmt.GetColCount();
                    }
                    dNestedArea += iSheetCount * iPartCount * dPartArea;
                }
            }

            // figure out the utilization.
            if (dMatArea == 0 || dNestedArea == 0)
            {
                dUtilization = .0;
            }
            else
            {
                dUtilization = (dNestedArea / dMatArea) * 100;
            }

            return(dUtilization);
        }
Esempio n. 3
0
        static private void SaveNestParam(XmlDocument xmlDoc, XmlNode paramNode, NestParamEx nestParam, int iNestingTime)
        {
            // MatLeftMargin.
            {
                XmlElement node = xmlDoc.CreateElement("MatLeftMargin");
                node.InnerText = nestParam.GetMatLeftMargin().ToString("0.0000000");
                paramNode.AppendChild(node);
            }

            // MatRightMargin.
            {
                XmlElement node = xmlDoc.CreateElement("MatRightMargin");
                node.InnerText = nestParam.GetMatRightMargin().ToString("0.0000000");
                paramNode.AppendChild(node);
            }

            // MatTopMargin.
            {
                XmlElement node = xmlDoc.CreateElement("MatTopMargin");
                node.InnerText = nestParam.GetMatTopMargin().ToString("0.0000000");
                paramNode.AppendChild(node);
            }

            // MatBottomMargin.
            {
                XmlElement node = xmlDoc.CreateElement("MatBottomMargin");
                node.InnerText = nestParam.GetMatBottomMargin().ToString("0.0000000");
                paramNode.AppendChild(node);
            }

            // MatMargin.
            {
                XmlElement node = xmlDoc.CreateElement("MatMargin");
                node.InnerText = nestParam.GetMatMargin().ToString("0.0000000");
                paramNode.AppendChild(node);
            }

            // PartDis.
            {
                XmlElement node = xmlDoc.CreateElement("PartDis");
                node.InnerText = nestParam.GetPartDis().ToString("0.0000000");
                paramNode.AppendChild(node);
            }

            // ConTol.
            {
                XmlElement node = xmlDoc.CreateElement("ConTol");
                node.InnerText = nestParam.GetConTol().ToString("0.0000000");
                paramNode.AppendChild(node);
            }

            // PartRotStep.
            {
                XmlElement node = xmlDoc.CreateElement("PartRotStep");
                node.InnerText = nestParam.GetPartRotStep().ToString("0.0000000");
                paramNode.AppendChild(node);
            }

            // StartCorner.
            {
                XmlElement node = xmlDoc.CreateElement("StartCorner");
                node.InnerText = ((int)nestParam.GetStartCorner()).ToString();
                paramNode.AppendChild(node);
            }

            // NestDir.
            {
                XmlElement node = xmlDoc.CreateElement("NestDir");
                node.InnerText = ((int)nestParam.GetNestDir()).ToString();
                paramNode.AppendChild(node);
            }

            // PartInPart.
            {
                XmlElement node = xmlDoc.CreateElement("PartInPart");
                if (nestParam.IsPartInPart())
                {
                    node.InnerText = "1";
                }
                else
                {
                    node.InnerText = "0";
                }
                paramNode.AppendChild(node);
            }

            // EvalFactor.
            {
                XmlElement node = xmlDoc.CreateElement("EvalFactor");
                node.InnerText = nestParam.GetEvalFactor().ToString();
                paramNode.AppendChild(node);
            }

            // nest time.
            {
                XmlElement node = xmlDoc.CreateElement("NestingTime");
                node.InnerText = iNestingTime.ToString();
                paramNode.AppendChild(node);
            }
        }
Esempio n. 4
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. 5
0
        private void addPartBtn_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();

            openFileDialog.Filter           = "DXF Files|*.dxf|DWG Files|*.dwg";
            openFileDialog.RestoreDirectory = true;
            openFileDialog.FilterIndex      = 1;
            openFileDialog.Multiselect      = true;
            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                // disable select-change event.
                m_bDisableSelChgEvent = true;
                lblLoadPart.Text      = "零件加载中……";

                Task tk = new Task(new Action(() =>
                {
                    for (int i = 0; i < openFileDialog.FileNames.Length; i++)
                    {
                        String strFilePath = openFileDialog.FileNames[i];

                        //获取文件所在的文件夹名,用做订单号
                        var view = strFilePath.Split('\\');
                        var dir  = view[view.Length - 2];

                        // 从Dxf文件中加载零件对象
                        PartEx part = NestHelper.LoadPartFromDxfdwg(strFilePath, m_impDataList);

                        // 判断零件是否是闭合的
                        bool bClosedBoundary = NestFacadeEx.HasClosedBoundary(part, m_nestParam.GetConTol());
                        if (!bClosedBoundary)
                        {
                            MessageBox.Show("零件没有闭合!!!");
                            continue;
                        }

                        // build NestPartEx object.
                        NestPartEx nestPart = new NestPartEx(part, NestPriorityEx.MaxPriority(), 1, PART_ROT_STYLE_EX.PART_ROT_PID2_INCREMENT, false);
                        m_nestPartList.AddNestPart(nestPart);
                        m_partDxfPath.Add(new KeyValuePair <long, string>(nestPart.GetID(), strFilePath));
                        m_partColorConfig[nestPart.GetPart().GetID()] = ColorTranslator.ToOle(NestHelper.PickNextColor_4_part(ref m_iCurrentColorIndex));

                        // add part to list control.
                        this.Invoke(new Action(() =>
                        {
                            AddPart_to_listCtrl(nestPart, dir);
                        }));
                    }
                }));
                tk.Start();
                tk.ContinueWith(t => this.Invoke(new Action(() => { lblLoadPart.Text = string.Empty; })));

                // disable select-change event.
                m_bDisableSelChgEvent = false;

                // select the last row.
                if (partListView.Items.Count > 0)
                {
                    partListView.SelectedItems.Clear();
                    partListView.Items[partListView.Items.Count - 1].Selected = true;
                    partListView.Items[partListView.Items.Count - 1].Focused  = true;
                    partListView.Items[partListView.Items.Count - 1].EnsureVisible();
                }
            }
        }