LeakCheckViewModel.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516
  1. using System;
  2. using System.IO;
  3. using System.Collections.Generic;
  4. using System.Collections.ObjectModel;
  5. using System.Linq;
  6. using System.Windows;
  7. using Aitex.Core.RT.Log;
  8. using Aitex.Core.UI.ControlDataContext;
  9. using Aitex.Core.Utilities;
  10. using Aitex.Sorter.Common;
  11. using Virgo_DUI.Client.Models.Sys;
  12. using MECF.Framework.Common.DataCenter;
  13. using OpenSEMI.ClientBase;
  14. using OpenSEMI.ClientBase.IO;
  15. using ExcelLibrary.SpreadSheet;
  16. using MECF.Framework.Common.OperationCenter;
  17. using Aitex.Core.Util;
  18. using Virgo_DCommon;
  19. using Aitex.Core.Common.DeviceData;
  20. using Aitex.Core.RT.SCCore;
  21. namespace Virgo_DUI.Client.Models.PMs
  22. {
  23. public class LeakCheckViewModel : ModuleUiViewModelBase, ISupportMultipleSystem
  24. {
  25. #region
  26. private int MenuPermission;
  27. private bool _isEnableGasLine;
  28. public bool IsEnableGasLine
  29. {
  30. get
  31. {
  32. return (LeakCheckModeSetPoint == "ChamberAndGasLine" || LeakCheckModeSetPoint == "ChamberAndGasLineAndFAC") && IsLeakCheckEnabled;
  33. }
  34. set
  35. {
  36. _isEnableGasLine = value;
  37. NotifyOfPropertyChange("IsEnableGasLine");
  38. }
  39. }
  40. #region GasLine
  41. public bool IsEnableGas1Line
  42. {
  43. get
  44. {
  45. bool originalCondition = (LeakCheckModeSetPoint == "ChamberAndGasLine" ||
  46. LeakCheckModeSetPoint == "ChamberAndGasLineAndFAC") &&
  47. IsLeakCheckEnabled;
  48. string configValue = QueryDataClient.Instance.Service.GetConfig($"{SystemName}.MfcGas1.Enable").ToString(); // GasIndex 表示当前气体管路序号(1/2/3/4)
  49. //string configValue = QueryDataClient.Instance.Service.GetConfig(configKey)?.ToString();
  50. bool isGasEnabled = bool.TryParse(configValue, out bool result) ? result : false;
  51. return originalCondition && isGasEnabled;
  52. }
  53. set
  54. {
  55. _isEnableGasLine = value;
  56. NotifyOfPropertyChange("IsEnableGasLine");
  57. }
  58. }
  59. public bool IsEnableGas2Line
  60. {
  61. get
  62. {
  63. bool originalCondition = (LeakCheckModeSetPoint == "ChamberAndGasLine" ||
  64. LeakCheckModeSetPoint == "ChamberAndGasLineAndFAC") &&
  65. IsLeakCheckEnabled;
  66. string configValue = QueryDataClient.Instance.Service.GetConfig($"{SystemName}.MfcGas2.Enable").ToString(); // GasIndex 表示当前气体管路序号(1/2/3/4)
  67. //string configValue = QueryDataClient.Instance.Service.GetConfig(configKey)?.ToString();
  68. bool isGasEnabled = bool.TryParse(configValue, out bool result) ? result : false;
  69. return originalCondition && isGasEnabled;
  70. }
  71. set
  72. {
  73. _isEnableGasLine = value;
  74. NotifyOfPropertyChange("IsEnableGasLine");
  75. }
  76. }
  77. public bool IsEnableGas3Line
  78. {
  79. get
  80. {
  81. bool originalCondition = (LeakCheckModeSetPoint == "ChamberAndGasLine" ||
  82. LeakCheckModeSetPoint == "ChamberAndGasLineAndFAC") &&
  83. IsLeakCheckEnabled;
  84. string configValue = QueryDataClient.Instance.Service.GetConfig($"{SystemName}.MfcGas3.Enable").ToString(); // GasIndex 表示当前气体管路序号(1/2/3/4)
  85. //string configValue = QueryDataClient.Instance.Service.GetConfig(configKey)?.ToString();
  86. bool isGasEnabled = bool.TryParse(configValue, out bool result) ? result : false;
  87. return originalCondition && isGasEnabled;
  88. }
  89. set
  90. {
  91. _isEnableGasLine = value;
  92. NotifyOfPropertyChange("IsEnableGasLine");
  93. }
  94. }
  95. public bool IsEnableGas4Line
  96. {
  97. get
  98. {
  99. bool originalCondition = (LeakCheckModeSetPoint == "ChamberAndGasLine" ||
  100. LeakCheckModeSetPoint == "ChamberAndGasLineAndFAC") &&
  101. IsLeakCheckEnabled;
  102. string configValue = QueryDataClient.Instance.Service.GetConfig($"{SystemName}.MfcGas4.Enable").ToString(); // GasIndex 表示当前气体管路序号(1/2/3/4)
  103. //string configValue = QueryDataClient.Instance.Service.GetConfig(configKey)?.ToString();
  104. bool isGasEnabled = bool.TryParse(configValue, out bool result) ? result : false;
  105. return originalCondition && isGasEnabled;
  106. }
  107. set
  108. {
  109. _isEnableGasLine = value;
  110. NotifyOfPropertyChange("IsEnableGasLine");
  111. }
  112. }
  113. public bool IsEnableMasterGasline
  114. {
  115. get
  116. {
  117. return (LeakCheckModeSetPoint == "ChamberAndGasLine" || LeakCheckModeSetPoint == "ChamberAndGasLineAndFAC") && IsLeakCheckEnabled;
  118. }
  119. set
  120. {
  121. _isEnableGasLine = value;
  122. NotifyOfPropertyChange("IsEnableMasterGasline");
  123. }
  124. }
  125. #endregion
  126. public bool IsLeakCheckEnabled
  127. {
  128. get
  129. {
  130. return IsManualMode && !IsLeakCheck;
  131. }
  132. }
  133. [IgnorePropertyChange]
  134. public string LeakCheckModeSetPoint
  135. {
  136. get;
  137. set;
  138. }
  139. [IgnorePropertyChange]
  140. public string LeakCheckPumpDownTimeSetPoint
  141. {
  142. get;
  143. set;
  144. }
  145. [IgnorePropertyChange]
  146. public string LeakCheckTimeSetPoint
  147. {
  148. get;
  149. set;
  150. }
  151. [IgnorePropertyChange]
  152. public string LeakRateUpperLimitSetPoint
  153. {
  154. get;
  155. set;
  156. }
  157. [IgnorePropertyChange]
  158. public string LeakCheckFlowScale
  159. {
  160. get;
  161. set;
  162. }
  163. [Subscription("IoMfc.MfcGas1.IsEnable")]
  164. public bool MfcGas1Enable
  165. {
  166. get;
  167. set;
  168. }
  169. [Subscription("IoMfc.MfcGas2.IsEnable")]
  170. public bool MfcGas2Enable
  171. {
  172. get;
  173. set;
  174. }
  175. [Subscription("IoMfc.MfcGas3.IsEnable")]
  176. public bool MfcGas3Enable
  177. {
  178. get;
  179. set;
  180. }
  181. [Subscription("IoMfc.MfcGas4.IsEnable")]
  182. public bool MfcGas4Enable
  183. {
  184. get;
  185. set;
  186. }
  187. //[Subscription("IoMfc.MfcGas5.IsEnable")]
  188. //public bool MfcGas5Enable
  189. //{
  190. // get;
  191. // set;
  192. //}
  193. private bool _enableGasLine1;
  194. public bool EnableGasLine1
  195. {
  196. get
  197. {
  198. return _enableGasLine1;
  199. }
  200. set
  201. {
  202. _enableGasLine1 = value;
  203. NotifyOfPropertyChange("EnableGasLine1");
  204. }
  205. }
  206. private bool _enableGasLine2;
  207. public bool EnableGasLine2
  208. {
  209. get
  210. {
  211. return _enableGasLine2;
  212. }
  213. set
  214. {
  215. _enableGasLine2 = value;
  216. NotifyOfPropertyChange("EnableGasLine2");
  217. }
  218. }
  219. private bool _enableGasLine3;
  220. public bool EnableGasLine3
  221. {
  222. get
  223. {
  224. return _enableGasLine3;
  225. }
  226. set
  227. {
  228. _enableGasLine3 = value;
  229. NotifyOfPropertyChange("EnableGasLine3");
  230. }
  231. }
  232. private bool _enableGasLine4;
  233. public bool EnableGasLine4
  234. {
  235. get
  236. {
  237. return _enableGasLine4;
  238. }
  239. set
  240. {
  241. _enableGasLine4 = value;
  242. NotifyOfPropertyChange("EnableGasLine4");
  243. }
  244. }
  245. private bool _enableGasLine5;
  246. public bool EnableGasLine5
  247. {
  248. get
  249. {
  250. return _enableGasLine5;
  251. }
  252. set
  253. {
  254. _enableGasLine5 = value;
  255. NotifyOfPropertyChange("EnableGasLine5");
  256. }
  257. }
  258. private bool _masterGasLineControl;
  259. public bool MasterGasLineControl
  260. {
  261. get => _masterGasLineControl;
  262. set
  263. {
  264. if (_masterGasLineControl == value) return;
  265. _masterGasLineControl = value;
  266. // 动态获取各气体管道的配置状态
  267. bool gas1Enabled = GetGasConfigState("MfcGas1");
  268. bool gas2Enabled = GetGasConfigState("MfcGas2");
  269. bool gas3Enabled = GetGasConfigState("MfcGas3");
  270. bool gas4Enabled = GetGasConfigState("MfcGas4");
  271. // 仅操作配置启用的管道
  272. if (gas1Enabled) EnableGasLine1 = value;
  273. if (gas2Enabled) EnableGasLine2 = value;
  274. if (gas3Enabled) EnableGasLine3 = value;
  275. if (gas4Enabled) EnableGasLine4 = value;
  276. NotifyOfPropertyChange(nameof(MasterGasLineControl));
  277. }
  278. }
  279. private bool GetGasConfigState(string gasName)
  280. {
  281. string configKey = $"{SystemName}.{gasName}.Enable";
  282. string configValue = QueryDataClient.Instance.Service.GetConfig(configKey)?.ToString();
  283. return bool.TryParse(configValue, out bool result) && result; // 配置无效时默认禁用
  284. }
  285. [Subscription(Virgo_DDevice.ProcessGauge)]
  286. public AITPressureMeterData ProcessGauge { get; set; }
  287. [Subscription(Virgo_DDevice.PressureGauge)]
  288. public AITPressureMeterData PressureGauge { get; set; }
  289. [Subscription(Virgo_DDevice.ForelineGauge)]
  290. public AITPressureMeterData ForelineGauge { get; set; }
  291. [Subscription("LeakCheckElapseTime")]
  292. public string LeakCheckElapseTime
  293. {
  294. get;
  295. set;
  296. }
  297. public List<LeakCheckResultItem> LeakCheckResultList
  298. {
  299. get;
  300. set;
  301. }
  302. [Subscription("IsAutoMode")]
  303. public bool IsAutoMode
  304. {
  305. get;
  306. set;
  307. }
  308. [Subscription(StateData.PMState)]
  309. public int PMStatus
  310. {
  311. get;
  312. set;
  313. }
  314. public string Status
  315. {
  316. get
  317. {
  318. return ((PMState)PMStatus).ToString();
  319. }
  320. }
  321. public string Pressure
  322. {
  323. get
  324. {
  325. return ProcessGauge == null ? "0" : ProcessGauge.FeedBack.ToString("F0") + ProcessGauge.Unit;
  326. }
  327. }
  328. public bool IsLeakCheck
  329. {
  330. get
  331. {
  332. return (PMState)PMStatus == PMState.LeakCheck;
  333. }
  334. }
  335. public bool IsManualMode
  336. {
  337. get
  338. {
  339. return !IsAutoMode;
  340. }
  341. }
  342. public bool IsEnableLeakCheck
  343. {
  344. get
  345. {
  346. return !IsAutoMode && (PMState)PMStatus == PMState.Idle;
  347. }
  348. }
  349. public LeakCheckResultItem CurrentLeakCheckResultItem
  350. {
  351. get;
  352. set;
  353. }
  354. F_TRIG _trigLeakCheckFinished = new F_TRIG();
  355. #endregion
  356. public LeakCheckViewModel()
  357. {
  358. LeakCheckModeSetPoint = LeakCheckMode.ChamberOnly.ToString();
  359. EnableGasLine1 = true;
  360. EnableGasLine2 = true;
  361. EnableGasLine3 = true;
  362. EnableGasLine4 = true;
  363. NotifyOfPropertyChange("EnableGasLine1");
  364. NotifyOfPropertyChange("EnableGasLine2");
  365. NotifyOfPropertyChange("EnableGasLine3");
  366. NotifyOfPropertyChange("EnableGasLine4");
  367. }
  368. protected override void OnInitialize()
  369. {
  370. base.OnInitialize();
  371. }
  372. protected override void OnActivate()
  373. {
  374. base.OnActivate();
  375. LeakCheckPumpDownTimeSetPoint = QueryDataClient.Instance.Service.GetConfig($"{SystemName}.Pump.LeakCheckPumpingTime").ToString();
  376. LeakCheckTimeSetPoint = QueryDataClient.Instance.Service.GetConfig($"{SystemName}.Pump.LeakCheckWaitTime").ToString();
  377. LeakRateUpperLimitSetPoint = ((float)(double)QueryDataClient.Instance.Service.GetConfig($"{SystemName}.Pump.LeakRate")).ToString();
  378. }
  379. public void UpdateLeakCheckResult(string Module)
  380. {
  381. LeakCheckResultList = QueryDataClient.Instance.Service.GetHistoryLeakCheck(Module);
  382. InvokePropertyChanged("LeakCheckResultList");
  383. }
  384. protected override void InvokeBeforeUpdateProperty(Dictionary<string, object> data)
  385. {
  386. MenuPermission = ClientApp.Instance.GetPermission($"LeakCheck{SystemName}");
  387. if (!MfcGas1Enable) EnableGasLine1 = false;
  388. if (!MfcGas2Enable) EnableGasLine2 = false;
  389. if (!MfcGas3Enable) EnableGasLine3 = false;
  390. if (!MfcGas4Enable) EnableGasLine4 = false;
  391. //if (!MfcGas5Enable) EnableGasLine5 = false;
  392. _trigLeakCheckFinished.CLK = IsLeakCheck;
  393. if (_trigLeakCheckFinished.Q)
  394. {
  395. Application.Current.Dispatcher.Invoke(new Action(() =>
  396. {
  397. UpdateLeakCheckResult(SystemName);
  398. }));
  399. }
  400. }
  401. protected override void InvokeAfterUpdateProperty(Dictionary<string, object> data)
  402. {
  403. if (CurrentLeakCheckResultItem == null)
  404. {
  405. UpdateLeakCheckResult(SystemName);
  406. ;
  407. }
  408. }
  409. public void LeakCheck()
  410. {
  411. if (MenuPermission != 3) return;
  412. if (!IsLeakCheck)
  413. {
  414. InvokeClient.Instance.Service.DoOperation("System.SetConfig", $"{SystemName}.Pump.LeakCheckPumpingTime", LeakCheckPumpDownTimeSetPoint.ToString());
  415. InvokeClient.Instance.Service.DoOperation("System.SetConfig", $"{SystemName}.Pump.LeakCheckWaitTime", LeakCheckTimeSetPoint.ToString());
  416. InvokeClient.Instance.Service.DoOperation("System.SetConfig", $"{SystemName}.Pump.LeakRate", LeakRateUpperLimitSetPoint.ToString());
  417. InvokeClient.Instance.Service.DoOperation($"{SystemName}.LeakCheck", new[]
  418. {
  419. LeakCheckPumpDownTimeSetPoint,
  420. LeakCheckTimeSetPoint,
  421. LeakCheckModeSetPoint,
  422. LeakRateUpperLimitSetPoint,
  423. EnableGasLine1.ToString(),
  424. EnableGasLine2.ToString(),
  425. EnableGasLine3.ToString(),
  426. EnableGasLine4.ToString(),
  427. EnableGasLine5.ToString(),
  428. });
  429. }
  430. }
  431. public void AbortLeakCheck()
  432. {
  433. if (MenuPermission != 3) return;
  434. if (MessageBox.Show("Confirm to stop leak detection?", "JetPlasma", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
  435. InvokeClient.Instance.Service.DoOperation($"{SystemName}.Abort");
  436. }
  437. public void DeleteLeakCheck()
  438. {
  439. if (MenuPermission != 3) return;
  440. if (CurrentLeakCheckResultItem == null)
  441. {
  442. MessageBox.Show("Please select the leak detection record to delete first.", "JetPlasma", MessageBoxButton.OK);
  443. return;
  444. }
  445. if (MessageBox.Show("Confirm to delete the current leak detection record?", "JetPlasma", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
  446. InvokeClient.Instance.Service.DoOperation($"{SystemName}.DeleteLeakCheck", CurrentLeakCheckResultItem.Id);
  447. CurrentLeakCheckResultItem = null;
  448. }
  449. }
  450. }