检测模块_0 成连续编号

This commit is contained in:
zhengxuan.zhang
2026-04-24 10:57:21 +08:00
parent f3e77562b1
commit dbfa09a9fd
2 changed files with 39 additions and 26 deletions
+13 -12
View File
@@ -364,23 +364,24 @@ namespace XplorePlane.Services.Cnc
private static IReadOnlyList<CncNode> RenumberNodes(List<CncNode> nodes) private static IReadOnlyList<CncNode> RenumberNodes(List<CncNode> nodes)
{ {
var result = new List<CncNode>(nodes.Count); var result = new List<CncNode>(nodes.Count);
int referencePointNumber = 0;
int savePositionNumber = 0;
int inspectionModuleNumber = 0;
for (int i = 0; i < nodes.Count; i++) 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(); 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
};
}
/// <summary>创建参考点节点 | Create reference point node</summary> /// <summary>创建参考点节点 | Create reference point node</summary>
private ReferencePointNode CreateReferencePointNode(Guid id, int index) private ReferencePointNode CreateReferencePointNode(Guid id, int index)
{ {
@@ -424,7 +425,7 @@ namespace XplorePlane.Services.Cnc
private SavePositionNode CreateSavePositionNode(Guid id, int index) private SavePositionNode CreateSavePositionNode(Guid id, int index)
{ {
return new SavePositionNode( return new SavePositionNode(
id, index, $"保存位置_{index}", id, index, $"检测位置_{index}",
MotionState: _appStateService.MotionState); MotionState: _appStateService.MotionState);
} }
private double TryReadCurrent() private double TryReadCurrent()
@@ -475,10 +475,7 @@ namespace XplorePlane.ViewModels.Cnc
return; return;
} }
var normalizedNodes = _currentProgram.Nodes var normalizedNodes = ApplyDefaultNodeNames(_currentProgram.Nodes);
.Select((node, index) => ApplyDefaultNodeName(node with { Index = index }, index))
.ToList()
.AsReadOnly();
bool changed = false; bool changed = false;
for (int i = 0; i < normalizedNodes.Count; i++) for (int i = 0; i < normalizedNodes.Count; i++)
@@ -510,6 +507,12 @@ namespace XplorePlane.ViewModels.Cnc
if (!IsSavePositionChild(nodeType)) if (!IsSavePositionChild(nodeType))
{ {
int? currentSavePositionIndex = FindOwningSavePositionIndex(SelectedNode?.Index);
if (currentSavePositionIndex.HasValue)
{
return GetSavePositionBlockEndIndex(currentSavePositionIndex.Value);
}
return SelectedNode?.Index ?? _currentProgram.Nodes.Count - 1; return SelectedNode?.Index ?? _currentProgram.Nodes.Count - 1;
} }
@@ -743,10 +746,7 @@ namespace XplorePlane.ViewModels.Cnc
private CncProgram ReplaceProgramNodes(List<CncNode> nodes) private CncProgram ReplaceProgramNodes(List<CncNode> nodes)
{ {
var renumberedNodes = nodes var renumberedNodes = ApplyDefaultNodeNames(nodes);
.Select((node, index) => ApplyDefaultNodeName(node with { Index = index }, index))
.ToList()
.AsReadOnly();
return _currentProgram with return _currentProgram with
{ {
@@ -755,14 +755,26 @@ namespace XplorePlane.ViewModels.Cnc
}; };
} }
private static CncNode ApplyDefaultNodeName(CncNode node, int index) private static IReadOnlyList<CncNode> ApplyDefaultNodeNames(IReadOnlyList<CncNode> nodes)
{ {
return node switch var result = new List<CncNode>(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}" }, var indexedNode = nodes[i] with { Index = i };
SavePositionNode savePositionNode => savePositionNode with { Name = $"保存位置_{index}" }, result.Add(indexedNode switch
_ => node {
}; 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) private static bool IsSavePositionChild(CncNodeType type)