using System; using System.Collections; using System.Drawing; using System.IO; using System.Linq; using System.Windows.Forms; using DevComponents.DotNetBar; using GeoScene.Data; using GeoScene.Engine; using GeoScene.Globe; namespace Cyberpipe.Forms { public partial class FrmMnModify : Office2007Form { private GSOGlobeControl globecontrol; private string shlayername; MainFrm mainfrm; private double movex; private double movey; private double movez; public ArrayList shresultLists = new ArrayList(); //定位和闪烁初始化定义 int count; //private string flashflag = "single"; GSOFeature hlfeature; public FrmMnModify(GSOGlobeControl _globecontrol, string _shlyr, ArrayList _shresultLists) { InitializeComponent(); globecontrol = _globecontrol; shlayername = _shlyr; shresultLists = _shresultLists; } /// <summary> /// 初始化 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void FrmMnModify_Load(object sender, EventArgs e) { moveXLbl.Text = ""; moveUpLbl.Text = ""; mainfrm = (MainFrm) Owner; if (shlayername != "") { GSOLayer layer = globecontrol.Globe.Layers.GetLayerByCaption(shlayername); layer.Editable = true; } int idx = -1; for (int i = 0; i < shresultLists.Count; i++) { ShResult sr = (ShResult) shresultLists[i]; idx = questionGrid.Rows.Add(); questionGrid.Rows[idx].Cells[0].Value = sr.layerid; questionGrid.Rows[idx].Cells[1].Value = sr.question; } } /// <summary> /// 选中某一行 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void questionGrid_CellContentClick(object sender, DataGridViewCellEventArgs e) { if (e.RowIndex < 0 || e.ColumnIndex < 0) return; if (questionGrid.SelectedCells.Count > 0) { DataGridViewRow row = questionGrid.Rows[questionGrid.SelectedCells[0].RowIndex]; selectLbl.Text = row.Cells["问题图层编号"].Value.ToString(); } GSOLayer centerlayer = globecontrol.Globe.Layers.GetLayerByCaption(shlayername); GSOFeatures feats = centerlayer.GetFeatureByName(selectLbl.Text, true); for (int j = 0; j < feats.Length; j++) { if (feats[j].Name != selectLbl.Text) continue; GSOFeature rowFeature = feats[j]; if (rowFeature == null) continue; if (rowFeature.Geometry != null && rowFeature.Geometry.Type == EnumGeometryType.GeoPolyline3D) { GSOGeoPolyline3D line = rowFeature.Geometry as GSOGeoPolyline3D; if (line == null) continue; 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]; globecontrol.Globe.JumpToPosition(point3D, EnumAltitudeMode.Absolute, 50); hlfeature = rowFeature; highlight(); } else { globecontrol.Globe.JumpToFeature(rowFeature, 300); } } } /// <summary> /// 高亮显示 /// </summary> public void highlight() { //flashflag = "single"; timer1.Start(); } /// <summary> /// 平移对象 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void button1_Click(object sender, EventArgs e) { if (selectLbl.Text == "") { MessageBox.Show("请选择要修改的管线"); return; } if (!isNumber(moveXTxt.Text.Trim()) || !isNumber(moveYTxt.Text.Trim())) { MessageBox.Show("请输入数字"); return; } double disx = double.Parse(moveXTxt.Text.Trim()); //jingdu double disy = double.Parse(moveYTxt.Text.Trim()); //weidu GSOLayer moniLayer = globecontrol.Globe.Layers.GetLayerByCaption(shlayername); if (moniLayer != null) { GSOFeatures monifeats = moniLayer.GetFeatureByFieldValue("编号", selectLbl.Text, true); for (int i = 0; i < monifeats.Length; i++) { GSOFeature monifeat = monifeats[i]; GSOGeometry monifeatline = monifeat.Geometry; GSOPoint3d pts = monifeatline.GeoCenterPoint; double pl = pts.X; double pa = pts.Y; double movealtitude = disy/110/1000; double movelongitude = disx/110/1000/Math.Cos(pa); monifeat.Geometry.MoveXY(movelongitude, movealtitude); } moniLayer.Save(); } movex += disx; movey += disy; moveXLbl.Text = movex.ToString(); moveYLbl.Text = movey.ToString(); globecontrol.Refresh(); } void button2_Click(object sender, EventArgs e) { if (selectLbl.Text == "") { MessageBox.Show("请选择要修改的管线"); return; } if (!isNumber(moveZTxt.Text.Trim())) { MessageBox.Show("请输入数字"); return; } double dis = double.Parse(moveZTxt.Text.Trim()); GSOLayer moniLayer = globecontrol.Globe.Layers.GetLayerByCaption(shlayername); if (moniLayer != null) { GSOFeatures monifeats = moniLayer.GetFeatureByFieldValue("编号", selectLbl.Text, true); for (int i = 0; i < monifeats.Length; i++) { GSOFeature monifeat = monifeats[i]; if (monifeat != null) { monifeat.Geometry.MoveZ(dis); } } moniLayer.Save(); moniLayer.Dataset.Save(); } movez += dis; moveUpLbl.Text = movez.ToString(); globecontrol.Refresh(); } /// <summary> /// 判断是否为数字 /// </summary> /// <param name="s"></param> /// <returns></returns> private bool isNumber(string s) { try { Double.Parse(s); } catch (Exception) { return false; } return true; } /// <summary> /// 导出cad /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void button3_Click(object sender, EventArgs e) { if (shlayername == null || shlayername.Trim().Equals("")) { MessageBox.Show("请选中要导出的图层!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } string checkItemText = shlayername; try { GSOLayer layer = globecontrol.Globe.Layers.GetLayerByCaption(checkItemText.Trim()); if (layer == null) { MessageBox.Show("请选中要导出的图层!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (layer.GetAllFeatures().Length <= 0) { MessageBox.Show("要导出的图层为空", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } layer.Dataset.ImportProjectionRefFromProj4(Utility.projectStr); SaveFileDialog dlg = new SaveFileDialog(); dlg.Filter = "*.dxf|*.dxf"; dlg.FileName = layer.Caption; if (dlg.ShowDialog() == DialogResult.OK) { if (layer.GetAllFeatures().Length > 0) { layer.SaveAs(dlg.FileName); string lprjFileName = dlg.FileName.Substring(0, dlg.FileName.LastIndexOf(".")) + ".lprj"; string lprjFileContent = "<Projects><Project><Index>0</Index><Type>prj4</Type><Param>" + Utility.projectStr + "</Param></Project></Projects>"; StreamWriter writer = new StreamWriter(lprjFileName, false); writer.Write(lprjFileContent); writer.Close(); //导出prj文件 string prjFileName = dlg.FileName.Substring(0, dlg.FileName.LastIndexOf(".")) + ".prj"; StreamWriter writer2 = new StreamWriter(prjFileName, false); writer2.Write(""); writer2.Close(); if (!GSODataEngineUtility.ConvertProj4ToEsriPrjFile(Utility.projectStr, prjFileName)) { MessageBox.Show("导出CAD完成!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); Close(); } } } } catch (Exception ex) { LogError.PublishError(ex); } } private void timer1_Tick(object sender, EventArgs e) { GSOFeature rowFeature = hlfeature;// as GSOFeature; if (rowFeature == null) return; if (count < 40) { count++; rowFeature.HighLight = count%2 != 0; globecontrol.Refresh(); } else { timer1.Stop(); rowFeature.HighLight = false; count = 0; } } private void FrmMnModify_FormClosed(object sender, FormClosedEventArgs e) { mainfrm.boolfrmModify = false; } } }