Example #1
0
        private void saveShtBtn_Click(object sender, EventArgs e)
        {
            ListView.SelectedListViewItemCollection selItems = shtListView.SelectedItems;
            if (selItems.Count != 1)
            {
                MessageBox.Show("Please select one sheet to save.", "NestProfessor DEMO");
                return;
            }
            else
            {
                // get the selected sheet object.
                ListViewItem item     = selItems[0];
                long         iSheetID = (long)item.Tag;
                SheetEx      sheet    = m_sheetList.GetSheetByID(iSheetID);

                // save sheet as dxf file.
                SaveFileDialog saveFileDialog = new SaveFileDialog();
                saveFileDialog.Filter           = "DXF Files|*.dxf";
                saveFileDialog.RestoreDirectory = true;
                if (saveFileDialog.ShowDialog() == DialogResult.OK)
                {
                    String         strFilePath  = saveFileDialog.FileName;
                    GeomItemListEx geomItemList = sheet.GetGeomItems(true);
                    //NestFacadeEx.GeomItems2DxfDwg(geomItemList, strFilePath, false); // save line/arc to dxf/dwg instead of saving polylines.
                    NestFacadeEx.Sheet2DxfDwg(sheet, m_impDataList, strFilePath, false);
                }
            }
        }
Example #2
0
        private void RemnantMatInfoForm_Load(object sender, EventArgs e)
        {
            // build the remnant material from the sheet.
            double dMergeDis = 10;

            m_polyMat = NestFacadeEx.BuildRemnantMat(m_sheet, m_dConnectTol, dMergeDis);

            // init the tree.
            UpdateTree();

            /************************************************************************/
            // init the view port.

            m_matViewPort.InitEnv(matViewWnd.Handle, 0.00001, 10000);

            // all polygons in material.
            Poly2DListEx poly2DList = new Poly2DListEx();

            poly2DList.AddPoly(m_polyMat.GetMatPolygon());
            poly2DList.AddPolyList(m_polyMat.GetUselessHoleList());

            // set the drawing area.
            Int32     iWidth       = matViewWnd.Right - matViewWnd.Left;
            Int32     iHeight      = matViewWnd.Bottom - matViewWnd.Top;
            Rect2DEx  geomRect     = poly2DList.GetRectBox();
            Point2DEx leftBottomPt = new Point2DEx();
            double    dXDirRange   = m_matViewPort.GetFitAllParam(iWidth, iHeight, geomRect, 1.2, leftBottomPt);

            m_matViewPort.SetDrawingArea(1.1 * dXDirRange, iWidth, iHeight, leftBottomPt);
            /************************************************************************/

            mergeDisTextBox.Text = dMergeDis.ToString("0.000");
        }
Example #3
0
        private void DemoForm_Load(object sender, EventArgs e)
        {
            /************************************************************************/
            // init the license.

            // init the license which is bound to local computer.
            ReturnInfoEx retInfo = NestFacadeEx.InitLicense("d:\\nest.NPLic");

            // init license if the license is bound to SafeNet hardware key.
            //ReturnInfoEx retInfo = NestFacadeEx.InitLicense(iDevelopID, softwareKey, iLicenseID, iFlag);
            /************************************************************************/

            // init the view port.
            partViewPort.InitEnv(partPreviewWnd.Handle, 0.00001, 10000);
            matViewPort.InitEnv(matPreviewWnd.Handle, 0.00001, 10000);
            // display the edition of the nest kernel on the dialog title.
            int iLicType = NestFacadeEx.GetLicenseType();

            if (iLicType == 0)
            {
                this.Text = "NestProfessor DEMO  (License type of the nest kernel: Trial Edition)";
            }
            else if (iLicType == 1)
            {
                this.Text = "NestProfessor DEMO  (License type of the nest kernel: Standard Edition)";
            }
            else if (iLicType == 2)
            {
                this.Text = "NestProfessor DEMO  (License type of the nest kernel: Professional Edition)";
            }

            SetConfig();
        }
