From 207f7b4334782d064e08d64ea9e37a58aa668bec Mon Sep 17 00:00:00 2001 From: Codex Date: Wed, 25 Nov 2026 10:14:39 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B6=E6=95=9B=E6=97=A7=E9=85=8D=E6=96=B9?= =?UTF-8?q?=E5=85=BC=E5=AE=B9=E4=B8=8E=E5=8E=86=E5=8F=B2=E8=B5=84=E6=96=99?= =?UTF-8?q?=E8=BF=81=E7=A7=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- .../Presentation/DesktopPlatform.cs | 6 +- src/SopHelper.Avalonia/Program.cs | 14 +- .../SopVideo/CameraVideoImport.cs | 2 +- .../SopVideo/CameraViewModel.cs | 2 +- .../SopVideo/SopVideoFlowTest.cs | 1 - .../VVMs/RecipeEditor/EditorNodes.cs | 113 +----- .../VVMs/RecipeEditor/RecipeEditor.axaml | 10 - .../RecipeEditor/RecipeEditorViewModel.cs | 4 +- .../RecipeEditor/StepTransferViewModel.cs | 4 +- .../RuntimeSettings/DeleteRecipeDialog.cs | 2 +- .../VVMs/SopPage/SopPageViewModel.cs | 9 +- .../{Training => Recipes}/RecipePackage.cs | 2 +- .../Recipes/RecipeWorkspace.cs | 206 +++++++++++ .../SopStandardVideoDuration.cs | 2 +- .../Sop/SopConfig.cs | 20 +- .../Sop/SopConfigLoader.cs | 7 +- .../Training/PartCatalog.cs | 76 ---- .../Training/RecipeModelResolver.cs | 44 --- .../Training/RecipeWorkspace.cs | 338 ------------------ tests/Avalonia.Smoke/Program.cs | 7 +- tests/RecipePackage.Smoke/Program.cs | 50 ++- tests/RecordingLimit.Smoke/Program.cs | 2 +- tests/RegionVideoCapture.Smoke/Program.cs | 2 +- .../AgentDraftGenerationChecks.cs | 2 +- tests/VideoFlowTest.Smoke/Program.cs | 29 +- .../VideoFlowTest.Smoke/RecipeCloseChecks.cs | 2 +- .../StandardVideoImportChecks.cs | 2 +- tests/VisionDecision.Smoke/Program.cs | 6 +- 29 files changed, 331 insertions(+), 635 deletions(-) rename src/SopHelper.CrossPlatform.Engine/{Training => Recipes}/RecipePackage.cs (99%) create mode 100644 src/SopHelper.CrossPlatform.Engine/Recipes/RecipeWorkspace.cs rename src/SopHelper.CrossPlatform.Engine/{Training => Recipes}/SopStandardVideoDuration.cs (98%) delete mode 100644 src/SopHelper.CrossPlatform.Engine/Training/PartCatalog.cs delete mode 100644 src/SopHelper.CrossPlatform.Engine/Training/RecipeModelResolver.cs delete mode 100644 src/SopHelper.CrossPlatform.Engine/Training/RecipeWorkspace.cs diff --git a/README.md b/README.md index 75027e9..781c1b1 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ Windows / Linux 共用一套 Avalonia 桌面程序:相机采集、双手关键点检测、区域触发和 djev 步骤确认。本分支已移除 YOLO 推理及模型、零件标注和训练设置界面。 -当前代码和构建不依赖原 WPF 归档。旧标注、训练记录和模型文件不自动删除,但不会被当前运行管线加载。 +当前代码和构建不依赖原 WPF 归档。旧标注、训练记录和模型文件保留在原目录。整目录导入配方时原样复制这些文件;从旧散放配置初始化时迁移标准视频。 ## 运行 diff --git a/src/SopHelper.Avalonia/Presentation/DesktopPlatform.cs b/src/SopHelper.Avalonia/Presentation/DesktopPlatform.cs index efe2852..9c78b16 100644 --- a/src/SopHelper.Avalonia/Presentation/DesktopPlatform.cs +++ b/src/SopHelper.Avalonia/Presentation/DesktopPlatform.cs @@ -9,16 +9,16 @@ namespace SopHelper.Presentation; internal static class DesktopPlatform { - private static readonly Lazy RecipeStorage = new(() => + private static readonly Lazy RecipeStorage = new(() => { - var storage = new SopHelper.Engine.Training.RecipeWorkspace(WorkspaceRoot); + var storage = new SopHelper.Engine.Recipes.RecipeWorkspace(WorkspaceRoot); if (string.IsNullOrWhiteSpace(Environment.GetEnvironmentVariable("SOPHELPER_WORKSPACE_ROOT")) && LegacySourceRoot is { } legacyRoot) storage.ImportFrom(legacyRoot); storage.Initialize(Path.Combine(AppContext.BaseDirectory, "configs", "sop")); return storage; }); - public static SopHelper.Engine.Training.RecipeWorkspace Recipes => RecipeStorage.Value; + public static SopHelper.Engine.Recipes.RecipeWorkspace Recipes => RecipeStorage.Value; public static string WorkspaceRoot { get diff --git a/src/SopHelper.Avalonia/Program.cs b/src/SopHelper.Avalonia/Program.cs index 7f78048..b696f9b 100644 --- a/src/SopHelper.Avalonia/Program.cs +++ b/src/SopHelper.Avalonia/Program.cs @@ -15,7 +15,7 @@ internal static class Program try { if(importIndex+1>=args.Length)throw new ArgumentException("--import-recipes 后需提供原数据根目录"); - var storage=new SopHelper.Engine.Training.RecipeWorkspace(Presentation.DesktopPlatform.WorkspaceRoot); + var storage=new SopHelper.Engine.Recipes.RecipeWorkspace(Presentation.DesktopPlatform.WorkspaceRoot); storage.ImportFrom(args[importIndex+1]); storage.Initialize(Path.Combine(AppContext.BaseDirectory,"configs","sop")); Console.WriteLine($"配方导入完成:{storage.RecipesDirectory}");return 0; @@ -39,8 +39,8 @@ internal static class Program try { if (exportIndex + 2 >= args.Length) throw new ArgumentException("--export-recipe-package 后需提供配方名和输出文件"); - var storage = new SopHelper.Engine.Training.RecipeWorkspace(Presentation.DesktopPlatform.WorkspaceRoot); - var result = SopHelper.Engine.Training.RecipePackage.Export(storage, args[exportIndex + 1], args[exportIndex + 2]); + var storage = new SopHelper.Engine.Recipes.RecipeWorkspace(Presentation.DesktopPlatform.WorkspaceRoot); + var result = SopHelper.Engine.Recipes.RecipePackage.Export(storage, args[exportIndex + 1], args[exportIndex + 2]); foreach (var note in result.Warnings) Console.WriteLine($"提醒:{note}"); Console.WriteLine($"已导出配方包:{result.Path}({result.FileCount} 个文件)"); return 0; @@ -55,12 +55,12 @@ internal static class Program // 一次可传多个包;同名配方自动追加 -2、-3 等后缀,命令行没有确认窗口,绝不覆盖现场配方。 var paths = args.Skip(packageIndex + 1).TakeWhile(arg => !arg.StartsWith("--")).ToArray(); if (paths.Length == 0) throw new ArgumentException("--import-recipe-package 后需提供配方包文件"); - var storage = new SopHelper.Engine.Training.RecipeWorkspace(Presentation.DesktopPlatform.WorkspaceRoot); + var storage = new SopHelper.Engine.Recipes.RecipeWorkspace(Presentation.DesktopPlatform.WorkspaceRoot); foreach (var path in paths) { - var info = SopHelper.Engine.Training.RecipePackage.Inspect(path); - var target = SopHelper.Engine.Training.RecipePackage.SuggestName(storage, info.RecipeName); - var result = SopHelper.Engine.Training.RecipePackage.Import(storage, path, target, false); + var info = SopHelper.Engine.Recipes.RecipePackage.Inspect(path); + var target = SopHelper.Engine.Recipes.RecipePackage.SuggestName(storage, info.RecipeName); + var result = SopHelper.Engine.Recipes.RecipePackage.Import(storage, path, target, false); foreach (var warning in result.Warnings) Console.WriteLine($"提醒:{warning}"); Console.WriteLine($"已导入配方:{result.Name}"); } diff --git a/src/SopHelper.Avalonia/SopVideo/CameraVideoImport.cs b/src/SopHelper.Avalonia/SopVideo/CameraVideoImport.cs index 5fbaf65..d955975 100644 --- a/src/SopHelper.Avalonia/SopVideo/CameraVideoImport.cs +++ b/src/SopHelper.Avalonia/SopVideo/CameraVideoImport.cs @@ -2,7 +2,7 @@ using System.IO; using OpenCvSharp; -using SopHelper.Engine.Training; +using SopHelper.Engine.Recipes; using SopHelper.Presentation; namespace SopHelper.SopVideo; diff --git a/src/SopHelper.Avalonia/SopVideo/CameraViewModel.cs b/src/SopHelper.Avalonia/SopVideo/CameraViewModel.cs index 6a65fe2..38dcc4a 100644 --- a/src/SopHelper.Avalonia/SopVideo/CameraViewModel.cs +++ b/src/SopHelper.Avalonia/SopVideo/CameraViewModel.cs @@ -9,7 +9,7 @@ using SopHelper.Presentation.Imaging; using SopHelper.Presentation.Threading; using OpenCvSharp; using SopHelper.Engine.Camera; -using SopHelper.Engine.Training; +using SopHelper.Engine.Recipes; using Prism.Commands; using Prism.Mvvm; diff --git a/src/SopHelper.Avalonia/SopVideo/SopVideoFlowTest.cs b/src/SopHelper.Avalonia/SopVideo/SopVideoFlowTest.cs index b3eb6c3..80e9da4 100644 --- a/src/SopHelper.Avalonia/SopVideo/SopVideoFlowTest.cs +++ b/src/SopHelper.Avalonia/SopVideo/SopVideoFlowTest.cs @@ -52,7 +52,6 @@ public sealed class SopVideoFlowTest : IDisposable var snapshot = SopConfigLoader.Parse(SopConfigLoader.ToYaml(config)); (SopHelper.Models.RuntimeSettingsStore.Current.Read() ?? new()).Apply(snapshot); snapshot.Sop.Settings.AutoResetOnComplete = false; - snapshot.Sop.Model = null; _stride = Math.Max(1, snapshot.Sop.Settings.FrameStride); _engine.VisionDecisionClient = visionClient ?? new ConfiguredVisionDecisionClient(VisionHttp); _engine.LogArrived += entry => LogObserved?.Invoke(entry); diff --git a/src/SopHelper.Avalonia/VVMs/RecipeEditor/EditorNodes.cs b/src/SopHelper.Avalonia/VVMs/RecipeEditor/EditorNodes.cs index 6c98df4..a10e85d 100644 --- a/src/SopHelper.Avalonia/VVMs/RecipeEditor/EditorNodes.cs +++ b/src/SopHelper.Avalonia/VVMs/RecipeEditor/EditorNodes.cs @@ -27,29 +27,7 @@ public interface IRemovable } /// -/// 字符串列表项(YAML 的 classes / must_keep / required_objects)。 -/// 不能直接绑 string——string 不实现 INPC,TwoWay 写不回集合项。 -/// -public class TextItem : EditorNode, IRemovable -{ - private string _text = ""; - - /// 文本 - public string Text - { - get { return _text; } - set { SetProperty(ref _text, value); } - } - - /// - public ICommand? RemoveCommand { get; set; } - - /// - public override string ToString() => Text; -} - -/// -/// 可增删的行列表(类别名、必在物料、违规规则都用它) +/// 可增删的编辑行列表,用于违规规则。 /// public class EditableList : EditorNode where T : EditorNode, IRemovable, new() { @@ -119,25 +97,10 @@ public class RecipeNode : EditorNode RemoveStepCommand = new DelegateCommand(node => { RemoveStep(node); Changed?.Invoke(); }, node => node is not null); MoveStepUpCommand = new DelegateCommand(node => { MoveStepUp(node); Changed?.Invoke(); }, node => node is not null && Steps.Any(s => s.Id < node.Id)); MoveStepDownCommand = new DelegateCommand(node => { MoveStepDown(node); Changed?.Invoke(); }, node => node is not null && Steps.Any(s => s.Id > node.Id)); - Parts.Items.CollectionChanged += (_, e) => - { - if (e.OldItems is not null) foreach (TextItem item in e.OldItems) item.PropertyChanged -= PartChanged; - if (e.NewItems is not null) foreach (TextItem item in e.NewItems) item.PropertyChanged += PartChanged; - RefreshPartNames(); - }; } - public EditableList Parts { get; } = new() { Title = "零件列表" }; - public ObservableCollection PartNames { get; } = [""]; - private void PartChanged(object? sender, System.ComponentModel.PropertyChangedEventArgs e) => RefreshPartNames(); - private void RefreshPartNames() - { - // 替换选项时 SelectionConverter 保留当前引用,删除已引用名称由保存校验拦截。 - PartNames.Clear(); - PartNames.Add(""); - foreach (var name in Parts.Items.Select(p => p.Text).Where(n => !string.IsNullOrWhiteSpace(n)).Distinct()) PartNames.Add(name); - Changed?.Invoke(); - } + /// 保留旧配方的零件名称,供保存和步骤交换往返。 + internal List? LegacyParts { get; set; } /// 加区域 public DelegateCommand AddRegionCommand { get; } @@ -224,9 +187,6 @@ public class RecipeNode : EditorNode /// 步骤(sop.steps) public ObservableCollection Steps { get; } = []; - /// 检测模型配置始终启用。 - public RecipeModelNode Model { get; } = new(); - /// 当前编辑的区域 public RegionNode? SelectedRegion { @@ -406,8 +366,7 @@ public class RecipeNode : EditorNode Description = config.Sop.Description, }; - foreach (var name in SopHelper.Engine.Training.PartCatalog.Read(config, null)) - node.Parts.Items.Add(new TextItem { Text = name, RemoveCommand = node.Parts.RemoveCommand }); + node.LegacyParts = config.Sop.Parts?.ToList(); foreach (var (key, def) in config.Sop.Regions) { @@ -444,8 +403,8 @@ public class RecipeNode : EditorNode }, }; - foreach (var item in step.MustKeep) stepNode.MustKeep.Items.Add(new TextItem { Text = item, RemoveCommand = stepNode.MustKeep.RemoveCommand }); - foreach (var item in step.RequiredObjects) stepNode.RequiredObjects.Items.Add(new TextItem { Text = item, RemoveCommand = stepNode.RequiredObjects.RemoveCommand }); + stepNode.LegacyMustKeep.AddRange(step.MustKeep); + stepNode.LegacyRequiredObjects.AddRange(step.RequiredObjects); if (step.Detection is not null) stepNode.Detection = ConditionNode.From(step.Detection); @@ -455,11 +414,6 @@ public class RecipeNode : EditorNode node.Steps.Add(stepNode); } - if (config.Sop.Model is not null) - { - node.Model.CopyFrom(config.Sop.Model); - } - node.SelectedStep = node.Steps.FirstOrDefault(); node.SelectedRegion = node.Regions.FirstOrDefault(); @@ -477,8 +431,7 @@ public class RecipeNode : EditorNode config.Sop.Name = Name; config.Sop.Version = Version; config.Sop.Description = Description; - config.Sop.Parts = Parts.Items.Select(p => p.Text).ToList(); - + config.Sop.Parts = LegacyParts?.ToList(); foreach (var region in Regions.Where(r => !string.IsNullOrWhiteSpace(r.Key))) { @@ -513,8 +466,8 @@ public class RecipeNode : EditorNode }, }; - def.MustKeep.AddRange(step.MustKeep.Items.Select(i => i.Text).Where(s => !string.IsNullOrWhiteSpace(s))); - def.RequiredObjects.AddRange(step.RequiredObjects.Items.Select(i => i.Text).Where(s => !string.IsNullOrWhiteSpace(s))); + def.MustKeep.AddRange(step.LegacyMustKeep); + def.RequiredObjects.AddRange(step.LegacyRequiredObjects); if (step.Detection is not null && !string.IsNullOrWhiteSpace(step.Detection.Method)) def.Detection = step.Detection.ToCondition(); @@ -525,48 +478,10 @@ public class RecipeNode : EditorNode config.Sop.Steps.Add(def); } - config.Sop.Model = null; - return config; } } -/// -/// sop.model -/// -public class RecipeModelNode : EditorNode -{ - private string _path = ""; - private int _inputSize = 640; - - /// onnx 路径(相对程序目录) - public string Path - { - get { return _path; } - set { SetProperty(ref _path, value); } - } - - /// 类别名(顺序必须与训练时一致) - public EditableList Classes { get; } = new() { Title = "类别名(顺序须与训练一致)" }; - - /// 输入尺寸 - public int InputSize - { - get { return _inputSize; } - set { SetProperty(ref _inputSize, value); } - } - - /// 读入 - public void CopyFrom(ModelDef from) - { - Path = from.Path; - InputSize = from.InputSize; - - Classes.Items.Clear(); - foreach (var name in from.Classes) Classes.Items.Add(new TextItem { Text = name, RemoveCommand = Classes.RemoveCommand }); - } -} - /// /// regions 里的一项(Key = 配方里引用的区域名,即 YAML 的字典键) /// @@ -864,11 +779,9 @@ public class StepNode : EditorNode set { SetProperty(ref _detection, value); } } - /// 本步期间必须常在的物体 - public EditableList MustKeep { get; } = new() { Title = "本步期间必须在的物体(被拿走即违规)" }; - - /// 本步完成时必须存在的物体 - public EditableList RequiredObjects { get; } = new() { Title = "本步完成时必须存在的物体(漏放/缺料)" }; + /// 保留旧物料规则,使编辑和保存后仍可提示工艺迁移。 + internal List LegacyMustKeep { get; } = []; + internal List LegacyRequiredObjects { get; } = []; /// 违规规则 public EditableList ViolationRules { get; } = new() { Title = "违规规则" }; @@ -924,7 +837,7 @@ public class ConditionNode : EditorNode public bool UsesHandTrigger => UsesTriggerRegion || IsMoveTrigger; public bool UsesStableGate => UsesTriggerRegion; - /// 目标物体类别 + /// 旧物体触发的目标名称,仅用于配方往返。 public string TargetObject { get { return _targetObject; } diff --git a/src/SopHelper.Avalonia/VVMs/RecipeEditor/RecipeEditor.axaml b/src/SopHelper.Avalonia/VVMs/RecipeEditor/RecipeEditor.axaml index 7c52476..aec859e 100644 --- a/src/SopHelper.Avalonia/VVMs/RecipeEditor/RecipeEditor.axaml +++ b/src/SopHelper.Avalonia/VVMs/RecipeEditor/RecipeEditor.axaml @@ -1,15 +1,5 @@ - - - - - - - -