算子工具箱增加 +形式

This commit is contained in:
zhengxuan.zhang
2026-05-07 13:06:13 +08:00
parent aa39f8ca95
commit 3c9b3a2731
4 changed files with 99 additions and 22 deletions
@@ -0,0 +1,11 @@
using Prism.Events;
namespace XplorePlane.Events
{
/// <summary>
/// 请求向当前流水线追加算子的事件,由算子工具箱发布,PipelineEditorViewModel 订阅
/// </summary>
public sealed class AddOperatorRequestedEvent : PubSubEvent<string>
{
}
}
@@ -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<OperatorDescriptor>();
FilteredOperators = new ObservableCollection<OperatorDescriptor>();
FilteredGroups = new ObservableCollection<OperatorGroupViewModel>();
AddOperatorCommand = new DelegateCommand<string>(AddOperator);
LoadOperators();
}
@@ -53,6 +59,8 @@ namespace XplorePlane.ViewModels
public ObservableCollection<OperatorDescriptor> FilteredOperators { get; }
public ObservableCollection<OperatorGroupViewModel> FilteredGroups { get; }
public DelegateCommand<string> 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<AddOperatorRequestedEvent>().Publish(operatorKey);
}
}
}
@@ -83,6 +83,9 @@ namespace XplorePlane.ViewModels
_eventAggregator.GetEvent<ManualImageLoadedEvent>()
.Subscribe(OnManualImageLoaded);
_eventAggregator.GetEvent<AddOperatorRequestedEvent>()
.Subscribe(key => { if (CanAddOperator(key)) AddOperator(key); });
}
// ── State Properties ──────────────────────────────────────────
@@ -135,7 +135,12 @@
</Style.Triggers>
</Style>
</Border.Style>
<StackPanel Orientation="Horizontal">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<StackPanel Grid.Column="0" Orientation="Horizontal">
<Border Width="28"
Height="28"
Background="#EEF2FF"
@@ -157,6 +162,50 @@
Foreground="#999" />
</StackPanel>
</StackPanel>
<Button Grid.Column="1"
Width="24"
Height="24"
Margin="6,0,0,0"
VerticalAlignment="Center"
Cursor="Hand"
ToolTip="添加到流水线"
Command="{Binding DataContext.AddOperatorCommand, RelativeSource={RelativeSource AncestorType=UserControl}}"
CommandParameter="{Binding Key}">
<Button.Style>
<Style TargetType="Button">
<Setter Property="Background" Value="Transparent" />
<Setter Property="BorderThickness" Value="0" />
<Setter Property="Padding" Value="0" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Border Background="{TemplateBinding Background}"
CornerRadius="4"
Padding="2">
<ContentPresenter HorizontalAlignment="Center"
VerticalAlignment="Center" />
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="#C8DCFF" />
</Trigger>
<Trigger Property="IsPressed" Value="True">
<Setter Property="Background" Value="#A0C0F0" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Button.Style>
<TextBlock Text="+"
FontSize="16"
FontWeight="Bold"
Foreground="#5B9BD5"
VerticalAlignment="Center"
HorizontalAlignment="Center" />
</Button>
</Grid>
</Border>
</DataTemplate>
</ItemsControl.ItemTemplate>