对齐配置参数

This commit is contained in:
tian 2025-10-11 17:36:33 +08:00
parent 7343133f12
commit a938afd946
20 changed files with 302 additions and 1569 deletions

View File

@ -180,7 +180,6 @@
<Compile Include="src\PathPlanning\SlopeAnalyzer.cs" />
<Compile Include="src\PathPlanning\OptimizedHeightCalculator.cs" />
<Compile Include="src\PathPlanning\ChannelBasedGridBuilder.cs" />
<Compile Include="src\PathPlanning\VerticalScanProcessor.cs" />
<Compile Include="src\PathPlanning\PathOptimizer.cs" />
<Compile Include="src\PathPlanning\TimeMarkerCalculationService.cs" />
<Compile Include="src\PathPlanning\GridMapCacheKey.cs" />

View File

@ -1,56 +0,0 @@
using System;
using NavisworksTransport.Core.Config;
namespace NavisworksTransport.Tests
{
/// <summary>
/// 配置管理器测试程序
/// 使用方法:在 MainPlugin 的 Execute 方法中临时调用 TestConfigManager.RunTests()
/// </summary>
public class TestConfigManager
{
public static void RunTests()
{
Console.WriteLine("=== 开始测试配置管理器 ===");
Console.WriteLine();
// 测试 1加载或创建默认配置
Console.WriteLine("测试 1: 加载或创建默认配置");
var config = ConfigManager.Instance.Current;
Console.WriteLine($"配置文件路径: {ConfigManager.ConfigFilePath}");
Console.WriteLine($"网格尺寸: {config.GridGeneration.CellSizeMeters} 米");
Console.WriteLine($"车辆半径: {config.GridGeneration.VehicleRadiusMeters} 米");
Console.WriteLine($"路径策略: {config.PathPlanning.DefaultPathStrategy}");
Console.WriteLine();
// 测试 2修改配置并保存
Console.WriteLine("测试 2: 修改配置并保存");
config.GridGeneration.CellSizeMeters = 0.6;
config.PathPlanning.DefaultPathStrategy = "SafetyFirst";
config.Visualization.EnableGridVisualization = true;
ConfigManager.Instance.SaveConfig(config);
Console.WriteLine("配置已保存");
Console.WriteLine();
// 测试 3重新加载配置
Console.WriteLine("测试 3: 重新加载配置");
ConfigManager.Instance.Reload();
var reloadedConfig = ConfigManager.Instance.Current;
Console.WriteLine($"重载后网格尺寸: {reloadedConfig.GridGeneration.CellSizeMeters} 米");
Console.WriteLine($"重载后路径策略: {reloadedConfig.PathPlanning.DefaultPathStrategy}");
Console.WriteLine($"重载后网格可视化: {reloadedConfig.Visualization.EnableGridVisualization}");
Console.WriteLine();
// 测试 4重置为默认配置
Console.WriteLine("测试 4: 重置为默认配置");
ConfigManager.Instance.ResetToDefault();
var defaultConfig = ConfigManager.Instance.Current;
Console.WriteLine($"重置后网格尺寸: {defaultConfig.GridGeneration.CellSizeMeters} 米");
Console.WriteLine($"重置后路径策略: {defaultConfig.PathPlanning.DefaultPathStrategy}");
Console.WriteLine();
Console.WriteLine("=== 测试完成 ===");
Console.WriteLine($"请检查配置文件: {ConfigManager.ConfigFilePath}");
}
}
}

View File

@ -1,76 +1,51 @@
# NavisworksTransport 系统配置文件
# 单位说明:长度单位均为米(m),时间单位为秒(s)
# 自动生成时间: 2025-10-11 10:50:00
# 单位说明:长度单位均为米(m)
[grid_generation]
# 网格单元大小(米)- 推荐值0.3-0.8
[path_editing]
# 网格单元大小(米)- 推荐值0.3-1.0
cell_size_meters = 0.5
# 车辆半径(米)- 用于障碍物膨胀计算
vehicle_radius_meters = 0.3
# 安全间隙(米)- 额外的安全距离
safety_margin_meters = 0.2
# 膨胀半径(网格单元数)
inflation_radius_cells = 2
# 扫描高度(米)
scan_height_meters = 0.1
[path_planning]
# 最大高度差(米)- 楼梯、坡道可接受的高度阈值
max_height_diff_meters = 0.35
# 车辆尺寸(米)
# 车辆长度(米)
vehicle_length_meters = 1.0
# 车辆宽度(米)
vehicle_width_meters = 1.0
# 车辆高度(米)
vehicle_height_meters = 2.0
vehicle_length_meters = 2.5
vehicle_width_meters = 1.8
# 默认路径策略:"Shortest" | "Straightest" | "SafetyFirst"
default_path_strategy = "Straightest"
# 启用路径优化(减少转弯点)
enable_path_optimization = true
# 安全间隙(米)
safety_margin_meters = 0.05
[visualization]
# 网格点大小(像素)
grid_point_size = 5.0
# 路径线宽(像素)
path_line_width = 2.0
# 路径点大小(模型单位)
path_point_size = 50.0
# 启用网格可视化
enable_grid_visualization = false
# 启用多层网格可视化
enable_multi_layer_visualization = true
# 地图边距比例0-1之间
margin_ratio = 0.1
[animation]
# 默认动画速度(米/秒)
default_speed_meters_per_second = 1.5
# 动画帧率(帧/秒)
frame_rate = 30
# 步进间隔(毫秒)
step_interval_ms = 100
# 动画持续时间(秒)
duration_seconds = 10.0
# 启用平滑插值
enable_smooth_interpolation = true
# 检测间隙(米)
detection_gap_meters = 0.05
[collision]
# 碰撞检测步长(米
detection_step_meters = 0.1
[logistics]
# 可通行性默认值true
traversable = true
# 碰撞容差(米
collision_tolerance_meters = 0.01
# 优先级默认值5范围1-5
priority = 5
# 启用实时碰撞检测
enable_realtime_detection = true
# 高度限制默认值3.0米)
height_limit_meters = 3.0
# 自动生成碰撞报告
auto_generate_report = true
# 速度限制默认值0.8米/秒)
speed_limit_meters_per_second = 0.8
# 宽度限制默认值3.0米)
width_limit_meters = 3.0

View File

@ -277,10 +277,10 @@ namespace NavisworksTransport.Commands
item
};
// 使用配置的默认值添加物流属性
int affectedCount = CategoryAttributeManager.AddLogisticsAttributes(
itemCollection,
_parameters.ElementType,
_parameters.IsTraversable ?? true);
_parameters.ElementType);
bool success = affectedCount > 0;

