From da528e999d6538a12f357b6c745974316d48c086 Mon Sep 17 00:00:00 2001 From: 13693261870 <252740454@qq.com> Date: 星期一, 09 九月 2024 15:27:16 +0800 Subject: [PATCH] 修改初始化fly --- TEWin/FrmWin.cs | 185 +++++++++++++++++++++++++++++++++++++++++++--- 1 files changed, 172 insertions(+), 13 deletions(-) diff --git a/TEWin/FrmWin.cs b/TEWin/FrmWin.cs index a3a45d2..e837577 100644 --- a/TEWin/FrmWin.cs +++ b/TEWin/FrmWin.cs @@ -34,17 +34,19 @@ public SGWorld71 SG; + System.Timers.Timer timer; + ITerrainLabel71 angleLabel; ITerrainPolyline71 angleLine; + + string startName = "OnStart"; string angleGroupName = "瑙掗噺绠�"; string shpGroupName = "鐭㈤噺鏁版嵁"; string mainUrl = Application.StartupPath; - - System.Timers.Timer timer; public FrmWin() { @@ -78,13 +80,14 @@ LogOut.Info("寮�濮嬭繍琛�.."); bool isTest = "1" == ConfigurationManager.AppSettings["isTest"]; - this.fly = ConfigurationManager.AppSettings["fly"] ?? ConfigurationManager.AppSettings["testFly"]; + 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鏂囦欢涓嶅瓨鍦細" + this.fly); return; - } + }*/ SG = new SGWorld71(); SG.OnLoadFinished += SG_OnLoadFinished; @@ -99,7 +102,7 @@ tool = new FrmTool(this); tool.Show(); - SG.Open(this.fly); + //SG.Open(this.fly); } //else //{ @@ -116,12 +119,25 @@ void SG_OnLoadFinished(bool bSuccess) { - this.SG.OnLoadFinished -= SG_OnLoadFinished; + 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_FormClosing(object sender, FormClosingEventArgs e) { - ExecCmd(new List<string> { "taskkill /f /t /im OSGBLab.exe" }); + ExecCmd(new List<string> { "taskkill /f /t /im OSGBLab.exe" }); LogOut.Info("鍏抽棴绋嬪簭."); } #endregion @@ -151,6 +167,7 @@ public void InvokeByCode(int code) { + LogOut.Info("InvokeByCode > 0x" + code.ToString("x")); switch (code) { case 0xc0: // 閲嶇疆榧犳爣妯″紡 @@ -158,7 +175,7 @@ case 0xc1: // 鎵撳紑鏁版嵁鏂规/鎵撳紑鏄剧ず鍦烘櫙 SG.Command.Execute(1001, null); break; case 0xc2: // 淇濆瓨鏁版嵁鏂规/淇濆瓨鏄剧ず鍦烘櫙 - SG.Command.Execute(1003, null); break; + Save(); break; case 0xc3: // 鐭㈤噺鏁版嵁(榛樿涓�*.shp锛屾敮鎸丒xcel) SG.Command.Execute(1013, 5); break; case 0xc4: // 褰卞儚鏁版嵁(榛樿涓�*.tif) @@ -215,6 +232,10 @@ DisplayByAttribute(0, "鎸夌収灞炴�ф樉绀�"); break; case 0xdb: // 鎸夌収灞炴�ц缃鑹� DisplayByAttribute(1, "鎸夌収灞炴�ц缃鑹�"); break; + case 0xdc: // 鎵撳紑鏁版嵁鏂规 + Open(); break; + case 0xdd: // 鍙﹀瓨涓� + SaveAs(); break; } } #endregion @@ -317,13 +338,27 @@ } 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) { - SetWindowText(hWnd, "OSGB鏁版嵁澶勭悊宸ュ叿"); + //ShowWindow(hWnd, 0); // 5 + SetWindowText(hWnd, ConfigurationManager.AppSettings["osgbLabTitle"]); Icon icon = new Icon(Path.Combine(mainUrl, @"Resources\favicon.ico")); - SetClassLongPtr(hWnd, GCLP_HICON + ICON_SMALL, icon.Handle); - SetClassLongPtr(hWnd, GCLP_HICON + ICON_BIG, icon.Handle); + SetClassLongPtr(hWnd, GCLP_HICON, icon.Handle); + //SetClassLongPtr(hWnd, GCLP_HICON + ICON_BIG, icon.Handle); } #endregion @@ -641,8 +676,8 @@ private void InvokeOsgbLab() { ExecCmd(new List<string> { "taskkill /f /t /im OSGBLab.exe" }); - osgbProc = RunExe(GetAbsolutePath("osgblabPath"), null, false); - DealOsgbLab(osgbProc); + Process p = RunExe(GetAbsolutePath("osgblabPath"), null, false); + DealOsgbLab(p); } private void DisplayByAttribute(int type, String name) @@ -752,5 +787,129 @@ return shpTxtPath; } #endregion + + #region 鏂规绠$悊 + private void Save() + { + 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