diff --git a/src/UI/WPF/ViewModels/AnimationControlViewModel.cs b/src/UI/WPF/ViewModels/AnimationControlViewModel.cs index 52dc0ff..7fbe3f1 100644 --- a/src/UI/WPF/ViewModels/AnimationControlViewModel.cs +++ b/src/UI/WPF/ViewModels/AnimationControlViewModel.cs @@ -3103,50 +3103,9 @@ namespace NavisworksTransport.UI.WPF.ViewModels { var dialog = new CollisionAnalysisDialog(hotspots, totalCollisions); DialogHelper.SetOwnerSafely(dialog); - var result = dialog.ShowDialog(); - - if (result == null) - { - // 用户取消 - UpdateMainStatus("预计算碰撞分析已取消"); - return; - } - - if (dialog.ExcludedObjects.Count > 0) - { - // 用户选择了排除某些物体并重新生成 - LogManager.Info($"[碰撞分析] 用户选择排除 {dialog.ExcludedObjects.Count} 个物体并重新生成"); - - // 🔥 添加排除对象到UI列表(合并,自动去重) - AddExcludedObjectsToUIList(dialog.ExcludedObjects); - - // 🔥 从UI列表获取所有排除对象(包括之前手工添加的),设置到Manager并重新生成 - var allExcludedObjects = _excludedObjects.Select(e => e.ModelItem).Where(m => m != null).ToList(); - _pathAnimationManager.SetExcludedObjectsAndClearCache(allExcludedObjects); - - // 触发重新生成(使用 Dispatcher 避免阻塞 UI) - System.Windows.Application.Current.Dispatcher.BeginInvoke(new Action(() => - { - ExecuteGenerateAnimation(); - }), DispatcherPriority.Background); - - UpdateMainStatus($"已排除 {allExcludedObjects.Count} 个物体,正在重新生成..."); - } - else - { - // 用户选择直接继续(无排除对象) - LogManager.Info("[碰撞分析] 用户选择直接继续生成"); - UpdateMainStatus($"预计算碰撞分析完成,共 {totalCollisions} 个候选碰撞"); - - // 🔥 保存检测记录到数据库(保存测试配置) - var recordId = SaveCollisionDetectionRecord(); - if (recordId.HasValue && IsReusedHistoryRecord(recordId.Value)) - { - // 用户选择使用历史记录,跳过后续流程 - LogManager.Info("[碰撞分析] 用户选择使用历史记录,跳过动画生成"); - return; - } - } + dialog.Closed += (_, __) => HandleCollisionAnalysisDialogClosed(dialog, totalCollisions); + dialog.Show(); + dialog.Activate(); } catch (Exception ex) { @@ -3154,6 +3113,57 @@ namespace NavisworksTransport.UI.WPF.ViewModels } } + private void HandleCollisionAnalysisDialogClosed(CollisionAnalysisDialog dialog, int totalCollisions) + { + try + { + if (dialog == null) + { + return; + } + + switch (dialog.SelectedAction) + { + case CollisionAnalysisDialog.CollisionAnalysisAction.Regenerate: + LogManager.Info($"[碰撞分析] 用户选择排除 {dialog.ExcludedObjects.Count} 个物体并重新生成"); + + AddExcludedObjectsToUIList(dialog.ExcludedObjects); + + var allExcludedObjects = _excludedObjects.Select(e => e.ModelItem).Where(m => m != null).ToList(); + _pathAnimationManager.SetExcludedObjectsAndClearCache(allExcludedObjects); + + System.Windows.Application.Current.Dispatcher.BeginInvoke(new Action(() => + { + ExecuteGenerateAnimation(); + }), DispatcherPriority.Background); + + UpdateMainStatus($"已排除 {allExcludedObjects.Count} 个物体,正在重新生成..."); + break; + + case CollisionAnalysisDialog.CollisionAnalysisAction.Continue: + LogManager.Info("[碰撞分析] 用户选择直接继续生成"); + UpdateMainStatus($"预计算碰撞分析完成,共 {totalCollisions} 个候选碰撞"); + + var recordId = SaveCollisionDetectionRecord(); + if (recordId.HasValue && IsReusedHistoryRecord(recordId.Value)) + { + LogManager.Info("[碰撞分析] 用户选择使用历史记录,跳过动画生成"); + } + break; + + case CollisionAnalysisDialog.CollisionAnalysisAction.Cancel: + case CollisionAnalysisDialog.CollisionAnalysisAction.None: + default: + UpdateMainStatus("预计算碰撞分析已取消"); + break; + } + } + catch (Exception ex) + { + LogManager.Error($"[碰撞分析] 处理分析窗口结果失败: {ex.Message}", ex); + } + } + /// /// 保存检测记录到数据库 /// 在生成动画完成后调用,创建检测记录并保存当时的完整配置 diff --git a/src/UI/WPF/ViewModels/PathEditingViewModel.cs b/src/UI/WPF/ViewModels/PathEditingViewModel.cs index 902e4ae..7a279b4 100644 --- a/src/UI/WPF/ViewModels/PathEditingViewModel.cs +++ b/src/UI/WPF/ViewModels/PathEditingViewModel.cs @@ -125,7 +125,7 @@ namespace NavisworksTransport.UI.WPF.ViewModels private const double DefaultAssemblyReferenceRodLengthInMeters = 20.0; private static readonly double DefaultAssemblyReferenceRodDiameterInMeters = CalculateDefaultAssemblyReferenceRodDiameterInMeters(); private const double DefaultAssemblyAnchorVerticalOffsetInMeters = 0.0; - private const double AssemblyVisualizationPointDiameterInMeters = 0.10; + private const double AssemblyVisualizationPointDiameterInMeters = 0.05; private const double RailNormalOffsetNudgeStepInMeters = 0.1; private const double DefaultAssemblySphereCenterX = 0.0; private const double DefaultAssemblySphereCenterY = 0.0; @@ -1749,7 +1749,7 @@ namespace NavisworksTransport.UI.WPF.ViewModels private void CreateAssemblyLinearRoute(Point3D startPoint) { Point3D endPoint = AssemblyReferencePathManager.Instance.ReferenceLineEnd; - string routeName = $"直线装配_{_pathPlanningManager.Routes.Count + 1}"; + string routeName = $"人工_{DateTime.Now:MMdd_HHmmss}"; var route = new PathRoute(routeName) { @@ -1768,7 +1768,7 @@ namespace NavisworksTransport.UI.WPF.ViewModels _assemblyInstallationPlaneNormal.Z); } - route.AddPoint(new PathPoint(startPoint, "装配起点", PathPointType.StartPoint)); + route.AddPoint(new PathPoint(startPoint, "起点", PathPointType.StartPoint)); route.AddPoint(new PathPoint(endPoint, "装配终点", PathPointType.EndPoint)); if (!_pathPlanningManager.AddRoute(route)) diff --git a/src/UI/WPF/Views/CollisionAnalysisDialog.xaml b/src/UI/WPF/Views/CollisionAnalysisDialog.xaml index 8eed1aa..5e2679b 100644 --- a/src/UI/WPF/Views/CollisionAnalysisDialog.xaml +++ b/src/UI/WPF/Views/CollisionAnalysisDialog.xaml @@ -8,7 +8,6 @@ Height="720" Width="720" WindowStartupLocation="CenterOwner" ResizeMode="CanResize" - Topmost="True" Background="White"> @@ -97,67 +96,89 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + public partial class CollisionAnalysisDialog : Window { + public enum CollisionAnalysisAction + { + None, + Continue, + Regenerate, + Cancel + } + private List _viewModels; public List ExcludedObjects { get; private set; } + public CollisionAnalysisAction SelectedAction { get; private set; } = CollisionAnalysisAction.None; // 使用项目中定义的预计算碰撞结果高亮类别(紫色 #9C27B0) private const string PrecomputedHighlightCategory = ModelHighlightHelper.PrecomputeCollisionResultsCategory; @@ -122,17 +131,14 @@ namespace NavisworksTransport.UI.WPF.Views // 清除预计算高亮 ModelHighlightHelper.ClearCategory(PrecomputedHighlightCategory); - // 根据是否有排除对象设置对话框结果 if (ExcludedObjects.Count > 0) { - // 有排除对象,需要重新生成 - DialogResult = true; + SelectedAction = CollisionAnalysisAction.Regenerate; LogManager.Info($"[碰撞分析] 用户选择排除 {ExcludedObjects.Count} 个物体并重新生成"); } else { - // 没有排除对象,直接继续 - DialogResult = false; + SelectedAction = CollisionAnalysisAction.Continue; LogManager.Info("[碰撞分析] 用户选择直接继续生成(无排除对象)"); } @@ -144,10 +150,36 @@ namespace NavisworksTransport.UI.WPF.Views // 清除预计算高亮 ModelHighlightHelper.ClearCategory(PrecomputedHighlightCategory); - DialogResult = null; + SelectedAction = CollisionAnalysisAction.Cancel; Close(); } + private void SelectAllButton_Click(object sender, RoutedEventArgs e) + { + if (_viewModels == null) + { + return; + } + + foreach (var viewModel in _viewModels) + { + viewModel.IsExcluded = true; + } + } + + private void ClearAllButton_Click(object sender, RoutedEventArgs e) + { + if (_viewModels == null) + { + return; + } + + foreach (var viewModel in _viewModels) + { + viewModel.IsExcluded = false; + } + } + /// /// 视图模型 ///