RecipeCompareSelectDialogViewModel.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  1. using System.Collections.Generic;
  2. using System.Collections.ObjectModel;
  3. using System.Linq;
  4. using System.Text.RegularExpressions;
  5. using System.Windows;
  6. using MECF.Framework.Common.DataCenter;
  7. using MECF.Framework.UI.Client.CenterViews.Editors.Recipe;
  8. using MECF.Framework.UI.Client.CenterViews.Editors.Sequence;
  9. using OpenSEMI.ClientBase;
  10. namespace FurnaceUI.Views.Recipes
  11. {
  12. public class RecipeCompareSelectDialogViewModel : DialogViewModel<string>
  13. {
  14. public RecipeCompareSelectDialogViewModel()
  15. {
  16. var chamber = QueryDataClient.Instance.Service.GetConfig("System.Recipe.SupportedChamberType");
  17. Chambers = new ObservableCollection<string>(((string)chamber).Split(','));
  18. SelectedChamber = Chambers[0];
  19. var pmSupportedProcessAndCLeanType = QueryDataClient.Instance.Service.GetConfig("System.Recipe.SupportedProcessAndCLeanType");
  20. if (pmSupportedProcessAndCLeanType != null)
  21. {
  22. string[] pmSPAndCTypeList = pmSupportedProcessAndCLeanType.ToString().Split(',');
  23. if (RecipeProcessTypeDic == null)
  24. RecipeProcessTypeDic = new Dictionary<string, ObservableCollection<string>>();
  25. foreach (string pm in Chambers)
  26. {
  27. if (pmSPAndCTypeList.Contains(pm))
  28. {
  29. RecipeProcessTypeDic.Add(pm, new ObservableCollection<string>() { "Process", "Clean" });
  30. }
  31. else
  32. {
  33. RecipeProcessTypeDic.Add(pm, new ObservableCollection<string>() { "Process" });
  34. }
  35. }
  36. }
  37. else
  38. {
  39. var processType = QueryDataClient.Instance.Service.GetConfig("System.Recipe.SupportedProcessType");
  40. Processes = new ObservableCollection<string>(((string)processType).Split(','));
  41. if (RecipeProcessTypeDic == null)
  42. RecipeProcessTypeDic = new Dictionary<string, ObservableCollection<string>>();
  43. foreach (string pm in Chambers)
  44. {
  45. ObservableCollection<string> recipeTypes = new ObservableCollection<string>();
  46. foreach (string recipeType in Processes)
  47. {
  48. recipeTypes.Add(recipeType);
  49. }
  50. RecipeProcessTypeDic.Add(pm, recipeTypes);
  51. }
  52. }
  53. DicPMChamberType = new Dictionary<string, string>();
  54. var chamberType = QueryDataClient.Instance.Service.GetConfig("System.Recipe.SupportedChamberType");
  55. if (chamberType == null)
  56. {
  57. ChamberType = new ObservableCollection<string>() { "Default" };
  58. }
  59. else
  60. {
  61. ChamberType = new ObservableCollection<string>(((string)(chamberType)).Split(','));
  62. }
  63. ChamberTypeIndexSelection = 0;
  64. foreach (var pm in Chambers)
  65. {
  66. var type = QueryDataClient.Instance.Service.GetConfig($"{pm}.ChamberType");
  67. if (type == null)
  68. {
  69. DicPMChamberType[pm] = ChamberType[0];
  70. }
  71. else
  72. {
  73. DicPMChamberType[pm] = (string)type;
  74. }
  75. }
  76. for (int i = 0; i < ChamberType.Count; i++)
  77. {
  78. if (ChamberType[i] == DicPMChamberType[SelectedChamber])
  79. {
  80. ChamberTypeIndexSelection = i; // 修改当前腔体类型
  81. }
  82. }
  83. }
  84. public void ChamberSelectionChanged()
  85. {
  86. if (IsSelectedA)
  87. {
  88. for (int i = 0; i < ChamberType.Count; i++)
  89. {
  90. if (ChamberType[i] == DicPMChamberType[SelectedChamber])
  91. {
  92. ChamberTypeIndexSelection = i; // 修改当前腔体类型
  93. }
  94. }
  95. }
  96. if (IsSelectedA)
  97. {
  98. if (!string.IsNullOrEmpty(SelectedChamber))
  99. {
  100. UpdateProcessTypeFileList(SelectedChamber);
  101. }
  102. else
  103. {
  104. UpdateProcessTypeFileList(Chambers[0]);
  105. }
  106. }
  107. else
  108. {
  109. if (!string.IsNullOrEmpty(SelectedChamber))
  110. {
  111. UpdateProcessTypeBFileList(SelectedChamber);
  112. }
  113. else
  114. {
  115. UpdateProcessTypeBFileList(Chambers[0]);
  116. }
  117. }
  118. ProcessTypeIndexSelection = 0;
  119. NotifyOfPropertyChange(nameof(ProcessTypeFileList));
  120. }
  121. public void ProcessSelectionChanged()
  122. {
  123. if (IsSelectedA)
  124. {
  125. for (int i = 0; i < ProcessType.Count; i++)
  126. {
  127. if (ProcessType[i] == DicPMChamberType[SelectedProcess])
  128. {
  129. ChamberTypeIndexSelection = i; // 修改当前腔体类型
  130. }
  131. }
  132. }
  133. if (IsSelectedA)
  134. { UpdateProcessTypeFileList(SelectedProcess); }
  135. else
  136. {
  137. UpdateProcessTypeBFileList(SelectedProcess);
  138. }
  139. ProcessTypeIndexSelection = 0;
  140. NotifyOfPropertyChange(nameof(ProcessTypeFileList));
  141. }
  142. public void UpdateProcessTypeBFileList(string selectedChamber)
  143. {
  144. ProcessTypeFileList.Clear();
  145. foreach (var item in Processes)
  146. {
  147. var type = new ProcessTypeFileItem();
  148. type.ProcessType = item;
  149. var prefix = $"{selectedChamber}\\{item}";
  150. var recipes = _recipeProvider.GetXmlRestoreRecipeList(prefix);
  151. // var prefix = $"{RestoreRecipeFolder}\\{recipeProcessType[i]}";
  152. type.FileListByProcessType = RecipeSequenceTreeBuilder.BuildRestoreFileNode(prefix, "", false, recipes)[0].Files;
  153. ProcessTypeFileList.Add(type);
  154. }
  155. }
  156. public void UpdateProcessTypeFileList(string selectedChamber)
  157. {
  158. //ProcessTypeFileList.Clear();
  159. for (int i = 0; i < RecipeProcessTypeDic[selectedChamber].Count; i++)
  160. {
  161. var type = new ProcessTypeFileItem();
  162. type.ProcessType = RecipeProcessTypeDic[selectedChamber][i];
  163. var prefix = $"{ChamberType[ChamberTypeIndexSelection]}\\{Processes[i]}";
  164. var recipes = _recipeProvider.GetXmlRecipeList(prefix);
  165. string[] parts = Regex.Split(recipes, "<");
  166. //string recipeChamber;
  167. //recipeChamber = "<" + parts[1];
  168. //foreach (string part in parts)
  169. //{
  170. // if (CurrentChamberType == ChamberType[0] && (Chambers.Count > 1 && part.Contains($".{Chambers[1]}")) && (Chambers.Count > 2 && part.Contains($".{Chambers[2]}")))
  171. // {
  172. // string temp = part.Replace($".{Chambers[1]}", string.Empty);
  173. // temp = temp.Replace($".{Chambers[2]}", string.Empty);
  174. // recipeChamber += "<" + temp;
  175. // }
  176. // else if (part.Contains(_selectedChamberSuffix))
  177. // {
  178. // string temp = part.Replace(_selectedChamberSuffix, string.Empty);
  179. // recipeChamber += "<" + temp;
  180. // }
  181. //}
  182. //if (parts.Length > 2)
  183. //{
  184. // recipeChamber += "<" + parts[parts.Length - 1];
  185. //}
  186. var recipesChamber = _recipeProvider.GetXmlRecipeList(prefix);
  187. type.FileListByProcessType = RecipeSequenceTreeBuilder.BuildFileNode(prefix, "", false, recipesChamber)[0].Files;
  188. ProcessTypeFileList.Add(type);
  189. }
  190. while (ProcessTypeFileList.Count > RecipeProcessTypeDic[SelectedChamber].Count)
  191. {
  192. ProcessTypeFileList.RemoveAt(0);
  193. }
  194. //for (int i = 0; i < ProcessTypeFileList.Count; i++)
  195. //{
  196. // for (int j = ProcessTypeFileList[i].FileListByProcessType.Count - 1; j >= 0; j--)
  197. // {
  198. // if (!ProcessTypeFileList[i].FileListByProcessType[j].Name.Contains(selectedChamber))
  199. // ProcessTypeFileList[i].FileListByProcessType.RemoveAt(j);
  200. // }
  201. //}
  202. }
  203. public string _selectedChamberSuffix => $".{SelectedChamber}";
  204. public string CurrentChamberType
  205. {
  206. get
  207. {
  208. return ChamberType[ChamberTypeIndexSelection];
  209. }
  210. }
  211. public string CurrentProcessType
  212. {
  213. get
  214. {
  215. return ProcessType[ChamberTypeIndexSelection];
  216. }
  217. }
  218. public int ChamberTypeIndexSelection { get; set; }
  219. private RecipeProvider _recipeProvider = new RecipeProvider();
  220. public ObservableCollection<string> ChamberType { get; set; }
  221. public ObservableCollection<string> ProcessType { get; set; }
  222. public Dictionary<string, string> DicPMChamberType { get; set; }
  223. public Dictionary<string, ObservableCollection<string>> RecipeProcessTypeDic { get; set; }
  224. public ObservableCollection<string> Chambers { get; set; }
  225. public ObservableCollection<string> Processes { get; set; }
  226. public string _selectedChamber;
  227. public string SelectedChamber
  228. {
  229. get { return _selectedChamber; }
  230. set { _selectedChamber = value; NotifyOfPropertyChange("SelectedChamber"); }
  231. }
  232. public string _selectedProcess;
  233. public string SelectedProcess
  234. {
  235. get { return _selectedProcess; }
  236. set { _selectedProcess = value; NotifyOfPropertyChange("SelectedProcess"); }
  237. }
  238. public string _chamberSuffix => Chambers.Count > 2 ? $".{Chambers[1]}" + $".{Chambers[2]}" : string.Empty;
  239. public ObservableCollection<ProcessTypeFileItem> ProcessTypeFileList { get; set; }
  240. public FileNode CurrentFileNode { get; set; }
  241. public bool IsSelectedA { get; set; } = true;
  242. private int _processTypeIndexSelection;
  243. public int ProcessTypeIndexSelection
  244. {
  245. get
  246. {
  247. return _processTypeIndexSelection;
  248. }
  249. set
  250. {
  251. _processTypeIndexSelection = value;
  252. //ProcessSelectionChanged();
  253. }
  254. }
  255. public ObservableCollection<FileNode> Files { get; set; }
  256. private FileNode currentFileNode;
  257. public void TreeSelectChanged(FileNode file)
  258. {
  259. this.currentFileNode = file;
  260. }
  261. public void TreeMouseDoubleClick(FileNode file)
  262. {
  263. this.currentFileNode = file;
  264. OK();
  265. }
  266. public void OK()
  267. {
  268. if (this.currentFileNode != null)
  269. {
  270. if (this.currentFileNode.IsFile)
  271. {
  272. this.DialogResult = currentFileNode.PrefixPath + "\\" + currentFileNode.FullPath;
  273. IsCancel = false;
  274. TryClose(true);
  275. }
  276. }
  277. }
  278. public void Cancel()
  279. {
  280. IsCancel = true;
  281. TryClose(false);
  282. }
  283. public void Browser()
  284. {
  285. Microsoft.Win32.OpenFileDialog openFileDialog = new Microsoft.Win32.OpenFileDialog();
  286. openFileDialog.Title = "Select source file";
  287. openFileDialog.Filter = string.Format("rcp|*.rcp", SelectedChamber);
  288. openFileDialog.FileName = string.Empty;
  289. // openFileDialog.DefaultExt = "xml";
  290. if (openFileDialog.ShowDialog() == false)
  291. {
  292. return;
  293. }
  294. string xmlFile = openFileDialog.FileName;
  295. this.DialogResult = xmlFile;
  296. TryClose(true);
  297. }
  298. }
  299. }