123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475 |
- using Aitex.Core.Common;
- using Aitex.Core.RT.SCCore;
- using Aitex.Core.UI.MVVM;
- using Aitex.Core.Util;
- using Aitex.Core.Utilities;
- using Aitex.Sorter.Common;
- using Aitex.Sorter.UI.Controls;
- using Aitex.Sorter.UI.Views;
- using MECF.Framework.Common.OperationCenter;
- using System.Collections;
- using System.Collections.Generic;
- using System.Collections.ObjectModel;
- using System.Linq;
- using System.Windows;
- using System.Windows.Input;
- using MECF.Framework.Common.Equipment;
- using System;
- using System.Globalization;
- using MECF.Framework.Common.RecipeCenter;
- namespace Aitex.Sorter.UI.ViewModel
- {
- public class RecipeViewBaseModel : FoupListViewModelBase
- {
- private RecipeTarget[] SourceTargets;
- private RecipeTarget[] DestinationTargets;
- public bool IsShowAllPlaceModel { get; set; } = false;
- public RecipeViewBaseModel(int foupCount,bool isShowAllPlaceModel=false) : base("Recipe", foupCount)
- {
- IsShowAllPlaceModel = isShowAllPlaceModel;
- WaferTransferCommand = new DelegateCommand<SorterRecipeTransferTableItem>(OnTransfer);
- WaferTransferOptionCommand = new DelegateCommand<WaferTransferOption>(BeforeTransfer);
- RemoveResultCommand = new DelegateCommand<SorterRecipeTransferTableItem>(RemoveResult);
- SourceDestinationCommand = new DelegateCommand<string>(SourceDestinationChanged);
- RecipeCommand = new DelegateCommand<string>(DoRecipeCommand);
- }
- private void DoRecipeCommand(string cmd)
- {
- if (!PerformInvokeFunctionCheck(new string[] { "RecipeCommand", cmd })) return;
- switch (cmd)
- {
- case "Add":
- var inputName = new RecipeNameDialog();
- if (inputName.ShowDialog() == true)
- {
- AddNewRecipe(inputName.RecipeName);
- }
- break;
- case "Save":
- SaveRecipe();
- break;
- case "Delete":
- 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))
- {
- DeleteRecipe();
- }
- break;
- case "Cancel":
- LoadRecipe(CurrentRecipe.Name);
- break;
- case "Rename":
- if (CurrentRecipe != null)
- {
- var recipeNameDialog = new RecipeNameDialog(CurrentRecipe.Name);
- if (recipeNameDialog.ShowDialog() == true)
- {
- RenameRecipe(recipeNameDialog.RecipeName);
- }
- }
- break;
- case "Copy":
- if (CurrentRecipe != null)
- {
- var newName = string.Format("Copy of {0}", CurrentRecipe.Name);
- var renameDialog = new RecipeNameDialog(newName);
- if (renameDialog.ShowDialog() == true)
- {
- CopyRecipe(renameDialog.RecipeName);
- }
- }
- break;
- default:
- break;
- }
- }
- public void ResetTarget()
- {
- foreach (var item in Sources)
- {
- item.IsChecked = false;
- }
- foreach (var item in Destinations)
- {
- item.IsChecked = false;
- }
- }
- public void AddNewRecipe(string name)
- {
- ResetTarget();
- CurrentRecipe = new SorterRecipeXml(name);
- UIRecipeManager.Instance.SaveRecipe(name, CurrentRecipe.GetContent());
- Refresh();
- }
- public void LoadRecipe(string name)
- {
- ResetTarget();
- if (name != null)
- {
- CurrentRecipe = new SorterRecipeXml(UIRecipeManager.Instance.LoadRecipe(name), name);
- if (CurrentRecipe.Source != null)
- {
- foreach (var item in CurrentRecipe.Source)
- {
- var lp = Sources.FirstOrDefault(x => x.Value == item);
- if (lp != null)
- lp.IsChecked = true;
- }
- }
- if (CurrentRecipe.Destination != null)
- {
- foreach (var item in CurrentRecipe.Destination)
- {
- var lp = Destinations.FirstOrDefault(x => x.Value == item);
- if (lp != null)
- lp.IsChecked = true;
- }
- }
- }
- else
- {
- CurrentRecipe = null;
- }
- }
- public void SaveRecipe()
- {
- if (CurrentRecipe != null)
- {
- CurrentRecipe.Source = new ObservableCollection<ModuleName>(Sources.Where(x => x.IsChecked).Select(x => x.Value));
- CurrentRecipe.Destination = new ObservableCollection<ModuleName>(Destinations.Where(x => x.IsChecked).Select(x => x.Value));
- if (CurrentRecipe.Source.Count == 0 && CurrentRecipe.RecipeType != SorterRecipeType.TransferNToN)
- {
- MessageBox.Show(string.Format("Source can not be empty"));
- return;
- }
- if (CurrentRecipe.Destination.Count == 0 && (CurrentRecipe.RecipeType == SorterRecipeType.Transfer1To1 || CurrentRecipe.RecipeType == SorterRecipeType.TransferNTo1))
- {
- MessageBox.Show(string.Format("Destination can not be empty"));
- return;
- }
- if (CurrentRecipe.RecipeType == SorterRecipeType.TransferNTo1 && CurrentRecipe.Destination.Count != 1)
- {
- MessageBox.Show(string.Format("Only one can be chosen from Destination"));
- return;
- }
- CurrentRecipe.SaveContent();
- UIRecipeManager.Instance.SaveRecipe(CurrentRecipe.Name, CurrentRecipe.GetContent());
- }
- }
- public void SaveHostUsageRecipe()
- {
- if (CurrentRecipe != null)
- {
- CurrentRecipe.Source = null;
- CurrentRecipe.Destination = 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();
- HostRecipeList = new ObservableCollection<string>(RecipeClient.Instance.Service.GetRecipes(ModuleName.Host, false));
- if (SourceTargets == null)
- {
- DestinationTargets = (Application.Current.Resources["RecipeDestinationTarget"] as ArrayList).Cast<RecipeTarget>().ToArray();
- SourceTargets = (Application.Current.Resources["RecipeSourceTarget"] as ArrayList).Cast<RecipeTarget>().ToArray();
- Sources = SourceTargets.Select(x => (RecipeTarget)x.Clone()).ToArray();
- Destinations = DestinationTargets.Select(x => (RecipeTarget)x.Clone()).ToArray();
- }
- }
- private void OnTransfer(SorterRecipeTransferTableItem transferItem)
- {
- if (CurrentRecipe.RecipeType == SorterRecipeType.TransferNToN)
- {
- if (CurrentRecipe.TransferItems.Any(x => (x.SourceStation == transferItem.SourceStation && x.SourceSlot == transferItem.SourceSlot)
- || (x.DestinationStation == transferItem.DestinationStation && x.DestinationSlot == transferItem.DestinationSlot)))
- {
- return;
- }
- CurrentRecipe.TransferItems.Add(transferItem);
- }
- }
- protected virtual 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);
- }
- }
- }
- private IEnumerable<string> recipeList;
- [IgnorePropertyChange]
- public IEnumerable<string> RecipeList
- {
- get
- {
- return recipeList;
- }
- set
- {
- recipeList = value;
- InvokePropertyChanged("RecipeList");
- }
- }
- private IEnumerable<string> hostRecipeList;
- [IgnorePropertyChange]
- public IEnumerable<string> HostRecipeList
- {
- get
- {
- return hostRecipeList;
- }
- set
- {
- hostRecipeList = value;
- InvokePropertyChanged("HostRecipeList");
- }
- }
- public ICommand WaferTransferCommand
- {
- get; set;
- }
- public ICommand WaferTransferOptionCommand
- {
- get; set;
- }
- public ICommand RecipeCommand
- {
- get; set;
- }
- private SorterRecipeXml currentRecipe;
- [IgnorePropertyChange]
- public SorterRecipeXml CurrentRecipe
- {
- get
- {
- return currentRecipe;
- }
- set
- {
- currentRecipe = value;
- InvokePropertyChanged("CurrentRecipe");
- }
- }
- public virtual IDictionary PlaceMode1To1
- {
- get
- {
- if (!IsShowAllPlaceModel)
- {
- var placeModel = EnumHelper.ToDictionary<SorterRecipePlaceModeTransfer1To1>();
- //placeModel.Remove(SorterRecipePlaceModeTransfer1To1.OddFromBotton);
- //placeModel.Remove(SorterRecipePlaceModeTransfer1To1.OddFromTop);
- //placeModel.Remove(SorterRecipePlaceModeTransfer1To1.EvenFromBotton);
- //placeModel.Remove(SorterRecipePlaceModeTransfer1To1.EvenFromTop);
- placeModel.Remove(SorterRecipePlaceModeTransfer1To1.IdentifySlotByLaserMark);
- placeModel.Remove(SorterRecipePlaceModeTransfer1To1.ToFixedSlot);
- return placeModel;// EnumHelper.ToDictionary<SorterRecipePlaceModeTransfer1To1>();
- }
- else
- {
- return EnumHelper.ToDictionary<SorterRecipePlaceModeTransfer1To1>();
- }
- }
- }
- public virtual IDictionary PickMode
- {
- get
- {
- return EnumHelper.ToDictionary<SorterPickMode>();
- }
- }
- public virtual IDictionary PlaceModePack
- {
- get
- {
- return EnumHelper.ToDictionary<SorterRecipePlaceModePack>();
- }
- }
- public IDictionary PlaceModeOrder
- {
- get
- {
- return EnumHelper.ToDictionary<SorterRecipePlaceModeOrder>();
- }
- }
- public virtual IDictionary RecipeType
- {
- get
- {
- return EnumHelper.ToDictionary<SorterRecipeType>();
- }
- }
- public ICommand RemoveResultCommand
- {
- get; set;
- }
- public ICommand SourceDestinationCommand
- {
- get; set;
- }
- private RecipeTarget[] sources;
- public RecipeTarget[] Sources
- {
- get => sources;
- set
- {
- sources = value;
- InvokePropertyChanged("Sources");
- }
- }
- private RecipeTarget[] destinations;
- public RecipeTarget[] Destinations
- {
- get => destinations;
- set
- {
- destinations = value;
- InvokePropertyChanged("Destinations");
- }
- }
- private string selectedRecipe;
- public string SelectedRecipe
- {
- get => selectedRecipe;
- set
- {
- selectedRecipe = value;
- InvokePropertyChanged("SelectedRecipe");
- LoadRecipe(selectedRecipe);
- }
- }
- private string selectedHostRecipe;
- public string SelectedHostRecipe
- {
- get => selectedHostRecipe;
- set
- {
- selectedHostRecipe = value;
- InvokePropertyChanged("SelectedHostRecipe");
- }
- }
- 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;
- }
- }
- }
- protected override WaferInfo[] UpdateWaferInfo(WaferInfo[] waferInfos)
- {
- foreach (var waferInfo in waferInfos)
- {
- if (waferInfo.Status != WaferStatus.Empty)
- {
- waferInfo.Status = WaferStatus.Dummy;
- }
- }
- return waferInfos;
- }
- }
- }
|