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