普通模式下图像算子拖动处理流程

This commit is contained in:
zhengxuan.zhang
2026-04-28 13:57:52 +08:00
parent 0d6a4bd22f
commit 89759cf511
3 changed files with 46 additions and 4 deletions
@@ -180,7 +180,7 @@ namespace XplorePlane.Services.MainViewport
_currentDisplayInfo = _latestManualInfo;
}
_logger.Info("主界面已加载手动图像 {FileName}", fileName);
_logger.Info("[图像链路] MainViewportService.SetManualImage:已更新图像 {FileName},触发 StateChanged", fileName);
RaiseStateChanged();
}
@@ -357,7 +357,12 @@ namespace XplorePlane.ViewModels
private async Task ExecutePipelineAsync()
{
if (SourceImage == null || IsExecuting) return;
if (SourceImage == null || IsExecuting)
{
_logger.Debug("[图像链路] ExecutePipelineAsync:跳过,SourceImage={HasImage}IsExecuting={IsExec}",
SourceImage != null, IsExecuting);
return;
}
if (TryReportInvalidParameters())
return;
@@ -368,6 +373,7 @@ namespace XplorePlane.ViewModels
IsExecuting = true;
SetInfoStatus("正在执行流水线...");
_logger.Info("[图像链路] ExecutePipelineAsync:开始执行,节点数={Count}", PipelineNodes.Count);
try
{
@@ -379,19 +385,23 @@ namespace XplorePlane.ViewModels
PreviewImage = result;
SetInfoStatus("流水线执行完成");
_logger.Info("[图像链路] ExecutePipelineAsync:执行完成,准备发布 PipelinePreviewUpdatedEvent");
PublishPipelinePreviewUpdated(result, StatusMessage);
}
catch (OperationCanceledException)
{
SetInfoStatus("流水线执行已取消");
_logger.Info("[图像链路] ExecutePipelineAsync:执行已取消");
}
catch (PipelineExecutionException ex)
{
SetErrorStatus($"执行失败:{ex.Message}");
_logger.Warn("[图像链路] ExecutePipelineAsync:执行失败 {Msg}", ex.Message);
}
catch (Exception ex)
{
SetErrorStatus($"执行错误:{ex.Message}");
_logger.Error(ex, "[图像链路] ExecutePipelineAsync:未预期异常");
}
finally
{
@@ -491,8 +501,13 @@ namespace XplorePlane.ViewModels
private void PublishPipelinePreviewUpdated(BitmapSource bitmap, string statusMessage)
{
if (bitmap == null) return;
if (bitmap == null)
{
_logger.Warn("[图像链路] PublishPipelinePreviewUpdatedbitmap 为 null,跳过发布");
return;
}
_logger.Info("[图像链路] PublishPipelinePreviewUpdated:发布事件,statusMessage={Msg}", statusMessage);
_eventAggregator.GetEvent<PipelinePreviewUpdatedEvent>()
.Publish(new PipelinePreviewUpdatedPayload(bitmap, statusMessage));
}
@@ -502,6 +517,7 @@ namespace XplorePlane.ViewModels
if (payload?.Image == null) return;
if (ReferenceEquals(SourceImage, payload.Image)) return;
_logger.Info("[图像链路] OnManualImageLoaded:收到图像 {File},设置 SourceImage", payload.FileName);
SourceImage = payload.Image;
PreviewImage = payload.Image;
SetInfoStatus($"已加载图像:{payload.FileName}");
@@ -514,8 +530,13 @@ namespace XplorePlane.ViewModels
private void TriggerDebouncedExecution()
{
if (SourceImage == null) return;
if (SourceImage == null)
{
_logger.Debug("[图像链路] TriggerDebouncedExecutionSourceImage 为 null,跳过执行");
return;
}
_logger.Debug("[图像链路] TriggerDebouncedExecution:触发防抖执行,节点数={Count}", PipelineNodes.Count);
_debounceCts?.Cancel();
_debounceCts = new CancellationTokenSource();
var token = _debounceCts.Token;
@@ -72,6 +72,9 @@ namespace XplorePlane.ViewModels
_cncEditorViewModel.RunCncCommand.CanExecuteChanged += (s, e) => RunCncCommand.RaiseCanExecuteChanged();
_cncEditorViewModel.StopCncCommand.CanExecuteChanged += (s, e) => StopCncCommand.RaiseCanExecuteChanged();
_eventAggregator.GetEvent<PipelinePreviewUpdatedEvent>()
.Subscribe(OnPipelinePreviewUpdated, ThreadOption.UIThread);
NavigationTree = new ObservableCollection<object>();
NavigateHomeCommand = new DelegateCommand(OnNavigateHome);
@@ -416,7 +419,14 @@ namespace XplorePlane.ViewModels
bitmap.EndInit();
bitmap.Freeze();
_logger.Info("[图像链路] ExecuteLoadImage:加载图像 {Path},准备推送到 MainViewportService 和 ManualImageLoadedEvent", dialog.FileName);
_mainViewportService.SetManualImage(bitmap, dialog.FileName);
// 同时发布事件,让 PipelineEditorViewModel 收到图像并触发流水线执行
_eventAggregator.GetEvent<ManualImageLoadedEvent>()
.Publish(new ManualImageLoadedPayload(bitmap, dialog.FileName));
_logger.Info("[图像链路] ManualImageLoadedEvent 已发布");
RaisePropertyChanged(nameof(IsUsingLiveDetectorSource));
}
catch (Exception ex)
@@ -553,5 +563,16 @@ namespace XplorePlane.ViewModels
RaisePropertyChanged(nameof(IsUsingLiveDetectorSource));
}));
}
private void OnPipelinePreviewUpdated(PipelinePreviewUpdatedPayload payload)
{
if (payload?.Image == null)
{
_logger.Warn("[图像链路] OnPipelinePreviewUpdatedpayload 或 Image 为 null,跳过");
return;
}
_logger.Info("[图像链路] OnPipelinePreviewUpdated:收到流水线结果图像,推送到 MainViewportService");
_mainViewportService.SetManualImage(payload.Image, string.Empty);
}
}
}