AITRfGenerator.xaml.cs 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  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 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. }
  91. }
  92. private AITRfInputDialogBox dialogBox;
  93. public Window AnalogOwner { get; set; }
  94. private void Grid_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
  95. {
  96. if (DeviceData == null)
  97. return;
  98. dialogBox = new AITRfInputDialogBox
  99. {
  100. SetRfModeCommandDelegate = ExecuteSetMode,
  101. SetContinuousCommandDelegate = ExecuteContinuous,
  102. SetPulsingCommandDelegate = ExecutePulsing,
  103. SetRfPowerOnOffCommandDelegate = ExecutePowerOnOff,
  104. DeviceName = DeviceData.DisplayName,
  105. DeviceId = DeviceData.DeviceSchematicId,
  106. ForwardPower = DeviceData.ForwardPower,
  107. ReflectPower = DeviceData.ReflectPower,
  108. IsRfOn = DeviceData.IsRfOn,
  109. Voltage = DeviceData.Voltage,
  110. Current = DeviceData.Current,
  111. SetPointPower = Math.Round(DeviceData.PowerSetPoint, 1),
  112. MaxValuePower = DeviceData.ScalePower,
  113. UnitPower = DeviceData.UnitPower,
  114. SetPointFrequency = Math.Round(DeviceData.FrequencySetPoint, 1),
  115. MaxValueFrequency = DeviceData.ScaleFrequency,
  116. UnitFrequency = DeviceData.UnitFrequency,
  117. SetPointDuty = Math.Round(DeviceData.DutySetPoint, 1),
  118. MaxValueDuty = DeviceData.ScaleDuty,
  119. UnitDuty = DeviceData.UnitDuty,
  120. IsContinuousMode = DeviceData.WorkMode == (int)RfMode.ContinuousWaveMode,
  121. IsPulsingMode = DeviceData.WorkMode==(int)RfMode.PulsingMode,
  122. EnablePulsing = DeviceData.EnablePulsing,
  123. GridLengthReflect = DeviceData.EnableReflectPower ? GridLength.Auto : new GridLength(0),
  124. GridLengthVoltageCurrent = DeviceData.EnableVoltageCurrent ? GridLength.Auto : new GridLength(0),
  125. GridLengthWorkMode = DeviceData.EnablePulsing ? GridLength.Auto : new GridLength(0),
  126. };
  127. if (AnalogOwner != null)
  128. dialogBox.Owner = AnalogOwner;
  129. dialogBox.Topmost = true;
  130. dialogBox.WindowStartupLocation = WindowStartupLocation.CenterScreen;
  131. dialogBox.FocasAll();
  132. dialogBox.ShowDialog();
  133. dialogBox = null;
  134. }
  135. private void ExecuteSetMode(RfMode value)
  136. {
  137. if (Command == null)
  138. {
  139. InvokeClient.Instance.Service.DoOperation($"{DeviceData.Module}.{DeviceData.DeviceName}.{AITRfOperation.SetMode}", value.ToString());
  140. return;
  141. }
  142. Command.Execute(new object[] { DeviceData.DeviceName, AITRfOperation.SetMode.ToString(), value.ToString() });
  143. }
  144. private void ExecutePowerOnOff(bool value)
  145. {
  146. if (Command == null)
  147. {
  148. InvokeClient.Instance.Service.DoOperation($"{DeviceData.Module}.{DeviceData.DeviceName}.{AITRfOperation.SetPowerOnOff}", value.ToString());
  149. return;
  150. }
  151. Command.Execute(new object[] { DeviceData.DeviceName, AITRfOperation.SetPowerOnOff.ToString(), value.ToString() });
  152. }
  153. private void ExecuteContinuous(double power)
  154. {
  155. if (Command == null)
  156. {
  157. InvokeClient.Instance.Service.DoOperation($"{DeviceData.Module}.{DeviceData.DeviceName}.{AITRfOperation.SetContinuousPower}", power.ToString());
  158. return;
  159. }
  160. Command.Execute(new object[] { DeviceData.DeviceName, AITRfOperation.SetContinuousPower.ToString(), power.ToString() });
  161. }
  162. private void ExecutePulsing(double power, double frequency, double duty)
  163. {
  164. if (Command == null)
  165. {
  166. InvokeClient.Instance.Service.DoOperation($"{DeviceData.Module}.{DeviceData.DeviceName}.{AITRfOperation.SetPulsingPower}", power.ToString());
  167. return;
  168. }
  169. Command.Execute(new object[] { DeviceData.DeviceName, AITRfOperation.SetPulsingPower.ToString(), power.ToString(), frequency.ToString(), duty.ToString() });
  170. }
  171. private void Grid_MouseEnter(object sender, MouseEventArgs e)
  172. {
  173. if (DeviceData != null)
  174. {
  175. try
  176. {
  177. string tooltipValue =
  178. DeviceData.EnableVoltageCurrent
  179. ? string.Format("{0}:{1}\r\n\r\nID:{2}\r\nForward Power:{3} w\r\nVoltage:{4} \r\nCurrent:{5} \r\nSetPoint:{6} w",
  180. "RF",
  181. DeviceData.DisplayName,
  182. DeviceData.DeviceSchematicId,
  183. DeviceData.ForwardPower.ToString("F1"),
  184. DeviceData.Voltage.ToString("F1"),
  185. DeviceData.Current.ToString("F1"),
  186. DeviceData.PowerSetPoint.ToString("F1"))
  187. : string.Format("{0}:{1}\r\n\r\nID:{2}\r\nForward Power:{3} w\r\nReflect Power:{4} w \r\nSetPoint:{5} w",
  188. "RF",
  189. DeviceData.DisplayName,
  190. DeviceData.DeviceSchematicId,
  191. DeviceData.ForwardPower.ToString("F1"),
  192. DeviceData.ReflectPower.ToString("F1"),
  193. DeviceData.PowerSetPoint.ToString("F1"));
  194. ToolTip = tooltipValue;
  195. }
  196. catch (Exception ex)
  197. {
  198. LOG.Write(ex);
  199. }
  200. }
  201. }
  202. }
  203. }