AITGasIIIValve.xaml.cs 23 KB

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