修复自动生成步骤后区域候选未刷新

This commit is contained in:
wanglei 2026-11-27 15:40:04 +08:00
parent 4aa471d536
commit d43147e606
2 changed files with 29 additions and 4 deletions

View File

@ -210,7 +210,7 @@ public class RecipeNode : EditorNode
/// <summary>违规类型下拉候选</summary>
public IReadOnlyList<string> ViolationTypes { get; }
/// <summary>区域名下拉候选(含空项,表示该字段不引用区域)</summary>
/// <summary>区域名下拉候选快照(含空项,表示该字段不引用区域)。区域键或集合变化后需通知下拉框重新读取。</summary>
public IReadOnlyList<string> RegionNames
{
get
@ -237,6 +237,7 @@ public class RecipeNode : EditorNode
node.Renamed += OnRegionRenamed;
Regions.Add(node);
RaisePropertyChanged(nameof(RegionNames));
SelectedRegion = node;
return node;
@ -254,6 +255,7 @@ public class RecipeNode : EditorNode
foreach (var step in Steps.Where(s => s.Detection is not null && References(s.Detection, node.Key)))
ClearRegionReferences(step.Detection!, node.Key);
RaisePropertyChanged(nameof(RegionNames));
SelectedRegion = Regions.FirstOrDefault();
}

View File

@ -1404,7 +1404,7 @@ internal static class Smoke
model.CancelAgentCommand.Execute();
for(var i=0;i<100&&model.IsAgentBusy;i++)await Task.Delay(10);
Check(!model.IsAgentBusy&&model.Recipe.Steps.Count==originalCount,"Cancelling analysis never mutates the recipe");
Check(editor.GetVisualDescendants().OfType<Button>().Any(b=>Equals(b.Content,"取消生成")),"Assistant uses the cancel generation label");
Check(editor.GetVisualDescendants().OfType<Button>().Any(b=>Equals(b.Content,"取消任务")),"Assistant uses the cancel task label");
async Task ApplyDraft(string buttonName, bool completed)
{
model.ApplyAgentDraftCommand.Execute();
@ -1428,9 +1428,30 @@ internal static class Smoke
}
await ApplyDraft("AgentApplyCancelButton",false);
Check(model.Recipe.Steps.Count==originalCount&&model.ApplyAgentDraftCommand.CanExecute(),"Cancelling the apply dialog preserves the recipe and draft");
// 下拉框已绑定时也需要收到通知,切换标签页可能重新绑定而掩盖候选未刷新的问题。
var notifiedOfGeneratedRegion=false;
void OnRegionNamesChanged(object? sender,System.ComponentModel.PropertyChangedEventArgs e)
{
if(e.PropertyName==nameof(RecipeNode.RegionNames))
notifiedOfGeneratedRegion|=model.Recipe.RegionNames.Contains("料盒2");
}
model.Recipe.PropertyChanged+=OnRegionNamesChanged;
await ApplyDraft("AgentApplyAppendButton",true);
model.Recipe.PropertyChanged-=OnRegionNamesChanged;
Check(notifiedOfGeneratedRegion,"Applying a generated region refreshes the existing dropdown bindings");
Check(model.Recipe.Steps.Count==originalCount+2&&model.Recipe.Steps[0].Name=="装配","Applying generated steps preserves existing steps and appends the draft");
Check(model.Recipe.Steps[originalCount].Description=="把连接器放入盒子,盒内可见连接器"&&model.Recipe.Steps[originalCount].Detection?.Method=="hand_leave_region","Edited draft description becomes the D3 criterion with a hand trigger");
// 同时核对区域列表、触发区与送检区,覆盖草稿写入和下拉候选刷新。
tabs.SelectedItem=tabs.Items.OfType<TabItem>().Single(t=>Equals(t.Header,"步骤"));
model.Recipe.SelectedStep=model.Recipe.Steps[originalCount+1];
await Task.Delay(30);
var regionList=editor.FindControl<ListBox>("StepRegionNavigation")!;
var triggerRegion=editor.FindControl<Grid>("TriggerRegionRow")!.Children.OfType<ComboBox>().Single();
var imageRegion=editor.FindControl<ComboBox>("AiImageRegionPicker")!;
Check(regionList.Items.OfType<RegionNode>().Any(r=>r.Key=="料盒2"&&r.X1==4&&r.X2==30)
&&Equals(triggerRegion.SelectedItem,"料盒2")&&Equals(imageRegion.SelectedItem,"料盒2"),
"A generated region appears in the region list and is selected for the step trigger and image crop");
tabs.SelectedItem=tabs.Items.OfType<TabItem>().Single(t=>Equals(t.Header,"Agent助手"));
model.ApplyAgentDraftCommand.Execute();
Check(model.Recipe.Steps.Count==originalCount+2&&!model.ApplyAgentDraftCommand.CanExecute(),"A draft cannot be applied twice");
Check(File.ReadAllBytes(configPath).SequenceEqual(before),"Adding draft steps still requires explicit recipe save");
@ -1457,6 +1478,7 @@ internal static class Smoke
Check(model.AgentChatMessages.Count==0&&model.AgentDraftSteps.Count==1,"Clearing chat preserves the current draft");
foreach(var step in model.Recipe.Steps.ToArray())model.Recipe.RemoveStep(step);
foreach(var step in originalSteps)model.Recipe.Steps.Add(step);
model.Recipe.RemoveRegion(model.Recipe.Regions.Single(r=>r.Key=="料盒2"));
model.Recipe.SelectedStep=model.Recipe.Steps[0];tabs.SelectedIndex=0;
}
@ -1917,8 +1939,9 @@ internal sealed class UiSopAgent : ISopVideoDraftClient
Request=request;Connection=connection;
if(Hold){Held=true;return new TaskCompletionSource<SopVideoDraft>().Task;}
return Task.FromResult(new SopVideoDraft{Summary="放入并取走零件",
ObservedFrames=SopVideoSampler.ReadFrames(request.Video,[0,2,3.9],0,token),Steps=[
ObservedFrames=SopVideoSampler.ReadFrames(request.Video,[0,2,3.9],0,token),
RegionAdjustments=[new(){Key="料盒2",Name="第二个料盒",X1=4,Y1=4,X2=30,Y2=30,EvidenceFrame=2,Note="取走零件的位置"}],Steps=[
new(){Name="放入零件",Description="盒子里有零件",StartSeconds=0,EndSeconds=2,Region="work",EvidenceFrame=1},
new(){Name="取走零件",Description="盒子里没有零件",StartSeconds=2,EndSeconds=4,Region="work",EvidenceFrame=2}]});
new(){Name="取走零件",Description="盒子里没有零件",StartSeconds=2,EndSeconds=4,Region="料盒2",EvidenceFrame=2}]});
}
}