diff --git a/src/UI/WPF/ViewModels/CollisionReportViewModel.cs b/src/UI/WPF/ViewModels/CollisionReportViewModel.cs index cb3652c..72c801d 100644 --- a/src/UI/WPF/ViewModels/CollisionReportViewModel.cs +++ b/src/UI/WPF/ViewModels/CollisionReportViewModel.cs @@ -150,7 +150,14 @@ namespace NavisworksTransport.UI.WPF.ViewModels public bool IsGenerating { get => _isGenerating; - set => SetProperty(ref _isGenerating, value); + set + { + if (SetProperty(ref _isGenerating, value)) + { + // 刷新命令状态 + System.Windows.Input.CommandManager.InvalidateRequerySuggested(); + } + } } /// @@ -159,7 +166,14 @@ namespace NavisworksTransport.UI.WPF.ViewModels public bool HasCollisions { get => _hasCollisions; - set => SetProperty(ref _hasCollisions, value); + set + { + if (SetProperty(ref _hasCollisions, value)) + { + // 刷新命令状态 + System.Windows.Input.CommandManager.InvalidateRequerySuggested(); + } + } } /// @@ -415,7 +429,7 @@ namespace NavisworksTransport.UI.WPF.ViewModels Statistics = new CollisionReportStatistics(); // 初始化命令 - ExportReportCommand = new RelayCommand(async () => await ExportReportAsync(), () => !IsGenerating && HasCollisions); + ExportReportCommand = new RelayCommand(async () => await ExportReportAsync(), () => !IsGenerating); CloseCommand = new RelayCommand(CloseWindow); HighlightCollisionCommand = new RelayCommand(HighlightCollision, item => item?.CollisionData != null); AddScreenshotCommand = new RelayCommand(ExecuteAddScreenshot, CanExecuteAddScreenshot); @@ -908,229 +922,17 @@ namespace NavisworksTransport.UI.WPF.ViewModels } /// - /// 生成HTML报告 + /// 生成HTML报告 - 统一使用 CollisionReportHtmlGenerator /// private string GenerateHtmlReport(string htmlFilePath = null) { - var html = new StringBuilder(); - var now = DateTime.Now; - - // HTML头部和样式 - html.AppendLine(""); - html.AppendLine(""); - html.AppendLine(""); - html.AppendLine("NavisworksTransport 碰撞检测报告"); - html.AppendLine(""); - html.AppendLine(""); - - // 报告标题 - html.AppendLine($"

NavisworksTransport 碰撞检测报告

"); - html.AppendLine($"

生成时间: {now:yyyy年MM月dd日 HH:mm:ss}

"); - html.AppendLine($"

报告类型: {Statistics.ReportType}

"); - html.AppendLine($"

路径名称: {PathName}

"); - - // 总体统计 - html.AppendLine("
"); - html.AppendLine("

总体统计

"); - html.AppendLine("
"); - html.AppendLine("
"); - html.AppendLine("
总碰撞数
"); - html.AppendLine($"
{Statistics.TotalCollisions}
"); - html.AppendLine("
"); - html.AppendLine("
"); - html.AppendLine("
碰撞构件
"); - html.AppendLine($"
{UniqueCollidedObjectsCount}个
"); - html.AppendLine("
"); - html.AppendLine("
"); - html.AppendLine("
检测点
"); - html.AppendLine($"
{Statistics.AnimationCollisions}个
"); - html.AppendLine("
"); - html.AppendLine("
"); - html.AppendLine("
"); - - // 动画参数 - html.AppendLine("

动画参数

"); - html.AppendLine("
"); - html.AppendLine("
"); - html.AppendLine("
帧率
"); - html.AppendLine($"
{FrameRate} FPS
"); - html.AppendLine("
"); - html.AppendLine("
"); - html.AppendLine("
时长
"); - html.AppendLine($"
{Duration:F1} 秒
"); - html.AppendLine("
"); - html.AppendLine("
"); - html.AppendLine("
检测容差
"); - html.AppendLine($"
{DetectionTolerance:F2} 米
"); - html.AppendLine("
"); - html.AppendLine("
"); - - // 碰撞场景截图(支持多张) - var validScreenshots = Screenshots?.Where(s => !string.IsNullOrEmpty(s.FilePath) && File.Exists(s.FilePath)).ToList(); - if (validScreenshots?.Count > 0) + // 确保 CurrentReport 的截图列表与 ViewModel 同步 + if (CurrentReport != null && Screenshots != null) { - html.AppendLine("

碰撞场景截图

"); - - if (validScreenshots.Count > 1) - { - // 多张截图 - 画廊样式 - html.AppendLine(""); - - html.AppendLine(""); - } - else - { - // 单张截图 - var screenshot = validScreenshots.First(); - html.AppendLine("
"); - string relativePath = PathHelper.GetRelativePath(htmlFilePath, screenshot.FilePath); - html.AppendLine("
"); - html.AppendLine($"\"碰撞场景截图\""); - html.AppendLine("
"); - html.AppendLine($"

分辨率: {screenshot.Width} x {screenshot.Height}

"); - html.AppendLine($"

格式: {screenshot.Format}

"); - html.AppendLine("
"); - html.AppendLine("
"); - html.AppendLine("
"); - } - } - - // 运动构件信息 - if (!string.IsNullOrEmpty(MovingObjectInfo)) - { - html.AppendLine("

运动构件信息

"); - html.AppendLine("
"); - html.AppendLine($"🚛 {MovingObjectInfo}"); - html.AppendLine("
"); - } - - // 碰撞构件清单 - if (CollidedObjectsList?.Count > 0) - { - html.AppendLine("

碰撞构件清单

"); - html.AppendLine("
"); - int index = 1; - foreach (var objName in CollidedObjectsList.Take(50)) // 限制显示前50个 - { - html.AppendLine($"
{index}. {objName}
"); - index++; - } - if (CollidedObjectsList.Count > 50) - { - html.AppendLine($"
... 还有 {CollidedObjectsList.Count - 50} 个构件
"); - } - html.AppendLine("
"); - } - - // 总结与建议 - html.AppendLine("

总结与建议

"); - html.AppendLine("
"); - html.AppendLine($"

{SummaryMessage}

"); - if (!string.IsNullOrEmpty(RecommendationMessage)) - { - html.AppendLine("

建议措施:

"); - var recommendations = RecommendationMessage.Split('\n'); - html.AppendLine("
    "); - foreach (var recommendation in recommendations) - { - if (!string.IsNullOrWhiteSpace(recommendation)) - { - html.AppendLine($"
  • {recommendation}
  • "); - } - } - html.AppendLine("
"); - } - html.AppendLine("
"); - - // 详细碰撞信息(前10个) - if (HasCollisions && AnimationCollisions?.Count > 0) - { - html.AppendLine("

碰撞详情

"); - foreach (var collision in AnimationCollisions.Take(10)) - { - html.AppendLine("
"); - html.AppendLine($"
{collision.Title}
"); - - // 状态标签 - var statusClass = GetStatusCssClass(collision.StatusText); - html.AppendLine($"{collision.StatusText}"); - - html.AppendLine($"

{collision.Description}

"); - html.AppendLine($"

{collision.Details}

"); - html.AppendLine("
"); - } - if (AnimationCollisions.Count > 10) - { - html.AppendLine($"

... 还有 {AnimationCollisions.Count - 10} 个碰撞未显示

"); - } - } - - // HTML结尾 - html.AppendLine($"
"); - html.AppendLine($"

报告生成完成 - {now:HH:mm:ss}

"); - html.AppendLine(""); - - return html.ToString(); - } - - /// - /// 获取状态对应的CSS类名 - /// - private string GetStatusCssClass(string statusText) - { - switch (statusText) - { - case "新发现": return "status-new"; - case "活跃": return "status-active"; - case "已审阅": return "status-reviewed"; - case "已批准": return "status-approved"; - case "已解决": return "status-resolved"; - default: return ""; + CurrentReport.Screenshots = Screenshots.ToList(); } + + return CollisionReportHtmlGenerator.GenerateHtmlReport(CurrentReport, htmlFilePath); } /// diff --git a/src/UI/WPF/Views/CollisionReportDialog.xaml b/src/UI/WPF/Views/CollisionReportDialog.xaml index be44862..e6ce6fc 100644 --- a/src/UI/WPF/Views/CollisionReportDialog.xaml +++ b/src/UI/WPF/Views/CollisionReportDialog.xaml @@ -539,8 +539,7 @@ NavisworksTransport 碰撞检测报告对话框 - 采用与主界面一致的Nav