View File

@ -95,7 +95,7 @@ namespace NavisworksTransport.Core.Animation
// === 预计算动画系统 ===
private List<AnimationFrame> _animationFrames; // 所有帧数据
private int _currentFrameIndex = 0; // 当前帧索引
private HashSet<ModelItem> _currentHighlightedItems; // 当前高亮的对象
private List<CollisionResult> _allCollisionResults; // 所有碰撞结果(不去重)
private bool _lastHighlightState = false; // 上一帧的高亮状态
@ -158,7 +158,6 @@ namespace NavisworksTransport.Core.Animation
{
_pathPoints = new List<Point3D>();
_animationFrames = new List<AnimationFrame>();
_currentHighlightedItems = new HashSet<ModelItem>();
_allCollisionResults = new List<CollisionResult>();
// 初始化动画模式
@ -363,7 +362,6 @@ namespace NavisworksTransport.Core.Animation
// 初始化帧列表
_animationFrames = new List<AnimationFrame>();
_currentHighlightedItems = new HashSet<ModelItem>();
_allCollisionResults = new List<CollisionResult>();
_currentFrameIndex = 0;

View File

@ -138,9 +138,6 @@ namespace NavisworksTransport
}
}
private DateTime _lastCollisionTestTime = DateTime.MinValue;
private readonly TimeSpan _minTestInterval = TimeSpan.FromMilliseconds(500); // 最小间隔500ms
/// <summary>
/// 缓存碰撞结果(动画过程中使用)- 现在包含位置信息用于恢复测试
/// 使用精确的碰撞检测算法替代简化检测

View File

