彻底清理控件主窗口的代码
This commit is contained in:
parent
049673c6bb
commit
d8b65342e1
@ -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)
|
||||
{
|
||||
|
||||
@ -1622,46 +1622,6 @@ namespace NavisworksTransport.UI.WPF.ViewModels
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 将碰撞报告详情输出到日志
|
||||
/// </summary>
|
||||
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
|
||||
|
||||
|
||||
|
||||
@ -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<string> _availableCategories;
|
||||
|
||||
|
||||
private bool _isProcessing = false;
|
||||
|
||||
// UI状态管理和命令框架
|
||||
private readonly UIStateManager _uiStateManager;
|
||||
private readonly NavisworksTransport.Commands.CommandManager _commandManager;
|
||||
|
||||
// 动画参数相关字段
|
||||
private double _animationSpeed = 1.0;
|
||||
private ObservableCollection<int> _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 公共属性
|
||||
|
||||
/// <summary>
|
||||
/// 选中模型文本
|
||||
/// </summary>
|
||||
public string SelectedModelsText
|
||||
{
|
||||
get => _selectedModelsText;
|
||||
set => SetProperty(ref _selectedModelsText, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 指令文本
|
||||
/// </summary>
|
||||
public string InstructionText
|
||||
{
|
||||
get => _instructionText;
|
||||
set => SetProperty(ref _instructionText, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 状态文本
|
||||
@ -89,49 +31,6 @@ namespace NavisworksTransport.UI.WPF.ViewModels
|
||||
set => SetProperty(ref _statusText, value);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 路径集合
|
||||
/// </summary>
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 选中的路径
|
||||
/// </summary>
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 是否处于路径编辑模式
|
||||
/// </summary>
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 动画状态
|
||||
/// </summary>
|
||||
public string AnimationStatus
|
||||
{
|
||||
get => _animationStatus;
|
||||
set => SetProperty(ref _animationStatus, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 动画进度
|
||||
/// </summary>
|
||||
public double AnimationProgress
|
||||
{
|
||||
get => _animationProgress;
|
||||
set => SetProperty(ref _animationProgress, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 可用类别集合
|
||||
/// </summary>
|
||||
public ObservableCollection<string> AvailableCategories
|
||||
{
|
||||
get => _availableCategories;
|
||||
set => SetProperty(ref _availableCategories, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 是否正在处理中(用于统一状态栏进度条显示)
|
||||
/// </summary>
|
||||
@ -141,15 +40,17 @@ namespace NavisworksTransport.UI.WPF.ViewModels
|
||||
set => SetProperty(ref _isProcessing, value);
|
||||
}
|
||||
|
||||
private double _progressPercentage = 0;
|
||||
|
||||
/// <summary>
|
||||
/// 进度百分比(0-100,-1表示不确定进度)
|
||||
/// </summary>
|
||||
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
|
||||
/// </summary>
|
||||
public bool IsIndeterminateProgress => ProgressPercentage < 0;
|
||||
|
||||
#region 动画控制属性
|
||||
|
||||
/// <summary>
|
||||
/// 动画速度
|
||||
/// </summary>
|
||||
public double AnimationSpeed
|
||||
{
|
||||
get => _animationSpeed;
|
||||
set => SetProperty(ref _animationSpeed, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 可用帧率集合
|
||||
/// </summary>
|
||||
public ObservableCollection<int> AvailableFrameRates
|
||||
{
|
||||
get => _availableFrameRates;
|
||||
set => SetProperty(ref _availableFrameRates, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 选中的帧率
|
||||
/// </summary>
|
||||
public int SelectedFrameRate
|
||||
{
|
||||
get => _selectedFrameRate;
|
||||
set => SetProperty(ref _selectedFrameRate, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 动画持续时间(秒)
|
||||
/// </summary>
|
||||
public double AnimationDuration
|
||||
{
|
||||
get => _animationDuration;
|
||||
set => SetProperty(ref _animationDuration, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 是否启用循环播放
|
||||
/// </summary>
|
||||
public bool IsLoopEnabled
|
||||
{
|
||||
get => _isLoopEnabled;
|
||||
set => SetProperty(ref _isLoopEnabled, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 是否启用平滑过渡
|
||||
/// </summary>
|
||||
public bool IsSmoothTransition
|
||||
{
|
||||
get => _isSmoothTransition;
|
||||
set => SetProperty(ref _isSmoothTransition, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 当前动画时间
|
||||
/// </summary>
|
||||
public double CurrentAnimationTime
|
||||
{
|
||||
get => _currentAnimationTime;
|
||||
set => SetProperty(ref _currentAnimationTime, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 是否可以开始动画
|
||||
/// </summary>
|
||||
public bool CanStartAnimation
|
||||
{
|
||||
get => _canStartAnimation;
|
||||
set => SetProperty(ref _canStartAnimation, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 是否可以暂停动画
|
||||
/// </summary>
|
||||
public bool CanPauseAnimation
|
||||
{
|
||||
get => _canPauseAnimation;
|
||||
set => SetProperty(ref _canPauseAnimation, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 是否可以停止动画
|
||||
/// </summary>
|
||||
public bool CanStopAnimation
|
||||
{
|
||||
get => _canStopAnimation;
|
||||
set => SetProperty(ref _canStopAnimation, value);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 碰撞检测属性
|
||||
|
||||
/// <summary>
|
||||
/// 是否可以运行碰撞检测
|
||||
/// </summary>
|
||||
public bool CanRunCollisionDetection
|
||||
{
|
||||
get => _canRunCollisionDetection;
|
||||
set => SetProperty(ref _canRunCollisionDetection, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 是否有碰撞检测结果
|
||||
/// </summary>
|
||||
public bool HasCollisionResults
|
||||
{
|
||||
get => _hasCollisionResults;
|
||||
set => SetProperty(ref _hasCollisionResults, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 碰撞检测状态
|
||||
/// </summary>
|
||||
public string CollisionStatus
|
||||
{
|
||||
get => _collisionStatus;
|
||||
set => SetProperty(ref _collisionStatus, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 碰撞检测摘要
|
||||
/// </summary>
|
||||
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<int>();
|
||||
|
||||
// 初始化命令(使用新的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");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 初始化命令(使用Command Pattern框架)
|
||||
/// </summary>
|
||||
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框架");
|
||||
}, "初始化命令");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 初始化动画设置
|
||||
/// </summary>
|
||||
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("动画设置初始化完成");
|
||||
}, "初始化动画设置");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 初始化系统管理设置
|
||||
/// </summary>
|
||||
|
||||
#endregion
|
||||
|
||||
#region 命令实现
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 异步开始动画命令(使用UIStateManager和Command Pattern)
|
||||
/// </summary>
|
||||
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;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步暂停动画命令
|
||||
/// </summary>
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步停止动画命令
|
||||
/// </summary>
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步碰撞检测命令(使用UIStateManager和Command Pattern)
|
||||
/// </summary>
|
||||
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);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步查看碰撞报告命令
|
||||
/// </summary>
|
||||
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 辅助方法
|
||||
|
||||
/// <summary>
|
||||
/// 更新指令文本
|
||||
/// </summary>
|
||||
public async Task UpdateInstructionTextAsync()
|
||||
{
|
||||
await SafeExecuteAsync(async () =>
|
||||
{
|
||||
await _uiStateManager.ExecuteUIUpdateAsync(() =>
|
||||
{
|
||||
if (NavisApplication.ActiveDocument?.Models?.Count > 0)
|
||||
{
|
||||
InstructionText = "请在主界面中点击选择模型";
|
||||
}
|
||||
else
|
||||
{
|
||||
InstructionText = "请先打开一个Navisworks模型文件";
|
||||
}
|
||||
});
|
||||
}, "更新指令文本");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新选择显示
|
||||
/// </summary>
|
||||
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 向后兼容性接口
|
||||
|
||||
/// <summary>
|
||||
/// 向后兼容:同步版本的更新指令文本方法
|
||||
/// </summary>
|
||||
[Obsolete("请使用UpdateInstructionTextAsync方法以获得更好的性能", false)]
|
||||
public void UpdateInstructionText()
|
||||
{
|
||||
Task.Run(async () => await UpdateInstructionTextAsync());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 向后兼容:同步版本的更新选择显示方法
|
||||
/// </summary>
|
||||
[Obsolete("请使用UpdateSelectionDisplayAsync方法以获得更好的性能", false)]
|
||||
public void UpdateSelectionDisplay()
|
||||
{
|
||||
Task.Run(async () => await UpdateSelectionDisplayAsync());
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 向后兼容:提供CommandManager访问接口
|
||||
/// </summary>
|
||||
public NavisworksTransport.Commands.CommandManager CommandManager => _commandManager;
|
||||
|
||||
/// <summary>
|
||||
/// 向后兼容:提供UIStateManager访问接口
|
||||
/// </summary>
|
||||
public UIStateManager UIStateManager => _uiStateManager;
|
||||
|
||||
/// <summary>
|
||||
/// 验证ViewModel状态是否正常
|
||||
/// </summary>
|
||||
public bool IsValidState()
|
||||
{
|
||||
return _uiStateManager != null &&
|
||||
_commandManager != null &&
|
||||
AvailableCategories != null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取ViewModel状态信息
|
||||
/// </summary>
|
||||
public string GetStateInfo()
|
||||
{
|
||||
return $"UIStateManager: {(_uiStateManager != null ? "已初始化" : "未初始化")}, " +
|
||||
$"CommandManager: {(_commandManager != null ? "已初始化" : "未初始化")}";
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user