From f3e77562b1cb7e6a44913bb2befa54722ae1efeb Mon Sep 17 00:00:00 2001 From: "zhengxuan.zhang" Date: Fri, 24 Apr 2026 10:44:22 +0800 Subject: [PATCH] =?UTF-8?q?=E9=AB=98=E4=BA=AE=E8=8A=82=E7=82=B9=E3=80=81?= =?UTF-8?q?=E5=8F=96=E6=B6=88=E5=89=8D=E9=9D=A2=E7=9A=84[n]=E5=BA=8F?= =?UTF-8?q?=E5=8F=B7=E3=80=81=E5=8F=82=E8=80=83=E4=BD=8D=E7=BD=AE=EF=BC=8C?= =?UTF-8?q?=E4=BF=9D=E5=AD=98=E4=BD=8D=E7=BD=AE=EF=BC=8C=E5=8F=82=E6=95=B0?= =?UTF-8?q?=E5=8C=BA=E4=B8=BA=E5=8F=AA=E8=AF=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- XplorePlane/Services/Cnc/CncProgramService.cs | 12 +- .../ViewModels/Cnc/CncEditorViewModel.cs | 42 ++++- .../ViewModels/Cnc/CncNodeViewModel.cs | 2 + XplorePlane/Views/Cnc/CncPageView.xaml | 25 ++- XplorePlane/Views/Cnc/CncPageView.xaml.cs | 177 +++++++++++++++++- 5 files changed, 245 insertions(+), 13 deletions(-) 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 @@ + +