修改系统配置的问题。

This commit is contained in:
tian 2025-12-31 11:29:21 +08:00
parent 93135d3c29
commit aa0557c9e6
9 changed files with 312 additions and 205 deletions

View File

@ -355,12 +355,18 @@
<Import Project="$(MSBuildExtensionsPath)\Microsoft\WinFX\3.0\Microsoft.WinFX.targets" Condition="Exists('$(MSBuildExtensionsPath)\Microsoft\WinFX\3.0\Microsoft.WinFX.targets')" />
<ItemGroup>
<!-- Localization Files -->
<None Include="src\Resources\NavisworksTransport.Tian.name.txt">
<None Include="src\Resources\NavisworksTransportPlugin.name.txt">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<Link>NavisworksTransport.Tian.name.txt</Link>
<Link>NavisworksTransportPlugin.name.txt</Link>
</None>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- Import NETStandard.Library targets to support .NET Standard 2.0 libraries -->
<Import Project="packages\NETStandard.Library.2.0.3\build\netstandard2.0\NETStandard.Library.targets" Condition="Exists('packages\NETStandard.Library.2.0.3\build\netstandard2.0\NETStandard.Library.targets')" />
<ItemGroup>
<!-- Configuration Template File -->
<None Include="default_config.toml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>

View File

@ -20,8 +20,6 @@ vehicle_height_meters = 2.0
# 安全间隙(米)
safety_margin_meters = 0.05
# 路径曲线化配置
# 路径默认转弯半径(米)- 表示路径允许的最大转弯半径
default_path_turn_radius = 2.5

View File

@ -4,6 +4,7 @@ set "TARGET_DIR=C:\ProgramData\Autodesk\Navisworks Manage 2026\plugins\Naviswork
if not exist "%TARGET_DIR%" mkdir "%TARGET_DIR%"
copy "bin\x64\Release\NavisworksTransportPlugin.dll" "%TARGET_DIR%\" >nul
if exist "bin\x64\Release\NavisworksTransport.Tian.name.txt" copy "bin\x64\Release\NavisworksTransport.Tian.name.txt" "%TARGET_DIR%\" >nul
if exist "bin\x64\Release\NavisworksTransportPlugin.name.txt" copy "bin\x64\Release\NavisworksTransportPlugin.name.txt" "%TARGET_DIR%\" >nul
if exist "bin\x64\Release\default_config.toml" copy "bin\x64\Release\default_config.toml" "%TARGET_DIR%\" >nul
echo Plugin deployed successfully!

View File

