调整操作员主界面并新增运行设置页
This commit is contained in:
parent
cb33b67329
commit
3436d08d4a
@ -0,0 +1,70 @@
|
||||
<UserControl xmlns="https://github.com/avaloniaui" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" x:Class="SopHelper.VVMs.RuntimeSettings.RuntimeSettings" Background="{StaticResource Bg}">
|
||||
<ScrollViewer HorizontalScrollBarVisibility="Disabled">
|
||||
<StackPanel Margin="10" MaxWidth="760" HorizontalAlignment="Stretch" Spacing="12">
|
||||
<TextBlock Text="运行设置" Classes="Title" />
|
||||
<TextBlock Text="配置相机、配方和检测参数,运行期间不可修改。" Foreground="{StaticResource FgDim}" TextWrapping="Wrap" />
|
||||
<Border Classes="panel">
|
||||
<StackPanel>
|
||||
<TextBlock Text="相机与配方" Classes="Title" />
|
||||
<Grid Margin="0,10,0,0">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="*" />
|
||||
<ColumnDefinition Width="Auto" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBlock Text="相机" Width="40" />
|
||||
<ComboBox Grid.Column="1" Height="26" VerticalContentAlignment="Center" ItemsSource="{Binding Cameras}" IsEnabled="{Binding CanSelectCamera}" SelectedItem="{Binding SelectedCamera, Converter={StaticResource SelectionConverter}}" ToolTip.Tip="支持 UVC 和海康 GigE/USB 工业相机">
|
||||
<ComboBox.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<TextBlock Text="{Binding Name}" />
|
||||
</DataTemplate>
|
||||
</ComboBox.ItemTemplate>
|
||||
</ComboBox>
|
||||
<Button Grid.Column="2" Content="刷新" Margin="6,0,0,0" Padding="10,4" Command="{Binding RefreshCamerasCommand}" />
|
||||
</Grid>
|
||||
<Grid Margin="0,8,0,0">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="*" />
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="Auto" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBlock Text="配方" Width="40" />
|
||||
<ComboBox Grid.Column="1" Height="26" VerticalContentAlignment="Center" IsEnabled="{Binding CanSelectCamera}" ItemsSource="{Binding Recipes}" SelectedItem="{Binding SelectedRecipe, Converter={StaticResource SelectionConverter}}" />
|
||||
<Button Grid.Column="2" Content="编辑" Margin="6,0,0,0" Padding="10,4" Command="{Binding EditRecipeCommand}" />
|
||||
<Button Grid.Column="3" Content="新建" Margin="6,0,0,0" Padding="10,4" Command="{Binding NewRecipeCommand}" />
|
||||
<Button Grid.Column="4" Content="应用" Margin="6,0,0,0" Padding="10,4" Command="{Binding ApplyRecipeCommand}" />
|
||||
</Grid>
|
||||
<Grid Margin="0,8,0,0">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="*" />
|
||||
<ColumnDefinition Width="44" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBlock Text="阈值" Width="40" />
|
||||
<Slider IsEnabled="{Binding CanSelectCamera}" Grid.Column="1" Minimum="0.1" Maximum="0.95" TickFrequency="0.05" IsSnapToTickEnabled="True" Value="{Binding Confidence}" VerticalAlignment="Center" />
|
||||
<TextBlock Grid.Column="2" Text="{Binding Confidence, StringFormat={}{0:F2}}" HorizontalAlignment="Right" Foreground="{StaticResource FgDim}" />
|
||||
</Grid>
|
||||
<Grid Margin="0,8,0,0">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="*" />
|
||||
<ColumnDefinition Width="44" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBlock Text="抽帧" Width="40" />
|
||||
<Slider IsEnabled="{Binding CanSelectCamera}" Grid.Column="1" Minimum="1" Maximum="10" TickFrequency="1" IsSnapToTickEnabled="True" Value="{Binding FrameStride}" VerticalAlignment="Center" />
|
||||
<TextBlock Grid.Column="2" Text="{Binding FrameStride}" HorizontalAlignment="Right" Foreground="{StaticResource FgDim}" />
|
||||
</Grid>
|
||||
</StackPanel>
|
||||
</Border>
|
||||
<Border Classes="panel">
|
||||
<StackPanel Spacing="8">
|
||||
<TextBlock Text="当前已应用配方" Classes="Title" />
|
||||
<TextBlock Text="{Binding ActiveRecipe}" TextWrapping="Wrap" />
|
||||
<TextBlock Text="选择配方后点击“应用”;阈值和抽帧参数在下次开始运行时生效。" Foreground="{StaticResource FgDim}" TextWrapping="Wrap" />
|
||||
</StackPanel>
|
||||
</Border>
|
||||
</StackPanel>
|
||||
</ScrollViewer>
|
||||
</UserControl>
|
||||
@ -0,0 +1,15 @@
|
||||
using Avalonia.Controls;
|
||||
using SopHelper.Core.Prism;
|
||||
using SopHelper.VVMs.SopPage;
|
||||
|
||||
namespace SopHelper.VVMs.RuntimeSettings;
|
||||
|
||||
[NavigationPage(ViewName = nameof(RuntimeSettings), DisplayName = "运行设置", Index = 2)]
|
||||
public partial class RuntimeSettings : UserControl
|
||||
{
|
||||
public RuntimeSettings(SopPageViewModel model)
|
||||
{
|
||||
InitializeComponent();
|
||||
DataContext = model;
|
||||
}
|
||||
}
|
||||
@ -58,57 +58,8 @@
|
||||
</Grid.RowDefinitions>
|
||||
<Border Grid.Row="0" Classes="panel">
|
||||
<StackPanel>
|
||||
<TextBlock Text="参数" Classes="Title" />
|
||||
<Grid Margin="0,10,0,0">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="*" />
|
||||
<ColumnDefinition Width="Auto" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBlock Text="相机" Width="40" />
|
||||
<ComboBox Grid.Column="1" Height="26" VerticalContentAlignment="Center" ItemsSource="{Binding Cameras}" IsEnabled="{Binding CanSelectCamera}" SelectedItem="{Binding SelectedCamera, Converter={StaticResource SelectionConverter}}" ToolTip.Tip="支持 UVC 和海康 GigE/USB 工业相机">
|
||||
<ComboBox.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<TextBlock Text="{Binding Name}" />
|
||||
</DataTemplate>
|
||||
</ComboBox.ItemTemplate>
|
||||
</ComboBox>
|
||||
<Button Grid.Column="2" Content="刷新" Margin="6,0,0,0" Padding="10,4" Command="{Binding RefreshCamerasCommand}" />
|
||||
</Grid>
|
||||
<Grid Margin="0,8,0,0">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="*" />
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="Auto" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBlock Text="配方" Width="40" />
|
||||
<ComboBox Grid.Column="1" Height="26" VerticalContentAlignment="Center" ItemsSource="{Binding Recipes}" SelectedItem="{Binding SelectedRecipe, Converter={StaticResource SelectionConverter}}" />
|
||||
<Button Grid.Column="2" Content="编辑" Margin="6,0,0,0" Padding="10,4" Command="{Binding EditRecipeCommand}" />
|
||||
<Button Grid.Column="3" Content="新建" Margin="6,0,0,0" Padding="10,4" Command="{Binding NewRecipeCommand}" />
|
||||
<Button Grid.Column="4" Content="应用" Margin="6,0,0,0" Padding="10,4" Command="{Binding ApplyRecipeCommand}" />
|
||||
</Grid>
|
||||
<Grid Margin="0,8,0,0">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="*" />
|
||||
<ColumnDefinition Width="44" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBlock Text="阈值" Width="40" />
|
||||
<Slider Grid.Column="1" Minimum="0.1" Maximum="0.95" TickFrequency="0.05" IsSnapToTickEnabled="True" Value="{Binding Confidence}" VerticalAlignment="Center" />
|
||||
<TextBlock Grid.Column="2" Text="{Binding Confidence, StringFormat={}{0:F2}}" HorizontalAlignment="Right" Foreground="{StaticResource FgDim}" />
|
||||
</Grid>
|
||||
<Grid Margin="0,8,0,0">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="*" />
|
||||
<ColumnDefinition Width="44" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBlock Text="抽帧" Width="40" />
|
||||
<Slider Grid.Column="1" Minimum="1" Maximum="10" TickFrequency="1" IsSnapToTickEnabled="True" Value="{Binding FrameStride}" VerticalAlignment="Center" />
|
||||
<TextBlock Grid.Column="2" Text="{Binding FrameStride}" HorizontalAlignment="Right" Foreground="{StaticResource FgDim}" />
|
||||
</Grid>
|
||||
<TextBlock Text="当前配方" Classes="Title" />
|
||||
<TextBlock Text="{Binding ActiveRecipe}" Margin="0,10,0,0" FontSize="18" FontWeight="SemiBold" TextWrapping="Wrap" />
|
||||
<WrapPanel Margin="0,10,0,0">
|
||||
<TextBlock Text="状态" Width="40" />
|
||||
<TextBlock Text="{Binding StatusText}" Foreground="{StaticResource Accent}" />
|
||||
|
||||
@ -59,6 +59,7 @@ public class SopPageViewModel : ViewModelBase
|
||||
private CameraInfo? _selectedCamera;
|
||||
private CameraInfo? _lastUsedCamera;
|
||||
private string? _selectedRecipe;
|
||||
private string _activeRecipe = "未应用配方";
|
||||
private ImageSource? _frame;
|
||||
private string _statusText = "就绪";
|
||||
private string _fpsText = "—";
|
||||
@ -115,7 +116,7 @@ public class SopPageViewModel : ViewModelBase
|
||||
EditRecipeCommand = new DelegateCommand(EditRecipe, CanEditRecipe);
|
||||
NewRecipeCommand = new DelegateCommand(NewRecipe, () => !IsRunning && !_isCameraBusy);
|
||||
|
||||
StatusText = "选择相机和配方,点开始";
|
||||
StatusText = "就绪,请确认运行设置后开始";
|
||||
LoadLastCamera();
|
||||
_ = RefreshCamerasAsync();
|
||||
}
|
||||
@ -160,6 +161,13 @@ public class SopPageViewModel : ViewModelBase
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>已成功应用的配方,与设置页尚未应用的选择分开。</summary>
|
||||
public string ActiveRecipe
|
||||
{
|
||||
get => _activeRecipe;
|
||||
private set => SetProperty(ref _activeRecipe, value);
|
||||
}
|
||||
|
||||
/// <summary>画面</summary>
|
||||
public ImageSource? Frame
|
||||
{
|
||||
@ -619,6 +627,7 @@ public class SopPageViewModel : ViewModelBase
|
||||
};
|
||||
|
||||
_pipeline.LoadModels(options);
|
||||
ActiveRecipe = SelectedRecipe;
|
||||
Log("info", $"推理设备:手部={_pipeline.HandBackend},YOLO={_pipeline.YoloBackend}");
|
||||
|
||||
StepCards.Clear();
|
||||
|
||||
@ -57,16 +57,34 @@ internal static class Smoke
|
||||
await Task.Delay(150);
|
||||
var app=(App)Application.Current!;var window=lifetime.MainWindow!;
|
||||
var navigation=app.Container.Resolve<NavigationModel>();
|
||||
Check(navigation.Pages.Count==2,"Both original navigation pages registered");
|
||||
Check(navigation.Pages.Count==3&&navigation.Pages[2].DisplayName=="运行设置","Runtime settings navigation page registered");
|
||||
Check(navigation.Pages[0].DisplayName=="SOP 辅助"&&navigation.Pages[1].DisplayName=="零件标注与训练","Original navigation labels retained");
|
||||
window.WindowState=WindowState.Normal;window.Width=1180;window.Height=820;
|
||||
await Task.Delay(150);
|
||||
var sop=app.Container.Resolve<SopPageViewModel>();
|
||||
var sopView=window.GetVisualDescendants().OfType<SopPage>().Single();
|
||||
Check(!sopView.GetVisualDescendants().Any(c=>c is ComboBox or Slider),"Operator page contains no camera, recipe or parameter editors");
|
||||
Check(sop.ActiveRecipe=="未应用配方","No recipe is reported active before applying");
|
||||
navigation.SelectedIndex=2;await Task.Delay(100);
|
||||
var settings=window.GetVisualDescendants().OfType<SopHelper.VVMs.RuntimeSettings.RuntimeSettings>().Single();
|
||||
Check(ReferenceEquals(settings.DataContext,sop),"Settings and operator page share runtime state");
|
||||
Check(settings.GetVisualDescendants().OfType<ComboBox>().Count()==2&&settings.GetVisualDescendants().OfType<Slider>().Count()==2,"Camera, recipe, threshold and stride editors are on settings page");
|
||||
sop.ApplyRecipeCommand.Execute();
|
||||
Check(sop.ActiveRecipe==sop.SelectedRecipe,"Applied recipe is shown as current");
|
||||
var applied=sop.ActiveRecipe;var selected=sop.SelectedRecipe;
|
||||
sop.SelectedRecipe="pending.yaml";
|
||||
Check(sop.ActiveRecipe==applied,"Unapplied recipe selection does not change current recipe");
|
||||
sop.SelectedRecipe=selected;
|
||||
Save(window,"runtime-settings");
|
||||
navigation.SelectedIndex=0;await Task.Delay(100);
|
||||
Check(window.GetVisualDescendants().OfType<SopPage>().Single().GetVisualDescendants().OfType<TextBlock>().Any(t=>t.Text==applied),"Operator page displays the applied recipe");
|
||||
Check(sop.StepCards.Count==4&&sop.Rois.Count==3,"Original SOP recipe creates four steps and three ROIs");
|
||||
sop.StartStopCommand.Execute();
|
||||
for(var i=0;i<100&&!sop.IsRunning;i++)await Task.Delay(20);
|
||||
Check(sop.IsRunning,"Original start command connects the shared camera/pipeline");
|
||||
navigation.SelectedIndex=2;await Task.Delay(80);
|
||||
Check(settings.GetVisualDescendants().Where(c=>c is ComboBox or Slider).Cast<Control>().All(c=>!c.IsEnabled),"Runtime settings cannot be edited during acquisition");
|
||||
navigation.SelectedIndex=0;await Task.Delay(80);
|
||||
await Task.Run(()=>{Camera.Emit();Camera.Emit();});
|
||||
await Task.Delay(150);
|
||||
Check(sop.Frame is not null&&sop.FrameWidth==640&&sop.FrameHeight==480,"Camera buffer renders through the shared Avalonia bitmap adapter");
|
||||
@ -74,6 +92,9 @@ internal static class Smoke
|
||||
Save(window,"sop");
|
||||
sop.StartStopCommand.Execute();for(var i=0;i<100&&sop.IsRunning;i++)await Task.Delay(20);
|
||||
Check(!sop.IsRunning&&!Camera.IsConnected,"Stop command releases acquisition");
|
||||
navigation.SelectedIndex=2;await Task.Delay(80);
|
||||
Check(settings.GetVisualDescendants().Where(c=>c is ComboBox or Slider).Cast<Control>().All(c=>c.IsEnabled),"Runtime settings become editable after stopping");
|
||||
navigation.SelectedIndex=0;await Task.Delay(80);
|
||||
Check(window.GetVisualDescendants().OfType<SopPage>().Any(),"SOP page navigates");
|
||||
sop.EditRecipeCommand.Execute();await Task.Delay(150);
|
||||
var modal=lifetime.Windows.OfType<RecipeDialogWindow>().Single();
|
||||
|
||||
Loading…
Reference in New Issue
Block a user