AITGasIIIValve.xaml.cs 25 KB

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