@ -119,32 +119,18 @@ namespace NavisworksTransport.Core.Config
var model = Toml.ToModel(tomlContent);
var config = new SystemConfig();
// 加载网格生成配置
if (model.ContainsKey("grid_generation"))
// 加载路径编辑配置
if (model.ContainsKey("path_editing"))
{
var gridGen = model["grid_generation"] as TomlTable;
if (gridGen != null)
var pathEdit = model["path_editing"] as TomlTable;
if (pathEdit != null)
{
config.GridGeneration.CellSizeMeters = GetDouble(gridGen, "cell_size_meters", 0.5);
config.GridGeneration.VehicleRadiusMeters = GetDouble(gridGen, "vehicle_radius_meters", 0.3);
config.GridGeneration.SafetyMarginMeters = GetDouble(gridGen, "safety_margin_meters", 0.2);
config.GridGeneration.InflationRadiusCells = GetInt(gridGen, "inflation_radius_cells", 2);
config.GridGeneration.ScanHeightMeters = GetDouble(gridGen, "scan_height_meters", 0.1);
}
}
// 加载路径规划配置
if (model.ContainsKey("path_planning"))
{
var pathPlan = model["path_planning"] as TomlTable;
if (pathPlan != null)
{
config.PathPlanning.MaxHeightDiffMeters = GetDouble(pathPlan, "max_height_diff_meters", 0.35);
config.PathPlanning.VehicleHeightMeters = GetDouble(pathPlan, "vehicle_height_meters", 2.0);
config.PathPlanning.VehicleLengthMeters = GetDouble(pathPlan, "vehicle_length_meters", 2.5);
config.PathPlanning.VehicleWidthMeters = GetDouble(pathPlan, "vehicle_width_meters", 1.8);
config.PathPlanning.DefaultPathStrategy = GetString(pathPlan, "default_path_strategy", "Straightest");
config.PathPlanning.EnablePathOptimization = GetBool(pathPlan, "enable_path_optimization", true);
config.PathEditing.CellSizeMeters = GetDouble(pathEdit, "cell_size_meters", 0.5);
config.PathEditing.MaxHeightDiffMeters = GetDouble(pathEdit, "max_height_diff_meters", 0.35);
config.PathEditing.VehicleLengthMeters = GetDouble(pathEdit, "vehicle_length_meters", 1.0);
config.PathEditing.VehicleWidthMeters = GetDouble(pathEdit, "vehicle_width_meters", 1.0);
config.PathEditing.VehicleHeightMeters = GetDouble(pathEdit, "vehicle_height_meters", 2.0);
config.PathEditing.SafetyMarginMeters = GetDouble(pathEdit, "safety_margin_meters", 0.05);
}
}
@ -154,11 +140,7 @@ namespace NavisworksTransport.Core.Config
var visual = model["visualization"] as TomlTable;
if (visual != null)
{
config.Visualization.GridPointSize = GetDouble(visual, "grid_point_size", 5.0);
config.Visualization.PathLineWidth = GetDouble(visual, "path_line_width", 2.0);
config.Visualization.PathPointSize = GetDouble(visual, "path_point_size", 50.0);
config.Visualization.EnableGridVisualization = GetBool(visual, "enable_grid_visualization", false);
config.Visualization.EnableMultiLayerVisualization = GetBool(visual, "enable_multi_layer_visualization", true);
config.Visualization.MarginRatio = GetDouble(visual, "margin_ratio", 0.1);
}
}
@ -168,23 +150,23 @@ namespace NavisworksTransport.Core.Config
var anim = model["animation"] as TomlTable;
if (anim != null)
{
config.Animation.DefaultSpeedMetersPerSecond = GetDouble(anim, "default_speed_meters_per_second", 1.5);
config.Animation.FrameRate = GetInt(anim, "frame_rate", 30);
config.Animation.StepIntervalMs = GetInt(anim, "step_interval_ms", 100);
config.Animation.EnableSmoothInterpolation = GetBool(anim, "enable_smooth_interpolation", true);
config.Animation.DurationSeconds = GetDouble(anim, "duration_seconds", 10.0);
config.Animation.DetectionGapMeters = GetDouble(anim, "detection_gap_meters", 0.05);
}
}
// 加载碰撞检测配置
if (model.ContainsKey("collision"))
// 加载物流属性配置
if (model.ContainsKey("logistics"))
{
var collision = model["collision"] as TomlTable;
if (collision != null)
var logistics = model["logistics"] as TomlTable;
if (logistics != null)
{
config.Collision.DetectionStepMeters = GetDouble(collision, "detection_step_meters", 0.1);
config.Collision.CollisionToleranceMeters = GetDouble(collision, "collision_tolerance_meters", 0.01);
config.Collision.EnableRealtimeDetection = GetBool(collision, "enable_realtime_detection", true);
config.Collision.AutoGenerateReport = GetBool(collision, "auto_generate_report", true);
config.Logistics.Traversable = GetBool(logistics, "traversable", true);
config.Logistics.Priority = GetInt(logistics, "priority", 5);
config.Logistics.HeightLimitMeters = GetDouble(logistics, "height_limit_meters", 3.0);
config.Logistics.SpeedLimitMetersPerSecond = GetDouble(logistics, "speed_limit_meters_per_second", 0.8);
config.Logistics.WidthLimitMeters = GetDouble(logistics, "width_limit_meters", 3.0);
}
}
@ -224,91 +206,65 @@ namespace NavisworksTransport.Core.Config
// 添加文件头注释
sb.AppendLine("# NavisworksTransport 系统配置文件");
sb.AppendLine("# 单位说明:长度单位均为米(m),时间单位为秒(s)");
sb.AppendLine("# 单位说明:长度单位均为米(m)");
sb.AppendLine("# 自动生成时间: " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
sb.AppendLine();
// 网格生成配置
sb.AppendLine("[grid_generation]");
sb.AppendLine("# 网格单元大小(米)- 推荐值0.3-0.8");
sb.AppendLine($"cell_size_meters = {config.GridGeneration.CellSizeMeters}");
// 路径编辑配置
sb.AppendLine("[path_editing]");
sb.AppendLine("# 网格单元大小(米)- 推荐值0.3-1.0");
sb.AppendLine($"cell_size_meters = {config.PathEditing.CellSizeMeters}");
sb.AppendLine();
sb.AppendLine("# 车辆半径(米)- 用于障碍物膨胀计算");
sb.AppendLine($"vehicle_radius_meters = {config.GridGeneration.VehicleRadiusMeters}");
sb.AppendLine();
sb.AppendLine("# 安全间隙(米)- 额外的安全距离");
sb.AppendLine($"safety_margin_meters = {config.GridGeneration.SafetyMarginMeters}");
sb.AppendLine();
sb.AppendLine("# 膨胀半径(网格单元数)");
sb.AppendLine($"inflation_radius_cells = {config.GridGeneration.InflationRadiusCells}");
sb.AppendLine();
sb.AppendLine("# 扫描高度(米)");
sb.AppendLine($"scan_height_meters = {config.GridGeneration.ScanHeightMeters}");
sb.AppendLine();
// 路径规划配置
sb.AppendLine("[path_planning]");
sb.AppendLine("# 最大高度差(米)- 楼梯、坡道可接受的高度阈值");
sb.AppendLine($"max_height_diff_meters = {config.PathPlanning.MaxHeightDiffMeters}");
sb.AppendLine($"max_height_diff_meters = {config.PathEditing.MaxHeightDiffMeters}");
sb.AppendLine();
sb.AppendLine("# 车辆尺寸(米)");
sb.AppendLine($"vehicle_height_meters = {config.PathPlanning.VehicleHeightMeters}");
sb.AppendLine($"vehicle_length_meters = {config.PathPlanning.VehicleLengthMeters}");
sb.AppendLine($"vehicle_width_meters = {config.PathPlanning.VehicleWidthMeters}");
sb.AppendLine("# 车辆长度(米)");
sb.AppendLine($"vehicle_length_meters = {config.PathEditing.VehicleLengthMeters}");
sb.AppendLine();
sb.AppendLine("# 默认路径策略:\"Shortest\" | \"Straightest\" | \"SafetyFirst\"");
sb.AppendLine($"default_path_strategy = \"{config.PathPlanning.DefaultPathStrategy}\"");
sb.AppendLine("# 车辆宽度(米)");
sb.AppendLine($"vehicle_width_meters = {config.PathEditing.VehicleWidthMeters}");
sb.AppendLine();
sb.AppendLine("# 启用路径优化(减少转弯点)");
sb.AppendLine($"enable_path_optimization = {config.PathPlanning.EnablePathOptimization.ToString().ToLower()}");
sb.AppendLine("# 车辆高度(米)");
sb.AppendLine($"vehicle_height_meters = {config.PathEditing.VehicleHeightMeters}");
sb.AppendLine();
sb.AppendLine("# 安全间隙(米)");
sb.AppendLine($"safety_margin_meters = {config.PathEditing.SafetyMarginMeters}");
sb.AppendLine();
// 可视化配置
sb.AppendLine("[visualization]");
sb.AppendLine("# 网格点大小(像素)");
sb.AppendLine($"grid_point_size = {config.Visualization.GridPointSize}");
sb.AppendLine();
sb.AppendLine("# 路径线宽(像素)");
sb.AppendLine($"path_line_width = {config.Visualization.PathLineWidth}");
sb.AppendLine();
sb.AppendLine("# 路径点大小(模型单位)");
sb.AppendLine($"path_point_size = {config.Visualization.PathPointSize}");
sb.AppendLine();
sb.AppendLine("# 启用网格可视化");
sb.AppendLine($"enable_grid_visualization = {config.Visualization.EnableGridVisualization.ToString().ToLower()}");
sb.AppendLine();
sb.AppendLine("# 启用多层网格可视化");
sb.AppendLine($"enable_multi_layer_visualization = {config.Visualization.EnableMultiLayerVisualization.ToString().ToLower()}");
sb.AppendLine("# 地图边距比例0-1之间");
sb.AppendLine($"margin_ratio = {config.Visualization.MarginRatio}");
sb.AppendLine();
// 动画配置
sb.AppendLine("[animation]");
sb.AppendLine("# 默认动画速度(米/秒)");
sb.AppendLine($"default_speed_meters_per_second = {config.Animation.DefaultSpeedMetersPerSecond}");
sb.AppendLine();
sb.AppendLine("# 动画帧率(帧/秒)");
sb.AppendLine($"frame_rate = {config.Animation.FrameRate}");
sb.AppendLine();
sb.AppendLine("# 步进间隔(毫秒)");
sb.AppendLine($"step_interval_ms = {config.Animation.StepIntervalMs}");
sb.AppendLine("# 动画持续时间(秒)");
sb.AppendLine($"duration_seconds = {config.Animation.DurationSeconds}");
sb.AppendLine();
sb.AppendLine("# 启用平滑插值");
sb.AppendLine($"enable_smooth_interpolation = {config.Animation.EnableSmoothInterpolation.ToString().ToLower()}");
sb.AppendLine("# 检测间隙(米)");
sb.AppendLine($"detection_gap_meters = {config.Animation.DetectionGapMeters}");
sb.AppendLine();
// 碰撞检测配置
sb.AppendLine("[collision]");
sb.AppendLine("# 碰撞检测步长(米");
sb.AppendLine($"detection_step_meters = {config.Collision.DetectionStepMeters}");
// 物流属性配置
sb.AppendLine("[logistics]");
sb.AppendLine("# 可通行性默认值true");
sb.AppendLine($"traversable = {config.Logistics.Traversable.ToString().ToLower()}");
sb.AppendLine();
sb.AppendLine("# 碰撞容差(米");
sb.AppendLine($"collision_tolerance_meters = {config.Collision.CollisionToleranceMeters}");
sb.AppendLine("# 优先级默认值5范围1-5");
sb.AppendLine($"priority = {config.Logistics.Priority}");
sb.AppendLine();
sb.AppendLine("# 启用实时碰撞检测");
sb.AppendLine($"enable_realtime_detection = {config.Collision.EnableRealtimeDetection.ToString().ToLower()}");
sb.AppendLine("# 高度限制默认值3.0米)");
sb.AppendLine($"height_limit_meters = {config.Logistics.HeightLimitMeters}");
sb.AppendLine();
sb.AppendLine("# 自动生成碰撞报告");
sb.AppendLine($"auto_generate_report = {config.Collision.AutoGenerateReport.ToString().ToLower()}");
sb.AppendLine("# 速度限制默认值0.8米/秒)");
sb.AppendLine($"speed_limit_meters_per_second = {config.Logistics.SpeedLimitMetersPerSecond}");
sb.AppendLine();
sb.AppendLine("# 宽度限制默认值3.0米)");
sb.AppendLine($"width_limit_meters = {config.Logistics.WidthLimitMeters}");
return sb.ToString();
}

