AITThrottleValve.xaml.cs 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  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 AITThrottleValve : UserControl
  23. {
  24. public AITThrottleValve()
  25. {
  26. InitializeComponent();
  27. }
  28. // define dependency properties
  29. public static readonly DependencyProperty CommandProperty = DependencyProperty.Register(
  30. "Command", typeof(ICommand), typeof(AITThrottleValve),
  31. new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.AffectsRender));
  32. public static readonly DependencyProperty DeviceDataProperty = DependencyProperty.Register(
  33. "DeviceData", typeof(AITThrottleValveData), typeof(AITThrottleValve),
  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 SupportPressureModeProperty = DependencyProperty.Register(
  61. "SupportPressureMode", typeof(bool), typeof(AITThrottleValve),
  62. new FrameworkPropertyMetadata(true, FrameworkPropertyMetadataOptions.AffectsRender));
  63. public bool SupportPressureMode
  64. {
  65. get
  66. {
  67. return (bool)this.GetValue(SupportPressureModeProperty);
  68. }
  69. set
  70. {
  71. this.SetValue(SupportPressureModeProperty, value);
  72. }
  73. }
  74. public static readonly DependencyProperty PressureStringFormatProperty = DependencyProperty.Register(
  75. "PressureStringFormat", typeof(string), typeof(AITThrottleValve),
  76. new FrameworkPropertyMetadata("F1", FrameworkPropertyMetadataOptions.AffectsRender));
  77. public string PressureStringFormat
  78. {
  79. get
  80. {
  81. return (string)this.GetValue(PressureStringFormatProperty);
  82. }
  83. set
  84. {
  85. this.SetValue(PressureStringFormatProperty, value);
  86. }
  87. }
  88. public static readonly DependencyProperty PositionStringFormatProperty = DependencyProperty.Register(
  89. "PositionStringFormat", typeof(string), typeof(AITThrottleValve),
  90. new FrameworkPropertyMetadata("F1", FrameworkPropertyMetadataOptions.AffectsRender));
  91. public string PositionStringFormat
  92. {
  93. get
  94. {
  95. return (string)this.GetValue(PositionStringFormatProperty);
  96. }
  97. set
  98. {
  99. this.SetValue(PositionStringFormatProperty, value);
  100. }
  101. }
  102. private AITThrottleValveInputDialogBox _dialogBox;
  103. public Window AnalogOwner { get; set; }
  104. protected override void OnRender(DrawingContext drawingContext)
  105. {
  106. base.OnRender(drawingContext);
  107. if (DeviceData != null)
  108. {
  109. //if (DeviceData.Mode == (int)PressureCtrlMode.TVPressureCtrl)
  110. //{
  111. // rotateTransform.Angle = DeviceData.PressureFeedback * -90.0 / DeviceData.MaxValuePressure;
  112. //}
  113. //else if (DeviceData.Mode == (int)PressureCtrlMode.TVPositionCtrl)
  114. //{
  115. // rotateTransform.Angle = DeviceData.PositionFeedback * -90.0 / DeviceData.MaxValuePosition;
  116. //}
  117. rotateTransform.Angle = DeviceData.PositionFeedback * -90.0 / DeviceData.MaxValuePosition;
  118. labelPressure.Content = DeviceData.PressureFeedback.ToString(PressureStringFormat);
  119. labelAngle.Content = DeviceData.PositionFeedback.ToString(PositionStringFormat);
  120. labelPressureUnit.Content = !string.IsNullOrEmpty(DeviceData.UnitPressure) ? DeviceData.UnitPressure : "mTorr";
  121. labelAngleUnit.Content = !string.IsNullOrEmpty(DeviceData.UnitPosition) ? DeviceData.UnitPosition : "%";
  122. if (_dialogBox != null)
  123. {
  124. _dialogBox.IsPositionMode = DeviceData.Mode == (int)PressureCtrlMode.TVPositionCtrl;
  125. _dialogBox.IsPressureMode = DeviceData.Mode == (int)PressureCtrlMode.TVPressureCtrl;
  126. //_dialogBox.IsCloseMode = DeviceData.Mode == (int)PressureCtrlMode.TVClose;
  127. //_dialogBox.SetPointPosition = DeviceData.PositionSetPoint;
  128. //_dialogBox.SetPointPressure = DeviceData.PressureSetPoint;
  129. }
  130. }
  131. }
  132. private void Grid_MouseEnter(object sender, MouseEventArgs e)
  133. {
  134. //if (DeviceData != null)
  135. //{
  136. // string tooltipValue =
  137. // string.Format(Application.Current.Resources["GlobalLableThrottleValveToolTip"].ToString(),
  138. // DeviceData.Type,
  139. // DeviceData.DisplayName,
  140. // DeviceData.DeviceSchematicId,
  141. // DeviceData.Mode == (int)PressureCtrlMode.TVPressureCtrl ? "Pressure" : (DeviceData.Mode == (int)PressureCtrlMode.TVPositionCtrl ? "Position" : ""),
  142. // DeviceData.PositionFeedback.ToString("F1"),
  143. // DeviceData.PressureFeedback.ToString("F1"));
  144. // ToolTip = tooltipValue;
  145. //}
  146. }
  147. private void Grid_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
  148. {
  149. if (DeviceData == null)
  150. return;
  151. _dialogBox = new AITThrottleValveInputDialogBox
  152. {
  153. SetThrottleModeCommandDelegate = SetThrottleModeExecute,
  154. SetPressureCommandDelegate = SetPressureExecute,
  155. SetPositionCommandDelegate = SetPositionExecute,
  156. DeviceName = string.Format("{0}: {1}", DeviceData.Type, DeviceData.DisplayName),
  157. DeviceId = DeviceData.DeviceSchematicId,
  158. SetPointPosition = Math.Round(DeviceData.PositionSetPoint, 1),
  159. SetPointPressure = Math.Round(DeviceData.PressureSetPoint, 1),
  160. MaxValuePressure = DeviceData.MaxValuePressure,
  161. MaxValuePosition = DeviceData.MaxValuePosition,
  162. UnitPosition = DeviceData.UnitPosition,
  163. UnitPressure = DeviceData.UnitPressure,
  164. FeedbackPosition = DeviceData.PositionFeedback,
  165. FeedbackPressure = DeviceData.PressureFeedback,
  166. //SupportPressureMode = SupportPressureMode,
  167. IsPositionMode = DeviceData.Mode == (int)PressureCtrlMode.TVPositionCtrl,
  168. IsPressureMode = DeviceData.Mode == (int)PressureCtrlMode.TVPressureCtrl,
  169. //IsCloseMode = DeviceData.Mode == (int)PressureCtrlMode.TVClose,
  170. };
  171. if (AnalogOwner != null)
  172. _dialogBox.Owner = AnalogOwner;
  173. _dialogBox.Topmost = true;
  174. _dialogBox.WindowStartupLocation = WindowStartupLocation.CenterScreen;
  175. _dialogBox.FocasAll();
  176. _dialogBox.ShowDialog();
  177. _dialogBox = null;
  178. }
  179. private void SetThrottleModeExecute(PressureCtrlMode value)
  180. {
  181. InvokeClient.Instance.Service.DoOperation($"{DeviceData.Module}.{DeviceData.DeviceName}.{AITThrottleValveOperation.SetMode}", value.ToString());
  182. }
  183. private void SetPressureExecute(double value)
  184. {
  185. if (!SupportPressureMode)
  186. return;
  187. InvokeClient.Instance.Service.DoOperation($"{DeviceData.Module}.{DeviceData.DeviceName}.{AITThrottleValveOperation.SetPressure}", (float)value);
  188. }
  189. private void SetPositionExecute(double value)
  190. {
  191. InvokeClient.Instance.Service.DoOperation($"{DeviceData.Module}.{DeviceData.DeviceName}.{AITThrottleValveOperation.SetPosition}", (float)value);
  192. }
  193. }
  194. }