AITRf.xaml.cs 9.7 KB

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