更正插入路径点的问题。

This commit is contained in:
tian 2026-01-06 18:01:23 +08:00
parent e3958affb7
commit 792d6d249c
3 changed files with 59 additions and 14 deletions

View File

@ -1927,6 +1927,40 @@ namespace NavisworksTransport
} }
} }
/// <summary>
/// 在3D视图中插入路径点在指定位置
/// </summary>
/// <param name="worldPoint">3D世界坐标</param>
/// <param name="pointType">点类型</param>
/// <returns>插入的路径点</returns>
public PathPoint InsertPathPointIn3D(Point3D worldPoint, PathPointType? pointType = null)
{
var insertInfo = FindNearestLineSegmentWithIndex(worldPoint, CurrentRoute.Points);
if (!insertInfo.HasValue)
{
throw new InvalidOperationException("无法确定插入位置");
}
PathPointType finalPointType = pointType ?? PathPointType.WayPoint;
var pathPoint = new PathPoint
{
Name = GeneratePointName(finalPointType),
Position = worldPoint,
Type = finalPointType
};
CurrentRoute.InsertPoint(pathPoint, insertInfo.Value.insertIndex);
DrawRouteVisualization(CurrentRoute, isAutoPath: false);
RaisePathPointOperation(PathPointOperationType.Inserted, pathPoint, CurrentRoute);
RaisePathPointsListUpdated(CurrentRoute, "插入路径点");
return pathPoint;
}
/// <summary> /// <summary>
/// 设置预览点位置(仅用于预览,不添加到路径中) /// 设置预览点位置(仅用于预览,不添加到路径中)
/// </summary> /// </summary>
@ -2047,30 +2081,18 @@ namespace NavisworksTransport
// 根据保存的插入索引决定添加方式 // 根据保存的插入索引决定添加方式
if (_previewInsertIndex >= 0 && _previewInsertIndex <= CurrentRoute.Points.Count) if (_previewInsertIndex >= 0 && _previewInsertIndex <= CurrentRoute.Points.Count)
{ {
// 在指定位置插入路径点 CurrentRoute.InsertPoint(confirmPoint, _previewInsertIndex);
CurrentRoute.Points.Insert(_previewInsertIndex, confirmPoint);
LogManager.Info($"路径点已插入到索引 {_previewInsertIndex}: {confirmPoint.Name}, 位置: ({confirmPoint.Position.X:F2}, {confirmPoint.Position.Y:F2}, {confirmPoint.Position.Z:F2})");
} }
else else
{ {
// 如果没有有效的插入索引,添加到末尾(原来的行为)
CurrentRoute.AddPoint(confirmPoint); CurrentRoute.AddPoint(confirmPoint);
LogManager.Info($"路径点已添加到末尾: {confirmPoint.Name}, 位置: ({confirmPoint.Position.X:F2}, {confirmPoint.Position.Y:F2}, {confirmPoint.Position.Z:F2})");
} }
// 清除预览状态 // 清除预览状态
ClearPreviewPoint(); ClearPreviewPoint();
// 绘制3D路径可视化 // 绘制3D路径可视化
try DrawRouteVisualization(CurrentRoute, isAutoPath: false);
{
DrawRouteVisualization(CurrentRoute, isAutoPath: false);
LogManager.Info($"手工路径3D可视化已更新: {confirmPoint.Name}");
}
catch (Exception renderEx)
{
LogManager.Error($"绘制手工路径3D可视化失败: {renderEx.Message}");
}
// 触发路径点添加事件 // 触发路径点添加事件
RaisePathPointOperation(PathPointOperationType.Added, confirmPoint, CurrentRoute); RaisePathPointOperation(PathPointOperationType.Added, confirmPoint, CurrentRoute);

View File

@ -336,6 +336,11 @@ namespace NavisworksTransport.Core
/// </summary> /// </summary>
Added, Added,
/// <summary>
/// 插入
/// </summary>
Inserted,
/// <summary> /// <summary>
/// 删除 /// 删除
/// </summary> /// </summary>

View File

@ -618,6 +618,24 @@ namespace NavisworksTransport
UpdateTotalLength(); UpdateTotalLength();
} }
/// <summary>
/// 在指定位置插入路径点
/// </summary>
/// <param name="point">要插入的路径点</param>
/// <param name="insertIndex">插入位置索引</param>
public void InsertPoint(PathPoint point, int insertIndex)
{
Points.Insert(insertIndex, point);
for (int i = 0; i < Points.Count; i++)
{
Points[i].Index = i;
}
LastModified = DateTime.Now;
UpdateTotalLength();
}
/// <summary> /// <summary>
/// 移除路径点 /// 移除路径点
/// </summary> /// </summary>