算子工具箱增加 +形式

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 Prism.Mvvm;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.Linq; using System.Linq;
using XplorePlane.Events;
using XplorePlane.Services; using XplorePlane.Services;
namespace XplorePlane.ViewModels namespace XplorePlane.ViewModels
@@ -35,17 +38,20 @@ namespace XplorePlane.ViewModels
public class OperatorToolboxViewModel : BindableBase public class OperatorToolboxViewModel : BindableBase
{ {
private readonly IImageProcessingService _imageProcessingService; private readonly IImageProcessingService _imageProcessingService;
private readonly IEventAggregator _eventAggregator;
private string _searchText = string.Empty; private string _searchText = string.Empty;
private OperatorGroupViewModel _selectedGroup; private OperatorGroupViewModel _selectedGroup;
// UI 元数据(分类 + 图标)由 ProcessorUiMetadata 统一提供,保持工具箱与流水线图标一致 // UI 元数据(分类 + 图标)由 ProcessorUiMetadata 统一提供,保持工具箱与流水线图标一致
public OperatorToolboxViewModel(IImageProcessingService imageProcessingService) public OperatorToolboxViewModel(IImageProcessingService imageProcessingService, IEventAggregator eventAggregator)
{ {
_imageProcessingService = imageProcessingService ?? throw new ArgumentNullException(nameof(imageProcessingService)); _imageProcessingService = imageProcessingService ?? throw new ArgumentNullException(nameof(imageProcessingService));
_eventAggregator = eventAggregator ?? throw new ArgumentNullException(nameof(eventAggregator));
AvailableOperators = new ObservableCollection<OperatorDescriptor>(); AvailableOperators = new ObservableCollection<OperatorDescriptor>();
FilteredOperators = new ObservableCollection<OperatorDescriptor>(); FilteredOperators = new ObservableCollection<OperatorDescriptor>();
FilteredGroups = new ObservableCollection<OperatorGroupViewModel>(); FilteredGroups = new ObservableCollection<OperatorGroupViewModel>();
AddOperatorCommand = new DelegateCommand<string>(AddOperator);
LoadOperators(); LoadOperators();
} }
@@ -53,6 +59,8 @@ namespace XplorePlane.ViewModels
public ObservableCollection<OperatorDescriptor> FilteredOperators { get; } public ObservableCollection<OperatorDescriptor> FilteredOperators { get; }
public ObservableCollection<OperatorGroupViewModel> FilteredGroups { get; } public ObservableCollection<OperatorGroupViewModel> FilteredGroups { get; }
public DelegateCommand<string> AddOperatorCommand { get; }
public OperatorGroupViewModel SelectedGroup public OperatorGroupViewModel SelectedGroup
{ {
get => _selectedGroup; get => _selectedGroup;
@@ -124,5 +132,11 @@ namespace XplorePlane.ViewModels
"检测分析" => 6, "检测分析" => 6,
_ => 99 _ => 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>() _eventAggregator.GetEvent<ManualImageLoadedEvent>()
.Subscribe(OnManualImageLoaded); .Subscribe(OnManualImageLoaded);
_eventAggregator.GetEvent<AddOperatorRequestedEvent>()
.Subscribe(key => { if (CanAddOperator(key)) AddOperator(key); });
} }
// ── State Properties ────────────────────────────────────────── // ── State Properties ──────────────────────────────────────────
@@ -135,28 +135,77 @@
</Style.Triggers> </Style.Triggers>
</Style> </Style>
</Border.Style> </Border.Style>
<StackPanel Orientation="Horizontal"> <Grid>
<Border Width="28" <Grid.ColumnDefinitions>
Height="28" <ColumnDefinition Width="*" />
Background="#EEF2FF" <ColumnDefinition Width="Auto" />
CornerRadius="4" </Grid.ColumnDefinitions>
Margin="0,0,8,0"> <StackPanel Grid.Column="0" Orientation="Horizontal">
<TextBlock Text="{Binding IconPath}" <Border Width="28"
HorizontalAlignment="Center" Height="28"
VerticalAlignment="Center" Background="#EEF2FF"
FontSize="14" /> CornerRadius="4"
</Border> Margin="0,0,8,0">
<StackPanel VerticalAlignment="Center"> <TextBlock Text="{Binding IconPath}"
<TextBlock Text="{Binding DisplayName}" HorizontalAlignment="Center"
FontFamily="Microsoft YaHei UI" VerticalAlignment="Center"
FontSize="11.5" FontSize="14" />
Foreground="#1c1c1b" /> </Border>
<TextBlock Text="{Binding Key}" <StackPanel VerticalAlignment="Center">
FontFamily="Consolas" <TextBlock Text="{Binding DisplayName}"
FontSize="9.5" FontFamily="Microsoft YaHei UI"
Foreground="#999" /> FontSize="11.5"
Foreground="#1c1c1b" />
<TextBlock Text="{Binding Key}"
FontFamily="Consolas"
FontSize="9.5"
Foreground="#999" />
</StackPanel>
</StackPanel> </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> </Border>
</DataTemplate> </DataTemplate>
</ItemsControl.ItemTemplate> </ItemsControl.ItemTemplate>