View File

@ -17,6 +17,11 @@ namespace NavisworksTransport.Core.Config
/// </summary>
public PathPlanningConfig PathPlanning { get; set; } = new PathPlanningConfig();
/// <summary>
/// 路径编辑配置
/// </summary>
public PathEditingConfig PathEditing { get; set; } = new PathEditingConfig();
/// <summary>
/// 可视化配置
/// </summary>
@ -28,9 +33,9 @@ namespace NavisworksTransport.Core.Config
public AnimationConfig Animation { get; set; } = new AnimationConfig();
/// <summary>
/// 碰撞检测配置
/// 物流属性配置
/// </summary>
public CollisionConfig Collision { get; set; } = new CollisionConfig();
public LogisticsConfig Logistics { get; set; } = new LogisticsConfig();
}
/// <summary>
@ -38,35 +43,6 @@ namespace NavisworksTransport.Core.Config
/// </summary>
public class GridGenerationConfig
{
/// <summary>
/// 网格单元大小(米)
/// 推荐值0.3-0.8
/// </summary>
public double CellSizeMeters { get; set; } = 0.5;
/// <summary>
/// 车辆半径(米)
/// 用于障碍物膨胀计算
/// </summary>
public double VehicleRadiusMeters { get; set; } = 0.3;
/// <summary>
/// 安全间隙(米)
/// 额外的安全距离
/// </summary>
public double SafetyMarginMeters { get; set; } = 0.2;
/// <summary>
/// 膨胀半径(网格单元数)
/// 障碍物膨胀的单元格数量
/// </summary>
public int InflationRadiusCells { get; set; } = 2;
/// <summary>
/// 扫描高度(米)
/// 障碍物扫描的垂直步进高度
/// </summary>
public double ScanHeightMeters { get; set; } = 0.1;
}
/// <summary>
@ -74,43 +50,44 @@ namespace NavisworksTransport.Core.Config
/// </summary>
public class PathPlanningConfig
{
}
/// <summary>
/// 路径编辑配置
/// </summary>
public class PathEditingConfig
{
/// <summary>
/// 网格单元大小(米)
/// 推荐值0.3-1.0
/// </summary>
public double CellSizeMeters { get; set; } = 0.5;
/// <summary>
/// 最大高度差(米)
/// 楼梯、坡道可接受的高度阈值
/// </summary>
public double MaxHeightDiffMeters { get; set; } = 0.35;
/// <summary>
/// 车辆长度(米)
/// </summary>
public double VehicleLengthMeters { get; set; } = 1.0;
/// <summary>
/// 车辆宽度(米)
/// </summary>
public double VehicleWidthMeters { get; set; } = 1.0;
/// <summary>
/// 车辆高度(米)
/// 用于通行性判断
/// </summary>
public double VehicleHeightMeters { get; set; } = 2.0;
/// <summary>
/// 车辆长度(米)
/// 用于转弯半径计算
/// 安全间隙(米)
/// </summary>
public double VehicleLengthMeters { get; set; } = 2.5;
/// <summary>
/// 车辆宽度(米)
/// 用于通道宽度判断
/// </summary>
public double VehicleWidthMeters { get; set; } = 1.8;
/// <summary>
/// 默认路径策略
/// "Shortest" - 最短路径优先
/// "Straightest" - 直线优先
/// "SafetyFirst" - 安全优先
/// </summary>
public string DefaultPathStrategy { get; set; } = "Straightest";
/// <summary>
/// 路径优化启用
/// 是否启用路径点优化(减少转弯点)
/// </summary>
public bool EnablePathOptimization { get; set; } = true;
public double SafetyMarginMeters { get; set; } = 0.05;
}
/// <summary>
@ -119,31 +96,10 @@ namespace NavisworksTransport.Core.Config
public class VisualizationConfig
{
/// <summary>
/// 网格点大小(像素)
/// 地图边距比例
/// 地图显示时的边距占比0-1之间
/// </summary>
public double GridPointSize { get; set; } = 5.0;
/// <summary>
/// 路径线宽(像素)
/// </summary>
public double PathLineWidth { get; set; } = 2.0;
/// <summary>
/// 路径点大小(模型单位)
/// </summary>
public double PathPointSize { get; set; } = 50.0;
/// <summary>
/// 启用网格可视化
/// 是否默认显示网格地图
/// </summary>
public bool EnableGridVisualization { get; set; } = false;
/// <summary>
/// 启用多层网格可视化
/// 是否显示多个高度层的网格
/// </summary>
public bool EnableMultiLayerVisualization { get; set; } = true;
public double MarginRatio { get; set; } = 0.1;
}
/// <summary>
@ -151,57 +107,50 @@ namespace NavisworksTransport.Core.Config
/// </summary>
public class AnimationConfig
{
/// <summary>
/// 动画速度(米/秒)
/// 默认车辆移动速度
/// </summary>
public double DefaultSpeedMetersPerSecond { get; set; } = 1.5;
/// <summary>
/// 动画帧率(帧/秒)
/// </summary>
public int FrameRate { get; set; } = 30;
/// <summary>
/// 步进间隔(毫秒)
/// 步进模式下每步的时间间隔
/// 动画持续时间(秒)
/// </summary>
public int StepIntervalMs { get; set; } = 100;
public double DurationSeconds { get; set; } = 10.0;
/// <summary>
/// 启用平滑插值
/// 是否在路径点之间使用平滑插值
/// 检测间隙(米)
/// </summary>
public bool EnableSmoothInterpolation { get; set; } = true;
public double DetectionGapMeters { get; set; } = 0.05;
}
/// <summary>
/// 碰撞检测配置
/// 物流属性配置
/// </summary>
public class CollisionConfig
public class LogisticsConfig
{
/// <summary>
/// 碰撞检测步长(米)
/// 动画过程中每次检测的移动距离
/// 可通行性默认值true
/// </summary>
public double DetectionStepMeters { get; set; } = 0.1;
public bool Traversable { get; set; } = true;
/// <summary>
/// 碰撞容差(米)
/// 判定为碰撞的最小距离
/// 优先级默认值5范围1-5
/// </summary>
public double CollisionToleranceMeters { get; set; } = 0.01;
public int Priority { get; set; } = 5;
/// <summary>
/// 启用实时碰撞检测
/// 动画播放时是否实时检测碰撞
/// 高度限制默认值3.0米)
/// </summary>
public bool EnableRealtimeDetection { get; set; } = true;
public double HeightLimitMeters { get; set; } = 3.0;
/// <summary>
/// 自动生成碰撞报告
/// 动画结束后是否自动生成报告
/// 速度限制默认值0.8米/秒)
/// </summary>
public bool AutoGenerateReport { get; set; } = true;
public double SpeedLimitMetersPerSecond { get; set; } = 0.8;
/// <summary>
/// 宽度限制默认值3.0米)
/// </summary>
public double WidthLimitMeters { get; set; } = 3.0;
}
}

