TempCorrectionParameterData.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  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 TempCorrectionParameterData : ParameterDataBase
  18. {
  19. private ParameterProvider _parameterProvider = new ParameterProvider();
  20. private ParameterFormatBuilder _columnBuilder = new ParameterFormatBuilder();
  21. private Dictionary<string, ObservableCollection<ParameterTemplateColumnBase>> ParameterTemplate;
  22. public TempCorrectionParameterData() : base()
  23. {
  24. string vars = _parameterProvider.GetParameterFormatXml($"Parameter\\TempCorrection");
  25. _columnBuilder.Build($"Parameter\\TempCorrection");
  26. ParameterTemplate = _parameterProvider.GetGroupParameterTemplate();
  27. TableNumber = _columnBuilder.TableNumber;
  28. Version = _columnBuilder.Version;
  29. for (int i = 1; i < TableNumber+1; i++)
  30. {
  31. Steps.Add(CreateStep());
  32. }
  33. }
  34. public override ParameterTable CreateStep(XmlNode stepNode = null)
  35. {
  36. ParameterTable table = new TempCorrectionTable();
  37. var step = table as TempCorrectionTable;
  38. if (stepNode != null)
  39. {
  40. if (stepNode.Attributes["StepNo"] != null)
  41. step.StepNo = int.Parse(stepNode.Attributes["StepNo"].Value);
  42. if (stepNode.Attributes["Name"] != null)
  43. step.Name = stepNode.Attributes["Name"].Value;
  44. }
  45. else
  46. {
  47. step.StepNo = StepNo;
  48. step.Name = "Name" + StepNo.ToString();
  49. // step.UseTemp = "0";
  50. StepNo++;
  51. }
  52. int pIDIndex = 1;
  53. var profileTCCalibTempcom = ParameterTemplate["Parameter Information"].Where(x => x.ControlName == "ProfileTCCalibTemp").FirstOrDefault();
  54. if (profileTCCalibTempcom != null)
  55. {
  56. DoubleParam profileTCCalibParam = new DoubleParam()
  57. {
  58. Name = profileTCCalibTempcom.ControlName,
  59. Value = profileTCCalibTempcom.Value.ToString(),
  60. DisplayName = profileTCCalibTempcom.DisplayName,
  61. Minimun = profileTCCalibTempcom.Minimun,
  62. Maximun = profileTCCalibTempcom.Maximun,
  63. Resolution = 0
  64. };
  65. step.ProfileTCCalibTemp = profileTCCalibParam;
  66. }
  67. var profileCTableNocom = ParameterTemplate["Parameter Information"].Where(x => x.ControlName == "ProfileConditionTableNo").FirstOrDefault();
  68. if (profileCTableNocom != null)
  69. {
  70. NumParam profileCTableNoParam = new NumParam()
  71. {
  72. Name = profileCTableNocom.ControlName,
  73. Value = (int)profileCTableNocom.Value,
  74. DisplayName = profileCTableNocom.DisplayName,
  75. Minimun = profileCTableNocom.Minimun,
  76. Maximun = profileCTableNocom.Maximun,
  77. };
  78. step.ProfileConditionTableNo = profileCTableNoParam;
  79. }
  80. var tableNocom = ParameterTemplate["Parameter Information"].Where(x => x.ControlName == "TempPIDTableNo").FirstOrDefault();
  81. if (tableNocom != null)
  82. {
  83. NumParam TableNo = new NumParam()
  84. {
  85. Name = tableNocom.ControlName,
  86. Value = (int)tableNocom.Value,
  87. DisplayName = tableNocom.DisplayName,
  88. Minimun = tableNocom.Minimun,
  89. Maximun = tableNocom.Maximun,
  90. };
  91. step.TableNo = TableNo;
  92. }
  93. var tableUseRangeMincom = ParameterTemplate["Parameter Information"].Where(x => x.ControlName == "TableUseRangeMin").FirstOrDefault();
  94. if (tableUseRangeMincom != null)
  95. {
  96. DoubleParam tableUseRangeMinParam = new DoubleParam()
  97. {
  98. Name = tableUseRangeMincom.ControlName,
  99. Value = tableUseRangeMincom.Value.ToString(),
  100. DisplayName = tableUseRangeMincom.DisplayName,
  101. Minimun = tableUseRangeMincom.Minimun,
  102. Maximun = tableUseRangeMincom.Maximun,
  103. Resolution = 0
  104. };
  105. step.TableUseRangeMin = tableUseRangeMinParam;
  106. }
  107. var tableUseRangeMaxcom = ParameterTemplate["Parameter Information"].Where(x => x.ControlName == "TableUseRangeMax").FirstOrDefault();
  108. if (tableUseRangeMaxcom != null)
  109. {
  110. DoubleParam tableUseRangeMaxParam = new DoubleParam()
  111. {
  112. Name = tableUseRangeMaxcom.ControlName,
  113. Value = tableUseRangeMaxcom.Value.ToString(),
  114. DisplayName = tableUseRangeMaxcom.DisplayName,
  115. Minimun = tableUseRangeMaxcom.Minimun,
  116. Maximun = tableUseRangeMaxcom.Maximun,
  117. Resolution = 0
  118. };
  119. step.TableUseRangeMax = tableUseRangeMaxParam;
  120. }
  121. foreach (var item in ParameterTemplate)
  122. {
  123. if (item.Key != "Parameter Information")
  124. {
  125. var _correctionData = new CorrectionData()
  126. {
  127. Name = item.Key,
  128. Index = pIDIndex
  129. };
  130. var profileTempcom = item.Value.Where(x => x.ControlName == "ProfileTemp").FirstOrDefault();
  131. if (profileTempcom != null)
  132. {
  133. DoubleParam profileTempParam = new DoubleParam()
  134. {
  135. Name = profileTempcom.ControlName,
  136. Value = profileTempcom.Value.ToString(),
  137. DisplayName = profileTempcom.DisplayName,
  138. Minimun = profileTempcom.Minimun,
  139. Maximun = profileTempcom.Maximun,
  140. Resolution = 0
  141. };
  142. _correctionData.ProfileTemp= profileTempParam;
  143. }
  144. var profileCorrectcom = item.Value.Where(x => x.ControlName == "ProfileCorrect").FirstOrDefault();
  145. if (profileCorrectcom != null)
  146. {
  147. DoubleParam profileCorrectParam = new DoubleParam()
  148. {
  149. Name = profileCorrectcom.ControlName,
  150. Value = profileCorrectcom.Value.ToString(),
  151. DisplayName = profileCorrectcom.DisplayName,
  152. Minimun = profileCorrectcom.Minimun,
  153. Maximun = profileCorrectcom.Maximun,
  154. Resolution = 0
  155. };
  156. _correctionData.ProfileCorrect = profileCorrectParam;
  157. }
  158. var cascadeTCCorrectcom = item.Value.Where(x => x.ControlName == "CascadeTCCorrect").FirstOrDefault();
  159. if (cascadeTCCorrectcom != null)
  160. {
  161. DoubleParam cascadeTCCorrectcomParam = new DoubleParam()
  162. {
  163. Name = cascadeTCCorrectcom.ControlName,
  164. Value = cascadeTCCorrectcom.Value.ToString(),
  165. DisplayName = cascadeTCCorrectcom.DisplayName,
  166. Minimun = cascadeTCCorrectcom.Minimun,
  167. Maximun = cascadeTCCorrectcom.Maximun,
  168. Resolution = 0
  169. };
  170. _correctionData.CascadeTCCorrect = cascadeTCCorrectcomParam;
  171. }
  172. var profileTCCalibcom = item.Value.Where(x => x.ControlName == "ProfileTCCalib").FirstOrDefault();
  173. if (profileTCCalibcom != null)
  174. {
  175. DoubleParam profileTCCalibParam = new DoubleParam()
  176. {
  177. Name = profileTCCalibcom.ControlName,
  178. Value = profileTCCalibcom.Value.ToString(),
  179. DisplayName = profileTCCalibcom.DisplayName,
  180. Minimun = profileTCCalibcom.Minimun,
  181. Maximun = profileTCCalibcom.Maximun,
  182. Resolution = 0
  183. };
  184. _correctionData.ProfileTCCalib = profileTCCalibParam;
  185. }
  186. ((TempCorrectionTable)step).CorrectionDataList.Add(_correctionData);
  187. pIDIndex++;
  188. }
  189. }
  190. if (stepNode != null)
  191. {
  192. if (stepNode.Attributes["ProfileTCCalibTemp"] != null)
  193. step.ProfileTCCalibTemp.Value = stepNode.Attributes["ProfileTCCalibTemp"].Value;
  194. if (stepNode.Attributes["ProfileConditionTableNo"] != null)
  195. step.ProfileConditionTableNo.Value = Convert.ToInt32(stepNode.Attributes["ProfileConditionTableNo"].Value);
  196. if (stepNode.Attributes["TempPIDTableNo"] != null)
  197. step.TableNo.Value = Convert.ToInt32(stepNode.Attributes["TempPIDTableNo"].Value);
  198. if (stepNode.Attributes["TableUseRangeMin"] != null)
  199. step.TableUseRangeMin.Value = stepNode.Attributes["TableUseRangeMin"].Value;
  200. if (stepNode.Attributes["TableUseRangeMax"] != null)
  201. step.TableUseRangeMax.Value = stepNode.Attributes["TableUseRangeMax"].Value;
  202. if (stepNode.Attributes["ProfileLastUpdate"] != null)
  203. step.ProfileLastUpdate = stepNode.Attributes["ProfileLastUpdate"].Value;
  204. foreach (var item in ((TempCorrectionTable)step).CorrectionDataList)
  205. {
  206. if (stepNode.Attributes["CorrectionData"] != null)
  207. {
  208. ((TempCorrectionTable)step).SetTempCorrectionData(stepNode.Attributes["CorrectionData"].Value.ToString());
  209. }
  210. }
  211. }
  212. return step;
  213. }
  214. public override string GetXmlString()
  215. {
  216. XmlElement nodeData = _doc.SelectSingleNode($"Aitex/TableParameterData") as XmlElement;
  217. nodeData.SetAttribute("CreatedBy", Creator);
  218. nodeData.SetAttribute("CreationTime", CreateTime.ToString("yyyy-MM-dd HH:mm:ss"));
  219. nodeData.SetAttribute("LastRevisedBy", Revisor);
  220. nodeData.SetAttribute("LastRevisionTime", ReviseTime.ToString("yyyy-MM-dd HH:mm:ss"));
  221. nodeData.SetAttribute("Description", Description);
  222. nodeData.SetAttribute("ParameterChamberType", ChamberType);
  223. nodeData.SetAttribute("Version", Version);
  224. nodeData.SetAttribute("TableNumber", TableNumber.ToString());
  225. nodeData.SetAttribute("Permission", Permission);
  226. nodeData.SetAttribute("ParameterLevel", Level);
  227. XmlNode nodeModule = _doc.SelectSingleNode($"Aitex/TableParameterData/Module[@Name='{_module}']");
  228. if (nodeModule == null)
  229. {
  230. nodeModule = _doc.CreateElement("Module");
  231. nodeData.AppendChild(nodeModule);
  232. }
  233. nodeModule.RemoveAll();
  234. (nodeModule as XmlElement).SetAttribute("Name", _module);
  235. int i = 0;
  236. foreach (TempCorrectionTable parameter in Steps)
  237. {
  238. XmlElement nodeStep = _doc.CreateElement("Step");
  239. nodeStep.SetAttribute("StepNo", parameter.StepNo.ToString());
  240. nodeStep.SetAttribute("Name", parameter.Name);
  241. // nodeStep.SetAttribute("UseTemp", parameter.UseTemp);
  242. nodeStep.SetAttribute("ProfileTCCalibTemp", parameter.ProfileTCCalibTemp.Value.ToString());
  243. nodeStep.SetAttribute("ProfileConditionTableNo", parameter.ProfileConditionTableNo.Value.ToString());
  244. nodeStep.SetAttribute("TempPIDTableNo", parameter.TableNo.Value.ToString());
  245. nodeStep.SetAttribute("TableUseRangeMin", parameter.TableUseRangeMin.Value.ToString());
  246. nodeStep.SetAttribute("TableUseRangeMax", parameter.TableUseRangeMax.Value.ToString());
  247. nodeStep.SetAttribute("ProfileLastUpdate", parameter.ProfileLastUpdate);
  248. var correctionDatas = ((TempCorrectionTable)parameter).CorrectionDataList.Select(x => x.ToString()).ToArray();
  249. nodeStep.SetAttribute($"CorrectionData",string.Join("|" ,correctionDatas));
  250. nodeModule.AppendChild(nodeStep);
  251. i++;
  252. }
  253. return _doc.OuterXml;
  254. }
  255. public override void InitData(string prefixPath, string recipeName, string recipeContent, string module)
  256. {
  257. IsCompatibleWithCurrentFormat = false;
  258. _module = module;
  259. Name = recipeName;
  260. PrefixPath = prefixPath;
  261. try
  262. {
  263. _doc = new XmlDocument();
  264. _doc.LoadXml(recipeContent);
  265. if (!LoadHeader(_doc.SelectSingleNode("Aitex/TableParameterData")))
  266. return;
  267. XmlNodeList nodeSteps = _doc.SelectNodes($"Aitex/TableParameterData/Module[@Name='{module}']/Step");
  268. if (nodeSteps == null)
  269. nodeSteps = _doc.SelectNodes($"Aitex/TableParameterData/Step");
  270. LoadSteps(nodeSteps);
  271. var index = 1;
  272. foreach (ParameterTable parameters in Steps)
  273. {
  274. parameters.Value = index.ToString();
  275. index++;
  276. }
  277. // ValidLoopData();
  278. XmlNode nodeConfig =
  279. _doc.SelectSingleNode($"Aitex/TableParameterData/Module[@Name='{module}']/Config");
  280. if (nodeSteps == null)
  281. nodeConfig = _doc.SelectSingleNode($"Aitex/TableParameterData/Config");
  282. IsCompatibleWithCurrentFormat = true;
  283. }
  284. catch (Exception ex)
  285. {
  286. LOG.Write(ex);
  287. }
  288. }
  289. public override void LoadSteps(XmlNodeList steps)
  290. {
  291. Steps.Clear();
  292. PopSettingSteps.Clear();
  293. StepTolerances.Clear();
  294. StepNos.Clear();
  295. int index = 1;
  296. foreach (XmlNode nodeStep in steps)
  297. {
  298. ParameterTable stepTable = this.CreateStep(nodeStep);
  299. StepNos.Add(stepTable.StepNo);
  300. Steps.Add(stepTable);
  301. index++;
  302. }
  303. }
  304. }
  305. }