ParameterFormatBuilder.cs 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Collections.ObjectModel;
  4. using System.Linq;
  5. using System.Windows;
  6. using System.Windows.Controls;
  7. using System.Xml;
  8. using Aitex.Core.RT.Log;
  9. using MECF.Framework.UI.Client.CenterViews.Configs.SystemConfig;
  10. using MECF.Framework.UI.Client.CenterViews.Parameter;
  11. using RecipeEditorLib.DGExtension.CustomColumn;
  12. using RecipeEditorLib.RecipeModel.Params;
  13. namespace MECF.Framework.UI.Client.CenterViews.Editors.Recipe
  14. {
  15. public class ParameterFormatBuilder
  16. {
  17. public ObservableCollection<EditorDataGridTemplateColumnBase> Columns
  18. {
  19. get;
  20. set;
  21. }
  22. public ObservableCollection<Param> Configs
  23. {
  24. get;
  25. set;
  26. }
  27. public string ChamberType
  28. {
  29. get;
  30. set;
  31. }
  32. public string Version
  33. {
  34. get;
  35. set;
  36. }
  37. private int _tableNumber;
  38. public int TableNumber
  39. {
  40. get;
  41. set;
  42. }
  43. private ParameterProvider parameterProvider = new ParameterProvider();
  44. public ObservableCollection<EditorDataGridTemplateColumnBase> Build(string path)
  45. {
  46. var str = parameterProvider.GetParameterFormatXml(path);
  47. string configstr = "";
  48. if (path == "PM1")
  49. {
  50. configstr = "Process";
  51. }
  52. else
  53. {
  54. configstr = path;
  55. }
  56. XmlDocument doc = new XmlDocument();
  57. try
  58. {
  59. doc.LoadXml(str);
  60. XmlNode nodeRoot = doc.SelectSingleNode("TableParameterFormat");
  61. ChamberType = nodeRoot.Attributes["ChamberType"].Value;
  62. Version = nodeRoot.Attributes["Version"].Value;
  63. if (nodeRoot.Attributes["TableNumber"] != null)
  64. {
  65. TableNumber = Convert.ToInt32(nodeRoot.Attributes["TableNumber"].Value);
  66. }
  67. }
  68. catch (Exception ex)
  69. {
  70. LOG.Write(ex);
  71. return null;
  72. }
  73. var columns = new ObservableCollection<EditorDataGridTemplateColumnBase>();
  74. EditorDataGridTemplateColumnBase col = null;
  75. XmlNodeList nodes = doc.SelectNodes("TableParameterFormat/Catalog/Group");
  76. foreach (XmlNode node in nodes)
  77. {
  78. columns.Add(new ExpanderColumn()
  79. {
  80. DisplayName = node.Attributes["DisplayName"].Value,
  81. StringCellTemplate = "TemplateExpander",
  82. StringHeaderTemplate = "ParamExpander"
  83. });
  84. XmlNodeList childNodes = node.SelectNodes("Step");
  85. foreach (XmlNode step in childNodes)
  86. {
  87. //step number
  88. if (step.Attributes["ControlName"].Value == "StepNo")
  89. {
  90. col = new StepColumn()
  91. {
  92. DisplayName = "Step",
  93. ControlName = "StepNo",
  94. StringCellTemplate = "TemplateStep",
  95. StringHeaderTemplate = "ParamTemplate"
  96. };
  97. columns.Add(col);
  98. continue;
  99. }
  100. switch (step.Attributes["InputType"].Value)
  101. {
  102. case "TextInput":
  103. col = new TextBoxColumn()
  104. {
  105. ModuleName = step.Attributes["ModuleName"].Value,
  106. ControlName = step.Attributes["ControlName"].Value,
  107. DisplayName = step.Attributes["DisplayName"].Value,
  108. StringCellTemplate = "TemplateText",
  109. StringHeaderTemplate = "ParamTemplate",
  110. EnableConfig = step.Attributes["EnableConfig"] != null && Convert.ToBoolean(step.Attributes["EnableConfig"].Value),
  111. EnableTolerance = step.Attributes["EnableTolerance"] != null && Convert.ToBoolean(step.Attributes["EnableTolerance"].Value),
  112. };
  113. columns.Add(col);
  114. break;
  115. case "ReadOnly":
  116. col = new TextBoxColumn()
  117. {
  118. ModuleName = step.Attributes["ModuleName"].Value,
  119. ControlName = step.Attributes["ControlName"].Value,
  120. DisplayName = step.Attributes["DisplayName"].Value,
  121. StringCellTemplate = "TemplateText",
  122. StringHeaderTemplate = "ParamTemplate",
  123. IsReadOnly = true,
  124. EnableConfig = step.Attributes["EnableConfig"] != null && Convert.ToBoolean(step.Attributes["EnableConfig"].Value),
  125. EnableTolerance = step.Attributes["EnableTolerance"] != null && Convert.ToBoolean(step.Attributes["EnableTolerance"].Value),
  126. };
  127. columns.Add(col);
  128. break;
  129. case "NumInput":
  130. col = new NumColumn()
  131. {
  132. ModuleName = step.Attributes["ModuleName"].Value,
  133. ControlName = step.Attributes["ControlName"].Value,
  134. DisplayName = step.Attributes["DisplayName"].Value,
  135. InputMode = step.Attributes["InputMode"].Value,
  136. Minimun = double.Parse(step.Attributes["Min"].Value),
  137. Maximun = double.Parse(step.Attributes["Max"].Value),
  138. StringCellTemplate = "TemplateNumber",
  139. StringHeaderTemplate = "ParamTemplate",
  140. EnableConfig = step.Attributes["EnableConfig"] != null && Convert.ToBoolean(step.Attributes["EnableConfig"].Value),
  141. EnableTolerance = step.Attributes["EnableTolerance"] != null && Convert.ToBoolean(step.Attributes["EnableTolerance"].Value),
  142. };
  143. columns.Add(col);
  144. break;
  145. case "DoubleInput":
  146. col = new DoubleColumn()
  147. {
  148. ModuleName = step.Attributes["ModuleName"].Value,
  149. ControlName = step.Attributes["ControlName"].Value,
  150. DisplayName = step.Attributes["DisplayName"].Value,
  151. InputMode = step.Attributes["InputMode"].Value,
  152. Minimun = double.Parse(step.Attributes["Min"].Value),
  153. Maximun = double.Parse(step.Attributes["Max"].Value),
  154. StringCellTemplate = "TemplateNumber",
  155. StringHeaderTemplate = "ParamTemplate",
  156. EnableConfig = step.Attributes["EnableConfig"] != null && Convert.ToBoolean(step.Attributes["EnableConfig"].Value),
  157. EnableTolerance = step.Attributes["EnableTolerance"] != null && Convert.ToBoolean(step.Attributes["EnableTolerance"].Value),
  158. };
  159. columns.Add(col);
  160. break;
  161. case "EditableSelection":
  162. case "ReadOnlySelection":
  163. col = new ComboxColumn()
  164. {
  165. IsReadOnly = step.Attributes["InputType"].Value == "ReadOnlySelection",
  166. ModuleName = step.Attributes["ModuleName"].Value,
  167. Default = step.Attributes["Default"] != null ? step.Attributes["Default"].Value : "",
  168. ControlName = step.Attributes["ControlName"].Value,
  169. DisplayName = step.Attributes["DisplayName"].Value,
  170. StringCellTemplate = "TemplateCombox",
  171. StringHeaderTemplate = "ParamTemplate",
  172. EnableConfig = step.Attributes["EnableConfig"] != null && Convert.ToBoolean(step.Attributes["EnableConfig"].Value),
  173. EnableTolerance = step.Attributes["EnableTolerance"] != null && Convert.ToBoolean(step.Attributes["EnableTolerance"].Value),
  174. };
  175. XmlNodeList items = step.SelectNodes("Item");
  176. foreach (XmlNode item in items)
  177. {
  178. ComboxColumn.Option opt = new ComboxColumn.Option();
  179. opt.ControlName = item.Attributes["ControlName"].Value;
  180. opt.DisplayName = item.Attributes["DisplayName"].Value;
  181. ((ComboxColumn)col).Options.Add(opt);
  182. }
  183. columns.Add(col);
  184. break;
  185. case "LoopSelection":
  186. col = new LoopComboxColumn()
  187. {
  188. IsReadOnly = false,
  189. ModuleName = step.Attributes["ModuleName"].Value,
  190. ControlName = step.Attributes["ControlName"].Value,
  191. DisplayName = step.Attributes["DisplayName"].Value,
  192. StringCellTemplate = "TemplateCombox",
  193. StringHeaderTemplate = "ParamTemplate",
  194. EnableConfig = step.Attributes["EnableConfig"] != null && Convert.ToBoolean(step.Attributes["EnableConfig"].Value),
  195. EnableTolerance = step.Attributes["EnableTolerance"] != null && Convert.ToBoolean(step.Attributes["EnableTolerance"].Value),
  196. };
  197. XmlNodeList options = step.SelectNodes("Item");
  198. foreach (XmlNode item in options)
  199. {
  200. LoopComboxColumn.Option opt = new LoopComboxColumn.Option();
  201. opt.ControlName = item.Attributes["ControlName"].Value;
  202. opt.DisplayName = item.Attributes["DisplayName"].Value;
  203. ((LoopComboxColumn)col).Options.Add(opt);
  204. }
  205. columns.Add(col);
  206. break;
  207. case "PopSetting":
  208. col = new PopSettingColumn()
  209. {
  210. ModuleName = step.Attributes["ModuleName"].Value,
  211. ControlName = step.Attributes["ControlName"].Value,
  212. DisplayName = step.Attributes["DisplayName"].Value,
  213. StringCellTemplate = "TemplatePopSetting",
  214. StringHeaderTemplate = "ParamTemplate",
  215. EnableConfig = step.Attributes["EnableConfig"] != null && Convert.ToBoolean(step.Attributes["EnableConfig"].Value),
  216. EnableTolerance = step.Attributes["EnableTolerance"] != null && Convert.ToBoolean(step.Attributes["EnableTolerance"].Value),
  217. };
  218. columns.Add(col);
  219. break;
  220. }
  221. }
  222. }
  223. Columns = columns;
  224. var configs = new ObservableCollection<Param>();
  225. nodes = doc.SelectNodes($"TableParameterFormat/Config/Configs");
  226. foreach (XmlNode node in nodes)
  227. {
  228. XmlNodeList childNodes = node.SelectNodes("Config");
  229. foreach (XmlNode configNode in childNodes)
  230. {
  231. switch (configNode.Attributes["InputType"].Value)
  232. {
  233. case "DoubleInput":
  234. var config = new DoubleParam()
  235. {
  236. Name = configNode.Attributes["ControlName"].Value,
  237. Value = configNode.Attributes["Default"].Value,
  238. DisplayName = configNode.Attributes["DisplayName"].Value,
  239. EnableConfig = configNode.Attributes["EnableConfig"] != null && Convert.ToBoolean(configNode.Attributes["EnableConfig"].Value),
  240. EnableTolerance = configNode.Attributes["EnableTolerance"] != null && Convert.ToBoolean(configNode.Attributes["EnableTolerance"].Value),
  241. };
  242. if (double.TryParse(configNode.Attributes["Max"].Value, out double max))
  243. {
  244. (config as DoubleParam).Maximun = max;
  245. }
  246. if (double.TryParse(configNode.Attributes["Min"].Value, out double min))
  247. {
  248. (config as DoubleParam).Minimun = min;
  249. }
  250. configs.Add(config);
  251. break;
  252. case "NumInput":
  253. var numConfig = new NumParam()
  254. {
  255. Name = configNode.Attributes["ControlName"].Value,
  256. Value = int.Parse(configNode.Attributes["Default"].Value),
  257. DisplayName = configNode.Attributes["DisplayName"].Value,
  258. EnableConfig = configNode.Attributes["EnableConfig"] != null && Convert.ToBoolean(configNode.Attributes["EnableConfig"].Value),
  259. EnableTolerance = configNode.Attributes["EnableTolerance"] != null && Convert.ToBoolean(configNode.Attributes["EnableTolerance"].Value),
  260. };
  261. if (double.TryParse(configNode.Attributes["Max"].Value, out max))
  262. {
  263. (numConfig as NumParam).Maximun = max;
  264. }
  265. if (double.TryParse(configNode.Attributes["Min"].Value, out min))
  266. {
  267. (numConfig as NumParam).Minimun = min;
  268. }
  269. configs.Add(numConfig);
  270. break;
  271. case "TextInput":
  272. var strConfig = new StringParam()
  273. {
  274. Name = configNode.Attributes["ControlName"].Value,
  275. Value = configNode.Attributes["Default"].Value,
  276. DisplayName = configNode.Attributes["DisplayName"].Value,
  277. EnableConfig = configNode.Attributes["EnableConfig"] != null && Convert.ToBoolean(configNode.Attributes["EnableConfig"].Value),
  278. EnableTolerance = configNode.Attributes["EnableTolerance"] != null && Convert.ToBoolean(configNode.Attributes["EnableTolerance"].Value),
  279. };
  280. configs.Add(strConfig);
  281. break;
  282. }
  283. }
  284. }
  285. Configs = configs;
  286. return Columns;
  287. }
  288. private ObservableCollection<Param> GetConfig(XmlNodeList nodes)
  289. {
  290. var configs = new ObservableCollection<Param>();
  291. foreach (XmlNode node in nodes)
  292. {
  293. XmlNodeList childNodes = node.SelectNodes("Config");
  294. foreach (XmlNode configNode in childNodes)
  295. {
  296. switch (configNode.Attributes["InputType"].Value)
  297. {
  298. case "TextInput":
  299. var text = new StringParam()
  300. {
  301. Name = configNode.Attributes["ControlName"].Value,
  302. Value = configNode.Attributes["Default"].Value,
  303. DisplayName = configNode.Attributes["DisplayName"].Value,
  304. };
  305. configs.Add(text);
  306. break;
  307. case "DoubleInput":
  308. var config = new DoubleParam()
  309. {
  310. Name = configNode.Attributes["ControlName"].Value,
  311. Value = configNode.Attributes["Default"].Value,
  312. DisplayName = configNode.Attributes["DisplayName"].Value,
  313. };
  314. if (double.TryParse(configNode.Attributes["Max"].Value, out double max))
  315. {
  316. (config as DoubleParam).Maximun = max;
  317. }
  318. if (double.TryParse(configNode.Attributes["Min"].Value, out double min))
  319. {
  320. (config as DoubleParam).Minimun = min;
  321. }
  322. configs.Add(config);
  323. break;
  324. case "ReadOnlySelection":
  325. var col = new ComboxParam()
  326. {
  327. Name = configNode.Attributes["ControlName"].Value,
  328. DisplayName = configNode.Attributes["DisplayName"].Value,
  329. Value = configNode.Attributes["Default"] != null ? configNode.Attributes["Default"].Value : "",
  330. Options = new ObservableCollection<ComboxColumn.Option>(),
  331. IsEditable = configNode.Attributes["InputType"].Value == "ReadOnlySelection",
  332. EnableTolerance = configNode.Attributes["EnableTolerance"] != null && Convert.ToBoolean(configNode.Attributes["EnableTolerance"].Value),
  333. };
  334. XmlNodeList items = configNode.SelectNodes("Item");
  335. foreach (XmlNode item in items)
  336. {
  337. ComboxColumn.Option opt = new ComboxColumn.Option();
  338. opt.ControlName = item.Attributes["ControlName"].Value;
  339. opt.DisplayName = item.Attributes["DisplayName"].Value;
  340. col.Options.Add(opt);
  341. }
  342. col.Value = !string.IsNullOrEmpty(col.Value) ? col.Value : (col.Options.Count > 0 ? col.Options[0].ControlName : "");
  343. configs.Add(col);
  344. break;
  345. }
  346. }
  347. }
  348. return configs;
  349. }
  350. public static void ApplyTemplate(UserControl uc, ObservableCollection<EditorDataGridTemplateColumnBase> columns)
  351. {
  352. columns.ToList().ForEach(col =>
  353. {
  354. col.CellTemplate = (DataTemplate)uc.FindResource(col.StringCellTemplate);
  355. col.HeaderTemplate = (DataTemplate)uc.FindResource(col.StringHeaderTemplate);
  356. });
  357. }
  358. }
  359. }