using System; using System.Collections.Generic; using System.Threading; using TeamAAS.FlowEditor.Execution; using TeamAAS.FlowEditor.Models; using TeamAAS.FlowEditor.Plugins; using Plugins.Vpp.Models; namespace Plugins.Vpp { // ───────────────────────────────────────────────────────────────────── // VisionPro 几何测量算子(算子级节点):卡尺 / 找圆 / 找直线。 // ───────────────────────────────────────────────────────────────────── /// Vp卡尺测量:边缘对位置与宽度。 [Serializable] [Plugin("Vp卡尺测量", PluginCategory.Vpp模块, typeof(VpCaliperModel), "Ruler", NodeShape = NodeCategory.Normal, IsSubFlowNode = true, VisionCategory = VisionPlugin.几何测量, Description = "Cognex Caliper 卡尺:高级编辑进原生界面摆卡尺/调极性;输出边缘位置与宽度")] public class VpCaliperPlugin : VpToolPluginBase { protected override string ToolTypeName => "CogCaliperTool"; /// 预设终端:卡尺匹配分数(边缘位置/宽度已由 类型化结果 覆盖)。 public override VpPresetTerminal[] PresetTerminals => new[] { new VpPresetTerminal("分数", "Results[0].Score"), }; protected override IEnumerable DeclareResultFields() { yield return new OutputField("位置1", typeof(double)); yield return new OutputField("位置2", typeof(double)); yield return new OutputField("宽度", typeof(double)); } protected override void ExtractResults(object tool, Dictionary results) { results["位置1"] = Get(tool, "Results[0].Edge0Position"); results["位置2"] = Get(tool, "Results[0].Edge1Position"); results["宽度"] = Get(tool, "Results[0].Width"); Log(2, $"卡尺完成:宽度={results["宽度"]}"); } } /// Vp找圆:圆心与半径。 [Serializable] [Plugin("Vp找圆", PluginCategory.Vpp模块, typeof(VpFindCircleModel), "CircleOutline", NodeShape = NodeCategory.Normal, IsSubFlowNode = true, VisionCategory = VisionPlugin.几何测量, Description = "Cognex FindCircle:高级编辑进原生界面设置搜索区域与卡尺组;输出圆心/半径")] public class VpFindCirclePlugin : VpToolPluginBase { protected override string ToolTypeName => "CogFindCircleTool"; protected override IEnumerable DeclareResultFields() { yield return new OutputField("圆心X", typeof(double)); yield return new OutputField("圆心Y", typeof(double)); yield return new OutputField("半径", typeof(double)); } protected override void ExtractResults(object tool, Dictionary results) { results["圆心X"] = Get(tool, "Results.Circle.Center.X"); results["圆心Y"] = Get(tool, "Results.Circle.Center.Y"); results["半径"] = Get(tool, "Results.Circle.Radius"); Log(2, $"找圆完成:圆心=({results["圆心X"]},{results["圆心Y"]}),半径={results["半径"]}"); } } /// Vp找直线:直线拟合。 [Serializable] [Plugin("Vp找直线", PluginCategory.Vpp模块, typeof(VpFindLineModel), "VectorLine", NodeShape = NodeCategory.Normal, IsSubFlowNode = true, VisionCategory = VisionPlugin.几何测量, Description = "Cognex FindLine:高级编辑进原生界面设置搜索带与卡尺组;输出拟合直线")] public class VpFindLinePlugin : VpToolPluginBase { protected override string ToolTypeName => "CogFindLineTool"; protected override IEnumerable DeclareResultFields() { yield return new OutputField("直线", typeof(object)); yield return new OutputField("合格", typeof(bool)); } protected override void ExtractResults(object tool, Dictionary results) { var line = Get(tool, "Results.Line"); results["直线"] = line; results["合格"] = line != null; Log(2, $"找直线完成:{(line != null ? "已拟合" : "未找到直线")}"); } } } namespace Plugins.Vpp.Models { using TeamAAS.FlowEditor.Plugins; /// Vp卡尺测量模型。 [Serializable] public class VpCaliperModel : VpToolModelBase { } /// Vp找圆模型。 [Serializable] public class VpFindCircleModel : VpToolModelBase { } /// Vp找直线模型。 [Serializable] public class VpFindLineModel : VpToolModelBase { } }