AITGasValve.xaml.cs 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447
  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 AITGasValve : UserControl
  29. {
  30. // define dependency properties
  31. public static readonly DependencyProperty CommandProperty = DependencyProperty.Register(
  32. "Command", typeof(ICommand), typeof(AITGasValve),
  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 bool IsSwitchOpen { get; set; }
  47. public BrushConverter _brushconvert = new BrushConverter();
  48. public bool IsVirtualSwitchOpen { get; set; }
  49. private SwitchDialog dialog;
  50. private string _valveDisplayName = "";
  51. public string ValveDisplayName
  52. {
  53. get => _valveDisplayName;
  54. set
  55. {
  56. _valveDisplayName = value;
  57. }
  58. }
  59. public bool IsSim
  60. {
  61. get { return (bool)this.GetValue(IsSimProperty); }
  62. set { this.SetValue(IsSimProperty, value); }
  63. }
  64. // Using a DependencyProperty as the backing store for MenuVisibility. This enables animation, styling, binding, etc...
  65. public static readonly DependencyProperty IsSimProperty =
  66. DependencyProperty.Register("IsSim", typeof(bool), typeof(AITGasValve),
  67. new FrameworkPropertyMetadata(false));
  68. public Visibility MenuVisibility
  69. {
  70. get { return (Visibility)this.GetValue(MenuVisibilityProperty); }
  71. set { this.SetValue(MenuVisibilityProperty, value); }
  72. }
  73. // Using a DependencyProperty as the backing store for MenuVisibility. This enables animation, styling, binding, etc...
  74. public static readonly DependencyProperty MenuVisibilityProperty =
  75. DependencyProperty.Register("MenuVisibility", typeof(Visibility), typeof(AITGasValve),
  76. new FrameworkPropertyMetadata(Visibility.Visible));
  77. public static readonly DependencyProperty DeviceDataProperty = DependencyProperty.Register(
  78. "DeviceData", typeof(AITValveData), typeof(AITGasValve),
  79. new FrameworkPropertyMetadata(new AITValveData(), FrameworkPropertyMetadataOptions.AffectsRender));
  80. public AITValveData DeviceData
  81. {
  82. get
  83. {
  84. var data = (AITValveData)this.GetValue(DeviceDataProperty);
  85. switch (GasStateType)
  86. {
  87. case GasPanelStateType.Manual:
  88. case GasPanelStateType.Monitor:
  89. rdTrig.CLK = (data == null || data.IsOpen);
  90. if (rdTrig.R)
  91. {
  92. if (data.ILKDiValue)
  93. {
  94. ValveName.Foreground = (Brush)_brushconvert.ConvertFromString("White");
  95. Application.Current.Dispatcher.BeginInvoke(new Action(() =>
  96. {
  97. Storyboard sb = this.FindResource("OpenValveStoryBoard") as Storyboard;
  98. sb.Begin();
  99. }));
  100. }
  101. else
  102. {
  103. ValveName.Foreground = (Brush)_brushconvert.ConvertFromString("White");
  104. Application.Current.Dispatcher.BeginInvoke(new Action(() =>
  105. {
  106. Storyboard sb = this.FindResource("FlickerValveStoryBoard") as Storyboard;
  107. sb.Begin();
  108. }));
  109. }
  110. }
  111. if (rdTrig.T)
  112. {
  113. ValveName.Foreground = (Brush)_brushconvert.ConvertFromString("Black");
  114. Application.Current.Dispatcher.BeginInvoke(new Action(() =>
  115. {
  116. Storyboard sb = this.FindResource("CloseValveStoryBoard") as Storyboard;
  117. sb.Begin();
  118. }));
  119. }
  120. break;
  121. case GasPanelStateType.Recipe:
  122. rdTrig.CLK = (data == null || data.VirtualFeedback);
  123. if (rdTrig.R)
  124. {
  125. ValveName.Foreground = (Brush)_brushconvert.ConvertFromString("White");
  126. Application.Current.Dispatcher.BeginInvoke(new Action(() =>
  127. {
  128. Storyboard sb = this.FindResource("OpenValveStoryBoard") as Storyboard;
  129. sb.Begin();
  130. }));
  131. IsVirtualSwitchOpen = true;
  132. }
  133. if (rdTrig.T)
  134. {
  135. ValveName.Foreground = (Brush)_brushconvert.ConvertFromString("Black");
  136. Application.Current.Dispatcher.BeginInvoke(new Action(() =>
  137. {
  138. Storyboard sb = this.FindResource("CloseValveStoryBoard") as Storyboard;
  139. sb.Begin();
  140. }));
  141. IsVirtualSwitchOpen = false;
  142. }
  143. break;
  144. default:
  145. break;
  146. }
  147. return data;
  148. }
  149. set
  150. {
  151. this.SetValue(DeviceDataProperty, value);
  152. }
  153. }
  154. public static readonly DependencyProperty GasPanelStateTypeProperty = DependencyProperty.Register(
  155. "GasStateType", typeof(GasPanelStateType), typeof(AITGasValve),
  156. new FrameworkPropertyMetadata(GasPanelStateType.Manual, FrameworkPropertyMetadataOptions.AffectsRender));
  157. public GasPanelStateType GasStateType
  158. {
  159. get
  160. {
  161. return (GasPanelStateType)this.GetValue(GasPanelStateTypeProperty);
  162. }
  163. set
  164. {
  165. this.SetValue(GasPanelStateTypeProperty, value);
  166. }
  167. }
  168. public bool IsShowSwitchDialog
  169. {
  170. get { return (bool)GetValue(IsShowSwitchDialogProperty); }
  171. set { SetValue(IsShowSwitchDialogProperty, value); }
  172. }
  173. // Using a DependencyProperty as the backing store for IsShowSwitchDialog. This enables animation, styling, binding, etc...
  174. public static readonly DependencyProperty IsShowSwitchDialogProperty =
  175. DependencyProperty.Register("IsShowSwitchDialog", typeof(bool), typeof(AITGasValve), new PropertyMetadata(false));
  176. public static readonly DependencyProperty DeviceData2Property = DependencyProperty.Register(
  177. "DeviceData2", typeof(AITValveData), typeof(AITGasValve),
  178. new FrameworkPropertyMetadata(new AITValveData(), FrameworkPropertyMetadataOptions.AffectsRender));
  179. public AITValveData DeviceData2
  180. {
  181. get
  182. {
  183. return (AITValveData)this.GetValue(DeviceData2Property);
  184. }
  185. set
  186. {
  187. this.SetValue(DeviceData2Property, value);
  188. }
  189. }
  190. public static readonly DependencyProperty ValveOpenOrientationProperty = DependencyProperty.Register(
  191. "ValveOpenOrientation", typeof(LineOrientation), typeof(AITGasValve),
  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(AITGasValve),
  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. RD_TRIG flickerTrig = new RD_TRIG();
  210. public AITGasValve()
  211. {
  212. InitializeComponent();
  213. }
  214. private BitmapSource GetImage(string name)
  215. {
  216. return new BitmapImage(new Uri(string.Format("pack://application:,,,/MECF.Framework.Common;component/Resources/Valve/{0}", name)));
  217. }
  218. protected override void OnRender(DrawingContext drawingContext)
  219. {
  220. var data = (AITValveData)this.GetValue(DeviceDataProperty);
  221. if (data != null)
  222. {
  223. ValveName.Text = DeviceData.DisplayName.Replace("ValveAV", "");
  224. if ((DeviceData.SetPoint && GasStateType == GasPanelStateType.Manual) || (DeviceData.Feedback && GasStateType == GasPanelStateType.Monitor)
  225. || (DeviceData.VirtualFeedback && GasStateType == GasPanelStateType.Recipe))
  226. {
  227. if (!DeviceData.ILKDiValue && !(GasStateType == GasPanelStateType.Recipe))
  228. {
  229. ValveName.Foreground = (Brush)_brushconvert.ConvertFromString("White");
  230. Application.Current.Dispatcher.BeginInvoke(new Action(() =>
  231. {
  232. Storyboard sb = this.FindResource("FlickerValveStoryBoard") as Storyboard;
  233. sb.Begin();
  234. }));
  235. }
  236. else if (DeviceData.ILKDiValue && !DeviceData.Feedback && !(GasStateType == GasPanelStateType.Recipe))
  237. {
  238. ValveName.Foreground = (Brush)_brushconvert.ConvertFromString("Black");
  239. Application.Current.Dispatcher.BeginInvoke(new Action(() =>
  240. {
  241. Storyboard sb = this.FindResource("CloseValveStoryBoard") as Storyboard;
  242. sb.Begin();
  243. }));
  244. }
  245. else
  246. {
  247. ValveName.Foreground = (Brush)_brushconvert.ConvertFromString("White");
  248. Application.Current.Dispatcher.BeginInvoke(new Action(() =>
  249. {
  250. Storyboard sb = this.FindResource("OpenValveStoryBoard") as Storyboard;
  251. sb.Begin();
  252. }));
  253. }
  254. }
  255. else
  256. {
  257. ValveName.Foreground = (Brush)_brushconvert.ConvertFromString("Black");
  258. Application.Current.Dispatcher.BeginInvoke(new Action(() =>
  259. {
  260. Storyboard sb = this.FindResource("CloseValveStoryBoard") as Storyboard;
  261. sb.Begin();
  262. }));
  263. }
  264. this.ToolTip =
  265. $"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}";
  266. }
  267. else
  268. {
  269. ValveName.Foreground = (Brush)_brushconvert.ConvertFromString("Black");
  270. Application.Current.Dispatcher.BeginInvoke(new Action(() =>
  271. {
  272. Storyboard sb = this.FindResource("CloseValveStoryBoard") as Storyboard;
  273. sb.Begin();
  274. }));
  275. }
  276. base.OnRender(drawingContext);
  277. }
  278. private void OpenValve(object sender, RoutedEventArgs e)
  279. {
  280. if (IsDisableMode) return;
  281. switch (GasStateType)
  282. {
  283. case GasPanelStateType.Manual:
  284. InvokeClient.Instance.Service.DoOperation($"{DeviceData.UniqueName}.{AITValveOperation.GVTurnValve}", true);
  285. break;
  286. case GasPanelStateType.Monitor:
  287. //InvokeClient.Instance.Service.DoOperation($"{DeviceData.UniqueName}.{AITValveOperation.GVTurnValve}", true);
  288. break;
  289. case GasPanelStateType.Recipe:
  290. InvokeClient.Instance.Service.DoOperation($"{DeviceData.UniqueName}.{AITValveOperation.GVVirtualTurnValve}", true);
  291. break;
  292. default:
  293. break;
  294. }
  295. if (Command == null)
  296. return;
  297. Command.Execute(new object[] { DeviceData.DeviceName, AITValveOperation.GVVirtualTurnValve, true });
  298. }
  299. private void CloseValve(object sender, RoutedEventArgs e)
  300. {
  301. if (IsDisableMode) return;
  302. switch (GasStateType)
  303. {
  304. case GasPanelStateType.Manual:
  305. InvokeClient.Instance.Service.DoOperation($"{DeviceData.UniqueName}.{AITValveOperation.GVTurnValve}", false);
  306. break;
  307. case GasPanelStateType.Monitor:
  308. //InvokeClient.Instance.Service.DoOperation($"{DeviceData.UniqueName}.{AITValveOperation.GVTurnValve}", false);
  309. break;
  310. case GasPanelStateType.Recipe:
  311. InvokeClient.Instance.Service.DoOperation($"{DeviceData.UniqueName}.{AITValveOperation.GVVirtualTurnValve}", false);
  312. break;
  313. default:
  314. break;
  315. }
  316. if (Command == null)
  317. return;
  318. Command.Execute(new object[] { DeviceData.DeviceName, AITValveOperation.GVVirtualTurnValve, false });
  319. }
  320. private void AITGasValve_OnLoaded(object sender, RoutedEventArgs e)
  321. {
  322. imgValveOpen.Source = GetImage(ValveOpenOrientation == LineOrientation.Horizontal ? "ValveOpenVerticalJet.png" : "ValveOpenHorizontalJet.png");
  323. imgValveClose.Source = GetImage(ValveOpenOrientation == LineOrientation.Vertical ? "ValveCloseVerticalJet.png" : "ValveCloseHorizontalJet.png");
  324. if (DeviceData == null || DeviceData.IsOpen)
  325. {
  326. ValveName.Foreground = (Brush)_brushconvert.ConvertFromString("White");
  327. Application.Current.Dispatcher.BeginInvoke(new Action(() =>
  328. {
  329. Storyboard sb = this.FindResource("OpenValveStoryBoard") as Storyboard;
  330. sb.Begin();
  331. }));
  332. }
  333. else
  334. {
  335. ValveName.Foreground = (Brush)_brushconvert.ConvertFromString("Black");
  336. Application.Current.Dispatcher.BeginInvoke(new Action(() =>
  337. {
  338. Storyboard sb = this.FindResource("CloseValveStoryBoard") as Storyboard;
  339. sb.Begin();
  340. }));
  341. }
  342. //valveTimer.Start();
  343. }
  344. private void imgValveClose_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
  345. {
  346. if (e.StylusDevice != null) e.Handled = true;//认为误触,直接标记成已处理
  347. else imgValve_TouchUp(sender, null);
  348. }
  349. private void imgValve_TouchUp(object sender, TouchEventArgs e)
  350. {
  351. if (IsShowSwitchDialog)
  352. {
  353. dialog = new SwitchDialog { };
  354. dialog.IsOpen = GasStateType == GasPanelStateType.Recipe ? IsVirtualSwitchOpen : IsSwitchOpen;
  355. dialog.Owner = AITGasOwner;
  356. dialog.Topmost = true;
  357. dialog.WindowStartupLocation = WindowStartupLocation.CenterScreen;
  358. dialog.DeviceName = "Valve Name: " + DeviceData.DeviceName.Replace("Valve", "");
  359. dialog.ShowDialog();
  360. if ((bool)dialog.IsSave)
  361. {
  362. switch (GasStateType)
  363. {
  364. case GasPanelStateType.Manual:
  365. IsSwitchOpen = dialog.IsOpen;
  366. InvokeClient.Instance.Service.DoOperation($"{DeviceData.UniqueName}.{AITValveOperation.GVTurnValve}", dialog.IsOpen);
  367. break;
  368. case GasPanelStateType.Monitor:
  369. break;
  370. case GasPanelStateType.Recipe:
  371. IsVirtualSwitchOpen = dialog.IsOpen;
  372. InvokeClient.Instance.Service.DoOperation($"{DeviceData.UniqueName}.{AITValveOperation.GVVirtualTurnValve}", dialog.IsOpen);
  373. break;
  374. default:
  375. break;
  376. }
  377. }
  378. if (Command == null)
  379. return;
  380. Command.Execute(new object[] { DeviceData.DeviceName, AITValveOperation.GVVirtualTurnValve, IsVirtualSwitchOpen });
  381. }
  382. else
  383. {
  384. if (IsDisableMode) return;
  385. switch (GasStateType)
  386. {
  387. case GasPanelStateType.Manual:
  388. IsSwitchOpen = !IsSwitchOpen;
  389. InvokeClient.Instance.Service.DoOperation($"{DeviceData.UniqueName}.{AITValveOperation.GVTurnValve}", IsSwitchOpen);
  390. break;
  391. case GasPanelStateType.Monitor:
  392. break;
  393. case GasPanelStateType.Recipe:
  394. IsVirtualSwitchOpen = !IsVirtualSwitchOpen;
  395. InvokeClient.Instance.Service.DoOperation($"{DeviceData.UniqueName}.{AITValveOperation.GVVirtualTurnValve}", IsVirtualSwitchOpen);
  396. break;
  397. default:
  398. break;
  399. }
  400. if (Command == null)
  401. return;
  402. Command.Execute(new object[] { DeviceData.DeviceName, AITValveOperation.GVVirtualTurnValve, IsVirtualSwitchOpen });
  403. }
  404. }
  405. }
  406. }