using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using VMControls.Interface; // IVmModule
using VMControls.RenderInterface; // IImageData
namespace Plugins.Vm.Views
{
/// VM 画面框的显示结果类型(OK/NG/无)。
public enum VmResultType { Null, OK, NG }
///
/// 单个画面框(镜像 VppWindow 的角色):标题、状态圆点、图像区。
///
public partial class VmWindow : UserControl
{
public VmWindow()
{
InitializeComponent();
}
public void SetCaption(string caption)
{
if (!Dispatcher.CheckAccess()) { Dispatcher.Invoke(() => SetCaption(caption)); return; }
CaptionText.Text = caption ?? "";
}
public void SetStatusDotVisible(bool visible)
{
if (!Dispatcher.CheckAccess()) { Dispatcher.Invoke(() => SetStatusDotVisible(visible)); return; }
StatusDot.Visibility = visible ? Visibility.Visible : Visibility.Collapsed;
}
public void SetLable(VmResultType type)
{
if (!Dispatcher.CheckAccess()) { Dispatcher.Invoke(() => SetLable(type)); return; }
StatusDot.Visibility = Visibility.Visible;
switch (type)
{
case VmResultType.OK: StatusDot.Fill = new SolidColorBrush(Color.FromRgb(0x4C, 0xAF, 0x50)); break;
case VmResultType.NG: StatusDot.Fill = new SolidColorBrush(Color.FromRgb(0xF4, 0x43, 0x36)); break;
default: StatusDot.Fill = new SolidColorBrush(Color.FromRgb(0x88, 0x88, 0x88)); break;
}
}
///
/// 刷新图像:用 VM 渲染控件显示。支持传入 VM 模块(IVmModule)或图像数据(IImageData);
/// TODO:如需显示 TeamAAS 的 GenImage,在此将其转为 VM 的 IImageData。
///
public void RefreshImage(object value)
{
if (!Dispatcher.CheckAccess()) { Dispatcher.Invoke(() => RefreshImage(value)); return; }
try
{
if (value is IVmModule module)
Render.ModuleSource = module;
else if (value is IImageData img)
Render.ImageSource = img;
Render.UpdateVMResultShow();
}
catch { /* 渲染失败不影响流程 */ }
}
/// 清空画面显示。
public void ClearImage()
{
if (!Dispatcher.CheckAccess()) { Dispatcher.Invoke(new Action(ClearImage)); return; }
try { Render.ClearDisplayView(); } catch { }
}
}
}