增加批处理高亮和报告生成功能

This commit is contained in:
tian 2026-01-26 12:48:24 +08:00
parent de55d7ea1b
commit d5d50d7568
2 changed files with 87 additions and 61 deletions

View File

@ -6,6 +6,7 @@ using Autodesk.Navisworks.Api;
using NavisworksTransport.Core.Animation;
using NavisworksTransport.Core.Collision;
using NavisworksTransport.Core.Models;
using NavisworksTransport.Utils;
namespace NavisworksTransport.Core
{
@ -235,7 +236,7 @@ namespace NavisworksTransport.Core
ClashDetectiveIntegration.InitializeCollisionDetectionCache(animatedObject);
// 在主线程执行Navisworks API调用
var frames = await UIStateManager.Instance.ExecuteUIUpdateAsync(() =>
var result = await UIStateManager.Instance.ExecuteUIUpdateAsync(() =>
{
// 预计算动画帧和碰撞
var config = new CollisionDetectionConfig
@ -250,7 +251,7 @@ namespace NavisworksTransport.Core
ReportGenerationEnabled = true
};
return _executor._processor.PrecomputeFrames(
var frames = _executor._processor.PrecomputeFrames(
pathRoute,
animatedObject,
isVirtualVehicle,
@ -262,65 +263,90 @@ namespace NavisworksTransport.Core
config.DetectionToleranceMeters,
null
);
// 检查预计算是否成功
if (frames == null || frames.Count == 0)
{
throw new InvalidOperationException("预计算动画帧失败:未生成任何帧");
}
// 提取碰撞结果
var collisions = frames.SelectMany(f => f.Collisions).ToList();
// 创建并运行ClashDetective测试直接在主线程执行避免异步切换导致的Navisworks Native对象生命周期问题
// 传入 pathPoints 参数,让 ClashDetective 测试完成后自动恢复到路径起点
var pathPoints = pathRoute.Points.Select(p => p.Position).ToList();
var testName = _executor._processor.CreateAndRunClashDetectiveTest(
collisions,
item.DetectionToleranceMeters,
pathRoute.Name,
pathRoute.Id,
animatedObject,
isVirtualVehicle,
item.FrameRate,
item.DurationSeconds,
item.VirtualVehicleLength,
item.VirtualVehicleWidth,
item.VirtualVehicleHeight,
pathPoints
);
// 🔥 使用 ClashDetective 确认的碰撞数,而不是预计算的碰撞数
item.CollisionCount = ClashDetectiveIntegration.Instance.ClashDetectiveCollisionCount;
// 保存测试名称
item.ClashDetectiveTestName = testName;
// 🔥 高亮碰撞结果(用于批处理中的截图和报告生成)
if (!string.IsNullOrEmpty(testName))
{
try
{
var clashIntegration = ClashDetectiveIntegration.Instance;
var clashResults = clashIntegration.GetCurrentPathClashResults(testName);
if (clashResults != null && clashResults.Count > 0)
{
ModelHighlightHelper.HighlightClashDetectiveResults(testName, clashIntegration.GetCurrentPathClashResults);
}
}
catch (Exception highlightEx)
{
LogManager.Error($"[批处理队列] 高亮碰撞结果失败: {highlightEx.Message}");
}
}
// 🔥 生成碰撞报告(包括截图)
if (!string.IsNullOrEmpty(testName))
{
try
{
var reportCommand = new Commands.GenerateCollisionReportCommand();
reportCommand.SetTestName(testName);
// 同步执行报告生成在UI线程中
var reportTask = reportCommand.ExecuteAsync();
reportTask.Wait(); // 等待报告生成完成
}
catch (Exception reportEx)
{
LogManager.Error($"[批处理队列] 生成碰撞报告失败: {reportEx.Message}");
// 报告生成失败不影响批处理流程
}
}
// 🔥 清除高亮(报告生成后)
try
{
ModelHighlightHelper.ClearClashDetectiveHighlights();
}
catch (Exception clearEx)
{
LogManager.Error($"[批处理队列] 清除高亮失败: {clearEx.Message}");
}
return testName;
});
// 检查预计算是否成功
if (frames == null || frames.Count == 0)
{
throw new InvalidOperationException("预计算动画帧失败:未生成任何帧");
}
// 提取碰撞结果
var collisions = frames.SelectMany(f => f.Collisions).ToList();
// 创建并运行ClashDetective测试直接在主线程执行避免异步切换导致的Navisworks Native对象生命周期问题
// 传入 pathPoints 参数,让 ClashDetective 测试完成后自动恢复到路径起点
var pathPoints = pathRoute.Points.Select(p => p.Position).ToList();
var testName = _executor._processor.CreateAndRunClashDetectiveTest(
collisions,
item.DetectionToleranceMeters,
pathRoute.Name,
pathRoute.Id,
animatedObject,
isVirtualVehicle,
item.FrameRate,
item.DurationSeconds,
item.VirtualVehicleLength,
item.VirtualVehicleWidth,
item.VirtualVehicleHeight,
pathPoints
);
// 🔥 使用 ClashDetective 确认的碰撞数,而不是预计算的碰撞数
item.CollisionCount = ClashDetectiveIntegration.Instance.ClashDetectiveCollisionCount;
// 保存测试名称
item.ClashDetectiveTestName = testName;
// 标记为完成
item.Status = BatchQueueStatus.Completed;

View File

@ -1419,7 +1419,7 @@ namespace NavisworksTransport
}
}
/// <summary>
/// <summary>
/// 清除所有缓存,在模型变化时调用
/// </summary>
public static void ClearAllCaches()