SystemConfigViewModel.cs 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Collections.ObjectModel;
  4. using System.Linq;
  5. using System.Windows;
  6. using Aitex.Core.RT.IOCore;
  7. using Caliburn.Micro;
  8. using Caliburn.Micro.Core;
  9. using MECF.Framework.Common.DataCenter;
  10. using MECF.Framework.Common.IOCore;
  11. using MECF.Framework.Common.OperationCenter;
  12. using MECF.Framework.UI.Client.CenterViews.Dialogs;
  13. using MECF.Framework.UI.Client.CenterViews.Editors.Recipe;
  14. using MECF.Framework.UI.Client.CenterViews.Editors.Sequence;
  15. using MECF.Framework.UI.Client.ClientBase;
  16. using OpenSEMI.ClientBase;
  17. using OpenSEMI.ClientBase.Command;
  18. using OpenSEMI.ClientBase.IO;
  19. namespace MECF.Framework.UI.Client.CenterViews.Configs.SystemConfig
  20. {
  21. public class SystemConfigViewModel : UiViewModelBase, ISupportMultipleSystem
  22. {
  23. #region Properties
  24. public bool IsPermission { get => this.Permission == 3; }
  25. private SystemConfigView view1;
  26. private Visibility _isShowTable = Visibility.Hidden;
  27. public Visibility IsShowTable
  28. {
  29. get => _isShowTable;
  30. set
  31. {
  32. _isShowTable = value;
  33. NotifyOfPropertyChange(nameof(IsShowTable));
  34. }
  35. }
  36. private Visibility _isListData = Visibility.Hidden;
  37. public Visibility IsListData
  38. {
  39. get => _isListData;
  40. set
  41. {
  42. _isListData = value;
  43. NotifyOfPropertyChange(nameof(IsListData));
  44. }
  45. }
  46. private Visibility _isShowData = Visibility.Hidden;
  47. public Visibility IsShowData
  48. {
  49. get => _isShowData;
  50. set
  51. {
  52. _isShowData = value;
  53. NotifyOfPropertyChange(nameof(IsShowData));
  54. }
  55. }
  56. private Visibility _isShowAUX = Visibility.Hidden;
  57. public Visibility IsShowAUX
  58. {
  59. get => _isShowAUX;
  60. set
  61. {
  62. _isShowAUX = value;
  63. NotifyOfPropertyChange(nameof(IsShowAUX));
  64. }
  65. }
  66. private List<ConfigNode> _ConfigNodes = new List<ConfigNode>();
  67. public List<ConfigNode> ConfigNodes
  68. {
  69. get { return _ConfigNodes; }
  70. set { _ConfigNodes = value; NotifyOfPropertyChange("ConfigNodes"); }
  71. }
  72. private ObservableCollection<ConfigItem> _configItems = new ObservableCollection<ConfigItem>();
  73. public ObservableCollection<ConfigItem> ConfigItems
  74. {
  75. get { return _configItems; }
  76. set { _configItems = value; NotifyOfPropertyChange("ConfigItems"); }
  77. }
  78. private ObservableCollection<ConfigItem> _configAUXItems = new ObservableCollection<ConfigItem>();
  79. public ObservableCollection<ConfigItem> ConfigAUXItems
  80. {
  81. get { return _configAUXItems; }
  82. set { _configAUXItems = value; NotifyOfPropertyChange("ConfigAUXItems"); }
  83. }
  84. string _CurrentNodeName = string.Empty;
  85. public BaseCommand<ConfigNode> TreeViewSelectedItemChangedCmd { private set; get; }
  86. private ObservableCollection<PageValue> valueList { get; set; } = new ObservableCollection<PageValue>();
  87. public ObservableCollection<ListName> NameList { get; set; } = new ObservableCollection<ListName>();
  88. public ObservableCollection<AOItemFloat> AOs { get; private set; }
  89. private string _currentCriteria = String.Empty;
  90. public string CurrentCriteria
  91. {
  92. get { return _currentCriteria; }
  93. set
  94. {
  95. if (value == _currentCriteria)
  96. return;
  97. _currentCriteria = value;
  98. NotifyOfPropertyChange("CurrentCriteria");
  99. ApplyFilter();
  100. }
  101. }
  102. public string SystemName { get; set; }
  103. private void ApplyFilter()
  104. {
  105. foreach (var node in ConfigNodes)
  106. node.ApplyCriteria(CurrentCriteria, new Stack<ConfigNode>());
  107. }
  108. #endregion
  109. #region Functions
  110. public SystemConfigViewModel()
  111. {
  112. this.DisplayName = "System Config";
  113. TreeViewSelectedItemChangedCmd = new BaseCommand<ConfigNode>(TreeViewSelectedItemChanged);
  114. }
  115. protected override void OnInitialize()
  116. {
  117. base.OnInitialize();
  118. ConfigNodes = SystemConfigProvider.Instance.GetConfigTree(SystemName).SubNodes;
  119. }
  120. protected override void OnActivate()
  121. {
  122. base.OnActivate();
  123. ConfigNodes = SystemConfigProvider.Instance.GetConfigTree(SystemName).SubNodes;
  124. }
  125. protected override void OnViewLoaded(object view)
  126. {
  127. base.OnViewLoaded(view);
  128. view1 = (SystemConfigView)view;
  129. }
  130. private void SetShowView(string name)
  131. {
  132. switch (name)
  133. {
  134. case "IsShowTable":
  135. IsShowTable = Visibility.Visible;
  136. IsShowData = Visibility.Hidden;
  137. IsListData = Visibility.Hidden;
  138. IsShowAUX = Visibility.Hidden;
  139. break;
  140. case "IsShowData":
  141. IsShowTable = Visibility.Hidden;
  142. IsShowData = Visibility.Visible;
  143. IsListData = Visibility.Hidden;
  144. IsShowAUX = Visibility.Hidden;
  145. if (view1 != null)
  146. {
  147. view1.ShowAUX.ItemsSource = null;
  148. view1.ShowData.ItemsSource = ConfigItems;
  149. }
  150. break;
  151. case "IsListData":
  152. IsShowTable = Visibility.Hidden;
  153. IsShowData = Visibility.Hidden;
  154. IsListData = Visibility.Visible;
  155. IsShowAUX = Visibility.Hidden;
  156. break;
  157. case "IsShowAUX":
  158. IsShowTable = Visibility.Hidden;
  159. IsShowData = Visibility.Hidden;
  160. IsListData = Visibility.Hidden;
  161. IsShowAUX = Visibility.Visible;
  162. if (view1 != null)
  163. {
  164. view1.ShowData.ItemsSource = null;
  165. view1.ShowAUX.ItemsSource = ConfigItems;
  166. }
  167. break;
  168. default:
  169. break;
  170. }
  171. }
  172. private void TreeViewSelectedItemChanged(ConfigNode node)
  173. {
  174. valueList.Clear();
  175. _CurrentNodeName = string.IsNullOrEmpty(node.Path) ? node.Name : $"{node.Path}.{node.Name}";
  176. ConfigItems.Clear();
  177. node.Items.ForEach(x => ConfigItems.Add(x));
  178. if (_CurrentNodeName.Contains("WaferCycleTime"))
  179. {
  180. SetShowView("IsShowTable");
  181. }
  182. else if (_CurrentNodeName.Contains("Step Name"))
  183. {
  184. int count = int.Parse(ConfigItems.FirstOrDefault(x => x.Name == "Count").DefaultValue);
  185. string names = ConfigItems.FirstOrDefault(x => x.Name == "Name").StringValue;
  186. NameList.Clear();
  187. int index = 1;
  188. for (int i = 0; i < count; i++)
  189. {
  190. NameList.Add(new ListName()
  191. { No = index, Name = "" });
  192. index++;
  193. }
  194. if (!string.IsNullOrEmpty(names))
  195. {
  196. }
  197. SetShowView("IsListData");
  198. }
  199. else if (_CurrentNodeName.Contains("AUX"))
  200. {
  201. //if (ConfigAUXItems.Count() == 0)
  202. //{
  203. node.Items.ForEach(x => ConfigAUXItems.Add(x));
  204. for (int i = 0; i < ConfigAUXItems.Count; i++)
  205. {
  206. ConfigAUXItems[i].CurrentValueParam.Value = ConfigAUXItems[i].CurrentValue;
  207. ConfigAUXItems[i].Unit = (i + 1).ToString();
  208. }
  209. //}
  210. GetDataOfConfigAUXItems();
  211. SetShowView("IsShowAUX");
  212. return;
  213. }
  214. else
  215. {
  216. SetShowView("IsShowData");
  217. }
  218. GetDataOfConfigItems();
  219. }
  220. private void GetDataOfConfigItems()
  221. {
  222. if (ConfigItems == null || ConfigItems.Count == 0)
  223. return;
  224. for (int i = 0; i < ConfigItems.Count; i++)
  225. {
  226. string key = String.Format("{0}{1}{2}", _CurrentNodeName, ".", ConfigItems[i].Name);
  227. ConfigItems[i].CurrentValue = SystemConfigProvider.Instance.GetValueByName(SystemName, key);
  228. if (ConfigItems[i].Type == DataType.Bool)
  229. {
  230. bool value;
  231. if (bool.TryParse(ConfigItems[i].CurrentValue, out value))
  232. {
  233. ConfigItems[i].BoolValue = value;
  234. ConfigItems[i].CurrentValue = value ? "Yes" : "No";
  235. }
  236. }
  237. else
  238. ConfigItems[i].StringValue = ConfigItems[i].CurrentValue;
  239. }
  240. }
  241. private void GetDataOfConfigAUXItems()
  242. {
  243. if (ConfigAUXItems == null || ConfigAUXItems.Count == 0)
  244. return;
  245. for (int i = 0; i < ConfigAUXItems.Count; i++)
  246. {
  247. string key = String.Format("{0}{1}{2}", _CurrentNodeName, ".", ConfigAUXItems[i].Name);
  248. ConfigAUXItems[i].CurrentValueParam.Value = SystemConfigProvider.Instance.GetValueByName(SystemName, key);
  249. }
  250. }
  251. public void SetValue(ConfigItem item)
  252. {
  253. InputDialogViewModel dialog = new InputDialogViewModel();
  254. RecipeSelectDialogViewModel selectDialog = new RecipeSelectDialogViewModel();
  255. WindowManager wm = new WindowManager();
  256. bool? bret = null;
  257. if (item.Name == "Idle Recipe" || item.Name == "Abort Recipe" || item.Name == "Reset Recipe")
  258. {
  259. selectDialog.DisplayName = "Select Recipe";
  260. var recipeProvider = new RecipeProvider();
  261. string selectRecipeType = "";
  262. if (item.Name == "Idle Recipe")
  263. selectRecipeType = "Idle";
  264. else if (item.Name == "Abort Recipe")
  265. selectRecipeType = "Abort";
  266. else
  267. selectRecipeType = "Reset";
  268. var processType = QueryDataClient.Instance.Service.GetConfig($"System.Recipe.{selectRecipeType}");
  269. if (processType == null)
  270. {
  271. processType = selectRecipeType;
  272. }
  273. var ProcessTypeFileList = new ObservableCollection<ProcessTypeFileItem>();
  274. string[] recipeProcessType = ((string)processType).Split(',');
  275. for (int i = 0; i < recipeProcessType.Length; i++)
  276. {
  277. var type = new ProcessTypeFileItem();
  278. type.ProcessType = recipeProcessType[i];
  279. var prefix = $"Furnace\\{recipeProcessType[i]}";
  280. var recipes = recipeProvider.GetXmlRecipeList(prefix);
  281. type.FileListByProcessType = RecipeSequenceTreeBuilder.BuildFileNode(prefix, "", false, recipes)[0].Files;
  282. ProcessTypeFileList.Add(type);
  283. }
  284. selectDialog.ProcessTypeFileList = ProcessTypeFileList;
  285. bret = wm.ShowDialog(selectDialog);
  286. }
  287. else
  288. {
  289. if (item.Type == DataType.String) dialog.KeyboardType = "FullKeyboard";
  290. dialog.Item = item;
  291. dialog.DisplayName = "Set Value";
  292. bret = wm.ShowDialog(dialog);
  293. }
  294. string strOldValue = item.CurrentValue;
  295. if ((bool)bret)
  296. {
  297. item.StringValue = dialog.DialogResult;
  298. string value = string.Empty;
  299. switch (item.Type)
  300. {
  301. case DataType.Int:
  302. int iValue;
  303. if (int.TryParse(item.StringValue, out iValue))
  304. {
  305. if (!double.IsNaN(item.Max) && !double.IsNaN(item.Min))
  306. {
  307. if (iValue > item.Max || iValue < item.Min)
  308. {
  309. DialogBox.ShowWarning(string.Format("The value should be between {0} and {1}.", ((int)item.Min).ToString(), ((int)item.Max).ToString()));
  310. return;
  311. }
  312. }
  313. }
  314. else
  315. {
  316. DialogBox.ShowWarning("Please input valid data.");
  317. return;
  318. }
  319. value = item.StringValue;
  320. break;
  321. case DataType.Double:
  322. double fValue;
  323. if (double.TryParse(item.StringValue, out fValue))
  324. {
  325. if (!double.IsNaN(item.Max) && !double.IsNaN(item.Min))
  326. {
  327. if (fValue > item.Max || fValue < item.Min)
  328. {
  329. DialogBox.ShowWarning(string.Format("The value should be between {0} and {1}.", item.Min.ToString(), item.Max.ToString()));
  330. return;
  331. }
  332. string[] box = fValue.ToString().Split('.');
  333. if (box.Length > 1 && box[1].Length > 3)
  334. {
  335. DialogBox.ShowWarning(string.Format("The value should be more than three decimal places"));
  336. return;
  337. }
  338. }
  339. }
  340. else
  341. {
  342. DialogBox.ShowWarning("Please input valid data.");
  343. return;
  344. }
  345. value = item.StringValue;
  346. break;
  347. case DataType.Bool:
  348. if (item.StringValue.Equals("Yes", StringComparison.CurrentCultureIgnoreCase))
  349. item.BoolValue = true;
  350. else if (item.StringValue.Equals("No", StringComparison.CurrentCultureIgnoreCase))
  351. item.BoolValue = false;
  352. else
  353. {
  354. DialogBox.ShowWarning("The Value Should be Yes Or No.");
  355. return;
  356. }
  357. value = item.BoolValue.ToString().ToLower();
  358. break;
  359. case DataType.String:
  360. if (item.StringValue != null)
  361. value = item.StringValue;
  362. else
  363. value = selectDialog.DialogResult;
  364. break;
  365. }
  366. if (_CurrentNodeName == "System.ShutDown" && item.StringValue == "ShutDown")
  367. InvokeClient.Instance.Service.DoOperation("System.ShutDown");
  368. //压力单位改变时候,已有设置根据改变进行值转换
  369. if (item.Name == "PressureUnit")
  370. ChangePressureUnit(value);
  371. string key = String.Format("{0}{1}{2}", _CurrentNodeName, ".", item.Name);
  372. valueList.Add(new PageValue() { Path = key, CurrentValue = value });
  373. InvokeClient.Instance.Service.DoOperation($"{SystemName}.SetConfig", key, value);
  374. if (item.Name == "Idle Recipe" || item.Name == "Abort Recipe" || item.Name == "Reset Recipe")
  375. {
  376. GetDataOfConfigItems();
  377. }
  378. }
  379. }
  380. private void ChangePressureUnit(string strNewValue)
  381. {
  382. //double dValue = 0;
  383. //if (strNewValue.Equals("Torr"))//从Pa转换成Torr
  384. // dValue = 0.0075006;
  385. //else //从Torr转换成Pa
  386. // dValue = 133.322;
  387. //for (int i = 1; i <= 5; i++)
  388. //{
  389. // string key = $"PM1.RecipeEditParameter.PressureStabilizeTable.Table{i}.MaxScale";
  390. // double newValue = dValue * double.Parse(SystemConfigProvider.Instance.GetValueByName(SystemName, key));
  391. // InvokeClient.Instance.Service.DoOperation($"{SystemName}.SetConfig", key, newValue);
  392. //}
  393. InvokeClient.Instance.Service.DoOperation($"PM1.APC.SetUnit", strNewValue);
  394. }
  395. public void Reload()
  396. {
  397. GetDataOfConfigItems();
  398. }
  399. public void SaveAll()
  400. {
  401. if (ConfigItems == null)
  402. return;
  403. ConfigItems.ToList().ForEach(item => SetValue(item));
  404. }
  405. public void SaveParameter()
  406. {
  407. foreach (var item in valueList)
  408. {
  409. InvokeClient.Instance.Service.DoOperation($"{SystemName}.SetConfig", item.Path, item.CurrentValue);
  410. }
  411. Reload();
  412. }
  413. public void Cancel()
  414. {
  415. valueList.Clear();
  416. Reload();
  417. }
  418. public void CollapseAll()
  419. {
  420. SetExpand(ConfigNodes, false);
  421. }
  422. public void ExpandAll()
  423. {
  424. SetExpand(ConfigNodes, true);
  425. }
  426. public void ClearFilter()
  427. {
  428. CurrentCriteria = "";
  429. }
  430. public void SetExpand(List<ConfigNode> configs, bool expand)
  431. {
  432. if (configs == null)
  433. return;
  434. foreach (var configNode in configs)
  435. {
  436. configNode.IsExpanded = expand;
  437. if (configNode.SubNodes != null)
  438. SetExpand(configNode.SubNodes, expand);
  439. }
  440. }
  441. #endregion
  442. protected override void InvokeAfterUpdateProperty(Dictionary<string, object> data)
  443. {
  444. base.InvokeAfterUpdateProperty(data);
  445. string _aoKey = $"{SystemName}.PM1.AOList";
  446. if (data[_aoKey] != null && _isReadPLC)
  447. {
  448. List<NotifiableIoItem> lstData = (List<NotifiableIoItem>)data[_aoKey];
  449. for (int i = 0; i < lstData.Count; i++)
  450. {
  451. var findConfigAUX = ConfigAUXItems.FirstOrDefault(x => $"PM1.{x.Name}" == lstData[i].Name);
  452. if (findConfigAUX != null)
  453. {
  454. if (findConfigAUX.CurrentValueParam.Value != lstData[i].FloatValue.ToString())
  455. {
  456. findConfigAUX.CurrentValueParam.SetValue(lstData[i].FloatValue.ToString());
  457. }
  458. }
  459. }
  460. _isReadPLC = false;
  461. }
  462. }
  463. public void AUXSaveClick()
  464. {
  465. SaveValueToSC();
  466. if (DialogBox.Confirm("Save SC Value To PLC?"))
  467. {
  468. SaveValueToPLC(true);
  469. }
  470. }
  471. public void AUXUploadClick()
  472. {
  473. if (DialogBox.Confirm("Upload save PLC data to SC?"))
  474. {
  475. GetPLCToSC();
  476. }
  477. }
  478. public void AUXDownloadClick()
  479. {
  480. if (DialogBox.Confirm("Save SC data and download to PLC?"))
  481. {
  482. SaveValueToSC();
  483. SaveValueToPLC();
  484. }
  485. }
  486. private void SaveValueToSC()
  487. {
  488. foreach (var item in ConfigAUXItems)
  489. {
  490. InvokeClient.Instance.Service.DoOperation($"{SystemName}.SetConfig", $"{item.Path}.{item.Name}", item.CurrentValueParam.Value);
  491. }
  492. }
  493. private void SaveValueToPLC(bool isSaveAll = false)
  494. {
  495. if (isSaveAll)
  496. {
  497. foreach (var item in ConfigAUXItems)
  498. {
  499. float tempValue = 0;
  500. float.TryParse(item.CurrentValueParam.Value, out tempValue);
  501. InvokeClient.Instance.Service.DoOperation("System.SetAoValueFloat", $"PM1.{item.Name}", tempValue);
  502. item.CurrentValueParam.IsSaved = true;
  503. }
  504. }
  505. else
  506. {
  507. foreach (var item in ConfigAUXItems)
  508. {
  509. if (!item.CurrentValueParam.IsSaved)
  510. {
  511. float tempValue = 0;
  512. float.TryParse(item.CurrentValueParam.Value, out tempValue);
  513. InvokeClient.Instance.Service.DoOperation("System.SetAoValueFloat", $"PM1.{item.Name}", tempValue);
  514. item.CurrentValueParam.IsSaved = true;
  515. }
  516. }
  517. }
  518. }
  519. private static bool _isReadPLC = false;
  520. private void GetPLCToSC()
  521. {
  522. _isReadPLC = true;
  523. string _aoKey = $"{SystemName}.PM1.AOItemList";
  524. this.AOs = InitIOData(IOType.AO, _aoKey);
  525. _aoKey = $"{SystemName}.PM1.AOList";
  526. Subscribe(_aoKey);
  527. }
  528. public ObservableCollection<AOItemFloat> InitIOData(IOType type, string dataName)
  529. {
  530. //get the whole informations
  531. ObservableCollection<AOItemFloat> da = new ObservableCollection<AOItemFloat>();
  532. if (type == IOType.AO)
  533. {
  534. var diList = QueryDataClient.Instance.Service.GetData(dataName);
  535. if (diList != null)
  536. {
  537. List<NotifiableIoItem> item = (List<NotifiableIoItem>)diList;
  538. for (int i = 0; i < item.Count; i++)
  539. {
  540. {
  541. da.Add(new AOItemFloat()
  542. {
  543. Index = da.Count,
  544. Name = item[i].Name,
  545. //DisplayName = item[i].Name.Substring(item[i].Name.IndexOf('.') + 1),
  546. DisplayName = item[i].Description,
  547. Value = item[i].FloatValue,
  548. Address = item[i].Address
  549. });
  550. }
  551. }
  552. }
  553. }
  554. return da;
  555. }
  556. }
  557. public class ListName : PropertyChangedBase
  558. {
  559. private int _no;
  560. public int No
  561. {
  562. get => _no;
  563. set
  564. {
  565. _no = value;
  566. NotifyOfPropertyChange(nameof(No));
  567. }
  568. }
  569. private string _name;
  570. public string Name
  571. {
  572. get => _name;
  573. set
  574. {
  575. _name = value;
  576. NotifyOfPropertyChange(nameof(Name));
  577. }
  578. }
  579. }
  580. public class PageValue
  581. {
  582. public string Path { get; set; }
  583. public double Min { get; set; }
  584. public double Max { get; set; }
  585. public DataType Type { get; set; }
  586. public string CurrentValue { get; set; }
  587. public List<string> Parameters { get; set; }
  588. }
  589. }