using System; using System.Data; using System.Drawing; using System.Windows.Forms; using DevComponents.DotNetBar; using GeoScene.Data; using GeoScene.Globe; namespace Cyberpipe { public partial class FrmGBJCresult : Office2007Form { DataTable dt; GSOGlobeControl globeControl1; GSOGlobeControl globeControl2; GSOLayer layerTemp; GSOLayer layerTemp2; public FrmGBJCresult(GSOGlobeControl _golbeControl1, GSOGlobeControl _golbeControl2, DataTable _dt,GSOLayer _layerTemp,GSOLayer _layerTemp2) { globeControl1=_golbeControl1; globeControl2 = _golbeControl2; dt = _dt; layerTemp = _layerTemp; layerTemp2 = _layerTemp2; InitializeComponent(); labelX1.Text = DoublePanelAnalysis.strLabel; } private void FrmGBJCresult_Load(object sender, EventArgs e) { dataGridViewX1.DataSource = dt; dataGridViewX1.Columns[0].Width = 80; dataGridViewX1.Columns[1].Width = 130; dataGridViewX1.Columns[2].Width = 80; dataGridViewX1.Columns[3].Width = 130; dataGridViewX1.Columns[4].Width = 70; dataGridViewX1.Columns[5].Width = 80; dataGridViewX1.Columns[6].Width = 70; dataGridViewX1.Columns[7].Width = 80; } /// <summary> /// 结果表双击事件,在地球场景中添加缓冲区和管段的标注 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void dataGridViewX1_CellDoubleClick(object sender, DataGridViewCellEventArgs e) { if (e.RowIndex != -1) { layerTemp.RemoveAllFeature(); layerTemp2.RemoveAllFeature(); //获取globeControl1飞行目标 string scLayer = dataGridViewX1.Rows[e.RowIndex].Cells["实测图层"].Value.ToString(); string scFeatureName = dataGridViewX1.Rows[e.RowIndex].Cells["实测管段"].Value.ToString(); GSOLayer scgsoLayer = globeControl1.Globe.Layers.GetLayerByCaption(scLayer); GSOFeatures scgsoFeatures = scgsoLayer.GetFeatureByName(scFeatureName, false); GSOFeature scgsoFeature = scgsoFeatures[0]; //获取globeControl2飞行目标 string sgLayer = dataGridViewX1.Rows[e.RowIndex].Cells["施工图层"].Value.ToString(); string sgFeatureName = dataGridViewX1.Rows[e.RowIndex].Cells["施工管段"].Value.ToString(); GSOLayer sggsoLayer = globeControl1.Globe.Layers.GetLayerByCaption(sgLayer); GSOFeatures sggsoFeatures = sggsoLayer.GetFeatureByName(sgFeatureName, false); GSOFeature sggsoFeature = sggsoFeatures[0]; AddPolygon(scgsoFeature); AddMakerToLayer(globeControl1, scgsoFeature, scFeatureName); if (sggsoFeature == null) { globeControl2.Globe.MemoryLayer.RemoveAllFeature(); GSOGeoPolyline3D scLine = scgsoFeature.Geometry as GSOGeoPolyline3D; if (scLine[0].Count > 1) { GSOGeoPoint3D pt = new GSOGeoPoint3D(); GSOPoint3d point3d = scLine.GeoCenterPoint; pt.X = point3d.X; pt.Y = point3d.Y; pt.Z = point3d.Z; //globeControl2.Globe.FlyToPosition(point3d, EnumAltitudeMode.Absolute, -4, 50, 50); globeControl2.Globe.JumpToPosition(point3d, EnumAltitudeMode.Absolute, 200); } } else { AddMakerToLayer(globeControl2, sggsoFeature, sgFeatureName); } } } /// <summary> /// 双屏中通知增加实测数据的缓冲区 /// </summary> /// <param name="scFeature"></param> private void AddPolygon(GSOFeature scFeature) { GSOFeature new_feat= new GSOFeature(); GSOGeoPolyline3D line = scFeature.Geometry as GSOGeoPolyline3D; GSOGeoPolygon3D resPolygon = new GSOGeoPolygon3D(); resPolygon = line.CreateBuffer(DoublePanelAnalysis.bufferWidth, true, 0, false, false); resPolygon.AltitudeMode = EnumAltitudeMode.RelativeToGround; new_feat.Geometry = resPolygon; layerTemp.AddFeature(new_feat); layerTemp2.AddFeature(new_feat); globeControl1.Refresh(); globeControl2.Refresh(); } /// <summary> /// 地球场景中添加lable标注 /// </summary> /// <param name="glb"></param> /// <param name="gsoFeature"></param> /// <param name="FeatureName"></param> private void AddMakerToLayer(GSOGlobeControl glb, GSOFeature gsoFeature, string FeatureName) { glb.Globe.MemoryLayer.RemoveAllFeature(); GSOFeature radiusMarkerFeature; if (gsoFeature != null) { GSOGeoPolyline3D selLine = gsoFeature.Geometry as GSOGeoPolyline3D; if (selLine[0].Count > 1) { GSOLayer makerLayer = glb.Globe.MemoryLayer; GSOGeoPoint3D pt = new GSOGeoPoint3D(); GSOPoint3d point3d = selLine.GeoCenterPoint; pt.X = point3d.X; pt.Y = point3d.Y; pt.Z = point3d.Z; //glb.Globe.FlyToPosition(point3d, EnumAltitudeMode.Absolute, -4, 50, 50); glb.Globe.JumpToPosition(point3d, EnumAltitudeMode.Absolute, 200); string radiusLabelName = FeatureName; radiusMarkerFeature = new GSOFeature(); GSOPoint2d point2d = new GSOPoint2d(0, 50); if (makerLayer != null) { if (getLabelName(makerLayer) != -1) { radiusMarkerFeature = createLabel(makerLayer, radiusMarkerFeature, pt, radiusLabelName, (getLabelName(makerLayer) + 1).ToString(), point2d); radiusMarkerFeature.Visible = true; makerLayer.AddFeature(radiusMarkerFeature); } } glb.Refresh(); } } } /// <summary> /// 获取指定图层中最后一个feature对象的名称对应的整数 /// </summary> /// <param name="layer"></param> /// <returns></returns> public int getLabelName(GSOLayer layer) { int nid = -1; if (layer.GetAllFeatures().Length > 0) { string id = layer.GetAllFeatures()[layer.GetAllFeatures().Length - 1].Name; int.TryParse(id, out nid); } else { nid = 0; } return nid; } /// <summary> /// /// </summary> /// <param name="layer"></param> /// <param name="feature"></param> /// <param name="point"></param> /// <param name="labelName"></param> /// <param name="featureName"></param> /// <param name="point2d"></param> /// <returns></returns> private GSOFeature createLabel(GSOLayer layer, GSOFeature feature, GSOGeoPoint3D point, string labelName, string featureName, GSOPoint2d point2d) { for (int i = layer.GetAllFeatures().Length - 1; i >= 0; i--) { GSOFeature gfeat = layer.GetAt(i); if (gfeat != null && gfeat.Geometry != null && gfeat.Geometry.Type == EnumGeometryType.GeoPoint3D) { GSOGeoPoint3D pointItem = gfeat.Geometry as GSOGeoPoint3D; if (pointItem.X == point.X && pointItem.Y == point.Y && pointItem.Z == point.Z) { layer.RemoveAt(i); break; } } } point.AltitudeMode = EnumAltitudeMode.RelativeToGround; feature.Geometry = point; feature.Name = featureName; GSOLabel newLabel = new GSOLabel(); newLabel.Text = labelName; newLabel.Style = new GSOLabelStyle(); newLabel.Style.Opaque = 0.8; newLabel.Style.OutlineColor = Color.Gray; newLabel.Style.TractionLineEndPos = point2d; newLabel.Style.OutlineWidth = 1; newLabel.Style.TracktionLineWidth = 3; newLabel.Style.TractionLineColor = Color.Green; Color color1 = Color.FromArgb(60, 187, 206, 230); Color color2 = Color.FromArgb(150, 187, 200, 250); newLabel.Style.BackBeginColor = color1; newLabel.Style.BackEndColor = color2; feature.Label = newLabel; return feature; } /// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void FrmGBJCresult_FormClosing(object sender, FormClosingEventArgs e) { globeControl1.Globe.MemoryLayer.RemoveAllFeature(); globeControl2.Globe.MemoryLayer.RemoveAllFeature(); layerTemp.RemoveAllFeature(); layerTemp2.RemoveAllFeature(); } /// <summary> /// 导出EXCEL /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void buttonEXPexcel_Click(object sender, EventArgs e) { try { string saveFileName = ""; SaveFileDialog saf = new SaveFileDialog(); saf.Filter = "Excel files (*.xlsx)|*.xlsx"; saf.FilterIndex = 0; saf.RestoreDirectory = true; saf.Title = "保存为Excel文件"; saf.FileName = "国标检测" + "-" + DateTime.Now.ToString("yyyyMMdd") + ".xlsx"; if (saf.ShowDialog() == DialogResult.OK) { saveFileName = saf.FileName; } ExpEXCEL.ExpToExcel(dataGridViewX1, saveFileName, "检测结果"); MessageBox.Show("导出成功!", "提示"); } catch (Exception ex) { MessageBox.Show(ex.Message); } } } }