AITGasIIValve.xaml.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Windows;
  7. using System.Windows.Controls;
  8. using System.Windows.Data;
  9. using System.Windows.Documents;
  10. using System.Windows.Input;
  11. using System.Windows.Media;
  12. using System.Windows.Media.Animation;
  13. using System.Windows.Media.Imaging;
  14. using System.Windows.Navigation;
  15. using System.Windows.Shapes;
  16. using System.Windows.Threading;
  17. using Aitex.Core.Common.DeviceData;
  18. using Aitex.Core.UI.Control;
  19. using Aitex.Core.Util;
  20. using MECF.Framework.Common.OperationCenter;
  21. using MECF.Framework.UI.Core.Control;
  22. using MECF.Framework.UI.Core.ExtendedControls;
  23. namespace Aitex.Core.UI.DeviceControl
  24. {
  25. /// <summary>
  26. /// TexGasValve.xaml 的交互逻辑
  27. /// </summary>
  28. public partial class AITGasIIValve : UserControl
  29. {
  30. // define dependency properties
  31. public static readonly DependencyProperty CommandProperty = DependencyProperty.Register(
  32. "Command", typeof(ICommand), typeof(AITGasIIValve),
  33. new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.AffectsRender));
  34. public ICommand Command
  35. {
  36. get
  37. {
  38. return (ICommand)this.GetValue(CommandProperty);
  39. }
  40. set
  41. {
  42. this.SetValue(CommandProperty, value);
  43. }
  44. }
  45. public Window AITGasOwner { get; set; }
  46. public static readonly DependencyProperty IsSwitchOpenProperty = DependencyProperty.Register(
  47. "IsSwitchOpen", typeof(bool), typeof(AITGasIIValve),
  48. new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.AffectsRender));
  49. public bool IsSwitchOpen
  50. {
  51. get
  52. {
  53. return (bool)this.GetValue(IsSwitchOpenProperty);
  54. }
  55. set
  56. {
  57. this.SetValue(IsSwitchOpenProperty, value);
  58. }
  59. }
  60. public BrushConverter _brushconvert = new BrushConverter();
  61. public bool IsVirtualSwitchOpen { get; set; }
  62. private SwitchDialog dialog;
  63. public static readonly DependencyProperty ValveDisplayNameProperty = DependencyProperty.Register(
  64. "ValveDisplayName", typeof(string), typeof(AITGasIIValve),
  65. new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.AffectsRender));
  66. public string ValveDisplayName
  67. {
  68. get
  69. {
  70. return (string)this.GetValue(ValveDisplayNameProperty);
  71. }
  72. set
  73. {
  74. this.SetValue(ValveDisplayNameProperty, value);
  75. }
  76. }
  77. public bool IsSim
  78. {
  79. get { return (bool)this.GetValue(IsSimProperty); }
  80. set { this.SetValue(IsSimProperty, value); }
  81. }
  82. // Using a DependencyProperty as the backing store for MenuVisibility. This enables animation, styling, binding, etc...
  83. public static readonly DependencyProperty IsSimProperty =
  84. DependencyProperty.Register("IsSim", typeof(bool), typeof(AITGasIIValve),
  85. new FrameworkPropertyMetadata(false));
  86. public Visibility MenuVisibility
  87. {
  88. get { return (Visibility)this.GetValue(MenuVisibilityProperty); }
  89. set { this.SetValue(MenuVisibilityProperty, value); }
  90. }
  91. // Using a DependencyProperty as the backing store for MenuVisibility. This enables animation, styling, binding, etc...
  92. public static readonly DependencyProperty MenuVisibilityProperty =
  93. DependencyProperty.Register("MenuVisibility", typeof(Visibility), typeof(AITGasIIValve),
  94. new FrameworkPropertyMetadata(Visibility.Visible));
  95. public static readonly DependencyProperty DeviceDataProperty = DependencyProperty.Register(
  96. "DeviceData", typeof(AITValveData), typeof(AITGasIIValve),
  97. new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.AffectsRender));
  98. public AITValveData DeviceData
  99. {
  100. get
  101. {
  102. var data = (AITValveData)this.GetValue(DeviceDataProperty);
  103. if (data!=null&&!string.IsNullOrEmpty(data.DisplayName))
  104. {
  105. ValveDisplayName = data.DisplayName.Replace("ValveAV","");
  106. }
  107. switch (GasStateType)
  108. {
  109. case GasPanelStateType.Manual:
  110. case GasPanelStateType.Monitor:
  111. if (data == null)
  112. {
  113. rdTrig.CLK = data == null;
  114. }
  115. else
  116. {
  117. if (data.IsOpen)
  118. {
  119. rdTrig.CLK = true;
  120. }
  121. else
  122. {
  123. rdTrig.CLK = false;
  124. }
  125. }
  126. if (rdTrig.R)
  127. {
  128. IsSwitchOpen = true;
  129. Application.Current.Dispatcher.BeginInvoke(new Action(() =>
  130. {
  131. Storyboard sb = this.FindResource("OpenValveStoryBoard") as Storyboard;
  132. sb.Begin();
  133. }));
  134. }
  135. if (rdTrig.T)
  136. {
  137. IsSwitchOpen = false;
  138. Application.Current.Dispatcher.BeginInvoke(new Action(() =>
  139. {
  140. Storyboard sb = this.FindResource("CloseValveStoryBoard") as Storyboard;
  141. sb.Begin();
  142. }));
  143. }
  144. break;
  145. case GasPanelStateType.Recipe:
  146. rdTrig.CLK = (data == null || data.VirtualFeedback);
  147. if (rdTrig.R)
  148. {
  149. Application.Current.Dispatcher.BeginInvoke(new Action(() =>
  150. {
  151. Storyboard sb = this.FindResource("OpenValveStoryBoard") as Storyboard;
  152. sb.Begin();
  153. }));
  154. IsVirtualSwitchOpen = true;
  155. }
  156. if (rdTrig.T)
  157. {
  158. Application.Current.Dispatcher.BeginInvoke(new Action(() =>
  159. {
  160. Storyboard sb = this.FindResource("CloseValveStoryBoard") as Storyboard;
  161. sb.Begin();
  162. }));
  163. IsVirtualSwitchOpen = false;
  164. }
  165. break;
  166. default:
  167. break;
  168. }
  169. return data;
  170. }
  171. set
  172. {
  173. this.SetValue(DeviceDataProperty, value);
  174. }
  175. }
  176. public static readonly DependencyProperty GasPanelStateTypeProperty = DependencyProperty.Register(
  177. "GasStateType", typeof(GasPanelStateType), typeof(AITGasIIValve),
  178. new FrameworkPropertyMetadata(GasPanelStateType.Manual, FrameworkPropertyMetadataOptions.AffectsRender));
  179. public GasPanelStateType GasStateType
  180. {
  181. get
  182. {
  183. return (GasPanelStateType)this.GetValue(GasPanelStateTypeProperty);
  184. }
  185. set
  186. {
  187. this.SetValue(GasPanelStateTypeProperty, value);
  188. }
  189. }
  190. public static readonly DependencyProperty ValveOpenOrientationProperty = DependencyProperty.Register(
  191. "ValveOpenOrientation", typeof(LineOrientation), typeof(AITGasIIValve),
  192. new FrameworkPropertyMetadata(LineOrientation.Horizontal, FrameworkPropertyMetadataOptions.AffectsRender));
  193. public LineOrientation ValveOpenOrientation
  194. {
  195. get { return (LineOrientation)GetValue(ValveOpenOrientationProperty); }
  196. set { SetValue(ValveOpenOrientationProperty, value); }
  197. }
  198. public static readonly DependencyProperty IsDisableModeProperty = DependencyProperty.Register(
  199. "IsDisableMode", typeof(bool), typeof(AITGasIIValve),
  200. new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.AffectsRender));
  201. public bool IsDisableMode
  202. {
  203. get { return (bool)GetValue(IsDisableModeProperty); }
  204. set { SetValue(IsDisableModeProperty, value); }
  205. }
  206. public bool IsOpen => DeviceData == null || DeviceData.IsOpen;
  207. private DispatcherTimer valveTimer = new DispatcherTimer();
  208. RD_TRIG rdTrig = new RD_TRIG();
  209. public AITGasIIValve()
  210. {
  211. InitializeComponent();
  212. }
  213. private BitmapSource GetImage(string name)
  214. {
  215. return new BitmapImage(new Uri(string.Format("pack://application:,,,/MECF.Framework.Common;component/Resources/Valve/{0}", name)));
  216. }
  217. protected override void OnRender(DrawingContext drawingContext)
  218. {
  219. if (DeviceData != null)
  220. {
  221. if ((DeviceData.Feedback && (GasStateType == GasPanelStateType.Manual || GasStateType == GasPanelStateType.Monitor))
  222. || (DeviceData.VirtualFeedback && GasStateType == GasPanelStateType.Recipe))
  223. {
  224. IsSwitchOpen = true;
  225. Application.Current.Dispatcher.BeginInvoke(new Action(() =>
  226. {
  227. Storyboard sb = this.FindResource("OpenValveStoryBoard") as Storyboard;
  228. sb.Begin();
  229. }));
  230. }
  231. else
  232. {
  233. IsSwitchOpen = false;
  234. Application.Current.Dispatcher.BeginInvoke(new Action(() =>
  235. {
  236. Storyboard sb = this.FindResource("CloseValveStoryBoard") as Storyboard;
  237. sb.Begin();
  238. }));
  239. }
  240. }
  241. if (DeviceData != null)
  242. {
  243. this.ToolTip =
  244. $"Valve Name:{DeviceData.DisplayName} \r\n Device ID:{DeviceData.DeviceSchematicId} \r\n SetPoint:{DeviceData.SetPoint} \r\n SetVirtual:{DeviceData.VirtualFeedback} \r\n Status:{DeviceData.Feedback}";
  245. }
  246. base.OnRender(drawingContext);
  247. }
  248. private void OpenValve(object sender, RoutedEventArgs e)
  249. {
  250. if (IsDisableMode) return;
  251. switch (GasStateType)
  252. {
  253. case GasPanelStateType.Manual:
  254. // InvokeClient.Instance.Service.DoOperation($"{DeviceData.UniqueName}.{AITValveOperation.GVTurnValve}", true);
  255. break;
  256. case GasPanelStateType.Monitor:
  257. break;
  258. case GasPanelStateType.Recipe:
  259. // InvokeClient.Instance.Service.DoOperation($"{DeviceData.UniqueName}.{AITValveOperation.GVVirtualTurnValve}", true);
  260. break;
  261. default:
  262. break;
  263. }
  264. if (Command == null)
  265. return;
  266. Command.Execute(new object[] { DeviceData.DeviceName, AITValveOperation.GVVirtualTurnValve, true });
  267. }
  268. private void CloseValve(object sender, RoutedEventArgs e)
  269. {
  270. if (IsDisableMode) return;
  271. switch (GasStateType)
  272. {
  273. case GasPanelStateType.Manual:
  274. // InvokeClient.Instance.Service.DoOperation($"{DeviceData.UniqueName}.{AITValveOperation.GVTurnValve}", false);
  275. break;
  276. case GasPanelStateType.Monitor:
  277. break;
  278. case GasPanelStateType.Recipe:
  279. // InvokeClient.Instance.Service.DoOperation($"{DeviceData.UniqueName}.{AITValveOperation.GVVirtualTurnValve}", false);
  280. break;
  281. default:
  282. break;
  283. }
  284. if (Command == null)
  285. return;
  286. Command.Execute(new object[] { DeviceData.DeviceName, AITValveOperation.GVVirtualTurnValve, false });
  287. }
  288. private void AITGasIIValve_OnLoaded(object sender, RoutedEventArgs e)
  289. {
  290. imgValveOpen.Source = GetImage(ValveOpenOrientation == LineOrientation.Horizontal ? "ValveOpenVerticalJet.png" : "ValveOpenHorizontalJet.png");
  291. imgValveClose.Source = GetImage(ValveOpenOrientation == LineOrientation.Vertical ? "ValveCloseVerticalJet.png" : "ValveCloseHorizontalJet.png");
  292. if (DeviceData == null || DeviceData.IsOpen)
  293. {
  294. IsSwitchOpen = true;
  295. Application.Current.Dispatcher.BeginInvoke(new Action(() =>
  296. {
  297. Storyboard sb = this.FindResource("OpenValveStoryBoard") as Storyboard;
  298. sb.Begin();
  299. }));
  300. }
  301. else
  302. {
  303. IsSwitchOpen = false;
  304. Application.Current.Dispatcher.BeginInvoke(new Action(() =>
  305. {
  306. Storyboard sb = this.FindResource("CloseValveStoryBoard") as Storyboard;
  307. sb.Begin();
  308. }));
  309. }
  310. //valveTimer.Start();
  311. }
  312. private void imgValveClose_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
  313. {
  314. if (e.StylusDevice != null) e.Handled = true;//认为误触
  315. else imgValve_TouchUp(sender, null);
  316. }
  317. private void imgValve_TouchUp(object sender, TouchEventArgs e)
  318. {
  319. if (IsDisableMode) return;
  320. switch (GasStateType)
  321. {
  322. case GasPanelStateType.Manual:
  323. DeviceData.Feedback = !DeviceData.IsOpen;
  324. rdTrig.CLK = (DeviceData == null || DeviceData.IsOpen);
  325. IsSwitchOpen = DeviceData.Feedback;
  326. break;
  327. case GasPanelStateType.Monitor:
  328. break;
  329. case GasPanelStateType.Recipe:
  330. IsVirtualSwitchOpen = !IsVirtualSwitchOpen;
  331. // InvokeClient.Instance.Service.DoOperation($"{DeviceData.UniqueName}.{AITValveOperation.GVVirtualTurnValve}", IsVirtualSwitchOpen);
  332. break;
  333. default:
  334. break;
  335. }
  336. if (Command == null)
  337. return;
  338. // Command.Execute(new object[] { DeviceData.DeviceName, AITValveOperation.GVVirtualTurnValve, IsVirtualSwitchOpen });
  339. }
  340. }
  341. }