修正了路径导入导出的数据缺少路径类型和吊装高度的问题
This commit is contained in:
parent
c24bff692e
commit
3a79f0e50e
@ -47,9 +47,11 @@ namespace NavisworksTransport
|
||||
public string id { get; set; }
|
||||
public string name { get; set; }
|
||||
public string description { get; set; }
|
||||
public string pathType { get; set; }
|
||||
public double totalLength { get; set; }
|
||||
public JsonVehicleLimits vehicleLimits { get; set; }
|
||||
public double gridSize { get; set; }
|
||||
public double liftHeightMeters { get; set; }
|
||||
public string created { get; set; }
|
||||
public JsonPathPoint[] points { get; set; }
|
||||
}
|
||||
@ -266,6 +268,7 @@ namespace NavisworksTransport
|
||||
id = route.Id,
|
||||
name = route.Name,
|
||||
description = route.Description ?? "",
|
||||
pathType = route.PathType.ToString(),
|
||||
totalLength = Math.Round(route.TotalLength, exportSettings?.Precision ?? 6),
|
||||
vehicleLimits = new
|
||||
{
|
||||
@ -275,6 +278,7 @@ namespace NavisworksTransport
|
||||
safetyMargin = Math.Round(route.SafetyMargin, exportSettings?.Precision ?? 6)
|
||||
},
|
||||
gridSize = Math.Round(route.GridSize, exportSettings?.Precision ?? 6),
|
||||
liftHeightMeters = Math.Round(route.LiftHeightMeters, exportSettings?.Precision ?? 6),
|
||||
created = route.CreatedTime.ToString("yyyy-MM-ddTHH:mm:ss"),
|
||||
points = route.GetSortedPoints().Select(point => new
|
||||
{
|
||||
@ -472,13 +476,33 @@ namespace NavisworksTransport
|
||||
Id = jsonRoute.id,
|
||||
Description = jsonRoute.description ?? "",
|
||||
CreatedTime = ParseJsonDateTime(jsonRoute.created),
|
||||
MaxVehicleLength = jsonRoute.vehicleLimits?.maxLength ?? 1.0,
|
||||
MaxVehicleWidth = jsonRoute.vehicleLimits?.maxWidth ?? 1.0,
|
||||
MaxVehicleHeight = jsonRoute.vehicleLimits?.maxHeight ?? 2.0,
|
||||
SafetyMargin = jsonRoute.vehicleLimits?.safetyMargin ?? 0.25,
|
||||
GridSize = jsonRoute.gridSize > 0 ? jsonRoute.gridSize : 0.5
|
||||
MaxVehicleLength = jsonRoute.vehicleLimits?.maxLength ?? 0,
|
||||
MaxVehicleWidth = jsonRoute.vehicleLimits?.maxWidth ?? 0,
|
||||
MaxVehicleHeight = jsonRoute.vehicleLimits?.maxHeight ?? 0,
|
||||
SafetyMargin = jsonRoute.vehicleLimits?.safetyMargin ?? 0,
|
||||
GridSize = jsonRoute.gridSize,
|
||||
LiftHeightMeters = jsonRoute.liftHeightMeters
|
||||
};
|
||||
|
||||
// 🔥 解析路径类型(关键字段,不输则报错)
|
||||
if (!string.IsNullOrEmpty(jsonRoute.pathType))
|
||||
{
|
||||
if (Enum.TryParse<PathType>(jsonRoute.pathType, out var pathType))
|
||||
{
|
||||
route.PathType = pathType;
|
||||
}
|
||||
else
|
||||
{
|
||||
LogManager.Error($"无法解析路径类型: {jsonRoute.pathType},路径: {jsonRoute.name}");
|
||||
continue;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
LogManager.Error($"路径类型缺失,路径: {jsonRoute.name}");
|
||||
continue;
|
||||
}
|
||||
|
||||
// 解析路径点
|
||||
var points = new List<PathPoint>();
|
||||
foreach (var jsonPoint in jsonRoute.points)
|
||||
@ -963,12 +987,14 @@ namespace NavisworksTransport
|
||||
routeElement.SetAttribute("id", route.Id);
|
||||
routeElement.SetAttribute("name", route.Name);
|
||||
routeElement.SetAttribute("description", route.Description ?? "");
|
||||
routeElement.SetAttribute("pathType", route.PathType.ToString());
|
||||
routeElement.SetAttribute("totalLength", route.TotalLength.ToString("F3"));
|
||||
routeElement.SetAttribute("maxVehicleLength", route.MaxVehicleLength.ToString("F3"));
|
||||
routeElement.SetAttribute("maxVehicleWidth", route.MaxVehicleWidth.ToString("F3"));
|
||||
routeElement.SetAttribute("maxVehicleHeight", route.MaxVehicleHeight.ToString("F3"));
|
||||
routeElement.SetAttribute("safetyMargin", route.SafetyMargin.ToString("F3"));
|
||||
routeElement.SetAttribute("gridSize", route.GridSize.ToString("F3"));
|
||||
routeElement.SetAttribute("liftHeightMeters", route.LiftHeightMeters.ToString("F3"));
|
||||
routeElement.SetAttribute("created", route.CreatedTime.ToString("yyyy-MM-ddTHH:mm:ss"));
|
||||
|
||||
// 添加路径点
|
||||
@ -1066,16 +1092,32 @@ namespace NavisworksTransport
|
||||
{
|
||||
try
|
||||
{
|
||||
// 🔥 路径类型是必需字段
|
||||
var pathTypeStr = routeNode.Attributes?["pathType"]?.Value;
|
||||
if (string.IsNullOrEmpty(pathTypeStr))
|
||||
{
|
||||
LogManager.Error("XML导入失败:路径类型(pathType)属性缺失");
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!Enum.TryParse<PathType>(pathTypeStr, out var pathType))
|
||||
{
|
||||
LogManager.Error($"XML导入失败:无法解析路径类型 '{pathTypeStr}'");
|
||||
return null;
|
||||
}
|
||||
|
||||
var route = new PathRoute
|
||||
{
|
||||
Id = routeNode.Attributes?["id"]?.Value ?? Guid.NewGuid().ToString(),
|
||||
Name = routeNode.Attributes?["name"]?.Value ?? "导入路径",
|
||||
Description = routeNode.Attributes?["description"]?.Value ?? "",
|
||||
MaxVehicleLength = double.TryParse(routeNode.Attributes?["maxVehicleLength"]?.Value, out double maxLength) ? maxLength : 1.0,
|
||||
MaxVehicleWidth = double.TryParse(routeNode.Attributes?["maxVehicleWidth"]?.Value, out double maxWidth) ? maxWidth : 1.0,
|
||||
MaxVehicleHeight = double.TryParse(routeNode.Attributes?["maxVehicleHeight"]?.Value, out double maxHeight) ? maxHeight : 2.0,
|
||||
SafetyMargin = double.TryParse(routeNode.Attributes?["safetyMargin"]?.Value, out double safetyMargin) ? safetyMargin : 0.5,
|
||||
GridSize = double.TryParse(routeNode.Attributes?["gridSize"]?.Value, out double gridSize) ? gridSize : 0.5
|
||||
PathType = pathType,
|
||||
MaxVehicleLength = double.TryParse(routeNode.Attributes?["maxVehicleLength"]?.Value, out double maxLength) ? maxLength : 0,
|
||||
MaxVehicleWidth = double.TryParse(routeNode.Attributes?["maxVehicleWidth"]?.Value, out double maxWidth) ? maxWidth : 0,
|
||||
MaxVehicleHeight = double.TryParse(routeNode.Attributes?["maxVehicleHeight"]?.Value, out double maxHeight) ? maxHeight : 0,
|
||||
SafetyMargin = double.TryParse(routeNode.Attributes?["safetyMargin"]?.Value, out double safetyMargin) ? safetyMargin : 0,
|
||||
GridSize = double.TryParse(routeNode.Attributes?["gridSize"]?.Value, out double gridSize) ? gridSize : 0,
|
||||
LiftHeightMeters = double.TryParse(routeNode.Attributes?["liftHeightMeters"]?.Value, out double liftHeight) ? liftHeight : 0
|
||||
};
|
||||
|
||||
// 解析创建时间
|
||||
|
||||
Loading…
Reference in New Issue
Block a user