From 1c4e474ff6a0ae6cf1b1f7a9de71b3246aba29b6 Mon Sep 17 00:00:00 2001
From: lixiaojun <1287241240@qq.com>
Date: 星期三, 07 五月 2025 16:52:05 +0800
Subject: [PATCH] 新增可见元素移除功能

---
 Yw.WpfUI.Hydro.L3d.Core/03-draw/00-core/04-camera/DrawCameraHelper.cs |  154 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 152 insertions(+), 2 deletions(-)

diff --git a/Yw.WpfUI.Hydro.L3d.Core/03-draw/00-core/04-camera/DrawCameraHelper.cs b/Yw.WpfUI.Hydro.L3d.Core/03-draw/00-core/04-camera/DrawCameraHelper.cs
index 532df27..ad4a91a 100644
--- a/Yw.WpfUI.Hydro.L3d.Core/03-draw/00-core/04-camera/DrawCameraHelper.cs
+++ b/Yw.WpfUI.Hydro.L3d.Core/03-draw/00-core/04-camera/DrawCameraHelper.cs
@@ -8,18 +8,67 @@
         /// <summary>
         /// 
         /// </summary>
-        public DrawCameraHelper(HelixViewport3D viewport)
+        public DrawCameraHelper
+            (
+                HelixViewport3D viewport,
+                DrawInitialHelper initialHelper
+            )
         {
             _viewport = viewport;
+            _initialHelper = initialHelper;
+            Attach();
         }
 
         private readonly HelixViewport3D _viewport = null;//涓夌淮缁勪欢
+        private readonly DrawInitialHelper _initialHelper = null;//鍒濆鍖栬緟鍔╃被   
+
+        /// <summary>
+        /// 鏄惁鍚敤
+        /// </summary>
+        public bool Enabled
+        {
+            get { return _enabled; }
+            set { _enabled = value; }
+        }
+        private bool _enabled = true;
+
+        /// <summary>
+        /// 鏄惁鍒濆鍖�
+        /// </summary>
+        public bool Initialized
+        {
+            get { return _initialized; }
+            private set { _initialized = value; }
+        }
+        private bool _initialized = false;
+
+        //鍒濆鍖�
+        private void Initialize()
+        {
+            if (!_initialHelper.Initialized)
+            {
+                return;
+            }
+            _initialized = true;
+        }
+
+        //澶勭悊鍒濆鍖栧畬鎴�
+        private void OnInitialCompleted()
+        {
+            Initialize();
+        }
+
+        #region 瑙嗗浘鎿嶄綔
 
         /// <summary>
         /// 鑾峰彇瑙嗗浘
         /// </summary>
         public CameraSettingL3d GetView()
         {
+            if (!Initialized)
+            {
+                return default;
+            }
             var cameraSetting = new CameraSetting(_viewport.Camera);
             return cameraSetting.ToCameraSettingL3d();
         }
@@ -29,6 +78,10 @@
         /// </summary>
         public void SetView(CameraSettingL3d cameraSetting)
         {
+            if (!Initialized)
+            {
+                return;
+            }
             if (cameraSetting == null)
             {
                 return;
@@ -49,6 +102,8 @@
             }
         }
 
+        #endregion
+
         #region 鍏鍥�
 
         /// <summary>
