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); } } }
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(); } }
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); } }
private void Preview_selected_part() { // get the select NestPartEx object. ListView.SelectedListViewItemCollection selItems = partListView.SelectedItems; if (selItems.Count == 0) { return; } ListViewItem item = selItems[0]; long iNestPartID = (long)item.Tag; NestPartEx nestPart = m_nestPartList.GetNestPartByID(iNestPartID); if (nestPart != null) { PartEx part = nestPart.GetPart(); GeomItemListEx partGeomItems = part.GetGeomItemList(); // fit the geom to window. DrawHelper.FitWindow(partGeomItems.GetRectBox(), partViewPort, partPreviewWnd); // clear screen and set the background color. partViewPort.BindRendContext(); partViewPort.ClearScreen(); partViewPort.SetBackgroundColor(Color.Black); // set the draw params. partViewPort.SetDrawColor(ColorTranslator.FromOle(m_partColorConfig[nestPart.GetPart().GetID()])); partViewPort.SetLineWidth(1); partViewPort.DrawGeomItemList(partGeomItems); // swap buffer to display the geometry. partViewPort.SwapBuffers(); //Graphics g = partPreviewWnd.Graphics; } }
// 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); }
// 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); }
// draw the part placements. static public void DrawPartPmts(PartPmtListEx partPmts, PartPmtListEx selected_partPmts, GlViewPortEx viewPort, Dictionary <long, int> partColorConfig, ImpDataListEx impDataList) { for (int k = 0; k < partPmts.Size(); k++) { PartPmtEx partPmt = partPmts.GetPartPmtByIndex(k); PartEx part = partPmt.GetPart(); // set the color and line width. if (selected_partPmts != null && selected_partPmts.GetPartPmtByID(partPmt.GetID()) != null) { viewPort.SetLineWidth(6); viewPort.SetDrawColor(Color.Red); } else { viewPort.SetLineWidth(2); int iColor = partColorConfig[part.GetID()]; viewPort.SetDrawColor(ColorTranslator.FromOle(iColor)); } // get the ImpData object. ImpDataEx impData = null; for (int m = 0; m < impDataList.Size(); m++) { ImpDataEx tmpImpData = impDataList.GetImpDataByIndex(m); if (tmpImpData.GetPartID() == part.GetID()) { impData = tmpImpData; break; } } // draw the first instance in the grid. { // draw base geom. GeomItemListEx geomItems_not_poly = impData.GetBaseGeomList(); if (geomItems_not_poly != null) { viewPort.DrawGeomItemList_With_Mat(geomItems_not_poly, partPmt.GetMatrix()); } // draw poly data. PolyDataListEx polyDataList = impData.GetPolyDataList(); if (polyDataList != null) { for (int m = 0; m < polyDataList.Size(); m++) { PolyDataEx polyData = polyDataList.GetPolyDataByIndex(m); viewPort.DrawLoop_With_Mat(polyData, partPmt.GetMatrix()); } } } // draw other parts in the grid. if (partPmt.IsGrid()) { int iColCount = partPmt.GetColCount(); int iRowCount = partPmt.GetRowCount(); double dSpacingX = partPmt.GetSpacingX(); double dSpacingY = partPmt.GetSpacingY(); for (int i = 0; i < iColCount; i++) { for (int j = 0; j < iRowCount; j++) { if (i == 0 && j == 0) { continue; } // prepare the transform matrix. double dOffsetX = dSpacingX * i; double dOffsetY = dSpacingY * j; Vector2DEx offsetVect = new Vector2DEx(dOffsetX, dOffsetY); Matrix2DEx mat = partPmt.GetMatrix(); mat.Transfer(offsetVect.X(), offsetVect.Y()); // draw base geom. GeomItemListEx geomItems_not_poly = impData.GetBaseGeomList(); if (geomItems_not_poly != null) { viewPort.DrawGeomItemList_With_Mat(geomItems_not_poly, mat); } // draw poly data. PolyDataListEx polyDataList = impData.GetPolyDataList(); if (polyDataList != null) { for (int m = 0; m < polyDataList.Size(); m++) { PolyDataEx polyData = polyDataList.GetPolyDataByIndex(m); viewPort.DrawLoop_With_Mat(polyData, mat); } } } } } } }