AITThrottleValve2.xaml.cs 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  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 MECF.Framework.Common.OperationCenter;
  17. namespace Aitex.Core.UI.DeviceControl
  18. {
  19. /// <summary>
  20. /// AITThrottleValve.xaml 的交互逻辑
  21. /// </summary>
  22. public partial class AITThrottleValve2 : UserControl
  23. {
  24. public AITThrottleValve2()
  25. {
  26. InitializeComponent();
  27. }
  28. // define dependency properties
  29. public static readonly DependencyProperty CommandProperty = DependencyProperty.Register(
  30. "Command", typeof(ICommand), typeof(AITThrottleValve2),
  31. new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.AffectsRender));
  32. public static readonly DependencyProperty DeviceDataProperty = DependencyProperty.Register(
  33. "DeviceData", typeof(AITThrottleValveData), typeof(AITThrottleValve2),
  34. new FrameworkPropertyMetadata(new AITThrottleValveData(), 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 AITThrottleValveData DeviceData
  50. {
  51. get
  52. {
  53. return (AITThrottleValveData)this.GetValue(DeviceDataProperty);
  54. }
  55. set
  56. {
  57. this.SetValue(DeviceDataProperty, value);
  58. }
  59. }
  60. public static readonly DependencyProperty PressureStringFormatProperty = DependencyProperty.Register(
  61. "PressureStringFormat", typeof(string), typeof(AITThrottleValve2),
  62. new FrameworkPropertyMetadata("F1", FrameworkPropertyMetadataOptions.AffectsRender));
  63. public string PressureStringFormat
  64. {
  65. get
  66. {
  67. return (string)this.GetValue(PressureStringFormatProperty);
  68. }
  69. set
  70. {
  71. this.SetValue(PressureStringFormatProperty, value);
  72. }
  73. }
  74. public static readonly DependencyProperty PositionStringFormatProperty = DependencyProperty.Register(
  75. "PositionStringFormat", typeof(string), typeof(AITThrottleValve2),
  76. new FrameworkPropertyMetadata("F1", FrameworkPropertyMetadataOptions.AffectsRender));
  77. public string PositionStringFormat
  78. {
  79. get
  80. {
  81. return (string)this.GetValue(PositionStringFormatProperty);
  82. }
  83. set
  84. {
  85. this.SetValue(PositionStringFormatProperty, value);
  86. }
  87. }
  88. private AITThrottleValveInputDialogBox _dialogBox;
  89. public Window AnalogOwner { get; set; }
  90. protected override void OnRender(DrawingContext drawingContext)
  91. {
  92. base.OnRender(drawingContext);
  93. if (DeviceData != null)
  94. {
  95. if (DeviceData.Mode == (int)PressureCtrlMode.TVPressureCtrl)
  96. {
  97. rotateTransform.Angle = DeviceData.PressureFeedback * 90.0 / DeviceData.MaxValuePressure;
  98. }
  99. else if (DeviceData.Mode == (int)PressureCtrlMode.TVPositionCtrl)
  100. {
  101. rotateTransform.Angle = DeviceData.PositionFeedback * 90.0 / DeviceData.MaxValuePosition;
  102. }
  103. PositionValue.Content = DeviceData.PositionFeedback.ToString(PositionStringFormat);
  104. PositionUnit.Content = !string.IsNullOrEmpty(DeviceData.UnitPosition) ? DeviceData.UnitPosition : "%"; ;
  105. PressureValue.Content = DeviceData.PressureFeedback.ToString(PressureStringFormat);
  106. PressureUnit.Content = !string.IsNullOrEmpty(DeviceData.UnitPressure) ? DeviceData.UnitPressure : "mTorr";
  107. if (_dialogBox != null)
  108. {
  109. _dialogBox.IsPositionMode = DeviceData.Mode == (int)PressureCtrlMode.TVPositionCtrl;
  110. _dialogBox.IsPressureMode = DeviceData.Mode == (int)PressureCtrlMode.TVPressureCtrl;
  111. //_dialogBox.SetPointPosition = DeviceData.PositionSetPoint;
  112. //_dialogBox.SetPointPressure = DeviceData.PressureSetPoint;
  113. }
  114. }
  115. }
  116. private void Grid_MouseEnter(object sender, MouseEventArgs e)
  117. {
  118. //if (DeviceData != null)
  119. //{
  120. // string tooltipValue =
  121. // string.Format(Application.Current.Resources["GlobalLableThrottleValveToolTip"].ToString(),
  122. // DeviceData.Type,
  123. // DeviceData.DisplayName,
  124. // DeviceData.DeviceSchematicId,
  125. // DeviceData.Mode == (int)PressureCtrlMode.TVPressureCtrl ? "Pressure" : (DeviceData.Mode == (int)PressureCtrlMode.TVPositionCtrl ? "Position" : ""),
  126. // DeviceData.PositionFeedback.ToString("F1"),
  127. // DeviceData.PressureFeedback.ToString("F1"));
  128. // ToolTip = tooltipValue;
  129. //}
  130. }
  131. private void Grid_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
  132. {
  133. if (DeviceData == null)
  134. return;
  135. _dialogBox = new AITThrottleValveInputDialogBox
  136. {
  137. SetThrottleModeCommandDelegate = SetThrottleModeExecute,
  138. SetPressureCommandDelegate = SetPressureExecute,
  139. SetPositionCommandDelegate = SetPositionExecute,
  140. DeviceName = string.Format("{0}: {1}", DeviceData.Type, DeviceData.DisplayName),
  141. DeviceId = DeviceData.DeviceSchematicId,
  142. SetPointPosition = Math.Round(DeviceData.PositionSetPoint, 1),
  143. SetPointPressure = Math.Round(DeviceData.PressureSetPoint, 1),
  144. MaxValuePressure = DeviceData.MaxValuePressure,
  145. MaxValuePosition = DeviceData.MaxValuePosition,
  146. UnitPosition = DeviceData.UnitPosition,
  147. UnitPressure = DeviceData.UnitPressure,
  148. FeedbackPosition = DeviceData.PositionFeedback,
  149. FeedbackPressure = DeviceData.PressureFeedback,
  150. IsPositionMode = DeviceData.Mode == (int)PressureCtrlMode.TVPositionCtrl,
  151. IsPressureMode = DeviceData.Mode == (int)PressureCtrlMode.TVPressureCtrl,
  152. };
  153. if (AnalogOwner != null)
  154. _dialogBox.Owner = AnalogOwner;
  155. _dialogBox.Topmost = true;
  156. _dialogBox.WindowStartupLocation = WindowStartupLocation.CenterScreen;
  157. _dialogBox.FocasAll();
  158. _dialogBox.ShowDialog();
  159. _dialogBox = null;
  160. }
  161. private void SetThrottleModeExecute(PressureCtrlMode value)
  162. {
  163. InvokeClient.Instance.Service.DoOperation($"{DeviceData.Module}.{DeviceData.DeviceName}.{AITThrottleValveOperation.SetMode}", value.ToString());
  164. }
  165. private void SetPressureExecute(double value)
  166. {
  167. InvokeClient.Instance.Service.DoOperation($"{DeviceData.Module}.{DeviceData.DeviceName}.{AITThrottleValveOperation.SetPressure}", (float)value);
  168. }
  169. private void SetPositionExecute(double value)
  170. {
  171. InvokeClient.Instance.Service.DoOperation($"{DeviceData.Module}.{DeviceData.DeviceName}.{AITThrottleValveOperation.SetPosition}", (float)value);
  172. }
  173. }
  174. }