APCPIDParameterData.cs 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454
  1. using Aitex.Core.RT.Log;
  2. using Aitex.Core.RT.ParameterCenter;
  3. using Caliburn.Micro.Core;
  4. using MECF.Framework.Common.ParameterCenter;
  5. using MECF.Framework.UI.Client.CenterViews.Editors.Recipe;
  6. using RecipeEditorLib.RecipeModel.Params;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Collections.ObjectModel;
  10. using System.Linq;
  11. using System.Text;
  12. using System.Threading.Tasks;
  13. using System.Windows;
  14. using System.Xml;
  15. namespace MECF.Framework.UI.Client.CenterViews.Parameter
  16. {
  17. public class APCPIDParameterData : ParameterDataBase
  18. {
  19. private ParameterProvider _parameterProvider = new ParameterProvider();
  20. private ParameterFormatBuilder _columnBuilder = new ParameterFormatBuilder();
  21. private DoubleParam _slowVacP;
  22. public DoubleParam SlowVacP
  23. {
  24. get => _slowVacP;
  25. set
  26. {
  27. _slowVacP = value;
  28. NotifyOfPropertyChange(nameof(SlowVacP));
  29. }
  30. }
  31. private DoubleParam _slowVacI;
  32. public DoubleParam SlowVacI
  33. {
  34. get => _slowVacI;
  35. set
  36. {
  37. _slowVacI = value;
  38. NotifyOfPropertyChange(nameof(SlowVacI));
  39. }
  40. }
  41. private DoubleParam _slowVacD;
  42. public DoubleParam SlowVacD
  43. {
  44. get => _slowVacD;
  45. set
  46. {
  47. _slowVacD = value;
  48. NotifyOfPropertyChange(nameof(SlowVacD));
  49. }
  50. }
  51. private DoubleParam _slowVacA;
  52. public DoubleParam SlowVacA
  53. {
  54. get => _slowVacA;
  55. set
  56. {
  57. _slowVacA = value;
  58. NotifyOfPropertyChange(nameof(SlowVacA));
  59. }
  60. }
  61. private Dictionary<string, ObservableCollection<ParameterTemplateColumnBase>> ParameterTemplate;
  62. public APCPIDParameterData() : base()
  63. {
  64. string vars = _parameterProvider.GetParameterFormatXml($"Parameter\\APCPID");
  65. _columnBuilder.Build($"Parameter\\APCPID");
  66. ParameterTemplate = _parameterProvider.GetGroupParameterTemplate();
  67. TableNumber = _columnBuilder.TableNumber;
  68. Version = _columnBuilder.Version;
  69. if (ParameterTemplate.ContainsKey("Parameter Information"))
  70. {
  71. var template = ParameterTemplate["Parameter Information"];
  72. var pcom = template.Where(x => x.ControlName == "P").FirstOrDefault();
  73. if (pcom != null)
  74. {
  75. DoubleParam pParam = new DoubleParam()
  76. {
  77. Name = pcom.ControlName,
  78. Value = pcom.Value.ToString(),
  79. DisplayName = pcom.DisplayName,
  80. Minimun = pcom.Minimun,
  81. Maximun = pcom.Maximun,
  82. Resolution = 0
  83. };
  84. SlowVacP = pParam;
  85. }
  86. var icom = template.Where(x => x.ControlName == "I").FirstOrDefault();
  87. if (icom != null)
  88. {
  89. DoubleParam iParam = new DoubleParam()
  90. {
  91. Name = icom.ControlName,
  92. Value = icom.Value.ToString(),
  93. DisplayName = icom.DisplayName,
  94. Minimun = icom.Minimun,
  95. Maximun = icom.Maximun,
  96. Resolution = 0
  97. };
  98. SlowVacI = iParam;
  99. }
  100. var dcom = template.Where(x => x.ControlName == "D").FirstOrDefault();
  101. if (dcom != null)
  102. {
  103. DoubleParam dParam = new DoubleParam()
  104. {
  105. Name = dcom.ControlName,
  106. Value = dcom.Value.ToString(),
  107. DisplayName = dcom.DisplayName,
  108. Minimun = dcom.Minimun,
  109. Maximun = dcom.Maximun,
  110. Resolution = 0
  111. };
  112. SlowVacD = dParam;
  113. }
  114. var acom = template.Where(x => x.ControlName == "a").FirstOrDefault();
  115. if (acom != null)
  116. {
  117. DoubleParam aParam = new DoubleParam()
  118. {
  119. Name = acom.ControlName,
  120. Value = acom.Value.ToString(),
  121. DisplayName = acom.DisplayName,
  122. Minimun = acom.Minimun,
  123. Maximun = acom.Maximun,
  124. Resolution = 0
  125. };
  126. SlowVacA = aParam;
  127. }
  128. }
  129. for (int i = 1; i < TableNumber + 1; i++)
  130. {
  131. Steps.Add(CreateStep());
  132. }
  133. }
  134. public override ParameterTable CreateStep(XmlNode stepNode = null)
  135. {
  136. APCPIDTable step = new APCPIDTable();
  137. if (stepNode != null)
  138. {
  139. if (stepNode.Attributes["StepNo"] != null)
  140. step.StepNo = int.Parse(stepNode.Attributes["StepNo"].Value);
  141. if (stepNode.Attributes["Name"] != null)
  142. step.Name = stepNode.Attributes["Name"].Value;
  143. //if (stepNode.Attributes["UseTemp"] != null)
  144. // step.UseTemp = stepNode.Attributes["UseTemp"].Value;
  145. }
  146. else
  147. {
  148. step.StepNo = StepNo;
  149. step.Name = "Name" + StepNo.ToString();
  150. // step.UseTemp = "0";
  151. StepNo++;
  152. }
  153. foreach (var item in ParameterTemplate)
  154. {
  155. if (item.Key != "Parameter Information")
  156. {
  157. var pcom = item.Value.Where(x => x.ControlName == "P").FirstOrDefault();
  158. if (pcom != null)
  159. {
  160. DoubleParam pParam = new DoubleParam()
  161. {
  162. Name = pcom.ControlName,
  163. Value = pcom.Value.ToString(),
  164. DisplayName = pcom.DisplayName,
  165. Minimun = pcom.Minimun,
  166. Maximun = pcom.Maximun,
  167. Resolution = 0
  168. };
  169. step.P = pParam;
  170. }
  171. var icom = item.Value.Where(x => x.ControlName == "I").FirstOrDefault();
  172. if (icom != null)
  173. {
  174. DoubleParam iParam = new DoubleParam()
  175. {
  176. Name = icom.ControlName,
  177. Value = icom.Value.ToString(),
  178. DisplayName = icom.DisplayName,
  179. Minimun = icom.Minimun,
  180. Maximun = icom.Maximun,
  181. Resolution = 0
  182. };
  183. step.I = iParam;
  184. }
  185. var dcom = item.Value.Where(x => x.ControlName == "D").FirstOrDefault();
  186. if (dcom != null)
  187. {
  188. DoubleParam dParam = new DoubleParam()
  189. {
  190. Name = dcom.ControlName,
  191. Value = dcom.Value.ToString(),
  192. DisplayName = dcom.DisplayName,
  193. Minimun = dcom.Minimun,
  194. Maximun = dcom.Maximun,
  195. Resolution = 0
  196. };
  197. step.D = dParam;
  198. }
  199. var acom = item.Value.Where(x => x.ControlName == "a").FirstOrDefault();
  200. if (acom != null)
  201. {
  202. DoubleParam aParam = new DoubleParam()
  203. {
  204. Name = acom.ControlName,
  205. Value = acom.Value.ToString(),
  206. DisplayName = acom.DisplayName,
  207. Minimun = acom.Minimun,
  208. Maximun = acom.Maximun,
  209. Resolution = 0
  210. };
  211. step.A = aParam;
  212. }
  213. var offsetcom = item.Value.Where(x => x.ControlName == "offset").FirstOrDefault();
  214. if (offsetcom != null)
  215. {
  216. DoubleParam offsetParam = new DoubleParam()
  217. {
  218. Name = offsetcom.ControlName,
  219. Value = offsetcom.Value.ToString(),
  220. DisplayName = offsetcom.DisplayName,
  221. Minimun = offsetcom.Minimun,
  222. Maximun = offsetcom.Maximun,
  223. Resolution = 0
  224. };
  225. step.Offset = offsetParam;
  226. }
  227. var chcom = item.Value.Where(x => x.ControlName == "CH").FirstOrDefault();
  228. if (chcom != null)
  229. {
  230. DoubleParam chParam = new DoubleParam()
  231. {
  232. Name = chcom.ControlName,
  233. Value = chcom.Value.ToString(),
  234. DisplayName = chcom.DisplayName,
  235. Minimun = chcom.Minimun,
  236. Maximun = chcom.Maximun,
  237. Resolution = 0
  238. };
  239. step.CH = chParam;
  240. }
  241. var clcom = item.Value.Where(x => x.ControlName == "CL").FirstOrDefault();
  242. if (clcom != null)
  243. {
  244. DoubleParam clParam = new DoubleParam()
  245. {
  246. Name = clcom.ControlName,
  247. Value = clcom.Value.ToString(),
  248. DisplayName = clcom.DisplayName,
  249. Minimun = clcom.Minimun,
  250. Maximun = clcom.Maximun,
  251. Resolution = 0
  252. };
  253. step.CL = clParam;
  254. }
  255. }
  256. }
  257. if (stepNode != null)
  258. {
  259. if (stepNode.Attributes["P"] != null && step.P != null)
  260. step.P.Value = stepNode.Attributes["P"].Value;
  261. if (stepNode.Attributes["I"] != null && step.I != null)
  262. step.I.Value = stepNode.Attributes["I"].Value;
  263. if (stepNode.Attributes["D"] != null && step.D != null)
  264. step.D.Value = stepNode.Attributes["D"].Value;
  265. if (stepNode.Attributes["a"] != null && step.A != null)
  266. step.A.Value = stepNode.Attributes["a"].Value;
  267. if (stepNode.Attributes["offset"] != null && step.Offset != null)
  268. step.Offset.Value = stepNode.Attributes["offset"].Value;
  269. if (stepNode.Attributes["CH"] != null && step.CH != null)
  270. step.CH.Value = stepNode.Attributes["CH"].Value;
  271. if (stepNode.Attributes["CL"] != null && step.CL != null)
  272. step.CL.Value = stepNode.Attributes["CL"].Value;
  273. }
  274. return (ParameterTable)step;
  275. }
  276. public override string GetXmlString()
  277. {
  278. XmlElement nodeData = _doc.SelectSingleNode($"Aitex/TableParameterData") as XmlElement;
  279. nodeData.SetAttribute("CreatedBy", Creator);
  280. nodeData.SetAttribute("CreationTime", CreateTime.ToString("yyyy-MM-dd HH:mm:ss"));
  281. nodeData.SetAttribute("LastRevisedBy", Revisor);
  282. nodeData.SetAttribute("LastRevisionTime", ReviseTime.ToString("yyyy-MM-dd HH:mm:ss"));
  283. nodeData.SetAttribute("Description", Description);
  284. nodeData.SetAttribute("ParameterChamberType", ChamberType);
  285. nodeData.SetAttribute("Version", Version);
  286. nodeData.SetAttribute("TableNumber", TableNumber.ToString());
  287. nodeData.SetAttribute("Permission", Permission);
  288. nodeData.SetAttribute("ParameterLevel", Level);
  289. nodeData.SetAttribute("P", SlowVacP.Value);
  290. nodeData.SetAttribute("I", SlowVacI.Value);
  291. nodeData.SetAttribute("D", SlowVacD.Value);
  292. nodeData.SetAttribute("a", SlowVacA.Value);
  293. XmlNode nodeModule = _doc.SelectSingleNode($"Aitex/TableParameterData/Module[@Name='{_module}']");
  294. if (nodeModule == null)
  295. {
  296. nodeModule = _doc.CreateElement("Module");
  297. nodeData.AppendChild(nodeModule);
  298. }
  299. nodeModule.RemoveAll();
  300. (nodeModule as XmlElement).SetAttribute("Name", _module);
  301. int i = 0;
  302. foreach (ParameterTable parameter in Steps)
  303. {
  304. XmlElement nodeStep = _doc.CreateElement("Step");
  305. nodeStep.SetAttribute("StepNo", parameter.StepNo.ToString());
  306. nodeStep.SetAttribute("Name", parameter.Name);
  307. //nodeStep.SetAttribute("UseTemp", parameter.UseTemp);
  308. if (parameter is APCPIDTable)
  309. {
  310. var apcParam = (APCPIDTable)parameter;
  311. if (apcParam.P != null)
  312. {
  313. nodeStep.SetAttribute("P", apcParam.P.Value);
  314. }
  315. if (apcParam.I != null)
  316. {
  317. nodeStep.SetAttribute("I", apcParam.I.Value);
  318. }
  319. if (apcParam.D != null)
  320. {
  321. nodeStep.SetAttribute("D", apcParam.D.Value);
  322. }
  323. if (apcParam.A != null)
  324. {
  325. nodeStep.SetAttribute("a", apcParam.A.Value);
  326. }
  327. if (apcParam.Offset != null)
  328. {
  329. nodeStep.SetAttribute("offset", apcParam.Offset.Value);
  330. }
  331. if (apcParam.CH != null)
  332. {
  333. nodeStep.SetAttribute("CH", apcParam.CH.Value);
  334. }
  335. if (apcParam.CL != null)
  336. {
  337. nodeStep.SetAttribute("CL", apcParam.CL.Value);
  338. }
  339. }
  340. nodeModule.AppendChild(nodeStep);
  341. i++;
  342. }
  343. return _doc.OuterXml;
  344. }
  345. public override void InitData(string prefixPath, string recipeName, string recipeContent, string module)
  346. {
  347. IsCompatibleWithCurrentFormat = false;
  348. _module = module;
  349. Name = recipeName;
  350. PrefixPath = prefixPath;
  351. try
  352. {
  353. _doc = new XmlDocument();
  354. _doc.LoadXml(recipeContent);
  355. if (!LoadHeader(_doc.SelectSingleNode("Aitex/TableParameterData")))
  356. return;
  357. XmlNodeList nodeSteps = _doc.SelectNodes($"Aitex/TableParameterData/Module[@Name='{module}']/Step");
  358. if (nodeSteps == null)
  359. nodeSteps = _doc.SelectNodes($"Aitex/TableParameterData/Step");
  360. LoadSteps(nodeSteps);
  361. var index = 1;
  362. foreach (ParameterTable parameters in Steps)
  363. {
  364. parameters.Value = index.ToString();
  365. index++;
  366. }
  367. // ValidLoopData();
  368. XmlNode nodeConfig =
  369. _doc.SelectSingleNode($"Aitex/TableParameterData/Module[@Name='{module}']/Config");
  370. if (nodeSteps == null)
  371. nodeConfig = _doc.SelectSingleNode($"Aitex/TableParameterData/Config");
  372. IsCompatibleWithCurrentFormat = true;
  373. }
  374. catch (Exception ex)
  375. {
  376. LOG.Write(ex);
  377. }
  378. }
  379. public override void LoadHeaderExtend(XmlNode nodeHeader)
  380. {
  381. base.LoadHeaderExtend(nodeHeader);
  382. if (nodeHeader.Attributes["P"] != null && SlowVacP!=null)
  383. SlowVacP.Value = nodeHeader.Attributes["P"].Value;
  384. if (nodeHeader.Attributes["I"] != null && SlowVacI != null)
  385. SlowVacI.Value = nodeHeader.Attributes["I"].Value;
  386. if (nodeHeader.Attributes["D"] != null && SlowVacD != null)
  387. SlowVacD.Value = nodeHeader.Attributes["D"].Value;
  388. if (nodeHeader.Attributes["a"] != null && SlowVacA != null)
  389. SlowVacA.Value = nodeHeader.Attributes["a"].Value;
  390. }
  391. public override void LoadSteps(XmlNodeList steps)
  392. {
  393. Steps.Clear();
  394. PopSettingSteps.Clear();
  395. StepTolerances.Clear();
  396. StepNos.Clear();
  397. int index = 1;
  398. foreach (XmlNode nodeStep in steps)
  399. {
  400. ParameterTable stepTable = this.CreateStep(nodeStep);
  401. StepNos.Add(stepTable.StepNo);
  402. Steps.Add(stepTable);
  403. index++;
  404. }
  405. }
  406. }
  407. }