From e739dcf35c31e931df544a0b41d8524c22d70d62 Mon Sep 17 00:00:00 2001 From: sophelper <123211521@163.com> Date: Thu, 5 Nov 2026 23:43:36 +0800 Subject: [PATCH] Improve recipe region editor layout and keep editor open after saving --- README.md | 17 ++ .../VVMs/RecipeEditor/EditorNodes.cs | 14 ++ .../VVMs/RecipeEditor/RecipeEditor.xaml | 177 +++++++++------ .../RecipeEditor/RecipeEditorViewModel.cs | 133 ++++++++++- .../VVMs/RecipeEditor/RegionCanvas.cs | 177 +++++++++++++++ .../VVMs/SopPage/SopPageViewModel.cs | 23 +- tests/RegionEditorSmoke/Program.cs | 213 ++++++++++++++++++ .../RegionEditorSmoke.csproj | 13 ++ 8 files changed, 684 insertions(+), 83 deletions(-) create mode 100644 src/SopHelper.App/VVMs/RecipeEditor/RegionCanvas.cs create mode 100644 tests/RegionEditorSmoke/Program.cs create mode 100644 tests/RegionEditorSmoke/RegionEditorSmoke.csproj diff --git a/README.md b/README.md index ad386bf..a643b85 100644 --- a/README.md +++ b/README.md @@ -135,6 +135,23 @@ SOP 页配方行的「编辑 / 新建」。表单式,四个 tab:步骤 / 区 "照抄别人的 YAML 拼错一个字母"这种事发生(下拉候选就是 `ConditionMethod` 那几项)。 区域改键名会同步更新所有引用它的步骤;删区域会清掉引用。 +区域页支持图像画框标定: + +1. 停止运行,在 SOP 页选好相机,打开「编辑 / 新建」→「区域」。 +2. 已有预览画面会作为背景带入;也可点「从相机取图」获取新的一帧,或「打开图片」载入原图。 + 取图完成后自动关闭相机,不启动 SOP 判定。 +3. 左侧选中区域(没有则点「加区域」),在图上按住左键拖动画框,松开后更新 X1/Y1/X2/Y2。 + 支持反方向拖动;超出图像边界会截取到边界;Esc 取消本次绘制。 +4. 重画可直接替换所选区域;下方数字可微调,并同步更新图上的框。点击「保存」写入配方。 + +图像保持原比例显示,坐标保存为原图像素,不包含预览留白。打开的图片应与现场相机分辨率一致。 + +区域编辑回归检查(可加 `--hardware` 使用现场海康取图): + +```bash +dotnet run --project tests/RegionEditorSmoke/RegionEditorSmoke.csproj +``` + 两条要注意的: - **保存是重写整个文件,注释会丢**(YamlDotNet 不保留注释)。`demo.yaml` 顶上那些说明 diff --git a/src/SopHelper.App/VVMs/RecipeEditor/EditorNodes.cs b/src/SopHelper.App/VVMs/RecipeEditor/EditorNodes.cs index 1cd3a0c..8b8fbad 100644 --- a/src/SopHelper.App/VVMs/RecipeEditor/EditorNodes.cs +++ b/src/SopHelper.App/VVMs/RecipeEditor/EditorNodes.cs @@ -172,6 +172,12 @@ public class RecipeNode : EditorNode get { return IsNew; } } + internal void MarkSaved(string fileName) + { + FileName = fileName; + IsNew = false; + } + /// 配方名(sop.name) public string Name { @@ -637,6 +643,14 @@ public class RecipeModelNode : EditorNode /// public class RegionNode : EditorNode { + /// 整组更新,属性通知发出时四个坐标已一致。 + public void SetBounds(System.Windows.Int32Rect bounds) + { + _x1 = bounds.X; _y1 = bounds.Y; _x2 = bounds.X + bounds.Width; _y2 = bounds.Y + bounds.Height; + RaisePropertyChanged(nameof(X1)); RaisePropertyChanged(nameof(Y1)); + RaisePropertyChanged(nameof(X2)); RaisePropertyChanged(nameof(Y2)); + } + private string _key = ""; private int _x1; private int _y1; diff --git a/src/SopHelper.App/VVMs/RecipeEditor/RecipeEditor.xaml b/src/SopHelper.App/VVMs/RecipeEditor/RecipeEditor.xaml index 81624b5..1a8f460 100644 --- a/src/SopHelper.App/VVMs/RecipeEditor/RecipeEditor.xaml +++ b/src/SopHelper.App/VVMs/RecipeEditor/RecipeEditor.xaml @@ -4,7 +4,20 @@ xmlns:prism="http://prismlibrary.com/" xmlns:ed="clr-namespace:SopHelper.VVMs.RecipeEditor" prism:ViewModelLocator.AutoWireViewModel="True" - Width="1020" Height="720" Background="{StaticResource Bg}"> + Background="{StaticResource Bg}"> + + + + @@ -344,84 +357,113 @@ - + +