AITGasValve.xaml.cs 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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.Animation;
  12. using System.Windows.Media.Imaging;
  13. using System.Windows.Navigation;
  14. using System.Windows.Shapes;
  15. using System.Windows.Threading;
  16. using Aitex.Core.Common.DeviceData;
  17. using Aitex.Core.UI.Control;
  18. using Aitex.Core.Util;
  19. using MECF.Framework.Common.OperationCenter;
  20. namespace Aitex.Core.UI.DeviceControl
  21. {
  22. /// <summary>
  23. /// TexGasValve.xaml 的交互逻辑
  24. /// </summary>
  25. public partial class AITGasValve : UserControl
  26. {
  27. // define dependency properties
  28. public static readonly DependencyProperty CommandProperty = DependencyProperty.Register(
  29. "Command", typeof(ICommand), typeof(AITGasValve),
  30. new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.AffectsRender));
  31. public ICommand Command
  32. {
  33. get
  34. {
  35. return (ICommand)this.GetValue(CommandProperty);
  36. }
  37. set
  38. {
  39. this.SetValue(CommandProperty, value);
  40. }
  41. }
  42. public static readonly DependencyProperty DeviceDataProperty = DependencyProperty.Register(
  43. "DeviceData", typeof(AITValveData), typeof(AITGasValve),
  44. new FrameworkPropertyMetadata(new AITValveData(), FrameworkPropertyMetadataOptions.AffectsRender));
  45. public AITValveData DeviceData
  46. {
  47. get
  48. {
  49. return (AITValveData)this.GetValue(DeviceDataProperty);
  50. }
  51. set
  52. {
  53. this.SetValue(DeviceDataProperty, value);
  54. }
  55. }
  56. public static readonly DependencyProperty EnableServiceControlProperty = DependencyProperty.Register(
  57. "EnableServiceControl", typeof(bool), typeof(AITGasValve),
  58. new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.AffectsRender));
  59. public bool EnableServiceControl
  60. {
  61. get
  62. {
  63. return (bool)this.GetValue(EnableServiceControlProperty);
  64. }
  65. set
  66. {
  67. this.SetValue(EnableServiceControlProperty, value);
  68. }
  69. }
  70. public static readonly DependencyProperty IsAutoModeProperty = DependencyProperty.Register(
  71. "IsAutoMode", typeof(bool), typeof(AITGasValve),
  72. new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.AffectsRender));
  73. public bool IsAutoMode
  74. {
  75. get
  76. {
  77. return (bool)this.GetValue(IsAutoModeProperty);
  78. }
  79. set
  80. {
  81. this.SetValue(IsAutoModeProperty, value);
  82. }
  83. }
  84. public static readonly DependencyProperty DeviceData2Property = DependencyProperty.Register(
  85. "DeviceData2", typeof(AITValveData), typeof(AITGasValve),
  86. new FrameworkPropertyMetadata(new AITValveData(), FrameworkPropertyMetadataOptions.AffectsRender));
  87. public AITValveData DeviceData2
  88. {
  89. get
  90. {
  91. return (AITValveData)this.GetValue(DeviceData2Property);
  92. }
  93. set
  94. {
  95. this.SetValue(DeviceData2Property, value);
  96. }
  97. }
  98. public static readonly DependencyProperty ValveOpenOrientationProperty = DependencyProperty.Register(
  99. "ValveOpenOrientation", typeof(LineOrientation), typeof(AITGasValve),
  100. new FrameworkPropertyMetadata(LineOrientation.Horizontal, FrameworkPropertyMetadataOptions.AffectsRender));
  101. public LineOrientation ValveOpenOrientation
  102. {
  103. get { return (LineOrientation)GetValue(ValveOpenOrientationProperty); }
  104. set { SetValue(ValveOpenOrientationProperty, value); }
  105. }
  106. public AITGasValve()
  107. {
  108. InitializeComponent();
  109. }
  110. private BitmapSource GetImage(string name)
  111. {
  112. return
  113. new BitmapImage(new Uri(string.Format("pack://application:,,,/MECF.Framework.Common;component/Resources/Valve/{0}", name)));
  114. }
  115. protected override void OnRender(DrawingContext drawingContext)
  116. {
  117. rotateTransform.Angle = ValveOpenOrientation == LineOrientation.Horizontal ? 0 : 90;
  118. bool IsOpen = DeviceData == null || DeviceData.IsOpen;
  119. IsOpen = IsOpen && (DeviceData2 == null || !DeviceData2.IsOpen);
  120. imagePicture.Source = GetImage(IsOpen ? "ValveOpenHorizontal.png" : "ValveCloseHorizontal.png");
  121. if (DeviceData != null)
  122. {
  123. this.ToolTip =
  124. $"Valve Name:{DeviceData.DisplayName} \r\n Device ID:{DeviceData.DeviceSchematicId} \r\n SetPoint:{DeviceData.SetPoint} \r\n Status:{DeviceData.Feedback}";
  125. }
  126. base.OnRender(drawingContext);
  127. }
  128. private void OpenValve(object sender, RoutedEventArgs e)
  129. {
  130. if (IsAutoMode) return;
  131. if (EnableServiceControl)
  132. {
  133. InvokeClient.Instance.Service.DoOperation($"{DeviceData.UniqueName}.{AITValveOperation.GVTurnValve}", true);
  134. return;
  135. }
  136. if (Command == null)
  137. return;
  138. Command.Execute(new object[] { DeviceData.DeviceName, AITValveOperation.GVTurnValve, true });
  139. if (DeviceData2 != null && !string.IsNullOrEmpty(DeviceData2.DeviceName))
  140. {
  141. Command.Execute(new object[] { DeviceData2.DeviceName, AITValveOperation.GVTurnValve, false });
  142. }
  143. }
  144. private void CloseValve(object sender, RoutedEventArgs e)
  145. {
  146. if (IsAutoMode) return;
  147. if (EnableServiceControl)
  148. {
  149. InvokeClient.Instance.Service.DoOperation($"{DeviceData.UniqueName}.{AITValveOperation.GVTurnValve}", false);
  150. return;
  151. }
  152. if (Command == null)
  153. return;
  154. Command.Execute(new object[] { DeviceData.DeviceName, AITValveOperation.GVTurnValve, false });
  155. if (DeviceData2 != null && !string.IsNullOrEmpty(DeviceData2.DeviceName))
  156. {
  157. Command.Execute(new object[] { DeviceData2.DeviceName, AITValveOperation.GVTurnValve, true });
  158. }
  159. }
  160. }
  161. }