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.Data; using System.IO; namespace Cyberpipe { public partial class FrmLineCoordinate : DevComponents.DotNetBar.Office2007Form { public GSOGlobeControl m_GlobeControl = null; public GSOGeometry m_Geometry = null; private int m_nCurSelected = -1; private GSOFeature m_FeatureSelPoint = null; private GSOFeature currentFeature; private string m_node; private GSOLayer layer; public FrmLineCoordinate(GSOFeature _feat, GSOGlobeControl globeControl,string _node) { InitializeComponent(); currentFeature = _feat; m_GlobeControl = globeControl; m_Geometry = _feat.Geometry; m_node = _node; } /// <summary> /// 句柄销毁事件处理 /// </summary> /// <param name="e"></param> protected override void OnHandleDestroyed(EventArgs e) { base.OnHandleDestroyed(e); if (m_FeatureSelPoint != null) { m_FeatureSelPoint.Delete(); if (m_GlobeControl != null) { m_GlobeControl.Refresh(); } } } /// <summary> /// 窗体初始化事件处理 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Frm_LineCoordinate_Load(object sender, EventArgs e) { layer = m_GlobeControl.Globe.Layers.GetLayerByCaption(m_node); cmbReference.SelectedIndex = 0; GSOFeatures feats = layer.GetAllFeatures(); if (feats.Length > 0) { GSOFeature colorFeat = feats[0]; GSOPipeLineStyle3D originstyle = colorFeat.Geometry.Style as GSOPipeLineStyle3D; if (originstyle != null) btnPipelineColor.BackColor = originstyle.LineColor; } if (m_Geometry != null) { UpdateNodeViewList(); } } /// <summary> /// 修改节点列表 /// </summary> private void UpdateNodeViewList() { GSOPoint3ds nodes = GetCurNodes(); if (nodes !=null) { listViewNodeList.Items.Clear(); for (int i = 0; i < nodes.Count ; i++) { ListViewItem item = new ListViewItem(); item.SubItems[0].Text = (i.ToString()); GSOPoint3d pt3d = nodes[i]; GSOPoint2d pt2d = Utility.Latlon_2_XYZ(pt3d.X, pt3d.Y); item.SubItems.Add(pt2d.X.ToString()); item.SubItems.Add(pt2d.Y.ToString()); listViewNodeList.Items.Add(item); } } } /// <summary> /// 得到所有的点集合 /// </summary> /// <returns></returns> private GSOPoint3ds GetCurNodes() { GSOPoint3ds nodes = null; if (m_Geometry .Type ==EnumGeometryType .GeoPolyline3D ) { GSOGeoPolyline3D getPolyline3D = currentFeature.Geometry as GSOGeoPolyline3D; if (getPolyline3D .PartCount >0) { //一条线由多条子线组成,目前就显示第一条子线的节点内容 nodes = getPolyline3D[0]; } } return nodes; } /// <summary> /// 列表选中项改变事件处理 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void listViewNodeList_SelectedIndexChanged(object sender, EventArgs e) { if (listViewNodeList .SelectedItems .Count >0) { ListViewItem item = listViewNodeList.SelectedItems[0]; if (item !=null ) { CheckOldAndSetCurSelItem(item.Index); CheckSelFeaturePoint(); textBoxX.Text = item.SubItems[1].Text; textBoxY.Text = item.SubItems[2].Text; } } } /// <summary> /// 改变选中要素的点 /// </summary> private void CheckSelFeaturePoint() { if (m_nCurSelected >0&&m_nCurSelected <listViewNodeList .Items .Count) { GSOGeoPoint3D geoPoint3D = null; if (m_FeatureSelPoint ==null ||m_FeatureSelPoint .IsDeleted ) { m_FeatureSelPoint = new GSOFeature(); geoPoint3D = new GSOGeoMarker(); GSOMarkerStyle3D style = new GSOMarkerStyle3D(); style.IconPath = Application.StartupPath + "\\Resource\\CrossIcon.png"; geoPoint3D.Style = style; m_FeatureSelPoint.Geometry = geoPoint3D; if (m_GlobeControl !=null ) { m_GlobeControl.Globe.MemoryLayer.AddFeature(m_FeatureSelPoint); m_GlobeControl.Refresh(); } } geoPoint3D = m_FeatureSelPoint.Geometry as GSOGeoPoint3D; geoPoint3D.AltitudeMode = m_Geometry.AltitudeMode; try { ListViewItem itemSel = listViewNodeList.Items[m_nCurSelected]; geoPoint3D.X = Double.Parse(itemSel.SubItems[1].Text); geoPoint3D.Y = Double.Parse(itemSel.SubItems[2].Text); } catch (Exception ex) { MessageBox.Show(ex.Message); } if (m_GlobeControl !=null ) { m_GlobeControl.Refresh(); } } } private void CheckOldAndSetCurSelItem(int nCurItemIndex) { if (m_nCurSelected !=nCurItemIndex ) { if (m_nCurSelected > -1 && m_nCurSelected < listViewNodeList.Items.Count) { ListViewItem itemOldSel = listViewNodeList.Items[m_nCurSelected]; itemOldSel.ForeColor = Color.Black; itemOldSel.BackColor = SystemColors.Window; } m_nCurSelected = nCurItemIndex; } } /// <summary> /// 修改按钮事件处理 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void buttonModify_Click(object sender, EventArgs e) { try { if (listViewNodeList .SelectedIndices .Count >0) { int nSelIndex = listViewNodeList.SelectedIndices[0]; GSOPoint3ds nodes = GetCurNodes(); if (nodes !=null&&nodes .Count >nSelIndex ) { GSOPoint3d newPoint = new GSOPoint3d(); newPoint.X = Double.Parse(textBoxX.Text); newPoint.Y = Double.Parse(textBoxY.Text); GSOPoint2d pt2d = Utility.XYZ_2_Latlon(newPoint.X, newPoint.Y); newPoint.X = pt2d.X; newPoint.Y = pt2d.Y; nodes[nSelIndex] = newPoint; ListViewItem item = listViewNodeList.Items[nSelIndex]; item.SubItems[1].Text = textBoxX.Text; item.SubItems[2].Text = textBoxY.Text; //选中行的索引 SelectItem(m_nCurSelected); if (m_GlobeControl !=null ) { m_GlobeControl.Refresh(); } currentFeature.Geometry = currentFeature.Geometry.Clone(); } } } catch (Exception) { } } /// <summary> /// 选中指定项 /// </summary> /// <param name="nItemIndex"></param> private void SelectItem(int nItemIndex) { if (nItemIndex < 0) { return; } int nRealIndex = nItemIndex; if (nRealIndex > listViewNodeList.Items.Count - 1) { nRealIndex = listViewNodeList.Items.Count - 1; } CheckOldAndSetCurSelItem(nRealIndex); CheckSelFeaturePoint(); ListViewItem item = listViewNodeList.Items[nRealIndex]; item.Selected = true; item.BackColor = SystemColors.Highlight; item.ForeColor = Color.White; listViewNodeList.SelectedIndices.Clear(); listViewNodeList.SelectedIndices.Add(nRealIndex);//**真正让其选择 } /// <summary> /// 列表框重绘列事件处理 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void listViewNodeList_DrawColumnHeader(object sender, DrawListViewColumnHeaderEventArgs e) { e.DrawBackground(); Rectangle r = e.Bounds; r.Width -= 1; Color c = Color.FromArgb(207, 221, 238); e.Graphics.FillRectangle(new SolidBrush(c), r); e.DrawText(); } /// <summary> /// 列表项重绘事件处理 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void listViewNodeList_DrawItem(object sender, DrawListViewItemEventArgs e) { e.DrawDefault = true; } /// <summary> /// 列表框验证事件处理 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void listViewNodeList_Validated(object sender, EventArgs e) { SelectItem(m_nCurSelected); } /// <summary> /// 下一步按钮事件处理 点击下一步,生成管线 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btn_Next_Click(object sender, EventArgs e) { this.Close(); if (m_node.Contains("污水") || m_node.Contains("雨水")) { layer = m_GlobeControl.Globe.Layers.GetLayerByCaption(m_node); Cyberpipe.Forms.FrmPaiShuiAttribute frm = new Cyberpipe.Forms.FrmPaiShuiAttribute(layer, currentFeature, btnPipelineColor.BackColor,cmbReference.Text.Trim()); if (frm.ShowDialog() == DialogResult.OK) { if (frm.line != null && frm.line.Type == EnumGeometryType.GeoPolyline3D) { GSOGeoPolyline3D line = frm.line as GSOGeoPolyline3D; double length = line.GetSpaceLength(true, 6378137); GSOGeoPolyline3D lineLine = line.GetSegment(0, length / 2); GSOPoint3d point3d = lineLine[lineLine.PartCount - 1][lineLine[lineLine.PartCount - 1].Count - 1]; m_GlobeControl.Globe.FlyToPosition(point3d, EnumAltitudeMode.Absolute, 0, 45, 5); } else { m_GlobeControl.Globe.FlyToGeometry(frm.line, 0, 45, 5); } } } else if (m_node.Contains("给水")) { layer = m_GlobeControl.Globe.Layers.GetLayerByCaption(m_node); Cyberpipe.Forms.FrmGongShuiAttribute frm = new Cyberpipe.Forms.FrmGongShuiAttribute(layer, currentFeature, btnPipelineColor.BackColor, cmbReference.Text.Trim()); if (frm.ShowDialog() == DialogResult.OK) { if (frm.line != null && frm.line.Type == EnumGeometryType.GeoPolyline3D) { GSOGeoPolyline3D line = frm.line as GSOGeoPolyline3D; double length = line.GetSpaceLength(true, 6378137); GSOGeoPolyline3D lineLine = line.GetSegment(0, length / 2); GSOPoint3d point3d = lineLine[lineLine.PartCount - 1][lineLine[lineLine.PartCount - 1].Count - 1]; m_GlobeControl.Globe.FlyToPosition(point3d, EnumAltitudeMode.Absolute, 0, 45, 5); } else { m_GlobeControl.Globe.FlyToGeometry(frm.line, 0, 45, 5); } } } else if (m_node.Contains("通信") || m_node.Contains("电信")) { layer = m_GlobeControl.Globe.Layers.GetLayerByCaption(m_node); Cyberpipe.Forms.FrmTongXunAttribute frm = new Cyberpipe.Forms.FrmTongXunAttribute(layer, currentFeature, btnPipelineColor.BackColor, cmbReference.Text.Trim()); if (frm.ShowDialog() == DialogResult.OK) { if (frm.line != null && frm.line.Type == EnumGeometryType.GeoPolyline3D) { GSOGeoPolyline3D line = frm.line as GSOGeoPolyline3D; double length = line.GetSpaceLength(true, 6378137); GSOGeoPolyline3D lineLine = line.GetSegment(0, length / 2); GSOPoint3d point3d = lineLine[lineLine.PartCount - 1][lineLine[lineLine.PartCount - 1].Count - 1]; m_GlobeControl.Globe.FlyToPosition(point3d, EnumAltitudeMode.Absolute, 0, 45, 5); } else { m_GlobeControl.Globe.FlyToGeometry(frm.line, 0, 45, 5); } } } else if (m_node.Contains("气")) { layer = m_GlobeControl.Globe.Layers.GetLayerByCaption(m_node); Cyberpipe.Forms.FrmRanQiAttribute frm = new Cyberpipe.Forms.FrmRanQiAttribute(layer, currentFeature, btnPipelineColor.BackColor, cmbReference.Text.Trim()); if (frm.ShowDialog() == DialogResult.OK) { if (frm.line != null && frm.line.Type == EnumGeometryType.GeoPolyline3D) { GSOGeoPolyline3D line = frm.line as GSOGeoPolyline3D; double length = line.GetSpaceLength(true, 6378137); GSOGeoPolyline3D lineLine = line.GetSegment(0, length / 2); GSOPoint3d point3d = lineLine[lineLine.PartCount - 1][lineLine[lineLine.PartCount - 1].Count - 1]; m_GlobeControl.Globe.FlyToPosition(point3d, EnumAltitudeMode.Absolute, 0, 45, 5); } else { m_GlobeControl.Globe.FlyToGeometry(frm.line, 0, 45, 5); } } } } /// <summary> /// 颜色按钮事件处理 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnPipelineColor_Click(object sender, EventArgs e) { colorDialog1.Color = btnPipelineColor.BackColor; if (colorDialog1.ShowDialog() == DialogResult.OK) { btnPipelineColor.BackColor = colorDialog1.Color; } } } }