From 9024eb2672cc2ba8b9d81f4c4b4a4ffb434369ea Mon Sep 17 00:00:00 2001
From: tian <11429339@qq.com>
Date: Sat, 13 Sep 2025 00:51:55 +0800
Subject: [PATCH] =?UTF-8?q?=E5=85=B3=E9=97=AD=E7=A8=8B=E5=BA=8F=E6=97=B6?=
=?UTF-8?q?=E6=B8=85=E7=90=86=E5=8A=A8=E7=94=BB?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/Core/Animation/PathAnimationManager.cs | 41 +++++++++++++++++--
.../Animation/TimeLinerIntegrationManager.cs | 2 +-
.../Collision/ClashDetectiveIntegration.cs | 3 --
src/Core/MainPlugin.cs | 4 +-
.../ViewModels/AnimationControlViewModel.cs | 13 ++++++
5 files changed, 53 insertions(+), 10 deletions(-)
diff --git a/src/Core/Animation/PathAnimationManager.cs b/src/Core/Animation/PathAnimationManager.cs
index f65518c..526fadc 100644
--- a/src/Core/Animation/PathAnimationManager.cs
+++ b/src/Core/Animation/PathAnimationManager.cs
@@ -657,6 +657,39 @@ namespace NavisworksTransport.Core.Animation
}
}
+ ///
+ /// 程序关闭时的动画清理(不执行UI操作)
+ ///
+ public void ShutdownAnimation()
+ {
+ try
+ {
+ LogManager.Info("[PathAnimationManager] 程序关闭,执行动画清理");
+
+ // 检查动画状态,避免重复停止
+ if (_currentState == AnimationState.Stopped || _currentState == AnimationState.Idle)
+ {
+ LogManager.Debug($"动画已处于{_currentState}状态,跳过关闭清理");
+ return;
+ }
+
+ // 注销Idle事件
+ NavisApplication.Idle -= OnApplicationIdle;
+ LogManager.Debug("[Idle模式] Idle事件已注销(关闭清理)");
+
+ // 直接设置状态为停止,不执行任何UI操作
+ SetState(AnimationState.Stopped);
+ _pausedProgress = 0.0; // 重置暂停进度
+ _currentFrameIndex = 0; // 重置帧索引
+
+ LogManager.Info("[PathAnimationManager] 动画关闭清理完成");
+ }
+ catch (Exception ex)
+ {
+ LogManager.Error($"[PathAnimationManager] 关闭动画清理失败: {ex.Message}");
+ }
+ }
+
///
/// 完成动画(当动画自然播放结束时调用)
///
@@ -1294,7 +1327,7 @@ namespace NavisworksTransport.Core.Animation
// 停止动画
if (_currentState == AnimationState.Playing || _currentState == AnimationState.Paused)
{
- StopAnimation();
+ ShutdownAnimation();
}
// 清空对象引用
@@ -1354,7 +1387,7 @@ namespace NavisworksTransport.Core.Animation
{
if (_currentState == AnimationState.Playing || _currentState == AnimationState.Paused)
{
- StopAnimation();
+ ShutdownAnimation();
}
else
{
@@ -1667,7 +1700,7 @@ namespace NavisworksTransport.Core.Animation
if (!IsAnimatedObjectValid())
{
LogManager.Warning("[PathAnimationManager] 动画对象已失效,停止动画");
- StopAnimation();
+ ShutdownAnimation();
return;
}
@@ -1735,7 +1768,7 @@ namespace NavisworksTransport.Core.Animation
{
LogManager.Error($"[Idle模式] 动画更新异常: {ex.Message}");
// 发生异常时停止动画,避免持续错误
- StopAnimation();
+ ShutdownAnimation();
}
}
diff --git a/src/Core/Animation/TimeLinerIntegrationManager.cs b/src/Core/Animation/TimeLinerIntegrationManager.cs
index d242975..3eb083d 100644
--- a/src/Core/Animation/TimeLinerIntegrationManager.cs
+++ b/src/Core/Animation/TimeLinerIntegrationManager.cs
@@ -75,7 +75,7 @@ namespace NavisworksTransport.Core.Animation
var activeDocument = Application.ActiveDocument;
if (activeDocument == null)
{
- LogManager.Warning("没有活动文档,TimeLiner 初始化失败");
+ LogManager.Debug("没有活动文档,跳过TimeLiner初始化");
_isTimeLinerAvailable = false;
return;
}
diff --git a/src/Core/Collision/ClashDetectiveIntegration.cs b/src/Core/Collision/ClashDetectiveIntegration.cs
index 66275ad..3e8bbf8 100644
--- a/src/Core/Collision/ClashDetectiveIntegration.cs
+++ b/src/Core/Collision/ClashDetectiveIntegration.cs
@@ -1291,9 +1291,6 @@ namespace NavisworksTransport
_cachedResults?.Clear();
}
- // 清除高亮显示
- ClearHighlights();
-
// 清除对象缓存
ClearAllCaches();
diff --git a/src/Core/MainPlugin.cs b/src/Core/MainPlugin.cs
index 5981ffb..d88217f 100644
--- a/src/Core/MainPlugin.cs
+++ b/src/Core/MainPlugin.cs
@@ -447,13 +447,13 @@ namespace NavisworksTransport
// 通知DocumentStateManager文档已失效
DocumentStateManager.Instance.OnDocumentInvalidated();
- // 停止所有动画
+ // 停止所有动画(程序关闭专用)
try
{
var animationManager = PathAnimationManager.GetInstance();
if (animationManager != null)
{
- animationManager.StopAnimation();
+ animationManager.ShutdownAnimation(); // 使用关闭专用方法,不执行UI操作
animationManager.ClearReferences();
}
}
diff --git a/src/UI/WPF/ViewModels/AnimationControlViewModel.cs b/src/UI/WPF/ViewModels/AnimationControlViewModel.cs
index f16b3b7..cebfa2f 100644
--- a/src/UI/WPF/ViewModels/AnimationControlViewModel.cs
+++ b/src/UI/WPF/ViewModels/AnimationControlViewModel.cs
@@ -1766,6 +1766,19 @@ namespace NavisworksTransport.UI.WPF.ViewModels
}
// 2. 取消事件订阅(在停止动画之前,避免事件处理中访问已释放的对象)
+
+ // 取消DocumentStateManager事件订阅
+ try
+ {
+ DocumentStateManager.Instance.DocumentInvalidated -= OnDocumentInvalidated;
+ DocumentStateManager.Instance.DocumentReady -= OnDocumentReady;
+ LogManager.Debug("DocumentStateManager事件订阅取消完成");
+ }
+ catch (Exception docEx)
+ {
+ LogManager.Warning($"取消DocumentStateManager事件订阅时出现警告: {docEx.Message}");
+ }
+
if (_pathAnimationManager != null)
{
try