AITThrottleValve.xaml.cs 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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 static readonly DependencyProperty IsAutoModeProperty = DependencyProperty.Register(
  36. "IsAutoMode", typeof(bool), typeof(AITThrottleValve),
  37. new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.AffectsRender));
  38. public ICommand Command
  39. {
  40. get
  41. {
  42. return (ICommand)this.GetValue(CommandProperty);
  43. }
  44. set
  45. {
  46. this.SetValue(CommandProperty, value);
  47. }
  48. }
  49. /// <summary>
  50. /// set, get current progress value AnalogDeviceData
  51. /// </summary>
  52. public AITThrottleValveData DeviceData
  53. {
  54. get
  55. {
  56. return (AITThrottleValveData)this.GetValue(DeviceDataProperty);
  57. }
  58. set
  59. {
  60. this.SetValue(DeviceDataProperty, value);
  61. }
  62. }
  63. public bool IsAutoMode
  64. {
  65. get
  66. {
  67. return (bool)this.GetValue(IsAutoModeProperty);
  68. }
  69. set
  70. {
  71. this.SetValue(IsAutoModeProperty, value);
  72. }
  73. }
  74. private AITThrottleValveInputDialogBox _dialogBox;
  75. public Window AnalogOwner { get; set; }
  76. protected override void OnRender(DrawingContext drawingContext)
  77. {
  78. base.OnRender(drawingContext);
  79. if (DeviceData != null)
  80. {
  81. if (DeviceData.Mode == (int)PressureCtrlMode.TVPressureCtrl)
  82. {
  83. labelValue.Content = DeviceData.PositionFeedback.ToString("F0") + " %";
  84. rotateTransform.Angle = DeviceData.PositionFeedback;
  85. }
  86. else if (DeviceData.Mode == (int)PressureCtrlMode.TVPositionCtrl)
  87. {
  88. labelValue.Content = DeviceData.PositionFeedback.ToString("F0") + " %";
  89. rotateTransform.Angle = DeviceData.PositionFeedback;
  90. }
  91. if (_dialogBox != null)
  92. {
  93. _dialogBox.IsPositionMode = DeviceData.Mode == (int)PressureCtrlMode.TVPositionCtrl;
  94. _dialogBox.IsPressureMode = DeviceData.Mode == (int) PressureCtrlMode.TVPressureCtrl;
  95. //_dialogBox.SetPointPosition = DeviceData.PositionSetPoint;
  96. //_dialogBox.SetPointPressure = DeviceData.PressureSetPoint;
  97. }
  98. }
  99. }
  100. private void Grid_MouseEnter(object sender, MouseEventArgs e)
  101. {
  102. //if (DeviceData != null)
  103. //{
  104. // string tooltipValue =
  105. // string.Format(Application.Current.Resources["GlobalLableThrottleValveToolTip"].ToString(),
  106. // DeviceData.Type,
  107. // DeviceData.DisplayName,
  108. // DeviceData.DeviceSchematicId,
  109. // DeviceData.Mode == (int)PressureCtrlMode.TVPressureCtrl ? "Pressure" : (DeviceData.Mode == (int)PressureCtrlMode.TVPositionCtrl ? "Position" : ""),
  110. // DeviceData.PositionFeedback.ToString("F1"),
  111. // DeviceData.PressureFeedback.ToString("F1"));
  112. // ToolTip = tooltipValue;
  113. //}
  114. }
  115. private void Grid_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
  116. {
  117. if (IsAutoMode)
  118. return;
  119. if (DeviceData == null)
  120. return;
  121. _dialogBox = new AITThrottleValveInputDialogBox
  122. {
  123. SetThrottleModeCommandDelegate = SetThrottleModeExecute,
  124. SetPressureCommandDelegate = SetPressureExecute,
  125. SetPositionCommandDelegate = SetPositionExecute,
  126. DeviceName = string.Format("{0}: {1}", DeviceData.Type, DeviceData.DisplayName),
  127. DeviceId = DeviceData.DeviceSchematicId,
  128. SetPointPosition = Math.Round(DeviceData.PositionSetPoint, 1),
  129. SetPointPressure = Math.Round(DeviceData.PressureSetPoint, 1),
  130. MaxValuePressure = DeviceData.MaxValuePressure,
  131. MaxValuePosition = DeviceData.MaxValuePosition,
  132. UnitPosition = DeviceData.UnitPosition,
  133. UnitPressure = DeviceData.UnitPressure,
  134. FeedbackPosition = DeviceData.PositionFeedback,
  135. FeedbackPressure = DeviceData.PressureFeedback,
  136. IsPositionMode = DeviceData.Mode == (int)PressureCtrlMode.TVPositionCtrl,
  137. IsPressureMode = DeviceData.Mode == (int) PressureCtrlMode.TVPressureCtrl,
  138. };
  139. if (AnalogOwner != null)
  140. _dialogBox.Owner = AnalogOwner;
  141. _dialogBox.Topmost = true;
  142. _dialogBox.WindowStartupLocation = WindowStartupLocation.CenterScreen;
  143. _dialogBox.FocasAll();
  144. _dialogBox.ShowDialog();
  145. _dialogBox = null;
  146. }
  147. private void SetThrottleModeExecute(PressureCtrlMode value)
  148. {
  149. InvokeClient.Instance.Service.DoOperation($"{DeviceData.Module}.{DeviceData.DeviceName}.{AITThrottleValveOperation.SetMode}", value.ToString() );
  150. }
  151. private void SetPressureExecute(double value)
  152. {
  153. InvokeClient.Instance.Service.DoOperation($"{DeviceData.Module}.{DeviceData.DeviceName}.{AITThrottleValveOperation.SetPressure}", value );
  154. }
  155. private void SetPositionExecute(double value)
  156. {
  157. InvokeClient.Instance.Service.DoOperation($"{DeviceData.Module}.{DeviceData.DeviceName}.{AITThrottleValveOperation.SetPosition}", value );
  158. }
  159. }
  160. }