using System; using System.Collections.Generic; using System.Windows.Forms; using DevComponents.DotNetBar; using GeoScene.Engine; using GeoScene.Globe; namespace Cyberpipe { public partial class FrmGenAndFaMenTopu : Office2007Form { private GSOGlobeControl mglobecontrol; private GSOLayer xc_layer; private GSOLayer dx_layer; private GSOLayer currentLayer; public FrmGenAndFaMenTopu(GSOGlobeControl globeControl) { InitializeComponent(); mglobecontrol = globeControl; } private void FrmGenAndFaMenTopu_Load(object sender, EventArgs e) { for (int i = 0; i < Utility.m_PipelineLayerNames.Count; i++) { cmbPipeLineType.Items.Add(Utility.m_PipelineLayerNames[i]); } if (cmbPipeLineType.Items.Count <= 0) return; for (int j = 0; j < Utility.instrumenLayerNames.Count; j++) { if (Utility.instrumenLayerNames[j].Contains("阀门")) cbbPointLayers.Items.Add(Utility.instrumenLayerNames[j]); } cmbPipeLineType.SelectedIndex = 0; tboxTopoName.Text = cmbPipeLineType.SelectedItem + "Network"; tboxTolerance.Text = "0.1"; 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.Trim()) as GSONetworkDataset; if (selNWDataset == null) { MessageBox.Show("处理的拓扑数据集不能为空!"); return; } GSOLayer selLayer = mglobecontrol.Globe.Layers.GetLayerByCaption(cbbPointLayers.SelectedItem.ToString()); if (selLayer == null) { MessageBox.Show("不存在图层:" + cbbPointLayers.SelectedItem); return; } 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 + " 个阀门!", "提示!", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("拓扑数据创建成功!", "提示!", MessageBoxButtons.OK, MessageBoxIcon.Information); } 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) { Close(); } /// <summary> /// 管线类型下拉框选中项改变事件处理 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void cmbPipeLineType_SelectedIndexChanged(object sender, EventArgs e) { tboxTopoName.Text = cmbPipeLineType.SelectedItem + "Network"; } } }