Recipe.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Collections.ObjectModel;
  4. using System.ComponentModel;
  5. using System.Diagnostics;
  6. using System.IO;
  7. using System.Linq;
  8. using System.Reflection;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. using Newtonsoft.Json;
  12. using Newtonsoft.Json.Converters;
  13. namespace Venus_Core
  14. {
  15. public enum RecipeType
  16. {
  17. Chuck,
  18. DeChuck,
  19. Process,
  20. Clean,
  21. }
  22. public enum StepType
  23. {
  24. Time,
  25. Stable,
  26. EndPoint,
  27. OverEtch,
  28. }
  29. public enum ProcessModule
  30. {
  31. Pressure,
  32. TCP, // Transformer Coupled Plasma (转换耦合等离子)
  33. Bias,
  34. Gas,
  35. ESC,
  36. Process,
  37. Compound,
  38. }
  39. public enum GeneratorMode
  40. {
  41. Pulsing,
  42. CW,
  43. }
  44. public enum PressureUnitMode
  45. {
  46. Pressure,
  47. Valve
  48. }
  49. public class RecipeHead: INotifyPropertyChanged
  50. {
  51. private string m_name;
  52. public string Name
  53. {
  54. get { return m_name; }
  55. set { m_name = value; InvokePropertyChanged("Name"); }
  56. }
  57. private string _Version = "TestVersion";
  58. public string Version
  59. {
  60. get { return _Version; }
  61. set { _Version = value; InvokePropertyChanged("Version"); }
  62. }
  63. private RecipeType m_Type;
  64. [JsonConverter(typeof(StringEnumConverter))]
  65. public RecipeType Type
  66. {
  67. get { return m_Type; }
  68. set { m_Type = value; InvokePropertyChanged("Type"); }
  69. }
  70. private string m_ChunckRecipe;
  71. public string ChuckRecipe
  72. {
  73. get { return m_ChunckRecipe;}
  74. set { m_ChunckRecipe = value; InvokePropertyChanged("ChuckRecipe"); }
  75. }
  76. private string m_DechuckRecipe;
  77. public string DechuckRecipe
  78. {
  79. get { return m_DechuckRecipe;}
  80. set{ m_DechuckRecipe = value;InvokePropertyChanged("DechuckRecipe");}
  81. }
  82. private string m_CreateTime;
  83. public string CreateTime
  84. {
  85. get { return m_CreateTime;}
  86. set { m_CreateTime = value; InvokePropertyChanged("CreateTime"); }
  87. }
  88. private string m_LastModifiedBy;
  89. public string LastModifiedBy
  90. {
  91. get { return m_LastModifiedBy;}
  92. set { m_LastModifiedBy = value; InvokePropertyChanged("CreateTime"); }
  93. }
  94. private string m_Barcode;
  95. public string Barcode
  96. {
  97. get { return m_Barcode;}
  98. set { m_Barcode = value; InvokePropertyChanged("Barcode"); }
  99. }
  100. private string m_BasePressure;
  101. public string BasePressure
  102. {
  103. get { return m_BasePressure;}
  104. set { m_BasePressure = value; InvokePropertyChanged("BasePressure"); }
  105. }
  106. private string m_ChillerTemp;
  107. public string ChillerTemp
  108. {
  109. get { return m_ChillerTemp;}
  110. set { m_ChillerTemp = value; InvokePropertyChanged("ChillerTemp"); }
  111. }
  112. public event PropertyChangedEventHandler PropertyChanged;
  113. public void InvokePropertyChanged(string propertyName)
  114. {
  115. if (PropertyChanged != null)
  116. {
  117. PropertyChanged.Invoke(this, new PropertyChangedEventArgs(propertyName));
  118. }
  119. }
  120. }
  121. public class ProcessUnitBase
  122. {
  123. [JsonIgnore]
  124. public Func<ProcessUnitBase, RecipeStep, RState> checker;
  125. [JsonIgnore]
  126. public Func<ProcessUnitBase, RecipeStep, RState> starter;
  127. [JsonIgnore]
  128. public Action<ProcessUnitBase, RecipeStep> end;
  129. //[JsonIgnore]
  130. //public string Name { get; set; }
  131. //[JsonIgnore]
  132. //public ProcessModule Moudle { get; set; }
  133. public RState Start(RecipeStep step)
  134. {
  135. if (starter != null)
  136. return starter(this, step);
  137. return RState.Running;
  138. }
  139. public RState Run(RecipeStep step)
  140. {
  141. if (checker != null)
  142. return checker(this, step);
  143. return RState.Running;
  144. }
  145. public void End(RecipeStep step)
  146. {
  147. if (end != null)
  148. end(this, step);
  149. }
  150. }
  151. public class RecipeStep:INotifyPropertyChanged
  152. {
  153. //public string m_UnitName="StepDescriptionUnit";
  154. //public string UnitName
  155. //{
  156. // get { return m_UnitName;}
  157. // set { m_UnitName = value; InvokePropertyChanged("UnitName"); }
  158. //}
  159. [JsonIgnore]
  160. public Func<RecipeStep, RState> checker;
  161. [JsonIgnore]
  162. public Func<RecipeStep, RState> starter;
  163. private StepType m_StepType;
  164. [JsonConverter(typeof(StringEnumConverter))]
  165. public StepType Type
  166. {
  167. get { return m_StepType;}
  168. set { m_StepType = value; InvokePropertyChanged("Type"); }
  169. }
  170. private int m_Time;
  171. public int Time
  172. {
  173. get { return m_Time;}
  174. set { m_Time = value; InvokePropertyChanged("Time"); }
  175. }
  176. private int m_MinEndPointTime;
  177. public int MinEndPointTime
  178. {
  179. get { return m_MinEndPointTime;}
  180. set { m_MinEndPointTime = value; InvokePropertyChanged("MinEndPointTime"); }
  181. }
  182. private int m_MaxEndPointTime;
  183. public int MaxEndPointTime
  184. {
  185. get { return m_MaxEndPointTime; }
  186. set { m_MaxEndPointTime = value; InvokePropertyChanged("MaxEndPointTime"); }
  187. }
  188. private bool m_CycleStart;
  189. public bool CycleStart
  190. {
  191. get { return m_CycleStart;}
  192. set { m_CycleStart = value; InvokePropertyChanged("CycleStart"); }
  193. }
  194. private bool m_CycleEnd;
  195. public bool CycleEnd
  196. {
  197. get { return m_CycleEnd;}
  198. set { m_CycleEnd = value; InvokePropertyChanged("CycleEnd"); }
  199. }
  200. private int m_CycleNumber;
  201. public int CycleNumber
  202. {
  203. get { return m_CycleNumber;}
  204. set { m_CycleNumber = value; InvokePropertyChanged("CycleNumber"); }
  205. }
  206. public PressureUnitMode PressureUnitMode { get; set; }
  207. private ObservableCollection<Object> lstUnit = new ObservableCollection<Object>();
  208. public ObservableCollection<Object> LstUnit
  209. {
  210. get { return lstUnit; }
  211. set { lstUnit = value; InvokePropertyChanged("LstUnit"); }
  212. }
  213. private Stopwatch _stepTimer = new Stopwatch();
  214. [JsonIgnore]
  215. public long ElapsedTime
  216. {
  217. get { return _stepTimer.ElapsedMilliseconds; }
  218. }
  219. public RState Start()
  220. {
  221. _stepTimer.Restart();
  222. starter(this);
  223. foreach (var unit in lstUnit)
  224. {
  225. var processUnit = unit as ProcessUnitBase;
  226. if (processUnit != null)
  227. {
  228. var state = processUnit.Start(this);
  229. if (state != RState.Running)
  230. return state;
  231. }
  232. else
  233. return RState.Failed;
  234. }
  235. return RState.Running;
  236. }
  237. public RState Run()
  238. {
  239. if (checker(this) == RState.End)
  240. return RState.End;
  241. foreach (var unit in lstUnit)
  242. {
  243. var processUnit = unit as ProcessUnitBase;
  244. if (processUnit != null)
  245. {
  246. var state = processUnit.Run(this);
  247. if (state != RState.Running)
  248. return state;
  249. }
  250. else
  251. return RState.Failed;
  252. }
  253. return RState.Running;
  254. }
  255. public void End()
  256. {
  257. foreach (var unit in lstUnit)
  258. {
  259. var processUnit = unit as ProcessUnitBase;
  260. if (processUnit != null)
  261. {
  262. processUnit.End(this);
  263. }
  264. }
  265. }
  266. public double RampFactor()
  267. {
  268. return _stepTimer.ElapsedMilliseconds / (Time * 1000.0);
  269. }
  270. public void AppendUnit(ProcessUnitBase unit)
  271. {
  272. lstUnit.Append(unit);
  273. }
  274. public event PropertyChangedEventHandler PropertyChanged;
  275. public void InvokePropertyChanged(string propertyName)
  276. {
  277. if (PropertyChanged != null)
  278. {
  279. PropertyChanged.Invoke(this, new PropertyChangedEventArgs(propertyName));
  280. }
  281. }
  282. }
  283. public class Recipe: INotifyPropertyChanged
  284. {
  285. private RecipeHead m_Header = new RecipeHead();
  286. public RecipeHead Header
  287. {
  288. get { return m_Header; }
  289. set { m_Header = value; InvokePropertyChanged("Header"); }
  290. }
  291. private ObservableCollection<RecipeStep> m_Steps;
  292. public ObservableCollection<RecipeStep> Steps
  293. {
  294. get { return m_Steps; }
  295. set { m_Steps = value; InvokePropertyChanged("Steps"); }
  296. }
  297. public static Recipe Load(string recipeFile)
  298. {
  299. var recipe= JsonConvert.DeserializeObject<Recipe>(recipeFile);
  300. foreach (var step in recipe.Steps)
  301. {
  302. ObservableCollection<ProcessUnitBase> unit = new ObservableCollection<ProcessUnitBase>();
  303. //int count = step.LstUnit.Count / 2;
  304. //for (int i = 0; i < count; i++)
  305. //{
  306. // Type t = Type.GetType(step.LstUnit[i].ToString());
  307. // //unit.Add(JsonConvert.DeserializeObject<t>(step.LstUnit[i+count].ToString()));
  308. // unit.Add(JsonConvert.DeserializeObject<ProcessUnitBase>(step.LstUnit[i + count].ToString()));
  309. //}
  310. //var item = step.LstUnit[0];
  311. for (int i=0;i< step.LstUnit.Count; i++)
  312. {
  313. //object item=step.LstUnit[i];
  314. //step.LstUnit[i].
  315. string value = step.LstUnit[i].ToString();
  316. string[] striparr = value.Split(new string[] { "\r\n" }, StringSplitOptions.None);
  317. string item1= striparr[1].Remove(0, 15);
  318. string item2 = item1.Remove(item1.Length - 2, 2);
  319. //var item= value.Substring(value.IndexOf("UnitName"));
  320. //Type t = Type.GetType(value);
  321. switch (item2)
  322. {
  323. case "PressureByPressureModeUnit":
  324. unit.Add(JsonConvert.DeserializeObject<PressureByPressureModeUnit>(step.LstUnit[i].ToString()));
  325. break;
  326. case "PressureByValveModeUnit":
  327. unit.Add(JsonConvert.DeserializeObject<PressureByValveModeUnit>(step.LstUnit[i].ToString()));
  328. break;
  329. case "TCPUnit":
  330. unit.Add(JsonConvert.DeserializeObject<TCPUnit>(step.LstUnit[i].ToString()));
  331. break;
  332. case "BiasUnit":
  333. unit.Add(JsonConvert.DeserializeObject<BiasUnit>(step.LstUnit[i].ToString()));
  334. break;
  335. case "GasControlUnit":
  336. unit.Add(JsonConvert.DeserializeObject<GasControlUnit>(step.LstUnit[i].ToString()));
  337. break;
  338. case "ESCHVUnit":
  339. unit.Add(JsonConvert.DeserializeObject<ESCHVUnit>(step.LstUnit[i].ToString()));
  340. break;
  341. case "ProcessKitUnit":
  342. unit.Add(JsonConvert.DeserializeObject<ProcessKitUnit>(step.LstUnit[i].ToString()));
  343. break;
  344. }
  345. }
  346. step.LstUnit.Clear();
  347. unit.ToList().ForEach(x =>
  348. {
  349. step.LstUnit.Add(x);
  350. });
  351. }
  352. return recipe;
  353. }
  354. public bool Validate()
  355. {
  356. return true;
  357. }
  358. public bool Save(string recipeFile)
  359. {
  360. return true;
  361. }
  362. public event PropertyChangedEventHandler PropertyChanged;
  363. public void InvokePropertyChanged(string propertyName)
  364. {
  365. if (PropertyChanged != null)
  366. {
  367. PropertyChanged.Invoke(this, new PropertyChangedEventArgs(propertyName));
  368. }
  369. }
  370. }
  371. public class RecipeUnity
  372. {
  373. public static string ConvertJsonString(string str)
  374. {
  375. JsonSerializer serializer = new JsonSerializer();
  376. TextReader tr = new StringReader(str);
  377. JsonTextReader jtr = new JsonTextReader(tr);
  378. object obj = serializer.Deserialize(jtr);
  379. if (obj != null)
  380. {
  381. StringWriter textWriter = new StringWriter();
  382. JsonTextWriter jsonWriter = new JsonTextWriter(textWriter)
  383. {
  384. Formatting = Newtonsoft.Json.Formatting.Indented,
  385. Indentation = 4,
  386. IndentChar = ' '
  387. };
  388. serializer.Serialize(jsonWriter, obj);
  389. return textWriter.ToString();
  390. }
  391. else
  392. {
  393. return str;
  394. }
  395. }
  396. public static string RecipeToString(Recipe recipe)
  397. {
  398. return JsonConvert.SerializeObject(recipe);
  399. }
  400. public static String CreateRecipe(RecipeType recipeType,string recipeName)
  401. {
  402. Recipe recipe = new Recipe();
  403. recipe.Header = new RecipeHead();
  404. recipe.Header.CreateTime = DateTime.Now.ToString();
  405. recipe.Header.Type = recipeType;
  406. recipe.Header.Name = recipeName;
  407. recipe.Header.LastModifiedBy = "Admin";
  408. recipe.Steps = new ObservableCollection<RecipeStep>();
  409. recipe.Steps.Add(new RecipeStep()
  410. {
  411. LstUnit = new ObservableCollection<Object>()
  412. {
  413. new PressureByPressureModeUnit(),
  414. new TCPUnit(),
  415. new BiasUnit(),
  416. new GasControlUnit(),
  417. new ESCHVUnit(),
  418. new ProcessKitUnit()
  419. }
  420. });
  421. var recipeString = JsonConvert.SerializeObject(recipe);
  422. //var Recipe2=JsonConvert.DeserializeObject<Recipe>(recipeString);
  423. //string test = "";
  424. //test = Recipe2.Steps[0].LstUnit[0].ToString();
  425. //var tcpinit = JsonConvert.DeserializeObject<TCPUnit>(test);
  426. return recipeString;
  427. }
  428. }
  429. }