@ -1,8 +1,9 @@
using System;
using System.IO;
using System.Text;
using System.Reflection;
using Tomlyn;
using Tomlyn.Model;
using Tomlyn.Syntax;
namespace NavisworksTransport.Core.Config
{
@ -62,11 +63,25 @@ namespace NavisworksTransport.Core.Config
get { return Path.GetDirectoryName(ConfigFilePath); }
}
/// <summary>
/// 配置模板文件路径
/// </summary>
private static string ConfigTemplatePath
{
get
{
// 从插件当前目录获取模板文件
var pluginDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
return Path.Combine(pluginDirectory, "default_config.toml");
}
}
private SystemConfig _currentConfig;
private string _cachedTemplateContent;
private ConfigManager()
{
_currentConfig = LoadOrCreateDefault();
_currentConfig = LoadConfigFile();
}
/// <summary>
@ -78,23 +93,37 @@ namespace NavisworksTransport.Core.Config
}
/// <summary>
/// 加载配置文件,如果不存在则创建默认配置
/// 读取配置模板文件内容
/// </summary>
public SystemConfig LoadOrCreateDefault()
private string ReadConfigTemplate()
{
if (!File.Exists(ConfigTemplatePath))
{
throw new FileNotFoundException($"配置模板文件不存在: {ConfigTemplatePath}");
}
LogManager.Info($"使用配置模板文件: {ConfigTemplatePath}");
return File.ReadAllText(ConfigTemplatePath);
}
/// <summary>
/// 加载配置文件,如果不存在则从模板创建
/// </summary>
private SystemConfig LoadConfigFile()
{
try
{
if (!File.Exists(ConfigFilePath))
{
LogManager.Info($"配置文件不存在,创建默认配置: {ConfigFilePath}");
var defaultConfig = new SystemConfig();
SaveConfig(defaultConfig);
return defaultConfig;
LogManager.Info($"配置文件不存在,从模板创建: {ConfigFilePath}");
var templateContent = ReadConfigTemplate();
WriteConfigFileDirect(templateContent);
return ParseTomlToConfig(templateContent);
}
LogManager.Info($"加载配置文件: {ConfigFilePath}");
var tomlContent = File.ReadAllText(ConfigFilePath, Encoding.UTF8);
var config = LoadFromToml(tomlContent);
var tomlContent = File.ReadAllText(ConfigFilePath);
var config = ParseTomlToConfig(tomlContent);
LogManager.Info("配置文件加载成功");
return config;
@ -104,74 +133,109 @@ namespace NavisworksTransport.Core.Config
LogManager.Error($"加载配置文件失败: {ex.Message}");
LogManager.Error($"堆栈跟踪: {ex.StackTrace}");
// 加载失败时返回默认配置
LogManager.Info("使用默认配置");
return new SystemConfig();
// 加载失败时使用模板中的默认配置
LogManager.Info("使用模板中的默认配置");
var templateContent = ReadConfigTemplate();
return ParseTomlToConfig(templateContent);
}
}
/// <summary>
/// 从 TOML 字符串加载配置
/// 将 TOML 字符串解析为配置对象
/// </summary>
private SystemConfig LoadFromToml(string tomlContent)
private SystemConfig ParseTomlToConfig(string tomlContent)
{
var model = Toml.ToModel(tomlContent);
var config = new SystemConfig();
var config = CreateEmptyConfigObject();
// 加载路径编辑配置
if (model.ContainsKey("path_editing"))
if (!model.ContainsKey("path_editing"))
{
var pathEdit = model["path_editing"] as TomlTable;
if (pathEdit != null)
{
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);
}
throw new InvalidOperationException("配置文件缺少 [path_editing] 部分");
}
var pathEdit = model["path_editing"] as TomlTable;
if (pathEdit == null)
{
throw new InvalidOperationException("[path_editing] 部分格式错误");
}
config.PathEditing.CellSizeMeters = GetRequiredDoubleValue(pathEdit, "cell_size_meters");
config.PathEditing.MaxHeightDiffMeters = GetRequiredDoubleValue(pathEdit, "max_height_diff_meters");
config.PathEditing.VehicleLengthMeters = GetRequiredDoubleValue(pathEdit, "vehicle_length_meters");
config.PathEditing.VehicleWidthMeters = GetRequiredDoubleValue(pathEdit, "vehicle_width_meters");
config.PathEditing.VehicleHeightMeters = GetRequiredDoubleValue(pathEdit, "vehicle_height_meters");
config.PathEditing.SafetyMarginMeters = GetRequiredDoubleValue(pathEdit, "safety_margin_meters");
config.PathEditing.DefaultPathTurnRadius = GetRequiredDoubleValue(pathEdit, "default_path_turn_radius");
config.PathEditing.ArcSamplingStep = GetRequiredDoubleValue(pathEdit, "arc_sampling_step");
// 加载可视化配置
if (model.ContainsKey("visualization"))
if (!model.ContainsKey("visualization"))
{
var visual = model["visualization"] as TomlTable;
if (visual != null)
{
config.Visualization.MarginRatio = GetDouble(visual, "margin_ratio", 0.1);
}
throw new InvalidOperationException("配置文件缺少 [visualization] 部分");
}
var visual = model["visualization"] as TomlTable;
if (visual == null)
{
throw new InvalidOperationException("[visualization] 部分格式错误");
}
config.Visualization.MarginRatio = GetRequiredDoubleValue(visual, "margin_ratio");
// 加载动画配置
if (model.ContainsKey("animation"))
if (!model.ContainsKey("animation"))
{
var anim = model["animation"] as TomlTable;
if (anim != null)
{
config.Animation.FrameRate = GetInt(anim, "frame_rate", 30);
config.Animation.DurationSeconds = GetDouble(anim, "duration_seconds", 10.0);
config.Animation.DetectionGapMeters = GetDouble(anim, "detection_gap_meters", 0.05);
}
throw new InvalidOperationException("配置文件缺少 [animation] 部分");
}
var anim = model["animation"] as TomlTable;
if (anim == null)
{
throw new InvalidOperationException("[animation] 部分格式错误");
}
config.Animation.FrameRate = GetRequiredIntValue(anim, "frame_rate");
config.Animation.DurationSeconds = GetRequiredDoubleValue(anim, "duration_seconds");
config.Animation.DetectionGapMeters = GetRequiredDoubleValue(anim, "detection_gap_meters");
// 加载物流属性配置
if (model.ContainsKey("logistics"))
if (!model.ContainsKey("logistics"))
{
var logistics = model["logistics"] as TomlTable;
if (logistics != null)
{
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);
}
throw new InvalidOperationException("配置文件缺少 [logistics] 部分");
}
var logistics = model["logistics"] as TomlTable;
if (logistics == null)
{
throw new InvalidOperationException("[logistics] 部分格式错误");
}
config.Logistics.Traversable = GetRequiredBoolValue(logistics, "traversable");
config.Logistics.Priority = GetRequiredIntValue(logistics, "priority");
config.Logistics.HeightLimitMeters = GetRequiredDoubleValue(logistics, "height_limit_meters");
config.Logistics.SpeedLimitMetersPerSecond = GetRequiredDoubleValue(logistics, "speed_limit_meters_per_second");
config.Logistics.WidthLimitMeters = GetRequiredDoubleValue(logistics, "width_limit_meters");
return config;
}
/// <summary>
/// 创建空的配置对象(初始化所有嵌套对象)
/// </summary>
private SystemConfig CreateEmptyConfigObject()
{
return new SystemConfig
{
GridGeneration = new GridGenerationConfig(),
PathPlanning = new PathPlanningConfig(),
PathEditing = new PathEditingConfig(),
Visualization = new VisualizationConfig(),
Animation = new AnimationConfig(),
Logistics = new LogisticsConfig()
};
}
/// <summary>
/// 保存配置到文件
/// </summary>
@ -182,8 +246,8 @@ namespace NavisworksTransport.Core.Config
// 确保目录存在
Directory.CreateDirectory(ConfigDirectory);
var tomlContent = ConvertToToml(config);
File.WriteAllText(ConfigFilePath, tomlContent, Encoding.UTF8);
var tomlContent = GenerateTomlFromConfig(config);
File.WriteAllText(ConfigFilePath, tomlContent);
_currentConfig = config;
LogManager.Info($"配置文件已保存: {ConfigFilePath}");
@ -197,133 +261,178 @@ namespace NavisworksTransport.Core.Config
}
/// <summary>
/// 将配置转换为 TOML 字符串
/// 直接写入配置文件内容(不经过模板转换)
/// </summary>
private string ConvertToToml(SystemConfig config)
private void WriteConfigFileDirect(string tomlContent)
{
var sb = new StringBuilder();
try
{
// 确保目录存在
Directory.CreateDirectory(ConfigDirectory);
// 添加文件头注释
sb.AppendLine("# NavisworksTransport 系统配置文件");
sb.AppendLine("# 单位说明:长度单位均为米(m)");
sb.AppendLine("# 自动生成时间: " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
sb.AppendLine();
// 路径编辑配置
sb.AppendLine("[path_editing]");
sb.AppendLine("# 网格单元大小(米)- 推荐值0.3-1.0");
sb.AppendLine($"cell_size_meters = {config.PathEditing.CellSizeMeters:0.0###}");
sb.AppendLine();
sb.AppendLine("# 最大高度差(米)- 楼梯、坡道可接受的高度阈值");
sb.AppendLine($"max_height_diff_meters = {config.PathEditing.MaxHeightDiffMeters:0.0###}");
sb.AppendLine();
sb.AppendLine("# 车辆长度(米)");
sb.AppendLine($"vehicle_length_meters = {config.PathEditing.VehicleLengthMeters:0.0###}");
sb.AppendLine();
sb.AppendLine("# 车辆宽度(米)");
sb.AppendLine($"vehicle_width_meters = {config.PathEditing.VehicleWidthMeters:0.0###}");
sb.AppendLine();
sb.AppendLine("# 车辆高度(米)");
sb.AppendLine($"vehicle_height_meters = {config.PathEditing.VehicleHeightMeters:0.0###}");
sb.AppendLine();
sb.AppendLine("# 安全间隙(米)");
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:0.0###}");
sb.AppendLine();
// 动画配置
sb.AppendLine("[animation]");
sb.AppendLine("# 动画帧率(帧/秒)");
sb.AppendLine($"frame_rate = {config.Animation.FrameRate}");
sb.AppendLine();
sb.AppendLine("# 动画持续时间(秒)");
sb.AppendLine($"duration_seconds = {config.Animation.DurationSeconds:0.0###}");
sb.AppendLine();
sb.AppendLine("# 检测间隙(米)");
sb.AppendLine($"detection_gap_meters = {config.Animation.DetectionGapMeters:0.00###}");
sb.AppendLine();
// 物流属性配置
sb.AppendLine("[logistics]");
sb.AppendLine("# 可通行性默认值true");
sb.AppendLine($"traversable = {config.Logistics.Traversable.ToString().ToLower()}");
sb.AppendLine();
sb.AppendLine("# 优先级默认值5范围1-5");
sb.AppendLine($"priority = {config.Logistics.Priority}");
sb.AppendLine();
sb.AppendLine("# 高度限制默认值3.0米)");
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:0.0###}");
sb.AppendLine();
sb.AppendLine("# 宽度限制默认值3.0米)");
sb.AppendLine($"width_limit_meters = {config.Logistics.WidthLimitMeters:0.0###}");
return sb.ToString();
File.WriteAllText(ConfigFilePath, tomlContent);
LogManager.Info($"配置文件已创建: {ConfigFilePath}");
}
catch (Exception ex)
{
LogManager.Error($"写入配置文件失败: {ex.Message}");
LogManager.Error($"堆栈跟踪: {ex.StackTrace}");
throw;
}
}
/// <summary>
/// 重新加载配置
/// 从配置对象生成 TOML 字符串(使用模板格式)
/// </summary>
private string GenerateTomlFromConfig(SystemConfig config)
{
// 加载模板内容(缓存)
if (_cachedTemplateContent == null)
{
_cachedTemplateContent = ReadConfigTemplate();
}
// 解析模板
var syntax = Toml.Parse(_cachedTemplateContent);
var model = syntax.ToModel();
// 更新配置值到模型
ApplyConfigValuesToModel(model, config);
// 转换回 TOML 字符串
return Toml.FromModel(model);
}
/// <summary>
/// 将配置对象的值应用到 TOML 模型
/// </summary>
private void ApplyConfigValuesToModel(TomlTable model, SystemConfig config)
{
// 更新路径编辑配置
if (model.ContainsKey("path_editing"))
{
var pathEdit = model["path_editing"] as TomlTable;
if (pathEdit != null)
{
pathEdit["cell_size_meters"] = config.PathEditing.CellSizeMeters;
pathEdit["max_height_diff_meters"] = config.PathEditing.MaxHeightDiffMeters;
pathEdit["vehicle_length_meters"] = config.PathEditing.VehicleLengthMeters;
pathEdit["vehicle_width_meters"] = config.PathEditing.VehicleWidthMeters;
pathEdit["vehicle_height_meters"] = config.PathEditing.VehicleHeightMeters;
pathEdit["safety_margin_meters"] = config.PathEditing.SafetyMarginMeters;
pathEdit["default_path_turn_radius"] = config.PathEditing.DefaultPathTurnRadius;
pathEdit["arc_sampling_step"] = config.PathEditing.ArcSamplingStep;
}
}
// 更新可视化配置
if (model.ContainsKey("visualization"))
{
var visual = model["visualization"] as TomlTable;
if (visual != null)
{
visual["margin_ratio"] = config.Visualization.MarginRatio;
}
}
// 更新动画配置
if (model.ContainsKey("animation"))
{
var anim = model["animation"] as TomlTable;
if (anim != null)
{
anim["frame_rate"] = config.Animation.FrameRate;
anim["duration_seconds"] = config.Animation.DurationSeconds;
anim["detection_gap_meters"] = config.Animation.DetectionGapMeters;
}
}
// 更新物流属性配置
if (model.ContainsKey("logistics"))
{
var logistics = model["logistics"] as TomlTable;
if (logistics != null)
{
logistics["traversable"] = config.Logistics.Traversable;
logistics["priority"] = config.Logistics.Priority;
logistics["height_limit_meters"] = config.Logistics.HeightLimitMeters;
logistics["speed_limit_meters_per_second"] = config.Logistics.SpeedLimitMetersPerSecond;
logistics["width_limit_meters"] = config.Logistics.WidthLimitMeters;
}
}
}
/// <summary>
/// 重新加载配置文件
/// </summary>
public void Reload()
{
_currentConfig = LoadOrCreateDefault();
_currentConfig = LoadConfigFile();
}
/// <summary>
/// 重置为默认配置
/// 恢复为模板中的默认配置
/// </summary>
public void ResetToDefault()
public void RestoreToDefaults()
{
var defaultConfig = new SystemConfig();
SaveConfig(defaultConfig);
LogManager.Info("开始恢复默认配置...");
var templateContent = ReadConfigTemplate();
LogManager.Info($"模板内容长度: {templateContent.Length}");
LogManager.Info($"模板内容前200字符: {templateContent.Substring(0, Math.Min(200, templateContent.Length))}");
WriteConfigFileDirect(templateContent);
var newConfig = ParseTomlToConfig(templateContent);
LogManager.Info($"解析后的配置 - CellSizeMeters: {newConfig.PathEditing.CellSizeMeters}");
LogManager.Info($"解析后的配置 - VehicleLengthMeters: {newConfig.PathEditing.VehicleLengthMeters}");
_currentConfig = newConfig;
LogManager.Info("默认配置恢复完成");
}
// 辅助方法:从 TomlTable 获取值
private double GetDouble(TomlTable table, string key, double defaultValue)
// 辅助方法:从 TomlTable 获取必需
private double GetRequiredDoubleValue(TomlTable table, string key)
{
if (table.ContainsKey(key))
if (!table.ContainsKey(key))
{
var value = table[key];
if (value is long longValue)
return (double)longValue;
if (value is double doubleValue)
return doubleValue;
throw new InvalidOperationException($"配置项 '{key}' 不存在");
}
return defaultValue;
var value = table[key];
if (value is long longValue)
return (double)longValue;
if (value is double doubleValue)
return doubleValue;
throw new InvalidOperationException($"配置项 '{key}' 的类型错误,应为数值类型");
}
private int GetInt(TomlTable table, string key, int defaultValue)
private int GetRequiredIntValue(TomlTable table, string key)
{
if (table.ContainsKey(key) && table[key] is long longValue)
if (!table.ContainsKey(key))
{
throw new InvalidOperationException($"配置项 '{key}' 不存在");
}
var value = table[key];
if (value is long longValue)
return (int)longValue;
}
return defaultValue;
throw new InvalidOperationException($"配置项 '{key}' 的类型错误,应为整数类型");
}
private bool GetBool(TomlTable table, string key, bool defaultValue)
private bool GetRequiredBoolValue(TomlTable table, string key)
{
if (table.ContainsKey(key) && table[key] is bool boolValue)
if (!table.ContainsKey(key))
{
throw new InvalidOperationException($"配置项 '{key}' 不存在");
}
var value = table[key];
if (value is bool boolValue)
return boolValue;
}
return defaultValue;
}
private string GetString(TomlTable table, string key, string defaultValue)
{
if (table.ContainsKey(key) && table[key] is string stringValue)
{
return stringValue;
}
return defaultValue;
throw new InvalidOperationException($"配置项 '{key}' 的类型错误,应为布尔类型");
}
}
}

