修复参数配置错误和门网格高度层缺失错误

This commit is contained in:
tian 2025-10-11 18:39:06 +08:00
parent a938afd946
commit 37f03362c4
11 changed files with 141 additions and 96 deletions

View File

@ -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();
}

View File

@ -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
/// <summary>
/// 初始化渲染插件的默认值
/// 推送合理的网格大小和车辆参数,确保渲染插件在任何情况下都有正确的可视化效果
/// 从配置文件读取网格大小和车辆参数,确保渲染插件在任何情况下都有正确的可视化效果
/// </summary>
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)
{

View File

@ -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++;

View File

@ -68,10 +68,10 @@ namespace NavisworksTransport.UI.WPF.ViewModels
private readonly ClashDetectiveIntegration _clashIntegration;
private readonly UIStateManager _uiStateManager;
// 动画参数相关字段
// 动画参数相关字段(从配置初始化)
private ObservableCollection<int> _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
/// <summary>
/// 碰撞检测精度(米)
/// </summary>
/// <summary>
/// 步长(米) - 根据路径长度、帧率和时长计算得出
/// 碰撞检测精度(米) - 步长,根据路径长度、帧率和时长计算得出
/// 如果无法计算则返回0表示数据不完整
/// </summary>
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;
}
}
/// <summary>
/// 运动速度(米/秒)
/// </summary>
/// <summary>
/// 运动速度(米/秒) - 根据路径长度和时长计算得出
/// 如果无法计算则返回0表示数据不完整
/// </summary>
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;
}
}
/// <summary>

View File

@ -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
}
/// <summary>
/// 重置为默认值 - 实现正确的业务逻辑与UI分离模式
/// 重置为默认值 - 从配置文件读取默认值
/// </summary>
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");
});
}

View File

