From 89759cf511ae9ddaedb29c8149c06b13fb519e64 Mon Sep 17 00:00:00 2001 From: "zhengxuan.zhang" Date: Tue, 28 Apr 2026 13:57:52 +0800 Subject: [PATCH] =?UTF-8?q?=E6=99=AE=E9=80=9A=E6=A8=A1=E5=BC=8F=E4=B8=8B?= =?UTF-8?q?=E5=9B=BE=E5=83=8F=E7=AE=97=E5=AD=90=E6=8B=96=E5=8A=A8=E5=A4=84?= =?UTF-8?q?=E7=90=86=E6=B5=81=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../MainViewport/MainViewportService.cs | 2 +- .../PipelineEditorViewModel.cs | 27 ++++++++++++++++--- XplorePlane/ViewModels/Main/MainViewModel.cs | 21 +++++++++++++++ 3 files changed, 46 insertions(+), 4 deletions(-) diff --git a/XplorePlane/Services/MainViewport/MainViewportService.cs b/XplorePlane/Services/MainViewport/MainViewportService.cs index ac13c50..27df11d 100644 --- a/XplorePlane/Services/MainViewport/MainViewportService.cs +++ b/XplorePlane/Services/MainViewport/MainViewportService.cs @@ -180,7 +180,7 @@ namespace XplorePlane.Services.MainViewport _currentDisplayInfo = _latestManualInfo; } - _logger.Info("主界面已加载手动图像 {FileName}", fileName); + _logger.Info("[图像链路] MainViewportService.SetManualImage:已更新图像 {FileName},触发 StateChanged", fileName); RaiseStateChanged(); } diff --git a/XplorePlane/ViewModels/ImageProcessing/PipelineEditorViewModel.cs b/XplorePlane/ViewModels/ImageProcessing/PipelineEditorViewModel.cs index 129c0fe..ca36fe9 100644 --- a/XplorePlane/ViewModels/ImageProcessing/PipelineEditorViewModel.cs +++ b/XplorePlane/ViewModels/ImageProcessing/PipelineEditorViewModel.cs @@ -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("[图像链路] PublishPipelinePreviewUpdated:bitmap 为 null,跳过发布"); + return; + } + _logger.Info("[图像链路] PublishPipelinePreviewUpdated:发布事件,statusMessage={Msg}", statusMessage); _eventAggregator.GetEvent() .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("[图像链路] TriggerDebouncedExecution:SourceImage 为 null,跳过执行"); + return; + } + _logger.Debug("[图像链路] TriggerDebouncedExecution:触发防抖执行,节点数={Count}", PipelineNodes.Count); _debounceCts?.Cancel(); _debounceCts = new CancellationTokenSource(); var token = _debounceCts.Token; diff --git a/XplorePlane/ViewModels/Main/MainViewModel.cs b/XplorePlane/ViewModels/Main/MainViewModel.cs index 43cdc1a..71df980 100644 --- a/XplorePlane/ViewModels/Main/MainViewModel.cs +++ b/XplorePlane/ViewModels/Main/MainViewModel.cs @@ -72,6 +72,9 @@ namespace XplorePlane.ViewModels _cncEditorViewModel.RunCncCommand.CanExecuteChanged += (s, e) => RunCncCommand.RaiseCanExecuteChanged(); _cncEditorViewModel.StopCncCommand.CanExecuteChanged += (s, e) => StopCncCommand.RaiseCanExecuteChanged(); + _eventAggregator.GetEvent() + .Subscribe(OnPipelinePreviewUpdated, ThreadOption.UIThread); + NavigationTree = new ObservableCollection(); 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() + .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("[图像链路] OnPipelinePreviewUpdated:payload 或 Image 为 null,跳过"); + return; + } + _logger.Info("[图像链路] OnPipelinePreviewUpdated:收到流水线结果图像,推送到 MainViewportService"); + _mainViewportService.SetManualImage(payload.Image, string.Empty); + } } }