AITRfGenerator.xaml.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  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.RT.Log;
  16. using Aitex.Core.UI.Control;
  17. using MECF.Framework.Common.OperationCenter;
  18. namespace Aitex.Core.UI.DeviceControl
  19. {
  20. /// <summary>
  21. /// AITRfGenerator.xaml 的交互逻辑
  22. /// </summary>
  23. public partial class AITRfGenerator : UserControl
  24. {
  25. public AITRfGenerator()
  26. {
  27. InitializeComponent();
  28. }
  29. // define dependency properties
  30. public static readonly DependencyProperty CommandProperty = DependencyProperty.Register(
  31. "Command", typeof(ICommand), typeof(AITRfGenerator),
  32. new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.AffectsRender));
  33. public static readonly DependencyProperty DeviceDataProperty = DependencyProperty.Register(
  34. "DeviceData", typeof(AITRfData), typeof(AITRfGenerator),
  35. new FrameworkPropertyMetadata(new AITRfData(), FrameworkPropertyMetadataOptions.AffectsRender));
  36. public static readonly DependencyProperty IsAutoModeProperty = DependencyProperty.Register(
  37. "IsAutoMode", typeof(bool), typeof(AITRfGenerator),
  38. new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.AffectsRender));
  39. public ICommand Command
  40. {
  41. get
  42. {
  43. return (ICommand)this.GetValue(CommandProperty);
  44. }
  45. set
  46. {
  47. this.SetValue(CommandProperty, value);
  48. }
  49. }
  50. public bool IsAutoMode
  51. {
  52. get
  53. {
  54. return (bool)this.GetValue(IsAutoModeProperty);
  55. }
  56. set
  57. {
  58. this.SetValue(IsAutoModeProperty, value);
  59. }
  60. }
  61. /// <summary>
  62. /// set, get current progress value AnalogDeviceData
  63. /// </summary>
  64. public AITRfData DeviceData
  65. {
  66. get
  67. {
  68. return (AITRfData)this.GetValue(DeviceDataProperty);
  69. }
  70. set
  71. {
  72. this.SetValue(DeviceDataProperty, value);
  73. }
  74. }
  75. protected override void OnRender(DrawingContext drawingContext)
  76. {
  77. base.OnRender(drawingContext);
  78. if (DeviceData != null)
  79. {
  80. //draw red board if meets a warning
  81. rectBkground.Stroke = !DeviceData.IsInterlockOk ? Brushes.Red : Brushes.Gray;
  82. //labelValue.Foreground = !DeviceData.IsInterlockOK ? Brushes.Pink : Brushes.MidnightBlue;
  83. rectBkground.StrokeThickness = !DeviceData.IsInterlockOk ? 2 : 1;
  84. if (dialogBox != null)
  85. {
  86. dialogBox.ForwardPower = DeviceData.ForwardPower ;
  87. dialogBox.ReflectPower = DeviceData.ReflectPower ;
  88. dialogBox.IsRfOn = DeviceData.IsRfOn;
  89. dialogBox.SetPointPower = DeviceData.PowerSetPoint;
  90. dialogBox.IsContinuousMode = DeviceData.WorkMode == (int) RfMode.ContinuousWaveMode;
  91. dialogBox.IsPulsingMode = DeviceData.WorkMode == (int) RfMode.PulsingMode;
  92. dialogBox.Voltage = DeviceData.Voltage;
  93. dialogBox.Current = DeviceData.Current;
  94. }
  95. rectBkground.Fill = DeviceData.IsRfOn ? new SolidColorBrush(System.Windows.Media.Color.FromRgb(0xF1, 0xA2, 0xE4)) : (DeviceData.IsInterlockOk ? new SolidColorBrush(System.Windows.Media.Color.FromRgb(0xD2, 0xD3, 0xD7)) : Brushes.Red);
  96. if (DeviceData.EnableVoltageCurrent)
  97. {
  98. labelValue.Content = string.Format("{0}/{1}/{2}", DeviceData.ForwardPower.ToString("F0"), DeviceData.Voltage.ToString("F0"), DeviceData.Current.ToString("F0"));
  99. }
  100. else
  101. {
  102. labelValue.Content = string.Format("{0} : {1}", DeviceData.ForwardPower.ToString("F1"), DeviceData.ReflectPower.ToString("F1"));
  103. }
  104. }
  105. }
  106. private AITRfInputDialogBox dialogBox;
  107. public Window AnalogOwner { get; set; }
  108. private void Grid_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
  109. {
  110. if (IsAutoMode) return;
  111. if (DeviceData == null)
  112. return;
  113. dialogBox = new AITRfInputDialogBox
  114. {
  115. SetRfModeCommandDelegate = ExecuteSetMode,
  116. SetContinuousCommandDelegate = ExecuteContinuous,
  117. SetPulsingCommandDelegate = ExecutePulsing,
  118. SetRfPowerOnOffCommandDelegate = ExecutePowerOnOff,
  119. DeviceName = DeviceData.DisplayName,
  120. DeviceId = DeviceData.DeviceSchematicId,
  121. ForwardPower = DeviceData.ForwardPower,
  122. ReflectPower = DeviceData.ReflectPower,
  123. IsRfOn = DeviceData.IsRfOn,
  124. Voltage = DeviceData.Voltage,
  125. Current = DeviceData.Current,
  126. SetPointPower = Math.Round(DeviceData.PowerSetPoint, 1),
  127. MaxValuePower = DeviceData.ScalePower,
  128. UnitPower = DeviceData.UnitPower,
  129. SetPointFrequency = Math.Round(DeviceData.FrequencySetPoint, 1),
  130. MaxValueFrequency = DeviceData.ScaleFrequency,
  131. UnitFrequency = DeviceData.UnitFrequency,
  132. SetPointDuty = Math.Round(DeviceData.DutySetPoint, 1),
  133. MaxValueDuty = DeviceData.ScaleDuty,
  134. UnitDuty = DeviceData.UnitDuty,
  135. IsContinuousMode = DeviceData.WorkMode == (int)RfMode.ContinuousWaveMode,
  136. IsPulsingMode = DeviceData.WorkMode==(int)RfMode.PulsingMode,
  137. EnablePulsing = DeviceData.EnablePulsing,
  138. GridLengthReflect = DeviceData.EnableReflectPower ? GridLength.Auto : new GridLength(0),
  139. GridLengthVoltageCurrent = DeviceData.EnableVoltageCurrent ? GridLength.Auto : new GridLength(0)
  140. };
  141. if (AnalogOwner != null)
  142. dialogBox.Owner = AnalogOwner;
  143. dialogBox.Topmost = true;
  144. dialogBox.WindowStartupLocation = WindowStartupLocation.CenterScreen;
  145. dialogBox.FocasAll();
  146. dialogBox.ShowDialog();
  147. dialogBox = null;
  148. }
  149. private void ExecuteSetMode(RfMode value)
  150. {
  151. if (Command == null)
  152. {
  153. InvokeClient.Instance.Service.DoOperation($"{DeviceData.Module}.{DeviceData.DeviceName}.{AITRfOperation.SetMode}", value.ToString());
  154. return;
  155. }
  156. Command.Execute(new object[] { DeviceData.DeviceName, AITRfOperation.SetMode.ToString(), value.ToString() });
  157. }
  158. private void ExecutePowerOnOff(bool value)
  159. {
  160. if (Command == null)
  161. {
  162. InvokeClient.Instance.Service.DoOperation($"{DeviceData.Module}.{DeviceData.DeviceName}.{AITRfOperation.SetPowerOnOff}", value.ToString());
  163. return;
  164. }
  165. Command.Execute(new object[] { DeviceData.DeviceName, AITRfOperation.SetPowerOnOff.ToString(), value.ToString() });
  166. }
  167. private void ExecuteContinuous(double power)
  168. {
  169. if (Command == null)
  170. {
  171. InvokeClient.Instance.Service.DoOperation($"{DeviceData.Module}.{DeviceData.DeviceName}.{AITRfOperation.SetContinuousPower}", power.ToString());
  172. return;
  173. }
  174. Command.Execute(new object[] { DeviceData.DeviceName, AITRfOperation.SetContinuousPower.ToString(), power.ToString() });
  175. }
  176. private void ExecutePulsing(double power, double frequency, double duty)
  177. {
  178. if (Command == null)
  179. {
  180. InvokeClient.Instance.Service.DoOperation($"{DeviceData.Module}.{DeviceData.DeviceName}.{AITRfOperation.SetPulsingPower}", power.ToString());
  181. return;
  182. }
  183. Command.Execute(new object[] { DeviceData.DeviceName, AITRfOperation.SetPulsingPower.ToString(), power.ToString(), frequency.ToString(), duty.ToString() });
  184. }
  185. private void Grid_MouseEnter(object sender, MouseEventArgs e)
  186. {
  187. if (DeviceData != null)
  188. {
  189. try
  190. {
  191. string tooltipValue =
  192. DeviceData.EnableVoltageCurrent
  193. ? string.Format("{0}:{1}\r\n\r\nID:{2}\r\nForward Power:{3} w\r\nVoltage:{4} \r\nCurrent:{5} \r\nSetPoint:{6} w",
  194. "RF",
  195. DeviceData.DisplayName,
  196. DeviceData.DeviceSchematicId,
  197. DeviceData.ForwardPower.ToString("F1"),
  198. DeviceData.Voltage.ToString("F1"),
  199. DeviceData.Current.ToString("F1"),
  200. DeviceData.PowerSetPoint.ToString("F1"))
  201. : string.Format("{0}:{1}\r\n\r\nID:{2}\r\nForward Power:{3} w\r\nReflect Power:{4} w \r\nSetPoint:{5} w",
  202. "RF",
  203. DeviceData.DisplayName,
  204. DeviceData.DeviceSchematicId,
  205. DeviceData.ForwardPower.ToString("F1"),
  206. DeviceData.ReflectPower.ToString("F1"),
  207. DeviceData.PowerSetPoint.ToString("F1"));
  208. ToolTip = tooltipValue;
  209. }
  210. catch (Exception ex)
  211. {
  212. LOG.Write(ex);
  213. }
  214. }
  215. }
  216. }
  217. }