From ee22df6c94793777fe5b28f2886ebeb2ba2c4256 Mon Sep 17 00:00:00 2001
From: 13693261870 <252740454@qq.com>
Date: 星期一, 02 九月 2024 21:06:36 +0800
Subject: [PATCH] 1

---
 TEWin/FrmWin.cs |  240 +++++++++++++++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 221 insertions(+), 19 deletions(-)

diff --git a/TEWin/FrmWin.cs b/TEWin/FrmWin.cs
index d31a8b4..2a29dc5 100644
--- a/TEWin/FrmWin.cs
+++ b/TEWin/FrmWin.cs
@@ -7,6 +7,7 @@
 using System.Drawing;
 using System.IO;
 using System.Linq;
+using System.Runtime.InteropServices;
 using System.Text;
 using System.Windows.Forms;
 using TerraExplorerX;
@@ -24,27 +25,49 @@
 
         FrmTool tool;
 
-        string mainUrl;
+        bool isAngle;
+
+        int angleCount;
+
+        double angleSize;
 
         public SGWorld71 SG;
 
-        private bool isAngle;
+        ITerrainLabel71 angleLabel;
 
-        private int angleCount;
+        ITerrainPolyline71 angleLine;
 
-        private double angleSize;
+        string angleGroupName = "瑙掗噺绠�";
 
-        private ITerrainLabel71 angleLabel;
+        string shpGroupName = "鐭㈤噺鏁版嵁";
 
-        private ITerrainPolyline71 angleLine;
+        string mainUrl = Application.StartupPath;
 
-        private string angleGroupName = "瑙掗噺绠�";
+        System.Timers.Timer timer;
 
         public FrmWin()
         {
             InitializeComponent();
+            //this.KeyPreview = true;
             this.Load += FrmWeb_Load;
+            //this.KeyDown += FrmWin_KeyDown;
             this.FormClosed += FrmWin_FormClosed;
+
+            timer = new System.Timers.Timer(1500);
+            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)
@@ -52,10 +75,10 @@
             try
             {
                 LogOut.Info("寮�濮嬭繍琛�..");
-                mainUrl = Application.StartupPath;
                 bool isTest = "1" == ConfigurationManager.AppSettings["isTest"];
 
-                this.fly = isTest ? ConfigurationManager.AppSettings["testFly"] : Path.Combine(Application.StartupPath, "Resources\\sample.fly");
+                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);
@@ -141,11 +164,14 @@
                     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"), " -RunConvertor -Mode ImportMeshLayer -Type osgb", false); // -RunApp TerraExplorer
+                    //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();
                     break;
                 case 0xc7: // 妯″瀷鏁版嵁(*.obj)
                     SG.Command.Execute(1012, 13); break;
-                case 0xc8: // 鍩虹缂栬緫(閫夋嫨瀵硅薄锛屽紑鍚紪杈�)
+                case 0xc8: // 缂栬緫鏁版嵁(閫夋嫨瀵硅薄锛屽紑鍚紪杈�)
                     SG.Command.Execute(1021, null); break;
                 case 0xc9: // 鐐归噺绠�(鍧愭爣+楂樼▼)
                     SG.Command.Execute(1023, null); break;
@@ -170,7 +196,7 @@
                     this.ShowHtmlByid(1093, 0); break;
                 case 0xd3: // DEM鍒嗘瀽(绛夊�肩嚎)
                     SG.Command.Execute(1039, null); break;
-                case 0xd4: // 涓夌淮妯″瀷鍒嗘瀽(鍓栭潰鍒嗘瀽+鍓栧垏鍒嗘瀽)
+                case 0xd4: // 涓夌淮妯″瀷鍒嗘瀽(鍓栧垏鍒嗘瀽)
                     this.ShowHtmlByid(1149, 39); break;
                 case 0xd5: // 鍦扮悊鍦烘櫙浜у搧缁勮(鎶藉彇鎸囧畾鍖哄煙骞跺彂甯冪绾挎暟鎹寘)
                     SG.Command.Execute(1028, null); break;
@@ -178,18 +204,84 @@
                     InvokeOsgbLab(); break;
                 case 0xd7: // 鎵撳紑fly
                     SG.Open(this.fly); break;
+                case 0xd8: // 鍔犺浇shp
+                    LoadShp(); break;
+                case 0xd9: // 璇诲彇shp
+                    ReadShp(); break;
             }
         }
+
+        #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);
+                }
+            }
+        }
+
+        public static void Main()
+        {
+            // 鑾峰彇鎸囧畾绐椾綋鐨勫彞鏌�
+            //IntPtr hWnd = // 鑾峰彇绐椾綋鍙ユ焺鐨勬柟娉曪紝渚嬪FindWindow鎴栬�呴�氳繃杩涚▼鍚嶈幏鍙�
+            // 鑾峰彇绐椾綋鐨勫潗鏍�
+            //RECT rect;
+            //GetWindowRect(hWnd, out rect);
+            //Console.WriteLine("绐椾綋鍧愭爣: 宸︿笂瑙�({0}, {1}), 鍙充笅瑙�({2}, {3})", rect.Left, rect.Top, rect.Right, rect.Bottom);
+        }
+        #endregion
 
         public void ShowHtmlByid(int id, int arg)
         {
             switch (id)
             {
                 case 1034:
-                    this.ShowHtml("璺濈娴嬮噺", mainUrl + @"\Resources\DistanceMeasurement\distanceMeasurement.html", 20, 20, 400, 245);
+                    this.ShowHtml("璺濈娴嬮噺", mainUrl + @"\Resources\DistanceMeasurement\distanceMeasurement.html", 20, 20, 400, 275);
                     break;
                 case 1037:
-                    this.ShowHtml("闈㈢Н娴嬮噺", mainUrl + @"/Resources\AreaMeasurement\AreaMeasurement.html", 20, 20, 400, 245);
+                    this.ShowHtml("闈㈢Н娴嬮噺", mainUrl + @"/Resources\AreaMeasurement\AreaMeasurement.html", 20, 20, 400, 205);
                     break;
                 case 1149:
                     switch (arg)
@@ -197,7 +289,7 @@
                         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, 290); break;
+                            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;
                     }
@@ -232,7 +324,7 @@
         {
             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();
@@ -284,7 +376,7 @@
             return str;
         }
 
-        #region 瑙掗噺绠�+绌洪棿缁熻+绌洪棿鍒嗘瀽+osgblab
+        #region 瑙掗噺绠�
         private void AngleMeasurement()
         {
             if (isAngle)
@@ -468,10 +560,18 @@
 
             return true;
         }
+        #endregion
+
+        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, 285);
         }
 
         private void SpatialAnalysis()
@@ -481,7 +581,109 @@
 
         private void InvokeOsgbLab()
         {
-            //
+            ExecCmd(new List<string> { "taskkill /f /t /im OSGBLab.exe" });
+            RunExe(GetAbsolutePath("osgblabPath"), null, false);
+        }
+
+        #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
     }

--
Gitblit v1.9.3