From d8b65342e1209f4caf7e06b741d0cbc004e1ef1d Mon Sep 17 00:00:00 2001 From: tian <11429339@qq.com> Date: Fri, 12 Sep 2025 12:50:24 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BD=BB=E5=BA=95=E6=B8=85=E7=90=86=E6=8E=A7?= =?UTF-8?q?=E4=BB=B6=E4=B8=BB=E7=AA=97=E5=8F=A3=E7=9A=84=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/UI/WPF/LogisticsControlPanel.xaml.cs | 6 - .../ViewModels/AnimationControlViewModel.cs | 40 -- .../ViewModels/LogisticsControlViewModel.cs | 679 +----------------- 3 files changed, 5 insertions(+), 720 deletions(-) diff --git a/src/UI/WPF/LogisticsControlPanel.xaml.cs b/src/UI/WPF/LogisticsControlPanel.xaml.cs index f9dab2b..01c0254 100644 --- a/src/UI/WPF/LogisticsControlPanel.xaml.cs +++ b/src/UI/WPF/LogisticsControlPanel.xaml.cs @@ -477,12 +477,6 @@ namespace NavisworksTransport.UI.WPF // 使用Dispatcher确保在UI线程上更新ViewModel Dispatcher.BeginInvoke(new Action(async () => { - if (ViewModel != null) - { - await ViewModel.UpdateSelectionDisplayAsync(); - await ViewModel.UpdateInstructionTextAsync(); - } - // 同时更新分层管理视图的ViewModel if (_layerManagementView?.ViewModel != null) { diff --git a/src/UI/WPF/ViewModels/AnimationControlViewModel.cs b/src/UI/WPF/ViewModels/AnimationControlViewModel.cs index 948185d..55b0382 100644 --- a/src/UI/WPF/ViewModels/AnimationControlViewModel.cs +++ b/src/UI/WPF/ViewModels/AnimationControlViewModel.cs @@ -1622,46 +1622,6 @@ namespace NavisworksTransport.UI.WPF.ViewModels } } - /// - /// 将碰撞报告详情输出到日志 - /// - private void LogCollisionReportDetails(CollisionReportData reportData) - { - if (!reportData.IsValid) - { - LogManager.Error($"碰撞报告无效: {reportData.ErrorMessage}"); - return; - } - - var report = new System.Text.StringBuilder(); - report.AppendLine("=== 碰撞检测详细报告 ==="); - report.AppendLine($"生成时间: {reportData.GeneratedTime:yyyy-MM-dd HH:mm:ss}"); - report.AppendLine($"动画对象: {reportData.AnimatedObjectName}"); - report.AppendLine($"动画路径: {reportData.PathName}"); - report.AppendLine($"总测试数: {reportData.TotalTests}"); - report.AppendLine($"总碰撞数: {reportData.TotalCollisions}"); - report.AppendLine(); - - foreach (var test in reportData.Tests) - { - report.AppendLine($"【测试】 {test.TestName}"); - report.AppendLine($" 类型: {test.TestType}, 容差: {test.Tolerance:F3}, 状态: {test.Status}"); - report.AppendLine($" 碰撞数量: {test.CollisionCount}"); - - foreach (var collision in test.Collisions) - { - report.AppendLine($" 碰撞 {collision.CollisionId}:"); - report.AppendLine($" 对象1: {collision.Object1Name} 位置: {collision.Object1Position}"); - report.AppendLine($" 对象2: {collision.Object2Name} 位置: {collision.Object2Position}"); - report.AppendLine($" 碰撞中心: {collision.CollisionCenter}"); - report.AppendLine($" 距离: {collision.Distance:F3}, 状态: {collision.Status}"); - } - report.AppendLine(); - } - - LogManager.Info(report.ToString()); - } - #endregion diff --git a/src/UI/WPF/ViewModels/LogisticsControlViewModel.cs b/src/UI/WPF/ViewModels/LogisticsControlViewModel.cs index 9f06a63..a1403fe 100644 --- a/src/UI/WPF/ViewModels/LogisticsControlViewModel.cs +++ b/src/UI/WPF/ViewModels/LogisticsControlViewModel.cs @@ -1,17 +1,5 @@ using System; -using System.Collections.Generic; -using System.Collections.ObjectModel; -using System.Windows; -using System.Windows.Input; -using System.Linq; -using System.Threading.Tasks; -using Autodesk.Navisworks.Api; -using NavisApplication = Autodesk.Navisworks.Api.Application; using NavisworksTransport.Core; -using NavisworksTransport.Commands; -using NavisworksTransport.UI.WPF.Collections; -using NavisworksTransport.UI.WPF.Models; -using NavisworksTransport.Utils; namespace NavisworksTransport.UI.WPF.ViewModels { @@ -22,63 +10,17 @@ namespace NavisworksTransport.UI.WPF.ViewModels { #region 私有字段 - private string _selectedModelsText; - private string _instructionText; private string _statusText; - - - - private string _animationStatus; - private double _animationProgress; - private ObservableCollection _availableCategories; - - private bool _isProcessing = false; // UI状态管理和命令框架 private readonly UIStateManager _uiStateManager; private readonly NavisworksTransport.Commands.CommandManager _commandManager; - - // 动画参数相关字段 - private double _animationSpeed = 1.0; - private ObservableCollection _availableFrameRates; - private int _selectedFrameRate = 30; - private double _animationDuration = 10.0; - private bool _isLoopEnabled = false; - private bool _isSmoothTransition = true; - private double _currentAnimationTime = 0.0; - private bool _canStartAnimation = true; - private bool _canPauseAnimation = false; - private bool _canStopAnimation = false; - - // 碰撞检测相关字段 - private bool _canRunCollisionDetection = true; - private bool _hasCollisionResults = false; - private string _collisionStatus = "就绪"; - private string _collisionSummary = "尚未运行碰撞检测"; - #endregion #region 公共属性 - /// - /// 选中模型文本 - /// - public string SelectedModelsText - { - get => _selectedModelsText; - set => SetProperty(ref _selectedModelsText, value); - } - - /// - /// 指令文本 - /// - public string InstructionText - { - get => _instructionText; - set => SetProperty(ref _instructionText, value); - } /// /// 状态文本 @@ -89,49 +31,6 @@ namespace NavisworksTransport.UI.WPF.ViewModels set => SetProperty(ref _statusText, value); } - - /// - /// 路径集合 - /// - - - /// - /// 选中的路径 - /// - - - /// - /// 是否处于路径编辑模式 - /// - - - /// - /// 动画状态 - /// - public string AnimationStatus - { - get => _animationStatus; - set => SetProperty(ref _animationStatus, value); - } - - /// - /// 动画进度 - /// - public double AnimationProgress - { - get => _animationProgress; - set => SetProperty(ref _animationProgress, value); - } - - /// - /// 可用类别集合 - /// - public ObservableCollection AvailableCategories - { - get => _availableCategories; - set => SetProperty(ref _availableCategories, value); - } - /// /// 是否正在处理中(用于统一状态栏进度条显示) /// @@ -141,15 +40,17 @@ namespace NavisworksTransport.UI.WPF.ViewModels set => SetProperty(ref _isProcessing, value); } + private double _progressPercentage = 0; + /// /// 进度百分比(0-100,-1表示不确定进度) /// public double ProgressPercentage { - get => _animationProgress; + get => _progressPercentage; set { - if (SetProperty(ref _animationProgress, value)) + if (SetProperty(ref _progressPercentage, value)) { OnPropertyChanged(nameof(IsIndeterminateProgress)); } @@ -161,151 +62,6 @@ namespace NavisworksTransport.UI.WPF.ViewModels /// public bool IsIndeterminateProgress => ProgressPercentage < 0; - #region 动画控制属性 - - /// - /// 动画速度 - /// - public double AnimationSpeed - { - get => _animationSpeed; - set => SetProperty(ref _animationSpeed, value); - } - - /// - /// 可用帧率集合 - /// - public ObservableCollection AvailableFrameRates - { - get => _availableFrameRates; - set => SetProperty(ref _availableFrameRates, value); - } - - /// - /// 选中的帧率 - /// - public int SelectedFrameRate - { - get => _selectedFrameRate; - set => SetProperty(ref _selectedFrameRate, value); - } - - /// - /// 动画持续时间(秒) - /// - public double AnimationDuration - { - get => _animationDuration; - set => SetProperty(ref _animationDuration, value); - } - - /// - /// 是否启用循环播放 - /// - public bool IsLoopEnabled - { - get => _isLoopEnabled; - set => SetProperty(ref _isLoopEnabled, value); - } - - /// - /// 是否启用平滑过渡 - /// - public bool IsSmoothTransition - { - get => _isSmoothTransition; - set => SetProperty(ref _isSmoothTransition, value); - } - - /// - /// 当前动画时间 - /// - public double CurrentAnimationTime - { - get => _currentAnimationTime; - set => SetProperty(ref _currentAnimationTime, value); - } - - /// - /// 是否可以开始动画 - /// - public bool CanStartAnimation - { - get => _canStartAnimation; - set => SetProperty(ref _canStartAnimation, value); - } - - /// - /// 是否可以暂停动画 - /// - public bool CanPauseAnimation - { - get => _canPauseAnimation; - set => SetProperty(ref _canPauseAnimation, value); - } - - /// - /// 是否可以停止动画 - /// - public bool CanStopAnimation - { - get => _canStopAnimation; - set => SetProperty(ref _canStopAnimation, value); - } - - #endregion - - #region 碰撞检测属性 - - /// - /// 是否可以运行碰撞检测 - /// - public bool CanRunCollisionDetection - { - get => _canRunCollisionDetection; - set => SetProperty(ref _canRunCollisionDetection, value); - } - - /// - /// 是否有碰撞检测结果 - /// - public bool HasCollisionResults - { - get => _hasCollisionResults; - set => SetProperty(ref _hasCollisionResults, value); - } - - /// - /// 碰撞检测状态 - /// - public string CollisionStatus - { - get => _collisionStatus; - set => SetProperty(ref _collisionStatus, value); - } - - /// - /// 碰撞检测摘要 - /// - public string CollisionSummary - { - get => _collisionSummary; - set => SetProperty(ref _collisionSummary, value); - } - - #endregion - - - #endregion - - #region 命令 - - public ICommand StartAnimationCommand { get; private set; } - public ICommand PauseAnimationCommand { get; private set; } - public ICommand StopAnimationCommand { get; private set; } - public ICommand RunCollisionDetectionCommand { get; private set; } - public ICommand ViewCollisionReportCommand { get; private set; } - #endregion #region 构造函数 @@ -330,15 +86,9 @@ namespace NavisworksTransport.UI.WPF.ViewModels LogManager.Error("CommandManager初始化失败"); throw new InvalidOperationException("CommandManager初始化失败"); } - - // 初始化线程安全的集合 - AvailableFrameRates = new ThreadSafeObservableCollection(); - - // 初始化命令(使用新的Command Pattern框架) - InitializeCommandsAsync(); // 初始化状态 - InitializeViewModelAsync(); + StatusText = "插件已就绪"; LogManager.Info("LogisticsControlViewModel构造函数执行完成"); } @@ -352,322 +102,6 @@ namespace NavisworksTransport.UI.WPF.ViewModels } } - #endregion - - #region 初始化 - - private async void InitializeViewModelAsync() - { - await SafeExecuteAsync(async () => - { - await UpdateInstructionTextAsync(); - await UpdateSelectionDisplayAsync(); - - await _uiStateManager.ExecuteUIUpdateAsync(() => - { - StatusText = "插件已就绪"; - AnimationStatus = "动画状态: 就绪"; - AnimationProgress = 0; - }); - - // 初始化动画参数 - await InitializeAnimationSettingsAsync(); - - - LogManager.Info("LogisticsControlViewModel 初始化完成"); - }, "初始化ViewModel"); - } - - /// - /// 初始化命令(使用Command Pattern框架) - /// - private async void InitializeCommandsAsync() - { - await SafeExecuteAsync(() => - { - // 动画控制命令 - StartAnimationCommand = new RelayCommand(async () => await ExecuteStartAnimationAsync(), () => CanStartAnimation); - PauseAnimationCommand = new RelayCommand(async () => await ExecutePauseAnimationAsync(), () => CanPauseAnimation); - StopAnimationCommand = new RelayCommand(async () => await ExecuteStopAnimationAsync(), () => CanStopAnimation); - - // 碰撞检测命令 - RunCollisionDetectionCommand = new RelayCommand(async () => await ExecuteRunCollisionDetectionAsync(), () => CanRunCollisionDetection); - ViewCollisionReportCommand = new RelayCommand(async () => await ExecuteViewCollisionReportAsync(), () => HasCollisionResults); - - LogManager.Info("命令初始化完成 - 使用新的异步Command Pattern框架"); - }, "初始化命令"); - } - - /// - /// 初始化动画设置 - /// - private async Task InitializeAnimationSettingsAsync() - { - await SafeExecuteAsync(async () => - { - await _uiStateManager.ExecuteUIUpdateAsync(() => - { - // 初始化可用帧率 - AvailableFrameRates.Clear(); - var frameRates = new[] { 15, 24, 30, 60 }; - foreach (var rate in frameRates) - { - AvailableFrameRates.Add(rate); - } - SelectedFrameRate = 30; // 默认30fps - - // 设置默认动画参数 - AnimationSpeed = 1.0; - AnimationDuration = 10.0; - IsLoopEnabled = false; - IsSmoothTransition = true; - CurrentAnimationTime = 0.0; - - // 设置初始状态 - CanStartAnimation = true; - CanPauseAnimation = false; - CanStopAnimation = false; - CanRunCollisionDetection = true; - HasCollisionResults = false; - CollisionStatus = "就绪"; - CollisionSummary = "尚未运行碰撞检测"; - }); - - LogManager.Info("动画设置初始化完成"); - }, "初始化动画设置"); - } - - /// - /// 初始化系统管理设置 - /// - - #endregion - - #region 命令实现 - - - /// - /// 异步开始动画命令(使用UIStateManager和Command Pattern) - /// - private async Task ExecuteStartAnimationAsync() - { - if (!CanStartAnimation) - { - await _uiStateManager.ExecuteUIUpdateAsync(() => - { - StatusText = "动画条件不满足,无法开始动画"; - }); - return; - } - - try - { - // 在UI线程上更新动画状态 - await _uiStateManager.ExecuteUIUpdateAsync(() => - { - AnimationStatus = "动画状态: 播放中"; - AnimationProgress = 0; - CurrentAnimationTime = 0.0; - - // 更新按钮状态 - CanStartAnimation = false; - CanPauseAnimation = true; - CanStopAnimation = true; - - StatusText = $"动画已开始 (速度: {AnimationSpeed}x, 帧率: {SelectedFrameRate}fps)"; - LogManager.Info($"开始动画播放, 速度: {AnimationSpeed}x, 帧率: {SelectedFrameRate}fps"); - }); - - // TODO: 集成LogisticsAnimationManager开始动画 - // 这里可以使用CommandManager执行动画命令 - // await _commandManager.ExecuteCommandAsync("StartAnimation", new object[] { ... }); - } - catch (Exception ex) - { - await _uiStateManager.ExecuteUIUpdateAsync(() => - { - StatusText = $"开始动画出错: {ex.Message}"; - LogManager.Error($"开始动画异常: {ex.Message}", ex); - - // 恢复按钮状态 - CanStartAnimation = true; - CanPauseAnimation = false; - CanStopAnimation = false; - }); - } - } - - /// - /// 异步暂停动画命令 - /// - private async Task ExecutePauseAnimationAsync() - { - try - { - await _uiStateManager.ExecuteUIUpdateAsync(() => - { - AnimationStatus = "动画状态: 已暂停"; - - CanStartAnimation = true; - CanPauseAnimation = false; - CanStopAnimation = true; - - StatusText = "动画已暂停"; - LogManager.Info("暂停动画播放"); - }); - } - catch (Exception ex) - { - LogManager.Error($"暂停动画异常: {ex.Message}", ex); - } - } - - /// - /// 异步停止动画命令 - /// - private async Task ExecuteStopAnimationAsync() - { - try - { - await _uiStateManager.ExecuteUIUpdateAsync(() => - { - AnimationStatus = "动画状态: 已停止"; - AnimationProgress = 0; - CurrentAnimationTime = 0.0; - - CanStartAnimation = true; - CanPauseAnimation = false; - CanStopAnimation = false; - - StatusText = "动画已停止"; - LogManager.Info("停止动画播放"); - }); - } - catch (Exception ex) - { - LogManager.Error($"停止动画异常: {ex.Message}", ex); - } - } - - /// - /// 异步碰撞检测命令(使用UIStateManager和Command Pattern) - /// - private async Task ExecuteRunCollisionDetectionAsync() - { - if (!CanRunCollisionDetection) - { - await _uiStateManager.ExecuteUIUpdateAsync(() => - { - StatusText = "碰撞检测条件不满足,无法开始检测"; - }); - return; - } - - try - { - // 更新UI状态 - await _uiStateManager.ExecuteUIUpdateAsync(() => - { - CollisionStatus = "正在运行碰撞检测..."; - CanRunCollisionDetection = false; - StatusText = "正在进行碰撞检测..."; - }); - - // 在后台线程执行碰撞检测 - var result = await Task.Run(() => - { - // 模拟碰撞检测过程 - System.Threading.Thread.Sleep(2000); - - // TODO: 集成ClashDetectiveIntegration运行碰撞检测 - // 这里可以使用CommandManager执行碰撞检测命令 - // return await _commandManager.ExecuteCommandAsync("RunCollisionDetection", new object[] { ... }); - - return new { - Success = true, - ConflictCount = 3, - Summary = "发现 3 个潜在碰撞点", - Details = "碰撞点位于模型的不同区域" - }; - }); - - // 更新结果 - await _uiStateManager.ExecuteUIUpdateAsync(() => - { - if (result.Success) - { - CollisionStatus = "碰撞检测完成"; - CollisionSummary = result.Summary; - HasCollisionResults = true; - StatusText = $"碰撞检测已完成,{result.Summary}"; - LogManager.Info($"碰撞检测完成: {result.Details}"); - } - else - { - CollisionStatus = "碰撞检测失败"; - CollisionSummary = "碰撞检测过程中发生错误"; - StatusText = "碰撞检测失败"; - } - - CanRunCollisionDetection = true; - }); - } - catch (Exception ex) - { - await _uiStateManager.ExecuteUIUpdateAsync(() => - { - CollisionStatus = "碰撞检测出错"; - CollisionSummary = $"错误: {ex.Message}"; - CanRunCollisionDetection = true; - StatusText = $"碰撞检测出错: {ex.Message}"; - LogManager.Error($"碰撞检测异常: {ex.Message}", ex); - }); - } - } - - /// - /// 异步查看碰撞报告命令 - /// - private async Task ExecuteViewCollisionReportAsync() - { - try - { - await _uiStateManager.ExecuteUIUpdateAsync(() => - { - StatusText = "正在生成碰撞检测报告..."; - LogManager.Info("开始生成碰撞检测报告"); - }); - - // 直接调用碰撞报告功能 - var reportCommand = NavisworksTransport.Commands.ViewCollisionReportCommand.CreateComprehensive(autoHighlight: true); - var result = await reportCommand.ExecuteAsync(System.Threading.CancellationToken.None); - - await _uiStateManager.ExecuteUIUpdateAsync(() => - { - if (result.IsSuccess) - { - StatusText = result.Message; - LogManager.Info($"碰撞报告生成成功: {result.Message}"); - } - else - { - StatusText = $"报告生成失败: {result.Message}"; - LogManager.Error($"碰撞报告生成失败: {result.Message}"); - } - }); - } - catch (Exception ex) - { - LogManager.Error($"查看碰撞报告异常: {ex.Message}", ex); - - await _uiStateManager.ExecuteUIUpdateAsync(() => - { - StatusText = $"报告生成异常: {ex.Message}"; - }); - } - } - - #endregion #region 统一状态栏方法 @@ -731,108 +165,5 @@ namespace NavisworksTransport.UI.WPF.ViewModels } #endregion - - #region 辅助方法 - - /// - /// 更新指令文本 - /// - public async Task UpdateInstructionTextAsync() - { - await SafeExecuteAsync(async () => - { - await _uiStateManager.ExecuteUIUpdateAsync(() => - { - if (NavisApplication.ActiveDocument?.Models?.Count > 0) - { - InstructionText = "请在主界面中点击选择模型"; - } - else - { - InstructionText = "请先打开一个Navisworks模型文件"; - } - }); - }, "更新指令文本"); - } - - /// - /// 更新选择显示 - /// - public async Task UpdateSelectionDisplayAsync() - { - await SafeExecuteAsync(async () => - { - await _uiStateManager.ExecuteUIUpdateAsync(() => - { - if (NavisApplication.ActiveDocument?.CurrentSelection?.SelectedItems?.Count > 0) - { - var selectedCount = NavisApplication.ActiveDocument.CurrentSelection.SelectedItems.Count; - SelectedModelsText = $"选中模型: {selectedCount} 个"; - } - else - { - SelectedModelsText = "选中模型: 0 个"; - } - }); - }, "更新选择显示"); - } - - - - - #endregion - - #region 向后兼容性接口 - - /// - /// 向后兼容:同步版本的更新指令文本方法 - /// - [Obsolete("请使用UpdateInstructionTextAsync方法以获得更好的性能", false)] - public void UpdateInstructionText() - { - Task.Run(async () => await UpdateInstructionTextAsync()); - } - - /// - /// 向后兼容:同步版本的更新选择显示方法 - /// - [Obsolete("请使用UpdateSelectionDisplayAsync方法以获得更好的性能", false)] - public void UpdateSelectionDisplay() - { - Task.Run(async () => await UpdateSelectionDisplayAsync()); - } - - - - /// - /// 向后兼容:提供CommandManager访问接口 - /// - public NavisworksTransport.Commands.CommandManager CommandManager => _commandManager; - - /// - /// 向后兼容:提供UIStateManager访问接口 - /// - public UIStateManager UIStateManager => _uiStateManager; - - /// - /// 验证ViewModel状态是否正常 - /// - public bool IsValidState() - { - return _uiStateManager != null && - _commandManager != null && - AvailableCategories != null; - } - - /// - /// 获取ViewModel状态信息 - /// - public string GetStateInfo() - { - return $"UIStateManager: {(_uiStateManager != null ? "已初始化" : "未初始化")}, " + - $"CommandManager: {(_commandManager != null ? "已初始化" : "未初始化")}"; - } - - #endregion } } \ No newline at end of file