From 85b05ad7bc5ba6d7755957e4c6b1ba10c031c23b Mon Sep 17 00:00:00 2001
From: 13693261870 <252740454@qq.com>
Date: 星期三, 25 九月 2024 10:24:16 +0800
Subject: [PATCH] 1

---
 TEWin/FrmWin.cs |  329 ++++++++++++++++++++++++++++++++++++++----------------
 1 files changed, 230 insertions(+), 99 deletions(-)

diff --git a/TEWin/FrmWin.cs b/TEWin/FrmWin.cs
index a1250e6..f88e9ea 100644
--- a/TEWin/FrmWin.cs
+++ b/TEWin/FrmWin.cs
@@ -38,6 +38,10 @@
 
         ITerrainLabel71 angleLabel;
 
+        ITerrainLabel71 aLabel;
+
+        ITerrainLabel71 bLabel;
+
         ITerrainPolyline71 angleLine;
 
         string startName = "OnStart";
@@ -80,13 +84,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;
@@ -101,14 +106,13 @@
                     tool = new FrmTool(this);
                     tool.Show();
 
-                    SG.Open(this.fly);
+                    //SG.Open(this.fly);
                 }
                 //else
                 //{
                 //    this.WindowState = FormWindowState.Maximized;
                 //    tree.WindowState = FormWindowState.Maximized;
                 //}
-
             }
             catch (Exception ex)
             {
@@ -137,6 +141,7 @@
         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
@@ -182,12 +187,7 @@
                 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"), " -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;
+                    ExportOsgb(); break;
                 case 0xc7: // 妯″瀷鏁版嵁(*.obj)
                     SG.Command.Execute(1012, 13); break;
                 case 0xc8: // 缂栬緫鏁版嵁(閫夋嫨瀵硅薄锛屽紑鍚紪杈�)
@@ -232,10 +232,44 @@
                 case 0xdb: // 鎸夌収灞炴�ц缃鑹�
                     DisplayByAttribute(1, "鎸夌収灞炴�ц缃鑹�"); break;
                 case 0xdc: // 鎵撳紑鏁版嵁鏂规
-                    OpenPrj(); break;
-                case 0xdd: // 淇濆瓨椤圭洰
-                    SavePrj(); break;
+                    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
 
@@ -543,26 +577,16 @@
 
                 if (angleCount % 3 == 2)
                 {
-                    IPoint firstPoint = (IPoint)line.Points[line.Points.Count - 3];
-                    IPoint secondPoint = (IPoint)line.Points[line.Points.Count - 2];
-                    IPoint nowPoint = (IPoint)line.Points[line.Points.Count - 1];
-                    var firstPosition = SG.Creator.CreatePosition(firstPoint.X, firstPoint.Y);
-                    var secondPosition = SG.Creator.CreatePosition(secondPoint.X, secondPoint.Y);
-                    var nowPosition = SG.Creator.CreatePosition(nowPoint.X, nowPoint.Y);
+                    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);
 
-                    nowPosition = SG.CoordServices.GetAimingAngles(nowPosition, secondPosition);
-                    secondPosition = SG.CoordServices.GetAimingAngles(firstPosition, secondPosition);
-                    if (secondPosition.Yaw > nowPosition.Yaw)
-                    {
-                        angleSize = secondPosition.Yaw - nowPosition.Yaw;
-                        if (angleSize > 180) angleSize = 360 - secondPosition.Yaw + nowPosition.Yaw;
-                    }
-                    else
-                    {
-                        angleSize = nowPosition.Yaw - secondPosition.Yaw;
-                        if (angleSize > 180) angleSize = 360 + secondPosition.Yaw - nowPosition.Yaw;
-                    }
-                    angleSize = Math.Round(angleSize, 2);
+                    var first = SG.CoordServices.GetAimingAngles(pos1, pos2);
+                    var sencod = SG.CoordServices.GetAimingAngles(pos2, pos3);
+                    angleSize = getAngle(first, sencod);
                     angleLabel.Text = angleSize.ToString() + "掳";
                 }
             }
@@ -570,6 +594,25 @@
             {
                 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)
