MfcControl.xaml.cs 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. using System.Windows;
  2. using System.Windows.Controls;
  3. using System.Windows.Input;
  4. using System.Windows.Media;
  5. using Aitex.Core.Common.DeviceData;
  6. using Caliburn.Micro;
  7. namespace MECF.Framework.UI.Client.Ctrlib.UnitControls
  8. {
  9. /// <summary>
  10. /// Interaction logic for AnalogControl.xaml
  11. /// </summary>
  12. public partial class MfcControl : UserControl
  13. {
  14. public MfcControl()
  15. {
  16. InitializeComponent();
  17. }
  18. // define dependency properties
  19. public static readonly DependencyProperty CommandProperty = DependencyProperty.Register(
  20. "Command", typeof(ICommand), typeof(MfcControl),
  21. new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.AffectsRender));
  22. public static readonly DependencyProperty DeviceDataProperty = DependencyProperty.Register(
  23. "DeviceData", typeof(AITMfcData), typeof(MfcControl),
  24. new FrameworkPropertyMetadata(new AITMfcData(), FrameworkPropertyMetadataOptions.AffectsRender,
  25. new PropertyChangedCallback(OnDeviceDataChanged)));
  26. public static readonly DependencyProperty BackColorProperty = DependencyProperty.Register(
  27. "BackColor", typeof(Brush), typeof(MfcControl),
  28. new FrameworkPropertyMetadata(Brushes.Green, FrameworkPropertyMetadataOptions.AffectsRender));
  29. public static readonly DependencyProperty HideDialogProperty = DependencyProperty.Register(
  30. "HideDialog", typeof(bool), typeof(MfcControl),
  31. new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.AffectsRender));
  32. private static void OnDeviceDataChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
  33. {
  34. }
  35. public ICommand Command
  36. {
  37. get
  38. {
  39. return (ICommand)this.GetValue(CommandProperty);
  40. }
  41. set
  42. {
  43. this.SetValue(CommandProperty, value);
  44. }
  45. }
  46. /// <summary>
  47. /// set, get current progress value AnalogDeviceData
  48. /// </summary>
  49. public AITMfcData DeviceData
  50. {
  51. get
  52. {
  53. return (AITMfcData)this.GetValue(DeviceDataProperty);
  54. }
  55. set
  56. {
  57. this.SetValue(DeviceDataProperty, value);
  58. }
  59. }
  60. public Brush BackColor
  61. {
  62. get
  63. {
  64. return (Brush)this.GetValue(BackColorProperty);
  65. }
  66. set
  67. {
  68. this.SetValue(BackColorProperty, value);
  69. }
  70. }
  71. public bool HideDialog
  72. {
  73. get
  74. {
  75. return (bool)this.GetValue(HideDialogProperty);
  76. }
  77. set
  78. {
  79. this.SetValue(HideDialogProperty, value);
  80. }
  81. }
  82. //
  83. /// <summary>
  84. /// MFC 控件的显示逻辑:
  85. ///
  86. /// 下面:设定值SetPoint
  87. ///
  88. /// </summary>
  89. /// <param name="drawingContext"></param>
  90. protected override void OnRender(DrawingContext drawingContext)
  91. {
  92. base.OnRender(drawingContext);
  93. //draw background color
  94. rectBkground.Fill = BackColor;
  95. if (DeviceData != null)
  96. {
  97. rectBkground.Stroke = DeviceData.IsError ? Brushes.Red : (DeviceData.IsWarning ? Brushes.Yellow : Brushes.DimGray);
  98. labelValue.Content = DeviceData.FeedBack.ToString("F1");
  99. if (_dialog != null)
  100. {
  101. _dialog.DeviceData = DeviceData;
  102. _dialog.DeviceData.InvokePropertyChanged();
  103. }
  104. labelSetPoint.Content = DeviceData.SetPoint.ToString("F1");
  105. }
  106. }
  107. private MfcSettingDialogViewModel _dialog;
  108. private void Grid_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
  109. {
  110. if (DeviceData == null)
  111. return;
  112. if (HideDialog)
  113. return;
  114. _dialog = new MfcSettingDialogViewModel($"MFC {DeviceData.DisplayName} Setting");
  115. _dialog.DeviceData = DeviceData;
  116. _dialog.InputSetPoint = DeviceData.SetPoint.ToString("F1");
  117. WindowManager wm = new WindowManager();
  118. Window owner = Application.Current.MainWindow;
  119. if (owner != null)
  120. {
  121. Mouse.Capture(owner);
  122. Point pointToWindow = Mouse.GetPosition(owner);
  123. Point pointToScreen = owner.PointToScreen(pointToWindow);
  124. pointToScreen.X = pointToScreen.X + 50;
  125. pointToScreen.Y = pointToScreen.Y - 150;
  126. Mouse.Capture(null);
  127. wm.ShowDialog(_dialog, pointToScreen);
  128. }
  129. else
  130. {
  131. wm.ShowDialog(_dialog);
  132. }
  133. }
  134. private void Grid_MouseEnter(object sender, MouseEventArgs e)
  135. {
  136. if (DeviceData != null)
  137. {
  138. string tooltipValue =
  139. $"{DeviceData.Type}:{DeviceData.DisplayName}\r\n\r\nID:{DeviceData.DeviceSchematicId}\r\nScale:{DeviceData.Scale} {DeviceData.Unit}\r\nSetPoint:{DeviceData.SetPoint} {DeviceData.Unit} \r\nFeedback:{DeviceData.FeedBack} {DeviceData.Unit}";
  140. ToolTip = tooltipValue;
  141. }
  142. }
  143. }
  144. }