diff --git a/XplorePlane/ViewModels/ImageProcessing/OperatorToolboxViewModel.cs b/XplorePlane/ViewModels/ImageProcessing/OperatorToolboxViewModel.cs index b8ba48f..f4e45d3 100644 --- a/XplorePlane/ViewModels/ImageProcessing/OperatorToolboxViewModel.cs +++ b/XplorePlane/ViewModels/ImageProcessing/OperatorToolboxViewModel.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; using Prism.Mvvm; @@ -12,31 +13,58 @@ namespace XplorePlane.ViewModels public string DisplayName { get; } public string IconPath { get; } public string Category { get; } + public string CategoryIcon { get; } - public OperatorDescriptor(string key, string displayName, string iconPath = "", string category = "通用") + public OperatorDescriptor(string key, string displayName, string iconPath = "", string category = "通用", string categoryIcon = "⚙") { Key = key; DisplayName = displayName; IconPath = iconPath; Category = category; + CategoryIcon = categoryIcon; } } + public class OperatorGroupViewModel + { + public string CategoryName { get; set; } + public string CategoryIcon { get; set; } + public ObservableCollection Operators { get; set; } = new(); + } + public class OperatorToolboxViewModel : BindableBase { private readonly IImageProcessingService _imageProcessingService; private string _searchText = string.Empty; + // 算子 Key -> (分类名, 分类图标, 算子图标) 映射 + private static readonly Dictionary CategoryMap = new() + { + ["GaussianBlur"] = ("滤波与平滑", "🔵", "🌀"), + ["GaussianBlur16"] = ("滤波与平滑", "🔵", "🌀"), + ["BandPassFilter"] = ("滤波与平滑", "🔵", "📶"), + ["ShockFilter"] = ("滤波与平滑", "🔵", "⚡"), + ["Contrast"] = ("增强与校正", "🟡", "🔆"), + ["Gamma"] = ("增强与校正", "🟡", "🌗"), + ["FlatFieldCorrection16"] = ("增强与校正", "🟡", "📐"), + ["Threshold"] = ("分割与阈值", "🟢", "📊"), + ["Division"] = ("分割与阈值", "🟢", "➗"), + ["Morphology"] = ("形态学与轮廓", "🔴", "🔲"), + ["Contour"] = ("形态学与轮廓", "🔴", "✏️"), + }; + public OperatorToolboxViewModel(IImageProcessingService imageProcessingService) { _imageProcessingService = imageProcessingService ?? throw new ArgumentNullException(nameof(imageProcessingService)); AvailableOperators = new ObservableCollection(); FilteredOperators = new ObservableCollection(); + FilteredGroups = new ObservableCollection(); LoadOperators(); } public ObservableCollection AvailableOperators { get; } public ObservableCollection FilteredOperators { get; } + public ObservableCollection FilteredGroups { get; } public string SearchText { @@ -54,7 +82,10 @@ namespace XplorePlane.ViewModels foreach (var key in _imageProcessingService.GetAvailableProcessors()) { var displayName = _imageProcessingService.GetProcessorDisplayName(key); - AvailableOperators.Add(new OperatorDescriptor(key, displayName ?? key)); + var (category, catIcon, opIcon) = CategoryMap.TryGetValue(key, out var info) + ? info + : ("其他", "⚙", "⚙"); + AvailableOperators.Add(new OperatorDescriptor(key, displayName ?? key, opIcon, category, catIcon)); } ApplyFilter(); } @@ -62,12 +93,39 @@ namespace XplorePlane.ViewModels private void ApplyFilter() { FilteredOperators.Clear(); + FilteredGroups.Clear(); + var filtered = string.IsNullOrWhiteSpace(SearchText) ? AvailableOperators : AvailableOperators.Where(o => - o.DisplayName.Contains(SearchText, StringComparison.OrdinalIgnoreCase)); + o.DisplayName.Contains(SearchText, StringComparison.OrdinalIgnoreCase) || + o.Category.Contains(SearchText, StringComparison.OrdinalIgnoreCase)); + foreach (var op in filtered) FilteredOperators.Add(op); + + var groups = filtered + .GroupBy(o => o.Category) + .OrderBy(g => GetCategoryOrder(g.Key)); + + foreach (var group in groups) + { + FilteredGroups.Add(new OperatorGroupViewModel + { + CategoryName = group.Key, + CategoryIcon = group.First().CategoryIcon, + Operators = new ObservableCollection(group) + }); + } } + + private static int GetCategoryOrder(string category) => category switch + { + "滤波与平滑" => 0, + "增强与校正" => 1, + "分割与阈值" => 2, + "形态学与轮廓" => 3, + _ => 99 + }; } } diff --git a/XplorePlane/Views/ImageProcessing/OperatorToolboxView.xaml b/XplorePlane/Views/ImageProcessing/OperatorToolboxView.xaml index 11bfd62..b1c27cf 100644 --- a/XplorePlane/Views/ImageProcessing/OperatorToolboxView.xaml +++ b/XplorePlane/Views/ImageProcessing/OperatorToolboxView.xaml @@ -7,11 +7,13 @@ xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation" prism:ViewModelLocator.AutoWireViewModel="True" mc:Ignorable="d" - d:DesignHeight="600" d:DesignWidth="200"> + d:DesignHeight="600" d:DesignWidth="280"> + + Microsoft YaHei UI @@ -26,18 +28,18 @@ - - + + - + Padding="6,4" BorderBrush="#cdcbcb" BorderThickness="1" + ToolTip="输入关键字搜索算子"> + + + + + + + + + + + + + + + + + + + diff --git a/XplorePlane/Views/Main/MainWindow.xaml b/XplorePlane/Views/Main/MainWindow.xaml index 05945e7..ba86a2d 100644 --- a/XplorePlane/Views/Main/MainWindow.xaml +++ b/XplorePlane/Views/Main/MainWindow.xaml @@ -10,10 +10,11 @@ xmlns:views="clr-namespace:XplorePlane.Views" x:Name="ParentWindow" Title="XplorePlane" - Width="1280" - Height="1000" - d:DesignWidth="1280" + Width="1920" + Height="1040" + d:DesignWidth="1580" Background="#F5F5F5" + Icon="pack://application:,,,/GapInspect.ico" WindowStartupLocation="CenterScreen" mc:Ignorable="d"> @@ -28,7 +29,6 @@ - @@ -39,11 +39,11 @@ @@ -51,7 +51,10 @@ - + - + Text="📂 加载CNC" /> + + + - - + @@ -95,8 +99,6 @@ - - - - + - - - - + + + Text="十字线" /> + + + + + + - - - - - - - - - - + - - - - - - + + - + + + + - + - + - + - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + @@ -402,7 +367,7 @@ Command="{Binding Path=ShowHyperlinkDialog.Command}" Content="螺旋扫描" IsEnabled="{Binding Path=ShowHyperlinkDialog.IsEnabled}" - LargeImage="/Assets/Icons/quick-scan.png" + LargeImage="/Assets/Icons/spiral.png" Size="Large" /> @@ -423,9 +388,26 @@ - - - + + + + + + + + + + + + + + - @@ -523,8 +504,6 @@ FontSize="11" Foreground="White" Text="x: 0 y: 0 RGB: 0 0 0" /> - - diff --git a/XplorePlane/XplorePlane.csproj b/XplorePlane/XplorePlane.csproj index feb6875..a13e43a 100644 --- a/XplorePlane/XplorePlane.csproj +++ b/XplorePlane/XplorePlane.csproj @@ -187,7 +187,7 @@ PreserveNewest Libs\ImageProcessing\zh-CN\%(Filename)%(Extension) - +