AITValve.xaml.cs 6.4 KB

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