diff --git a/XplorePlane/Services/Cnc/CncProgramService.cs b/XplorePlane/Services/Cnc/CncProgramService.cs index f4fa478..f502f56 100644 --- a/XplorePlane/Services/Cnc/CncProgramService.cs +++ b/XplorePlane/Services/Cnc/CncProgramService.cs @@ -366,11 +366,21 @@ namespace XplorePlane.Services.Cnc var result = new List(nodes.Count); for (int i = 0; i < nodes.Count; i++) { - result.Add(nodes[i] with { Index = i }); + result.Add(ApplyDefaultNodeName(nodes[i] with { Index = i }, i)); } 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) { diff --git a/XplorePlane/ViewModels/Cnc/CncEditorViewModel.cs b/XplorePlane/ViewModels/Cnc/CncEditorViewModel.cs index 738b945..1f15e1e 100644 --- a/XplorePlane/ViewModels/Cnc/CncEditorViewModel.cs +++ b/XplorePlane/ViewModels/Cnc/CncEditorViewModel.cs @@ -416,6 +416,8 @@ namespace XplorePlane.ViewModels.Cnc private void RefreshNodes() { + NormalizeDefaultNodeNamesInCurrentProgram(); + var selectedId = _preferredSelectedNodeId ?? SelectedNode?.Id; var expansionState = Nodes.ToDictionary(node => node.Id, node => node.IsExpanded); @@ -466,6 +468,34 @@ namespace XplorePlane.ViewModels.Cnc _preferredSelectedNodeId = null; } + private void NormalizeDefaultNodeNamesInCurrentProgram() + { + if (_currentProgram?.Nodes == null || _currentProgram.Nodes.Count == 0) + { + return; + } + + var normalizedNodes = _currentProgram.Nodes + .Select((node, index) => ApplyDefaultNodeName(node with { Index = index }, index)) + .ToList() + .AsReadOnly(); + + bool changed = false; + for (int i = 0; i < normalizedNodes.Count; i++) + { + if (!Equals(normalizedNodes[i], _currentProgram.Nodes[i])) + { + changed = true; + break; + } + } + + if (changed) + { + _currentProgram = _currentProgram with { Nodes = normalizedNodes }; + } + } + private int ResolveInsertAfterIndex(CncNodeType nodeType) { if (_currentProgram == null || _currentProgram.Nodes.Count == 0) @@ -714,7 +744,7 @@ namespace XplorePlane.ViewModels.Cnc private CncProgram ReplaceProgramNodes(List nodes) { var renumberedNodes = nodes - .Select((node, index) => node with { Index = index }) + .Select((node, index) => ApplyDefaultNodeName(node with { Index = index }, index)) .ToList() .AsReadOnly(); @@ -725,6 +755,16 @@ namespace XplorePlane.ViewModels.Cnc }; } + private static CncNode ApplyDefaultNodeName(CncNode node, int index) + { + return node switch + { + ReferencePointNode referencePointNode => referencePointNode with { Name = $"参考点_{index}" }, + SavePositionNode savePositionNode => savePositionNode with { Name = $"保存位置_{index}" }, + _ => node + }; + } + private static bool IsSavePositionChild(CncNodeType type) { return type is CncNodeType.InspectionMarker diff --git a/XplorePlane/ViewModels/Cnc/CncNodeViewModel.cs b/XplorePlane/ViewModels/Cnc/CncNodeViewModel.cs index 6e00950..0fed114 100644 --- a/XplorePlane/ViewModels/Cnc/CncNodeViewModel.cs +++ b/XplorePlane/ViewModels/Cnc/CncNodeViewModel.cs @@ -37,6 +37,8 @@ namespace XplorePlane.ViewModels.Cnc set => UpdateModel(_model with { Name = value ?? string.Empty }); } + public bool IsReadOnlyNodeProperties => IsReferencePoint || IsSavePosition; + public CncNodeType NodeType => _model.NodeType; public string NodeTypeDisplay => NodeType.ToString(); diff --git a/XplorePlane/Views/Cnc/CncPageView.xaml b/XplorePlane/Views/Cnc/CncPageView.xaml index 9325c72..147fbf9 100644 --- a/XplorePlane/Views/Cnc/CncPageView.xaml +++ b/XplorePlane/Views/Cnc/CncPageView.xaml @@ -15,6 +15,8 @@ + + @@ -58,6 +60,19 @@ + +