public void SaveConflictPath(string dir, string ruleName, string conflictName, string filename) { Conflict conflict = _ruleDic[ruleName].ConflictDic[conflictName]; if (dir.Contains(".gdb")) { conflict.Address = dir + "\\" + filename; } else { conflict.Address = dir + "\\" + filename + ".shp"; } SaveTree(); }
/// <summary> /// 读取XML /// </summary> public void Initial() { _ruleDic.Clear();//清空 try { //利用xmldoc对象读取xml文件 XmlDocument xmldoc = new XmlDocument(); xmldoc.Load(xmlpath); //读取根节点 XmlElement xmlele = xmldoc.DocumentElement; //buleMapAddress = xmlele.Attributes["blueMapAddress"].Value; isSDE = Convert.ToBoolean(xmlele.Attributes["isSDE"].Value); //获取根节点下的所有节点 XmlNodeList rules = xmlele.ChildNodes; foreach (XmlNode ruleXML in rules) { Rule rule = new Rule(); rule.Name = ruleXML.Attributes["name"].Value; if (ruleXML.HasChildNodes) { XmlNodeList conflictNodes = ruleXML.ChildNodes; foreach (XmlNode conflictXml in conflictNodes) { Conflict conflict = new Conflict(); conflict.Name = conflictXml.Attributes["name"].Value.ToString(); conflict.ConflictType = conflictXml.Attributes["type"].Value.ToString(); conflict.Address = conflictXml.Attributes["address"].Value.ToString(); XmlNodeList zoneNodes = conflictXml.ChildNodes; conflict.ZoneA.Name = zoneNodes[0].Attributes["name"].Value.ToString(); conflict.ZoneB.Name = zoneNodes[1].Attributes["name"].Value.ToString(); rule.ConflictDic.Add(conflict.Name, conflict); } } _ruleDic.Add(rule.Name, rule); } } catch (Exception ex) { //MessageBox.Show(ex.Message); } }
/// <summary> /// 冲突分析 /// </summary> private void buttonConflict_Click(object sender, EventArgs e) { TreeNode node = treeView1.SelectedNode; if (node.Parent != null) { #region 采用系统自带对话框,保存选择路径 SaveFileDialog dialog = new SaveFileDialog(); dialog.Filter = "Shp files|*.shp"; DialogResult result = dialog.ShowDialog(); if (result == DialogResult.OK) { Conflict conflict = _ruleTree.GetSelectedNode(node) as Conflict; ///获取Zone PlanTree planTree = new PlanTree(); string planNameA = conflict.ZoneA.Name.Split('.')[0]; string zoneNameA = conflict.ZoneA.Name.Split('.')[1]; conflict.ZoneA = planTree.GetZone(planNameA, zoneNameA); string planNameB = conflict.ZoneB.Name.Split('.')[0]; string zoneNameB = conflict.ZoneB.Name.Split('.')[1]; conflict.ZoneB = planTree.GetZone(planNameB, zoneNameB); textBox3.Text = dialog.FileName; conflict.Address = dialog.FileName; conflict.ConflictAnalysis(); conflict.Name = conflict.Name.Replace(".shp", ""); _ruleTree.SaveConflictPath(dialog.FileName, node.Parent.Text, conflict.Name); } #endregion } else { MessageBox.Show("请选择冲突!"); } }
//public void SaveBlueAddress() //{ // //利用xmldoc对象读取xml文件 // XmlDocument xmldoc = new XmlDocument(); // xmldoc.Load(xmlpath); // //读取根节点 // XmlElement xmlele = xmldoc.DocumentElement; // xmlele.SetAttribute("blueMapAddress", buleMapAddress); // xmlele.SetAttribute("isSDE", isSDE.ToString()); // xmldoc.Save(xmlpath); //} /// <summary> /// 获取所有冲突 /// </summary> /// <returns></returns> public List <Conflict> GetConflicts() { TreeView treeview = new TreeView(); BuildTree(treeview); List <Conflict> result = new List <Conflict>(); Conflict conflict = new Conflict(); foreach (string key in _ruleDic.Keys) { Rule rule = _ruleDic[key]; foreach (string key2 in rule.ConflictDic.Keys) { conflict = rule.ConflictDic[key2]; result.Add(conflict); } } //blueMapAddress = buleMapAddress; return(result); }
/// <summary> /// 获取选中树,返回节点信息 /// </summary> public object GetSelectedNode(TreeNode node) { try { if (_ruleDic.Keys.Contains(node.Text))//规划冲突节点 { Rule rule = _ruleDic[node.Text]; return(rule); } else if (_ruleDic.Keys.Contains(node.Parent.Text))//冲突节点 { Conflict conflict = _ruleDic[node.Parent.Text].ConflictDic[node.Text]; return(conflict); } else { return(null); } } catch (Exception ex) { return(null); } }
/// <summary> /// 修改冲突节点名称 /// </summary> public void ModifyConflictName(Conflict conflict, Rule rule, string newName) { _ruleDic[rule.Name].ConflictDic.Remove(conflict.Name); conflict.Name = newName; _ruleDic[rule.Name].ConflictDic.Add(newName, conflict); }
/// <summary> /// 修改冲突节点 /// </summary> public void ModifyConflict(Conflict conflict, Rule rule) { _ruleDic[rule.Name].ConflictDic[conflict.Name] = conflict; }
/// <summary> /// 删除冲突节点 /// </summary> public void RemoveConflict(Conflict conflict, Rule rule) { _ruleDic[rule.Name].ConflictDic.Remove(conflict.Name); }