Example #4
0
        private void executeBtn_Click(object sender, EventArgs e)
        {
            // check
            if (m_nestPartList.Size() == 0)
            {
                MessageBox.Show("没有需要排版的零件!!!");
                return;
            }
            if (m_matList.Size() == 0)
            {
                MessageBox.Show("没有需要排版的材料!!!");
                return;
            }

            // create nest task object and execute it.
            NestTaskEx      nestTask      = new NestTaskEx(m_nestPartList, m_matList, m_nestParam);
            NestProcessorEx nestProcessor = NestFacadeEx.StartNest(nestTask);

            if (nestProcessor == null)
            {
                //MessageBox.Show("Cannot start the nesting task, please contact TAOSoft and check your license.");
                MessageBox.Show("没有排版的结果,请联系技术人员!!!");
                return;
            }

            // display the nesting result.
            NestResultForm form = new NestResultForm(nestTask, m_nestParam, nestProcessor, m_iNestingTime, m_impDataList, m_partColorConfig);

            form.ShowDialog();
        }
Example #5
0
        private void DemoForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            partViewPort.ReleaseResource();
            matViewPort.ReleaseResource();

            // unload the nesting kernel before the client app will quit.
            NestFacadeEx.UnloadNestKernel();
        }
Example #6
0
        private void saveDxfBtn_Click(object sender, EventArgs e)
        {
            SaveFileDialog saveFileDialog = new SaveFileDialog();

            saveFileDialog.Filter           = "DXF Files|*.dxf";
            saveFileDialog.RestoreDirectory = true;
            if (saveFileDialog.ShowDialog() == DialogResult.OK)
            {
                String strFilePath = saveFileDialog.FileName;

                // save the remnant material as dxf file.
                PolyMatEx      polyMat      = NestFacadeEx.BuildRemnantMat(m_sheet, m_dConnectTol, Convert.ToDouble(mergeDisTextBox.Text));
                GeomItemListEx geomItemList = polyMat.GetGeomItemList();
                NestFacadeEx.GeomItems2DxfDwg(geomItemList, strFilePath, false);
            }
        }
Example #7
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);
        }
Example #8
0
        private void reGenBtn_Click(object sender, EventArgs e)
        {
            // verify input.
            try
            {
                Convert.ToDouble(mergeDisTextBox.Text);
            }
            catch (FormatException exception)
            {
                MessageBox.Show("Incorrect input: " + exception.Message, "NestProfessor DEMO");
                return;
            }

            // re-generate the remnant material from the sheet.
            m_polyMat = NestFacadeEx.BuildRemnantMat(m_sheet, m_dConnectTol, Convert.ToDouble(mergeDisTextBox.Text));

            // update tree nodes.
            UpdateTree();

            /************************************************************************/
            // adjust the drawing area.

            // the boundary rect of all polygons in material.
            Poly2DListEx poly2DList = new Poly2DListEx();

            poly2DList.AddPoly(m_polyMat.GetMatPolygon());
            poly2DList.AddPolyList(m_polyMat.GetUselessHoleList());
            Rect2DEx geomRect = poly2DList.GetRectBox();

            // set the drawing area.
            Int32     iWidth       = matViewWnd.Right - matViewWnd.Left;
            Int32     iHeight      = matViewWnd.Bottom - matViewWnd.Top;
            Point2DEx leftBottomPt = new Point2DEx();
            double    dXDirRange   = m_matViewPort.GetFitAllParam(iWidth, iHeight, geomRect, 1.2, leftBottomPt);

            m_matViewPort.SetDrawingArea(1.1 * dXDirRange, iWidth, iHeight, leftBottomPt);

            m_selPoly = null;
            Invalidate();
            /************************************************************************/
        }
Example #9
0
        // load part object from dxf/dwg file.
        static public PartEx LoadPartFromDxfdwg(String strFilePath, ImpDataListEx impDataList)
        {
            PartEx part = null;

            // 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(part);
            }

            // 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);
            }

            // build part object.
            GeomItemListEx  geomItemList  = impData.GetAllGeomItem();
            AncillaryDataEx ancillaryData = new AncillaryDataEx();

            part = new PartEx(strFileName, geomItemList, ancillaryData);
            impData.SetPartID(part.GetID());
            impDataList.AddImpData(impData);

            return(part);
        }
Example #10
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);
        }
Example #11
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();
                }
            }
        }