From bf5266dbda0da2af7a35548b7191953fab8f5e06 Mon Sep 17 00:00:00 2001
From: 13693261870 <252740454@qq.com>
Date: 星期四, 04 一月 2024 14:58:44 +0800
Subject: [PATCH] 集成角测量功能

---
 TEWin/FrmWin.cs |  199 ++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 195 insertions(+), 4 deletions(-)

diff --git a/TEWin/FrmWin.cs b/TEWin/FrmWin.cs
index c2cf872..da8a5be 100644
--- a/TEWin/FrmWin.cs
+++ b/TEWin/FrmWin.cs
@@ -26,6 +26,18 @@
 
         public SGWorld74 SG;
 
+        private bool isAngle;
+
+        private int angleCount;
+
+        private double angleSize;
+
+        private ITerrainLabel74 angleLabel;
+
+        private ITerrainPolyline74 angleLine;
+
+        private string angleGroupName = "瑙掗噺绠�";
+
         public FrmWin()
         {
             InitializeComponent();
@@ -268,12 +280,191 @@
         }
 
         #region 瑙掗噺绠�+绌洪棿缁熻+绌洪棿鍒嗘瀽+osgblab
-        public void AngleMeasurement()
+        private void AngleMeasurement()
         {
-            //
+            if (isAngle)
+            {
+                DeleteGroup(angleGroupName);
+                RmAngleEvent();
+                isAngle = false;
+                return;
+            }
+
+            isAngle = true;
+            AddAngleEvent();
         }
 
-        public void SpaceStatistics()
+        private string GetGroupId(string groupName)
+        {
+            string gid = SG.ProjectTree.FindItem(groupName);
+            if (!string.IsNullOrEmpty(gid)) return gid;
+
+            return SG.ProjectTree.CreateLockedGroup(groupName);
+        }
+
+        private void DeleteGroup(string groupName)
+        {
+            try
+            {
+                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);
+            }
+        }
+
+        private void AddAngleEvent()
+        {
+            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
+            {
+                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 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);
+
+                    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);
+                    angleLabel.Text = angleSize.ToString() + "掳";
+                }
+            }
+            catch (Exception ex)
+            {
+                LogOut.Error(ex.Message + "\r\n" + ex.StackTrace);
+            }
+        }
+
+        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)
+                {
+                    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.Geometry.StartEdit();
+                    angleCount++;
+
+                    return true;
+                }
+
+                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;
+                }
+
+                if (angleCount % 3 == 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;
+                p.Z = 0;
+                line.Points.AddPoint(CursorCoord.Position.X, CursorCoord.Position.Y, 0);
+                if (angleCount == 3)
+                {
+                    angleSize = 0;
+                    angleCount = 0;
+                    angleLine = null;
+                    angleLabel = null;
+                }
+            }
+            catch (Exception ex)
+            {
+                LogOut.Error(ex.Message + "\r\n" + ex.StackTrace);
+            }
+
+            return true;
+        }
+
+        bool Angle_OnRButtonUp(int Flags, int X, int Y)
+        {
+            DeleteGroup(angleGroupName);
+            RmAngleEvent();
+            angleCount = 0;
+            angleSize = 0;
+            isAngle = false;
+
+            return true;
+        }
+
+        private void SpaceStatistics()
         {
             //
         }
@@ -283,7 +474,7 @@
             this.ShowHtml("绌洪棿鍒嗘瀽", mainUrl + @"\Resources\SpatialQuery\SpatialQuery.html", 20, 20, 420, 285);
         }
 
-        public void InvokeOsgbLab()
+        private void InvokeOsgbLab()
         {
             //
         }

--
Gitblit v1.9.3