@@ -582,45 +625,41 @@
                 var gid = GetGroupId(angleGroupName);
                 if (angleLine == null)
                 {
-                    IList<double> lineVertex = new List<double>();
-                    lineVertex.Add(CursorCoord.Position.X);
-                    lineVertex.Add(CursorCoord.Position.Y);
-                    lineVertex.Add(0);
-                    lineVertex.Add(CursorCoord.Position.X);
-                    lineVertex.Add(CursorCoord.Position.Y);
-                    lineVertex.Add(0);
-
-                    double[] px = new double[lineVertex.Count];
-                    lineVertex.CopyTo(px, 0);
-                    var myGeometry = SG.Creator.GeometryCreator.CreateLineStringGeometry(px);
-
-                    angleLine = SG.Creator.CreatePolyline(myGeometry, SG.Creator.CreateColor(255, 255, 0, 255), AltitudeTypeCode.ATC_TERRAIN_RELATIVE, gid, angleCount.ToString());
-                    angleLine.LineStyle.Width = -2;
+                    angleLine = CreateLine(CursorCoord.Position, gid);
                     angleLine.Geometry.StartEdit();
                     angleCount++;
 
                     return true;
                 }
 
+                ILineString line = (ILineString)(angleLine.Geometry);
                 if (angleCount % 3 == 1)
                 {
-                    angleLabel = SG.Creator.CreateLabel(CursorCoord.Position, angleSize.ToString(), "", null, gid, angleCount.ToString());
-                    var LableColor = SG.Creator.CreateColor();
-                    LableColor.FromHTMLColor("#FFFF00");
-                    LableColor.SetAlpha(0.6);
-                    angleLabel.Style.TextColor = LableColor;
-                    angleLabel.Style.Bold = true;
-                    angleLabel.Style.FontName = "榛戜綋";
-                    angleLabel.Style.FontSize = 12;
-                    // angleLabel.Style.LineToGround = true;
-                    angleLabel.Style.LineToGroundType = LineType.LINE_TYPE_TO_GROUND;
-                    angleLabel.Style.Scale = 5000;
+                    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) angleLabel.Text = angleSize.ToString() + "掳";
+                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++;
 
-                ILineString line = (ILineString)(angleLine.Geometry);
                 IPoint p = (IPoint)line.Points[line.Points.Count - 1];
                 p.X = CursorCoord.Position.X; ;
                 p.Y = CursorCoord.Position.Y;
@@ -632,6 +671,8 @@
                     angleCount = 0;
                     angleLine = null;
                     angleLabel = null;
+                    aLabel = null;
+                    bLabel = null;
                 }
             }
             catch (Exception ex)
@@ -640,6 +681,44 @@
             }
 
             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)
@@ -790,44 +869,16 @@
         #region 鏂规绠$悊
         private void Save()
         {
-            //SG.Command.Execute(1003, null);
+            string emptyFly = Path.Combine(Application.StartupPath, "Resources", "empty.fly");
+            if (emptyFly.Equals(this.fly))
+            {
+                SaveAs();
+                return;
+            }
+
             SaveLocation();
-            this.SG.Project.Save();
-        }
-
-        private void OpenPrj()
-        {
-            string flyPath = ReadPrjPath();
-            if (String.IsNullOrEmpty(flyPath)) flyPath = this.fly; // 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 = this.fly; // 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);
-            }
+            this.SG.Command.Execute(1019, 0); // Capture Tree State
+            SG.Command.Execute(1003, 0); // this.SG.Project.Save(); // 
         }
 
         private void SaveLocation()
@@ -846,13 +897,28 @@
             }
         }
 
+        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()
         {
-            String txt = Path.Combine(mainUrl, "fly.txt");
-            if (!File.Exists(txt)) return null;
-
             try
             {
+                String txt = Path.Combine(mainUrl, "Resources", "fly.txt");
+                if (!File.Exists(txt)) return null;
+
                 using (StreamReader sr = new StreamReader(txt))
                 {
                     return sr.ReadLine();
@@ -864,6 +930,71 @@
                 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