// init the tree by part name. private void InitTreeByPart() { partPmtTreeView.Nodes.Clear(); PartPmtListEx partPmtList = m_sheet.GetPartPmtList(); PartListEx partList = partPmtList.GetPartList(); for (int i = 0; i < partList.Size(); i++) { PartEx part = partList.GetPartByIndex(i); // append the part node. TreeNode partNode = partPmtTreeView.Nodes.Add(part.GetName()); partNode.ImageIndex = 0; partNode.SelectedImageIndex = 0; partNode.Tag = part.GetID(); // insert each part pmt node. PartPmtListEx partPmtList1 = partPmtList.GetAllPmtOfPart(part.GetID()); for (int j = 0; j < partPmtList1.Size(); j++) { PartPmtEx partPmt = partPmtList1.GetPartPmtByIndex(j); // append the part placement node. String strNodeName = "Placement "; strNodeName += (j + 1); TreeNode pmtNode = partNode.Nodes.Add(strNodeName); pmtNode.ImageIndex = 1; pmtNode.SelectedImageIndex = 1; pmtNode.Tag = partPmt.GetID(); } } }
// 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); }
// init the tree by part name. private void InitTreeByTopology(TreeNodeCollection nodes, PartTopItemListEx partTopItemList) { for (int i = 0; i < partTopItemList.Size(); i++) { PartTopItemEx partTopItem = partTopItemList.GetPartPmtByIndex(i); PartPmtEx partPmt = partTopItem.GetPartPmt(); PartEx part = partPmt.GetPart(); // append a node. TreeNode pmtNode = nodes.Add(part.GetName()); pmtNode.ImageIndex = 1; pmtNode.SelectedImageIndex = 1; pmtNode.Tag = partPmt.GetID(); // append the child node. PartTopItemListEx subTopItemList = partTopItem.GetSubPartTopItem(); if (subTopItemList.Size() > 0) { InitTreeByTopology(pmtNode.Nodes, subTopItemList); } } }
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; } }
private void QrCodeForm_Load(object sender, EventArgs e) { int v = 0; int vv = 0; int vvv = 0; Pen blackPen = new Pen(Color.Black, 1); Pen blackPen2 = new Pen(Color.Black, 2); SolidBrush blackBrush = new SolidBrush(Color.Black); HatchBrush hatchBrush = new HatchBrush(HatchStyle.BackwardDiagonal, Color.Black, Color.White); //外边距 int space = 2; for (int length = 0; length < shtListView.Items.Count; length++) { SLTQrCodeItem SLTQrCodeItemTemp = new SLTQrCodeItem() { SLTBmpShadowList = new List <SLTShadowBmp>() }; ListViewItem item = shtListView.Items[length]; long iSheetID = (long)item.Tag; SheetEx sheet = m_sheetList.GetSheetByID(iSheetID); string M_Name = sheet.GetMat().GetName(); PartPmtListEx partPmtList = sheet.GetPartPmtList(); int partsCount = partPmtList.GetPartList().Size(); Rect2DEx sheetRec = sheet.GetMat().GetBoundaryRect(); int MatWidth = (int)sheetRec.GetWidth(); int MatHeight = (int)sheetRec.GetHeight(); SLTQrCodeItemTemp.BlankBmp = new Bitmap(MatWidth + 1, MatHeight + 1); Graphics gBlank = Graphics.FromImage(SLTQrCodeItemTemp.BlankBmp); gBlank.Clear(Color.FromArgb(255, 255, 255, 255)); //边框 gBlank.DrawRectangle(blackPen, 0, 0, MatWidth, MatHeight); //缩略图 for (int i = 0; i < partsCount; i++) { SLTShadowBmp SLTShadowBmpItem = new SLTShadowBmp(); PartPmtEx partPmt = sheet.GetPartTopItemList().GetPartPmtByIndex(i).GetPartPmt(); Rect2DEx partRe2 = partPmt.GetRectBox(); Matrix2DEx Matrix = partPmt.GetMatrix(); int PartWidth = (int)partRe2.GetWidth(); int PartHeight = (int)partRe2.GetHeight(); int PoX = (int)Matrix.GetMatVal(2, 0); int PoY = (int)Matrix.GetMatVal(2, 1); int Angle = (int)(Math.Asin(Matrix.GetMatVal(0, 1)) * 180 / Math.PI); SLTShadowBmpItem.SLTPartInfos = new SLTPartShape() { PoX = m_nestParam.GetNestDir() == NEST_DIRECTION_EX.NEST_DIR_X ? PoX : PoX - PartWidth, PoY = MatHeight - PoY - PartHeight, PartWidth = PartWidth, PartHeight = PartHeight, NestDir = m_nestParam.GetNestDir() == NEST_DIRECTION_EX.NEST_DIR_X ? "X" : "Y", MatName = M_Name, }; SLTQrCodeItemTemp.SLTBmpShadowList.Add(SLTShadowBmpItem); gBlank.DrawRectangle(blackPen, SLTShadowBmpItem.SLTPartInfos.PoX, SLTShadowBmpItem.SLTPartInfos.PoY, PartWidth, PartHeight); } gBlank.Dispose(); //加阴影缩略图 for (int i = 0; i < SLTQrCodeItemTemp.SLTBmpShadowList.Count; i++) { Bitmap original = SLTQrCodeItemTemp.BlankBmp; Bitmap copy = new Bitmap(original.Width, original.Height); SLTShadowBmp Shapeitem = SLTQrCodeItemTemp.SLTBmpShadowList[i]; using (Graphics gTemp = Graphics.FromImage(copy)) { gTemp.Clear(Color.White); Rectangle imageRectangle = new Rectangle(0, 0, copy.Width, copy.Height); gTemp.DrawImage(original, imageRectangle, imageRectangle, GraphicsUnit.Pixel); gTemp.FillRectangle(hatchBrush, Shapeitem.SLTPartInfos.PoX, Shapeitem.SLTPartInfos.PoY, Shapeitem.SLTPartInfos.PartWidth, Shapeitem.SLTPartInfos.PartHeight); gTemp.DrawRectangle(blackPen2, Shapeitem.SLTPartInfos.PoX, Shapeitem.SLTPartInfos.PoY, Shapeitem.SLTPartInfos.PartWidth, Shapeitem.SLTPartInfos.PartHeight);//画矩形 } SLTQrCodeItemTemp.SLTBmpShadowList[i].ShadowBmp = copy; PartEx partEx = partPmtList.GetPartList().GetPartByIndex(i); string OrderNo = OrderManagerDal.Instance.GetOrder(partEx.GetID()); string partNameIndex = partEx.GetName().Substring(1, 1); string partName = partEx.GetName(); SLTQrCodeItemTemp.SLTBmpShadowList[i].QrCodeText = OrderNo + "-" + partNameIndex; SLTQrCodeItemTemp.SLTBmpShadowList[i].QrCodeBmp = GenerateQRCode(partNameIndex); //字体 Font font = new Font("微软雅黑", 60f);//8号 //设定字体格式 StringFormat format = new StringFormat() { Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center, }; string text1 = OrderNo + "-" + partNameIndex; string text2 = partName; string text3 = Shapeitem.SLTPartInfos.PartWidth + "*" + Shapeitem.SLTPartInfos.PartHeight; string text4 = Shapeitem.SLTPartInfos.MatName; SLTQrCodeItemTemp.SLTBmpShadowList[i].SLTText = text1 + "\r\n" + text2 + "\r\n" + text3 + "\r\n" + text4; Size SLTTextSize = TextRenderer.MeasureText(SLTQrCodeItemTemp.SLTBmpShadowList[i].SLTText, font); Bitmap textBmp = new Bitmap(SLTTextSize.Width + space + 5, SLTTextSize.Width + space + 5); using (Graphics gTextTemp = Graphics.FromImage(textBmp)) { gTextTemp.Clear(Color.White); gTextTemp.SmoothingMode = SmoothingMode.HighQuality; gTextTemp.DrawString(SLTQrCodeItemTemp.SLTBmpShadowList[i].SLTText, font, blackBrush, new RectangleF(space, (textBmp.Height - SLTTextSize.Height - (2 * space)) / 2 + space, textBmp.Width - space, textBmp.Height - space)); } SLTQrCodeItemTemp.SLTBmpShadowList[i].SLTTextBmp = textBmp; } _SLTQrCodeList.Add(SLTQrCodeItemTemp); //g.DrawString(partName, font, blackBrush, new RectangleF(0, 0, 100, 100), format); //g.DrawImage(qrBmp, 150, 150, 50, 50); } // int bmpPrintWidth = 500; int Colunm = 2; List <Shape> positionBase = new List <Shape>(); int count = 0; for (int i = 0; i < _SLTQrCodeList.Count; i++) { for (int j = 0; j < _SLTQrCodeList[i].SLTBmpShadowList.Count; j++) { count++; } } for (int i = 0; i < count; i++) { for (int j = 0; j < Colunm; j++) { if (i * j + j >= count) { break; } Shape itemTemp = new Shape() { PoX = j * (bmpPrintWidth / Colunm), PoY = i * (bmpPrintWidth / Colunm), PartWidth = bmpPrintWidth / Colunm, PartHeight = bmpPrintWidth / Colunm, }; positionBase.Add(itemTemp); } } int bmpPrintHeight = ((positionBase.Count / Colunm) + (positionBase.Count % Colunm)) * (bmpPrintWidth / Colunm); Bitmap PrintBmp = new Bitmap(bmpPrintWidth, bmpPrintHeight); using (Graphics gPrint = Graphics.FromImage(PrintBmp)) { gPrint.Clear(Color.White); count = 0; for (int i = 0; i < _SLTQrCodeList.Count; i++) { for (int j = 0; j < _SLTQrCodeList[i].SLTBmpShadowList.Count; j++) { float TextPx = positionBase[count].PoX; float TextPy = positionBase[count].PoY + positionBase[count].PartHeight * 0.1f; float QrCodePx = TextPx; float QrCodePy = positionBase[count].PoY + positionBase[count].PartHeight * 0.5f; float SLTPx = positionBase[count].PoX + positionBase[count].PartWidth * 0.4f; float SLTPy = positionBase[count].PoY; Size SLTSize = _SLTQrCodeList[i].SLTBmpShadowList[j].ShadowBmp.Size; float SLTWidth = (int)(positionBase[count].PartHeight * SLTSize.Width / SLTSize.Height); float SLTHeight = (int)(positionBase[count].PartHeight); Bitmap SLTBmpTemp = _SLTQrCodeList[i].SLTBmpShadowList[j].ShadowBmp; float scale = (float)SLTSize.Width / (float)SLTSize.Height; if (scale < 0.6f)//固定高度 { SLTWidth = (int)(positionBase[count].PartHeight * SLTSize.Width / SLTSize.Height); SLTHeight = positionBase[count].PartHeight; } else if (0.6f < scale && scale < 1)//固定宽度 { SLTWidth = positionBase[count].PartWidth * 0.6f; SLTHeight = (int)(positionBase[count].PartWidth * 0.6f * SLTSize.Height / SLTSize.Width); } else if (scale > 1)//旋转 { SLTWidth = positionBase[count].PartWidth * 0.6f; SLTHeight = (int)(positionBase[count].PartWidth * 0.6f * SLTSize.Height / SLTSize.Width); //SLTBmpTemp = new Bitmap(SLTSize.Width, SLTSize.Height); //using (Graphics gCcopy = Graphics.FromImage(SLTBmpTemp)) //{ // gCcopy.Clear(Color.White); // gCcopy.TranslateTransform(0, 0); //源点移动到旋转中心 // gCcopy.RotateTransform(90f); //旋转 // Rectangle imageRectangle = new Rectangle(0, 0, SLTSize.Width, SLTSize.Height); // gCcopy.DrawImage(_SLTQrCodeList[i].SLTBmpShadowList[j].ShadowBmp, imageRectangle, imageRectangle, GraphicsUnit.Pixel); //} //scale = SLTSize.Height / SLTSize.Width; //if (0.6f < scale && scale < 1)//固定高度 //{ // SLTWidth = (int)(positionBase[count].PartHeight * SLTSize.Width / SLTSize.Height); // SLTHeight = positionBase[count].PartHeight; //} //else if (0.6f < scale && scale < 1)//固定宽度 //{ // SLTWidth = positionBase[count].PartWidth * 0.6f; // SLTHeight = (int)(positionBase[count].PartWidth * 0.6f * SLTSize.Height / SLTSize.Width); //} } //else//固定高度 //{ // SLTWidth = (int)(positionBase[count].PartHeight * SLTSize.Width / SLTSize.Height); // SLTHeight = positionBase[count].PartHeight; //} gPrint.DrawImage(_SLTQrCodeList[i].SLTBmpShadowList[j].SLTTextBmp, TextPx, TextPy, (int)(positionBase[count].PartWidth * 0.4), (int)(positionBase[count].PartHeight * 0.4)); gPrint.DrawImage(_SLTQrCodeList[i].SLTBmpShadowList[j].QrCodeBmp, QrCodePx, QrCodePy, (int)(positionBase[count].PartWidth * 0.4), (int)(positionBase[count].PartHeight * 0.4)); gPrint.DrawImage(SLTBmpTemp, SLTPx, SLTPy, SLTWidth, SLTHeight); count++; } } } panelQrCodePrint.BackgroundImage = PrintBmp; panelQrCodePrint.BackgroundImageLayout = ImageLayout.Stretch; for (int i = 0; i < _SLTQrCodeList.Count; i++) { for (int j = 0; j < _SLTQrCodeList[i].SLTBmpShadowList.Count; j++) { cbShadowBmp.Items.Add(_SLTQrCodeList[i].SLTBmpShadowList[j].QrCodeText); } } }
static private NestPartListEx LoadNestParts_V1(string strTaskFilePath, XmlNode partListNode, List <KeyValuePair <long, string> > partDxfPath, ImpDataListEx impDataList, Dictionary <long, int> partColorConfig) { NestPartListEx nestParts = new NestPartListEx(); for (int i = 0; i < partListNode.ChildNodes.Count; i++) { XmlNode partNode = partListNode.ChildNodes.Item(i); NestPartEx nestPart = new NestPartEx(); // part Path. string strPartFileFullPath = partNode.SelectSingleNode("Path").InnerText; // load part. if (!File.Exists(strPartFileFullPath)) { // the new file path. string strTaskFileFolder = strTaskFilePath.Substring(0, strTaskFilePath.LastIndexOf("\\")); string strPartFileName = strPartFileFullPath.Substring(strPartFileFullPath.LastIndexOf("\\") + 1, strPartFileFullPath.Length - strPartFileFullPath.LastIndexOf("\\") - 1); string strNewPartFileFullPath = strTaskFileFolder + "\\" + strPartFileName; // try again. if (!File.Exists(strNewPartFileFullPath)) { string strMessage = "Cannot find part file: "; MessageBox.Show(strMessage + strPartFileFullPath, "NestProfessor DEMO"); continue; } else { strPartFileFullPath = strNewPartFileFullPath; } } PartEx part = NestHelper.LoadPartFromDxfdwg(strPartFileFullPath, impDataList); nestPart.SetPart(part); // nest count. nestPart.SetNestCount(Convert.ToInt32(partNode.SelectSingleNode("Count").InnerText)); // rotate. nestPart.SetRotStyle((PART_ROT_STYLE_EX)Convert.ToInt32(partNode.SelectSingleNode("Rotate").InnerText)); // custom angle. if (nestPart.GetRotStyle() == PART_ROT_STYLE_EX.PART_ROT_CUSTOM_ANG) { ArrayList customRotAngs = new ArrayList(); string strAngles = partNode.SelectSingleNode("CustomAng").InnerText; string[] strArray = strAngles.Split(','); foreach (string strAngle in strArray) { double dAngle = Convert.ToDouble(strAngle); customRotAngs.Add(dAngle); } nestPart.SetCustomRotAng(customRotAngs); } // color. int iColor = Convert.ToInt32(partNode.SelectSingleNode("Color").InnerText); nestParts.AddNestPart(nestPart); partDxfPath.Add(new KeyValuePair <long, string>(nestPart.GetID(), strPartFileFullPath)); partColorConfig[nestPart.GetPart().GetID()] = iColor; } return(nestParts); }
/// <summary> /// NX 1953 中可能无法正确导入 STEP,返回 null /// </summary> /// <param name="filePath"></param> /// <returns></returns> public static NXOpen.Body NXImport(string filePath) { var originalBodies = WorkPart.Bodies.ToArray(); var preferenceFilePath = System.IO.Path.Combine(System.IO.Path.GetTempPath(), "RhinoInside Preferences.config"); var currentNXProcessFile = new System.IO.FileInfo(Process.GetCurrentProcess().MainModule.FileName); // NXBIN\ugraf.exe var nxRootPath = currentNXProcessFile.Directory.Parent.FullName; //if (!System.IO.File.Exists(preferenceFilePath) || System.IO.File.ReadAllLines(preferenceFilePath).First(obj => obj.Contains("STEPMode")).Split('=')[1] == "Internal") if (true) { NXOpen.Step242Importer step242Importer = TheSession.DexManager.CreateStep242Importer(); step242Importer.SimplifyGeometry = true; step242Importer.Messages = NXOpen.Step242Importer.MessageEnum.None; step242Importer.ObjectTypes.Surfaces = true; step242Importer.ObjectTypes.Solids = true; step242Importer.SimplifyGeometry = false; step242Importer.SmoothBSurfaces = false; step242Importer.SettingsFile = Path.Combine(nxRootPath, "translators", "step242", "step242ug.def"); step242Importer.ImportToTeamcenter = false; #if !NX1847 && !NX1872 && !NX1899 && !NX1926 step242Importer.SetMode(NXOpen.BaseImporter.Mode.NativeFileSystem); #endif step242Importer.OutputFile = GetTempFileName(".prt"); step242Importer.InputFile = filePath; step242Importer.ObjectTypes.Curves = false; step242Importer.ObjectTypes.Surfaces = true; step242Importer.ObjectTypes.Solids = true; step242Importer.ObjectTypes.Csys = false; step242Importer.ObjectTypes.PmiData = false; #if !NX1847 && !NX1872 && !NX1899 && !NX1926 step242Importer.ObjectTypes.Kinematic = false; step242Importer.ObjectTypes.Attributes = false; #endif step242Importer.SewSurfaces = true; step242Importer.SimplifyGeometry = true; step242Importer.Optimize = true; step242Importer.SmoothBSurfaces = true; step242Importer.FlattenAssembly = false; step242Importer.FileOpenFlag = false; step242Importer.ProcessHoldFlag = false; NXOpen.NXObject nXObject = step242Importer.Commit(); step242Importer.Destroy(); } else { string outputFile = GetTempFileName("prt"); using (Process p = new Process()) { p.StartInfo.FileName = "cmd.exe"; p.StartInfo.UseShellExecute = false; //是否使用操作系统shell启动 p.StartInfo.RedirectStandardInput = true; //接受来自调用程序的输入信息 p.StartInfo.RedirectStandardOutput = true; //由调用程序获取输出信息 p.StartInfo.RedirectStandardError = true; //重定向标准错误输出 p.StartInfo.CreateNoWindow = true; //不显示程序窗口 p.Start(); //启动程序 //向cmd窗口写入命令 p.StandardInput.AutoFlush = true; p.StandardInput.WriteLine(Path.Combine(nxRootPath, "UGII", "nxcommand.bat") + "&exit"); string cmd = Path.Combine(nxRootPath, @"step214ug\step214ug.cmd") + $" {filePath} o={outputFile} d=" + Path.Combine(nxRootPath, @"STEP214UG\step214ug.def") + $" l={outputFile}.log" + "&exit"; p.StandardInput.WriteLine(cmd); //获取cmd窗口的输出信息 p.StandardOutput.ReadToEnd(); p.WaitForExit();//等待程序执行完退出进程 p.Close(); } PartEx.ImportPart(WorkPart, outputFile, Matrix4x4Ex.Identity); } if (WorkPart.Bodies.ToArray().Length == originalBodies.Length) { return(null); } else { var resultBody = WorkPart.Bodies.ToArray().Last(); resultBody.SetBooleanUserAttribute("GH_Baked_Object", -1, false, NXOpen.Update.Option.Now); return(resultBody); } }
private void viewShtBtn_Click(object sender, EventArgs e) { ListView.SelectedListViewItemCollection selItems = shtListView.SelectedItems; if (selItems.Count != 1) { MessageBox.Show("Please select one sheet to view.", "NestProfessor DEMO"); return; } else { ListViewItem item = selItems[0]; long iSheetID = (long)item.Tag; SheetEx sheet = m_sheetList.GetSheetByID(iSheetID); string M_Name = sheet.GetMat().GetName(); PartPmtListEx partPmtList = sheet.GetPartPmtList(); int partsCount = partPmtList.GetPartList().Size(); Rect2DEx sheetRec = sheet.GetMat().GetGeomItemList().GetItemByIndex(0).GetRectBox(); string info = "SheetName:" + M_Name + "\r\nWidth:" + sheetRec.GetWidth().ToString() + "--Height:" + sheetRec.GetHeight().ToString(); for (int i = 0; i < partsCount; i++) { PartEx partEx = partPmtList.GetPartList().GetPartByIndex(i); PartPmtEx part = sheet.GetPartTopItemList().GetPartPmtByIndex(i).GetPartPmt(); Rect2DEx re2 = part.GetRectBox(); Matrix2DEx Matrix = part.GetMatrix(); info += "\r\nPartName:" + partEx.GetName() + "\r\n角度:" + Math.Round(Math.Asin(Matrix.GetMatVal(0, 1)) * 180 / Math.PI).ToString() + "度" + "\r\nX:" + Math.Round(Matrix.GetMatVal(2, 0)).ToString() + "\tY:" + Math.Round(Matrix.GetMatVal(2, 1)).ToString() + "\r\n长:" + Math.Round(re2.GetWidth()).ToString() + "\t宽:" + Math.Round(re2.GetHeight()).ToString() + "\t面积:" + Math.Round(re2.GetWidth() * re2.GetHeight()).ToString(); } Bitmap bmp = new Bitmap(300, 300); Graphics GraphicsObj = Graphics.FromImage(bmp); GraphicsObj.Clear(Color.White); //写字 string str = "OrderNo:0025"; Font font = new Font("微软雅黑", 15f); double strWidth = TextRenderer.MeasureText(str, font).Width; Brush brush = Brushes.Red; PointF point = new PointF(10f, 10f); GraphicsObj.DrawString(str, font, brush, 10, 10); //画图形 Pen myPen = new Pen(Color.Red, 1); GraphicsObj.DrawRectangle(myPen, 50, 50, 30, 30);//画矩形 SolidBrush myBrush = new SolidBrush(Color.Red); GraphicsObj.FillRectangle(myBrush, 70, 70, 30, 30); //添加图形 Bitmap tBtm = new Bitmap(1000, 1000); Brush blackrush = Brushes.Black; Graphics gTest = Graphics.FromImage(tBtm); gTest.FillRectangle(blackrush, 0, 0, 1000, 1000); GraphicsObj.DrawImage(tBtm, 100, 100, 50, 50); MessageBox.Show(info); if (sheet != null) { SheetInfoForm form = new SheetInfoForm(m_impDataList, m_partColorConfig, sheet); form.ShowDialog(); } } }
// 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; }
// 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); }
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(); } } }
// 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); } } } } } } }