AITRfGenerator.xaml.cs 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  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.UI.Control;
  16. using Aitex.Platform;
  17. namespace Aitex.Core.UI.DeviceControl
  18. {
  19. /// <summary>
  20. /// AITRfGenerator.xaml 的交互逻辑
  21. /// </summary>
  22. public partial class AITRfGenerator : UserControl
  23. {
  24. public AITRfGenerator()
  25. {
  26. InitializeComponent();
  27. }
  28. // define dependency properties
  29. public static readonly DependencyProperty CommandProperty = DependencyProperty.Register(
  30. "Command", typeof(ICommand), typeof(AITRfGenerator),
  31. new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.AffectsRender));
  32. public static readonly DependencyProperty DeviceDataProperty = DependencyProperty.Register(
  33. "DeviceData", typeof(AITRfData), typeof(AITRfGenerator),
  34. new FrameworkPropertyMetadata(new AITRfData(), FrameworkPropertyMetadataOptions.AffectsRender));
  35. public ICommand Command
  36. {
  37. get
  38. {
  39. return (ICommand)this.GetValue(CommandProperty);
  40. }
  41. set
  42. {
  43. this.SetValue(CommandProperty, value);
  44. }
  45. }
  46. /// <summary>
  47. /// set, get current progress value AnalogDeviceData
  48. /// </summary>
  49. public AITRfData DeviceData
  50. {
  51. get
  52. {
  53. return (AITRfData)this.GetValue(DeviceDataProperty);
  54. }
  55. set
  56. {
  57. this.SetValue(DeviceDataProperty, value);
  58. }
  59. }
  60. protected override void OnRender(DrawingContext drawingContext)
  61. {
  62. base.OnRender(drawingContext);
  63. if (DeviceData != null)
  64. {
  65. //draw red board if meets a warning
  66. rectBkground.Stroke = !DeviceData.IsInterlockOk ? Brushes.Red : Brushes.Gray;
  67. //labelValue.Foreground = !DeviceData.IsInterlockOK ? Brushes.Pink : Brushes.MidnightBlue;
  68. rectBkground.StrokeThickness = !DeviceData.IsInterlockOk ? 2 : 1;
  69. if (dialogBox != null)
  70. {
  71. dialogBox.ForwardPower = DeviceData.ForwardPower ;
  72. dialogBox.ReflectPower = DeviceData.ReflectPower ;
  73. dialogBox.IsRfOn = DeviceData.IsRfOn;
  74. dialogBox.SetPointPower = DeviceData.PowerSetPoint;
  75. dialogBox.IsContinuousMode = DeviceData.WorkMode == (int) RfMode.ContinuousWaveMode;
  76. dialogBox.IsPulsingMode = DeviceData.WorkMode == (int) RfMode.PulsingMode;
  77. dialogBox.Voltage = DeviceData.Voltage;
  78. dialogBox.Current = DeviceData.Current;
  79. }
  80. 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);
  81. if (DeviceData.EnableVoltageCurrent)
  82. {
  83. labelValue.Content = string.Format("{0}/{1}/{2}", DeviceData.ForwardPower.ToString("F0"), DeviceData.Voltage.ToString("F0"), DeviceData.Current.ToString("F0"));
  84. }
  85. else
  86. {
  87. labelValue.Content = string.Format("{0} : {1}", DeviceData.ForwardPower.ToString("F1"), DeviceData.ReflectPower.ToString("F1"));
  88. }
  89. }
  90. }
  91. private AITRfInputDialogBox dialogBox;
  92. public Window AnalogOwner { get; set; }
  93. private void Grid_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
  94. {
  95. if (DeviceData == null)
  96. return;
  97. dialogBox = new AITRfInputDialogBox
  98. {
  99. SetRfModeCommandDelegate = ExecuteSetMode,
  100. SetContinuousCommandDelegate = ExecuteContinuous,
  101. SetPulsingCommandDelegate = ExecutePulsing,
  102. SetRfPowerOnOffCommandDelegate = ExecutePowerOnOff,
  103. DeviceName = DeviceData.DisplayName,
  104. DeviceId = DeviceData.DeviceSchematicId,
  105. ForwardPower = DeviceData.ForwardPower,
  106. ReflectPower = DeviceData.ReflectPower,
  107. IsRfOn = DeviceData.IsRfOn,
  108. Voltage = DeviceData.Voltage,
  109. Current = DeviceData.Current,
  110. SetPointPower = Math.Round(DeviceData.PowerSetPoint, 1),
  111. MaxValuePower = DeviceData.ScalePower,
  112. UnitPower = DeviceData.UnitPower,
  113. SetPointFrequency = Math.Round(DeviceData.FrequencySetPoint, 1),
  114. MaxValueFrequency = DeviceData.ScaleFrequency,
  115. UnitFrequency = DeviceData.UnitFrequency,
  116. SetPointDuty = Math.Round(DeviceData.DutySetPoint, 1),
  117. MaxValueDuty = DeviceData.ScaleDuty,
  118. UnitDuty = DeviceData.UnitDuty,
  119. IsContinuousMode = DeviceData.WorkMode == (int)RfMode.ContinuousWaveMode,
  120. IsPulsingMode = DeviceData.WorkMode==(int)RfMode.PulsingMode,
  121. EnablePulsing = DeviceData.EnablePulsing,
  122. GridLengthReflect = DeviceData.EnableReflectPower ? GridLength.Auto : new GridLength(0),
  123. GridLengthVoltageCurrent = DeviceData.EnableVoltageCurrent ? GridLength.Auto : new GridLength(0)
  124. };
  125. if (AnalogOwner != null)
  126. dialogBox.Owner = AnalogOwner;
  127. dialogBox.Topmost = true;
  128. dialogBox.WindowStartupLocation = WindowStartupLocation.CenterScreen;
  129. dialogBox.FocasAll();
  130. dialogBox.ShowDialog();
  131. dialogBox = null;
  132. }
  133. private void ExecuteSetMode(RfMode value)
  134. {
  135. Command.Execute(new object[] { DeviceData.DeviceName, AITRfOperation.SetMode.ToString(), value.ToString() });
  136. }
  137. private void ExecutePowerOnOff(bool value)
  138. {
  139. Command.Execute(new object[] { DeviceData.DeviceName, AITRfOperation.SetPowerOnOff.ToString(), value.ToString() });
  140. }
  141. private void ExecuteContinuous(double power)
  142. {
  143. Command.Execute(new object[] { DeviceData.DeviceName, AITRfOperation.SetContinuousPower.ToString(), power.ToString() });
  144. }
  145. private void ExecutePulsing(double power, double frequency, double duty)
  146. {
  147. Command.Execute(new object[] { DeviceData.DeviceName, AITRfOperation.SetPulsingPower.ToString(), power.ToString(), frequency.ToString(), duty.ToString() });
  148. }
  149. private void Grid_MouseEnter(object sender, MouseEventArgs e)
  150. {
  151. if (DeviceData != null)
  152. {
  153. string tooltipValue =
  154. DeviceData.EnableVoltageCurrent
  155. ? string.Format(Application.Current.Resources["GlobalLableRfGeneratorToolTipVoltage"].ToString(),
  156. "RF",
  157. DeviceData.DisplayName,
  158. DeviceData.DeviceSchematicId,
  159. DeviceData.ForwardPower.ToString("F1"),
  160. DeviceData.Voltage.ToString("F1"),
  161. DeviceData.Current.ToString("F1"),
  162. DeviceData.PowerSetPoint.ToString("F1"))
  163. : string.Format(Application.Current.Resources["GlobalLableRfGeneratorToolTipReflect"].ToString(),
  164. "RF",
  165. DeviceData.DisplayName,
  166. DeviceData.DeviceSchematicId,
  167. DeviceData.ForwardPower.ToString("F1"),
  168. DeviceData.ReflectPower.ToString("F1"),
  169. DeviceData.PowerSetPoint.ToString("F1"));
  170. ToolTip = tooltipValue;
  171. }
  172. }
  173. }
  174. }