diff --git a/src/Core/PathPlanningManager.cs b/src/Core/PathPlanningManager.cs index ca5ecb9..a592a09 100644 --- a/src/Core/PathPlanningManager.cs +++ b/src/Core/PathPlanningManager.cs @@ -1927,6 +1927,40 @@ namespace NavisworksTransport } } + /// + /// 在3D视图中插入路径点(在指定位置) + /// + /// 3D世界坐标 + /// 点类型 + /// 插入的路径点 + 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; + } + /// /// 设置预览点位置(仅用于预览,不添加到路径中) /// @@ -2047,30 +2081,18 @@ namespace NavisworksTransport // 根据保存的插入索引决定添加方式 if (_previewInsertIndex >= 0 && _previewInsertIndex <= CurrentRoute.Points.Count) { - // 在指定位置插入路径点 - CurrentRoute.Points.Insert(_previewInsertIndex, confirmPoint); - LogManager.Info($"路径点已插入到索引 {_previewInsertIndex}: {confirmPoint.Name}, 位置: ({confirmPoint.Position.X:F2}, {confirmPoint.Position.Y:F2}, {confirmPoint.Position.Z:F2})"); + CurrentRoute.InsertPoint(confirmPoint, _previewInsertIndex); } else { - // 如果没有有效的插入索引,添加到末尾(原来的行为) CurrentRoute.AddPoint(confirmPoint); - LogManager.Info($"路径点已添加到末尾: {confirmPoint.Name}, 位置: ({confirmPoint.Position.X:F2}, {confirmPoint.Position.Y:F2}, {confirmPoint.Position.Z:F2})"); } // 清除预览状态 ClearPreviewPoint(); // 绘制3D路径可视化 - try - { - DrawRouteVisualization(CurrentRoute, isAutoPath: false); - LogManager.Info($"手工路径3D可视化已更新: {confirmPoint.Name}"); - } - catch (Exception renderEx) - { - LogManager.Error($"绘制手工路径3D可视化失败: {renderEx.Message}"); - } + DrawRouteVisualization(CurrentRoute, isAutoPath: false); // 触发路径点添加事件 RaisePathPointOperation(PathPointOperationType.Added, confirmPoint, CurrentRoute); diff --git a/src/Core/PathPlanningManagerEventArgs.cs b/src/Core/PathPlanningManagerEventArgs.cs index ebbd08a..48b61a6 100644 --- a/src/Core/PathPlanningManagerEventArgs.cs +++ b/src/Core/PathPlanningManagerEventArgs.cs @@ -336,6 +336,11 @@ namespace NavisworksTransport.Core /// Added, + /// + /// 插入 + /// + Inserted, + /// /// 删除 /// diff --git a/src/Core/PathPlanningModels.cs b/src/Core/PathPlanningModels.cs index d2b7cf4..d4d6708 100644 --- a/src/Core/PathPlanningModels.cs +++ b/src/Core/PathPlanningModels.cs @@ -618,6 +618,24 @@ namespace NavisworksTransport UpdateTotalLength(); } + /// + /// 在指定位置插入路径点 + /// + /// 要插入的路径点 + /// 插入位置索引 + 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(); + } + /// /// 移除路径点 ///