@ -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)
{

View File

@ -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
}
/// <summary>
/// 重置参数
/// 重置参数 - 从配置读取默认值
/// </summary>
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)
{

View File

@ -72,8 +72,8 @@ NavisworksTransport 检测动画页签视图 - 采用与类别设置和分层管
<Label Grid.Column="2" Content="帧/秒" Style="{StaticResource UnitLabelStyle}" Margin="0,0,30,0"/>
<Label Grid.Column="3" Content="持续时间:" Style="{StaticResource ParameterLabelStyle}"/>
<TextBox Grid.Column="4"
Text="{Binding AnimationDuration}"
<TextBox Grid.Column="4"
Text="{Binding AnimationDuration, StringFormat=0.0###}"
Style="{StaticResource ParameterInputStyle}"
Width="80"
Margin="5,2"/>

View File

@ -114,15 +114,15 @@ NavisworksTransport 类别设置页签视图 - 参考分层管理页签的设计
</Grid.ColumnDefinitions>
<Label Grid.Column="0" Content="限宽:" Style="{StaticResource ParameterLabelStyle}"/>
<TextBox Grid.Column="1"
Text="{Binding WidthLimit, StringFormat=F2}"
<TextBox Grid.Column="1"
Text="{Binding WidthLimit, StringFormat=0.0###}"
Style="{StaticResource ParameterInputStyle}"
ToolTip="通行宽度限制(米)"/>
<Label Grid.Column="2" Content="米" Style="{StaticResource UnitLabelStyle}"/>
<Label Grid.Column="3" Content="限高:" VerticalAlignment="Center" Margin="15,0,0,0"/>
<TextBox Grid.Column="4"
Text="{Binding HeightLimit, StringFormat=F2}"
<TextBox Grid.Column="4"
Text="{Binding HeightLimit, StringFormat=0.0###}"
Style="{StaticResource ParameterInputStyle}"
ToolTip="通行高度限制(米)"/>
<Label Grid.Column="5" Content="米" Style="{StaticResource UnitLabelStyle}"/>
@ -138,8 +138,8 @@ NavisworksTransport 类别设置页签视图 - 参考分层管理页签的设计
</Grid.ColumnDefinitions>
<Label Grid.Column="0" Content="限速:" Style="{StaticResource ParameterLabelStyle}"/>
<TextBox Grid.Column="1"
Text="{Binding SpeedLimit, StringFormat=F2}"
<TextBox Grid.Column="1"
Text="{Binding SpeedLimit, StringFormat=0.0###}"
Style="{StaticResource ParameterInputStyle}"
ToolTip="速度限制(米/秒)"/>
<Label Grid.Column="2" Content="米/秒" Style="{StaticResource UnitLabelStyle}" Width="40"/>

View File

@ -87,32 +87,32 @@ NavisworksTransport 路径编辑页签视图 - 采用与动画控制和分层管
<!-- 车辆长度 -->
<Label Grid.Row="0" Grid.Column="0" Content="车辆长度:" Style="{StaticResource ParameterLabelStyle}"/>
<TextBox Grid.Row="0" Grid.Column="1"
Text="{Binding VehicleLength}"
<TextBox Grid.Row="0" Grid.Column="1"
Text="{Binding VehicleLength, StringFormat=0.0###}"
Style="{StaticResource ParameterInputStyle}"
Width="60"/>
<Label Grid.Row="0" Grid.Column="2" Content="米" Style="{StaticResource UnitLabelStyle}" Margin="0,0,15,0"/>
<!-- 车辆宽度 -->
<Label Grid.Row="0" Grid.Column="3" Content="车辆宽度:" Style="{StaticResource ParameterLabelStyle}"/>
<TextBox Grid.Row="0" Grid.Column="4"
Text="{Binding VehicleWidth}"
<TextBox Grid.Row="0" Grid.Column="4"
Text="{Binding VehicleWidth, StringFormat=0.0###}"
Style="{StaticResource ParameterInputStyle}"
Width="60"/>
<Label Grid.Row="0" Grid.Column="5" Content="米" Style="{StaticResource UnitLabelStyle}"/>
<!-- 车辆高度 -->
<Label Grid.Row="1" Grid.Column="0" Content="车辆高度:" Style="{StaticResource ParameterLabelStyle}"/>
<TextBox Grid.Row="1" Grid.Column="1"
Text="{Binding VehicleHeight}"
<TextBox Grid.Row="1" Grid.Column="1"
Text="{Binding VehicleHeight, StringFormat=0.0###}"
Style="{StaticResource ParameterInputStyle}"
Width="60"/>
<Label Grid.Row="1" Grid.Column="2" Content="米" Style="{StaticResource UnitLabelStyle}" Margin="0,0,15,0"/>
<!-- 安全间隙 -->
<Label Grid.Row="1" Grid.Column="3" Content="安全间隙:" Style="{StaticResource ParameterLabelStyle}"/>
<TextBox Grid.Row="1" Grid.Column="4"
Text="{Binding SafetyMargin}"
<TextBox Grid.Row="1" Grid.Column="4"
Text="{Binding SafetyMargin, StringFormat=0.00###}"
Style="{StaticResource ParameterInputStyle}"
Width="60"/>
<Label Grid.Row="1" Grid.Column="5" Content="米" Style="{StaticResource UnitLabelStyle}"/>

View File

@ -108,7 +108,7 @@ NavisworksTransport 时间标签设置对话框 - 采用与主界面一致的Nav
<StackPanel Style="{StaticResource ParameterGroupStyle}">
<TextBlock Text="默认速度:" Style="{StaticResource ParameterLabelStyle}"/>
<TextBox Text="{Binding DefaultSpeed, StringFormat=F2}" Style="{StaticResource ParameterInputStyle}"/>
<TextBox Text="{Binding DefaultSpeed, StringFormat=0.0###}" Style="{StaticResource ParameterInputStyle}"/>
<TextBlock Text="m/s" FontSize="10" Foreground="#FF666666" VerticalAlignment="Center" Margin="5,0,0,0"/>
</StackPanel>