VpMeasurementNodes.cs 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Threading;
  4. using TeamAAS.FlowEditor.Execution;
  5. using TeamAAS.FlowEditor.Models;
  6. using TeamAAS.FlowEditor.Plugins;
  7. using Plugins.Vpp.Models;
  8. namespace Plugins.Vpp
  9. {
  10. // ─────────────────────────────────────────────────────────────────────
  11. // VisionPro 几何测量算子(算子级节点):卡尺 / 找圆 / 找直线。
  12. // ─────────────────────────────────────────────────────────────────────
  13. /// <summary>Vp卡尺测量:边缘对位置与宽度。</summary>
  14. [Serializable]
  15. [Plugin("Vp卡尺测量", PluginCategory.Vpp模块, typeof(VpCaliperModel), "Ruler",
  16. NodeShape = NodeCategory.Normal, IsSubFlowNode = true, VisionCategory = VisionPlugin.几何测量,
  17. Description = "Cognex Caliper 卡尺:高级编辑进原生界面摆卡尺/调极性;输出边缘位置与宽度")]
  18. public class VpCaliperPlugin : VpToolPluginBase<VpCaliperModel>
  19. {
  20. protected override string ToolTypeName => "CogCaliperTool";
  21. /// <summary>预设终端:卡尺匹配分数(边缘位置/宽度已由 类型化结果 覆盖)。</summary>
  22. public override VpPresetTerminal[] PresetTerminals => new[]
  23. {
  24. new VpPresetTerminal("分数", "Results[0].Score"),
  25. };
  26. protected override IEnumerable<OutputField> DeclareResultFields()
  27. {
  28. yield return new OutputField("位置1", typeof(double));
  29. yield return new OutputField("位置2", typeof(double));
  30. yield return new OutputField("宽度", typeof(double));
  31. }
  32. protected override void ExtractResults(object tool, Dictionary<string, object> results)
  33. {
  34. results["位置1"] = Get(tool, "Results[0].Edge0Position");
  35. results["位置2"] = Get(tool, "Results[0].Edge1Position");
  36. results["宽度"] = Get(tool, "Results[0].Width");
  37. Log(2, $"卡尺完成:宽度={results["宽度"]}");
  38. }
  39. }
  40. /// <summary>Vp找圆:圆心与半径。</summary>
  41. [Serializable]
  42. [Plugin("Vp找圆", PluginCategory.Vpp模块, typeof(VpFindCircleModel), "CircleOutline",
  43. NodeShape = NodeCategory.Normal, IsSubFlowNode = true, VisionCategory = VisionPlugin.几何测量,
  44. Description = "Cognex FindCircle:高级编辑进原生界面设置搜索区域与卡尺组;输出圆心/半径")]
  45. public class VpFindCirclePlugin : VpToolPluginBase<VpFindCircleModel>
  46. {
  47. protected override string ToolTypeName => "CogFindCircleTool";
  48. protected override IEnumerable<OutputField> DeclareResultFields()
  49. {
  50. yield return new OutputField("圆心X", typeof(double));
  51. yield return new OutputField("圆心Y", typeof(double));
  52. yield return new OutputField("半径", typeof(double));
  53. }
  54. protected override void ExtractResults(object tool, Dictionary<string, object> results)
  55. {
  56. results["圆心X"] = Get(tool, "Results.Circle.Center.X");
  57. results["圆心Y"] = Get(tool, "Results.Circle.Center.Y");
  58. results["半径"] = Get(tool, "Results.Circle.Radius");
  59. Log(2, $"找圆完成:圆心=({results["圆心X"]},{results["圆心Y"]}),半径={results["半径"]}");
  60. }
  61. }
  62. /// <summary>Vp找直线:直线拟合。</summary>
  63. [Serializable]
  64. [Plugin("Vp找直线", PluginCategory.Vpp模块, typeof(VpFindLineModel), "VectorLine",
  65. NodeShape = NodeCategory.Normal, IsSubFlowNode = true, VisionCategory = VisionPlugin.几何测量,
  66. Description = "Cognex FindLine:高级编辑进原生界面设置搜索带与卡尺组;输出拟合直线")]
  67. public class VpFindLinePlugin : VpToolPluginBase<VpFindLineModel>
  68. {
  69. protected override string ToolTypeName => "CogFindLineTool";
  70. protected override IEnumerable<OutputField> DeclareResultFields()
  71. {
  72. yield return new OutputField("直线", typeof(object));
  73. yield return new OutputField("合格", typeof(bool));
  74. }
  75. protected override void ExtractResults(object tool, Dictionary<string, object> results)
  76. {
  77. var line = Get(tool, "Results.Line");
  78. results["直线"] = line;
  79. results["合格"] = line != null;
  80. Log(2, $"找直线完成:{(line != null ? "已拟合" : "未找到直线")}");
  81. }
  82. }
  83. }
  84. namespace Plugins.Vpp.Models
  85. {
  86. using TeamAAS.FlowEditor.Plugins;
  87. /// <summary>Vp卡尺测量模型。</summary>
  88. [Serializable]
  89. public class VpCaliperModel : VpToolModelBase
  90. {
  91. }
  92. /// <summary>Vp找圆模型。</summary>
  93. [Serializable]
  94. public class VpFindCircleModel : VpToolModelBase
  95. {
  96. }
  97. /// <summary>Vp找直线模型。</summary>
  98. [Serializable]
  99. public class VpFindLineModel : VpToolModelBase
  100. {
  101. }
  102. }