diff --git a/src/UI/WPF/ViewModels/AnimationControlViewModel.cs b/src/UI/WPF/ViewModels/AnimationControlViewModel.cs index 50ef64c..a9b5e67 100644 --- a/src/UI/WPF/ViewModels/AnimationControlViewModel.cs +++ b/src/UI/WPF/ViewModels/AnimationControlViewModel.cs @@ -72,7 +72,6 @@ namespace NavisworksTransport.UI.WPF.ViewModels private readonly NavisworksTransport.Core.Animation.LogisticsAnimationManager _logisticsAnimationManager; private readonly ClashDetectiveIntegration _clashIntegration; private readonly UIStateManager _uiStateManager; - private readonly LogisticsControlViewModel _mainViewModel; // 动画参数相关字段 private ObservableCollection _availableFrameRates; @@ -423,8 +422,8 @@ namespace NavisworksTransport.UI.WPF.ViewModels { try { - // 保存主ViewModel引用 - _mainViewModel = mainViewModel; + // 设置主ViewModel引用到基类 + SetMainViewModel(mainViewModel); // 初始化管理器 _pathAnimationManager = new NavisworksTransport.Core.Animation.PathAnimationManager(); @@ -1629,66 +1628,6 @@ namespace NavisworksTransport.UI.WPF.ViewModels #endregion - #region 统一状态栏方法 - - /// - /// 更新统一状态栏(简单版本,不显示进度条) - /// - private void UpdateMainStatus(string message) - { - try - { - // 如果有主ViewModel引用,更新统一状态栏 - if (_mainViewModel != null) - { - _mainViewModel.UpdateStatus(message); - } - } - catch (Exception ex) - { - LogManager.Error($"更新统一状态栏失败: {ex.Message}", ex); - } - } - - /// - /// 更新统一状态栏(支持百分比进度) - /// - private void UpdateMainStatus(string message, double percentage) - { - try - { - // 如果有主ViewModel引用,更新统一状态栏 - if (_mainViewModel != null) - { - _mainViewModel.UpdateStatus(message, percentage); - } - } - catch (Exception ex) - { - LogManager.Error($"更新统一状态栏失败: {ex.Message}", ex); - } - } - - /// - /// 更新统一状态栏(完整版本,支持不确定进度) - /// - private void UpdateMainStatus(string message, double progress = -1, bool? isProcessing = null) - { - try - { - // 如果有主ViewModel引用,更新统一状态栏 - if (_mainViewModel != null) - { - _mainViewModel.UpdateStatus(message, progress, isProcessing); - } - } - catch (Exception ex) - { - LogManager.Error($"更新统一状态栏失败: {ex.Message}", ex); - } - } - - #endregion #region 资源清理 diff --git a/src/UI/WPF/ViewModels/LayerManagementViewModel.cs b/src/UI/WPF/ViewModels/LayerManagementViewModel.cs index 761be3f..99f400f 100644 --- a/src/UI/WPF/ViewModels/LayerManagementViewModel.cs +++ b/src/UI/WPF/ViewModels/LayerManagementViewModel.cs @@ -43,7 +43,6 @@ namespace NavisworksTransport.UI.WPF.ViewModels private readonly ModelSplitterManager _modelSplitterManager; private readonly AttributeGrouper _attributeGrouper; private readonly UIStateManager _uiStateManager; - private readonly LogisticsControlViewModel _mainViewModel; private CancellationTokenSource _cancellationTokenSource; // 选择事件订阅管理器 @@ -809,8 +808,8 @@ namespace NavisworksTransport.UI.WPF.ViewModels { try { - // 保存主ViewModel引用 - _mainViewModel = mainViewModel; + // 设置主ViewModel引用到基类 + SetMainViewModel(mainViewModel); // 获取UI状态管理器实例 _uiStateManager = UIStateManager.Instance; @@ -3787,65 +3786,5 @@ namespace NavisworksTransport.UI.WPF.ViewModels #endregion - #region 统一状态栏方法 - - /// - /// 更新统一状态栏(简单版本,不显示进度条) - /// - private void UpdateMainStatus(string message) - { - try - { - // 如果有主ViewModel引用,更新统一状态栏 - if (_mainViewModel != null) - { - _mainViewModel.UpdateStatus(message); - } - } - catch (Exception ex) - { - LogManager.Error($"更新统一状态栏失败: {ex.Message}", ex); - } - } - - /// - /// 更新统一状态栏(支持百分比进度) - /// - private void UpdateMainStatus(string message, double percentage) - { - try - { - // 如果有主ViewModel引用,更新统一状态栏 - if (_mainViewModel != null) - { - _mainViewModel.UpdateStatus(message, percentage); - } - } - catch (Exception ex) - { - LogManager.Error($"更新统一状态栏失败: {ex.Message}", ex); - } - } - - /// - /// 更新统一状态栏(完整版本,支持不确定进度) - /// - private void UpdateMainStatus(string message, double progress = -1, bool? isProcessing = null) - { - try - { - // 如果有主ViewModel引用,更新统一状态栏 - if (_mainViewModel != null) - { - _mainViewModel.UpdateStatus(message, progress, isProcessing); - } - } - catch (Exception ex) - { - LogManager.Error($"更新统一状态栏失败: {ex.Message}", ex); - } - } - - #endregion } } \ No newline at end of file diff --git a/src/UI/WPF/ViewModels/ModelSettingsViewModel.cs b/src/UI/WPF/ViewModels/ModelSettingsViewModel.cs index 756f3fa..ae80f5c 100644 --- a/src/UI/WPF/ViewModels/ModelSettingsViewModel.cs +++ b/src/UI/WPF/ViewModels/ModelSettingsViewModel.cs @@ -32,7 +32,6 @@ namespace NavisworksTransport.UI.WPF.ViewModels #region 私有字段和依赖注入 private readonly UIStateManager _uiStateManager; - private readonly LogisticsControlViewModel _mainViewModel; // 选择事件订阅管理器 private SelectionEventSubscription _selectionEventSubscription; @@ -277,9 +276,9 @@ namespace NavisworksTransport.UI.WPF.ViewModels { try { - // 获取UI状态管理器实例和主ViewModel引用 + // 获取UI状态管理器实例和设置主ViewModel引用到基类 _uiStateManager = UIStateManager.Instance; - _mainViewModel = mainViewModel; + SetMainViewModel(mainViewModel); // 验证关键组件是否正常初始化 if (_uiStateManager == null) @@ -1216,43 +1215,6 @@ namespace NavisworksTransport.UI.WPF.ViewModels System.Windows.Input.CommandManager.InvalidateRequerySuggested(); } - /// - /// 更新统一状态栏(简单版本,不显示进度条) - /// - private void UpdateMainStatus(string message) - { - try - { - // 如果有主ViewModel引用,更新统一状态栏 - if (_mainViewModel != null) - { - _mainViewModel.UpdateStatus(message); - } - } - catch (Exception ex) - { - LogManager.Error($"更新统一状态栏失败: {ex.Message}", ex); - } - } - - /// - /// 更新统一状态栏(完整版本,支持进度条) - /// - private void UpdateMainStatus(string message, double progress = -1, bool? isProcessing = null) - { - try - { - // 如果有主ViewModel引用,更新统一状态栏 - if (_mainViewModel != null) - { - _mainViewModel.UpdateStatus(message, progress, isProcessing); - } - } - catch (Exception ex) - { - LogManager.Error($"更新统一状态栏失败: {ex.Message}", ex); - } - } #endregion diff --git a/src/UI/WPF/ViewModels/PathEditingViewModel.cs b/src/UI/WPF/ViewModels/PathEditingViewModel.cs index 0c42035..3cffced 100644 --- a/src/UI/WPF/ViewModels/PathEditingViewModel.cs +++ b/src/UI/WPF/ViewModels/PathEditingViewModel.cs @@ -30,7 +30,6 @@ namespace NavisworksTransport.UI.WPF.ViewModels private PathPlanningManager _pathPlanningManager; private readonly UIStateManager _uiStateManager; private readonly PathDataManager _pathDataManager; - private readonly LogisticsControlViewModel _mainViewModel; // 路径集合 private ObservableCollection _pathRoutes; @@ -411,8 +410,8 @@ namespace NavisworksTransport.UI.WPF.ViewModels { try { - // 保存主ViewModel引用 - _mainViewModel = mainViewModel; + // 设置主ViewModel引用到基类 + SetMainViewModel(mainViewModel); _uiStateManager = UIStateManager.Instance; _pathDataManager = new PathDataManager(); @@ -2374,66 +2373,6 @@ namespace NavisworksTransport.UI.WPF.ViewModels #endregion - #region 统一状态栏方法 - - /// - /// 更新统一状态栏(简单版本,不显示进度条) - /// - private void UpdateMainStatus(string message) - { - try - { - // 如果有主ViewModel引用,更新统一状态栏 - if (_mainViewModel != null) - { - _mainViewModel.UpdateStatus(message); - } - } - catch (Exception ex) - { - LogManager.Error($"更新统一状态栏失败: {ex.Message}", ex); - } - } - - /// - /// 更新统一状态栏(支持百分比进度) - /// - private void UpdateMainStatus(string message, double percentage) - { - try - { - // 如果有主ViewModel引用,更新统一状态栏 - if (_mainViewModel != null) - { - _mainViewModel.UpdateStatus(message, percentage); - } - } - catch (Exception ex) - { - LogManager.Error($"更新统一状态栏失败: {ex.Message}", ex); - } - } - - /// - /// 更新统一状态栏(完整版本,支持不确定进度) - /// - private void UpdateMainStatus(string message, double progress = -1, bool? isProcessing = null) - { - try - { - // 如果有主ViewModel引用,更新统一状态栏 - if (_mainViewModel != null) - { - _mainViewModel.UpdateStatus(message, progress, isProcessing); - } - } - catch (Exception ex) - { - LogManager.Error($"更新统一状态栏失败: {ex.Message}", ex); - } - } - - #endregion #region 清理资源 diff --git a/src/UI/WPF/ViewModels/SystemManagementViewModel.cs b/src/UI/WPF/ViewModels/SystemManagementViewModel.cs index 1f1c2aa..d0dc664 100644 --- a/src/UI/WPF/ViewModels/SystemManagementViewModel.cs +++ b/src/UI/WPF/ViewModels/SystemManagementViewModel.cs @@ -18,7 +18,6 @@ namespace NavisworksTransport.UI.WPF.ViewModels #region 私有字段 private readonly UIStateManager _uiStateManager; - private readonly LogisticsControlViewModel _mainViewModel; // 系统管理相关字段 private bool _isAutoSaveEnabled = true; @@ -229,8 +228,8 @@ namespace NavisworksTransport.UI.WPF.ViewModels { try { - // 保存主ViewModel引用 - _mainViewModel = mainViewModel; + // 设置主ViewModel引用到基类 + SetMainViewModel(mainViewModel); // 获取UI状态管理器实例 _uiStateManager = UIStateManager.Instance; @@ -856,63 +855,6 @@ namespace NavisworksTransport.UI.WPF.ViewModels #region 辅助方法 - /// - /// 更新统一状态栏(简单版本,不显示进度条) - /// - private void UpdateMainStatus(string message) - { - try - { - // 如果有主ViewModel引用,更新统一状态栏 - if (_mainViewModel != null) - { - _mainViewModel.UpdateStatus(message); - } - } - catch (Exception ex) - { - LogManager.Error($"更新统一状态栏失败: {ex.Message}", ex); - } - } - - /// - /// 更新统一状态栏(支持百分比进度) - /// - private void UpdateMainStatus(string message, double percentage) - { - try - { - // 如果有主ViewModel引用,更新统一状态栏 - if (_mainViewModel != null) - { - _mainViewModel.UpdateStatus(message, percentage); - } - } - catch (Exception ex) - { - LogManager.Error($"更新统一状态栏失败: {ex.Message}", ex); - } - } - - /// - /// 更新统一状态栏(完整版本,支持不确定进度) - /// - private void UpdateMainStatus(string message, double progress = -1, bool? isProcessing = null) - { - try - { - // 如果有主ViewModel引用,更新统一状态栏 - if (_mainViewModel != null) - { - _mainViewModel.UpdateStatus(message, progress, isProcessing); - } - } - catch (Exception ex) - { - LogManager.Error($"更新统一状态栏失败: {ex.Message}", ex); - } - } - /// /// 安全执行异步操作 /// diff --git a/src/UI/WPF/ViewModels/ViewModelBase.cs b/src/UI/WPF/ViewModels/ViewModelBase.cs index 425c1a7..f5fc864 100644 --- a/src/UI/WPF/ViewModels/ViewModelBase.cs +++ b/src/UI/WPF/ViewModels/ViewModelBase.cs @@ -56,6 +56,11 @@ namespace NavisworksTransport.UI.WPF.ViewModels /// protected bool IsPerformanceMonitoringEnabled { get; set; } = true; + /// + /// 主ViewModel引用,用于统一状态栏更新 + /// + protected LogisticsControlViewModel _mainViewModel; + #endregion #region 构造函数 @@ -676,6 +681,82 @@ namespace NavisworksTransport.UI.WPF.ViewModels } #endregion + + #region 统一状态栏更新方法 + + /// + /// 设置主ViewModel引用 + /// + /// 主ViewModel实例 + protected void SetMainViewModel(LogisticsControlViewModel mainViewModel) + { + _mainViewModel = mainViewModel; + } + + /// + /// 更新统一状态栏(简单版本,不显示进度条) + /// + /// 状态消息 + protected void UpdateMainStatus(string message) + { + try + { + // 如果有主ViewModel引用,更新统一状态栏 + if (_mainViewModel != null) + { + _mainViewModel.UpdateStatus(message); + } + } + catch (Exception ex) + { + LogManager.Error($"更新统一状态栏失败: {ex.Message}", ex); + } + } + + /// + /// 更新统一状态栏(支持百分比进度) + /// + /// 状态消息 + /// 进度百分比 + protected void UpdateMainStatus(string message, double percentage) + { + try + { + // 如果有主ViewModel引用,更新统一状态栏 + if (_mainViewModel != null) + { + _mainViewModel.UpdateStatus(message, percentage); + } + } + catch (Exception ex) + { + LogManager.Error($"更新统一状态栏失败: {ex.Message}", ex); + } + } + + /// + /// 更新统一状态栏(完整版本,支持不确定进度) + /// + /// 状态消息 + /// 进度值(-1表示不确定进度) + /// 是否正在处理(可选) + protected void UpdateMainStatus(string message, double progress = -1, bool? isProcessing = null) + { + try + { + // 如果有主ViewModel引用,更新统一状态栏 + if (_mainViewModel != null) + { + _mainViewModel.UpdateStatus(message, progress, isProcessing); + } + } + catch (Exception ex) + { + LogManager.Error($"更新统一状态栏失败: {ex.Message}", ex); + } + } + + #endregion } ///