AITHeaterControl.xaml.cs 7.2 KB

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