View File

@ -3,7 +3,7 @@ using System.Collections.Generic;
using System.Linq;
using Autodesk.Navisworks.Api;
using Autodesk.Navisworks.Api.Plugins;
using NavisworksTransport.Core;
using NavisworksTransport.Utils;
namespace NavisworksTransport
{
@ -776,7 +776,7 @@ namespace NavisworksTransport
private VehicleSpaceMarker CreateVehicleSpaceMarker(PathPoint fromPoint, PathPoint toPoint)
{
// 获取单位转换系数
double metersToModelUnits = GetMetersToModelUnitsConversionFactor();
double metersToModelUnits = UnitsConverter.GetMetersToUnitsConversionFactor();
// 计算车辆通行空间宽度(米)
double vehicleInflationWidthInMeters = Math.Max(_vehicleLength, _vehicleWidth) + 2 * _safetyMargin;
@ -848,7 +848,7 @@ namespace NavisworksTransport
{
Center = point.Position,
Normal = new Vector3D(0, 0, 1),
Radius = isGridVisualization ? GetRadiusForGridVisualization(_currentGridSizeInMeters) : GetRadiusForPointType(point.Type),
Radius = isGridVisualization ? GetRadiusForGridVisualization() : GetRadiusForPointType(point.Type),
Color = isGridVisualization ? gridStyle.Color : GetColorForPointType(point.Type),
Alpha = isGridVisualization ? gridStyle.Alpha : 1.0,
Filled = true,
@ -862,13 +862,13 @@ namespace NavisworksTransport
/// 获取网格可视化小球的半径(比正常路径点小)
/// </summary>
/// <returns>网格可视化半径</returns>
private double GetRadiusForGridVisualization(double gridSizeInMeters = 0.5)
private double GetRadiusForGridVisualization()
{
// 使用标准尺寸的1/5作为网格点尺寸
double standardRadiusInMeters = GetStandardRadiusInMeters();
double radiusInMeters = standardRadiusInMeters / 5.0;
double metersToModelUnits = GetMetersToModelUnitsConversionFactor();
double metersToModelUnits = UnitsConverter.GetMetersToUnitsConversionFactor();
return radiusInMeters * metersToModelUnits;
}
@ -972,11 +972,11 @@ namespace NavisworksTransport
{
// 获取标准尺寸(起点尺寸)
double standardRadiusInMeters = GetStandardRadiusInMeters();
// 连线半径为标准尺寸的40%
double lineRadiusInMeters = standardRadiusInMeters * 0.4;
return lineRadiusInMeters * GetMetersToModelUnitsConversionFactor();
return lineRadiusInMeters * UnitsConverter.GetMetersToUnitsConversionFactor();
}
/// <summary>
@ -1411,7 +1411,7 @@ namespace NavisworksTransport
{
// 获取标准尺寸(起点尺寸)
double standardRadiusInMeters = GetStandardRadiusInMeters();
// 根据点类型应用比例系数
double baseRadiusInMeters;
if (pointType == PathPointType.WayPoint)
@ -1424,59 +1424,14 @@ namespace NavisworksTransport
// 起点/终点使用标准尺寸100%
baseRadiusInMeters = standardRadiusInMeters * 1.0;
}
// 获取真实文档单位转换系数
double metersToModelUnits = GetMetersToModelUnitsConversionFactor();
double metersToModelUnits = UnitsConverter.GetMetersToUnitsConversionFactor();
// 转换为模型单位
double radiusInModelUnits = baseRadiusInMeters * metersToModelUnits;
return radiusInModelUnits;
}
/// <summary>
/// 获取米转换为文档单位的转换系数
/// 使用Navisworks API直接获取真实文档单位而不是猜测
/// </summary>
private double GetMetersToModelUnitsConversionFactor()
{
try
{
var units = Application.ActiveDocument.Units;
switch (units)
{
case Units.Millimeters:
return 1000.0; // 1米 = 1000毫米
case Units.Centimeters:
return 100.0; // 1米 = 100厘米
case Units.Meters:
return 1.0; // 1米 = 1米
case Units.Inches:
return 39.37; // 1米 = 39.37英寸
case Units.Feet:
return 3.281; // 1米 = 3.281英尺
case Units.Kilometers:
return 0.001; // 1米 = 0.001公里
case Units.Micrometers:
return 1000000.0; // 1米 = 1000000微米
case Units.Microinches:
return 39370078.74; // 1米 = 39370078.74微英寸
case Units.Mils:
return 39370.08; // 1米 = 39370.08密尔
case Units.Yards:
return 1.094; // 1米 = 1.094码
case Units.Miles:
return 0.000621; // 1米 = 0.000621英里
default:
return 1.0;
}
}
catch (Exception ex)
{
LogManager.Error($"[单位检测] API调用失败: {ex.Message}");
return 1.0;
}
return radiusInModelUnits;
}
/// <summary>

View File

@ -95,7 +95,28 @@ namespace NavisworksTransport
}
/// <summary>
/// 为选定的模型项添加物流属性
/// 为选定的模型项添加物流属性(使用配置默认值)
/// </summary>
/// <param name="items">要处理的模型项集合</param>
/// <param name="elementType">物流元素类型</param>
/// <returns>成功处理的项目数量</returns>
public static int AddLogisticsAttributes(
ModelItemCollection items,
LogisticsElementType elementType)
{
var logistics = NavisworksTransport.Core.Config.ConfigManager.Instance.Current.Logistics;
return AddLogisticsAttributes(
items,
elementType,
logistics.Traversable,
logistics.Priority,
logistics.HeightLimitMeters,
logistics.SpeedLimitMetersPerSecond,
logistics.WidthLimitMeters);
}
/// <summary>
/// 为选定的模型项添加物流属性(指定所有参数)
/// </summary>
/// <param name="items">要处理的模型项集合</param>
/// <param name="elementType">物流元素类型</param>
@ -108,11 +129,11 @@ namespace NavisworksTransport
public static int AddLogisticsAttributes(
ModelItemCollection items,
LogisticsElementType elementType,
bool isTraversable = true,
int priority = 5,
double heightLimit = 3.0,
double speedLimit = 10.0,
double widthLimit = 3.0)
bool isTraversable,
int priority,
double heightLimit,
double speedLimit,
double widthLimit)
{
if (items == null || items.Count == 0)
{
@ -142,8 +163,8 @@ namespace NavisworksTransport
};
int successCount = NavisworksComPropertyManager.SetUserDefinedProperties(
items,
LogisticsCategories.LOGISTICS,
items,
LogisticsCategories.LOGISTICS,
LogisticsCategories.CATEGORY_INTERNAL_NAME,
properties,
propertyInternalNames);

View File

@ -6,6 +6,7 @@ using Roy_T.AStar.Grids;
using Roy_T.AStar.Primitives;
using Roy_T.AStar.Paths;
using NavisworksTransport.Utils;
using NavisworksTransport.Core.Config;
namespace NavisworksTransport.PathPlanning
{
@ -48,11 +49,14 @@ namespace NavisworksTransport.PathPlanning
public class AutoPathFinder
{
/// <summary>
/// 水平边连接允许的最大高度差(米)
/// 足以支持台阶连接约0.15米和地面到楼梯底部的连接约0.3米)
/// 获取水平边连接允许的最大高度差(米)
/// 从配置文件读取,足以支持台阶连接约0.15米和地面到楼梯底部的连接约0.3米)
/// 使用时需转换为模型单位
/// </summary>
private const double MAX_HEIGHT_DIFF_METERS = 0.35;
private double GetMaxHeightDiffMeters()
{
return ConfigManager.Instance.Current.PathEditing.MaxHeightDiffMeters;
}
/// <summary>
/// 3D节点信息存储每个A*节点对应的3D坐标和类型
@ -143,8 +147,9 @@ namespace NavisworksTransport.PathPlanning
float maxSpeed = (float)baseSpeed;
// 将米转换为模型单位
double maxHeightDiffInModelUnits = MAX_HEIGHT_DIFF_METERS * UnitsConverter.GetMetersToUnitsConversionFactor();
LogManager.Info($"[3D图构建] 高度差阈值: {MAX_HEIGHT_DIFF_METERS}米 = {maxHeightDiffInModelUnits:F2}模型单位");
double maxHeightDiffMeters = GetMaxHeightDiffMeters();
double maxHeightDiffInModelUnits = maxHeightDiffMeters * UnitsConverter.GetMetersToUnitsConversionFactor();
LogManager.Info($"[3D图构建] 高度差阈值: {maxHeightDiffMeters}米 = {maxHeightDiffInModelUnits:F2}模型单位");
// === 阶段1创建所有3D节点 ===
int totalNodesCreated = 0;

View File

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq;
using Autodesk.Navisworks.Api;
using NavisworksTransport.Utils;
using NavisworksTransport.Core.Config;
namespace NavisworksTransport.PathPlanning
{
@ -30,11 +31,14 @@ namespace NavisworksTransport.PathPlanning
public class GridMapGenerator
{
/// <summary>
/// 边界检测的最大高度差(米)
/// 与AutoPathFinder中的MAX_HEIGHT_DIFF_METERS保持一致
/// 获取边界检测的最大高度差(米)
/// 从配置文件读取,与AutoPathFinder保持一致
/// 用于判断层间是否构成边界(超过此阈值则标记为边界)
/// </summary>
private const double MAX_HEIGHT_DIFF_METERS = 0.35;
private double GetMaxHeightDiffMeters()
{
return ConfigManager.Instance.Current.PathEditing.MaxHeightDiffMeters;
}
private readonly CategoryAttributeManager _categoryManager;
private readonly ChannelBasedGridBuilder _channelBuilder;
@ -153,8 +157,9 @@ namespace NavisworksTransport.PathPlanning
// 2.7. 标记边界层(用于膨胀计算)
LogManager.Info("【生成网格地图】步骤2.7: 标记边界层");
double maxHeightDiffInModelUnits = MAX_HEIGHT_DIFF_METERS * metersToModelUnitsConversionFactor;
LogManager.Info($"【生成网格地图】边界高度差阈值: {MAX_HEIGHT_DIFF_METERS}米 = {maxHeightDiffInModelUnits:F2}模型单位");
double maxHeightDiffMeters = GetMaxHeightDiffMeters();
double maxHeightDiffInModelUnits = maxHeightDiffMeters * metersToModelUnitsConversionFactor;
LogManager.Info($"【生成网格地图】边界高度差阈值: {maxHeightDiffMeters}米 = {maxHeightDiffInModelUnits:F2}模型单位");
MarkBoundaryLayers(channelCoverage.GridMap, maxHeightDiffInModelUnits);
LogManager.Info($"【阶段2.7完成】边界层标记后网格统计: {channelCoverage.GridMap.GetStatistics()}");
@ -849,7 +854,8 @@ namespace NavisworksTransport.PathPlanning
// 计算高度差阈值(用于楼梯口保护)
double metersToModelUnitsConversionFactor = UnitsConverter.GetMetersToUnitsConversionFactor(Application.ActiveDocument.Units);
double maxHeightDiffInModelUnits = MAX_HEIGHT_DIFF_METERS * metersToModelUnitsConversionFactor;
double maxHeightDiffMeters = GetMaxHeightDiffMeters();
double maxHeightDiffInModelUnits = maxHeightDiffMeters * metersToModelUnitsConversionFactor;
// 统计每个层索引的处理情况
var layerStats = new Dictionary<int, (int obstacleInflated, int boundaryCount, int boundaryInflated)>();

File diff suppressed because it is too large Load Diff

View File

@ -501,6 +501,9 @@ namespace NavisworksTransport.UI.WPF.ViewModels
/// </summary>
private void InitializeAnimationSettings()
{
// 从配置加载动画参数
var config = NavisworksTransport.Core.Config.ConfigManager.Instance.Current;
// 初始化可用帧率
AvailableFrameRates.Clear();
var frameRates = new[] { 15, 24, 30, 60 };
@ -508,10 +511,12 @@ namespace NavisworksTransport.UI.WPF.ViewModels
{
AvailableFrameRates.Add(rate);
}
SelectedFrameRate = 30; // 默认30fps
// 设置默认动画参数
AnimationDuration = 10.0;
// 从配置读取帧率
SelectedFrameRate = config.Animation.FrameRate;
// 从配置读取动画持续时间
AnimationDuration = config.Animation.DurationSeconds;
// 设置初始状态 - 修改: 默认状态应该是未激活,等待有效动画
CanPauseAnimation = false;
@ -520,16 +525,16 @@ namespace NavisworksTransport.UI.WPF.ViewModels
// 初始化碰撞检测状态
HasCollisionResults = false;
UpdateMainStatus("碰撞检测就绪");
// 初始化碰撞检测参数
DetectionGap = 0.05; // 0.05米
AnimationFrameRate = 30; // 30FPS
// 从配置读取碰撞检测参数
DetectionGap = config.Animation.DetectionGapMeters;
AnimationFrameRate = config.Animation.FrameRate;
// 注意CollisionDetectionAccuracy(步长)和MovementSpeed(速度)现在是计算属性,不需要设置初始值
// 修改: 使用新的按钮状态更新方法来设置正确的初始状态
UpdateAnimationButtonStates();
LogManager.Info("动画设置初始化完成");
LogManager.Info($"动画设置初始化完成 - 帧率:{SelectedFrameRate}fps, 持续时间:{AnimationDuration}秒, 检测间隙:{DetectionGap}米");
}
/// <summary>

View File

@ -11,6 +11,7 @@ using System.IO;
using Microsoft.Win32;
using Autodesk.Navisworks.Api;
using NavisworksTransport.Core;
using NavisworksTransport.Core.Config;
using NavisworksTransport.UI.WPF.Collections;
using NavisworksTransport.UI.WPF.Models;
using NavisworksTransport.UI.WPF.Commands;
@ -73,7 +74,7 @@ namespace NavisworksTransport.UI.WPF.ViewModels
private double _vehicleLength = 1.0; // 车辆长度(米)
private double _vehicleWidth = 1.0; // 车辆宽度(米)
private double _vehicleHeight = 2.0; // 车辆高度(米)
private double _safetyMargin = 0.25; // 安全间隙(米)
private double _safetyMargin = 0.05; // 安全间隙(米)
// 网格大小参数
private bool _isGridSizeManuallyEnabled = false; // 是否启用手动网格大小设置
@ -481,50 +482,8 @@ namespace NavisworksTransport.UI.WPF.ViewModels
#region
public PathEditingViewModel() : base()
{
try
{
_uiStateManager = UIStateManager.Instance;
_pathDataManager = new PathDataManager();
// 不在构造函数中创建PathPlanningManager由外部设置
_pathPlanningManager = null;
if (_uiStateManager == null)
{
throw new InvalidOperationException("UIStateManager初始化失败");
}
// PathPlanningManager将在外部设置这里不需要检查
// 初始化集合
PathRoutes = new ObservableCollection<PathRouteViewModel>();
// 初始化路径策略选项
InitializePathStrategyOptions();
// 初始化命令
InitializeCommands();
// 初始化车辆参数同步在PathPointRenderPlugin实例不为空时才同步
// 如果PathPointRenderPlugin尚未初始化将在属性变更时自动同步
SyncVehicleParametersToRenderPlugin();
// 注意不在这里订阅PathPlanningManager事件
// 因为PathPlanningManager还没有设置事件订阅在PathPlanningManager属性setter中处理
LogManager.Info("PathEditingViewModel构造函数执行完成已迁移原有业务逻辑");
}
catch (Exception ex)
{
LogManager.Error($"PathEditingViewModel构造函数异常: {ex.Message}", ex);
UpdateMainStatus("初始化失败,请检查日志");
throw;
}
}
/// <summary>
/// 带主ViewModel参数的构造函数支持统一状态栏
/// 构造函数需要传入主ViewModel以支持统一状态栏
/// </summary>
/// <param name="mainViewModel">主ViewModel用于统一状态栏</param>
public PathEditingViewModel(LogisticsControlViewModel mainViewModel) : base()
@ -551,7 +510,10 @@ namespace NavisworksTransport.UI.WPF.ViewModels
// 初始化路径策略选项
InitializePathStrategyOptions();
// 从配置加载参数
LoadParametersFromConfig();
// 初始化命令
InitializeCommands();
@ -607,6 +569,31 @@ namespace NavisworksTransport.UI.WPF.ViewModels
_selectedPathStrategy = _pathStrategyOptions.FirstOrDefault(x => x.Value == PathStrategy.Shortest);
}
/// <summary>
/// 从配置文件加载参数
/// </summary>
private void LoadParametersFromConfig()
{
try
{
var config = ConfigManager.Instance.Current;
// 从 PathEditing 配置加载所有参数
_gridSize = config.PathEditing.CellSizeMeters;
_vehicleLength = config.PathEditing.VehicleLengthMeters;
_vehicleWidth = config.PathEditing.VehicleWidthMeters;
_vehicleHeight = config.PathEditing.VehicleHeightMeters;
_safetyMargin = config.PathEditing.SafetyMarginMeters;
LogManager.Info($"从配置加载参数 - 车辆: {_vehicleLength}x{_vehicleWidth}x{_vehicleHeight}米, 安全间隙: {_safetyMargin}米, 网格: {_gridSize}米");
}
catch (Exception ex)
{
LogManager.Error($"加载配置参数失败: {ex.Message}", ex);
// 使用默认值,不抛出异常
}
}
private void InitializeCommands()
{
NewPathCommand = new RelayCommand(async () => await ExecuteNewPathAsync(), () => CanExecuteNewPath);

View File

@ -56,7 +56,7 @@ NavisworksTransport 主控制面板 - 采用与其他视图一致的Navisworks 2
<TabItem Header="路径编辑" Name="PathEditingTab" Style="{StaticResource NavisworksTabItemStyle}">
<Border Background="White" CornerRadius="0">
<views:PathEditingView x:Name="PathEditingView" Margin="0"/>
<ContentControl x:Name="PathEditingContent" Margin="0"/>
</Border>
</TabItem>

View File

@ -170,6 +170,11 @@ namespace NavisworksTransport.UI.WPF
}
}
/// <summary>
/// PathEditingView引用
/// </summary>
private PathEditingView PathEditingView;
/// <summary>
/// 初始化PathEditingView
/// </summary>
@ -177,25 +182,29 @@ namespace NavisworksTransport.UI.WPF
{
try
{
// 重新创建PathEditingView传入主ViewModel引用
// 创建PathEditingView传入主ViewModel引用
var newPathEditingView = new PathEditingView(ViewModel);
// 替换XAML中的PathEditingView
if (PathEditingTab?.Content is Border pathEditingBorder)
// 设置到ContentControl中
if (PathEditingContent != null)
{
pathEditingBorder.Child = newPathEditingView;
PathEditingContent.Content = newPathEditingView;
// 更新引用
PathEditingView = newPathEditingView;
}
if (PathEditingView?.ViewModel != null)
{
// 将PathPlanningManager传递给PathEditingView
PathEditingView.ViewModel.PathPlanningManager = _pathPlanningManager;
LogManager.Info("PathEditingView初始化完成 - 支持统一状态栏");
}
else
{
LogManager.Error("PathEditingContent占位符未找到");
}
}
catch (Exception ex)
{

View File

@ -19,19 +19,8 @@ namespace NavisworksTransport.UI.WPF.Views
/// </summary>
public PathEditingViewModel ViewModel { get; private set; }
public PathEditingView()
{
InitializeComponent();
// 创建并设置ViewModel
ViewModel = new PathEditingViewModel();
DataContext = ViewModel;
LogManager.Info("PathEditingView初始化完成");
}
/// <summary>
/// 带主ViewModel参数的构造函数支持统一状态栏
/// 构造函数需要传入主ViewModel以支持统一状态栏
/// </summary>
/// <param name="mainViewModel">主ViewModel用于统一状态栏</param>
public PathEditingView(LogisticsControlViewModel mainViewModel)

View File

@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using Autodesk.Navisworks.Api;
using NavisworksTransport.Core.Config;
namespace NavisworksTransport
{
@ -17,7 +18,24 @@ namespace NavisworksTransport
private double _zoomFactor = 1.0;
private double _offsetX = 0.0;
private double _offsetY = 0.0;
private const double _marginRatio = 0.1; // 10%边距
/// <summary>
/// 获取地图边距比例(从配置读取)
/// </summary>
private double MarginRatio
{
get
{
try
{
return ConfigManager.Instance.Current.Visualization.MarginRatio;
}
catch
{
return 0.1; // 配置加载失败时使用默认值10%
}
}
}
/// <summary>
/// 地图宽度(像素)
@ -138,12 +156,13 @@ namespace NavisworksTransport
throw new ArgumentNullException(nameof(mapPoint));
// 计算可用的地图尺寸(减去边距)
double availableWidth = _mapWidth * (1.0 - 2 * _marginRatio);
double availableHeight = _mapHeight * (1.0 - 2 * _marginRatio);
double marginRatio = MarginRatio;
double availableWidth = _mapWidth * (1.0 - 2 * marginRatio);
double availableHeight = _mapHeight * (1.0 - 2 * marginRatio);
// 从地图坐标计算相对位置
double relativeX = (mapPoint.X - _mapWidth * _marginRatio) / availableWidth;
double relativeY = 1.0 - ((mapPoint.Y - _mapHeight * _marginRatio) / availableHeight); // Y轴翻转
double relativeX = (mapPoint.X - _mapWidth * marginRatio) / availableWidth;
double relativeY = 1.0 - ((mapPoint.Y - _mapHeight * marginRatio) / availableHeight); // Y轴翻转
// 转换为世界坐标
double worldX = _channelBounds.MinPoint.X + relativeX * (_channelBounds.MaxPoint.X - _channelBounds.MinPoint.X);
@ -172,12 +191,13 @@ namespace NavisworksTransport
double relativeY = (worldPoint.Y - _channelBounds.MinPoint.Y) / worldHeight;
// 计算可用的地图尺寸(减去边距)
double availableWidth = _mapWidth * (1.0 - 2 * _marginRatio);
double availableHeight = _mapHeight * (1.0 - 2 * _marginRatio);
double marginRatio = MarginRatio;
double availableWidth = _mapWidth * (1.0 - 2 * marginRatio);
double availableHeight = _mapHeight * (1.0 - 2 * marginRatio);
// 转换为地图像素坐标
double mapX = relativeX * availableWidth + _mapWidth * _marginRatio;
double mapY = (1.0 - relativeY) * availableHeight + _mapHeight * _marginRatio; // Y轴翻转
double mapX = relativeX * availableWidth + _mapWidth * marginRatio;
double mapY = (1.0 - relativeY) * availableHeight + _mapHeight * marginRatio; // Y轴翻转
// 确保坐标在地图范围内
mapX = Math.Max(0, Math.Min(_mapWidth, mapX));

View File

@ -10,19 +10,12 @@ namespace NavisworksTransport
/// </summary>
public class FloorDetector
{
#region
private const double DEFAULT_FLOOR_HEIGHT_THRESHOLD = 2.5; // 默认最小楼层高度(米)
private const double DEFAULT_ELEVATION_TOLERANCE = 0.5; // 默认高程容差(米)
// 常见的楼层属性名称
private readonly string[] COMMON_FLOOR_ATTRIBUTES = {
"Level", "Floor", "Storey", "楼层", "层", "Level Name", "Story",
"Building Level", "Floor Level", "Elevation", "Z", "Height"
};
#endregion
#region
/// <summary>
@ -190,9 +183,6 @@ namespace NavisworksTransport
}
}
// GetFloorByElevation方法已删除 - 性能优化:不再支持基于高程的楼层查找
/// <summary>
/// 从给定的模型项集合中检测楼层信息 - 不进行深度遍历
/// </summary>
@ -346,7 +336,7 @@ namespace NavisworksTransport
{
try
{
string floorValue = GetAttributeValue(item, attributeName);
string floorValue = CategoryAttributeManager.GetGeneralPropertyValueSafe(item, attributeName);
if (!string.IsNullOrEmpty(floorValue))
{
if (!floorGroups.ContainsKey(floorValue))
@ -388,19 +378,6 @@ namespace NavisworksTransport
return floors.OrderBy(f => f.Elevation).ToList();
}
private string GetAttributeValue(ModelItem item, string attributeName)
{
try
{
// 使用 CategoryAttributeManager 的安全属性获取方法,简化代码
return CategoryAttributeManager.GetGeneralPropertyValueSafe(item, attributeName);
}
catch
{
return null;
}
}
#endregion