AITRf.xaml.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. using System;
  2. using System.Windows;
  3. using System.Windows.Controls;
  4. using System.Windows.Input;
  5. using System.Windows.Media;
  6. using Aitex.Core.Common.DeviceData;
  7. using Aitex.Core.RT.Log;
  8. using Caliburn.Micro;
  9. using MECF.Framework.Common.OperationCenter;
  10. namespace MECF.Framework.UI.Client.Ctrlib.UnitControls
  11. {
  12. /// <summary>
  13. /// AITRfGenerator.xaml 的交互逻辑
  14. /// </summary>
  15. public partial class AITRf : UserControl
  16. {
  17. public AITRf()
  18. {
  19. InitializeComponent();
  20. }
  21. // define dependency properties
  22. public static readonly DependencyProperty CommandProperty = DependencyProperty.Register(
  23. "Command", typeof(ICommand), typeof(AITRf),
  24. new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.AffectsRender));
  25. public static readonly DependencyProperty DeviceDataProperty = DependencyProperty.Register(
  26. "DeviceData", typeof(AITRfData), typeof(AITRf),
  27. new FrameworkPropertyMetadata(new AITRfData(), FrameworkPropertyMetadataOptions.AffectsRender));
  28. public static readonly DependencyProperty IsMicrowaveModeProperty = DependencyProperty.Register(
  29. "IsMicrowaveMode", typeof(bool), typeof(AITRf),
  30. new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.AffectsRender));
  31. public bool IsMicrowaveMode
  32. {
  33. get
  34. {
  35. return (bool)this.GetValue(IsMicrowaveModeProperty);
  36. }
  37. set
  38. {
  39. this.SetValue(IsMicrowaveModeProperty, value);
  40. }
  41. }
  42. public ICommand Command
  43. {
  44. get
  45. {
  46. return (ICommand)this.GetValue(CommandProperty);
  47. }
  48. set
  49. {
  50. this.SetValue(CommandProperty, value);
  51. }
  52. }
  53. /// <summary>
  54. /// set, get current progress value AnalogDeviceData
  55. /// </summary>
  56. public AITRfData DeviceData
  57. {
  58. get
  59. {
  60. return (AITRfData)this.GetValue(DeviceDataProperty);
  61. }
  62. set
  63. {
  64. this.SetValue(DeviceDataProperty, value);
  65. }
  66. }
  67. protected override void OnRender(DrawingContext drawingContext)
  68. {
  69. base.OnRender(drawingContext);
  70. if (DeviceData != null)
  71. {
  72. if (DeviceData.IsToleranceError)
  73. {
  74. rectFeedback.Stroke = Brushes.OrangeRed;
  75. }else if (DeviceData.IsToleranceWarning)
  76. {
  77. rectFeedback.Stroke = Brushes.Yellow;
  78. }
  79. else
  80. {
  81. rectFeedback.Stroke = Brushes.Gray;
  82. }
  83. if (DeviceData.IsRfAlarm)
  84. {
  85. rectSetPoint.Stroke = Brushes.OrangeRed;
  86. }
  87. else if (!DeviceData.IsInterlockOk)
  88. {
  89. rectSetPoint.Stroke = Brushes.Yellow;
  90. }
  91. else
  92. {
  93. rectSetPoint.Stroke = Brushes.Gray;
  94. }
  95. if (DeviceData.IsRfOn)
  96. {
  97. rectFeedback.Fill = Brushes.HotPink;
  98. }
  99. else
  100. {
  101. rectFeedback.Fill = Brushes.MediumPurple;
  102. }
  103. labelValue.Content = $"{DeviceData.ForwardPower:F1} : {DeviceData.ReflectPower:F1}";
  104. labelSetPoint.Content = $"{DeviceData.PowerSetPoint:F1} {DeviceData.UnitPower}";
  105. if (IsMicrowaveMode)
  106. {
  107. if (_dialogMicrowave != null)
  108. {
  109. _dialogMicrowave.DeviceData = DeviceData;
  110. _dialogMicrowave.DeviceData.InvokePropertyChanged();
  111. _dialogMicrowave.NotifyOfPropertyChange(nameof(_dialogMicrowave.IsEnablePowerOff));
  112. _dialogMicrowave.NotifyOfPropertyChange(nameof(_dialogMicrowave.IsEnablePowerOn));
  113. _dialogMicrowave.NotifyOfPropertyChange(nameof(_dialogMicrowave.IsEnableHeatOff));
  114. _dialogMicrowave.NotifyOfPropertyChange(nameof(_dialogMicrowave.IsEnableHeatOn));
  115. _dialogMicrowave.NotifyOfPropertyChange(nameof(_dialogMicrowave.IsHeatOn));
  116. }
  117. }
  118. else
  119. {
  120. if (_dialogRf != null)
  121. {
  122. _dialogRf.DeviceData = DeviceData;
  123. _dialogRf.DeviceData.InvokePropertyChanged();
  124. _dialogRf.NotifyOfPropertyChange(nameof(_dialogRf.IsEnablePowerOff));
  125. _dialogRf.NotifyOfPropertyChange(nameof(_dialogRf.IsEnablePowerOn));
  126. }
  127. }
  128. }
  129. }
  130. private AITRfSettingDialogViewModel _dialogRf;
  131. private AITMicrowaveSettingDialogViewModel _dialogMicrowave;
  132. private void Grid_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
  133. {
  134. if (DeviceData == null)
  135. return;
  136. if (IsMicrowaveMode)
  137. {
  138. _dialogMicrowave = new AITMicrowaveSettingDialogViewModel($"{DeviceData.DisplayName} Setting");
  139. _dialogMicrowave.DeviceData = DeviceData;
  140. _dialogMicrowave.InputSetPoint = DeviceData.PowerSetPoint.ToString("F1");
  141. WindowManager wm1 = new WindowManager();
  142. Window owner1 = Application.Current.MainWindow;
  143. if (owner1 != null)
  144. {
  145. Mouse.Capture(owner1);
  146. Point pointToWindow = Mouse.GetPosition(owner1);
  147. Point pointToScreen = owner1.PointToScreen(pointToWindow);
  148. pointToScreen.X = pointToScreen.X + 50;
  149. pointToScreen.Y = pointToScreen.Y - 150;
  150. Mouse.Capture(null);
  151. wm1.ShowDialog(_dialogMicrowave, pointToScreen);
  152. }
  153. else
  154. {
  155. wm1.ShowDialog(_dialogMicrowave);
  156. }
  157. return;
  158. }
  159. _dialogRf = new AITRfSettingDialogViewModel($"{DeviceData.DisplayName} Setting");
  160. _dialogRf.DeviceData = DeviceData;
  161. _dialogRf.InputSetPoint = DeviceData.PowerSetPoint.ToString("F1");
  162. WindowManager wm = new WindowManager();
  163. Window owner = Application.Current.MainWindow;
  164. if (owner != null)
  165. {
  166. Mouse.Capture(owner);
  167. Point pointToWindow = Mouse.GetPosition(owner);
  168. Point pointToScreen = owner.PointToScreen(pointToWindow);
  169. pointToScreen.X = pointToScreen.X + 50;
  170. pointToScreen.Y = pointToScreen.Y - 150;
  171. Mouse.Capture(null);
  172. wm.ShowDialog(_dialogRf, pointToScreen);
  173. }
  174. else
  175. {
  176. wm.ShowDialog(_dialogRf);
  177. }
  178. }
  179. private void ExecuteSetMode(RfMode value)
  180. {
  181. if (Command == null)
  182. {
  183. InvokeClient.Instance.Service.DoOperation($"{DeviceData.Module}.{DeviceData.DeviceName}.{AITRfOperation.SetMode}", value.ToString());
  184. return;
  185. }
  186. Command.Execute(new object[] { DeviceData.DeviceName, AITRfOperation.SetMode.ToString(), value.ToString() });
  187. }
  188. private void ExecutePowerOnOff(bool value)
  189. {
  190. if (Command == null)
  191. {
  192. InvokeClient.Instance.Service.DoOperation($"{DeviceData.Module}.{DeviceData.DeviceName}.{AITRfOperation.SetPowerOnOff}", value.ToString());
  193. return;
  194. }
  195. Command.Execute(new object[] { DeviceData.DeviceName, AITRfOperation.SetPowerOnOff.ToString(), value.ToString() });
  196. }
  197. private void ExecuteContinuous(double power)
  198. {
  199. if (Command == null)
  200. {
  201. InvokeClient.Instance.Service.DoOperation($"{DeviceData.Module}.{DeviceData.DeviceName}.{AITRfOperation.SetContinuousPower}", power.ToString());
  202. return;
  203. }
  204. Command.Execute(new object[] { DeviceData.DeviceName, AITRfOperation.SetContinuousPower.ToString(), power.ToString() });
  205. }
  206. private void ExecutePulsing(double power, double frequency, double duty)
  207. {
  208. if (Command == null)
  209. {
  210. InvokeClient.Instance.Service.DoOperation($"{DeviceData.Module}.{DeviceData.DeviceName}.{AITRfOperation.SetPulsingPower}", power.ToString());
  211. return;
  212. }
  213. Command.Execute(new object[] { DeviceData.DeviceName, AITRfOperation.SetPulsingPower.ToString(), power.ToString(), frequency.ToString(), duty.ToString() });
  214. }
  215. private void Grid_MouseEnter(object sender, MouseEventArgs e)
  216. {
  217. if (DeviceData != null)
  218. {
  219. try
  220. {
  221. string tooltipValue =
  222. DeviceData.EnableVoltageCurrent
  223. ? string.Format("{0}:{1}\r\n\r\nID:{2}\r\nForward Power:{3} w\r\nVoltage:{4} \r\nCurrent:{5} \r\nSetPoint:{6} w",
  224. "RF",
  225. DeviceData.DisplayName,
  226. DeviceData.DeviceSchematicId,
  227. DeviceData.ForwardPower.ToString("F1"),
  228. DeviceData.Voltage.ToString("F1"),
  229. DeviceData.Current.ToString("F1"),
  230. DeviceData.PowerSetPoint.ToString("F1"))
  231. : string.Format("{0}:{1}\r\n\r\nID:{2}\r\nForward Power:{3} w\r\nReflect Power:{4} w \r\nSetPoint:{5} w",
  232. "RF",
  233. DeviceData.DisplayName,
  234. DeviceData.DeviceSchematicId,
  235. DeviceData.ForwardPower.ToString("F1"),
  236. DeviceData.ReflectPower.ToString("F1"),
  237. DeviceData.PowerSetPoint.ToString("F1"));
  238. ToolTip = tooltipValue;
  239. }
  240. catch (Exception ex)
  241. {
  242. LOG.Write(ex);
  243. }
  244. }
  245. }
  246. }
  247. }