private void partListView_MouseDoubleClick(object sender, MouseEventArgs e) { ListView.SelectedListViewItemCollection selItems = partListView.SelectedItems; if (selItems.Count == 1) { ListViewItem item = selItems[0]; long iNestPartID = (long)item.Tag; NestPartEx nestPart = m_nestPartList.GetNestPartByID(iNestPartID); if (nestPart != null) { NestPartForm nestPartForm = new NestPartForm(nestPart); if (nestPartForm.ShowDialog() == DialogResult.OK) { /************************************************************************/ // update the list control. // priority column. item.SubItems[2].Text = nestPart.GetPriority().GetVal().ToString(); // nest count column. item.SubItems[3].Text = nestPart.GetNestCount().ToString(); // priority column. item.SubItems[4].Text = NestHelper.GetRotateAngName(nestPart.GetRotStyle()); /************************************************************************/ } } } }
// add part to list control. private void AddPart_to_listCtrl(NestPartEx nestPart, string order) { // insert a row. int iCount = partListView.Items.Count + 1; ListViewItem item = partListView.Items.Add(iCount.ToString()); // part name column. item.SubItems.Add(nestPart.GetPart().GetName()); // priority column. item.SubItems.Add(nestPart.GetPriority().GetVal().ToString()); // nest count column. item.SubItems.Add(nestPart.GetNestCount().ToString()); // rotate angle column. String strRotateAng = NestHelper.GetRotateAngName(nestPart.GetRotStyle()); string temp = string.Empty; switch (strRotateAng.Trim()) { case "Free Rotate": temp = "自由旋转"; break; case "90 Increment": temp = "90度增量"; break; case "180 Increment": temp = "180度增量"; break; case "0 Fixed": temp = "0度固定"; break; case "90 Fixed": temp = "90度固定"; break; case "180 Fixed": temp = "180度固定"; break; case "270 Fixed": temp = "270度固定"; break; } item.SubItems.Add(temp); // "Part Size" column. Rect2DEx partRect = nestPart.GetPart().GetGeomItemList().GetRectBox(); StringBuilder sb = new StringBuilder(); sb.Append(partRect.GetWidth().ToString("0.00")).Append("(W) * ").Append(partRect.GetHeight().ToString("0.00")).Append("(H)"); item.SubItems.Add(sb.ToString()); //添加订单号 item.SubItems.Add(order); // hold the ID. item.Tag = nestPart.GetID(); OrderManagerDal.Instance.AddOrder(nestPart.GetPart().GetID(), order); }
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); } } }
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); }
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); }
// 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; }
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(); } } }