From 3c9b3a273122a58f8274602ea0810b57ed97aaf3 Mon Sep 17 00:00:00 2001 From: "zhengxuan.zhang" Date: Thu, 7 May 2026 13:06:13 +0800 Subject: [PATCH] =?UTF-8?q?=E7=AE=97=E5=AD=90=E5=B7=A5=E5=85=B7=E7=AE=B1?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20+=E5=BD=A2=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Events/AddOperatorRequestedEvent.cs | 11 +++ .../OperatorToolboxViewModel.cs | 16 +++- .../PipelineEditorViewModel.cs | 3 + .../ImageProcessing/OperatorToolboxView.xaml | 91 ++++++++++++++----- 4 files changed, 99 insertions(+), 22 deletions(-) create mode 100644 XplorePlane/Events/AddOperatorRequestedEvent.cs diff --git a/XplorePlane/Events/AddOperatorRequestedEvent.cs b/XplorePlane/Events/AddOperatorRequestedEvent.cs new file mode 100644 index 0000000..7643779 --- /dev/null +++ b/XplorePlane/Events/AddOperatorRequestedEvent.cs @@ -0,0 +1,11 @@ +using Prism.Events; + +namespace XplorePlane.Events +{ + /// + /// 请求向当前流水线追加算子的事件,由算子工具箱发布,PipelineEditorViewModel 订阅 + /// + public sealed class AddOperatorRequestedEvent : PubSubEvent + { + } +} diff --git a/XplorePlane/ViewModels/ImageProcessing/OperatorToolboxViewModel.cs b/XplorePlane/ViewModels/ImageProcessing/OperatorToolboxViewModel.cs index b704c3f..027f803 100644 --- a/XplorePlane/ViewModels/ImageProcessing/OperatorToolboxViewModel.cs +++ b/XplorePlane/ViewModels/ImageProcessing/OperatorToolboxViewModel.cs @@ -1,8 +1,11 @@ +using Prism.Commands; +using Prism.Events; using Prism.Mvvm; using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; +using XplorePlane.Events; using XplorePlane.Services; namespace XplorePlane.ViewModels @@ -35,17 +38,20 @@ namespace XplorePlane.ViewModels public class OperatorToolboxViewModel : BindableBase { private readonly IImageProcessingService _imageProcessingService; + private readonly IEventAggregator _eventAggregator; private string _searchText = string.Empty; private OperatorGroupViewModel _selectedGroup; // UI 元数据(分类 + 图标)由 ProcessorUiMetadata 统一提供,保持工具箱与流水线图标一致 - public OperatorToolboxViewModel(IImageProcessingService imageProcessingService) + public OperatorToolboxViewModel(IImageProcessingService imageProcessingService, IEventAggregator eventAggregator) { _imageProcessingService = imageProcessingService ?? throw new ArgumentNullException(nameof(imageProcessingService)); + _eventAggregator = eventAggregator ?? throw new ArgumentNullException(nameof(eventAggregator)); AvailableOperators = new ObservableCollection(); FilteredOperators = new ObservableCollection(); FilteredGroups = new ObservableCollection(); + AddOperatorCommand = new DelegateCommand(AddOperator); LoadOperators(); } @@ -53,6 +59,8 @@ namespace XplorePlane.ViewModels public ObservableCollection FilteredOperators { get; } public ObservableCollection FilteredGroups { get; } + public DelegateCommand AddOperatorCommand { get; } + public OperatorGroupViewModel SelectedGroup { get => _selectedGroup; @@ -124,5 +132,11 @@ namespace XplorePlane.ViewModels "检测分析" => 6, _ => 99 }; + + private void AddOperator(string operatorKey) + { + if (!string.IsNullOrWhiteSpace(operatorKey)) + _eventAggregator.GetEvent().Publish(operatorKey); + } } } diff --git a/XplorePlane/ViewModels/ImageProcessing/PipelineEditorViewModel.cs b/XplorePlane/ViewModels/ImageProcessing/PipelineEditorViewModel.cs index 2494bfd..f0233c0 100644 --- a/XplorePlane/ViewModels/ImageProcessing/PipelineEditorViewModel.cs +++ b/XplorePlane/ViewModels/ImageProcessing/PipelineEditorViewModel.cs @@ -83,6 +83,9 @@ namespace XplorePlane.ViewModels _eventAggregator.GetEvent() .Subscribe(OnManualImageLoaded); + + _eventAggregator.GetEvent() + .Subscribe(key => { if (CanAddOperator(key)) AddOperator(key); }); } // ── State Properties ────────────────────────────────────────── diff --git a/XplorePlane/Views/ImageProcessing/OperatorToolboxView.xaml b/XplorePlane/Views/ImageProcessing/OperatorToolboxView.xaml index 9c5ff9d..fc69075 100644 --- a/XplorePlane/Views/ImageProcessing/OperatorToolboxView.xaml +++ b/XplorePlane/Views/ImageProcessing/OperatorToolboxView.xaml @@ -135,28 +135,77 @@ - - - - - - - + + + + + + + + + + + + + - + +