From c84a12beb05378eb438401275ff2e892ec6e6589 Mon Sep 17 00:00:00 2001
From: tfarcraw <123211521@163.com>
Date: Fri, 20 Nov 2026 10:03:34 +0800
Subject: [PATCH] =?UTF-8?q?=E7=B2=BE=E7=AE=80=E4=B8=BB=E7=95=8C=E9=9D=A2?=
=?UTF-8?q?=E8=BF=90=E8=A1=8C=E6=8E=A7=E4=BB=B6=E5=B9=B6=E5=A2=9E=E5=8A=A0?=
=?UTF-8?q?=E6=A0=87=E5=87=86SOP=E8=A7=86=E9=A2=91=E6=92=AD=E6=94=BE?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
README.md | 4 +-
.../VVMs/SopPage/SopPage.axaml | 13 ++--
.../VVMs/SopPage/SopPageViewModel.cs | 38 +++++++---
.../VVMs/SopPage/StandardSopWindow.axaml | 18 +++++
.../VVMs/SopPage/StandardSopWindow.axaml.cs | 63 ++++++++++++++++
tests/Avalonia.Smoke/Program.cs | 75 ++++++++++++++++++-
6 files changed, 189 insertions(+), 22 deletions(-)
create mode 100644 src/SopHelper.Avalonia/VVMs/SopPage/StandardSopWindow.axaml
create mode 100644 src/SopHelper.Avalonia/VVMs/SopPage/StandardSopWindow.axaml.cs
diff --git a/README.md b/README.md
index 3d57afb..c2b99dc 100644
--- a/README.md
+++ b/README.md
@@ -32,7 +32,7 @@ pwsh -File tools/Start-HandAiD3.ps1
Windows DirectShow 设置分辨率时可能把 MJPG 重置为 YUY2,因此程序在分辨率和帧率设置后再应用视频格式;Linux V4L2 保持先设置格式。2026-11-18 在 USB Camera(0c45:636d)上验证:原顺序在 640×480 和 800×600 下均约 15fps,修复后通过实际 UvcCameraService 采集均约 30fps,格式回读为 MJPG,手动曝光回读 15.625ms。设置接口返回成功和驱动回读 30fps 均不能代替实际采集计数。
-SOP 流程视频可在配方编辑器中录制和播放,独立保存在该配方的 `sop_stand` 目录。配方选择和相机选择会记忆;恢复选择不会自动开始采集。
+SOP 流程视频可在配方编辑器中录制和播放,独立保存在该配方的 `sop_stand` 目录。主界面的“播放标准 SOP”可独立打开当前已应用配方的视频,支持播放和拖动进度,不影响相机采集。配方选择和相机选择会记忆;恢复选择不会自动开始采集。
“Agent助手”接收本地标准视频路径,通过工具自主查看不同时间点、继续检查细节,再生成步骤草稿。模型需支持 Chat Completions 工具调用和图片输入,不需要上传完整视频。每次工具读取上限默认 3 张,可修改并记住。草稿包含时间段、参考画面、步骤说明和手部规则,修改后追加到配方,最后手动保存。接口地址、模型名、密钥及生成参数自动保存,下次启动恢复;模型列表可自动获取。运行时仍由 djev 确认步骤完成。详细限制与配置见 [HAND_AI.md](HAND_AI.md)。
@@ -57,7 +57,7 @@ pwsh -File tools/Publish-Avalonia.ps1
`--import-recipes 原数据根目录` 可以导入已有配方,`--check-standalone` / `--check-runtime` 检查本地手部模型和使用模拟 AI 的步骤门控,`--check-gpu` 额外要求手部推理使用 GPU;这些本地诊断不代表真实 D3 接口联调成功。
-主界面每个步骤显示正常次数和异常次数:正常完成计入正常,异常跳过计入异常;按配方保存在 `workspace/step-counts.json`,复位、停止、重新应用配方或重启软件均保留;仅点击“重置步骤”后的“重置计数”按钮,才会清零当前已应用配方的计数,不影响步骤进度及其他配方。
+主界面每个步骤显示正常次数和异常次数:正常完成计入正常,异常跳过计入异常;按配方保存在 `workspace/step-counts.json`,复位、停止、重新应用配方或重启软件均保留;仅点击“重置计数”按钮,才会清零当前已应用配方的计数,不影响步骤进度及其他配方。
## 验证
diff --git a/src/SopHelper.Avalonia/VVMs/SopPage/SopPage.axaml b/src/SopHelper.Avalonia/VVMs/SopPage/SopPage.axaml
index 627bfc2..f8f7e7d 100644
--- a/src/SopHelper.Avalonia/VVMs/SopPage/SopPage.axaml
+++ b/src/SopHelper.Avalonia/VVMs/SopPage/SopPage.axaml
@@ -80,21 +80,18 @@
-
-
+
+
-
-
-
-
+
+
-
-
+
diff --git a/src/SopHelper.Avalonia/VVMs/SopPage/SopPageViewModel.cs b/src/SopHelper.Avalonia/VVMs/SopPage/SopPageViewModel.cs
index b486403..5273714 100644
--- a/src/SopHelper.Avalonia/VVMs/SopPage/SopPageViewModel.cs
+++ b/src/SopHelper.Avalonia/VVMs/SopPage/SopPageViewModel.cs
@@ -137,9 +137,8 @@ public class SopPageViewModel : ViewModelBase
ConfigureCameraCommand = new DelegateCommand(async () => await ConfigureCameraAsync(), () => CanSelectCamera && SelectedCamera is not null);
RefreshCamerasCommand = new DelegateCommand(async () => await RefreshCamerasAsync(), () => CanSelectCamera);
StartStopCommand = new DelegateCommand(async () => await StartStopAsync(), CanStart);
- TogglePauseCommand = new DelegateCommand(_engine.TogglePause, () => IsRunning);
- ResetCommand = new DelegateCommand(_engine.Reset, () => IsRunning);
ResetCountsCommand = new DelegateCommand(ResetCounts, () => StepCards.Count > 0);
+ PlayStandardSopCommand = new DelegateCommand(PlayStandardSop, () => StandardSopVideoPath is { } path && File.Exists(path));
ApplyRecipeCommand = new DelegateCommand(ApplyRecipe, () => CanSelectCamera && !string.IsNullOrWhiteSpace(SelectedRecipe));
SnapshotCommand = new DelegateCommand(Snapshot, () => _lastFrame is not null);
EditRecipeCommand = new DelegateCommand(EditRecipe, CanEditRecipe);
@@ -345,12 +344,8 @@ public class SopPageViewModel : ViewModelBase
/// 开始 / 停止
public DelegateCommand StartStopCommand { get; private set; } = null!;
- /// 暂停 / 继续
- public DelegateCommand TogglePauseCommand { get; private set; } = null!;
-
- /// 复位
- public DelegateCommand ResetCommand { get; private set; } = null!;
public DelegateCommand ResetCountsCommand { get; private set; } = null!;
+ public DelegateCommand PlayStandardSopCommand { get; private set; } = null!;
public DelegateCommand DeleteRecipeCommand { get; private set; } = null!;
/// 应用配方
@@ -403,9 +398,8 @@ public class SopPageViewModel : ViewModelBase
ConfigureCameraCommand?.RaiseCanExecuteChanged();
RefreshCamerasCommand?.RaiseCanExecuteChanged();
StartStopCommand?.RaiseCanExecuteChanged();
- TogglePauseCommand?.RaiseCanExecuteChanged();
- ResetCommand?.RaiseCanExecuteChanged();
ResetCountsCommand?.RaiseCanExecuteChanged();
+ PlayStandardSopCommand?.RaiseCanExecuteChanged();
ApplyRecipeCommand?.RaiseCanExecuteChanged();
SnapshotCommand?.RaiseCanExecuteChanged();
EditRecipeCommand?.RaiseCanExecuteChanged();
@@ -462,6 +456,7 @@ public class SopPageViewModel : ViewModelBase
public override void Destroy()
{
_statisticsTimer.Stop();
+ _standardSopWindow?.Close();
_engine.Stop();
_engine.RoundFinished -= OnRoundFinished;
_camera.FrameArrived -= OnCameraFrame;
@@ -597,6 +592,7 @@ public class SopPageViewModel : ViewModelBase
ClearProcessImages();
StepCards.Clear(); Rois.Clear(); HandResult = null; _lastFrame = null;
ResetCountsCommand?.RaiseCanExecuteChanged();
+ PlayStandardSopCommand?.RaiseCanExecuteChanged();
ActiveRecipe = "未应用配方";
RaisePropertyChanged(nameof(InferenceBackendText));
RaiseCommands();
@@ -858,6 +854,7 @@ public class SopPageViewModel : ViewModelBase
}
ResetCountsCommand.RaiseCanExecuteChanged();
+ PlayStandardSopCommand.RaiseCanExecuteChanged();
foreach (var (name, def) in config.Sop.Regions)
Rois.Add(new RoiItem { Name = name, X = def.X1, Y = def.Y1, W = def.X2 - def.X1, H = def.Y2 - def.Y1, ColorHex = def.Color });
@@ -1006,6 +1003,29 @@ public class SopPageViewModel : ViewModelBase
}
}
+ private StandardSopWindow? _standardSopWindow;
+ private string? StandardSopVideoPath => string.IsNullOrWhiteSpace(ActiveRecipe) || ActiveRecipe == "未应用配方" ? null
+ : Path.Combine(DesktopPlatform.Recipes.DirectoryFor(Path.GetFileNameWithoutExtension(ActiveRecipe)), "sop_stand", "sop.avi");
+
+ private void PlayStandardSop()
+ {
+ if (StandardSopVideoPath is not { } path || !File.Exists(path))
+ {
+ Log("warn", "当前配方没有标准 SOP 视频,请先录制或导入视频");
+ PlayStandardSopCommand.RaiseCanExecuteChanged();
+ return;
+ }
+ if (_standardSopWindow is { IsVisible: true } existing && existing.VideoPath == path)
+ {
+ existing.Activate();
+ return;
+ }
+ _standardSopWindow?.Close();
+ var window = _standardSopWindow = new StandardSopWindow(path, Path.GetFileNameWithoutExtension(ActiveRecipe));
+ window.Closed += (_, _) => { if (ReferenceEquals(_standardSopWindow, window)) _standardSopWindow = null; };
+ window.Show(DesktopPlatform.Owner);
+ }
+
private void ResetCounts()
{
if (StepCards.Count == 0) return;
diff --git a/src/SopHelper.Avalonia/VVMs/SopPage/StandardSopWindow.axaml b/src/SopHelper.Avalonia/VVMs/SopPage/StandardSopWindow.axaml
new file mode 100644
index 0000000..74262bd
--- /dev/null
+++ b/src/SopHelper.Avalonia/VVMs/SopPage/StandardSopWindow.axaml
@@ -0,0 +1,18 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/SopHelper.Avalonia/VVMs/SopPage/StandardSopWindow.axaml.cs b/src/SopHelper.Avalonia/VVMs/SopPage/StandardSopWindow.axaml.cs
new file mode 100644
index 0000000..2f4e510
--- /dev/null
+++ b/src/SopHelper.Avalonia/VVMs/SopPage/StandardSopWindow.axaml.cs
@@ -0,0 +1,63 @@
+using Avalonia.Controls;
+using Avalonia.Interactivity;
+using SopHelper.Training;
+
+namespace SopHelper.VVMs.SopPage;
+
+public partial class StandardSopWindow : Window
+{
+ public string VideoPath { get; }
+ public RecordedVideoPlayback Playback { get; } = new();
+ private Task _playOperation = Task.CompletedTask;
+ private bool _closeRequested, _closedSafely;
+
+ public StandardSopWindow(string videoPath, string recipeName)
+ {
+ InitializeComponent();
+ VideoPath = videoPath;
+ Title = "标准 SOP · " + recipeName;
+ RecipeTitle.Text = recipeName + " · 标准 SOP";
+ DataContext = Playback;
+ Playback.Failed += message => PlaybackErrorText.Text = message;
+ Playback.PropertyChanged += (_, e) =>
+ {
+ if (e.PropertyName is nameof(Playback.IsPlaying) or nameof(Playback.IsAtEnd))
+ PlaybackToggleButton.Content = Playback.IsPlaying ? "暂停播放" : Playback.IsAtEnd ? "重新播放" : "播放";
+ };
+ Opened += (_, _) => _playOperation = PlayAsync();
+ Closing += OnSafeClosing;
+ }
+
+ private async Task PlayAsync()
+ {
+ PlaybackToggleButton.IsEnabled = false;
+ PlaybackErrorText.Text = "";
+ try { await Playback.PlayAsync(VideoPath); }
+ catch (Exception error)
+ {
+ await Playback.StopAsync();
+ PlaybackErrorText.Text = "标准 SOP 视频无法播放:" + error.Message;
+ }
+ finally { if (!_closeRequested) PlaybackToggleButton.IsEnabled = true; }
+ }
+
+ private void TogglePlayback(object? sender, RoutedEventArgs e)
+ {
+ if (_closeRequested) return;
+ if (Playback.IsPlaying) Playback.Pause();
+ else _playOperation = PlayAsync();
+ }
+
+ private void ClosePlayback(object? sender, RoutedEventArgs e) => Close();
+
+ private async void OnSafeClosing(object? sender, WindowClosingEventArgs e)
+ {
+ if (_closedSafely) return;
+ e.Cancel = true;
+ if (_closeRequested) return;
+ _closeRequested = true;
+ PlaybackToggleButton.IsEnabled = false;
+ try { await _playOperation; await Playback.StopAsync(); }
+ finally { _closedSafely = true; Close(); }
+ }
+}
diff --git a/tests/Avalonia.Smoke/Program.cs b/tests/Avalonia.Smoke/Program.cs
index e835fda..f6e80ae 100644
--- a/tests/Avalonia.Smoke/Program.cs
+++ b/tests/Avalonia.Smoke/Program.cs
@@ -87,6 +87,8 @@ internal static class Smoke
var userCameraBefore=File.Exists(userCameraPath)?File.ReadAllBytes(userCameraPath):null;
await Task.Delay(150);
var app=(App)Application.Current!;var window=lifetime.MainWindow!;
+ if(Environment.GetCommandLineArgs().Contains("--standard-sop-only"))
+ { await CheckStandardSopPlayback(app,window,lifetime);_exit=0;return; }
if(Environment.GetCommandLineArgs().Contains("--step-counts-only"))
{ await CheckStepCounts(app,window);_exit=0;return; }
if(Environment.GetCommandLineArgs().Contains("--startup-recipe-only"))
@@ -662,6 +664,73 @@ internal static class Smoke
}
finally{sop.IsRunning=false;sop.ApplyRecipeCommand.Execute();}
}
+ private static async Task CheckStandardSopPlayback(App app,Window window,IClassicDesktopStyleApplicationLifetime lifetime)
+ {
+ var model=app.Container.Resolve();
+ var engine=app.Container.Resolve();
+ var view=window.GetVisualDescendants().OfType().Single();
+ var texts=view.GetVisualDescendants().OfType().Select(t=>t.Text).ToArray();
+ Check(!texts.Contains("步骤计时")&&texts.Contains("流程计时")&&texts.Contains("标准用时"),"Header retains flow and standard times without step timing");
+ var buttons=view.GetVisualDescendants().OfType