View File

@ -9,32 +9,32 @@ namespace NavisworksTransport.Core.Config
/// <summary>
/// 网格生成配置
/// </summary>
public GridGenerationConfig GridGeneration { get; set; } = new GridGenerationConfig();
public GridGenerationConfig GridGeneration { get; set; }
/// <summary>
/// 路径规划配置
/// </summary>
public PathPlanningConfig PathPlanning { get; set; } = new PathPlanningConfig();
public PathPlanningConfig PathPlanning { get; set; }
/// <summary>
/// 路径编辑配置
/// </summary>
public PathEditingConfig PathEditing { get; set; } = new PathEditingConfig();
public PathEditingConfig PathEditing { get; set; }
/// <summary>
/// 可视化配置
/// </summary>
public VisualizationConfig Visualization { get; set; } = new VisualizationConfig();
public VisualizationConfig Visualization { get; set; }
/// <summary>
/// 动画配置
/// </summary>
public AnimationConfig Animation { get; set; } = new AnimationConfig();
public AnimationConfig Animation { get; set; }
/// <summary>
/// 物流属性配置
/// </summary>
public LogisticsConfig Logistics { get; set; } = new LogisticsConfig();
public LogisticsConfig Logistics { get; set; }
}
/// <summary>
@ -58,49 +58,43 @@ namespace NavisworksTransport.Core.Config
{
/// <summary>
/// 网格单元大小(米)
/// 推荐值0.3-1.0
/// </summary>
public double CellSizeMeters { get; set; } = 0.5;
public double CellSizeMeters { get; set; }
/// <summary>
/// 最大高度差(米)
/// 楼梯、坡道可接受的高度阈值
/// </summary>
public double MaxHeightDiffMeters { get; set; } = 0.35;
public double MaxHeightDiffMeters { get; set; }
/// <summary>
/// 车辆长度(米)
/// </summary>
public double VehicleLengthMeters { get; set; } = 1.0;
public double VehicleLengthMeters { get; set; }
/// <summary>
/// 车辆宽度(米)
/// </summary>
public double VehicleWidthMeters { get; set; } = 1.0;
public double VehicleWidthMeters { get; set; }
/// <summary>
/// 车辆高度(米)
/// </summary>
public double VehicleHeightMeters { get; set; } = 2.0;
public double VehicleHeightMeters { get; set; }
/// <summary>
/// 安全间隙(米)
/// </summary>
public double SafetyMarginMeters { get; set; } = 0.05;
// 路径曲线化配置
public double SafetyMarginMeters { get; set; }
/// <summary>
/// 路径默认转弯半径(米)
/// 表示路径允许的最大转弯半径,车辆的最小转弯半径必须小于等于此值
/// </summary>
public double DefaultPathTurnRadius { get; set; } = 2.5;
public double DefaultPathTurnRadius { get; set; }
/// <summary>
/// 圆弧采样步长(米)
/// 推荐值0.02-0.1
/// </summary>
public double ArcSamplingStep { get; set; } = 0.05;
public double ArcSamplingStep { get; set; }
}
/// <summary>
@ -110,9 +104,8 @@ namespace NavisworksTransport.Core.Config
{
/// <summary>
/// 地图边距比例
/// 地图显示时的边距占比0-1之间
/// </summary>
public double MarginRatio { get; set; } = 0.1;
public double MarginRatio { get; set; }
}
/// <summary>
@ -123,17 +116,17 @@ namespace NavisworksTransport.Core.Config
/// <summary>
/// 动画帧率(帧/秒)
/// </summary>
public int FrameRate { get; set; } = 30;
public int FrameRate { get; set; }
/// <summary>
/// 动画持续时间(秒)
/// </summary>
public double DurationSeconds { get; set; } = 10.0;
public double DurationSeconds { get; set; }
/// <summary>
/// 检测间隙(米)
/// </summary>
public double DetectionGapMeters { get; set; } = 0.05;
public double DetectionGapMeters { get; set; }
}
/// <summary>
@ -142,28 +135,28 @@ namespace NavisworksTransport.Core.Config
public class LogisticsConfig
{
/// <summary>
/// 可通行性默认值true
/// 可通行性
/// </summary>
public bool Traversable { get; set; } = true;
public bool Traversable { get; set; }
/// <summary>
/// 优先级默认值5范围1-5
/// 优先级
/// </summary>
public int Priority { get; set; } = 5;
public int Priority { get; set; }
/// <summary>
/// 高度限制(默认值3.0米)
/// 高度限制(米)
/// </summary>
public double HeightLimitMeters { get; set; } = 3.0;
public double HeightLimitMeters { get; set; }
/// <summary>
/// 速度限制(默认值0.8米/秒)
/// 速度限制(米/秒)
/// </summary>
public double SpeedLimitMetersPerSecond { get; set; } = 0.8;
public double SpeedLimitMetersPerSecond { get; set; }
/// <summary>
/// 宽度限制(默认值3.0米)
/// 宽度限制(米)
/// </summary>
public double WidthLimitMeters { get; set; } = 3.0;
public double WidthLimitMeters { get; set; }
}
}

