AITHeaterControl.xaml.cs 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. using System;
  2. using System.Windows;
  3. using System.Windows.Controls;
  4. using System.Windows.Input;
  5. using System.Windows.Media;
  6. using Aitex.Core.Common.DeviceData;
  7. using Aitex.Core.UI.DeviceControl;
  8. using MECF.Framework.Common.OperationCenter;
  9. namespace MECF.Framework.UI.Client.Ctrlib.UnitControls
  10. {
  11. /// <summary>
  12. /// AITHeaterControl.xaml 的交互逻辑
  13. /// </summary>
  14. public partial class AITHeaterControl : UserControl
  15. {
  16. public AITHeaterControl()
  17. {
  18. InitializeComponent();
  19. }
  20. // define dependency properties
  21. public static readonly DependencyProperty CommandProperty = DependencyProperty.Register(
  22. "Command", typeof(ICommand), typeof(AITHeaterControl),
  23. new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.AffectsRender));
  24. public static readonly DependencyProperty DeviceDataProperty = DependencyProperty.Register(
  25. "DeviceData", typeof(AITHeaterData), typeof(AITHeaterControl),
  26. new FrameworkPropertyMetadata(new AITHeaterData(), FrameworkPropertyMetadataOptions.AffectsRender));
  27. public static readonly DependencyProperty BackColorProperty = DependencyProperty.Register(
  28. "BackColor", typeof(Brush), typeof(AITHeaterControl),
  29. new FrameworkPropertyMetadata(Brushes.DarkMagenta, FrameworkPropertyMetadataOptions.AffectsRender));
  30. public static readonly DependencyProperty HideDialogProperty = DependencyProperty.Register(
  31. "HideDialog", typeof(bool), typeof(AITHeaterControl),
  32. new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.AffectsRender));
  33. public static readonly DependencyProperty AlwaysPowerOnProperty = DependencyProperty.Register(
  34. "AlwaysPowerOn", typeof(bool), typeof(AITHeaterControl),
  35. new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.AffectsRender));
  36. public static readonly DependencyProperty FontSizeSettingProperty = DependencyProperty.Register(
  37. "FontSizeSetting", typeof(int), typeof(AITHeaterControl),
  38. new FrameworkPropertyMetadata(13, FrameworkPropertyMetadataOptions.AffectsRender));
  39. public int FontSizeSetting
  40. {
  41. get
  42. {
  43. return (int)this.GetValue(FontSizeSettingProperty);
  44. }
  45. set
  46. {
  47. this.SetValue(FontSizeSettingProperty, value);
  48. }
  49. }
  50. public static readonly DependencyProperty ForegroundSettingProperty = DependencyProperty.Register(
  51. "ForegroundSetting", typeof(string), typeof(AITHeaterControl),
  52. new FrameworkPropertyMetadata("White", FrameworkPropertyMetadataOptions.AffectsRender));
  53. public string ForegroundSetting
  54. {
  55. get
  56. {
  57. return (string)this.GetValue(ForegroundSettingProperty);
  58. }
  59. set
  60. {
  61. this.SetValue(ForegroundSettingProperty, value);
  62. }
  63. }
  64. /// <summary>
  65. /// 输入值是否百分比,默认否
  66. /// </summary>
  67. public bool IsPercent { get; set; }
  68. public ICommand Command
  69. {
  70. get
  71. {
  72. return (ICommand)this.GetValue(CommandProperty);
  73. }
  74. set
  75. {
  76. this.SetValue(CommandProperty, value);
  77. }
  78. }
  79. /// <summary>
  80. /// set, get current progress value AnalogDeviceData
  81. /// </summary>
  82. public AITHeaterData DeviceData
  83. {
  84. get
  85. {
  86. return (AITHeaterData)this.GetValue(DeviceDataProperty);
  87. }
  88. set
  89. {
  90. this.SetValue(DeviceDataProperty, value);
  91. }
  92. }
  93. public Brush BackColor
  94. {
  95. get
  96. {
  97. return (Brush)this.GetValue(BackColorProperty);
  98. }
  99. set
  100. {
  101. this.SetValue(BackColorProperty, value);
  102. }
  103. }
  104. public bool HideDialog
  105. {
  106. get
  107. {
  108. return (bool)this.GetValue(HideDialogProperty);
  109. }
  110. set
  111. {
  112. this.SetValue(HideDialogProperty, value);
  113. }
  114. }
  115. public bool AlwaysPowerOn
  116. {
  117. get
  118. {
  119. return (bool)this.GetValue(AlwaysPowerOnProperty);
  120. }
  121. set
  122. {
  123. this.SetValue(AlwaysPowerOnProperty, value);
  124. }
  125. }
  126. protected override void OnRender(DrawingContext drawingContext)
  127. {
  128. base.OnRender(drawingContext);
  129. //draw background color
  130. if (DeviceData != null)
  131. {
  132. rectBkground.Fill = (DeviceData.IsPowerOn || AlwaysPowerOn) ? Brushes.DarkMagenta : Brushes.Gray;
  133. //draw red board if mfc meets a warning
  134. rectBkground.Stroke = DeviceData.IsWarning ? Brushes.Red : new SolidColorBrush(System.Windows.Media.Color.FromRgb(0X37, 0X37, 0X37));
  135. labelValue.Foreground = DeviceData.IsWarning ? Brushes.Pink : Brushes.LightYellow;
  136. rectBkground.StrokeThickness = DeviceData.IsWarning ? 2 : 1;
  137. if (dialogBox != null)
  138. {
  139. dialogBox.RealValue = DeviceData.FeedBack.ToString("F1");
  140. dialogBox.IsHeaterOn = DeviceData.IsPowerOn;
  141. dialogBox.SetPoint = DeviceData.SetPoint;
  142. }
  143. }
  144. }
  145. private void ExecutePowerOnOff(bool value)
  146. {
  147. if (Command == null)
  148. {
  149. InvokeClient.Instance.Service.DoOperation($"{DeviceData.Module}.{DeviceData.DeviceName}.SetPowerOnOff", value.ToString());
  150. }
  151. else
  152. {
  153. Command.Execute(new object[] { DeviceData.DeviceName, AITHeaterOperation.SetPowerOnOff.ToString(), value.ToString() });
  154. }
  155. }
  156. private void ExecuteSetHeaterValue(double power)
  157. {
  158. if (Command == null)
  159. {
  160. InvokeClient.Instance.Service.DoOperation($"{DeviceData.Module}.{DeviceData.DeviceName}.Ramp",
  161. power.ToString());
  162. }
  163. else
  164. {
  165. Command.Execute(new object[]
  166. {DeviceData.DeviceName, AITHeaterOperation.Ramp.ToString(), power.ToString()});
  167. }
  168. }
  169. private AITHeaterInputDialogBox dialogBox;
  170. public Window AnalogOwner { get; set; }
  171. private void Grid_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
  172. {
  173. if (DeviceData == null)
  174. return;
  175. if (HideDialog)
  176. return;
  177. dialogBox = new AITHeaterInputDialogBox
  178. {
  179. SetHeaterValueCommandDelegate = ExecuteSetHeaterValue,
  180. SetHeaterPowerOnOffCommandDelegate = ExecutePowerOnOff,
  181. DeviceName = DeviceData.DisplayName,
  182. DeviceId = DeviceData.DeviceSchematicId,
  183. DefaultValue = DeviceData.DefaultValue,
  184. RealValue = DeviceData.FeedBack.ToString("F1"),
  185. SetPoint = Math.Round(DeviceData.SetPoint, 1),
  186. MaxValue = DeviceData.Scale,
  187. Unit = DeviceData.Unit,
  188. IsHeaterOn = DeviceData.IsPowerOn,
  189. };
  190. if (AnalogOwner != null)
  191. dialogBox.Owner = AnalogOwner;
  192. dialogBox.Topmost = true;
  193. dialogBox.WindowStartupLocation = WindowStartupLocation.CenterScreen;
  194. dialogBox.FocasAll();
  195. dialogBox.ShowDialog();
  196. dialogBox = null;
  197. }
  198. private void Grid_MouseEnter(object sender, MouseEventArgs e)
  199. {
  200. if (DeviceData != null)
  201. {
  202. string tooltipValue =
  203. string.Format("{0}:{1}\r\n\r\nID:{2}\r\nScale:{3} {4}\r\nSetPoint:{5} {4} \r\nFeedback:{6} {4}\r\nHeaterPower:{7}",
  204. DeviceData.Type,
  205. DeviceData.DisplayName,
  206. DeviceData.DeviceSchematicId,
  207. DeviceData.Scale,
  208. DeviceData.Unit,
  209. DeviceData.SetPoint.ToString("F1"),
  210. DeviceData.FeedBack.ToString("F1"),
  211. DeviceData.IsPowerOn ? "On" : "Off");
  212. ToolTip = tooltipValue;
  213. }
  214. }
  215. }
  216. }