@@ -56,6 +111,10 @@
         /// </summary>
         public void SetTopView()
         {
+            if (!Initialized)
+            {
+                return;
+            }
             var lookDirection = new Vector3D(0, 0, -1); // 鍚戜笅鐪�
             var upDirection = new Vector3D(0, 1, 0);// Y杞存湞涓�
             _viewport.FitView(lookDirection, upDirection);
@@ -66,6 +125,10 @@
         /// </summary>
         public void SetBottomView()
         {
+            if (!Initialized)
+            {
+                return;
+            }
             var lookDirection = new Vector3D(0, 0, 1);   // 鍚戜笂鐪�
             var upDirection = new Vector3D(0, 1, 0);// Y杞存湞涓�
             _viewport.FitView(lookDirection, upDirection);
@@ -76,6 +139,10 @@
         /// </summary>
         public void SetLeftView()
         {
+            if (!Initialized)
+            {
+                return;
+            }
             var lookDirection = new Vector3D(1, 0, 0);   // 鍚戝彸鐪�
             var upDirection = new Vector3D(0, 0, 1);// Z杞存湞涓�
             _viewport.FitView(lookDirection, upDirection);
@@ -86,6 +153,10 @@
         /// </summary>
         public void SetRightView()
         {
+            if (!Initialized)
+            {
+                return;
+            }
             var lookDirection = new Vector3D(-1, 0, 0);   // 鍚戝乏鐪�
             var upDirection = new Vector3D(0, 0, 1);// Z杞存湞涓�
             _viewport.FitView(lookDirection, upDirection);
@@ -96,6 +167,10 @@
         /// </summary>
         public void SetFrontView()
         {
+            if (!Initialized)
+            {
+                return;
+            }
             var lookDirection = new Vector3D(0, 1, 0);   // 鍚戝悗鐪�
             var upDirection = new Vector3D(0, 0, 1);// Z杞存湞涓�
             _viewport.FitView(lookDirection, upDirection);
@@ -106,6 +181,10 @@
         /// </summary>
         public void SetBackView()
         {
+            if (!Initialized)
+            {
+                return;
+            }
             var lookDirection = new Vector3D(0, -1, 0);   // 鍚戝墠鐪�
             var upDirection = new Vector3D(0, 0, 1);// Z杞存湞涓�
             _viewport.FitView(lookDirection, upDirection);
@@ -121,6 +200,10 @@
         /// </summary>
         public void SetSouthWestView()
         {
+            if (!Initialized)
+            {
+                return;
+            }
             var lookDirection = new Vector3D(1, 1, -1);
             var upDirection = new Vector3D(0, 0, 1);
             _viewport.FitView(lookDirection, upDirection);
@@ -132,6 +215,10 @@
         /// </summary>
         public void SetSouthEastView()
         {
+            if (!Initialized)
+            {
+                return;
+            }
             var lookDirection = new Vector3D(-1, 1, -1);
             var upDirection = new Vector3D(0, 0, 1);
             _viewport.FitView(lookDirection, upDirection);
@@ -143,6 +230,10 @@
         /// </summary>
         public void SetNorthEastView()
         {
+            if (!Initialized)
+            {
+                return;
+            }
             var lookDirection = new Vector3D(-1, -1, -1);
             var upDirection = new Vector3D(0, 0, 1);
             _viewport.FitView(lookDirection, upDirection);
@@ -154,6 +245,10 @@
         /// </summary>
         public void SetNorthWestView()
         {
+            if (!Initialized)
+            {
+                return;
+            }
             var lookDirection = new Vector3D(1, -1, -1);
             var upDirection = new Vector3D(0, 0, 1);
             _viewport.FitView(lookDirection, upDirection);
@@ -161,12 +256,67 @@
 
         #endregion
 
+        #region 榛樿瑙嗗浘
+
+        /// <summary>
+        /// 鏄剧ず榛樿瑙嗗浘
+        /// </summary>
+        public bool ShowDefaultView()
+        {
+            if (!Initialized)
+            {
+                return false;
+            }
+            var cameraSetting = _initialHelper.GetDefaultCameraSetting();
+            if (cameraSetting == null)
+            {
+                return false;
+            }
+            SetView(cameraSetting);
+            return true;
+        }
+
+        #endregion
+
+        //澶勭悊榧犳爣鍙屽嚮浜嬩欢
+        private void OnMouseDoubleClick(object sender, MouseButtonEventArgs e)
+        {
+            if (e.ChangedButton != MouseButton.Left)
+            {
+                return;
+            }
+            if (!Enabled)
+            {
+                return;
+            }
+            var bol = ShowDefaultView();
+            if (bol)
+            {
+                return;
+            }
+            SetSouthWestView();
+        }
+
+        //闄勫姞
+        private void Attach()
+        {
+            _viewport.MouseDoubleClick += OnMouseDoubleClick;
+            _initialHelper.InitialCompletedEvent += OnInitialCompleted;
+        }
+
+        //鍒嗙
+        private void Detach()
+        {
+            _viewport.MouseDoubleClick -= OnMouseDoubleClick;
+            _initialHelper.InitialCompletedEvent -= OnInitialCompleted;
+        }
+
         /// <summary>
         /// 閲婃斁
         /// </summary>
         public void Dispose()
         {
-
+            Detach();
         }
 
     }

--
Gitblit v1.9.3