RecipeViewModel.cs 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. using Aitex.Core.Common;
  2. using Aitex.Core.UI.MVVM;
  3. using Aitex.Core.Util;
  4. using Aitex.Core.Utilities;
  5. using Aitex.Sorter.Common;
  6. using Aitex.Sorter.UI.Controls;
  7. using System;
  8. using System.Collections;
  9. using System.Collections.Generic;
  10. using System.ComponentModel;
  11. using System.Linq;
  12. using System.Windows.Input;
  13. using MECF.Framework.Common.Equipment;
  14. namespace Aitex.Sorter.UI.ViewModel
  15. {
  16. class RecipeViewModel : UIViewModelBase
  17. {
  18. private WaferInfo[] foupAWaferInfo;
  19. private WaferInfo[] foupBWaferInfo;
  20. public RecipeViewModel() : base("Recipe")
  21. {
  22. WaferTransferCommand = new DelegateCommand<SorterRecipeTransferTableItem>(OnTransfer);
  23. WaferTransferOptionCommand = new DelegateCommand<WaferTransferOption>(BeforeTransfer);
  24. RemoveResultCommand = new DelegateCommand<SorterRecipeTransferTableItem>(RemoveResult);
  25. SourceDestinationCommand = new DelegateCommand<string>(SourceDestinationChanged);
  26. }
  27. public void AddNewRecipe(string name)
  28. {
  29. CurrentRecipe = new SorterRecipeXml(name);
  30. UIRecipeManager.Instance.SaveRecipe(name, CurrentRecipe.GetContent());
  31. Refresh();
  32. }
  33. public void LoadRecipe(string name)
  34. {
  35. if (name != null)
  36. {
  37. CurrentRecipe = new SorterRecipeXml(UIRecipeManager.Instance.LoadRecipe(name), name);
  38. }
  39. else
  40. {
  41. CurrentRecipe = null;
  42. }
  43. }
  44. public void SaveRecipe()
  45. {
  46. if (CurrentRecipe != null)
  47. {
  48. CurrentRecipe.SaveContent();
  49. UIRecipeManager.Instance.SaveRecipe(CurrentRecipe.Name, CurrentRecipe.GetContent());
  50. }
  51. }
  52. public void DeleteRecipe()
  53. {
  54. if (CurrentRecipe != null)
  55. {
  56. UIRecipeManager.Instance.DeleteRecipe(CurrentRecipe.Name);
  57. CurrentRecipe = null;
  58. Refresh();
  59. }
  60. }
  61. public void RenameRecipe(string newName)
  62. {
  63. if (CurrentRecipe != null)
  64. {
  65. UIRecipeManager.Instance.RenameRecipe(CurrentRecipe.Name, newName);
  66. LoadRecipe(newName);
  67. Refresh();
  68. }
  69. }
  70. public void CopyRecipe(string newName)
  71. {
  72. if (CurrentRecipe != null)
  73. {
  74. UIRecipeManager.Instance.SaveAsRecipe(newName, CurrentRecipe.GetContent());
  75. LoadRecipe(newName);
  76. Refresh();
  77. }
  78. }
  79. public void Refresh()
  80. {
  81. RecipeList = UIRecipeManager.Instance.GetRecipes();
  82. }
  83. private void OnTransfer(SorterRecipeTransferTableItem transferItem)
  84. {
  85. CurrentRecipe.TransferItems.Add(transferItem);
  86. }
  87. private void BeforeTransfer(WaferTransferOption option)
  88. {
  89. if (currentRecipe != null && currentRecipe.RecipeType == SorterRecipeType.TransferNToN)
  90. {
  91. option.Align = currentRecipe.IsAlign;
  92. option.TurnOver = currentRecipe.IsTurnOver;
  93. option.ReadLaserMarker = currentRecipe.IsReadLaserMarker;
  94. option.ReadT7Code = currentRecipe.IsReadT7Code;
  95. option.AlignerAngle = currentRecipe.AlignAngle;
  96. }
  97. }
  98. private void RemoveResult(SorterRecipeTransferTableItem item)
  99. {
  100. CurrentRecipe.TransferItems.Remove(item);
  101. }
  102. private void SourceDestinationChanged(string param)
  103. {
  104. if (currentRecipe != null && currentRecipe.RecipeType == SorterRecipeType.Transfer1To1)
  105. {
  106. if (param == "1")
  107. {
  108. //currentRecipe.Destination = (currentRecipe.Source == ModuleName.LP1 ? ModuleName.LP2 : ModuleName.LP1);
  109. }
  110. else
  111. {
  112. //currentRecipe.Source = (currentRecipe.Destination == ModuleName.LP1 ? ModuleName.LP2 : ModuleName.LP1);
  113. }
  114. }
  115. }
  116. [Subscription(ParamName.WaferInfoFoupA, "System")]
  117. public WaferInfo[] FoupAWaferInfo
  118. {
  119. get
  120. {
  121. return foupAWaferInfo;
  122. }
  123. set
  124. {
  125. for (int i = 0; i < value.Length; i++)
  126. {
  127. var wafer = value[i];
  128. if (wafer.Status != WaferStatus.Empty) wafer.Status = WaferStatus.Dummy;
  129. UpdateTransferState(wafer, ModuleName.LP1, i);
  130. }
  131. foupAWaferInfo = value.Reverse().ToArray();
  132. }
  133. }
  134. [Subscription(ParamName.WaferInfoFoupB, "System")]
  135. public WaferInfo[] FoupBWaferInfo
  136. {
  137. get
  138. {
  139. return foupBWaferInfo;
  140. }
  141. set
  142. {
  143. for (int i = 0; i < value.Length; i++)
  144. {
  145. var wafer = value[i];
  146. if (wafer.Status != WaferStatus.Empty) wafer.Status = WaferStatus.Dummy;
  147. UpdateTransferState(wafer, ModuleName.LP2, i);
  148. }
  149. foupBWaferInfo = value.Reverse().ToArray();
  150. }
  151. }
  152. private IEnumerable<string> recipeList;
  153. [IgnorePropertyChange]
  154. public IEnumerable<string> RecipeList
  155. {
  156. get
  157. {
  158. return recipeList;
  159. }
  160. set
  161. {
  162. recipeList = value;
  163. InvokePropertyChanged("RecipeList");
  164. }
  165. }
  166. public ICommand WaferTransferCommand
  167. {
  168. get; set;
  169. }
  170. public ICommand WaferTransferOptionCommand
  171. {
  172. get; set;
  173. }
  174. private SorterRecipeXml currentRecipe;
  175. [IgnorePropertyChange]
  176. public SorterRecipeXml CurrentRecipe
  177. {
  178. get
  179. {
  180. return currentRecipe;
  181. }
  182. set
  183. {
  184. currentRecipe = value;
  185. InvokePropertyChanged("CurrentRecipe");
  186. }
  187. }
  188. public IDictionary PlaceMode1To1
  189. {
  190. get
  191. {
  192. return EnumHelper.ToDictionary<SorterRecipePlaceModeTransfer1To1>();
  193. }
  194. }
  195. public IDictionary PlaceModePack
  196. {
  197. get
  198. {
  199. return EnumHelper.ToDictionary<SorterRecipePlaceModePack>();
  200. }
  201. }
  202. public IDictionary PlaceModeOrder
  203. {
  204. get
  205. {
  206. return EnumHelper.ToDictionary<SorterRecipePlaceModeOrder>();
  207. }
  208. }
  209. public ICommand RemoveResultCommand
  210. {
  211. get; set;
  212. }
  213. public ICommand SourceDestinationCommand
  214. {
  215. get;set;
  216. }
  217. private void UpdateTransferState(WaferInfo wafer, ModuleName station, int slot)
  218. {
  219. if (CurrentRecipe != null && currentRecipe.TransferItems != null)
  220. {
  221. var sourceItem = currentRecipe.TransferItems.FirstOrDefault(x => x.SourceStation == station && x.SourceSlot == slot);
  222. if (sourceItem != null)
  223. {
  224. wafer.IsSource = true;
  225. }
  226. var destinationItem = currentRecipe.TransferItems.FirstOrDefault(x => x.DestinationStation == station && x.DestinationSlot == slot);
  227. if (destinationItem != null)
  228. {
  229. wafer.IsDestination = true;
  230. }
  231. }
  232. }
  233. }
  234. }