在现有的 位置节点属性中新增一个 checkbox 按钮,来确认是否保存图片

This commit is contained in:
zhengxuan.zhang
2026-05-14 17:04:29 +08:00
parent ca22f59447
commit d3e75f3fac
10 changed files with 141 additions and 44 deletions
@@ -747,5 +747,54 @@ internal sealed class SynchronousProgress<T> : IProgress<T>
});
}
[Fact]
public async Task SavePosition_WithSaveImage_RefreshesInputImageForFollowingInspectionModule()
{
var (service, mockStore, _, mockMainViewport, _) = CreateService();
var initialImage = CreateBitmapSource(1, 1);
var refreshedImage = CreateBitmapSource(2, 3);
mockMainViewport.SetupGet(m => m.LatestManualImage).Returns((ImageSource)null);
mockMainViewport.SetupSequence(m => m.CurrentDisplayImage)
.Returns(initialImage)
.Returns(refreshedImage);
List<InspectionAssetWriteRequest> capturedAssets = null;
mockStore.Setup(s => s.AppendNodeResultAsync(
It.IsAny<InspectionNodeResult>(),
It.IsAny<IEnumerable<InspectionMetricResult>>(),
It.IsAny<PipelineExecutionSnapshot>(),
It.IsAny<IEnumerable<InspectionAssetWriteRequest>>()))
.Callback<InspectionNodeResult, IEnumerable<InspectionMetricResult>, PipelineExecutionSnapshot, IEnumerable<InspectionAssetWriteRequest>>(
(_, __, ___, assets) => capturedAssets = assets?.ToList())
.Returns(Task.CompletedTask);
var program = new CncProgram(
Guid.NewGuid(),
"Program",
DateTime.UtcNow,
DateTime.UtcNow,
new List<CncNode>
{
new SavePositionNode(Guid.NewGuid(), 0, "Pos_0", MotionState.Default, SaveImage: true),
new InspectionModuleNode(Guid.NewGuid(), 1, "Inspect_0", new PipelineModel { Name = "Pipeline" })
}.AsReadOnly());
await service.ExecuteAsync(program, null, CancellationToken.None);
var inputAsset = Assert.Single(capturedAssets.Where(a => a.AssetType == InspectionAssetType.NodeInputImage));
Assert.Equal(2, inputAsset.Width);
Assert.Equal(3, inputAsset.Height);
}
private static BitmapSource CreateBitmapSource(int width, int height)
{
var stride = width * 4;
var pixels = new byte[stride * height];
var bitmap = BitmapSource.Create(width, height, 96, 96, PixelFormats.Bgra32, null, pixels, stride);
bitmap.Freeze();
return bitmap;
}
}
}
@@ -7,15 +7,25 @@ using FsCheck.Fluent;
using FsCheck.Xunit;
using XplorePlane.Models;
using XplorePlane.ViewModels.Cnc;
using Xunit;
namespace XplorePlane.Tests.ViewModels
{
public class CncNodeViewModelTests
{
// ── Property 11: 节点执行状态转换正确性 ──────────────────────────────
[Fact]
public void SavePosition_SaveImage_CanBeUpdated()
{
var node = new SavePositionNode(Guid.NewGuid(), 0, "Pos_0", MotionState.Default, SaveImage: false);
var vm = new CncNodeViewModel(node, (_, __) => { });
vm.SaveImage = true;
var updatedNode = Assert.IsType<SavePositionNode>(vm.Model);
Assert.True(vm.SaveImage);
Assert.True(updatedNode.SaveImage);
}
// Feature: cnc-run-execution, Property 11: 节点执行状态转换正确性
// Validates: Requirements 6.1, 6.2
[Property(MaxTest = 100)]
public Property ExecutionState_TransitionsProduceCorrectBoolProperties()
{
@@ -30,31 +40,27 @@ namespace XplorePlane.Tests.ViewModels
gen.ToArbitrary(),
node =>
{
var vm = new CncNodeViewModel(node, (vm2, n) => { });
var vm = new CncNodeViewModel(node, (_, __) => { });
// Running
vm.ExecutionState = NodeExecutionState.Running;
bool runningOk = vm.IsRunningNode == true
&& vm.IsSucceededNode == false
&& vm.IsFailedNode == false;
bool runningOk = vm.IsRunningNode
&& !vm.IsSucceededNode
&& !vm.IsFailedNode;
// Succeeded
vm.ExecutionState = NodeExecutionState.Succeeded;
bool succeededOk = vm.IsRunningNode == false
&& vm.IsSucceededNode == true
&& vm.IsFailedNode == false;
bool succeededOk = !vm.IsRunningNode
&& vm.IsSucceededNode
&& !vm.IsFailedNode;
// Failed
vm.ExecutionState = NodeExecutionState.Failed;
bool failedOk = vm.IsRunningNode == false
&& vm.IsSucceededNode == false
&& vm.IsFailedNode == true;
bool failedOk = !vm.IsRunningNode
&& !vm.IsSucceededNode
&& vm.IsFailedNode;
// Idle
vm.ExecutionState = NodeExecutionState.Idle;
bool idleOk = vm.IsRunningNode == false
&& vm.IsSucceededNode == false
&& vm.IsFailedNode == false;
bool idleOk = !vm.IsRunningNode
&& !vm.IsSucceededNode
&& !vm.IsFailedNode;
return runningOk && succeededOk && failedOk && idleOk;
});