From 27ca4163256bfd673312c7caa9035a65c49f3fcc Mon Sep 17 00:00:00 2001 From: tfarcraw <123211521@163.com> Date: Fri, 17 Jul 2026 00:03:27 +0800 Subject: [PATCH] =?UTF-8?q?=E9=87=8D=E5=A4=8D=E4=BB=A3=E7=A0=81=E5=90=88?= =?UTF-8?q?=E5=B9=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../VVMs/Vision/VisionConfigViewModel.cs | 65 ++++--------------- 1 file changed, 11 insertions(+), 54 deletions(-) diff --git a/PLCSharpWpf/VVMs/Vision/VisionConfigViewModel.cs b/PLCSharpWpf/VVMs/Vision/VisionConfigViewModel.cs index 7214c13..45efb36 100644 --- a/PLCSharpWpf/VVMs/Vision/VisionConfigViewModel.cs +++ b/PLCSharpWpf/VVMs/Vision/VisionConfigViewModel.cs @@ -1054,17 +1054,7 @@ namespace PLCSharp.VVMs.Vision private async Task ExecuteComputeEdgeTemplateAsync() { - if (SelectVisionFlow == null || SelectedVisionFunction == null) return; - SelectVisionFlow.StringParams["ComputeTemplate"] = "1"; - try - { - if (!SelectedVisionFunction.RunItem(SelectVisionFlow)) - SendInfoDialog("模板计算失败"); - else - SendInfoDialog("模板已保存"); - } - catch (Exception ex) { SendInfoDialog(ex.Message); } - finally { SelectVisionFlow.StringParams.Remove("ComputeTemplate"); } + await ComputeTemplateAsync(); } @@ -1331,23 +1321,7 @@ namespace PLCSharp.VVMs.Vision _ComputeTwoLineTemplate ??= new AsyncDelegateCommand(ExecuteComputeTwoLineTemplateAsync); private async Task ExecuteComputeTwoLineTemplateAsync() { - if (SelectVisionFlow == null || SelectedVisionFunction == null) return; - SelectVisionFlow.StringParams["ComputeTemplate"] = "1"; - try - { - if (!SelectedVisionFunction.RunItem(SelectVisionFlow)) - SendInfoDialog("模板计算失败"); - else - SendInfoDialog("模板已保存"); - } - catch (Exception ex) - { - SendInfoDialog(ex.Message); - } - finally - { - SelectVisionFlow.StringParams.Remove("ComputeTemplate"); - } + await ComputeTemplateAsync(); } @@ -1357,23 +1331,7 @@ namespace PLCSharp.VVMs.Vision private async Task ExecuteComputeCircleTemplateAsync() { - if (SelectVisionFlow == null || SelectedVisionFunction == null) return; - SelectVisionFlow.StringParams["ComputeTemplate"] = "1"; - try - { - if (!SelectedVisionFunction.RunItem(SelectVisionFlow)) - SendInfoDialog("模板计算失败"); - else - SendInfoDialog("模板已保存"); - } - catch (Exception ex) - { - SendInfoDialog(ex.Message); - } - finally - { - SelectVisionFlow.StringParams.Remove("ComputeTemplate"); - } + await ComputeTemplateAsync(); } @@ -1386,23 +1344,22 @@ namespace PLCSharp.VVMs.Vision private async Task ExecuteComputeRectTemplateAsync() { - if (SelectVisionFlow == null || SelectedVisionFunction == null) - return; + await ComputeTemplateAsync(); + } - // 设标记让 handler 保存模板 + /// + /// 通用模板计算:设标记 → RunItem → 弹提示 → 清标记 + /// + private async Task ComputeTemplateAsync() + { + if (SelectVisionFlow == null || SelectedVisionFunction == null) return; SelectVisionFlow.StringParams["ComputeTemplate"] = "1"; - try { - // 执行一次找矩形 if (!SelectedVisionFunction.RunItem(SelectVisionFlow)) - { SendInfoDialog("模板计算失败"); - } else - { SendInfoDialog("模板已保存"); - } } catch (Exception ex) {