Recipe.cs 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702
  1. using System;
  2. using System.Collections.ObjectModel;
  3. using System.ComponentModel;
  4. using System.Diagnostics;
  5. using System.IO;
  6. using System.Linq;
  7. using Newtonsoft.Json;
  8. using Newtonsoft.Json.Converters;
  9. using Venus_Core.Attributes;
  10. namespace Venus_Core
  11. {
  12. public enum RecipeType
  13. {
  14. Chuck,
  15. DeChuck,
  16. Process,
  17. Clean,
  18. }
  19. public enum StepType
  20. {
  21. Time,
  22. Stable,
  23. EndPoint,
  24. OverEtch,
  25. }
  26. public enum ProcessModule
  27. {
  28. Pressure,
  29. TCP, // Transformer Coupled Plasma (转换耦合等离子)
  30. Bias,
  31. Gas,
  32. ESC,
  33. Process,
  34. Compound,
  35. }
  36. public enum GeneratorMode
  37. {
  38. CW,
  39. Pulsing,
  40. }
  41. public enum PressureUnitMode
  42. {
  43. Pressure,
  44. Valve
  45. }
  46. public enum Suspect
  47. {
  48. Origin,
  49. Position1,
  50. Position2,
  51. Position3,
  52. Position4,
  53. Position5
  54. }
  55. public enum TargetMode
  56. {
  57. Step,
  58. Cycle
  59. }
  60. public enum ToleranceMode
  61. {
  62. None,
  63. Value,
  64. Percent
  65. }
  66. public enum MatchWorkMode
  67. {
  68. Auto,
  69. Manual
  70. }
  71. public class RecipeHead : INotifyPropertyChanged
  72. {
  73. private string m_name;
  74. [IsOnlyRead]
  75. public string Name
  76. {
  77. get { return m_name; }
  78. set { m_name = value; InvokePropertyChanged("Name"); }
  79. }
  80. private string _Version = "TestVersion";
  81. public string Version
  82. {
  83. get { return _Version; }
  84. set { _Version = value; InvokePropertyChanged("Version"); }
  85. }
  86. private JetChamber _ChamberType = JetChamber.None;
  87. [JsonConverter(typeof(StringEnumConverter))]
  88. [IsOnlyRead]
  89. public JetChamber ChamberType
  90. {
  91. get { return _ChamberType; }
  92. set { _ChamberType = value; InvokePropertyChanged("ChamberType"); }
  93. }
  94. private RecipeType m_Type;
  95. [JsonConverter(typeof(StringEnumConverter))]
  96. [IsOnlyRead]
  97. public RecipeType Type
  98. {
  99. get { return m_Type; }
  100. set { m_Type = value; InvokePropertyChanged("Type"); }
  101. }
  102. private string m_ChunckRecipe;
  103. public string ChuckRecipe
  104. {
  105. get { return m_ChunckRecipe; }
  106. set { m_ChunckRecipe = value; InvokePropertyChanged("ChuckRecipe"); }
  107. }
  108. private string m_DechuckRecipe;
  109. public string DechuckRecipe
  110. {
  111. get { return m_DechuckRecipe; }
  112. set { m_DechuckRecipe = value; InvokePropertyChanged("DechuckRecipe"); }
  113. }
  114. private bool m_IsShowTolerance;
  115. public bool IsShowTolerance
  116. {
  117. get { return m_IsShowTolerance; }
  118. set { m_IsShowTolerance = value; InvokePropertyChanged("IsShowTolerance"); }
  119. }
  120. private string m_CreateTime;
  121. [IsOnlyRead]
  122. public string CreateTime
  123. {
  124. get { return m_CreateTime; }
  125. set { m_CreateTime = value; InvokePropertyChanged("CreateTime"); }
  126. }
  127. private string m_EditTime;
  128. [IsOnlyRead]
  129. public string EditTime
  130. {
  131. get { return m_EditTime; }
  132. set { m_EditTime = value; InvokePropertyChanged("EditTime"); }
  133. }
  134. private string m_LastModifiedBy;
  135. [IsOnlyRead]
  136. public string LastModifiedBy
  137. {
  138. get { return m_LastModifiedBy; }
  139. set { m_LastModifiedBy = value; InvokePropertyChanged("LastModifiedBy"); }
  140. }
  141. private string m_Barcode;
  142. public string Barcode
  143. {
  144. get { return m_Barcode; }
  145. set { m_Barcode = value; InvokePropertyChanged("Barcode"); }
  146. }
  147. private string m_BasePressure;
  148. public string BasePressure
  149. {
  150. get { return m_BasePressure; }
  151. set { m_BasePressure = value; InvokePropertyChanged("BasePressure"); }
  152. }
  153. private string m_Temperature;
  154. public string Temperature
  155. {
  156. get { return m_Temperature; }
  157. set { m_Temperature = value; InvokePropertyChanged("Temperature"); }
  158. }
  159. private int m_RFHoldTime = 1000;
  160. [CustomName("RF HoldTime(s)")]
  161. public int RFHoldTime
  162. {
  163. get { return m_RFHoldTime; }
  164. set { m_RFHoldTime = value; InvokePropertyChanged("RFHoldTime"); }
  165. }
  166. private int m_BiasRFHoldTime = 1000;
  167. [CustomName("BiasRF HoldTime(s)")]
  168. public int BiasRFHoldTime
  169. {
  170. get { return m_BiasRFHoldTime; }
  171. set { m_BiasRFHoldTime = value; InvokePropertyChanged("BiasRFHoldTime"); }
  172. }
  173. private string m_Comment;
  174. public string Comment
  175. {
  176. get { return m_Comment; }
  177. set { m_Comment = value; InvokePropertyChanged("Comment"); }
  178. }
  179. public event PropertyChangedEventHandler PropertyChanged;
  180. public void InvokePropertyChanged(string propertyName)
  181. {
  182. if (PropertyChanged != null)
  183. {
  184. PropertyChanged.Invoke(this, new PropertyChangedEventArgs(propertyName));
  185. }
  186. }
  187. }
  188. public class ProcessUnitBase
  189. {
  190. [JsonIgnore]
  191. public Func<ProcessUnitBase, RecipeStep, RState> checker;
  192. [JsonIgnore]
  193. public Func<ProcessUnitBase, RecipeStep, RState> starter;
  194. [JsonIgnore]
  195. public Action<ProcessUnitBase, RecipeStep> end;
  196. //[JsonIgnore]
  197. //public string Name { get; set; }
  198. //[JsonIgnore]
  199. //public ProcessModule Moudle { get; set; }
  200. public RState Start(RecipeStep step)
  201. {
  202. if (starter != null)
  203. return starter(this, step);
  204. return RState.Running;
  205. }
  206. public RState Run(RecipeStep step)
  207. {
  208. if (checker != null)
  209. return checker(this, step);
  210. return RState.Running;
  211. }
  212. public void End(RecipeStep step)
  213. {
  214. if (end != null)
  215. end(this, step);
  216. }
  217. }
  218. [Serializable]
  219. public class RecipeStep : INotifyPropertyChanged
  220. {
  221. [JsonIgnore]
  222. public Func<RecipeStep, RState> checker;
  223. [JsonIgnore]
  224. public Func<RecipeStep, RState> starter;
  225. [JsonIgnore]
  226. public Func<RecipeStep, RState> ender;
  227. private int m_StepNo = 1;
  228. [IsOnlyRead]
  229. public int StepNo
  230. {
  231. get { return m_StepNo; }
  232. set { m_StepNo = value; InvokePropertyChanged("StepNo"); }
  233. }
  234. private StepType m_StepType;
  235. [JsonConverter(typeof(StringEnumConverter))]
  236. public StepType Type
  237. {
  238. get { return m_StepType; }
  239. set { m_StepType = value; InvokePropertyChanged("Type"); }
  240. }
  241. private int m_Time;
  242. [CustomName("Time(s)")]
  243. public int Time
  244. {
  245. get { return m_Time; }
  246. set { m_Time = value; InvokePropertyChanged("Time"); }
  247. }
  248. private string m_Description;
  249. public string Description
  250. {
  251. get { return m_Description; }
  252. set { m_Description = value; InvokePropertyChanged("Description"); }
  253. }
  254. private string m_EPDConfigName;
  255. public string EPDConfig
  256. {
  257. get { return m_EPDConfigName; }
  258. set { m_EPDConfigName = value; InvokePropertyChanged("EPDConfig"); }
  259. }
  260. private int m_MinEndPointTime;
  261. public int MinEndPointTime
  262. {
  263. get { return m_MinEndPointTime; }
  264. set { m_MinEndPointTime = value; InvokePropertyChanged("MinEndPointTime"); }
  265. }
  266. private int m_MaxEndPointTime;
  267. public int MaxEndPointTime
  268. {
  269. get { return m_MaxEndPointTime; }
  270. set { m_MaxEndPointTime = value; InvokePropertyChanged("MaxEndPointTime"); }
  271. }
  272. //private bool m_EnableRamp;
  273. //public bool EnableRamp
  274. //{
  275. // get { return m_EnableRamp; }
  276. // set { m_EnableRamp = value; InvokePropertyChanged("EnableRamp"); }
  277. //}
  278. private int m_OverEtchPercent;
  279. public int OverEtchPercent
  280. {
  281. get { return m_OverEtchPercent; }
  282. set { m_OverEtchPercent = value; InvokePropertyChanged("OverEtchPercent"); }
  283. }
  284. private bool m_CycleStart;
  285. public bool CycleStart
  286. {
  287. get { return m_CycleStart; }
  288. set { m_CycleStart = value; InvokePropertyChanged("CycleStart"); }
  289. }
  290. private bool m_CycleEnd;
  291. public bool CycleEnd
  292. {
  293. get { return m_CycleEnd; }
  294. set { m_CycleEnd = value; InvokePropertyChanged("CycleEnd"); }
  295. }
  296. private int m_CycleNumber;
  297. public int CycleNumber
  298. {
  299. get { return m_CycleNumber; }
  300. set { m_CycleNumber = value; InvokePropertyChanged("CycleNumber"); }
  301. }
  302. private ObservableCollection<Object> lstUnit = new ObservableCollection<Object>();
  303. public ObservableCollection<Object> LstUnit
  304. {
  305. get { return lstUnit; }
  306. set { lstUnit = value; InvokePropertyChanged("LstUnit"); }
  307. }
  308. private Stopwatch _stepTimer = new Stopwatch();
  309. public long ElapsedTime()
  310. {
  311. return _stepTimer.ElapsedMilliseconds;
  312. }
  313. public void StartStepTimer()
  314. {
  315. _stepTimer.Restart();
  316. }
  317. private long _lastEPDStepTimne = 0;
  318. public void RecordEPDStepTime()
  319. {
  320. _lastEPDStepTimne = _stepTimer.ElapsedMilliseconds;
  321. }
  322. public long GetLastEPDStepTime()
  323. {
  324. return _lastEPDStepTimne;
  325. }
  326. public RState Start()
  327. {
  328. starter(this);
  329. foreach (var unit in lstUnit)
  330. {
  331. var processUnit = unit as ProcessUnitBase;
  332. if (processUnit != null)
  333. {
  334. var state = processUnit.Start(this);
  335. if (state != RState.Running)
  336. return state;
  337. }
  338. else
  339. return RState.Failed;
  340. }
  341. return RState.Running;
  342. }
  343. public RState Start(int steps, int currentstep)
  344. {
  345. starter(this);
  346. foreach (var unit in lstUnit)
  347. {
  348. var processUnit = unit as ProcessUnitBase;
  349. if (processUnit != null)
  350. {
  351. var state = processUnit.Start(this);
  352. if (state != RState.Running)
  353. return state;
  354. }
  355. else
  356. return RState.Failed;
  357. }
  358. return RState.Running;
  359. }
  360. public RState Run()
  361. {
  362. if (checker(this) == RState.End)
  363. return RState.End;
  364. bool bStable = true;
  365. foreach (var unit in lstUnit)
  366. {
  367. var processUnit = unit as ProcessUnitBase;
  368. if (processUnit != null)
  369. {
  370. var state = processUnit.Run(this);
  371. if (Type == StepType.Stable)
  372. {
  373. if (state != RState.Running && state != RState.End)
  374. return state;
  375. if (state == RState.Running)
  376. bStable = false;
  377. }
  378. else
  379. {
  380. if (state != RState.Running)
  381. return state;
  382. }
  383. }
  384. else
  385. return RState.Failed;
  386. }
  387. return (Type == StepType.Stable && bStable) ? RState.End : RState.Running;
  388. }
  389. public void End()
  390. {
  391. foreach (var unit in lstUnit)
  392. {
  393. var processUnit = unit as ProcessUnitBase;
  394. if (processUnit != null)
  395. {
  396. processUnit.End(this);
  397. }
  398. }
  399. ender(this);
  400. }
  401. public double RampFactor()
  402. {
  403. return _stepTimer.ElapsedMilliseconds / (Time * 1000.0);
  404. }
  405. public void AppendUnit(ProcessUnitBase unit)
  406. {
  407. lstUnit.Append(unit);
  408. }
  409. public event PropertyChangedEventHandler PropertyChanged;
  410. public void InvokePropertyChanged(string propertyName)
  411. {
  412. if (PropertyChanged != null)
  413. {
  414. PropertyChanged.Invoke(this, new PropertyChangedEventArgs(propertyName));
  415. }
  416. }
  417. }
  418. public class Recipe : INotifyPropertyChanged
  419. {
  420. private RecipeHead m_Header = new RecipeHead();
  421. public RecipeHead Header
  422. {
  423. get { return m_Header; }
  424. set { m_Header = value; InvokePropertyChanged("Header"); }
  425. }
  426. private ObservableCollection<RecipeStep> m_Steps;
  427. public ObservableCollection<RecipeStep> Steps
  428. {
  429. get { return m_Steps; }
  430. set { m_Steps = value; InvokePropertyChanged("Steps"); }
  431. }
  432. public static Recipe Load(string recipeFile)
  433. {
  434. var recipe = JsonConvert.DeserializeObject<Recipe>(recipeFile);
  435. if (recipe == null)
  436. {
  437. return null;
  438. }
  439. foreach (var step in recipe.Steps)
  440. {
  441. ObservableCollection<ProcessUnitBase> unit = new ObservableCollection<ProcessUnitBase>();
  442. for (int i = 0; i < step.LstUnit.Count; i++)
  443. {
  444. string value = step.LstUnit[i].ToString();
  445. string[] striparr = value.Split(new string[] { "\r\n" }, StringSplitOptions.None);
  446. string item1 = striparr[1].Remove(0, 15);
  447. string item2 = item1.Remove(item1.Length - 2, 2);
  448. switch (item2)
  449. {
  450. case "PressureModeUnit":
  451. unit.Add(JsonConvert.DeserializeObject<PressureByPressureModeUnit>(step.LstUnit[i].ToString()));
  452. break;
  453. //case "PressureByValveModeUnit":
  454. // unit.Add(JsonConvert.DeserializeObject<PressureByValveModeUnit>(step.LstUnit[i].ToString()));
  455. // break;
  456. case "TCPUnit":
  457. unit.Add(JsonConvert.DeserializeObject<TCPUnit>(step.LstUnit[i].ToString()));
  458. break;
  459. case "BiasUnit":
  460. unit.Add(JsonConvert.DeserializeObject<BiasUnit>(step.LstUnit[i].ToString()));
  461. break;
  462. case "GasControlUnit":
  463. unit.Add(JsonConvert.DeserializeObject<GasControlUnit>(step.LstUnit[i].ToString()));
  464. break;
  465. case "ESCHVUnit":
  466. unit.Add(JsonConvert.DeserializeObject<ESCHVUnit>(step.LstUnit[i].ToString()));
  467. break;
  468. case "SEESCHVUnit":
  469. unit.Add(JsonConvert.DeserializeObject<SEESCHVUnit>(step.LstUnit[i].ToString()));
  470. break;
  471. case "ProcessKitUnit":
  472. unit.Add(JsonConvert.DeserializeObject<ProcessKitUnit>(step.LstUnit[i].ToString()));
  473. break;
  474. case "HeaterUnit":
  475. unit.Add(JsonConvert.DeserializeObject<HeaterUnit>(step.LstUnit[i].ToString()));
  476. break;
  477. case "RFBoxUnit":
  478. unit.Add(JsonConvert.DeserializeObject<RFBoxUnit>(step.LstUnit[i].ToString()));
  479. break;
  480. case "GasUnit":
  481. unit.Add(JsonConvert.DeserializeObject<Kepler2200GasControlUnit>(step.LstUnit[i].ToString()));
  482. break;
  483. case "SEGasControlUnit":
  484. unit.Add(JsonConvert.DeserializeObject<VenusSEGasControlUnit>(step.LstUnit[i].ToString()));
  485. break;
  486. }
  487. }
  488. step.LstUnit.Clear();
  489. unit.ToList().ForEach(x =>
  490. {
  491. step.LstUnit.Add(x);
  492. });
  493. }
  494. return recipe;
  495. }
  496. public bool Validate()
  497. {
  498. return true;
  499. }
  500. public bool Save(string recipeFile)
  501. {
  502. return true;
  503. }
  504. public event PropertyChangedEventHandler PropertyChanged;
  505. public void InvokePropertyChanged(string propertyName)
  506. {
  507. if (PropertyChanged != null)
  508. {
  509. PropertyChanged.Invoke(this, new PropertyChangedEventArgs(propertyName));
  510. }
  511. }
  512. }
  513. public class RecipeUnity
  514. {
  515. public static string ConvertJsonString(string str)
  516. {
  517. JsonSerializer serializer = new JsonSerializer();
  518. TextReader tr = new StringReader(str);
  519. JsonTextReader jtr = new JsonTextReader(tr);
  520. object obj = serializer.Deserialize(jtr);
  521. if (obj != null)
  522. {
  523. StringWriter textWriter = new StringWriter();
  524. JsonTextWriter jsonWriter = new JsonTextWriter(textWriter)
  525. {
  526. Formatting = Newtonsoft.Json.Formatting.Indented,
  527. Indentation = 4,
  528. IndentChar = ' '
  529. };
  530. serializer.Serialize(jsonWriter, obj);
  531. return textWriter.ToString();
  532. }
  533. else
  534. {
  535. return str;
  536. }
  537. }
  538. public static string RecipeToString(Recipe recipe)
  539. {
  540. return JsonConvert.SerializeObject(recipe);
  541. }
  542. public static String CreateRecipe(JetChamber currentChamber, RecipeType recipeType, string recipeName)
  543. {
  544. Recipe recipe = new Recipe();
  545. recipe.Header = new RecipeHead();
  546. recipe.Header.CreateTime = DateTime.Now.ToString();
  547. recipe.Header.EditTime = DateTime.Now.ToString();
  548. recipe.Header.Type = recipeType;
  549. recipe.Header.ChamberType = currentChamber;
  550. recipe.Header.Name = recipeName;
  551. recipe.Header.LastModifiedBy = "Admin";
  552. recipe.Steps = new ObservableCollection<RecipeStep>();
  553. RecipeStep recipeStep = new RecipeStep();
  554. recipeStep.LstUnit = GetAllUnits(currentChamber, recipeType);
  555. recipe.Steps.Add(recipeStep);
  556. var recipeString = JsonConvert.SerializeObject(recipe);
  557. return recipeString;
  558. }
  559. public static ObservableCollection<Object> GetAllUnits(JetChamber jetChamber, RecipeType recipeType)
  560. {
  561. ObservableCollection<Object> LstUnit = new ObservableCollection<object>();
  562. switch (jetChamber)
  563. {
  564. //case JetChamber.Venus:
  565. // if (recipeType == RecipeType.Clean)
  566. // {
  567. // foreach (var item in Enum.GetValues(typeof(VenusCleanRecipeUnits)))
  568. // {
  569. // Type t = Type.GetType($"Venus_Core.{item.ToString()}");
  570. // var obj = System.Activator.CreateInstance(t);
  571. // LstUnit.Add(obj);
  572. // }
  573. // }
  574. // else
  575. // {
  576. // foreach (var item in Enum.GetValues(typeof(VenusUnits)))
  577. // {
  578. // Type t = Type.GetType($"Venus_Core.{item.ToString()}");
  579. // var obj = System.Activator.CreateInstance(t);
  580. // LstUnit.Add(obj);
  581. // }
  582. // }
  583. // break;
  584. case JetChamber.Kepler2300:
  585. if (recipeType == RecipeType.Clean)
  586. {
  587. foreach (var item in Enum.GetValues(typeof(Kepler2300CleanRecipeUints)))
  588. {
  589. Type t = Type.GetType($"Venus_Core.{item.ToString()}");
  590. var obj = System.Activator.CreateInstance(t);
  591. LstUnit.Add(obj);
  592. }
  593. }
  594. else
  595. {
  596. foreach (var item in Enum.GetValues(typeof(Kepler2300Uints)))
  597. {
  598. Type t = Type.GetType($"Venus_Core.{item.ToString()}");
  599. var obj = System.Activator.CreateInstance(t);
  600. LstUnit.Add(obj);
  601. }
  602. }
  603. break;
  604. case JetChamber.Kepler2200A:
  605. foreach (var item in Enum.GetValues(typeof(Kepler2200AUnits)))
  606. {
  607. Type t = Type.GetType($"Venus_Core.{item.ToString()}");
  608. var obj = System.Activator.CreateInstance(t);
  609. LstUnit.Add(obj);
  610. }
  611. break;
  612. case JetChamber.Kepler2200B:
  613. foreach (var item in Enum.GetValues(typeof(Kepler2200BUnits)))
  614. {
  615. Type t = Type.GetType($"Venus_Core.{item.ToString()}");
  616. var obj = System.Activator.CreateInstance(t);
  617. LstUnit.Add(obj);
  618. }
  619. break;
  620. case JetChamber.VenusSE:
  621. foreach (var item in Enum.GetValues(typeof(VenusSEUnits)))
  622. {
  623. Type t = Type.GetType($"Venus_Core.{item.ToString()}");
  624. var obj = System.Activator.CreateInstance(t);
  625. LstUnit.Add(obj);
  626. }
  627. break;
  628. }
  629. return LstUnit;
  630. }
  631. }
  632. }