using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using DevComponents.DotNetBar; using GeoScene.Globe; using GeoScene.Engine; namespace Cyberpipe { public partial class FrmGenAndFaMenTopu : DevComponents.DotNetBar.Office2007Form { private GSOGlobeControl mglobecontrol; List<string> pipeLayerNames; List<string> valueLayerNames; private GSOLayer xc_layer; private GSOLayer dx_layer; private GSOLayer currentLayer; public FrmGenAndFaMenTopu(GSOGlobeControl globeControl, List<string> _list, List<string> valueList) { InitializeComponent(); mglobecontrol = globeControl; pipeLayerNames = _list; valueLayerNames = valueList; } private void FrmGenAndFaMenTopu_Load(object sender, EventArgs e) { //设置线拓扑参数 //m_layer = globeControl.Globe.Layers.GetLayerByID((int)(Utility.LayerLabel_LayerIDs[pipelineName])); //xc_layer = mglobecontrol.Globe.Layers.GetLayerByCaption(xcpipelineName); //if (xc_layer != null && xc_layer.Dataset != null) //{ // //tboxTopoName.Text = xc_layer.Dataset.Name + "Network"; // cmbPipeLineType.Items.Add(xcpipelineName); //} //dx_layer = mglobecontrol.Globe.Layers.GetLayerByCaption(dxpipelineName); //if (dx_layer != null && dx_layer.Dataset != null) //{ // //tboxTopoName.Text = dx_layer.Dataset.Name + "Network"; // cmbPipeLineType.Items.Add(dxpipelineName); //} for (int i = 0; i < pipeLayerNames.Count; i++) { cmbPipeLineType.Items.Add(pipeLayerNames[i]); } if (cmbPipeLineType.Items.Count <= 0) { return; } cmbPipeLineType.SelectedIndex = 0; tboxTopoName.Text = cmbPipeLineType.SelectedItem.ToString() + "Network"; tboxTolerance.Text = "0.1"; //checkBoxIgnoreZ.Checked = true; //阀门图层参数设置 for (int i = 0; i < mglobecontrol.Globe.Layers.Count; i++)//获取树节点后中所有的layer图层 { GSOLayer layer = mglobecontrol.Globe.Layers[i]; if (layer != null && layer.Dataset != null && layer.Dataset.IsFeatureDataset) { string name = layer.Name; if (layer.Type == EnumLayerType.FeatureLayer && !layer.Caption.Contains("管线") && !name.Contains("\\")) { cbbPointLayers.Items.Add(layer.Caption); } } } if (cbbPointLayers .Items .Count >0) { cbbPointLayers.SelectedIndex = 0; } tboxFMTolerance.Text = "0.1"; //checkBoxFMIgnoreZ.Checked = true; tbNearestDistLimit.Text = "0.2"; tbNearestDistLimit.Enabled = false; //默认为不开启阀门信息 cbbPointLayers.Enabled = false; tboxFMTolerance.Enabled = false; checkBoxFMIgnoreZ.Enabled = false; checkBoxMatchNearest.Enabled = false; checkBoxClearValves.Enabled = false; } /// <summary> /// 确定按钮事件处理 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btn_OK_Click(object sender, EventArgs e) { try { //创建线拓扑 if (tboxTopoName.Text == "") { MessageBox.Show("生成数据名称不能为空!"); return; } currentLayer = mglobecontrol.Globe.Layers.GetLayerByCaption(cmbPipeLineType.SelectedItem.ToString()); GSODataSource selDS = currentLayer.Dataset.DataSource; GSOFeatureDataset linedataset = currentLayer.Dataset as GSOFeatureDataset; if (currentLayer == null) { MessageBox.Show("处理的图层不能为空!", "提示!", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (selDS == null) { MessageBox.Show("数据源不能为空!"); return; } GSODataset testDataset = selDS.GetDatasetByName(tboxTopoName.Text); if (testDataset != null) { DialogResult dres = MessageBox.Show("拓扑数据已经存在,是否重建?", "警告", MessageBoxButtons.OKCancel); if (dres == DialogResult.OK) { selDS.DeleteDatasetByName(tboxTopoName.Text); } else { return; } } double dTolerance = 0; Double.TryParse(tboxTolerance.Text, out dTolerance); GSODataEngineUtility.GeneratePipelineNetwork(selDS, linedataset, tboxTopoName.Text, true, dTolerance, "", "", checkBoxIgnoreZ.Checked, false); if (checkUnionFamen.Checked) { //添加阀门信息 GSONetworkDataset selNWDataset = selDS.GetDatasetByName(tboxTopoName.Text.ToString().Trim()) as GSONetworkDataset; if (selNWDataset == null) { MessageBox.Show("处理的拓扑数据集不能为空!"); return; } GSOLayer selLayer = mglobecontrol.Globe.Layers.GetLayerByCaption(cbbPointLayers.SelectedItem.ToString()); GSOFeatureDataset pointDataset = selLayer.Dataset as GSOFeatureDataset; if (pointDataset == null) { MessageBox.Show("必须有用于匹配的矢量图层!"); return; } if (checkBoxClearValves.Checked)//清除掉以前关联的阀门信息 { selNWDataset.ClearValves(); } double dFMTolerance = 0; Double.TryParse(tboxFMTolerance.Text, out dFMTolerance); Boolean bMatchNearest = checkBoxMatchNearest.Checked; double dNearstDisLimit = 0; Double.TryParse(tbNearestDistLimit.Text, out dNearstDisLimit); Int32 nMatchNum = selNWDataset.GenerateValves(pointDataset, dFMTolerance, checkBoxFMIgnoreZ.Checked, bMatchNearest, dNearstDisLimit); //MessageBox.Show("阀门匹配完成!共匹配了" + nMatchNum + "个阀门!"); MessageBox.Show("拓扑数据创建成功,阀门匹配完成!共匹配了 " + nMatchNum + " 个阀门!", "提示!", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("拓扑数据创建成功!", "提示!", MessageBoxButtons.OK, MessageBoxIcon.Information); } this.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message); LogError.PublishError(ex); } } /// <summary> /// 如果没有找到最近点匹配 复选框选中状态改变事件处理 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void checkBoxMatchNearest_CheckedChanged(object sender, EventArgs e) { if (checkBoxMatchNearest.Checked) { tbNearestDistLimit.Enabled = true; } else { tbNearestDistLimit.Enabled = false; } } /// <summary> /// 关联阀门复选框选中状态事件处理 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void checkUnionFamen_CheckedChanged(object sender, EventArgs e) { if (checkUnionFamen.Checked) { //默认为不开启阀门信息 cbbPointLayers.Enabled = true; tboxFMTolerance.Enabled = true; checkBoxFMIgnoreZ.Enabled = true; checkBoxMatchNearest.Enabled = true; checkBoxClearValves.Enabled = true; } else { cbbPointLayers.Enabled = false; tboxFMTolerance.Enabled = false; checkBoxFMIgnoreZ.Enabled = false; checkBoxMatchNearest.Enabled = false; checkBoxClearValves.Enabled = false; } } /// <summary> /// 取消按钮事件处理 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void buttonX1_Click(object sender, EventArgs e) { this.Close(); } /// <summary> /// 管线类型下拉框选中项改变事件处理 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void cmbPipeLineType_SelectedIndexChanged(object sender, EventArgs e) { tboxTopoName.Text = cmbPipeLineType.SelectedItem.ToString() + "Network"; } } }