RecipeViewBaseModel.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475
  1. using Aitex.Core.Common;
  2. using Aitex.Core.RT.SCCore;
  3. using Aitex.Core.UI.MVVM;
  4. using Aitex.Core.Util;
  5. using Aitex.Core.Utilities;
  6. using Aitex.Sorter.Common;
  7. using Aitex.Sorter.UI.Controls;
  8. using Aitex.Sorter.UI.Views;
  9. using MECF.Framework.Common.OperationCenter;
  10. using System.Collections;
  11. using System.Collections.Generic;
  12. using System.Collections.ObjectModel;
  13. using System.Linq;
  14. using System.Windows;
  15. using System.Windows.Input;
  16. using MECF.Framework.Common.Equipment;
  17. using System;
  18. using System.Globalization;
  19. using MECF.Framework.Common.RecipeCenter;
  20. namespace Aitex.Sorter.UI.ViewModel
  21. {
  22. public class RecipeViewBaseModel : FoupListViewModelBase
  23. {
  24. private RecipeTarget[] SourceTargets;
  25. private RecipeTarget[] DestinationTargets;
  26. public bool IsShowAllPlaceModel { get; set; } = false;
  27. public RecipeViewBaseModel(int foupCount,bool isShowAllPlaceModel=false) : base("Recipe", foupCount)
  28. {
  29. IsShowAllPlaceModel = isShowAllPlaceModel;
  30. WaferTransferCommand = new DelegateCommand<SorterRecipeTransferTableItem>(OnTransfer);
  31. WaferTransferOptionCommand = new DelegateCommand<WaferTransferOption>(BeforeTransfer);
  32. RemoveResultCommand = new DelegateCommand<SorterRecipeTransferTableItem>(RemoveResult);
  33. SourceDestinationCommand = new DelegateCommand<string>(SourceDestinationChanged);
  34. RecipeCommand = new DelegateCommand<string>(DoRecipeCommand);
  35. }
  36. private void DoRecipeCommand(string cmd)
  37. {
  38. if (!PerformInvokeFunctionCheck(new string[] { "RecipeCommand", cmd })) return;
  39. switch (cmd)
  40. {
  41. case "Add":
  42. var inputName = new RecipeNameDialog();
  43. if (inputName.ShowDialog() == true)
  44. {
  45. AddNewRecipe(inputName.RecipeName);
  46. }
  47. break;
  48. case "Save":
  49. SaveRecipe();
  50. break;
  51. case "Delete":
  52. if ((CurrentRecipe != null && MessageBox.Show(string.Format("Are you sure you want to delete recipe [{0}]?", CurrentRecipe.Name), "Delete Recipe", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes))
  53. {
  54. DeleteRecipe();
  55. }
  56. break;
  57. case "Cancel":
  58. LoadRecipe(CurrentRecipe.Name);
  59. break;
  60. case "Rename":
  61. if (CurrentRecipe != null)
  62. {
  63. var recipeNameDialog = new RecipeNameDialog(CurrentRecipe.Name);
  64. if (recipeNameDialog.ShowDialog() == true)
  65. {
  66. RenameRecipe(recipeNameDialog.RecipeName);
  67. }
  68. }
  69. break;
  70. case "Copy":
  71. if (CurrentRecipe != null)
  72. {
  73. var newName = string.Format("Copy of {0}", CurrentRecipe.Name);
  74. var renameDialog = new RecipeNameDialog(newName);
  75. if (renameDialog.ShowDialog() == true)
  76. {
  77. CopyRecipe(renameDialog.RecipeName);
  78. }
  79. }
  80. break;
  81. default:
  82. break;
  83. }
  84. }
  85. public void ResetTarget()
  86. {
  87. foreach (var item in Sources)
  88. {
  89. item.IsChecked = false;
  90. }
  91. foreach (var item in Destinations)
  92. {
  93. item.IsChecked = false;
  94. }
  95. }
  96. public void AddNewRecipe(string name)
  97. {
  98. ResetTarget();
  99. CurrentRecipe = new SorterRecipeXml(name);
  100. UIRecipeManager.Instance.SaveRecipe(name, CurrentRecipe.GetContent());
  101. Refresh();
  102. }
  103. public void LoadRecipe(string name)
  104. {
  105. ResetTarget();
  106. if (name != null)
  107. {
  108. CurrentRecipe = new SorterRecipeXml(UIRecipeManager.Instance.LoadRecipe(name), name);
  109. if (CurrentRecipe.Source != null)
  110. {
  111. foreach (var item in CurrentRecipe.Source)
  112. {
  113. var lp = Sources.FirstOrDefault(x => x.Value == item);
  114. if (lp != null)
  115. lp.IsChecked = true;
  116. }
  117. }
  118. if (CurrentRecipe.Destination != null)
  119. {
  120. foreach (var item in CurrentRecipe.Destination)
  121. {
  122. var lp = Destinations.FirstOrDefault(x => x.Value == item);
  123. if (lp != null)
  124. lp.IsChecked = true;
  125. }
  126. }
  127. }
  128. else
  129. {
  130. CurrentRecipe = null;
  131. }
  132. }
  133. public void SaveRecipe()
  134. {
  135. if (CurrentRecipe != null)
  136. {
  137. CurrentRecipe.Source = new ObservableCollection<ModuleName>(Sources.Where(x => x.IsChecked).Select(x => x.Value));
  138. CurrentRecipe.Destination = new ObservableCollection<ModuleName>(Destinations.Where(x => x.IsChecked).Select(x => x.Value));
  139. if (CurrentRecipe.Source.Count == 0 && CurrentRecipe.RecipeType != SorterRecipeType.TransferNToN)
  140. {
  141. MessageBox.Show(string.Format("Source can not be empty"));
  142. return;
  143. }
  144. if (CurrentRecipe.Destination.Count == 0 && (CurrentRecipe.RecipeType == SorterRecipeType.Transfer1To1 || CurrentRecipe.RecipeType == SorterRecipeType.TransferNTo1))
  145. {
  146. MessageBox.Show(string.Format("Destination can not be empty"));
  147. return;
  148. }
  149. if (CurrentRecipe.RecipeType == SorterRecipeType.TransferNTo1 && CurrentRecipe.Destination.Count != 1)
  150. {
  151. MessageBox.Show(string.Format("Only one can be chosen from Destination"));
  152. return;
  153. }
  154. CurrentRecipe.SaveContent();
  155. UIRecipeManager.Instance.SaveRecipe(CurrentRecipe.Name, CurrentRecipe.GetContent());
  156. }
  157. }
  158. public void SaveHostUsageRecipe()
  159. {
  160. if (CurrentRecipe != null)
  161. {
  162. CurrentRecipe.Source = null;
  163. CurrentRecipe.Destination = null;
  164. CurrentRecipe.SaveContent();
  165. UIRecipeManager.Instance.SaveRecipe(CurrentRecipe.Name, CurrentRecipe.GetContent());
  166. }
  167. }
  168. public void DeleteRecipe()
  169. {
  170. if (CurrentRecipe != null)
  171. {
  172. UIRecipeManager.Instance.DeleteRecipe(CurrentRecipe.Name);
  173. CurrentRecipe = null;
  174. Refresh();
  175. }
  176. }
  177. public void RenameRecipe(string newName)
  178. {
  179. if (CurrentRecipe != null)
  180. {
  181. UIRecipeManager.Instance.RenameRecipe(CurrentRecipe.Name, newName);
  182. LoadRecipe(newName);
  183. Refresh();
  184. }
  185. }
  186. public void CopyRecipe(string newName)
  187. {
  188. if (CurrentRecipe != null)
  189. {
  190. UIRecipeManager.Instance.SaveAsRecipe(newName, CurrentRecipe.GetContent());
  191. LoadRecipe(newName);
  192. Refresh();
  193. }
  194. }
  195. public void Refresh()
  196. {
  197. RecipeList = UIRecipeManager.Instance.GetRecipes();
  198. HostRecipeList = new ObservableCollection<string>(RecipeClient.Instance.Service.GetRecipes(ModuleName.Host, false));
  199. if (SourceTargets == null)
  200. {
  201. DestinationTargets = (Application.Current.Resources["RecipeDestinationTarget"] as ArrayList).Cast<RecipeTarget>().ToArray();
  202. SourceTargets = (Application.Current.Resources["RecipeSourceTarget"] as ArrayList).Cast<RecipeTarget>().ToArray();
  203. Sources = SourceTargets.Select(x => (RecipeTarget)x.Clone()).ToArray();
  204. Destinations = DestinationTargets.Select(x => (RecipeTarget)x.Clone()).ToArray();
  205. }
  206. }
  207. private void OnTransfer(SorterRecipeTransferTableItem transferItem)
  208. {
  209. if (CurrentRecipe.RecipeType == SorterRecipeType.TransferNToN)
  210. {
  211. if (CurrentRecipe.TransferItems.Any(x => (x.SourceStation == transferItem.SourceStation && x.SourceSlot == transferItem.SourceSlot)
  212. || (x.DestinationStation == transferItem.DestinationStation && x.DestinationSlot == transferItem.DestinationSlot)))
  213. {
  214. return;
  215. }
  216. CurrentRecipe.TransferItems.Add(transferItem);
  217. }
  218. }
  219. protected virtual void BeforeTransfer(WaferTransferOption option)
  220. {
  221. if (currentRecipe != null && currentRecipe.RecipeType == SorterRecipeType.TransferNToN)
  222. {
  223. option.Align = currentRecipe.IsAlign;
  224. option.TurnOver = currentRecipe.IsTurnOver;
  225. option.ReadLaserMarker = currentRecipe.IsReadLaserMarker;
  226. option.ReadT7Code = currentRecipe.IsReadT7Code;
  227. option.AlignerAngle = currentRecipe.AlignAngle;
  228. }
  229. }
  230. private void RemoveResult(SorterRecipeTransferTableItem item)
  231. {
  232. CurrentRecipe.TransferItems.Remove(item);
  233. }
  234. private void SourceDestinationChanged(string param)
  235. {
  236. if (currentRecipe != null && currentRecipe.RecipeType == SorterRecipeType.Transfer1To1)
  237. {
  238. if (param == "1")
  239. {
  240. //currentRecipe.Destination = (currentRecipe.Source == ModuleName.LP1 ? ModuleName.LP2 : ModuleName.LP1);
  241. }
  242. else
  243. {
  244. //currentRecipe.Source = (currentRecipe.Destination == ModuleName.LP1 ? ModuleName.LP2 : ModuleName.LP1);
  245. }
  246. }
  247. }
  248. private IEnumerable<string> recipeList;
  249. [IgnorePropertyChange]
  250. public IEnumerable<string> RecipeList
  251. {
  252. get
  253. {
  254. return recipeList;
  255. }
  256. set
  257. {
  258. recipeList = value;
  259. InvokePropertyChanged("RecipeList");
  260. }
  261. }
  262. private IEnumerable<string> hostRecipeList;
  263. [IgnorePropertyChange]
  264. public IEnumerable<string> HostRecipeList
  265. {
  266. get
  267. {
  268. return hostRecipeList;
  269. }
  270. set
  271. {
  272. hostRecipeList = value;
  273. InvokePropertyChanged("HostRecipeList");
  274. }
  275. }
  276. public ICommand WaferTransferCommand
  277. {
  278. get; set;
  279. }
  280. public ICommand WaferTransferOptionCommand
  281. {
  282. get; set;
  283. }
  284. public ICommand RecipeCommand
  285. {
  286. get; set;
  287. }
  288. private SorterRecipeXml currentRecipe;
  289. [IgnorePropertyChange]
  290. public SorterRecipeXml CurrentRecipe
  291. {
  292. get
  293. {
  294. return currentRecipe;
  295. }
  296. set
  297. {
  298. currentRecipe = value;
  299. InvokePropertyChanged("CurrentRecipe");
  300. }
  301. }
  302. public virtual IDictionary PlaceMode1To1
  303. {
  304. get
  305. {
  306. if (!IsShowAllPlaceModel)
  307. {
  308. var placeModel = EnumHelper.ToDictionary<SorterRecipePlaceModeTransfer1To1>();
  309. //placeModel.Remove(SorterRecipePlaceModeTransfer1To1.OddFromBotton);
  310. //placeModel.Remove(SorterRecipePlaceModeTransfer1To1.OddFromTop);
  311. //placeModel.Remove(SorterRecipePlaceModeTransfer1To1.EvenFromBotton);
  312. //placeModel.Remove(SorterRecipePlaceModeTransfer1To1.EvenFromTop);
  313. placeModel.Remove(SorterRecipePlaceModeTransfer1To1.IdentifySlotByLaserMark);
  314. placeModel.Remove(SorterRecipePlaceModeTransfer1To1.ToFixedSlot);
  315. return placeModel;// EnumHelper.ToDictionary<SorterRecipePlaceModeTransfer1To1>();
  316. }
  317. else
  318. {
  319. return EnumHelper.ToDictionary<SorterRecipePlaceModeTransfer1To1>();
  320. }
  321. }
  322. }
  323. public virtual IDictionary PickMode
  324. {
  325. get
  326. {
  327. return EnumHelper.ToDictionary<SorterPickMode>();
  328. }
  329. }
  330. public virtual IDictionary PlaceModePack
  331. {
  332. get
  333. {
  334. return EnumHelper.ToDictionary<SorterRecipePlaceModePack>();
  335. }
  336. }
  337. public IDictionary PlaceModeOrder
  338. {
  339. get
  340. {
  341. return EnumHelper.ToDictionary<SorterRecipePlaceModeOrder>();
  342. }
  343. }
  344. public virtual IDictionary RecipeType
  345. {
  346. get
  347. {
  348. return EnumHelper.ToDictionary<SorterRecipeType>();
  349. }
  350. }
  351. public ICommand RemoveResultCommand
  352. {
  353. get; set;
  354. }
  355. public ICommand SourceDestinationCommand
  356. {
  357. get; set;
  358. }
  359. private RecipeTarget[] sources;
  360. public RecipeTarget[] Sources
  361. {
  362. get => sources;
  363. set
  364. {
  365. sources = value;
  366. InvokePropertyChanged("Sources");
  367. }
  368. }
  369. private RecipeTarget[] destinations;
  370. public RecipeTarget[] Destinations
  371. {
  372. get => destinations;
  373. set
  374. {
  375. destinations = value;
  376. InvokePropertyChanged("Destinations");
  377. }
  378. }
  379. private string selectedRecipe;
  380. public string SelectedRecipe
  381. {
  382. get => selectedRecipe;
  383. set
  384. {
  385. selectedRecipe = value;
  386. InvokePropertyChanged("SelectedRecipe");
  387. LoadRecipe(selectedRecipe);
  388. }
  389. }
  390. private string selectedHostRecipe;
  391. public string SelectedHostRecipe
  392. {
  393. get => selectedHostRecipe;
  394. set
  395. {
  396. selectedHostRecipe = value;
  397. InvokePropertyChanged("SelectedHostRecipe");
  398. }
  399. }
  400. private void UpdateTransferState(WaferInfo wafer, ModuleName station, int slot)
  401. {
  402. if (CurrentRecipe != null && currentRecipe.TransferItems != null)
  403. {
  404. var sourceItem = currentRecipe.TransferItems.FirstOrDefault(x => x.SourceStation == station && x.SourceSlot == slot);
  405. if (sourceItem != null)
  406. {
  407. wafer.IsSource = true;
  408. }
  409. var destinationItem = currentRecipe.TransferItems.FirstOrDefault(x => x.DestinationStation == station && x.DestinationSlot == slot);
  410. if (destinationItem != null)
  411. {
  412. wafer.IsDestination = true;
  413. }
  414. }
  415. }
  416. protected override WaferInfo[] UpdateWaferInfo(WaferInfo[] waferInfos)
  417. {
  418. foreach (var waferInfo in waferInfos)
  419. {
  420. if (waferInfo.Status != WaferStatus.Empty)
  421. {
  422. waferInfo.Status = WaferStatus.Dummy;
  423. }
  424. }
  425. return waferInfos;
  426. }
  427. }
  428. }