VirgoRecipeFileContext.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using System.Xml;
  8. using Aitex.Common.Util;
  9. using Aitex.Core.RT.Event;
  10. using Aitex.Core.RT.Log;
  11. using Aitex.Core.RT.RecipeCenter;
  12. using Aitex.Core.RT.SCCore;
  13. using Aitex.Core.Util;
  14. namespace VirgoRT.Modules.PMs
  15. {
  16. public class VirgoRecipeFileContext : IRecipeFileContext
  17. {
  18. public string GetRecipeDefiniton(string chamberId)
  19. {
  20. try
  21. {
  22. string recipeSchema = PathManager.GetCfgDir() + @"\RecipeFormat.xml";
  23. XmlDocument xmlDom = new XmlDocument();
  24. xmlDom.Load(recipeSchema);
  25. bool epdInstalled = SC.ContainsItem("System.SetUp.EPDInstalled") && SC.GetValue<bool>($"System.SetUp.EPDInstalled");
  26. if (!epdInstalled)
  27. {
  28. var nodeEndPoint =
  29. xmlDom.SelectSingleNode(
  30. string.Format(
  31. "/Aitex/TableRecipeFormat/Catalog/Group/Step[@ControlName='System.SetUp.EPDInstalled']"))
  32. as XmlElement;
  33. if (nodeEndPoint != null)
  34. {
  35. nodeEndPoint.ParentNode.RemoveChild(nodeEndPoint);
  36. }
  37. }
  38. double rfPowerRange = SC.GetValue<double>($"{chamberId}.Rf.PowerRange");
  39. double rfPowerRangeBias = SC.GetValue<double>($"{chamberId}.BiasRf.PowerRange");
  40. bool rfEnablePulsing = SC.GetValue<bool>($"{chamberId}.Rf.EnablePulsingFunction");
  41. bool rfEnableBias = SC.GetValue<bool>($"{chamberId}.BiasRf.EnableBiasRF");
  42. var nodeRfPowerBias = xmlDom.SelectSingleNode(string.Format("/Aitex/TableRecipeFormat/Catalog/Group/Step[@ControlName='BiasRf.SetPower']")) as XmlElement;
  43. var nodeMatchModeBias = xmlDom.SelectSingleNode(string.Format("/Aitex/TableRecipeFormat/Catalog/Group/Step[@ControlName='BiasRf.SetMatchProcessMode']")) as XmlElement;
  44. var nodeMatchC1Bias = xmlDom.SelectSingleNode(string.Format("/Aitex/TableRecipeFormat/Catalog/Group/Step[@ControlName='BiasRf.SetMatchPositionC1']")) as XmlElement;
  45. var nodeMatchC2Bias = xmlDom.SelectSingleNode(string.Format("/Aitex/TableRecipeFormat/Catalog/Group/Step[@ControlName='BiasRf.SetMatchPositionC2']")) as XmlElement;
  46. var nodeRfPower = xmlDom.SelectSingleNode(string.Format("/Aitex/TableRecipeFormat/Catalog/Group/Step[@ControlName='Rf.SetPower']")) as XmlElement;
  47. if (nodeRfPower != null)
  48. {
  49. nodeRfPower.SetAttribute("Max", (int)rfPowerRange + "");
  50. }
  51. if (nodeRfPowerBias != null)
  52. {
  53. nodeRfPowerBias.SetAttribute("Max", (int)rfPowerRangeBias + "");
  54. if (!rfEnableBias)
  55. {
  56. nodeRfPowerBias.ParentNode.RemoveChild(nodeRfPowerBias);
  57. nodeMatchModeBias.ParentNode.RemoveChild(nodeMatchModeBias);
  58. nodeMatchC1Bias.ParentNode.RemoveChild(nodeMatchC1Bias);
  59. nodeMatchC2Bias.ParentNode.RemoveChild(nodeMatchC2Bias);
  60. }
  61. }
  62. if (!rfEnablePulsing)
  63. {
  64. var node1 = xmlDom.SelectSingleNode(string.Format("/Aitex/TableRecipeFormat/Catalog/Group/Step[@ControlName='Rf.SetPulsingFrequency']")) as XmlElement;
  65. if (node1 != null)
  66. node1.ParentNode.RemoveChild(node1);
  67. var node2 = xmlDom.SelectSingleNode(string.Format("/Aitex/TableRecipeFormat/Catalog/Group/Step[@ControlName='Rf.SetPulsingDuty']")) as XmlElement;
  68. if (node2 != null)
  69. node2.ParentNode.RemoveChild(node2);
  70. var node3 = xmlDom.SelectSingleNode(string.Format("/Aitex/TableRecipeFormat/Catalog/Group/Step/Item[@ControlName='PulsingMode']")) as XmlElement;
  71. if (node3 != null)
  72. node3.ParentNode.RemoveChild(node3);
  73. }
  74. string gas1Name = SC.GetStringValue($"{chamberId}.MfcGas1.GasName");
  75. bool gas1Enable = SC.GetValue<bool>($"{chamberId}.MfcGas1.Enable");
  76. int gas1N2Scale = SC.GetValue<int>($"{chamberId}.MfcGas1.MfcN2Scale");
  77. double gas1ScaleFactor = SC.GetValue<double>($"{chamberId}.MfcGas1.MfcScaleFactor");
  78. var nodeGas1 = xmlDom.SelectSingleNode(string.Format("/Aitex/TableRecipeFormat/Catalog/Group/Step[@ControlName='MfcGas1']")) as XmlElement;
  79. if (nodeGas1 != null)
  80. {
  81. nodeGas1.SetAttribute("DisplayName", gas1Name);
  82. nodeGas1.SetAttribute("Max", (int)(gas1N2Scale * gas1ScaleFactor) + "");
  83. if (!gas1Enable)
  84. nodeGas1.ParentNode.RemoveChild(nodeGas1);
  85. }
  86. string gas2Name = SC.GetStringValue($"{chamberId}.MfcGas2.GasName");
  87. bool gas2Enable = SC.GetValue<bool>($"{chamberId}.MfcGas2.Enable");
  88. int gas2N2Scale = SC.GetValue<int>($"{chamberId}.MfcGas2.MfcN2Scale");
  89. double gas2ScaleFactor = SC.GetValue<double>($"{chamberId}.MfcGas2.MfcScaleFactor");
  90. var nodeGas2 = xmlDom.SelectSingleNode(string.Format("/Aitex/TableRecipeFormat/Catalog/Group/Step[@ControlName='MfcGas2']")) as XmlElement;
  91. if (nodeGas2 != null)
  92. {
  93. nodeGas2.SetAttribute("DisplayName", gas2Name);
  94. nodeGas2.SetAttribute("Max", (int)(gas2N2Scale * gas2ScaleFactor) + "");
  95. if (!gas2Enable)
  96. nodeGas2.ParentNode.RemoveChild(nodeGas2);
  97. }
  98. string gas3Name = SC.GetStringValue($"{chamberId}.MfcGas3.GasName");
  99. bool gas3Enable = SC.GetValue<bool>($"{chamberId}.MfcGas3.Enable");
  100. int gas3N2Scale = SC.GetValue<int>($"{chamberId}.MfcGas3.MfcN2Scale");
  101. double gas3ScaleFactor = SC.GetValue<double>($"{chamberId}.MfcGas3.MfcScaleFactor");
  102. var nodeGas3 = xmlDom.SelectSingleNode(string.Format("/Aitex/TableRecipeFormat/Catalog/Group/Step[@ControlName='MfcGas3']")) as XmlElement;
  103. if (nodeGas3 != null)
  104. {
  105. nodeGas3.SetAttribute("DisplayName", gas3Name);
  106. nodeGas3.SetAttribute("Max", (int)(gas3N2Scale * gas3ScaleFactor) + "");
  107. if (!gas3Enable)
  108. nodeGas3.ParentNode.RemoveChild(nodeGas3);
  109. }
  110. string gas4Name = SC.GetStringValue($"{chamberId}.MfcGas4.GasName");
  111. bool gas4Enable = SC.GetValue<bool>($"{chamberId}.MfcGas4.Enable");
  112. int gas4N2Scale = SC.GetValue<int>($"{chamberId}.MfcGas4.MfcN2Scale");
  113. double gas4ScaleFactor = SC.GetValue<double>($"{chamberId}.MfcGas4.MfcScaleFactor");
  114. var nodeGas4 = xmlDom.SelectSingleNode(string.Format("/Aitex/TableRecipeFormat/Catalog/Group/Step[@ControlName='MfcGas4']")) as XmlElement;
  115. if (nodeGas4 != null)
  116. {
  117. nodeGas4.SetAttribute("DisplayName", gas4Name);
  118. nodeGas4.SetAttribute("Max", (int)(gas4N2Scale * gas4ScaleFactor) + "");
  119. if (!gas4Enable)
  120. nodeGas4.ParentNode.RemoveChild(nodeGas4);
  121. }
  122. string gas5Name = SC.GetStringValue($"{chamberId}.MfcGas5.GasName");
  123. bool gas5Enable = SC.GetValue<bool>($"{chamberId}.MfcGas5.Enable");
  124. int gas5N2Scale = SC.GetValue<int>($"{chamberId}.MfcGas5.MfcN2Scale");
  125. double gas5ScaleFactor = SC.GetValue<double>($"{chamberId}.MfcGas5.MfcScaleFactor");
  126. var nodeGas5 = xmlDom.SelectSingleNode(string.Format("/Aitex/TableRecipeFormat/Catalog/Group/Step[@ControlName='MfcGas5']")) as XmlElement;
  127. if (nodeGas5 != null)
  128. {
  129. nodeGas5.SetAttribute("DisplayName", gas5Name);
  130. nodeGas5.SetAttribute("Max", (int)(gas5N2Scale * gas5ScaleFactor) + "");
  131. if (!gas5Enable)
  132. nodeGas5.ParentNode.RemoveChild(nodeGas5);
  133. }
  134. //xmlDom.Save(recipeSchema);
  135. return xmlDom.OuterXml;
  136. }
  137. catch (Exception ex)
  138. {
  139. LOG.Write(ex);
  140. return "";
  141. }
  142. }
  143. public IEnumerable<string> GetRecipes(string chamberId, bool includingUsedRecipe)
  144. {
  145. try
  146. {
  147. string recipePath = PathManager.GetRecipeDir() + chamberId + "\\";
  148. var di = new DirectoryInfo(recipePath);
  149. var fis = di.GetFiles("*.rcp", SearchOption.AllDirectories);
  150. var recipes = new List<string>();
  151. foreach (var fi in fis)
  152. {
  153. string str = fi.FullName.Substring(recipePath.Length);
  154. str = str.Substring(0, str.LastIndexOf('.'));
  155. if (includingUsedRecipe || (!includingUsedRecipe && !str.Contains("HistoryRecipe\\")))
  156. {
  157. recipes.Add(str);
  158. }
  159. }
  160. return recipes;
  161. }
  162. catch (Exception ex)
  163. {
  164. LOG.Write(ex);
  165. return new List<string>();
  166. }
  167. }
  168. public void PostInfoEvent(string message)
  169. {
  170. EV.PostMessage("System", EventEnum.GeneralInfo, message);
  171. }
  172. public void PostWarningEvent(string message)
  173. {
  174. EV.PostMessage("System", EventEnum.DefaultWarning, message);
  175. }
  176. public void PostAlarmEvent(string message)
  177. {
  178. EV.PostMessage("System", EventEnum.DefaultAlarm, message);
  179. }
  180. public void PostDialogEvent(string message)
  181. {
  182. EV.PostNotificationMessage(message);
  183. }
  184. public void PostInfoDialogMessage(string message)
  185. {
  186. EV.PostMessage("System", EventEnum.GeneralInfo, message);
  187. EV.PostPopDialogMessage(EventLevel.Information, "System Information", message);
  188. }
  189. public void PostWarningDialogMessage(string message)
  190. {
  191. EV.PostMessage("System", EventEnum.GeneralInfo, message);
  192. EV.PostPopDialogMessage(EventLevel.Warning, "System Warning", message);
  193. }
  194. public void PostAlarmDialogMessage(string message)
  195. {
  196. EV.PostMessage("System", EventEnum.GeneralInfo, message);
  197. EV.PostPopDialogMessage(EventLevel.Alarm, "System Alarm", message);
  198. }
  199. public string GetRecipeTemplate(string chamberId)
  200. {
  201. string schema = GetRecipeDefiniton(chamberId);
  202. XmlDocument dom = new XmlDocument();
  203. dom.LoadXml(schema);
  204. XmlNode nodeTemplate = dom.SelectSingleNode("/Aitex/TableRecipeData");
  205. return nodeTemplate.OuterXml;
  206. }
  207. public bool EnableEdit(string recipeName)
  208. {
  209. if (Singleton<RouteManager>.Instance.CheckRecipeUsedInJob(recipeName))
  210. {
  211. EV.PostWarningLog("System", "Recipe is used in auto running jobs, can not be modified");
  212. return false;
  213. }
  214. return true;
  215. }
  216. }
  217. }