HalconDisplayModel.cs 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using PropertyGridLib.Attributes;
  5. using PropertyGridLib.Controls;
  6. using TeamAAS.FlowEditor.Plugins;
  7. using TeamAAS.FlowEngine.FormulaData;
  8. namespace Plugins.Halcon.Models
  9. {
  10. /// <summary>
  11. /// HALCON 图像显示节点模型:把上游 HALCON 节点的图像/区域显示到主页指定画面框(视觉窗体),
  12. /// 每个显示项可独立链接 OK/NG 结果驱动画面框状态圆点。镜像 VppDisplayModel,但对象为 HALCON HObject。
  13. /// </summary>
  14. [Serializable]
  15. public class HalconDisplayModel : BasePluginModel
  16. {
  17. [Category("属性")]
  18. [DisplayName("1.显示项列表")]
  19. [Description("配置图像到画面框的显示映射,可添加多条;每项可独立链接叠加区域与 OK/NG(可不链接)")]
  20. [CollectionEditor(CanAdd = true, CanRemove = true, CanSort = true)]
  21. public List<HalconDisplayItem> DisplayItems { get; set; } = new List<HalconDisplayItem>();
  22. }
  23. [Serializable]
  24. public class HalconDisplayItem
  25. {
  26. /// <summary>目标画面序号(实际存储值,运行按 halconWindow[FrameNo-1] 取窗体)。</summary>
  27. [Browsable(false)]
  28. public int FrameNo { get; set; } = 1;
  29. /// <summary>目标画面名称(属性网格显示/选择):来自当前产品「画面列表」,选择时映射为序号存入 FrameNo。</summary>
  30. [DisplayName("1.目标画面")]
  31. [Category("属性")]
  32. [Description("从当前产品的画面列表中选择目标画面,按名称选择、内部存储对应序号")]
  33. [TypeConverter(typeof(Plugins.Halcon.Core.HalconFrameNameConverter))]
  34. [Newtonsoft.Json.JsonIgnore]
  35. public string FrameName
  36. {
  37. get => Plugins.Halcon.Core.HalconFrameNameConverter.GetFrameName(
  38. Plugins.Halcon.Core.HalconFrameNameConverter.GetFrames(), FrameNo);
  39. set
  40. {
  41. int no = Plugins.Halcon.Core.HalconFrameNameConverter.ResolveFrameNo(value);
  42. if (no >= 1) FrameNo = no;
  43. }
  44. }
  45. [DisplayName("2.链接图像")]
  46. [Category("属性")]
  47. [Description("链接上游图像输出(HALCON HObject 图像,或主流程 &{输入.图像} 的 GenImage)")]
  48. [FormulaEditor(typeof(PluginDataProvider))]
  49. public FormulaBound<object> Source { get; set; } = new FormulaBound<object>();
  50. [DisplayName("3.叠加区域(可选)")]
  51. [Category("属性")]
  52. [Description("可选:链接上游区域/区域集,以红色边界叠加绘制在图像上(如阈值分割的区域)")]
  53. [FormulaEditor(typeof(PluginDataProvider))]
  54. public FormulaBound<object> OverlaySource { get; set; } = new FormulaBound<object>();
  55. [DisplayName("4.OK/NG 链接(可选)")]
  56. [Category("属性")]
  57. [Description("链接该画面的结果公式;为空=不链接(圆点保持原状)。非空时按真假把圆点刷成 绿/红")]
  58. [FormulaEditor(typeof(PluginDataProvider))]
  59. public FormulaBound<bool> OkNgBinding { get; set; } = new FormulaBound<bool>();
  60. public override string ToString()
  61. => $"{FrameName} ← {Source?.Formula ?? "(未链接)"}" +
  62. (string.IsNullOrWhiteSpace(OverlaySource?.Formula) ? "" : " +叠加") +
  63. (string.IsNullOrWhiteSpace(OkNgBinding?.Formula) ? "" : " |OK/NG");
  64. }
  65. /// <summary>交互绘制的 ROI 类型。</summary>
  66. [Serializable]
  67. public enum HalconRoiType
  68. {
  69. None = 0,
  70. Rectangle1 = 1, // 正矩形(row1,col1,row2,col2)
  71. Rectangle2 = 2, // 旋转矩形(row,col,phi,length1,length2)
  72. Circle = 3, // 圆(row,col,radius)
  73. }
  74. /// <summary>
  75. /// 可序列化的 ROI 描述(HalconWindow 交互绘制结果;节点可读取用于限定处理区域)。
  76. /// 只存几何参数(double),不持有 HObject,随流程安全序列化。
  77. /// </summary>
  78. [Serializable]
  79. public class HalconRoi
  80. {
  81. public HalconRoiType Type { get; set; } = HalconRoiType.None;
  82. // Rectangle1
  83. public double Row1 { get; set; }
  84. public double Col1 { get; set; }
  85. public double Row2 { get; set; }
  86. public double Col2 { get; set; }
  87. // Rectangle2 / Circle 共用中心
  88. public double Row { get; set; }
  89. public double Col { get; set; }
  90. // Rectangle2
  91. public double Phi { get; set; }
  92. public double Length1 { get; set; }
  93. public double Length2 { get; set; }
  94. // Circle
  95. public double Radius { get; set; }
  96. public override string ToString()
  97. {
  98. switch (Type)
  99. {
  100. case HalconRoiType.Rectangle1: return $"Rect1[{Row1:F0},{Col1:F0},{Row2:F0},{Col2:F0}]";
  101. case HalconRoiType.Rectangle2: return $"Rect2[{Row:F0},{Col:F0},φ{Phi:F2},{Length1:F0},{Length2:F0}]";
  102. case HalconRoiType.Circle: return $"Circle[{Row:F0},{Col:F0},R{Radius:F0}]";
  103. default: return "None";
  104. }
  105. }
  106. }
  107. }