| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119 |
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using PropertyGridLib.Attributes;
- using PropertyGridLib.Controls;
- using TeamAAS.FlowEditor.Plugins;
- using TeamAAS.FlowEngine.FormulaData;
- namespace Plugins.Halcon.Models
- {
- /// <summary>
- /// HALCON 图像显示节点模型:把上游 HALCON 节点的图像/区域显示到主页指定画面框(视觉窗体),
- /// 每个显示项可独立链接 OK/NG 结果驱动画面框状态圆点。镜像 VppDisplayModel,但对象为 HALCON HObject。
- /// </summary>
- [Serializable]
- public class HalconDisplayModel : BasePluginModel
- {
- [Category("属性")]
- [DisplayName("1.显示项列表")]
- [Description("配置图像到画面框的显示映射,可添加多条;每项可独立链接叠加区域与 OK/NG(可不链接)")]
- [CollectionEditor(CanAdd = true, CanRemove = true, CanSort = true)]
- public List<HalconDisplayItem> DisplayItems { get; set; } = new List<HalconDisplayItem>();
- }
- [Serializable]
- public class HalconDisplayItem
- {
- /// <summary>目标画面序号(实际存储值,运行按 halconWindow[FrameNo-1] 取窗体)。</summary>
- [Browsable(false)]
- public int FrameNo { get; set; } = 1;
- /// <summary>目标画面名称(属性网格显示/选择):来自当前产品「画面列表」,选择时映射为序号存入 FrameNo。</summary>
- [DisplayName("1.目标画面")]
- [Category("属性")]
- [Description("从当前产品的画面列表中选择目标画面,按名称选择、内部存储对应序号")]
- [TypeConverter(typeof(Plugins.Halcon.Core.HalconFrameNameConverter))]
- [Newtonsoft.Json.JsonIgnore]
- public string FrameName
- {
- get => Plugins.Halcon.Core.HalconFrameNameConverter.GetFrameName(
- Plugins.Halcon.Core.HalconFrameNameConverter.GetFrames(), FrameNo);
- set
- {
- int no = Plugins.Halcon.Core.HalconFrameNameConverter.ResolveFrameNo(value);
- if (no >= 1) FrameNo = no;
- }
- }
- [DisplayName("2.链接图像")]
- [Category("属性")]
- [Description("链接上游图像输出(HALCON HObject 图像,或主流程 &{输入.图像} 的 GenImage)")]
- [FormulaEditor(typeof(PluginDataProvider))]
- public FormulaBound<object> Source { get; set; } = new FormulaBound<object>();
- [DisplayName("3.叠加区域(可选)")]
- [Category("属性")]
- [Description("可选:链接上游区域/区域集,以红色边界叠加绘制在图像上(如阈值分割的区域)")]
- [FormulaEditor(typeof(PluginDataProvider))]
- public FormulaBound<object> OverlaySource { get; set; } = new FormulaBound<object>();
- [DisplayName("4.OK/NG 链接(可选)")]
- [Category("属性")]
- [Description("链接该画面的结果公式;为空=不链接(圆点保持原状)。非空时按真假把圆点刷成 绿/红")]
- [FormulaEditor(typeof(PluginDataProvider))]
- public FormulaBound<bool> OkNgBinding { get; set; } = new FormulaBound<bool>();
- public override string ToString()
- => $"{FrameName} ← {Source?.Formula ?? "(未链接)"}" +
- (string.IsNullOrWhiteSpace(OverlaySource?.Formula) ? "" : " +叠加") +
- (string.IsNullOrWhiteSpace(OkNgBinding?.Formula) ? "" : " |OK/NG");
- }
- /// <summary>交互绘制的 ROI 类型。</summary>
- [Serializable]
- public enum HalconRoiType
- {
- None = 0,
- Rectangle1 = 1, // 正矩形(row1,col1,row2,col2)
- Rectangle2 = 2, // 旋转矩形(row,col,phi,length1,length2)
- Circle = 3, // 圆(row,col,radius)
- }
- /// <summary>
- /// 可序列化的 ROI 描述(HalconWindow 交互绘制结果;节点可读取用于限定处理区域)。
- /// 只存几何参数(double),不持有 HObject,随流程安全序列化。
- /// </summary>
- [Serializable]
- public class HalconRoi
- {
- public HalconRoiType Type { get; set; } = HalconRoiType.None;
- // Rectangle1
- public double Row1 { get; set; }
- public double Col1 { get; set; }
- public double Row2 { get; set; }
- public double Col2 { get; set; }
- // Rectangle2 / Circle 共用中心
- public double Row { get; set; }
- public double Col { get; set; }
- // Rectangle2
- public double Phi { get; set; }
- public double Length1 { get; set; }
- public double Length2 { get; set; }
- // Circle
- public double Radius { get; set; }
- public override string ToString()
- {
- switch (Type)
- {
- case HalconRoiType.Rectangle1: return $"Rect1[{Row1:F0},{Col1:F0},{Row2:F0},{Col2:F0}]";
- case HalconRoiType.Rectangle2: return $"Rect2[{Row:F0},{Col:F0},φ{Phi:F2},{Length1:F0},{Length2:F0}]";
- case HalconRoiType.Circle: return $"Circle[{Row:F0},{Col:F0},R{Radius:F0}]";
- default: return "None";
- }
- }
- }
- }
|