主视口没有可用图像时,回退到 IAppStateService.LatestDetectorFrame
This commit is contained in:
@@ -6,8 +6,10 @@ using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Media.Imaging;
|
||||
using XP.Common.Converters;
|
||||
using XP.Common.Logging.Interfaces;
|
||||
using XplorePlane.Models;
|
||||
using XplorePlane.Services.AppState;
|
||||
using XplorePlane.Services.InspectionResults;
|
||||
using XplorePlane.Services.MainViewport;
|
||||
using XplorePlane.ViewModels;
|
||||
@@ -22,6 +24,7 @@ namespace XplorePlane.Services.Cnc
|
||||
private readonly IInspectionResultStore _store;
|
||||
private readonly ILoggerService _logger;
|
||||
private readonly IMainViewportService _mainViewportService;
|
||||
private readonly IAppStateService _appStateService;
|
||||
private readonly IPipelineExecutionService _pipelineExecutionService;
|
||||
private readonly IImageProcessingService _imageProcessingService;
|
||||
|
||||
@@ -29,12 +32,14 @@ namespace XplorePlane.Services.Cnc
|
||||
IInspectionResultStore store,
|
||||
ILoggerService logger,
|
||||
IMainViewportService mainViewportService,
|
||||
IAppStateService appStateService,
|
||||
IPipelineExecutionService pipelineExecutionService,
|
||||
IImageProcessingService imageProcessingService)
|
||||
{
|
||||
_store = store ?? throw new ArgumentNullException(nameof(store));
|
||||
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
|
||||
_mainViewportService = mainViewportService;
|
||||
_appStateService = appStateService ?? throw new ArgumentNullException(nameof(appStateService));
|
||||
_pipelineExecutionService = pipelineExecutionService;
|
||||
_imageProcessingService = imageProcessingService;
|
||||
}
|
||||
@@ -46,10 +51,7 @@ namespace XplorePlane.Services.Cnc
|
||||
return;
|
||||
|
||||
int inspectionNodeCount = program.Nodes.OfType<InspectionModuleNode>().Count();
|
||||
|
||||
// 获取当前源图像(用于 run/source.bmp)
|
||||
var sourceImage = _mainViewportService?.LatestManualImage as BitmapSource
|
||||
?? _mainViewportService?.CurrentDisplayImage as BitmapSource;
|
||||
var sourceImage = TryGetSourceImage();
|
||||
|
||||
Guid runId;
|
||||
try
|
||||
@@ -105,7 +107,7 @@ namespace XplorePlane.Services.Cnc
|
||||
{
|
||||
case ReferencePointNode rp:
|
||||
_logger.ForModule<CncExecutionService>().Info(
|
||||
"执行参考点节点 [{Index}] {Name} | " +
|
||||
"Executing reference point node [{Index}] {Name} | " +
|
||||
"StageX={StageX} StageY={StageY} SourceZ={SourceZ} DetectorZ={DetectorZ} " +
|
||||
"DetectorSwing={DetectorSwing} FDD={FDD} FOD={FOD} Magnification={Magnification} " +
|
||||
"StageRotation={StageRotation} FixtureRotation={FixtureRotation} " +
|
||||
@@ -119,7 +121,7 @@ namespace XplorePlane.Services.Cnc
|
||||
|
||||
case SavePositionNode sp:
|
||||
_logger.ForModule<CncExecutionService>().Info(
|
||||
"执行保存位置节点 [{Index}] {Name} | " +
|
||||
"Executing save-position node [{Index}] {Name} | " +
|
||||
"StageX={StageX} StageY={StageY} SourceZ={SourceZ} DetectorZ={DetectorZ} " +
|
||||
"DetectorSwing={DetectorSwing} FDD={FDD} FOD={FOD} Magnification={Magnification} " +
|
||||
"StageRotation={StageRotation} FixtureRotation={FixtureRotation}",
|
||||
@@ -133,7 +135,7 @@ namespace XplorePlane.Services.Cnc
|
||||
|
||||
case SaveNodeNode sn:
|
||||
_logger.ForModule<CncExecutionService>().Info(
|
||||
"执行保存节点 [{Index}] {Name} | " +
|
||||
"Executing save node [{Index}] {Name} | " +
|
||||
"StageX={StageX} StageY={StageY} SourceZ={SourceZ} DetectorZ={DetectorZ} " +
|
||||
"DetectorSwing={DetectorSwing} FDD={FDD} FOD={FOD} Magnification={Magnification} " +
|
||||
"RayOn={RayOn} Voltage={Voltage}kV Power={Power}W",
|
||||
@@ -147,7 +149,7 @@ namespace XplorePlane.Services.Cnc
|
||||
|
||||
case SaveNodeWithImageNode sni:
|
||||
_logger.ForModule<CncExecutionService>().Info(
|
||||
"执行保存节点(图像) [{Index}] {Name} | " +
|
||||
"Executing save-with-image node [{Index}] {Name} | " +
|
||||
"StageX={StageX} StageY={StageY} SourceZ={SourceZ} DetectorZ={DetectorZ} " +
|
||||
"DetectorSwing={DetectorSwing} FDD={FDD} FOD={FOD} Magnification={Magnification} " +
|
||||
"RayOn={RayOn} Voltage={Voltage}kV Power={Power}W ImageFile={ImageFile}",
|
||||
@@ -218,7 +220,7 @@ namespace XplorePlane.Services.Cnc
|
||||
break;
|
||||
}
|
||||
|
||||
// InspectionModuleNode 完成时携带结果图像,供 ViewModel 缓存到节点上
|
||||
// Carry the latest inspection result image so the ViewModel can cache it on the node.
|
||||
var nodeResultImage = node is InspectionModuleNode ? lastResultImage : null;
|
||||
var finalState = nodeSucceeded ? NodeExecutionState.Succeeded : NodeExecutionState.Failed;
|
||||
progress?.Report(new CncNodeExecutionProgress(node.Id, finalState, nodeResultImage));
|
||||
@@ -242,6 +244,25 @@ namespace XplorePlane.Services.Cnc
|
||||
}
|
||||
}
|
||||
|
||||
private BitmapSource TryGetSourceImage()
|
||||
{
|
||||
var viewportImage = _mainViewportService?.LatestManualImage as BitmapSource
|
||||
?? _mainViewportService?.CurrentDisplayImage as BitmapSource;
|
||||
if (viewportImage != null)
|
||||
return viewportImage;
|
||||
|
||||
var detectorFrame = _appStateService?.LatestDetectorFrame;
|
||||
if (detectorFrame?.ImageData == null || detectorFrame.Width <= 0 || detectorFrame.Height <= 0)
|
||||
return null;
|
||||
|
||||
var bitmap = ImageConverter.ConvertGray16ToBitmapSource(
|
||||
detectorFrame.ImageData,
|
||||
(int)detectorFrame.Width,
|
||||
(int)detectorFrame.Height);
|
||||
bitmap.Freeze();
|
||||
return bitmap;
|
||||
}
|
||||
|
||||
private async Task<BitmapSource> ExecuteInspectionNodeAsync(
|
||||
Guid runId,
|
||||
InspectionModuleNode inspectionNode,
|
||||
@@ -304,7 +325,7 @@ namespace XplorePlane.Services.Cnc
|
||||
Height = resultImage.PixelHeight
|
||||
});
|
||||
nodeResult.Status = InspectionNodeStatus.Succeeded;
|
||||
_mainViewportService?.SetManualImage(resultImage, $"CNC节点:{inspectionNode.Name}");
|
||||
_mainViewportService?.SetManualImage(resultImage, $"CNC Node: {inspectionNode.Name}");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
||||
Reference in New Issue
Block a user