AITGasIIIValve.xaml.cs 20 KB

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