AITRfGenerator.xaml.cs 10.0 KB

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