N2PurgeEditViewModel.cs 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437
  1. using Aitex.Core.RT.SCCore;
  2. using Caliburn.Micro;
  3. using MECF.Framework.Common.DataCenter;
  4. using MECF.Framework.Common.OperationCenter;
  5. using MECF.Framework.UI.Client.CenterViews.Configs.SystemConfig;
  6. using MECF.Framework.UI.Client.CenterViews.Dialogs;
  7. using MECF.Framework.UI.Client.CenterViews.Editors.Recipe;
  8. using MECF.Framework.UI.Client.ClientBase;
  9. using OpenSEMI.ClientBase;
  10. using System;
  11. using System.Collections.Generic;
  12. using System.Collections.ObjectModel;
  13. using System.Globalization;
  14. using System.Linq;
  15. using System.Text;
  16. using System.Threading.Tasks;
  17. using System.Windows;
  18. using System.Windows.Controls;
  19. using System.Windows.Data;
  20. namespace MECF.Framework.UI.Client.CenterViews.Parameter
  21. {
  22. public class N2PurgeEditViewModel : ModuleUiViewModelBase
  23. {
  24. public bool IsPermission { get => this.Permission == 3; }
  25. public List<ParamBase> ParameterTree { get; set; } = new List<ParamBase>();
  26. public RecipeDataBase CurrentRecipe { get; set; } = new RecipeDataBase();
  27. public ObservableCollection<TempSetData> HeadLst { get; set; } = new ObservableCollection<TempSetData>();
  28. public ObservableCollection<TempSetData> PIDHeadLst { get; set; } = new ObservableCollection<TempSetData>();
  29. private ConfigNode levelOneNode;
  30. public ConfigNode LevelOneNode
  31. {
  32. get { return levelOneNode; }
  33. set { levelOneNode = value; this.NotifyOfPropertyChange(nameof(LevelOneNode)); }
  34. }
  35. private ConfigNode levelTwoNode;
  36. public ConfigNode LevelTwoNode
  37. {
  38. get { return levelTwoNode; }
  39. set { levelTwoNode = value; this.NotifyOfPropertyChange(nameof(LevelTwoNode)); }
  40. }
  41. private List<ConfigItem> currenItems;
  42. public List<ConfigItem> CurrenItems
  43. {
  44. get { return currenItems; }
  45. set { currenItems = value; this.NotifyOfPropertyChange(nameof(CurrenItems)); }
  46. }
  47. private List<ConfigNode> _ConfigNodes = new List<ConfigNode>();
  48. public List<ConfigNode> ConfigNodes
  49. {
  50. get { return _ConfigNodes; }
  51. set { _ConfigNodes = value; NotifyOfPropertyChange("ConfigNodes"); }
  52. }
  53. private string _defaultUnit = "Pa";
  54. public string DefaultUnit
  55. {
  56. get
  57. {
  58. return _defaultUnit;
  59. }
  60. set
  61. {
  62. _defaultUnit = value;
  63. NotifyOfPropertyChange("DefaultUnit");
  64. }
  65. }
  66. private ConfigNode _rootNode;
  67. private string _CurrentNodeName = string.Empty;
  68. private string path;
  69. private string currentValue;
  70. private ObservableCollection<PageValue> valueList { get; set; } = new ObservableCollection<PageValue>();
  71. protected override void OnInitialize()
  72. {
  73. base.OnInitialize();
  74. this.SystemName = "System";
  75. ConfigNodes = SystemConfigProvider.Instance.GetConfigTree(SystemName).SubNodes;
  76. InitTree();
  77. _rootNode = SystemConfigProvider.Instance.GetConfig(true);
  78. }
  79. protected override void OnActivate()
  80. {
  81. base.OnActivate();
  82. DefaultUnit = (string)QueryDataClient.Instance.Service.GetConfig($"PM1.APC.PressureUnit");
  83. }
  84. private void InitTree()
  85. {
  86. var node = SystemConfigProvider.Instance.GetConfigTree(SystemName).SubNodes;
  87. ParameterTree.Add(new ParamBase() { ID = 1, ParentID = 0, Name = "StepTime", ConfigName = "StepTime" });
  88. ParameterTree.Add(new ParamBase() { ID = 2, ParentID = 0, Name = "Temperature" });
  89. {
  90. ParameterTree.Add(new ParamBase() { ID = 21, ParentID = 2, Name = "TempOffset", ConfigName = "TempOffsetTable" });
  91. ParameterTree.Add(new ParamBase() { ID = 22, ParentID = 2, Name = "TempProfile", ConfigName = "TempProfileTable" });
  92. ParameterTree.Add(new ParamBase() { ID = 23, ParentID = 2, Name = "TempStabilize", ConfigName = "TempStabilizeTable" });
  93. ParameterTree.Add(new ParamBase() { ID = 24, ParentID = 2, Name = "TempSetting", ConfigName = "TempSetting" });
  94. ParameterTree.Add(new ParamBase() { ID = 25, ParentID = 2, Name = "TempPIDTable", ConfigName = "TempPIDTable" });
  95. }
  96. //ParameterTree.Add(new ParamBase() { ID = 3, ParentID = 0, Name = "TempSetting", ConfigName = "TempSetting" });
  97. ParameterTree.Add(new ParamBase() { ID = 4, ParentID = 0, Name = "PressureStabilize", ConfigName = "PressureStabilizeTable" });
  98. ParameterTree.Add(new ParamBase() { ID = 5, ParentID = 0, Name = "AlarmWatchTable" });
  99. {
  100. ParameterTree.Add(new ParamBase() { ID = 51, ParentID = 5, Name = "TempAlarm", ConfigName = "AlarmWatchTable.TempAlarmWatch" });
  101. ParameterTree.Add(new ParamBase() { ID = 52, ParentID = 5, Name = "FlowAlarm", ConfigName = "AlarmWatchTable.FlowAlarmWatch" });
  102. ParameterTree.Add(new ParamBase() { ID = 53, ParentID = 5, Name = "PressureAlarm", ConfigName = "AlarmWatchTable.PressureAlarmWatch" });
  103. }
  104. ParameterTree.Add(new ParamBase() { ID = 6, ParentID = 0, Name = "FlowSetting", ConfigName = "FlowSetting" });
  105. {
  106. var MfcItems = ConfigNodes.Where(x => x.Display == "Parameter").FirstOrDefault().SubNodes.Where(y => y.Name == "MFC").FirstOrDefault().SubNodes;
  107. foreach (var item in MfcItems)
  108. {
  109. var isInstalled = QueryDataClient.Instance.Service.GetConfig($"PM1.MFC.{item.Name}.IsMFCInstalled");
  110. if (!(bool)isInstalled) continue;
  111. ParameterTree.Add(new ParamBase()
  112. {
  113. ID = 61,
  114. ParentID = 6,
  115. Name = SystemConfigProvider.Instance.GetValueByName($"PM1.MFC.{item.Name}.GasName"),
  116. ConfigName = $"FlowSetting.{item.Name}"
  117. });
  118. }
  119. }
  120. ParameterTree.Add(new ParamBase() { ID = 7, ParentID = 0, Name = "APCSetting" });
  121. {
  122. ParameterTree.Add(new ParamBase() { ID = 71, ParentID = 7, Name = "Pressure", ConfigName = "APCSetting.Pressure" });
  123. ParameterTree.Add(new ParamBase() { ID = 72, ParentID = 7, Name = "Position", ConfigName = "APCSetting.Position" });
  124. }
  125. ParameterTree.Add(new ParamBase() { ID = 8, ParentID = 0, Name = "LayoutPitch", ConfigName = "LayoutPitch" });
  126. ParameterTree.Add(new ParamBase() { ID = 9, ParentID = 0, Name = "CoolingTime", ConfigName = "CoolTime" });
  127. ParameterTree = this.LoadTreeView(0);
  128. }
  129. private List<ParamBase> LoadTreeView(int id)
  130. {
  131. List<ParamBase> node = ParameterTree.FindAll(s => s.ParentID.Equals(id));
  132. foreach (var item in node)
  133. {
  134. item.Children = LoadTreeView(item.ID);
  135. }
  136. return node;
  137. }
  138. public void HideAllCanvas()
  139. {
  140. }
  141. public void TreeViewSelectedItemChanged(object obj)
  142. {
  143. valueList.Clear();
  144. LevelOneNode = LevelTwoNode = new ConfigNode();
  145. HideAllCanvas();
  146. var view = GetView() as N2PurgeEditView;
  147. ParamBase para = obj as ParamBase;
  148. string strHeader = "PM1.RecipeEditParameter";
  149. Canvas canvas = null;
  150. LevelOneNode = FindNodeByName(_rootNode, $"{strHeader}.{para.ConfigName}");
  151. LevelTwoNode = LevelOneNode.SubNodes.FirstOrDefault();
  152. if (canvas == null) return;
  153. canvas.Visibility = Visibility.Visible;
  154. this.GetHeaderConfig();
  155. this.GetPIDHeaderConfig();
  156. if (LevelTwoNode == null)
  157. {
  158. InitItemsCurrentValue(LevelOneNode, false);
  159. }
  160. else
  161. {
  162. InitItemsCurrentValue(LevelTwoNode, true);
  163. ConfigNode subNode = LevelTwoNode.SubNodes.FirstOrDefault();
  164. if (subNode != null) InitItemsCurrentValue(subNode, true);
  165. }
  166. }
  167. private void InitItemsCurrentValue(ConfigNode node, bool initSubItems = true)
  168. {
  169. if (node == null) return;
  170. CurrenItems = node.Items;
  171. _CurrentNodeName = string.IsNullOrEmpty(node.Path) ? node.Name : $"{node.Path}.{node.Name}";
  172. if (CurrenItems == null || CurrenItems.Count <= 0)
  173. {
  174. if (!initSubItems) return;
  175. foreach (var item in node.SubNodes)
  176. {
  177. InitItemsCurrentValue(item);
  178. }
  179. }
  180. else
  181. {
  182. GetDataOfConfigItems();
  183. }
  184. }
  185. private void GetDataOfConfigItems()
  186. {
  187. if (CurrenItems == null)
  188. return;
  189. for (int i = 0; i < CurrenItems.Count; i++)
  190. {
  191. var isInstalled = QueryDataClient.Instance.Service.GetConfig($"PM1.MFC.{CurrenItems[i].Name}.IsMFCInstalled");
  192. if (isInstalled != null && !(bool)isInstalled)
  193. CurrenItems[i].Visible = false;
  194. else
  195. CurrenItems[i].Visible = true;
  196. string key = String.Format("{0}{1}{2}", _CurrentNodeName, ".", CurrenItems[i].Name);
  197. CurrenItems[i].CurrentValue = SystemConfigProvider.Instance.GetValueByName(key);
  198. CurrenItems[i].Path = key;
  199. //if (CurrenItems[i].Path.Contains("PM1.RecipeEditParameter.PressureStabilizeTable"))
  200. // DefaultUnit = CurrenItems[i].Unit;
  201. if (CurrenItems[i].Type == DataType.Bool)
  202. {
  203. bool value;
  204. if (bool.TryParse(CurrenItems[i].CurrentValue, out value))
  205. {
  206. CurrenItems[i].BoolValue = value;
  207. CurrenItems[i].CurrentValue = value ? "Yes" : "No";
  208. }
  209. }
  210. else
  211. CurrenItems[i].StringValue = CurrenItems[i].CurrentValue;
  212. }
  213. }
  214. public void MenuCommand(object obj, object menuLevel)
  215. {
  216. RadioButton radioButton = obj as RadioButton;
  217. ConfigNode currentNode = null;
  218. switch (menuLevel.ToString())
  219. {
  220. case "LevelOne":
  221. currentNode = LevelTwoNode = LevelOneNode.SubNodes.Find((x) => x.Name == radioButton.ToolTip.ToString());
  222. break;
  223. case "LevelTwo":
  224. currentNode = LevelTwoNode.SubNodes.Find((x) => x.Name == radioButton.ToolTip.ToString());
  225. break;
  226. }
  227. InitItemsCurrentValue(currentNode);
  228. }
  229. public void SetValue(object obj)
  230. {
  231. var CurrentRecipes = CurrentRecipe;
  232. if (CurrenItems == null || currenItems.Count == 0) return;
  233. ConfigItem item = null;
  234. if (obj is Control)
  235. item = CurrenItems.Find((x) => x.Name == (obj as Control).ToolTip.ToString());
  236. else
  237. item = obj as ConfigItem;
  238. InputDialogViewModel dialog = new InputDialogViewModel();
  239. dialog.Item = item;
  240. dialog.DisplayName = "Set Value";
  241. WindowManager wm = new WindowManager();
  242. bool? bret = wm.ShowDialog(dialog);
  243. if ((bool)bret)
  244. {
  245. item.StringValue = dialog.DialogResult;
  246. //key :System.IsSimulatorMode
  247. //value: true or false 都是字符串
  248. //input check
  249. string value;
  250. if (item.Type == DataType.Bool)
  251. {
  252. if (item.StringValue.Equals("Yes", StringComparison.CurrentCultureIgnoreCase))
  253. item.BoolValue = true;
  254. else if (item.StringValue.Equals("No", StringComparison.CurrentCultureIgnoreCase))
  255. item.BoolValue = false;
  256. else
  257. {
  258. DialogBox.ShowWarning("The Value Should be Yes Or No.");
  259. return;
  260. }
  261. value = item.BoolValue.ToString().ToLower();
  262. }
  263. else
  264. {
  265. if (item.Type == DataType.Int)
  266. {
  267. int iValue;
  268. if (int.TryParse(item.StringValue, out iValue))
  269. {
  270. if (!double.IsNaN(item.Max) && !double.IsNaN(item.Min))
  271. {
  272. if (iValue > item.Max || iValue < item.Min)
  273. {
  274. DialogBox.ShowWarning(string.Format("The value should be between {0} and {1}.", ((int)item.Min).ToString(), ((int)item.Max).ToString()));
  275. return;
  276. }
  277. }
  278. }
  279. else
  280. {
  281. DialogBox.ShowWarning("Please input valid data.");
  282. return;
  283. }
  284. value = item.StringValue;
  285. }
  286. else if (item.Type == DataType.Double)
  287. {
  288. double fValue;
  289. if (double.TryParse(item.StringValue, out fValue))
  290. {
  291. if (!double.IsNaN(item.Max) && !double.IsNaN(item.Min))
  292. {
  293. if (fValue > item.Max || fValue < item.Min)
  294. {
  295. DialogBox.ShowWarning(string.Format("The value should be between {0} and {1}.", item.Min.ToString(), item.Max.ToString()));
  296. return;
  297. }
  298. string[] box = fValue.ToString().Split('.');
  299. if (box.Length > 1 && box[1].Length > 3)
  300. {
  301. DialogBox.ShowWarning(string.Format("The value should be more than three decimal places"));
  302. return;
  303. }
  304. }
  305. }
  306. else
  307. {
  308. DialogBox.ShowWarning("Please input valid data.");
  309. return;
  310. }
  311. value = item.StringValue;
  312. }
  313. else
  314. value = item.StringValue;
  315. }
  316. string key = String.Format("{0}{1}{2}", _CurrentNodeName, ".", item.Name);
  317. if (item.Path.Split('.')[2] == "LayoutPitch")
  318. {
  319. if (item.Path.Split('.')[3] == "StandardPitch")
  320. {
  321. foreach (var current in currenItems.Where(x => x.Description != "StandardPitch"))
  322. {
  323. current.CurrentValue = "No";
  324. InvokeClient.Instance.Service.DoOperation($"{SystemName}.SetConfig", current.Path, "false");
  325. }
  326. }
  327. else if (item.Path.Split('.')[3] == "DoublePitch")
  328. {
  329. foreach (var current in currenItems.Where(x => x.Description != "DoublePitch"))
  330. {
  331. current.CurrentValue = "No";
  332. InvokeClient.Instance.Service.DoOperation($"{SystemName}.SetConfig", current.Path, "false");
  333. }
  334. }
  335. else
  336. {
  337. foreach (var current in currenItems.Where(x => x.Description != "TriplePitch"))
  338. {
  339. current.CurrentValue = "No";
  340. InvokeClient.Instance.Service.DoOperation($"{SystemName}.SetConfig", current.Path, "false");
  341. }
  342. }
  343. }
  344. path = item.Path;
  345. currentValue = value;
  346. valueList.Add(new PageValue() { Path = path, CurrentValue = currentValue });
  347. }
  348. }
  349. public void SaveParameter()
  350. {
  351. foreach (var item in valueList)
  352. {
  353. InvokeClient.Instance.Service.DoOperation($"{SystemName}.SetConfig", item.Path, item.CurrentValue);
  354. }
  355. }
  356. public void GetHeaderConfig()
  357. {
  358. HeadLst.Clear();
  359. for (int i = 0; i < 10; i++)
  360. {
  361. if (i % 2 != 0)
  362. {
  363. var configHeater = (string)QueryDataClient.Instance.Service.GetConfig($"PM1.Heater.Heater{i}.DisplayName");
  364. TempSetData item = new TempSetData(configHeater);
  365. item.SetValue.Value = configHeater;
  366. HeadLst.Add(item);
  367. }
  368. }
  369. }
  370. public void GetPIDHeaderConfig()
  371. {
  372. PIDHeadLst.Clear();
  373. for (int i = 0; i < 10; i++)
  374. {
  375. if (i % 2 != 0)
  376. {
  377. var configHeater = (string)QueryDataClient.Instance.Service.GetConfig($"PM1.Heater.Heater{i}.DisplayName");
  378. TempSetData item1 = new TempSetData(configHeater);
  379. TempSetData item2 = new TempSetData(configHeater);
  380. TempSetData item3 = new TempSetData(configHeater);
  381. item1.SetValue.Value = $"{configHeater} P";
  382. PIDHeadLst.Add(item1);
  383. item2.SetValue.Value = $"{configHeater} I";
  384. PIDHeadLst.Add(item2);
  385. item3.SetValue.Value = $"{configHeater} D";
  386. PIDHeadLst.Add(item3);
  387. }
  388. }
  389. }
  390. private ConfigNode FindNodeByName(ConfigNode parentNode, string strName)
  391. {
  392. string strCates = strName.Split('.')[0];
  393. ConfigNode node = parentNode.SubNodes.Find((x) => x.Name == strCates);
  394. if (node == null)
  395. return parentNode;
  396. else
  397. return FindNodeByName(node, strName.Replace(strCates + ".", ""));
  398. }
  399. }
  400. }