VmWindow.xaml.cs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. using System;
  2. using System.Windows;
  3. using System.Windows.Controls;
  4. using System.Windows.Media;
  5. using VMControls.Interface; // IVmModule
  6. using VMControls.RenderInterface; // IImageData
  7. namespace Plugins.Vm.Views
  8. {
  9. /// <summary>VM 画面框的显示结果类型(OK/NG/无)。</summary>
  10. public enum VmResultType { Null, OK, NG }
  11. /// <summary>
  12. /// 单个画面框(镜像 VppWindow 的角色):标题、状态圆点、图像区。
  13. /// </summary>
  14. public partial class VmWindow : UserControl
  15. {
  16. public VmWindow()
  17. {
  18. InitializeComponent();
  19. }
  20. public void SetCaption(string caption)
  21. {
  22. if (!Dispatcher.CheckAccess()) { Dispatcher.Invoke(() => SetCaption(caption)); return; }
  23. CaptionText.Text = caption ?? "";
  24. }
  25. public void SetStatusDotVisible(bool visible)
  26. {
  27. if (!Dispatcher.CheckAccess()) { Dispatcher.Invoke(() => SetStatusDotVisible(visible)); return; }
  28. StatusDot.Visibility = visible ? Visibility.Visible : Visibility.Collapsed;
  29. }
  30. public void SetLable(VmResultType type)
  31. {
  32. if (!Dispatcher.CheckAccess()) { Dispatcher.Invoke(() => SetLable(type)); return; }
  33. StatusDot.Visibility = Visibility.Visible;
  34. switch (type)
  35. {
  36. case VmResultType.OK: StatusDot.Fill = new SolidColorBrush(Color.FromRgb(0x4C, 0xAF, 0x50)); break;
  37. case VmResultType.NG: StatusDot.Fill = new SolidColorBrush(Color.FromRgb(0xF4, 0x43, 0x36)); break;
  38. default: StatusDot.Fill = new SolidColorBrush(Color.FromRgb(0x88, 0x88, 0x88)); break;
  39. }
  40. }
  41. /// <summary>
  42. /// 刷新图像:用 VM 渲染控件显示。支持传入 VM 模块(IVmModule)或图像数据(IImageData);
  43. /// TODO:如需显示 TeamAAS 的 GenImage,在此将其转为 VM 的 IImageData。
  44. /// </summary>
  45. public void RefreshImage(object value)
  46. {
  47. if (!Dispatcher.CheckAccess()) { Dispatcher.Invoke(() => RefreshImage(value)); return; }
  48. try
  49. {
  50. if (value is IVmModule module)
  51. Render.ModuleSource = module;
  52. else if (value is IImageData img)
  53. Render.ImageSource = img;
  54. Render.UpdateVMResultShow();
  55. }
  56. catch { /* 渲染失败不影响流程 */ }
  57. }
  58. /// <summary>清空画面显示。</summary>
  59. public void ClearImage()
  60. {
  61. if (!Dispatcher.CheckAccess()) { Dispatcher.Invoke(new Action(ClearImage)); return; }
  62. try { Render.ClearDisplayView(); } catch { }
  63. }
  64. }
  65. }