diff --git a/XplorePlane/Services/Matrix/IMatrixService.cs b/XplorePlane/Services/Matrix/IMatrixService.cs
index 8815d45..24a3e87 100644
--- a/XplorePlane/Services/Matrix/IMatrixService.cs
+++ b/XplorePlane/Services/Matrix/IMatrixService.cs
@@ -22,7 +22,7 @@ namespace XplorePlane.Services.Matrix
MatrixLayout ToggleCellEnabled(MatrixLayout layout, int row, int column);
/// 关联 CNC 程序到矩阵布局 | Associate a CNC program with the matrix layout
- MatrixLayout AssociateCncProgram(MatrixLayout layout, CncProgram program);
+ MatrixLayout AssociateCncProgram(MatrixLayout layout, CncProgram program, string filePath = null);
/// 将矩阵布局保存到 JSON 文件 | Save matrix layout to JSON file
Task SaveAsync(MatrixLayout layout, string filePath);
diff --git a/XplorePlane/Services/Matrix/MatrixService.cs b/XplorePlane/Services/Matrix/MatrixService.cs
index 100fe82..cad176a 100644
--- a/XplorePlane/Services/Matrix/MatrixService.cs
+++ b/XplorePlane/Services/Matrix/MatrixService.cs
@@ -123,15 +123,17 @@ namespace XplorePlane.Services.Matrix
}
///
- public MatrixLayout AssociateCncProgram(MatrixLayout layout, CncProgram program)
+ public MatrixLayout AssociateCncProgram(MatrixLayout layout, CncProgram program, string filePath = null)
{
ArgumentNullException.ThrowIfNull(layout);
ArgumentNullException.ThrowIfNull(program);
- var updated = layout with { CncProgramPath = program.Name };
+ // 优先使用传入的文件路径(绝对路径),否则回退到程序名
+ var programPath = !string.IsNullOrWhiteSpace(filePath) ? filePath : program.Name;
+ var updated = layout with { CncProgramPath = programPath };
- _logger.Info("已关联 CNC 程序到矩阵布局 | Associated CNC program with matrix layout: LayoutId={LayoutId}, Program={ProgramName}",
- layout.Id, program.Name);
+ _logger.Info("已关联 CNC 程序到矩阵布局 | Associated CNC program with matrix layout: LayoutId={LayoutId}, Program={ProgramPath}",
+ layout.Id, programPath);
return updated;
}
diff --git a/XplorePlane/ViewModels/Cnc/MatrixEditorViewModel.cs b/XplorePlane/ViewModels/Cnc/MatrixEditorViewModel.cs
index 6bfe8bb..dc366cc 100644
--- a/XplorePlane/ViewModels/Cnc/MatrixEditorViewModel.cs
+++ b/XplorePlane/ViewModels/Cnc/MatrixEditorViewModel.cs
@@ -409,7 +409,7 @@ namespace XplorePlane.ViewModels.Cnc
return;
}
- _currentLayout = _matrixService.AssociateCncProgram(_currentLayout, program);
+ _currentLayout = _matrixService.AssociateCncProgram(_currentLayout, program, filePath);
AssociatedProgramPath = filePath;
_logger.Info("已关联 CNC 程序 | Associated CNC program: {ProgramPath}", filePath);
}