移除检测模型开关并始终启用模型配置

This commit is contained in:
tfarcraw 2026-11-09 14:49:05 +08:00
parent 45e3534dd4
commit cc082080ea
3 changed files with 11 additions and 37 deletions

View File

@ -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
/// <summary>步骤(sop.steps)</summary>
public ObservableCollection<StepNode> Steps { get; } = [];
/// <summary>是否配置检测模型(不勾就不写 sop.model 节点)</summary>
public bool HasModel
{
get { return _hasModel; }
set
{
if (!SetProperty(ref _hasModel, value)) return;
// 勾上给一个可编辑的模型节点,取消勾选就丢弃
_model = value ? _model ?? new RecipeModelNode() : null;
RaisePropertyChanged(nameof(Model));
}
}
/// <summary>模型定义(HasModel=false 时为 null)</summary>
public RecipeModelNode? Model
{
get { return _model; }
private set { SetProperty(ref _model, value); }
}
/// <summary>检测模型配置始终启用。</summary>
public RecipeModelNode Model { get; } = new();
/// <summary>当前编辑的区域</summary>
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;
}

View File

@ -380,12 +380,11 @@
</TabItem>
<TabItem Header="检测模型">
<StackPanel x:Name="ModelSettings" Margin="10" DataContext="{Binding Recipe}">
<CheckBox Content="使用检测模型(object_* 与 hand_near_object / person_present 依赖它)" IsChecked="{Binding HasModel}" Margin="0,0,0,10" />
<StackPanel Orientation="Horizontal" Margin="0,0,0,10">
<TextBlock Text="相机曝光(μs)" VerticalAlignment="Center" Margin="0,0,8,0" />
<TextBox x:Name="CameraExposureInput" Width="120" Text="{Binding Settings.ExposureTimeUs, Mode=TwoWay}" ToolTip.Tip="海康相机曝光时间,10000 为 10 毫秒;留空保留相机设置。保存配方后保留,区域取图和 SOP 启动前应用。" />
</StackPanel>
<StackPanel DataContext="{Binding Model}" IsVisible="{Binding DataContext.HasModel, ElementName=ModelSettings}">
<StackPanel DataContext="{Binding Model}">
<Grid Classes="Row">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />

View File

@ -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("配方需要检测模型但尚未配置模型路径 —— 只有手部与计时类条件能工作");
}
}