diff --git a/src/Core/Config/ConfigManager.cs b/src/Core/Config/ConfigManager.cs index 873c3f8..4477b2a 100644 --- a/src/Core/Config/ConfigManager.cs +++ b/src/Core/Config/ConfigManager.cs @@ -213,28 +213,28 @@ namespace NavisworksTransport.Core.Config // 路径编辑配置 sb.AppendLine("[path_editing]"); sb.AppendLine("# 网格单元大小(米)- 推荐值:0.3-1.0"); - sb.AppendLine($"cell_size_meters = {config.PathEditing.CellSizeMeters}"); + sb.AppendLine($"cell_size_meters = {config.PathEditing.CellSizeMeters:0.0###}"); sb.AppendLine(); sb.AppendLine("# 最大高度差(米)- 楼梯、坡道可接受的高度阈值"); - sb.AppendLine($"max_height_diff_meters = {config.PathEditing.MaxHeightDiffMeters}"); + sb.AppendLine($"max_height_diff_meters = {config.PathEditing.MaxHeightDiffMeters:0.0###}"); sb.AppendLine(); sb.AppendLine("# 车辆长度(米)"); - sb.AppendLine($"vehicle_length_meters = {config.PathEditing.VehicleLengthMeters}"); + sb.AppendLine($"vehicle_length_meters = {config.PathEditing.VehicleLengthMeters:0.0###}"); sb.AppendLine(); sb.AppendLine("# 车辆宽度(米)"); - sb.AppendLine($"vehicle_width_meters = {config.PathEditing.VehicleWidthMeters}"); + sb.AppendLine($"vehicle_width_meters = {config.PathEditing.VehicleWidthMeters:0.0###}"); sb.AppendLine(); sb.AppendLine("# 车辆高度(米)"); - sb.AppendLine($"vehicle_height_meters = {config.PathEditing.VehicleHeightMeters}"); + sb.AppendLine($"vehicle_height_meters = {config.PathEditing.VehicleHeightMeters:0.0###}"); sb.AppendLine(); sb.AppendLine("# 安全间隙(米)"); - sb.AppendLine($"safety_margin_meters = {config.PathEditing.SafetyMarginMeters}"); + sb.AppendLine($"safety_margin_meters = {config.PathEditing.SafetyMarginMeters:0.00###}"); sb.AppendLine(); // 可视化配置 sb.AppendLine("[visualization]"); sb.AppendLine("# 地图边距比例(0-1之间)"); - sb.AppendLine($"margin_ratio = {config.Visualization.MarginRatio}"); + sb.AppendLine($"margin_ratio = {config.Visualization.MarginRatio:0.0###}"); sb.AppendLine(); // 动画配置 @@ -243,10 +243,10 @@ namespace NavisworksTransport.Core.Config sb.AppendLine($"frame_rate = {config.Animation.FrameRate}"); sb.AppendLine(); sb.AppendLine("# 动画持续时间(秒)"); - sb.AppendLine($"duration_seconds = {config.Animation.DurationSeconds}"); + sb.AppendLine($"duration_seconds = {config.Animation.DurationSeconds:0.0###}"); sb.AppendLine(); sb.AppendLine("# 检测间隙(米)"); - sb.AppendLine($"detection_gap_meters = {config.Animation.DetectionGapMeters}"); + sb.AppendLine($"detection_gap_meters = {config.Animation.DetectionGapMeters:0.00###}"); sb.AppendLine(); // 物流属性配置 @@ -258,13 +258,13 @@ namespace NavisworksTransport.Core.Config sb.AppendLine($"priority = {config.Logistics.Priority}"); sb.AppendLine(); sb.AppendLine("# 高度限制(默认值:3.0米)"); - sb.AppendLine($"height_limit_meters = {config.Logistics.HeightLimitMeters}"); + sb.AppendLine($"height_limit_meters = {config.Logistics.HeightLimitMeters:0.0###}"); sb.AppendLine(); sb.AppendLine("# 速度限制(默认值:0.8米/秒)"); - sb.AppendLine($"speed_limit_meters_per_second = {config.Logistics.SpeedLimitMetersPerSecond}"); + sb.AppendLine($"speed_limit_meters_per_second = {config.Logistics.SpeedLimitMetersPerSecond:0.0###}"); sb.AppendLine(); sb.AppendLine("# 宽度限制(默认值:3.0米)"); - sb.AppendLine($"width_limit_meters = {config.Logistics.WidthLimitMeters}"); + sb.AppendLine($"width_limit_meters = {config.Logistics.WidthLimitMeters:0.0###}"); return sb.ToString(); } diff --git a/src/Core/PathPlanningManager.cs b/src/Core/PathPlanningManager.cs index 0ab45d2..11655c2 100644 --- a/src/Core/PathPlanningManager.cs +++ b/src/Core/PathPlanningManager.cs @@ -7,6 +7,7 @@ using Autodesk.Navisworks.Api.Plugins; using NavisworksTransport.PathPlanning; using NavisworksTransport.Utils; using NavisworksTransport.Core; +using NavisworksTransport.Core.Config; using NavisworksTransport.Commands; namespace NavisworksTransport @@ -189,31 +190,33 @@ namespace NavisworksTransport /// /// 初始化渲染插件的默认值 - /// 推送合理的网格大小和车辆参数,确保渲染插件在任何情况下都有正确的可视化效果 + /// 从配置文件读取网格大小和车辆参数,确保渲染插件在任何情况下都有正确的可视化效果 /// private void InitializeRenderPluginDefaults() { try { - // 设置默认网格大小(0.5米,适合大多数场景) - const double defaultGridSizeInMeters = 0.5; - _renderPlugin.SetGridSize(defaultGridSizeInMeters); - LogManager.Info($"[渲染插件初始化] 已设置默认网格大小: {defaultGridSizeInMeters}米"); + var config = ConfigManager.Instance.Current; - // 设置默认车辆参数(与PathEditingViewModel的默认值保持一致) - const double defaultVehicleLength = 1.0; // 米 - const double defaultVehicleWidth = 1.0; // 米 - const double defaultVehicleHeight = 2.0; // 米 - const double defaultSafetyMargin = 0.25; // 米 + // 从配置读取网格大小 + double gridSizeInMeters = config.PathEditing.CellSizeMeters; + _renderPlugin.SetGridSize(gridSizeInMeters); + LogManager.Info($"[渲染插件初始化] 已设置网格大小: {gridSizeInMeters}米(来自配置)"); + + // 从配置读取车辆参数 + double vehicleLength = config.PathEditing.VehicleLengthMeters; + double vehicleWidth = config.PathEditing.VehicleWidthMeters; + double vehicleHeight = config.PathEditing.VehicleHeightMeters; + double safetyMargin = config.PathEditing.SafetyMarginMeters; _renderPlugin.SetVehicleParameters( - defaultVehicleLength, - defaultVehicleWidth, - defaultVehicleHeight, - defaultSafetyMargin + vehicleLength, + vehicleWidth, + vehicleHeight, + safetyMargin ); - LogManager.Info($"[渲染插件初始化] 已设置默认车辆参数: 长={defaultVehicleLength}m, 宽={defaultVehicleWidth}m, 高={defaultVehicleHeight}m, 安全间隙={defaultSafetyMargin}m"); + LogManager.Info($"[渲染插件初始化] 已设置车辆参数: 长={vehicleLength:F1}m, 宽={vehicleWidth:F1}m, 高={vehicleHeight:F1}m, 安全间隙={safetyMargin:F2}m(来自配置)"); } catch (Exception ex) { diff --git a/src/PathPlanning/GridMapGenerator.cs b/src/PathPlanning/GridMapGenerator.cs index 5310f13..8ed1f87 100644 --- a/src/PathPlanning/GridMapGenerator.cs +++ b/src/PathPlanning/GridMapGenerator.cs @@ -327,6 +327,20 @@ namespace NavisworksTransport.PathPlanning // 一次性放置完整配置的GridCell gridMap.PlaceCell(gridPos, cell); LogManager.Info($"[门网格放置] 网格坐标({gridPos.X},{gridPos.Y}) 最终限速: {gridMap.GetCell(gridPos)?.SpeedLimit:F2}m/s"); + + // 为门添加可通行的高度层 + var doorLayer = new HeightLayer + { + Type = CategoryAttributeManager.LogisticsElementType.门, + Z = doorBottomZ, + PassableHeight = new HeightInterval(doorBottomZ, doorBottomZ + doorHeight), + IsWalkable = true, // 关键:门是可通行的 + SpeedLimit = doorSpeedLimit, + SourceItem = doorItem, + IsBoundary = false + }; + gridMap.AddHeightLayer(gridPos, doorLayer); + LogManager.Info($"[门高度层添加] 网格({gridPos.X},{gridPos.Y}) 高度范围: [{doorBottomZ:F2}, {doorBottomZ + doorHeight:F2}], 可通行高度: {doorHeight:F2}"); } processedCount++; diff --git a/src/UI/WPF/ViewModels/AnimationControlViewModel.cs b/src/UI/WPF/ViewModels/AnimationControlViewModel.cs index 3e84b9c..0f7e86a 100644 --- a/src/UI/WPF/ViewModels/AnimationControlViewModel.cs +++ b/src/UI/WPF/ViewModels/AnimationControlViewModel.cs @@ -68,10 +68,10 @@ namespace NavisworksTransport.UI.WPF.ViewModels private readonly ClashDetectiveIntegration _clashIntegration; private readonly UIStateManager _uiStateManager; - // 动画参数相关字段 + // 动画参数相关字段(从配置初始化) private ObservableCollection _availableFrameRates; - private int _selectedFrameRate = 30; - private double _animationDuration = 10.0; + private int _selectedFrameRate; + private double _animationDuration; private bool _canStartAnimation = true; private bool _canPauseAnimation = false; private bool _canStopAnimation = false; @@ -80,9 +80,9 @@ namespace NavisworksTransport.UI.WPF.ViewModels private bool _hasCollisionResults = false; private CollisionReportResult _lastGeneratedReport; // 缓存最后生成的报告 - // 碰撞检测参数字段 - private double _detectionGap = 0.05; // 检测间隙(米) - private int _animationFrameRate = 30; // 动画帧率(FPS) + // 碰撞检测参数字段(从配置初始化) + private double _detectionGap; // 检测间隙(米) + private int _animationFrameRate; // 动画帧率(FPS) // 当前选中路径 @@ -186,10 +186,8 @@ namespace NavisworksTransport.UI.WPF.ViewModels /// - /// 碰撞检测精度(米) - /// - /// - /// 步长(米) - 根据路径长度、帧率和时长计算得出 + /// 碰撞检测精度(米) - 步长,根据路径长度、帧率和时长计算得出 + /// 如果无法计算则返回0,表示数据不完整 /// public double CollisionDetectionAccuracy { @@ -201,15 +199,19 @@ namespace NavisworksTransport.UI.WPF.ViewModels // 步长 = 路径长度 / (帧率 * 时长) return Math.Round(pathLength / (_animationFrameRate * _animationDuration), 3); } - return 0.1; // 默认值 + + // 无法计算时返回0,让问题暴露 + if (pathLength <= 0 || _animationFrameRate <= 0 || _animationDuration <= 0) + { + LogManager.Warning($"[AnimationControlViewModel] 无法计算碰撞检测精度 - 路径长度:{pathLength}m, 帧率:{_animationFrameRate}fps, 时长:{_animationDuration}s"); + } + return 0; } } - /// - /// 运动速度(米/秒) - /// /// /// 运动速度(米/秒) - 根据路径长度和时长计算得出 + /// 如果无法计算则返回0,表示数据不完整 /// public double MovementSpeed { @@ -221,7 +223,13 @@ namespace NavisworksTransport.UI.WPF.ViewModels // 速度 = 路径长度 / 时长 return Math.Round(pathLength / _animationDuration, 2); } - return 1.0; // 默认值 + + // 无法计算时返回0,让问题暴露 + if (pathLength <= 0 || _animationDuration <= 0) + { + LogManager.Warning($"[AnimationControlViewModel] 无法计算运动速度 - 路径长度:{pathLength}m, 时长:{_animationDuration}s"); + } + return 0; } } /// diff --git a/src/UI/WPF/ViewModels/ModelSettingsViewModel.cs b/src/UI/WPF/ViewModels/ModelSettingsViewModel.cs index 3a4a6f2..220aad1 100644 --- a/src/UI/WPF/ViewModels/ModelSettingsViewModel.cs +++ b/src/UI/WPF/ViewModels/ModelSettingsViewModel.cs @@ -9,6 +9,7 @@ using System.Windows.Input; using Autodesk.Navisworks.Api; using NavisApplication = Autodesk.Navisworks.Api.Application; using NavisworksTransport.Core; +using NavisworksTransport.Core.Config; using NavisworksTransport.Commands; using NavisworksTransport.UI.WPF.Collections; using NavisworksTransport.UI.WPF.Commands; @@ -44,14 +45,14 @@ namespace NavisworksTransport.UI.WPF.ViewModels #region 状态字段 private bool _isProcessing; - private string _selectedModelsText = "请在主界面中选择需要设置的模型"; - private string _selectedCategory = "通道"; - private bool _isTraversable = true; - private int _priority = 5; - private double _widthLimit = 3.0; - private double _heightLimit = 3.0; - private double _speedLimit = 0.8; - private bool _isLogisticsOnlyMode = false; + private string _selectedModelsText; + private string _selectedCategory; + private bool _isTraversable; + private int _priority; + private double _widthLimit; + private double _heightLimit; + private double _speedLimit; + private bool _isLogisticsOnlyMode; private LogisticsModel _selectedLogisticsModel; @@ -366,6 +367,17 @@ namespace NavisworksTransport.UI.WPF.ViewModels { try { + // 从配置文件初始化默认值(必须在UI绑定之前完成) + var config = ConfigManager.Instance.Current; + _selectedModelsText = "请在主界面中选择需要设置的模型"; + _selectedCategory = "通道"; + _isTraversable = config.Logistics.Traversable; + _priority = config.Logistics.Priority; + _widthLimit = config.Logistics.WidthLimitMeters; + _heightLimit = config.Logistics.HeightLimitMeters; + _speedLimit = config.Logistics.SpeedLimitMetersPerSecond; + _isLogisticsOnlyMode = false; + // 获取UI状态管理器实例和设置主ViewModel引用到基类 _uiStateManager = UIStateManager.Instance; SetMainViewModel(mainViewModel); @@ -787,21 +799,23 @@ namespace NavisworksTransport.UI.WPF.ViewModels } /// - /// 重置为默认值 - 实现正确的业务逻辑与UI分离模式 + /// 重置为默认值 - 从配置文件读取默认值 /// private async Task ResetToDefaultsAsync() { await _uiStateManager.ExecuteUIUpdateAsync(() => { - SelectedCategory = "通道"; - IsTraversable = true; - Priority = 5; - WidthLimit = 3.0; - HeightLimit = 3.0; - SpeedLimit = 0.8; + var config = ConfigManager.Instance.Current; - UpdateMainStatus("已重置为默认值"); - LogManager.Info("已重置类别设置为默认值"); + SelectedCategory = "通道"; + IsTraversable = config.Logistics.Traversable; + Priority = config.Logistics.Priority; + WidthLimit = config.Logistics.WidthLimitMeters; + HeightLimit = config.Logistics.HeightLimitMeters; + SpeedLimit = config.Logistics.SpeedLimitMetersPerSecond; + + UpdateMainStatus("已重置为默认值(来自配置)"); + LogManager.Info($"已重置类别设置为默认值 - 可通行:{IsTraversable}, 优先级:{Priority}, 宽度:{WidthLimit:F1}m, 高度:{HeightLimit:F1}m, 速度:{SpeedLimit:F1}m/s"); }); } diff --git a/src/UI/WPF/ViewModels/PathEditingViewModel.cs b/src/UI/WPF/ViewModels/PathEditingViewModel.cs index 65c1c39..30fc149 100644 --- a/src/UI/WPF/ViewModels/PathEditingViewModel.cs +++ b/src/UI/WPF/ViewModels/PathEditingViewModel.cs @@ -70,15 +70,15 @@ namespace NavisworksTransport.UI.WPF.ViewModels private bool _isSelectingStartPoint = false; private bool _isSelectingEndPoint = false; - // 车辆参数 - 改为三个独立参数 - private double _vehicleLength = 1.0; // 车辆长度(米) - private double _vehicleWidth = 1.0; // 车辆宽度(米) - private double _vehicleHeight = 2.0; // 车辆高度(米) - private double _safetyMargin = 0.05; // 安全间隙(米) - - // 网格大小参数 + // 车辆参数 - 改为三个独立参数(从配置初始化) + private double _vehicleLength; // 车辆长度(米) + private double _vehicleWidth; // 车辆宽度(米) + private double _vehicleHeight; // 车辆高度(米) + private double _safetyMargin; // 安全间隙(米) + + // 网格大小参数(从配置初始化) private bool _isGridSizeManuallyEnabled = false; // 是否启用手动网格大小设置 - private double _gridSize = 0.5; // 网格大小(米) + private double _gridSize; // 网格大小(米) // 路径策略参数 private PathStrategyOption _selectedPathStrategy; @@ -585,7 +585,7 @@ namespace NavisworksTransport.UI.WPF.ViewModels _vehicleHeight = config.PathEditing.VehicleHeightMeters; _safetyMargin = config.PathEditing.SafetyMarginMeters; - LogManager.Info($"从配置加载参数 - 车辆: {_vehicleLength}x{_vehicleWidth}x{_vehicleHeight}米, 安全间隙: {_safetyMargin}米, 网格: {_gridSize}米"); + LogManager.Info($"从配置加载参数 - 车辆: {_vehicleLength:F1}x{_vehicleWidth:F1}x{_vehicleHeight:F1}米, 安全间隙: {_safetyMargin:F2}米, 网格: {_gridSize:F1}米"); } catch (Exception ex) { diff --git a/src/UI/WPF/ViewModels/TimeTagViewModel.cs b/src/UI/WPF/ViewModels/TimeTagViewModel.cs index dd85090..cc2f805 100644 --- a/src/UI/WPF/ViewModels/TimeTagViewModel.cs +++ b/src/UI/WPF/ViewModels/TimeTagViewModel.cs @@ -3,6 +3,7 @@ using System.Collections.ObjectModel; using System.ComponentModel; using System.Linq; using System.Runtime.CompilerServices; +using NavisworksTransport.Core.Config; using NavisworksTransport.PathPlanning; namespace NavisworksTransport.UI.WPF.ViewModels @@ -15,11 +16,11 @@ namespace NavisworksTransport.UI.WPF.ViewModels { #region 字段 - private double _defaultSpeed = 0.8; + private double _defaultSpeed; private bool _useElementSpeedLimit = true; private bool _isCalculating = false; - private double _totalDuration = 24.8; - private string _selectedRoute = "Route_A1"; + private double _totalDuration; + private string _selectedRoute; private readonly TimeMarkerCalculationService _timeCalculationService; private PathPlanningManager _pathPlanningManager; @@ -123,13 +124,17 @@ namespace NavisworksTransport.UI.WPF.ViewModels { try { + // 从配置读取默认速度 + var config = ConfigManager.Instance.Current; + _defaultSpeed = config.Logistics.SpeedLimitMetersPerSecond; + _timeCalculationService = new TimeMarkerCalculationService(); _pathPlanningManager = PathPlanningManager.GetActivePathManager(); - InitializeCollections(); + InitializeCollections(); LoadRouteData(_pathPlanningManager.CurrentRoute); - LogManager.Info("TimeTagViewModel初始化完成"); + LogManager.Info($"TimeTagViewModel初始化完成 - 默认速度: {_defaultSpeed:F1}m/s(来自配置)"); } catch (Exception ex) { @@ -404,15 +409,16 @@ namespace NavisworksTransport.UI.WPF.ViewModels } /// - /// 重置参数 + /// 重置参数 - 从配置读取默认值 /// public void ResetParameters() { try { - DefaultSpeed = 0.8; + var config = ConfigManager.Instance.Current; + DefaultSpeed = config.Logistics.SpeedLimitMetersPerSecond; UseElementSpeedLimit = true; - LogManager.Info("参数重置完成"); + LogManager.Info($"参数重置完成 - 默认速度: {DefaultSpeed:F1}m/s(来自配置)"); } catch (Exception ex) { diff --git a/src/UI/WPF/Views/AnimationControlView.xaml b/src/UI/WPF/Views/AnimationControlView.xaml index de964b2..5b76b11 100644 --- a/src/UI/WPF/Views/AnimationControlView.xaml +++ b/src/UI/WPF/Views/AnimationControlView.xaml @@ -72,8 +72,8 @@ NavisworksTransport 检测动画页签视图 - 采用与类别设置和分层管