AITGasIIIValve.xaml.cs 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544
  1. using Aitex.Core.Common.DeviceData;
  2. using Aitex.Core.UI.Control;
  3. using Aitex.Core.Util;
  4. using MECF.Framework.Common.OperationCenter;
  5. using MECF.Framework.UI.Core.Control;
  6. using MECF.Framework.UI.Core.ExtendedControls;
  7. using System;
  8. using System.Windows;
  9. using System.Windows.Controls;
  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.Threading;
  15. namespace Aitex.Core.UI.DeviceControl
  16. {
  17. /// <summary>
  18. /// AITGasIIIValve.xaml 的交互逻辑
  19. /// </summary>
  20. public partial class AITGasIIIValve : UserControl
  21. {
  22. public AITGasIIIValve()
  23. {
  24. InitializeComponent();
  25. }
  26. // define dependency properties
  27. public static readonly DependencyProperty CommandProperty = DependencyProperty.Register(
  28. "Command", typeof(ICommand), typeof(AITGasIIIValve),
  29. new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.AffectsRender));
  30. public ICommand Command
  31. {
  32. get
  33. {
  34. return (ICommand)this.GetValue(CommandProperty);
  35. }
  36. set
  37. {
  38. this.SetValue(CommandProperty, value);
  39. }
  40. }
  41. public Window AITGasOwner { get; set; }
  42. public bool IsSwitchOpen { get; set; }
  43. public BrushConverter _brushconvert = new BrushConverter();
  44. public bool IsVirtualSwitchOpen { get; set; }
  45. private SwitchDialog dialog;
  46. private string _valveDisplayName = "";
  47. public string ValveDisplayName
  48. {
  49. get => _valveDisplayName;
  50. set
  51. {
  52. _valveDisplayName = value;
  53. }
  54. }
  55. public bool IsN2PurgeView
  56. {
  57. get { return (bool)this.GetValue(IsN2PurgeViewProperty); }
  58. set { this.SetValue(IsN2PurgeViewProperty, value); }
  59. }
  60. // Using a DependencyProperty as the backing store for MenuVisibility. This enables animation, styling, binding, etc...
  61. public static readonly DependencyProperty IsN2PurgeViewProperty =
  62. DependencyProperty.Register("IsN2PurgeView", typeof(bool), typeof(AITGasIIIValve),
  63. new FrameworkPropertyMetadata(false));
  64. public bool IsSim
  65. {
  66. get { return (bool)this.GetValue(IsSimProperty); }
  67. set { this.SetValue(IsSimProperty, value); }
  68. }
  69. // Using a DependencyProperty as the backing store for MenuVisibility. This enables animation, styling, binding, etc...
  70. public static readonly DependencyProperty IsSimProperty =
  71. DependencyProperty.Register("IsSim", typeof(bool), typeof(AITGasIIIValve),
  72. new FrameworkPropertyMetadata(false));
  73. Storyboard sb;
  74. public Visibility MenuVisibility
  75. {
  76. get { return (Visibility)this.GetValue(MenuVisibilityProperty); }
  77. set { this.SetValue(MenuVisibilityProperty, value); }
  78. }
  79. // Using a DependencyProperty as the backing store for MenuVisibility. This enables animation, styling, binding, etc...
  80. public static readonly DependencyProperty MenuVisibilityProperty =
  81. DependencyProperty.Register("MenuVisibility", typeof(Visibility), typeof(AITGasIIIValve),
  82. new FrameworkPropertyMetadata(Visibility.Visible));
  83. public static readonly DependencyProperty DeviceDataProperty = DependencyProperty.Register(
  84. "DeviceData", typeof(AITValveData), typeof(AITGasIIIValve),
  85. new FrameworkPropertyMetadata(new AITValveData(), FrameworkPropertyMetadataOptions.AffectsRender));
  86. public AITValveData DeviceData
  87. {
  88. get
  89. {
  90. var data = (AITValveData)this.GetValue(DeviceDataProperty);
  91. switch (GasStateType)
  92. {
  93. case GasPanelStateType.Manual:
  94. case GasPanelStateType.Monitor:
  95. {
  96. rdTrig.CLK = (data == null || data.IsOpen);
  97. flickerTrig.CLK = (data == null || data.IsOpen) && data.IsILKOK;
  98. if (flickerTrig.R)
  99. {
  100. Application.Current.Dispatcher.BeginInvoke(new Action(() =>
  101. {
  102. ValveName.Foreground = (Brush)_brushconvert.ConvertFromString("White");
  103. if (sb != null)
  104. {
  105. sb.Stop();
  106. sb.Remove();
  107. }
  108. sb = this.FindResource("OpenValveStoryBoard") as Storyboard;
  109. sb.Begin();
  110. }));
  111. }
  112. if (rdTrig.R)
  113. {
  114. if (data.IsILKOK)
  115. {
  116. Application.Current.Dispatcher.BeginInvoke(new Action(() =>
  117. {
  118. ValveName.Foreground = (Brush)_brushconvert.ConvertFromString("White");
  119. if (sb != null)
  120. {
  121. sb.Stop();
  122. sb.Remove();
  123. }
  124. sb = this.FindResource("OpenValveStoryBoard") as Storyboard;
  125. sb.Begin();
  126. }));
  127. }
  128. else
  129. {
  130. Application.Current.Dispatcher.BeginInvoke(new Action(() =>
  131. {
  132. ValveName.Foreground = (Brush)_brushconvert.ConvertFromString("White");
  133. if (sb != null)
  134. {
  135. sb.Stop();
  136. sb.Remove();
  137. }
  138. sb = this.FindResource("FlickerValveStoryBoard") as Storyboard;
  139. sb.Begin();
  140. }));
  141. }
  142. }
  143. if (rdTrig.T)
  144. {
  145. Application.Current.Dispatcher.BeginInvoke(new Action(() =>
  146. {
  147. ValveName.Foreground = (Brush)_brushconvert.ConvertFromString("Black");
  148. if (sb != null)
  149. {
  150. sb.Stop();
  151. sb.Remove();
  152. }
  153. sb = this.FindResource("CloseValveStoryBoard") as Storyboard;
  154. sb.Begin();
  155. }));
  156. }
  157. }
  158. break;
  159. case GasPanelStateType.Recipe:
  160. rdTrig.CLK = (data == null || data.VirtualFeedback);
  161. if (rdTrig.R)
  162. {
  163. Application.Current.Dispatcher.BeginInvoke(new Action(() =>
  164. {
  165. ValveName.Foreground = (Brush)_brushconvert.ConvertFromString("White");
  166. if (sb != null)
  167. {
  168. sb.Stop();
  169. sb.Remove();
  170. }
  171. sb = this.FindResource("OpenValveStoryBoard") as Storyboard;
  172. sb.Begin();
  173. }));
  174. IsVirtualSwitchOpen = true;
  175. }
  176. if (rdTrig.T)
  177. {
  178. Application.Current.Dispatcher.BeginInvoke(new Action(() =>
  179. {
  180. ValveName.Foreground = (Brush)_brushconvert.ConvertFromString("Black");
  181. if (sb != null)
  182. {
  183. sb.Stop();
  184. sb.Remove();
  185. }
  186. sb = this.FindResource("CloseValveStoryBoard") as Storyboard;
  187. sb.Begin();
  188. }));
  189. IsVirtualSwitchOpen = false;
  190. }
  191. break;
  192. default:
  193. break;
  194. }
  195. return data;
  196. }
  197. set
  198. {
  199. this.SetValue(DeviceDataProperty, value);
  200. }
  201. }
  202. public static readonly DependencyProperty GasPanelStateTypeProperty = DependencyProperty.Register(
  203. "GasStateType", typeof(GasPanelStateType), typeof(AITGasIIIValve),
  204. new FrameworkPropertyMetadata(GasPanelStateType.Manual, FrameworkPropertyMetadataOptions.AffectsRender));
  205. public GasPanelStateType GasStateType
  206. {
  207. get
  208. {
  209. return (GasPanelStateType)this.GetValue(GasPanelStateTypeProperty);
  210. }
  211. set
  212. {
  213. this.SetValue(GasPanelStateTypeProperty, value);
  214. }
  215. }
  216. public bool IsShowSwitchDialog
  217. {
  218. get { return (bool)GetValue(IsShowSwitchDialogProperty); }
  219. set { SetValue(IsShowSwitchDialogProperty, value); }
  220. }
  221. // Using a DependencyProperty as the backing store for IsShowSwitchDialog. This enables animation, styling, binding, etc...
  222. public static readonly DependencyProperty IsShowSwitchDialogProperty =
  223. DependencyProperty.Register("IsShowSwitchDialog", typeof(bool), typeof(AITGasIIIValve), new PropertyMetadata(false));
  224. public static readonly DependencyProperty DeviceData2Property = DependencyProperty.Register(
  225. "DeviceData2", typeof(AITValveData), typeof(AITGasIIIValve),
  226. new FrameworkPropertyMetadata(new AITValveData(), FrameworkPropertyMetadataOptions.AffectsRender));
  227. public AITValveData DeviceData2
  228. {
  229. get
  230. {
  231. return (AITValveData)this.GetValue(DeviceData2Property);
  232. }
  233. set
  234. {
  235. this.SetValue(DeviceData2Property, value);
  236. }
  237. }
  238. public static readonly DependencyProperty ValveOpenOrientationProperty = DependencyProperty.Register(
  239. "ValveOpenOrientation", typeof(LineOrientation), typeof(AITGasIIIValve),
  240. new FrameworkPropertyMetadata(LineOrientation.Horizontal, FrameworkPropertyMetadataOptions.AffectsRender));
  241. public LineOrientation ValveOpenOrientation
  242. {
  243. get { return (LineOrientation)GetValue(ValveOpenOrientationProperty); }
  244. set { SetValue(ValveOpenOrientationProperty, value); }
  245. }
  246. public static readonly DependencyProperty IsDisableModeProperty = DependencyProperty.Register(
  247. "IsDisableMode", typeof(bool), typeof(AITGasIIIValve),
  248. new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.AffectsRender));
  249. public bool IsDisableMode
  250. {
  251. get { return (bool)GetValue(IsDisableModeProperty); }
  252. set { SetValue(IsDisableModeProperty, value); }
  253. }
  254. public bool IsOpen => DeviceData == null || DeviceData.IsOpen;
  255. private DispatcherTimer valveTimer = new DispatcherTimer();
  256. RD_TRIG rdTrig = new RD_TRIG();
  257. RD_TRIG flickerTrig = new RD_TRIG();
  258. private BitmapSource GetImage(string name)
  259. {
  260. return new BitmapImage(new Uri(string.Format("pack://application:,,,/MECF.Framework.Common;component/Resources/Valve/{0}", name)));
  261. }
  262. protected override void OnRender(DrawingContext drawingContext)
  263. {
  264. var data = (AITValveData)this.GetValue(DeviceDataProperty);
  265. if (data != null)
  266. {
  267. ValveName.Text = DeviceData.DisplayName.Replace("ValveAV", "");
  268. if ((DeviceData.Feedback && GasStateType == GasPanelStateType.Manual) || (DeviceData.Feedback && GasStateType == GasPanelStateType.Monitor)
  269. || (DeviceData.VirtualFeedback && GasStateType == GasPanelStateType.Recipe))
  270. {
  271. if (!DeviceData.IsILKOK && !(GasStateType == GasPanelStateType.Recipe))
  272. {
  273. Application.Current.Dispatcher.BeginInvoke(new Action(() =>
  274. {
  275. ValveName.Foreground = (Brush)_brushconvert.ConvertFromString("White");
  276. if (sb != null)
  277. {
  278. sb.Stop();
  279. sb.Remove();
  280. }
  281. sb = this.FindResource("FlickerValveStoryBoard") as Storyboard;
  282. sb.Begin();
  283. }));
  284. }
  285. else if (DeviceData.IsILKOK && !DeviceData.Feedback && !(GasStateType == GasPanelStateType.Recipe))
  286. {
  287. Application.Current.Dispatcher.BeginInvoke(new Action(() =>
  288. {
  289. ValveName.Foreground = (Brush)_brushconvert.ConvertFromString("Black");
  290. if (sb != null)
  291. {
  292. sb.Stop();
  293. sb.Remove();
  294. }
  295. sb = this.FindResource("CloseValveStoryBoard") as Storyboard;
  296. sb.Begin();
  297. }));
  298. }
  299. else
  300. {
  301. Application.Current.Dispatcher.BeginInvoke(new Action(() =>
  302. {
  303. ValveName.Foreground = (Brush)_brushconvert.ConvertFromString("White");
  304. if (sb != null)
  305. {
  306. sb.Stop();
  307. sb.Remove();
  308. }
  309. sb = this.FindResource("OpenValveStoryBoard") as Storyboard;
  310. sb.Begin();
  311. }));
  312. }
  313. }
  314. else
  315. {
  316. Application.Current.Dispatcher.BeginInvoke(new Action(() =>
  317. {
  318. ValveName.Foreground = (Brush)_brushconvert.ConvertFromString("Black");
  319. if (sb != null)
  320. {
  321. sb.Stop();
  322. sb.Remove();
  323. }
  324. sb = this.FindResource("CloseValveStoryBoard") as Storyboard;
  325. sb.Begin();
  326. }));
  327. }
  328. this.ToolTip =
  329. $"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}";
  330. }
  331. else
  332. {
  333. Application.Current.Dispatcher.BeginInvoke(new Action(() =>
  334. {
  335. ValveName.Foreground = (Brush)_brushconvert.ConvertFromString("Black");
  336. if (sb != null)
  337. {
  338. sb.Stop();
  339. sb.Remove();
  340. }
  341. sb = this.FindResource("CloseValveStoryBoard") as Storyboard;
  342. sb.Begin();
  343. }));
  344. }
  345. base.OnRender(drawingContext);
  346. }
  347. private void OpenValve(object sender, RoutedEventArgs e)
  348. {
  349. if (IsDisableMode) return;
  350. switch (GasStateType)
  351. {
  352. case GasPanelStateType.Manual:
  353. InvokeClient.Instance.Service.DoOperation($"{DeviceData.UniqueName}.{AITValveOperation.GVTurnValve}", true);
  354. break;
  355. case GasPanelStateType.Monitor:
  356. //InvokeClient.Instance.Service.DoOperation($"{DeviceData.UniqueName}.{AITValveOperation.GVTurnValve}", true);
  357. break;
  358. case GasPanelStateType.Recipe:
  359. InvokeClient.Instance.Service.DoOperation($"{DeviceData.UniqueName}.{AITValveOperation.GVVirtualTurnValve}", true);
  360. break;
  361. default:
  362. break;
  363. }
  364. if (Command == null)
  365. return;
  366. Command.Execute(new object[] { DeviceData.DeviceName, AITValveOperation.GVVirtualTurnValve, true });
  367. }
  368. private void CloseValve(object sender, RoutedEventArgs e)
  369. {
  370. if (IsDisableMode) return;
  371. switch (GasStateType)
  372. {
  373. case GasPanelStateType.Manual:
  374. InvokeClient.Instance.Service.DoOperation($"{DeviceData.UniqueName}.{AITValveOperation.GVTurnValve}", false);
  375. break;
  376. case GasPanelStateType.Monitor:
  377. //InvokeClient.Instance.Service.DoOperation($"{DeviceData.UniqueName}.{AITValveOperation.GVTurnValve}", false);
  378. break;
  379. case GasPanelStateType.Recipe:
  380. InvokeClient.Instance.Service.DoOperation($"{DeviceData.UniqueName}.{AITValveOperation.GVVirtualTurnValve}", false);
  381. break;
  382. default:
  383. break;
  384. }
  385. if (Command == null)
  386. return;
  387. Command.Execute(new object[] { DeviceData.DeviceName, AITValveOperation.GVVirtualTurnValve, false });
  388. }
  389. private void AITGasValve_OnLoaded(object sender, RoutedEventArgs e)
  390. {
  391. imgValveOpen.Source = GetImage(ValveOpenOrientation == LineOrientation.Horizontal ? "ValveOpenVerticalJet.png" : "ValveOpenHorizontalJet.png");
  392. imgValveClose.Source = GetImage(ValveOpenOrientation == LineOrientation.Vertical ? "ValveCloseVerticalJet.png" : "ValveCloseHorizontalJet.png");
  393. if (DeviceData == null || DeviceData.IsOpen)
  394. {
  395. Application.Current.Dispatcher.BeginInvoke(new Action(() =>
  396. {
  397. ValveName.Foreground = (Brush)_brushconvert.ConvertFromString("White");
  398. if (sb != null)
  399. {
  400. sb.Stop();
  401. sb.Remove();
  402. }
  403. sb = this.FindResource("OpenValveStoryBoard") as Storyboard;
  404. sb.Begin();
  405. }));
  406. }
  407. else
  408. {
  409. Application.Current.Dispatcher.BeginInvoke(new Action(() =>
  410. {
  411. ValveName.Foreground = (Brush)_brushconvert.ConvertFromString("Black");
  412. if (sb != null)
  413. {
  414. sb.Stop();
  415. sb.Remove();
  416. }
  417. sb = this.FindResource("CloseValveStoryBoard") as Storyboard;
  418. sb.Begin();
  419. }));
  420. }
  421. //valveTimer.Start();
  422. }
  423. private void imgValveClose_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
  424. {
  425. if (e.StylusDevice != null) e.Handled = true;//认为误触,直接标记成已处理
  426. else imgValve_TouchUp(sender, null);
  427. }
  428. private void imgValve_TouchUp(object sender, TouchEventArgs e)
  429. {
  430. if (IsShowSwitchDialog)
  431. {
  432. dialog = new SwitchDialog { };
  433. dialog.IsOpen = GasStateType == GasPanelStateType.Recipe ? IsVirtualSwitchOpen : IsSwitchOpen;
  434. dialog.Owner = AITGasOwner;
  435. dialog.Topmost = true;
  436. dialog.WindowStartupLocation = WindowStartupLocation.CenterScreen;
  437. dialog.DeviceName = "Valve Name: " + DeviceData.DeviceName.Replace("Valve", "");
  438. dialog.ShowDialog();
  439. if ((bool)dialog.IsSave)
  440. {
  441. switch (GasStateType)
  442. {
  443. case GasPanelStateType.Manual:
  444. IsSwitchOpen = dialog.IsOpen;
  445. InvokeClient.Instance.Service.DoOperation($"{DeviceData.UniqueName}.{AITValveOperation.GVTurnValve}", dialog.IsOpen);
  446. break;
  447. case GasPanelStateType.Monitor:
  448. break;
  449. case GasPanelStateType.Recipe:
  450. IsVirtualSwitchOpen = dialog.IsOpen;
  451. InvokeClient.Instance.Service.DoOperation($"{DeviceData.UniqueName}.{AITValveOperation.GVVirtualTurnValve}", dialog.IsOpen);
  452. break;
  453. default:
  454. break;
  455. }
  456. }
  457. if (Command == null)
  458. return;
  459. Command.Execute(new object[] { DeviceData.DeviceName, AITValveOperation.GVVirtualTurnValve, IsVirtualSwitchOpen });
  460. }
  461. else
  462. {
  463. if (IsN2PurgeView)
  464. {
  465. IsSwitchOpen = DeviceData.Feedback;
  466. IsSwitchOpen = !IsSwitchOpen;
  467. IsVirtualSwitchOpen = IsSwitchOpen;
  468. }
  469. else
  470. {
  471. //if (IsDisableMode) return;
  472. switch (GasStateType)
  473. {
  474. case GasPanelStateType.Manual:
  475. DeviceData.Feedback = !DeviceData.IsOpen;
  476. rdTrig.CLK = (DeviceData == null || DeviceData.IsOpen);
  477. IsSwitchOpen = DeviceData.Feedback;
  478. //IsSwitchOpen = !IsSwitchOpen;
  479. //InvokeClient.Instance.Service.DoOperation($"{DeviceData.UniqueName}.{AITValveOperation.GVTurnValve}", IsSwitchOpen);
  480. break;
  481. case GasPanelStateType.Monitor:
  482. break;
  483. case GasPanelStateType.Recipe:
  484. IsVirtualSwitchOpen = !IsVirtualSwitchOpen;
  485. InvokeClient.Instance.Service.DoOperation($"{DeviceData.UniqueName}.{AITValveOperation.GVVirtualTurnValve}", IsVirtualSwitchOpen);
  486. break;
  487. default:
  488. break;
  489. }
  490. }
  491. if (Command == null)
  492. return;
  493. Command.Execute(new object[] { DeviceData.DeviceName, AITValveOperation.GVVirtualTurnValve, IsVirtualSwitchOpen });
  494. }
  495. }
  496. }
  497. }