LayerContracts.cs 3.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. using System;
  2. using System.Collections.Generic;
  3. namespace TeamAAS.Vision
  4. {
  5. /// <summary>图层内容类型(决定显示控件如何渲染)。</summary>
  6. public enum LayerKind
  7. {
  8. /// <summary>底图(图像)。</summary>
  9. Image = 0,
  10. /// <summary>区域(Region)。</summary>
  11. Region = 1,
  12. /// <summary>轮廓/边界(XLD 等)。</summary>
  13. Contour = 2,
  14. /// <summary>几何对象(矩形/圆/线等,由各平台自行解释)。</summary>
  15. Geometry = 3,
  16. /// <summary>文字/标注。</summary>
  17. Text = 4,
  18. /// <summary>其他(平台自定义)。</summary>
  19. Other = 99,
  20. }
  21. /// <summary>
  22. /// 一个图层项:视觉节点运行后产出的可显示对象。
  23. /// <see cref="Content"/> 为平台对象(HObject / GenImage / Vm 对象等),所有权由 <see cref="Owned"/> 标记:
  24. /// Owned=true 表示该对象由图层库创建(图层被淘汰时负责释放);false 表示归流程注册表所有,图层只引用不释放。
  25. /// </summary>
  26. public sealed class LayerItem
  27. {
  28. /// <summary>图层显示名(ComboBox 里显示的文案,如 “H阈值分割.区域”)。</summary>
  29. public string Name { get; set; }
  30. /// <summary>图层类型。</summary>
  31. public LayerKind Kind { get; set; }
  32. /// <summary>平台显示对象。</summary>
  33. public object Content { get; set; }
  34. /// <summary>是否为图层库自有对象(淘汰时需要释放)。</summary>
  35. public bool Owned { get; set; }
  36. /// <summary>建议颜色(如 "red"/"#FF0000"),null 用显示控件默认。</summary>
  37. public string Color { get; set; }
  38. public LayerItem() { }
  39. public LayerItem(string name, LayerKind kind, object content, bool owned = false, string color = null)
  40. {
  41. Name = name; Kind = kind; Content = content; Owned = owned; Color = color;
  42. }
  43. }
  44. /// <summary>一次发布 = 某节点一次运行的完整图层集(整体替换,不做增量叠加,避免内存堆积)。</summary>
  45. public sealed class LayerPublishArgs
  46. {
  47. /// <summary>流程 Id(子流程用子图 GraphId)。</summary>
  48. public string FlowId { get; set; }
  49. /// <summary>节点名(DisplayName)。</summary>
  50. public string NodeName { get; set; }
  51. /// <summary>节点显示名(与 NodeName 相同,冗余给 UI 绑定用)。</summary>
  52. public string NodeDisplay => NodeName;
  53. /// <summary>运行批次号(同批次整体替换旧图层;跨批次自动淘汰)。</summary>
  54. public string RunStamp { get; set; }
  55. /// <summary>
  56. /// 发布方推荐的显示图层(节点属性「输出图层」里配置的那一项)。
  57. /// 显示端在"节点级/最新运行"视图下优先显示它;null=用发布方默认(根记录/底图)。
  58. /// </summary>
  59. public string PreferredLayer { get; set; }
  60. /// <summary>本批次图层(顺序 = 叠加顺序;[0] 通常是底图/根记录)。</summary>
  61. public List<LayerItem> Layers { get; } = new List<LayerItem>();
  62. }
  63. /// <summary>
  64. /// 视觉图层发布器契约:节点运行后把自己的渲染图层发布进来;显示端(编辑器大预览窗/主页画面)订阅消费。
  65. /// 三平台(Halcon/Vm/Vpp)共用同一契约,显示控件按 LayerKind + 平台自行解释 Content。
  66. /// </summary>
  67. public interface ILayerPublisher
  68. {
  69. /// <summary>发布一个节点的图层集(整体替换该节点当前批次的图层;后台线程调用安全)。</summary>
  70. void Publish(LayerPublishArgs args);
  71. /// <summary>清除指定流程(或节点,nodeName 为 null 时全流程)的所有图层并释放 owned 对象。</summary>
  72. void Clear(string flowId, string nodeName = null);
  73. }
  74. }