From 596f3ad8d0a3b8d4641df16ba5b17f6a2a5090a7 Mon Sep 17 00:00:00 2001
From: 13693261870 <252740454@qq.com>
Date: 星期二, 03 九月 2024 16:46:42 +0800
Subject: [PATCH] 1

---
 TEWin/FrmWin.cs  |  106 +++++++++++++++++++++++++++++++++++++++++++++++++++--
 TEWin/FrmTool.cs |    2 
 2 files changed, 103 insertions(+), 5 deletions(-)

diff --git a/TEWin/FrmTool.cs b/TEWin/FrmTool.cs
index 62855df..5440f67 100644
--- a/TEWin/FrmTool.cs
+++ b/TEWin/FrmTool.cs
@@ -17,7 +17,7 @@
             "褰卞儚鏁版嵁", "鍦板舰鏁版嵁", "妯″瀷鏁版嵁(osgb)", "妯″瀷鏁版嵁(obj)", "缂栬緫鏁版嵁", "鐐归噺绠�", 
             "鍧″悜鍒嗘瀽", "绾块噺绠�", "闈㈤噺绠�", "浣撻噺绠�", "瑙掗噺绠�", "绌洪棿缁熻", "绌洪棿鍒嗘瀽", 
             "鍓栭潰鍒嗘瀽", "鍧″害鍒嗘瀽", "绛夊�肩嚎", "鍓栧垏鍒嗘瀽", "鍦扮悊鍦烘櫙浜у搧缁勮", "浼犵粺4D浜у搧娲剧敓", 
-            "鎵撳紑fly", "鍔犺浇shp", "璇诲彇shp", "鎸夌収灞炴�ф樉绀�", "鎸夌収灞炴�ц缃鑹�" };
+            "鎵撳紑fly", "鍔犺浇shp", "璇诲彇shp", "鎸夌収灞炴�ф樉绀�", "鎸夌収灞炴�ц缃鑹�", "鎵撳紑鏁版嵁鏂规", "淇濆瓨椤圭洰" };
 
         public FrmTool(FrmWin win)
         {
diff --git a/TEWin/FrmWin.cs b/TEWin/FrmWin.cs
index fff7089..3af8dcd 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()
         {
@@ -116,7 +118,20 @@
 
         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)
@@ -158,7 +173,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 +230,10 @@
                     DisplayByAttribute(0, "鎸夌収灞炴�ф樉绀�"); break;
                 case 0xdb: // 鎸夌収灞炴�ц缃鑹�
                     DisplayByAttribute(1, "鎸夌収灞炴�ц缃鑹�"); break;
+                case 0xdc: // 鎵撳紑鏁版嵁鏂规
+                    OpenPrj(); break;
+                case 0xdd: // 淇濆瓨椤圭洰
+                    SavePrj(); break;
             }
         }
         #endregion
@@ -766,5 +785,84 @@
             return shpTxtPath;
         }
         #endregion
+
+        #region 鏂规绠$悊
+        private void Save()
+        {
+            //SG.Command.Execute(1003, null);
+            SaveLocation();
+            this.SG.Project.Save();
+        }
+
+        private void OpenPrj()
+        {
+            string flyPath = ReadPrjPath();
+            if (String.IsNullOrEmpty(flyPath)) flyPath = Path.Combine(mainUrl, "see.fly");
+
+            if (!File.Exists(flyPath))
+            {
+                flyPath = ConfigurationManager.AppSettings["fly"] ?? ConfigurationManager.AppSettings["testFly"];
+                if (!flyPath.Contains(":\\")) flyPath = Path.Combine(mainUrl, flyPath);
+            }
+
+            this.SG.Open(flyPath);
+        }
+
+        private void SavePrj()
+        {
+            try
+            {
+                string flyPath = ReadPrjPath();
+                if (String.IsNullOrEmpty(flyPath)) flyPath = Path.Combine(mainUrl, "see.fly");
+
+                this.Save();
+                //this.SG.Project.SaveAs(flyPath);
+                if (this.fly.Equals(flyPath)) return;
+                if (File.Exists(flyPath)) File.Delete(flyPath);
+
+                string cmd = string.Format("mklink \"{0}\" \"{1}\"", flyPath, this.fly);
+                ExecCmd(new List<string> { cmd });
+            }
+            catch (Exception ex)
+            {
+                LogOut.Error(ex.Message + "\r\n" + ex.StackTrace);
+            }
+        }
+
+        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 String ReadPrjPath()
+        {
+            String txt = Path.Combine(mainUrl, "fly.txt");
+            if (!File.Exists(txt)) return null;
+
+            try
+            {
+                using (StreamReader sr = new StreamReader(txt))
+                {
+                    return sr.ReadLine();
+                }
+            }
+            catch (Exception ex)
+            {
+                LogOut.Error(ex.Message + "\r\n" + ex.StackTrace);
+                return null;
+            }
+        }
+        #endregion
     }
 }

--
Gitblit v1.9.3