View File

@ -307,7 +307,8 @@ namespace NavisworksTransport
var p2 = sortedPoints[i + 1];
// 判断是否为转折点(需要圆弧过渡)
bool needsArc = (i > 0 && i < sortedPoints.Count - 1);
// 需要满足:不是第一段,不是最后一段,且还有下一个点用于计算圆弧
bool needsArc = (i > 0 && i < sortedPoints.Count - 2);
if (needsArc)
{
@ -326,7 +327,7 @@ namespace NavisworksTransport
}
else
{
// 直线边
// 直线边(第一段、最后一段或只有两个点时)
var edge = BuildStraightEdge(p1, p2, samplingStep);
route.Edges.Add(edge);
}

View File

@ -1399,6 +1399,17 @@ namespace NavisworksTransport
{
try
{
// 自动选择所有可通行的物流模型(先检查是否有可通行的模型)
AutoSelectLogisticsChannels();
// 检查是否有可通行的物流模型
if (_walkableAreas == null || _walkableAreas.Count == 0)
{
RaiseErrorOccurred("没有找到任何可通行的物流模型,请先为模型设置可通行的物流属性");
// 不需要重置状态,因为还没有进入创建状态
return null;
}
// 设置为创建状态
PathEditState = PathEditState.Creating;
@ -1407,18 +1418,6 @@ namespace NavisworksTransport
_editingRoute = newRoute;
SetCurrentRouteInternal(newRoute, triggerEvent: true);
// 自动选择所有可通行的物流模型
AutoSelectLogisticsChannels();
// 检查是否有可通行的物流模型
if (_walkableAreas == null || _walkableAreas.Count == 0)
{
RaiseErrorOccurred("没有找到任何可通行的物流模型,请先为模型设置可通行的物流属性");
// 重置状态
SwitchToViewingState();
return null;
}
// 智能管理ToolPlugin状态
ManageToolPluginForEditState();

View File

@ -173,7 +173,7 @@ namespace NavisworksTransport.UI.WPF.Views
{
try
{
ConfigManager.Instance.ResetToDefault();
ConfigManager.Instance.RestoreToDefaults();
LoadConfigContent();
StatusLabel.Content = "已恢复默认配置";
StatusLabel.Foreground = System.Windows.Media.Brushes.Green;