From cc082080eadad5d8c8e4649cc14f6e27d612e6ef Mon Sep 17 00:00:00 2001
From: tfarcraw <123211521@163.com>
Date: Mon, 9 Nov 2026 14:49:05 +0800
Subject: [PATCH] =?UTF-8?q?=E7=A7=BB=E9=99=A4=E6=A3=80=E6=B5=8B=E6=A8=A1?=
=?UTF-8?q?=E5=9E=8B=E5=BC=80=E5=85=B3=E5=B9=B6=E5=A7=8B=E7=BB=88=E5=90=AF?=
=?UTF-8?q?=E7=94=A8=E6=A8=A1=E5=9E=8B=E9=85=8D=E7=BD=AE?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../VVMs/RecipeEditor/EditorNodes.cs | 37 +++----------------
.../VVMs/RecipeEditor/RecipeEditor.axaml | 3 +-
.../Sop/SopConfigLoader.cs | 8 ++--
3 files changed, 11 insertions(+), 37 deletions(-)
diff --git a/src/SopHelper.Avalonia/VVMs/RecipeEditor/EditorNodes.cs b/src/SopHelper.Avalonia/VVMs/RecipeEditor/EditorNodes.cs
index 8666567..a1b8a3c 100644
--- a/src/SopHelper.Avalonia/VVMs/RecipeEditor/EditorNodes.cs
+++ b/src/SopHelper.Avalonia/VVMs/RecipeEditor/EditorNodes.cs
@@ -90,8 +90,6 @@ public class RecipeNode : EditorNode
private string _name = "";
private string _version = "1.0";
private string _description = "";
- private bool _hasModel;
- private RecipeModelNode? _model;
private RegionNode? _selectedRegion;
private StepNode? _selectedStep;
@@ -210,26 +208,8 @@ public class RecipeNode : EditorNode
/// 步骤(sop.steps)
public ObservableCollection Steps { get; } = [];
- /// 是否配置检测模型(不勾就不写 sop.model 节点)
- public bool HasModel
- {
- get { return _hasModel; }
- set
- {
- if (!SetProperty(ref _hasModel, value)) return;
-
- // 勾上给一个可编辑的模型节点,取消勾选就丢弃
- _model = value ? _model ?? new RecipeModelNode() : null;
- RaisePropertyChanged(nameof(Model));
- }
- }
-
- /// 模型定义(HasModel=false 时为 null)
- public RecipeModelNode? Model
- {
- get { return _model; }
- private set { SetProperty(ref _model, value); }
- }
+ /// 检测模型配置始终启用。
+ public RecipeModelNode Model { get; } = new();
/// 当前编辑的区域
public RegionNode? SelectedRegion
@@ -438,8 +418,7 @@ public class RecipeNode : EditorNode
if (config.Sop.Model is not null)
{
- node.HasModel = true;
- node.Model?.CopyFrom(config.Sop.Model);
+ node.Model.CopyFrom(config.Sop.Model);
}
node.SelectedStep = node.Steps.FirstOrDefault();
@@ -491,13 +470,9 @@ public class RecipeNode : EditorNode
config.Sop.Steps.Add(def);
}
- // 只有勾了模型才写 sop.model:留一个 path 为空的节点会让校验里"需要模型"那几条提醒失灵
- if (HasModel && Model is not null)
- {
- var def = new ModelDef { Path = Model.Path, InputSize = Model.InputSize };
- def.Classes.AddRange(Model.Classes.Items.Select(c => c.Text).Where(c => !string.IsNullOrWhiteSpace(c)));
- config.Sop.Model = def;
- }
+ var model = new ModelDef { Path = Model.Path, InputSize = Model.InputSize };
+ model.Classes.AddRange(Model.Classes.Items.Select(c => c.Text).Where(c => !string.IsNullOrWhiteSpace(c)));
+ config.Sop.Model = model;
return config;
}
diff --git a/src/SopHelper.Avalonia/VVMs/RecipeEditor/RecipeEditor.axaml b/src/SopHelper.Avalonia/VVMs/RecipeEditor/RecipeEditor.axaml
index e2165cb..b88ca54 100644
--- a/src/SopHelper.Avalonia/VVMs/RecipeEditor/RecipeEditor.axaml
+++ b/src/SopHelper.Avalonia/VVMs/RecipeEditor/RecipeEditor.axaml
@@ -380,12 +380,11 @@
-
-
+
diff --git a/src/SopHelper.CrossPlatform.Engine/Sop/SopConfigLoader.cs b/src/SopHelper.CrossPlatform.Engine/Sop/SopConfigLoader.cs
index 518ccd3..ad79233 100644
--- a/src/SopHelper.CrossPlatform.Engine/Sop/SopConfigLoader.cs
+++ b/src/SopHelper.CrossPlatform.Engine/Sop/SopConfigLoader.cs
@@ -126,8 +126,8 @@ public static partial class SopConfigLoader
config.Warnings.Add($"步骤 {step.Id} 引用了未定义的区域 '{name}'");
}
- if (NeedsModel(condition.Method) && config.Sop.Model is null)
- config.Warnings.Add($"步骤 {step.Id} 的方法 '{condition.Method}' 需要模型,但配方没写 sop.model");
+ if (NeedsModel(condition.Method) && string.IsNullOrWhiteSpace(config.Sop.Model?.Path))
+ config.Warnings.Add($"步骤 {step.Id} 的方法 '{condition.Method}' 需要模型,但尚未配置模型路径");
foreach (var rule in step.ViolationRules)
{
@@ -140,11 +140,11 @@ public static partial class SopConfigLoader
}
// 没有模型时,靠模型的条件全部无法判定
- if (config.Sop.Model is null)
+ if (string.IsNullOrWhiteSpace(config.Sop.Model?.Path))
{
var needsModel = config.Sop.Steps.Any(s => s.Detection is not null && NeedsModel(s.Detection.Method));
if (needsModel)
- config.Warnings.Add("配方需要检测模型但未配置 sop.model —— 只有手部与计时类条件能工作");
+ config.Warnings.Add("配方需要检测模型但尚未配置模型路径 —— 只有手部与计时类条件能工作");
}
}