AITThrottleValve.xaml.cs 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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. /// 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. private AITThrottleValveInputDialogBox _dialogBox;
  61. public Window AnalogOwner { get; set; }
  62. protected override void OnRender(DrawingContext drawingContext)
  63. {
  64. base.OnRender(drawingContext);
  65. if (DeviceData != null)
  66. {
  67. //if (DeviceData.Mode == (int) PressureCtrlMode.TVPressureCtrl)
  68. //{
  69. //labelValue.Content = DeviceData.PressureFeedback.ToString("F1");
  70. // rotateTransform.Angle = 0;
  71. //}
  72. //else if (DeviceData.Mode == (int) PressureCtrlMode.TVPositionCtrl)
  73. //{
  74. //labelValue.Content = DeviceData.PositionFeedback.ToString("F1");
  75. rotateTransform.Angle = DeviceData.PositionFeedback;
  76. //}
  77. if (_dialogBox != null)
  78. {
  79. _dialogBox.IsPositionMode = DeviceData.Mode == (int)PressureCtrlMode.TVPositionCtrl;
  80. _dialogBox.IsPressureMode = DeviceData.Mode == (int) PressureCtrlMode.TVPressureCtrl;
  81. //_dialogBox.SetPointPosition = DeviceData.PositionSetPoint;
  82. //_dialogBox.SetPointPressure = DeviceData.PressureSetPoint;
  83. }
  84. }
  85. }
  86. private void Grid_MouseEnter(object sender, MouseEventArgs e)
  87. {
  88. if (DeviceData != null)
  89. {
  90. string tooltipValue =
  91. string.Format(Application.Current.Resources["GlobalLableThrottleValveToolTip"].ToString(),
  92. DeviceData.Type,
  93. DeviceData.DisplayName,
  94. DeviceData.DeviceSchematicId,
  95. DeviceData.Mode == (int)PressureCtrlMode.TVPressureCtrl ? "Pressure" : (DeviceData.Mode == (int)PressureCtrlMode.TVPositionCtrl ? "Position" : ""),
  96. DeviceData.PositionFeedback.ToString("F1"),
  97. DeviceData.PressureFeedback.ToString("F1"));
  98. ToolTip = tooltipValue;
  99. }
  100. }
  101. private void Grid_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
  102. {
  103. if (DeviceData == null)
  104. return;
  105. _dialogBox = new AITThrottleValveInputDialogBox
  106. {
  107. SetThrottleModeCommandDelegate = SetThrottleModeExecute,
  108. SetPressureCommandDelegate = SetPressureExecute,
  109. SetPositionCommandDelegate = SetPositionExecute,
  110. DeviceName = string.Format("{0}: {1}", DeviceData.Type, DeviceData.DisplayName),
  111. DeviceId = DeviceData.DeviceSchematicId,
  112. SetPointPosition = Math.Round(DeviceData.PositionSetPoint, 1),
  113. SetPointPressure = Math.Round(DeviceData.PressureSetPoint, 1),
  114. MaxValuePressure = DeviceData.MaxValuePressure,
  115. MaxValuePosition = DeviceData.MaxValuePosition,
  116. UnitPosition = DeviceData.UnitPosition,
  117. UnitPressure = DeviceData.UnitPressure,
  118. FeedbackPosition = DeviceData.PositionFeedback,
  119. FeedbackPressure = DeviceData.PressureFeedback,
  120. IsPositionMode = DeviceData.Mode == (int)PressureCtrlMode.TVPositionCtrl,
  121. IsPressureMode = DeviceData.Mode == (int) PressureCtrlMode.TVPressureCtrl,
  122. };
  123. if (AnalogOwner != null)
  124. _dialogBox.Owner = AnalogOwner;
  125. _dialogBox.Topmost = true;
  126. _dialogBox.WindowStartupLocation = WindowStartupLocation.CenterScreen;
  127. _dialogBox.FocasAll();
  128. _dialogBox.ShowDialog();
  129. _dialogBox = null;
  130. }
  131. private void SetThrottleModeExecute(PressureCtrlMode value)
  132. {
  133. Command.Execute(new object[] { DeviceData.DeviceName, AITThrottleValveOperation.SetMode.ToString(), value.ToString() });
  134. }
  135. private void SetPressureExecute(double value)
  136. {
  137. Command.Execute(new object[] { DeviceData.DeviceName, AITThrottleValveOperation.SetPressure.ToString(), value.ToString() });
  138. }
  139. private void SetPositionExecute(double value)
  140. {
  141. Command.Execute(new object[] { DeviceData.DeviceName, AITThrottleValveOperation.SetPosition.ToString(), value.ToString() });
  142. }
  143. }
  144. }