using Aitex.Core.Common; using Aitex.Core.UI.MVVM; using Aitex.Core.Util; using Aitex.Core.Utilities; using Aitex.Sorter.Common; using Aitex.Sorter.UI.Controls; using System; using System.Collections; using System.Collections.Generic; using System.ComponentModel; using System.Linq; using System.Windows.Input; using MECF.Framework.Common.Equipment; namespace Aitex.Sorter.UI.ViewModel { class RecipeViewModel : UIViewModelBase { private WaferInfo[] foupAWaferInfo; private WaferInfo[] foupBWaferInfo; public RecipeViewModel() : base("Recipe") { WaferTransferCommand = new DelegateCommand(OnTransfer); WaferTransferOptionCommand = new DelegateCommand(BeforeTransfer); RemoveResultCommand = new DelegateCommand(RemoveResult); SourceDestinationCommand = new DelegateCommand(SourceDestinationChanged); } public void AddNewRecipe(string name) { CurrentRecipe = new SorterRecipeXml(name); UIRecipeManager.Instance.SaveRecipe(name, CurrentRecipe.GetContent()); Refresh(); } public void LoadRecipe(string name) { if (name != null) { CurrentRecipe = new SorterRecipeXml(UIRecipeManager.Instance.LoadRecipe(name), name); } else { CurrentRecipe = null; } } public void SaveRecipe() { if (CurrentRecipe != null) { CurrentRecipe.SaveContent(); UIRecipeManager.Instance.SaveRecipe(CurrentRecipe.Name, CurrentRecipe.GetContent()); } } public void DeleteRecipe() { if (CurrentRecipe != null) { UIRecipeManager.Instance.DeleteRecipe(CurrentRecipe.Name); CurrentRecipe = null; Refresh(); } } public void RenameRecipe(string newName) { if (CurrentRecipe != null) { UIRecipeManager.Instance.RenameRecipe(CurrentRecipe.Name, newName); LoadRecipe(newName); Refresh(); } } public void CopyRecipe(string newName) { if (CurrentRecipe != null) { UIRecipeManager.Instance.SaveAsRecipe(newName, CurrentRecipe.GetContent()); LoadRecipe(newName); Refresh(); } } public void Refresh() { RecipeList = UIRecipeManager.Instance.GetRecipes(); } private void OnTransfer(SorterRecipeTransferTableItem transferItem) { CurrentRecipe.TransferItems.Add(transferItem); } private void BeforeTransfer(WaferTransferOption option) { if (currentRecipe != null && currentRecipe.RecipeType == SorterRecipeType.TransferNToN) { option.Align = currentRecipe.IsAlign; option.TurnOver = currentRecipe.IsTurnOver; option.ReadLaserMarker = currentRecipe.IsReadLaserMarker; option.ReadT7Code = currentRecipe.IsReadT7Code; option.AlignerAngle = currentRecipe.AlignAngle; } } private void RemoveResult(SorterRecipeTransferTableItem item) { CurrentRecipe.TransferItems.Remove(item); } private void SourceDestinationChanged(string param) { if (currentRecipe != null && currentRecipe.RecipeType == SorterRecipeType.Transfer1To1) { if (param == "1") { //currentRecipe.Destination = (currentRecipe.Source == ModuleName.LP1 ? ModuleName.LP2 : ModuleName.LP1); } else { //currentRecipe.Source = (currentRecipe.Destination == ModuleName.LP1 ? ModuleName.LP2 : ModuleName.LP1); } } } [Subscription(ParamName.WaferInfoFoupA, "System")] public WaferInfo[] FoupAWaferInfo { get { return foupAWaferInfo; } set { for (int i = 0; i < value.Length; i++) { var wafer = value[i]; if (wafer.Status != WaferStatus.Empty) wafer.Status = WaferStatus.Dummy; UpdateTransferState(wafer, ModuleName.LP1, i); } foupAWaferInfo = value.Reverse().ToArray(); } } [Subscription(ParamName.WaferInfoFoupB, "System")] public WaferInfo[] FoupBWaferInfo { get { return foupBWaferInfo; } set { for (int i = 0; i < value.Length; i++) { var wafer = value[i]; if (wafer.Status != WaferStatus.Empty) wafer.Status = WaferStatus.Dummy; UpdateTransferState(wafer, ModuleName.LP2, i); } foupBWaferInfo = value.Reverse().ToArray(); } } private IEnumerable recipeList; [IgnorePropertyChange] public IEnumerable RecipeList { get { return recipeList; } set { recipeList = value; InvokePropertyChanged("RecipeList"); } } public ICommand WaferTransferCommand { get; set; } public ICommand WaferTransferOptionCommand { get; set; } private SorterRecipeXml currentRecipe; [IgnorePropertyChange] public SorterRecipeXml CurrentRecipe { get { return currentRecipe; } set { currentRecipe = value; InvokePropertyChanged("CurrentRecipe"); } } public IDictionary PlaceMode1To1 { get { return EnumHelper.ToDictionary(); } } public IDictionary PlaceModePack { get { return EnumHelper.ToDictionary(); } } public IDictionary PlaceModeOrder { get { return EnumHelper.ToDictionary(); } } public ICommand RemoveResultCommand { get; set; } public ICommand SourceDestinationCommand { get;set; } private void UpdateTransferState(WaferInfo wafer, ModuleName station, int slot) { if (CurrentRecipe != null && currentRecipe.TransferItems != null) { var sourceItem = currentRecipe.TransferItems.FirstOrDefault(x => x.SourceStation == station && x.SourceSlot == slot); if (sourceItem != null) { wafer.IsSource = true; } var destinationItem = currentRecipe.TransferItems.FirstOrDefault(x => x.DestinationStation == station && x.DestinationSlot == slot); if (destinationItem != null) { wafer.IsDestination = true; } } } } }