From a305ba31e18b0c8201a6ae85f169f697c6e347f1 Mon Sep 17 00:00:00 2001 From: tian <11429339@qq.com> Date: Mon, 2 Feb 2026 22:25:26 +0800 Subject: [PATCH] =?UTF-8?q?=E9=87=8D=E6=96=B0=E6=88=AA=E5=9B=BE=E4=BF=A1?= =?UTF-8?q?=E6=81=AF=E6=9B=B4=E6=96=B0=E8=87=B3=E6=95=B0=E6=8D=AE=E5=BA=93?= =?UTF-8?q?=EF=BC=8C=E5=90=8C=E6=97=B6=E5=AF=BC=E5=87=BAhtml?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- doc/requirement/todo_features.md | 4 +- .../GenerateCollisionReportCommand.cs | 30 ++++++++++++- src/Core/PathDatabase.cs | 45 +++++++++++++++++++ .../ViewModels/CollisionReportViewModel.cs | 42 +++++++++++++++-- 4 files changed, 113 insertions(+), 8 deletions(-) diff --git a/doc/requirement/todo_features.md b/doc/requirement/todo_features.md index cf7b397..337b289 100644 --- a/doc/requirement/todo_features.md +++ b/doc/requirement/todo_features.md @@ -9,9 +9,9 @@ 3、[x] (优化)修改吊装路径适应桁车空中路线(纵向+平移,有吊绳) 4、[x] (优化)对系统配置文件的修改即时起效 5、[ ] (优化)切换文档时重新加载数据库 -6、[ ] (优化)默认打开指定碰撞物体 +6、[x] (优化)默认打开指定碰撞物体 7、[ ] (优化)动画运行视角优化设计,不能只用俯视图 -8、[ ] (BUG)旧版配置文件要主动提示升级配置文件,不能崩溃 +8、[x] (BUG)旧版配置文件要主动提示升级配置文件,不能崩溃 ### [2026/1/26] diff --git a/src/Commands/GenerateCollisionReportCommand.cs b/src/Commands/GenerateCollisionReportCommand.cs index b52ebf7..6480f94 100644 --- a/src/Commands/GenerateCollisionReportCommand.cs +++ b/src/Commands/GenerateCollisionReportCommand.cs @@ -95,6 +95,7 @@ namespace NavisworksTransport.Commands public int UniqueCollidedObjectsCount { get; set; } // 新增:动画参数 + public string RouteId { get; set; } // 路径ID,用于数据库关联 public string PathName { get; set; } public int FrameRate { get; set; } public double Duration { get; set; } @@ -179,8 +180,10 @@ namespace NavisworksTransport.Commands result.DetectionTolerance = animationManager.DetectionTolerance; } - // 从数据库获取路径名称(不依赖动画管理器的状态,使用同步方法避免死锁) - result.PathName = GetPathNameFromDatabase(targetTestName) ?? "未知路径"; + // 从数据库获取路径名称和RouteId(不依赖动画管理器的状态,使用同步方法避免死锁) + var testInfo = GetTestInfoFromDatabase(targetTestName); + result.PathName = testInfo?.PathName ?? "未知路径"; + result.RouteId = testInfo?.RouteId; LogManager.Info($"碰撞报告计数 - 检查点: {result.AnimationCollisions}, Clash Detective: {result.TotalCollisions}"); @@ -513,6 +516,29 @@ namespace NavisworksTransport.Commands } } + /// + /// 从数据库获取测试信息(包括路径名称和RouteId) + /// + private ClashDetectiveResultRecord GetTestInfoFromDatabase(string testName) + { + var pathDatabase = PathPlanningManager.Instance?.GetPathDatabase(); + if (pathDatabase == null) + { + LogManager.Warning("无法获取PathDatabase实例"); + return null; + } + + try + { + return pathDatabase.GetClashDetectiveResultByTestName(testName); + } + catch (Exception ex) + { + LogManager.Error($"从数据库获取测试信息失败: {ex.Message}"); + return null; + } + } + /// /// 生成报告内容 /// diff --git a/src/Core/PathDatabase.cs b/src/Core/PathDatabase.cs index 3222e03..388b5b6 100644 --- a/src/Core/PathDatabase.cs +++ b/src/Core/PathDatabase.cs @@ -391,6 +391,51 @@ namespace NavisworksTransport } } + /// + /// 更新碰撞报告的截图信息(更新ClashDetectiveResults表) + /// + public void UpdateCollisionReportScreenshot(string routeId, string screenshotPath, + string screenshotFormat, int screenshotWidth, int screenshotHeight) + { + try + { + // 更新 ClashDetectiveResults 表(该表包含 ScreenshotPath 列) + // 更新该 RouteId 的最新记录 + var sql = @" + UPDATE ClashDetectiveResults + SET ScreenshotPath = @screenshotPath + WHERE RouteId = @routeId + AND Id = ( + SELECT Id FROM ClashDetectiveResults + WHERE RouteId = @routeId + ORDER BY TestTime DESC + LIMIT 1 + ) + "; + + using (var cmd = new SQLiteCommand(sql, _connection)) + { + cmd.Parameters.AddWithValue("@routeId", routeId ?? ""); + cmd.Parameters.AddWithValue("@screenshotPath", screenshotPath ?? (object)DBNull.Value); + var rowsAffected = cmd.ExecuteNonQuery(); + + if (rowsAffected > 0) + { + LogManager.Info($"碰撞报告截图已更新: RouteId={routeId}, 截图={screenshotPath}"); + } + else + { + LogManager.Warning($"未找到需要更新的碰撞记录: RouteId={routeId}"); + } + } + } + catch (Exception ex) + { + LogManager.Error($"更新碰撞报告截图失败: {ex.Message}", ex); + throw; + } + } + /// /// 更新路径名称(仅更新名称字段) /// diff --git a/src/UI/WPF/ViewModels/CollisionReportViewModel.cs b/src/UI/WPF/ViewModels/CollisionReportViewModel.cs index 6bd43a3..040a6e2 100644 --- a/src/UI/WPF/ViewModels/CollisionReportViewModel.cs +++ b/src/UI/WPF/ViewModels/CollisionReportViewModel.cs @@ -1014,19 +1014,53 @@ namespace NavisworksTransport.UI.WPF.ViewModels CurrentReport.ScreenshotWidth = dialog.ImageWidth; CurrentReport.ScreenshotHeight = dialog.ImageHeight; + // 保存到数据库 + try + { + var pathDatabase = PathPlanningManager.Instance?.GetPathDatabase(); + if (pathDatabase != null && !string.IsNullOrEmpty(CurrentReport.RouteId)) + { + pathDatabase.UpdateCollisionReportScreenshot( + CurrentReport.RouteId, + screenshotPath, + CurrentReport.ScreenshotFormat, + dialog.ImageWidth, + dialog.ImageHeight + ); + LogManager.Info($"碰撞报告截图已保存到数据库: RouteId={CurrentReport.RouteId}"); + } + else + { + LogManager.Warning("无法保存截图到数据库:PathDatabase不可用或RouteId为空"); + } + } + catch (Exception dbEx) + { + LogManager.Error($"保存截图到数据库失败: {dbEx.Message}"); + // 继续执行,不影响截图生成 + } + // 通知UI更新 OnPropertyChanged(nameof(CurrentReport)); OnPropertyChanged(nameof(ScreenshotPreviewSource)); + // 提示用户 + System.Windows.MessageBox.Show( + "截图已更新并保存到数据库。", + "截图更新成功", + System.Windows.MessageBoxButton.OK, + System.Windows.MessageBoxImage.Information); + LogManager.Info("碰撞场景截图已更新"); } } } catch (Exception ex) - { - LogManager.Error($"重新截图失败: {ex.Message}"); - System.Windows.MessageBox.Show($"重新截图失败: {ex.Message}", "错误", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Error); - } } + { + LogManager.Error($"重新截图失败: {ex.Message}"); + System.Windows.MessageBox.Show($"重新截图失败: {ex.Message}", "错误", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Error); + } + } /// /// 检查是否可以执行重新截图