From 566e0d21293a5fe6423fd7a16541bce00eeb2e38 Mon Sep 17 00:00:00 2001 From: 13693261870 <252740454@qq.com> Date: 星期五, 27 九月 2024 11:15:21 +0800 Subject: [PATCH] OK --- TEWin/FrmWin.cs | 968 ++++++++++++++++++++++++++++++++++++++++++++++++++------ 1 files changed, 850 insertions(+), 118 deletions(-) diff --git a/TEWin/FrmWin.cs b/TEWin/FrmWin.cs index 4b04207..49a0a95 100644 --- a/TEWin/FrmWin.cs +++ b/TEWin/FrmWin.cs @@ -7,7 +7,9 @@ using System.Drawing; using System.IO; using System.Linq; +using System.Runtime.InteropServices; using System.Text; +using System.Threading; using System.Windows.Forms; using TerraExplorerX; using TETree; @@ -17,19 +19,62 @@ { public partial class FrmWin : Form { + #region 鎴愬憳鍙橀噺+鏋勯�犲嚱鏁�+浜嬩欢 + string fly; + FrmTree tree; FrmTool tool; - string mainUrl; + bool isAngle; - public SGWorld74 SG = null; + int angleCount; + + double angleSize; + + public SGWorld71 SG; + + System.Timers.Timer timer; + + ITerrainLabel71 angleLabel; + + ITerrainLabel71 aLabel; + + ITerrainLabel71 bLabel; + + ITerrainPolyline71 angleLine; + + string startName = "OnStart"; + + string angleGroupName = "瑙掗噺绠�"; + + string shpGroupName = "鐭㈤噺鏁版嵁"; + + string mainUrl = Application.StartupPath; public FrmWin() { InitializeComponent(); + //this.KeyPreview = true; + //this.KeyDown += FrmWin_KeyDown; this.Load += FrmWeb_Load; - this.FormClosed += FrmWin_FormClosed; + this.FormClosing += FrmWin_FormClosing; + + timer = new System.Timers.Timer(1000); + timer.Elapsed += timer_Elapsed; + } + + void timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e) + { + MoveWinPosition("MeshLayerTool", 583, 304); + } + + void FrmWin_KeyDown(object sender, KeyEventArgs e) + { + if (e.Modifiers == Keys.Control && e.KeyCode == Keys.F1) + { + MoveWinPosition("MeshLayerTool", 400, 400); + } } void FrmWeb_Load(object sender, EventArgs e) @@ -37,36 +82,37 @@ try { LogOut.Info("寮�濮嬭繍琛�.."); - mainUrl = Application.StartupPath.Replace("\\", "/"); + bool isTest = "1" == ConfigurationManager.AppSettings["isTest"]; - string fly = Path.Combine(Application.StartupPath, "Resources\\sample.fly"); - if (!File.Exists(fly)) + this.fly = getFly(); + /*this.fly = ConfigurationManager.AppSettings["fly"] ?? ConfigurationManager.AppSettings["testFly"]; + if (!this.fly.Contains(":\\")) this.fly = Path.Combine(Application.StartupPath, this.fly); + if (!File.Exists(this.fly)) { - LogOut.Error("Fly鏂囦欢涓嶅瓨鍦細" + fly); + LogOut.Error("Fly鏂囦欢涓嶅瓨鍦細" + this.fly); return; - } + }*/ - SG = new SGWorld74(); + SG = new SGWorld71(); SG.OnLoadFinished += SG_OnLoadFinished; - SG.Open(fly); tree = new FrmTree(); tree.Show(this); - string isTest = ConfigurationManager.AppSettings["isTest"]; - if ("1".Equals(isTest)) + if (isTest) { - this.FormBorderStyle = FormBorderStyle.FixedSingle; - tree.FormBorderStyle = FormBorderStyle.FixedSingle; + this.FormBorderStyle = FormBorderStyle.Sizable; + tree.FormBorderStyle = FormBorderStyle.Sizable; tool = new FrmTool(this); tool.Show(); - } - else - { - this.WindowState = FormWindowState.Maximized; - tree.WindowState = FormWindowState.Maximized; - } + //SG.Open(this.fly); + } + //else + //{ + // this.WindowState = FormWindowState.Maximized; + // tree.WindowState = FormWindowState.Maximized; + //} } catch (Exception ex) { @@ -76,79 +122,39 @@ void SG_OnLoadFinished(bool bSuccess) { - // + try + { + //this.SG.OnLoadFinished -= SG_OnLoadFinished; + + string id = this.SG.ProjectTree.FindItem(startName); + if (string.IsNullOrEmpty(id)) return; + + var obj = this.SG.ProjectTree.GetObject(id); + if (obj.ObjectType == ObjectTypeCode.OT_LOCATION) + { + this.SG.Navigate.FlyTo(id); + } + } + catch { } } - void FrmWin_FormClosed(object sender, FormClosedEventArgs e) + void FrmWin_FormClosing(object sender, FormClosingEventArgs e) { + ExecCmd(new List<string> { "taskkill /f /t /im OSGBLab.exe" }); + ExecCmd(new List<string> { "taskkill /f /t /im MeshLayerTool.exe" }); LogOut.Info("鍏抽棴绋嬪簭."); } + #endregion + #region invoke protected override void DefWndProc(ref Message m) { switch (m.Msg) { - case 0xc0: // 閲嶇疆榧犳爣妯″紡 - SG.Window.SetInputMode(0); break; - case 0xc1: // 鎵撳紑鏁版嵁鏂规/鎵撳紑鏄剧ず鍦烘櫙 - SG.Command.Execute(1001, null); break; - case 0xc2: // 淇濆瓨鏁版嵁鏂规/淇濆瓨鏄剧ず鍦烘櫙 - SG.Command.Execute(1003, null); break; - case 0xc3: // 鐭㈤噺鏁版嵁(榛樿涓�*.shp锛屾敮鎸丒xcel) - SG.Command.Execute(1013, 5); break; - case 0xc4: // 褰卞儚鏁版嵁(榛樿涓�*.tif) - SG.Command.Execute(1014, 9); break; - case 0xc5: // 鍦板舰鏁版嵁(榛樿涓�*.tif) - SG.Command.Execute(1014, 26); break; - case 0xc6: // 妯″瀷鏁版嵁(*.osgb) - ExecCmd(new List<string> { "taskkill /f /t /im MeshLayerTool.exe" }); // SG.Command.Execute(2342, null); - RunExe(Path.Combine(ConfigurationManager.AppSettings["tePath"], "MeshLayerTool.exe"), " -RunApp TerraExplorer -RunConvertor -Mode ImportMeshLayer -Type osgb", false); - break; - case 0xc7: // 妯″瀷鏁版嵁(*.obj) - SG.Command.Execute(1012, 13); break; - case 0xc8: // 鍩虹缂栬緫(閫夋嫨瀵硅薄锛屽紑鍚紪杈�) - SG.Command.Execute(1021, null); break; - case 0xc9: // 鐐归噺绠�(鍧愭爣+楂樼▼) - SG.Command.Execute(1023, null); break; - case 0xca: // 鐐归噺绠�(鍧″害+鍧″悜) - // - break; - case 0xcb: // 绾块噺绠� - SG.Command.Execute(2356, null); break; - case 0xcc: // 闈㈤噺绠� - if (SG.Command.IsChecked(2359, null)) - SG.Window.SetInputMode(0); - else - SG.Command.Execute(2359, null); - break; - case 0xcd: // 浣撻噺绠�(鎸栧~鏂�) - - break; - case 0xce: // 瑙掗噺绠� - - break; - case 0xcf: // 绌洪棿缁熻 - - break; - case 0xd0: // 绌洪棿鍒嗘瀽 - - break; - case 0xd1: // DEM鍒嗘瀽(鍓栭潰鍒嗘瀽) - - break; - case 0xd2: // DEM鍒嗘瀽(鍧″害鍒嗘瀽) - - break; - case 0xd3: // DEM鍒嗘瀽(绛夊�肩嚎) - - break; - case 0xd4: // 涓夌淮妯″瀷鍒嗘瀽(鍓栭潰鍒嗘瀽+鍓栧垏鍒嗘瀽) - - break; - case 0xd5: // 鍦扮悊鍦烘櫙浜у搧缁勮(鎶藉彇鎸囧畾鍖哄煙骞跺彂甯冪绾挎暟鎹寘) - SG.Command.Execute(1028, null); break; - case 0xd6: // 浼犵粺4D浜у搧娲剧敓(闆嗘垚osgblab) - InvokeOsgbLab(); break; + case 0x64: + InvokeByCode(m.WParam.ToInt32()); break; + case 0x4A: + MessageBox.Show("Test."); break; default: base.DefWndProc(ref m); break; } @@ -157,19 +163,296 @@ public void InvokeProc(int code) { Message m = new Message(); - m.Msg = code; + m.Msg = 0x64; // m.Msg = 0x4A; + m.WParam = new IntPtr(code); this.DefWndProc(ref m); } - public void RunExe(string path, string args, bool noWindow = true) + public void InvokeByCode(int code) + { + LogOut.Info("InvokeByCode > 0x" + code.ToString("x")); + switch (code) + { + case 0xc0: // 閲嶇疆榧犳爣妯″紡 + SG.Window.SetInputMode(0); break; + case 0xc1: // 鎵撳紑鏁版嵁鏂规/鎵撳紑鏄剧ず鍦烘櫙 + SG.Command.Execute(1001, null); break; + case 0xc2: // 淇濆瓨鏁版嵁鏂规/淇濆瓨鏄剧ず鍦烘櫙 + Save(); break; + case 0xc3: // 鐭㈤噺鏁版嵁(榛樿涓�*.shp锛屾敮鎸丒xcel) + SG.Command.Execute(1013, 5); break; + case 0xc4: // 褰卞儚鏁版嵁(榛樿涓�*.tif) + SG.Command.Execute(1014, 9); break; + case 0xc5: // 鍦板舰鏁版嵁(榛樿涓�*.tif) + SG.Command.Execute(1014, 26); break; + case 0xc6: // 妯″瀷鏁版嵁(*.osgb) + ExportOsgb(); break; + case 0xc7: // 妯″瀷鏁版嵁(*.obj) + SG.Command.Execute(1012, 13); break; + case 0xc8: // 缂栬緫鏁版嵁(閫夋嫨瀵硅薄锛屽紑鍚紪杈�) + SG.Command.Execute(1021, null); break; + case 0xc9: // 鐐归噺绠�(鍧愭爣+楂樼▼) + SG.Command.Execute(1023, null); break; + case 0xca: // 鐐归噺绠�(鍧″害+鍧″悜) + this.ShowHtmlByid(1149, 24); break; + case 0xcb: // 绾块噺绠� + this.ShowHtmlByid(1034, 0); break; // SG.Command.Execute(2356, null); break; + case 0xcc: // 闈㈤噺绠� + // if (SG.Command.IsChecked(2359, null)) SG.Window.SetInputMode(0); else SG.Command.Execute(2359, null); break; + this.ShowHtmlByid(1037, 0); break; + case 0xcd: // 浣撻噺绠�(鎸栧~鏂�) + this.ShowHtmlByid(1045, 0); break; + case 0xce: // 瑙掗噺绠� + AngleMeasurement(); break; + case 0xcf: // 绌洪棿缁熻 + SpaceStatistics(); break; + case 0xd0: // 绌洪棿鍒嗘瀽 + SpatialAnalysis(); break; + case 0xd1: // DEM鍒嗘瀽(鍓栭潰鍒嗘瀽) + this.ShowHtmlByid(1149, 28); break; + case 0xd2: // DEM鍒嗘瀽(鍧″害鍒嗘瀽) + this.ShowHtmlByid(1093, 0); break; + case 0xd3: // DEM鍒嗘瀽(绛夊�肩嚎) + SG.Command.Execute(1039, null); break; + case 0xd4: // 涓夌淮妯″瀷鍒嗘瀽(鍓栧垏鍒嗘瀽) + this.ShowHtmlByid(1149, 39); break; + case 0xd5: // 鍦扮悊鍦烘櫙浜у搧缁勮(鎶藉彇鎸囧畾鍖哄煙骞跺彂甯冪绾挎暟鎹寘) + SG.Command.Execute(1028, null); break; + case 0xd6: // 浼犵粺4D浜у搧娲剧敓(闆嗘垚osgblab) + InvokeOsgbLab(); break; + case 0xd7: // 鎵撳紑fly + SG.Open(this.fly); break; + case 0xd8: // 鍔犺浇shp + LoadShp(); break; + case 0xd9: // 璇诲彇shp + ReadShp(); break; + case 0xda: // 鎸夌収灞炴�ф樉绀� + DisplayByAttribute(0, "鎸夌収灞炴�ф樉绀�"); break; + case 0xdb: // 鎸夌収灞炴�ц缃鑹� + DisplayByAttribute(1, "鎸夌収灞炴�ц缃鑹�"); break; + case 0xdc: // 鎵撳紑鏁版嵁鏂规 + Open(); break; + case 0xdd: // 鍙﹀瓨涓� + SaveAs(); break; + case 0xde: // 閫夋嫨瀵硅薄 + SG.Command.Execute(1021, 0); break; + case 0xdf: // 瀵煎嚭妯″瀷(鍏跺畠) + ExportOther(); break; + case 0xe0: // 鍒锋柊鍥惧眰 + SG.Command.Execute(1087, 0); break; + case 0xe1: // 淇濆瓨鍥惧眰 + SG.Command.Execute(1088, 0); break; + case 0xe2: // 澶嶅埗 + SG.Command.Execute(1031, 0); break; + case 0xe3: // 鍓垏 + SG.Command.Execute(1032, 0); break; + case 0xe4: // 鍒犻櫎 + SG.Command.Execute(1033, 0); break; + case 0xe5: // 绮樿创鑷冲睆骞曚腑蹇� + SG.Command.Execute(1030, 0); break; + } + } + + private void ExportOsgb() + { + ExecCmd(new List<string> { "taskkill /f /t /im MeshLayerTool.exe" }); // SG.Command.Execute(2342, null); + //RunExe(Path.Combine(ConfigurationManager.AppSettings["tePath"], "MeshLayerTool.exe"), " -RunConvertor -Mode ImportMeshLayer -Type osgb", false); // -RunApp TerraExplorer + RunExe(Path.Combine(ConfigurationManager.AppSettings["tePath"], "MeshLayerTool.exe"), " -RunApp TerraExplorer -RunConvertor -Mode ImportMeshLayer -Type osgb", false); // -RunApp TerraExplorer + timer.Stop(); + timer.Start(); + } + + private void ExportOther() + { + ExecCmd(new List<string> { "taskkill /f /t /im MeshLayerTool.exe" }); + //RunExe(Path.Combine(ConfigurationManager.AppSettings["tePath"], "slmeshconverter.exe"), " -cmd convert -in \"D:/SEM/osgb/xizhan.3dml\" -f 3dml -out \"C:/Export.3dml\" -vdat convert_z -wktout -ui 1", false); + RunExe(Path.Combine(ConfigurationManager.AppSettings["tePath"], "MeshLayerTool.exe"), " -RunApp TerraExplorer -RunConvertor -Mode ExportMeshLayer", false); + timer.Stop(); + timer.Start(); + } + #endregion + + #region user32.dll + public const int SWP_NOSIZE = 0x0001; + + public const int SWP_NOMOVE = 0x0002; + + public const int SWP_NOZORDER = 0x0004; + + public const int SWP_SHOWWINDOW = 0x0040; + + public const int HWND_TOPMOST = -1; + + public const int HWND_NOTOPMOST = -2; + + [DllImport("user32.dll", SetLastError = true)] + [return: MarshalAs(UnmanagedType.Bool)] + static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, uint uFlags); + + [DllImport("user32.dll", SetLastError = true)] + static extern bool GetWindowRect(IntPtr hWnd, out RECT lpRect); + + [Serializable] + [StructLayout(LayoutKind.Sequential)] + public struct RECT + { + public int Left; + public int Top; + public int Right; + public int Bottom; + } + + public void MoveWinPosition(String name, int left, int right) + { + Process[] processes = Process.GetProcessesByName(name); + if (processes.Length > 0) + { + Process process = processes[0]; + IntPtr hWnd = process.MainWindowHandle; + + // 鑾峰彇绐椾綋鐨勫潗鏍� + RECT rect; + GetWindowRect(hWnd, out rect); + + if (rect.Left < 0 || rect.Left > 1920 || rect.Top < 0 || rect.Top > 1080) + { + timer.Stop(); + // 绉诲姩绐楀彛鍒板睆骞曚笂鐨勪綅缃�: + SetWindowPos(hWnd, IntPtr.Zero, left, right, 0, 0, SWP_NOSIZE | SWP_SHOWWINDOW); + } + } + } + #endregion + + #region OSGBLab + const int GCLP_HICON = -14; + const int ICON_SMALL = 0; + const int ICON_BIG = 1; + + [DllImport("user32.dll", SetLastError = true)] + static extern IntPtr FindWindow(string lpClassName, string lpWindowsName); + + [DllImport("user32.dll", SetLastError = true)] + public static extern IntPtr FindWindowEx(IntPtr hWndParent, IntPtr hWndChildAfter, string lpszClass, string lpszWindow); + + [DllImport("user32.dll", SetLastError = true)] + static extern bool SetWindowText(IntPtr hWnd, String lpString); + + [DllImport("user32.dll", SetLastError = true)] + public static extern IntPtr SetClassLongPtr(IntPtr hWnd, int nIndex, IntPtr dwNewLong); + + public void DealOsgbLab() + { + /*Process[] processes = Process.GetProcessesByName("OSGBLab"); + if (processes.Length > 0) + { + IntPtr hWnd = processes[0].MainWindowHandle; + SetWindowText(hWnd, "OSGB鏁版嵁澶勭悊宸ュ叿"); + }*/ + + IntPtr hWnd = FindWindow(null, "OSGBLab(鍊炬枩浼翠荆) (Windows) 鍏嶈垂鐗�"); + if (hWnd == IntPtr.Zero) return; + + DealOsgbLab(hWnd); + } + + public void DealOsgbLab(Process p) + { + do + { + if (p.MainWindowHandle != IntPtr.Zero) + { + DealOsgbLab(p.MainWindowHandle); + break; + } + + Thread.Sleep(50); + } while (true); + } + + [DllImport("user32.dll", EntryPoint = "SetClassLongPtr", SetLastError = true)] + static extern IntPtr SetClassLongPtr64(IntPtr hWnd, int nIndex, IntPtr dwNewLong); + + [DllImport("user32.dll", EntryPoint = "SetClassLong", SetLastError = true)] + static extern int SetClassLong32(IntPtr hWnd, int nIndex, int dwNewLong); + + [DllImport("user32.dll")] + static extern IntPtr LoadIcon(IntPtr hInstance, IntPtr iconName); + + [DllImport("user32.dll")] + [return: MarshalAs(UnmanagedType.Bool)] + static extern bool ShowWindow(IntPtr hWnd, int nCmdShow); + + public void DealOsgbLab(IntPtr hWnd) + { + //ShowWindow(hWnd, 0); // 5 + SetWindowText(hWnd, ConfigurationManager.AppSettings["osgbLabTitle"]); + + Icon icon = new Icon(Path.Combine(mainUrl, @"Resources\favicon.ico")); + SetClassLongPtr(hWnd, GCLP_HICON, icon.Handle); + //SetClassLongPtr(hWnd, GCLP_HICON + ICON_BIG, icon.Handle); + } + #endregion + + #region ShowHtml+RunExe + public void ShowHtmlByid(int id, int arg) + { + switch (id) + { + case 1034: + this.ShowHtml("璺濈娴嬮噺", mainUrl + @"\Resources\DistanceMeasurement\distanceMeasurement.html", 20, 20, 400, 275); + break; + case 1037: + this.ShowHtml("闈㈢Н娴嬮噺", mainUrl + @"/Resources\AreaMeasurement\AreaMeasurement.html", 20, 20, 400, 205); + break; + case 1149: + switch (arg) + { + case 24: + this.ShowHtml("鍧″悜鍒嗘瀽", mainUrl + @"\Resources\SlopeCursor\SlopeCursor.html", 20, 20, 400, 330); break; + case 28: + this.ShowHtml("鍓栭潰鍒嗘瀽", mainUrl + @"\Resources\TerrainProfile\TerrainProfile.html", 20, 20, 400, 265); break; + case 39: + this.ShowHtml("鍓栧垏鍒嗘瀽", mainUrl + @"\Resources\CrossSection\CrossSection.html", 20, 20, 400, 225); break; + } + break; + case 1093: + this.ShowHtml("鍧″害鍒嗘瀽", mainUrl + @"\Resources\SlopeMapQuery\SlopeMapQuery.html", 20, 20, 350, 365); + break; + case 1045: + this.ShowHtml("浣撶Н鍒嗘瀽", mainUrl + @"\Resources\Volume\Volume.html", 20, 20, 350, 225); + break; + } + } + + public void ShowHtml(string tile, string url, int left, int top, int width, int height) + { + if (SG.Window.GetPopupByCaption(tile) != null) + { + SG.Window.RemovePopupByCaption(tile); + } + + var popup = SG.Creator.CreatePopupMessage(tile, url, left, top, width, height); + popup.AllowResize = true; + popup.ShowCaption = true; + popup.AllowDrag = true; + popup.Width = width; + popup.Height = height; + + SG.Window.ShowPopup(popup); + } + + public Process RunExe(string path, string args, bool noWindow = true) { Process p = new Process(); p.StartInfo.FileName = path; - p.StartInfo.Arguments = args; + if (!string.IsNullOrEmpty(args)) p.StartInfo.Arguments = args; p.StartInfo.CreateNoWindow = noWindow; p.StartInfo.UseShellExecute = false; p.Start(); + + return p; } public static string ExecCmd(List<string> list) @@ -217,52 +500,501 @@ return str; } + #endregion - public void InvokeOsgbLab() + #region 瑙掗噺绠� + private void AngleMeasurement() { + if (isAngle) + { + DeleteGroup(angleGroupName); + RmAngleEvent(); + isAngle = false; + return; + } + isAngle = true; + AddAngleEvent(); } - public void ShowHtmlByid(int id, int arg) + private string GetGroupId(string groupName) { - switch (id) + string gid = SG.ProjectTree.FindItem(groupName); + if (!string.IsNullOrEmpty(gid)) return gid; + + return SG.ProjectTree.CreateLockedGroup(groupName); + } + + private void DeleteGroup(string groupName) + { + try { - case 1034: - this.ShowHtml("璺濈娴嬮噺", mainUrl + "/Resources/DistanceMeasurement/distanceMeasurement.html", 20, 20, 400, 245); - break; - case 1037: - this.ShowHtml("闈㈢Н娴嬮噺", mainUrl + "/Resources/AreaMeasurement/AreaMeasurement.html", 20, 20, 400, 245); - break; - case 1149: - if (28 == arg) - this.ShowHtml("鍓栭潰鍒嗘瀽", mainUrl + "/Resources/TerrainProfile/TerrainProfile.html", 20, 20, 400, 290); - else - this.ShowHtml("鍓栧垏鍒嗘瀽", mainUrl + "/Resources/CrossSection/CrossSection.html", 20, 20, 400, 225); - break; - case 1093: - this.ShowHtml("鍧″害鍒嗘瀽", mainUrl + "/Resources/SlopeMapQuery/SlopeMapQuery.html", 20, 20, 350, 365); - break; - case 1045: - this.ShowHtml("浣撶Н鍒嗘瀽", mainUrl + "/Resources/Volume/Volume.html", 20, 20, 350, 225); - break; + string gid = SG.ProjectTree.FindItem(groupName); + if (!string.IsNullOrEmpty(gid)) + { + SG.ProjectTree.DeleteItem(gid); + } + } + catch (Exception ex) + { + LogOut.Error(ex.Message + "\r\n" + ex.StackTrace); } } - public void ShowHtml(string tile, string url, int left, int top, int width, int height) + private void AddAngleEvent() { - if (SG.Window.GetPopupByCaption(tile) != null) + RmAngleEvent(); + + SG.OnFrame += Angle_OnFrame; + SG.OnLButtonDown += Angle_OnLButtonDown; + SG.OnRButtonUp += Angle_OnRButtonUp; + SG.Window.SetInputMode(MouseInputMode.MI_COM_CLIENT); + } + + private void RmAngleEvent() + { + SG.OnFrame -= Angle_OnFrame; + SG.OnLButtonDown -= Angle_OnLButtonDown; + SG.OnRButtonUp -= Angle_OnRButtonUp; + SG.Window.SetInputMode(MouseInputMode.MI_FREE_FLIGHT); + } + + void Angle_OnFrame() + { + if (null == angleLine) return; + + try { - SG.Window.RemovePopupByCaption(tile); + var mouseInfo = SG.Window.GetMouseInfo(); + var CursorCoord = SG.Window.PixelToWorld(mouseInfo.X, mouseInfo.Y, WorldPointType.WPT_DEFAULT); + if (CursorCoord == null) return; + + ILineString line = (ILineString)(angleLine.Geometry); + IPoint p = (IPoint)line.Points[line.Points.Count - 1]; + p.X = CursorCoord.Position.X; + p.Y = CursorCoord.Position.Y; + p.Z = 0; + + if (angleCount % 3 == 2) + { + IPoint p1 = (IPoint)line.Points[0]; + IPoint p2 = (IPoint)line.Points[1]; + IPoint p3 = (IPoint)line.Points[2]; + var pos1 = SG.Creator.CreatePosition(p1.X, p1.Y); + var pos2 = SG.Creator.CreatePosition(p2.X, p2.Y); + var pos3 = SG.Creator.CreatePosition(p3.X, p3.Y); + + var first = SG.CoordServices.GetAimingAngles(pos1, pos2); + var sencod = SG.CoordServices.GetAimingAngles(pos2, pos3); + angleSize = getAngle(first, sencod); + angleLabel.Text = angleSize.ToString() + "掳"; + } + } + catch (Exception ex) + { + LogOut.Error(ex.Message + "\r\n" + ex.StackTrace); + } + } + + private double getAngle(IPosition71 first, IPosition71 sencod) + { + /*double angle = 0; + if (sencod.Yaw > first.Yaw) + { + angle = sencod.Yaw - first.Yaw; + if (angle > 180) angle = 360 - sencod.Yaw + first.Yaw; + } + else + { + angle = first.Yaw - sencod.Yaw; + if (angle > 180) angle = 360 + sencod.Yaw - first.Yaw; + }*/ + + double angle = sencod.Yaw > first.Yaw ? sencod.Yaw - first.Yaw : first.Yaw - sencod.Yaw; + + return Math.Round(angle, 2); + } + + bool Angle_OnLButtonDown(int Flags, int X, int Y) + { + try + { + var CursorCoord = SG.Window.PixelToWorld(X, Y, WorldPointType.WPT_DEFAULT); + if (CursorCoord == null) return false; + + var gid = GetGroupId(angleGroupName); + if (angleLine == null) + { + angleLine = CreateLine(CursorCoord.Position, gid); + angleLine.Geometry.StartEdit(); + angleCount++; + + return true; + } + + ILineString line = (ILineString)(angleLine.Geometry); + if (angleCount % 3 == 1) + { + angleLabel = CreateLabel(CursorCoord.Position, gid, "#FFFF00"); + + IPoint firstPoint = (IPoint)line.Points[0]; + IPoint secondPoint = (IPoint)line.Points[1]; + var firstPos = SG.Creator.CreatePosition(firstPoint.X, firstPoint.Y); + var secondPos = SG.Creator.CreatePosition(secondPoint.X, secondPoint.Y); + + aLabel = CreateLabel(firstPos, gid, "#00FFFF"); + aLabel.Text = Math.Round(SG.CoordServices.GetAimingAngles(firstPos, secondPos).Yaw, 2) + "掳"; + } + + if (angleCount % 3 == 2) + { + IPoint secondPoint = (IPoint)line.Points[line.Points.Count - 2]; + IPoint nowPoint = (IPoint)line.Points[line.Points.Count - 1]; + var secondPos = SG.Creator.CreatePosition(secondPoint.X, secondPoint.Y); + var newPos = SG.Creator.CreatePosition(nowPoint.X, nowPoint.Y); + + bLabel = CreateLabel(newPos, GetGroupId(angleGroupName), "#00FFFF"); + bLabel.Text = Math.Round(SG.CoordServices.GetAimingAngles(secondPos, newPos).Yaw, 2) + "掳"; + + angleLabel.Text = angleSize.ToString() + "掳"; + } + angleCount++; + + IPoint p = (IPoint)line.Points[line.Points.Count - 1]; + p.X = CursorCoord.Position.X; ; + p.Y = CursorCoord.Position.Y; + p.Z = 0; + line.Points.AddPoint(CursorCoord.Position.X, CursorCoord.Position.Y, 0); + if (angleCount == 3) + { + angleSize = 0; + angleCount = 0; + angleLine = null; + angleLabel = null; + aLabel = null; + bLabel = null; + } + } + catch (Exception ex) + { + LogOut.Error(ex.Message + "\r\n" + ex.StackTrace); } - var popup = SG.Creator.CreatePopupMessage(tile, url, left, top, width, height); - popup.AllowResize = true; - popup.ShowCaption = true; - popup.AllowDrag = true; - popup.Width = width; - popup.Height = height; - - SG.Window.ShowPopup(popup); + return true; } + + private ITerrainPolyline71 CreateLine(IPosition71 pos, String gid) + { + IList<double> lineVertex = new List<double>(); + lineVertex.Add(pos.X); + lineVertex.Add(pos.Y); + lineVertex.Add(0); + lineVertex.Add(pos.X); + lineVertex.Add(pos.Y); + lineVertex.Add(0); + + double[] px = new double[lineVertex.Count]; + lineVertex.CopyTo(px, 0); + var myGeometry = SG.Creator.GeometryCreator.CreateLineStringGeometry(px); + + var line = SG.Creator.CreatePolyline(myGeometry, SG.Creator.CreateColor(255, 255, 0, 255), AltitudeTypeCode.ATC_TERRAIN_RELATIVE, gid, angleCount.ToString()); + line.LineStyle.Width = -2; + + return line; + } + + private ITerrainLabel71 CreateLabel(IPosition71 pos, String gid, String color) + { + var lableColor = SG.Creator.CreateColor(); + lableColor.FromHTMLColor(color); + lableColor.SetAlpha(0.6); + + var label = SG.Creator.CreateLabel(pos, "0", "", null, gid, ""); + label.Style.TextColor = lableColor; + label.Style.Bold = true; + label.Style.FontName = "榛戜綋"; + label.Style.FontSize = 12; + // label.Style.LineToGround = true; + label.Style.LineToGroundType = LineType.LINE_TYPE_TO_GROUND; + label.Style.Scale = 5000; + + return label; + } + + bool Angle_OnRButtonUp(int Flags, int X, int Y) + { + DeleteGroup(angleGroupName); + RmAngleEvent(); + angleCount = 0; + angleSize = 0; + isAngle = false; + + return true; + } + #endregion + + #region 璋冪敤Html + private string GetAbsolutePath(string key) + { + string str = ConfigurationManager.AppSettings[key]; + + return str.Contains(":\\") ? str : Path.Combine(Application.StartupPath, str); + } + + private void SpaceStatistics() + { + this.ShowHtml("绌洪棿缁熻", mainUrl + @"\Resources\SpaceStatistics\SpaceStatistics.html", 20, 20, 420, 305); + } + + private void SpatialAnalysis() + { + this.ShowHtml("绌洪棿鍒嗘瀽", mainUrl + @"\Resources\SpatialQuery\SpatialQuery.html", 20, 20, 420, 285); + } + + private void InvokeOsgbLab() + { + ExecCmd(new List<string> { "taskkill /f /t /im OSGBLab.exe" }); + Process p = RunExe(GetAbsolutePath("osgblabPath"), null, false); + DealOsgbLab(p); + } + + private void DisplayByAttribute(int type, String name) + { + this.ShowHtml(name, mainUrl + @"\Resources\DisplayByAttribute\DisplayByAttribute.html?Type=" + type + "&lang=2052", 20, 20, 365, 355); + } + #endregion + + #region 鍔犺浇shp + 璇诲彇shp + private void LoadShp() + { + OpenFileDialog dialog = new OpenFileDialog(); + dialog.Filter = "Shapefile鏂囦欢 (*.shp)|*.shp"; + dialog.RestoreDirectory = true; + + if (dialog.ShowDialog() == DialogResult.OK) + { + string shpFile = dialog.FileName; + if (LoadShp(shpFile)) + { + sendShpFile(shpFile); + } + } + } + + private bool LoadShp(string shpFile) + { + try + { + string gid = GetGroupIdByName(shpGroupName); + string conn = "FileName=" + shpFile + ";TEPlugName=OGR;"; // 杩炴帴瀛楃涓� + string shpName = Path.GetFileNameWithoutExtension(shpFile); + + IFeatureLayer71 layer = SG.Creator.CreateFeatureLayer(shpName, conn, gid); // 鍔犺浇shp + layer.Refresh(); + SG.Navigate.FlyTo(layer.ID); + + return true; + } + catch (Exception ex) + { + LogOut.Error(ex.Message + "\r\n" + ex.StackTrace); + return false; + } + } + + private string GetGroupIdByName(string groupName) + { + string gid = SG.ProjectTree.FindItem(groupName); + if (string.IsNullOrEmpty(gid) || !SG.ProjectTree.IsGroup(gid)) + { + gid = SG.ProjectTree.CreateGroup(groupName, SG.ProjectTree.RootID); + } + + return gid; + } + + private void sendShpFile(string shpFile) + { + try + { + string shpTxtPath = GetShpTxtPath(); + using (StreamWriter sw = new StreamWriter(shpTxtPath, false)) + { + sw.Write(shpFile.Replace("\\", "/")); + } + } + catch (Exception ex) + { + LogOut.Error(ex.Message + "\r\n" + ex.StackTrace); + } + } + + private void ReadShp() + { + try + { + string shpTxtPath = GetShpTxtPath(); + if (string.IsNullOrEmpty(shpTxtPath) || !File.Exists(shpTxtPath)) + { + return; + } + + string shpFile = File.ReadAllText(shpTxtPath); + if (string.IsNullOrEmpty(shpFile) || !shpFile.ToLower().EndsWith(".shp") || !File.Exists(shpFile)) + { + return; + } + + LoadShp(shpFile); + File.Delete(shpTxtPath); + } + catch (Exception ex) + { + LogOut.Error(ex.Message + "\r\n" + ex.StackTrace); + } + } + + private string GetShpTxtPath() + { + string shpTxtPath = ConfigurationManager.AppSettings["shpTxtPath"]; + if (!shpTxtPath.Contains(":\\")) + { + shpTxtPath = Path.Combine(Application.StartupPath, shpTxtPath); + } + + return shpTxtPath; + } + #endregion + + #region 鏂规绠$悊 + private void Save() + { + string emptyFly = Path.Combine(Application.StartupPath, "Resources", "empty.fly"); + if (emptyFly.Equals(this.fly)) + { + SaveAs(); + return; + } + + SaveLocation(); + this.SG.Command.Execute(1019, 0); // Capture Tree State + SG.Command.Execute(1003, 0); // this.SG.Project.Save(); // + } + + private void SaveLocation() + { + try + { + string id = this.SG.ProjectTree.FindItem(startName); + if (!string.IsNullOrEmpty(id)) this.SG.ProjectTree.DeleteItem(id); + + var pos = this.SG.Navigate.GetPosition(); + var loc = this.SG.Creator.CreateLocationHere(this.SG.ProjectTree.RootID, startName); + } + catch (Exception ex) + { + LogOut.Error(ex.Message + "\r\n" + ex.StackTrace); + } + } + + private void Open() + { + this.fly = getFly(); + this.SG.Open(this.fly); + } + + private String getFly() + { + string flyPath = ReadPrjPath(); + if (String.IsNullOrEmpty(flyPath)) flyPath = "empty.fly"; + if (!flyPath.Contains(":\\")) flyPath = Path.Combine(Application.StartupPath, "Resources", flyPath); + + return flyPath; + } + + private String ReadPrjPath() + { + try + { + String txt = Path.Combine(mainUrl, "Resources", "fly.txt"); + if (!File.Exists(txt)) return null; + + using (StreamReader sr = new StreamReader(txt)) + { + return sr.ReadLine(); + } + } + catch (Exception ex) + { + LogOut.Error(ex.Message + "\r\n" + ex.StackTrace); + return null; + } + } + + private void SaveAs() + { + string flyPath = ReadPrjPath(); + string fileName = String.IsNullOrEmpty(flyPath) ? null : Path.GetFileName(flyPath); + + string dest = SaveAs(fileName); + if (string.IsNullOrEmpty(dest)) return; + + this.fly = dest; + string sourcePath = Path.Combine(mainUrl, "Resources"); + if (string.IsNullOrEmpty(flyPath) || (dest.Contains(sourcePath) && dest.IndexOf("\\", sourcePath.Length + 1) == -1)) return; + + CreateShortcut(flyPath, this.fly); + //ExecCmd(new List<string> { string.Format("mklink \"{0}\" \"{1}\"", flyPath, this.fly) }); + } + + private String SaveAs(String fileName) + { + try + { + if (String.IsNullOrEmpty(fileName)) fileName = DateTime.Now.ToString("yyyyMMddHHmmss") + ".fly"; + + SaveLocation(); + this.SG.Command.Execute(1019, 0); // Capture Tree State + this.SG.Project.SaveAs(fileName); + + string source = Path.Combine(GetSavePath(), fileName); + if (!File.Exists(source)) + { + LogOut.Error(fileName + "锛屾壘涓嶅埌"); + } + + string dest = Path.Combine(Application.StartupPath, "Resources", fileName); + if (File.Exists(dest)) File.Delete(dest); + File.Move(source, dest); + + return dest; + } + catch (Exception ex) + { + LogOut.Error(ex.Message + "\r\n" + ex.StackTrace); + return null; + } + } + + private String GetSavePath() + { + string appData = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData); + string tePathName = ConfigurationManager.AppSettings["tePath"].Contains("SmartEarth") ? "SmartEarth" : "Skyline"; + + return Path.Combine(appData, tePathName, "TerraExplorer"); + } + + public static void CreateShortcut(string shortcutPath, string targetPath, string description = null, string iconLocation = null) + { + var shell = new IWshRuntimeLibrary.WshShell(); + var shortcut = (IWshRuntimeLibrary.IWshShortcut)shell.CreateShortcut(shortcutPath + ".lnk"); // 鍒涘缓蹇嵎鏂瑰紡瀵硅薄 + shortcut.TargetPath = targetPath; // 鎸囧畾鐩爣璺緞 + shortcut.WorkingDirectory = Path.GetDirectoryName(targetPath); // 璁剧疆璧峰浣嶇疆 + shortcut.WindowStyle = 1; // 璁剧疆杩愯鏂瑰紡锛岄粯璁や负甯歌绐楀彛 + shortcut.Description = description; // 璁剧疆澶囨敞 + shortcut.IconLocation = string.IsNullOrWhiteSpace(iconLocation) ? targetPath : iconLocation; // 璁剧疆鍥炬爣璺緞 + shortcut.Save(); // 淇濆瓨蹇嵎鏂瑰紡 + } + #endregion } } -- Gitblit v1.9.3