diff --git a/XplorePlane/Services/Cnc/CncProgramService.cs b/XplorePlane/Services/Cnc/CncProgramService.cs index f502f56..8765574 100644 --- a/XplorePlane/Services/Cnc/CncProgramService.cs +++ b/XplorePlane/Services/Cnc/CncProgramService.cs @@ -364,23 +364,24 @@ namespace XplorePlane.Services.Cnc private static IReadOnlyList RenumberNodes(List nodes) { var result = new List(nodes.Count); + int referencePointNumber = 0; + int savePositionNumber = 0; + int inspectionModuleNumber = 0; + for (int i = 0; i < nodes.Count; i++) { - result.Add(ApplyDefaultNodeName(nodes[i] with { Index = i }, i)); + var indexedNode = nodes[i] with { Index = i }; + result.Add(indexedNode switch + { + ReferencePointNode referencePointNode => referencePointNode with { Name = $"\u53C2\u8003\u70B9_{referencePointNumber++}" }, + SavePositionNode savePositionNode => savePositionNode with { Name = $"\u4FDD\u5B58\u4F4D\u7F6E_{savePositionNumber++}" }, + InspectionModuleNode inspectionModuleNode => inspectionModuleNode with { Name = $"\u68C0\u6D4B\u6A21\u5757_{inspectionModuleNumber++}" }, + _ => indexedNode + }); } return result.AsReadOnly(); } - private static CncNode ApplyDefaultNodeName(CncNode node, int index) - { - return node switch - { - ReferencePointNode referencePointNode => referencePointNode with { Name = $"参考点_{index}" }, - SavePositionNode savePositionNode => savePositionNode with { Name = $"保存位置_{index}" }, - _ => node - }; - } - /// 创建参考点节点 | Create reference point node private ReferencePointNode CreateReferencePointNode(Guid id, int index) { @@ -424,7 +425,7 @@ namespace XplorePlane.Services.Cnc private SavePositionNode CreateSavePositionNode(Guid id, int index) { return new SavePositionNode( - id, index, $"保存位置_{index}", + id, index, $"检测位置_{index}", MotionState: _appStateService.MotionState); } private double TryReadCurrent() diff --git a/XplorePlane/ViewModels/Cnc/CncEditorViewModel.cs b/XplorePlane/ViewModels/Cnc/CncEditorViewModel.cs index 1f15e1e..60a5c6e 100644 --- a/XplorePlane/ViewModels/Cnc/CncEditorViewModel.cs +++ b/XplorePlane/ViewModels/Cnc/CncEditorViewModel.cs @@ -475,10 +475,7 @@ namespace XplorePlane.ViewModels.Cnc return; } - var normalizedNodes = _currentProgram.Nodes - .Select((node, index) => ApplyDefaultNodeName(node with { Index = index }, index)) - .ToList() - .AsReadOnly(); + var normalizedNodes = ApplyDefaultNodeNames(_currentProgram.Nodes); bool changed = false; for (int i = 0; i < normalizedNodes.Count; i++) @@ -510,6 +507,12 @@ namespace XplorePlane.ViewModels.Cnc if (!IsSavePositionChild(nodeType)) { + int? currentSavePositionIndex = FindOwningSavePositionIndex(SelectedNode?.Index); + if (currentSavePositionIndex.HasValue) + { + return GetSavePositionBlockEndIndex(currentSavePositionIndex.Value); + } + return SelectedNode?.Index ?? _currentProgram.Nodes.Count - 1; } @@ -743,10 +746,7 @@ namespace XplorePlane.ViewModels.Cnc private CncProgram ReplaceProgramNodes(List nodes) { - var renumberedNodes = nodes - .Select((node, index) => ApplyDefaultNodeName(node with { Index = index }, index)) - .ToList() - .AsReadOnly(); + var renumberedNodes = ApplyDefaultNodeNames(nodes); return _currentProgram with { @@ -755,14 +755,26 @@ namespace XplorePlane.ViewModels.Cnc }; } - private static CncNode ApplyDefaultNodeName(CncNode node, int index) + private static IReadOnlyList ApplyDefaultNodeNames(IReadOnlyList nodes) { - return node switch + var result = new List(nodes.Count); + int referencePointNumber = 0; + int savePositionNumber = 0; + int inspectionModuleNumber = 0; + + for (int i = 0; i < nodes.Count; i++) { - ReferencePointNode referencePointNode => referencePointNode with { Name = $"参考点_{index}" }, - SavePositionNode savePositionNode => savePositionNode with { Name = $"保存位置_{index}" }, - _ => node - }; + var indexedNode = nodes[i] with { Index = i }; + result.Add(indexedNode switch + { + ReferencePointNode referencePointNode => referencePointNode with { Name = $"\u53C2\u8003\u70B9_{referencePointNumber++}" }, + SavePositionNode savePositionNode => savePositionNode with { Name = $"\u4FDD\u5B58\u4F4D\u7F6E_{savePositionNumber++}" }, + InspectionModuleNode inspectionModuleNode => inspectionModuleNode with { Name = $"\u68C0\u6D4B\u6A21\u5757_{inspectionModuleNumber++}" }, + _ => indexedNode + }); + } + + return result.AsReadOnly(); } private static bool IsSavePositionChild(CncNodeType type)