using Aitex.Core.Common; using Aitex.Core.Common.DeviceData; using Aitex.Core.UI.Dialog; using Aitex.Core.UI.MVVM; using Aitex.Core.Util; using Aitex.Core.Utilities; using Aitex.Sorter.Common; using MECF.Framework.Common.OperationCenter; using System.Collections.Generic; using System.Linq; using System.Windows; using System.Windows.Input; using Aitex.Core.RT.SCCore; using MECF.Framework.Common.DataCenter; using MECF.Framework.Common.Equipment; using MECF.Framework.Common.RecipeCenter; namespace Aitex.Sorter.UI.ViewModel { class OperationViewModel : UIViewModelBase { private WaferInfo[] foupAWaferInfo; private WaferInfo[] foupBWaferInfo; #region command public ICommand OperationCommand { get; private set; } public ICommand RecipeSelectCommand { get; private set; } public ICommand RecipeStartCommand { get; private set; } public ICommand RecipePauseCommand { get; private set; } public ICommand RecipeResumeCommand { get; private set; } public ICommand RecipeStopCommand { get; private set; } #endregion #region Subscription [Subscription(ParamName.TranserThroughput, SystemStateModule)] public int TranserThroughput { get; set; } [Subscription(ParamName.TransferCount, SystemStateModule)] public int TransferCount { get; set; } [Subscription(ParamName.CycleCount, SystemStateModule)] public int CycleCount { get; set; } [Subscription(ParamName.TransferTime, SystemStateModule)] public int TransferTime { get; set; } [Subscription(ParamName.TotalWaferCount, SystemStateModule)] public int TotalWaferCount { get; set; } [Subscription(ParamName.RTStatus, SystemStateModule)] public int RoutManagerState { get; set; } [Subscription(ParamName.WaferInfoFoupA, "System")] public WaferInfo[] FoupAWaferInfo { get { return foupAWaferInfo; } set { foupAWaferInfo = value.Reverse().ToArray(); } } [Subscription(ParamName.WaferInfoFoupB, "System")] public WaferInfo[] FoupBWaferInfo { get { return foupBWaferInfo; } set { foupBWaferInfo = value.Reverse().ToArray(); } } [Subscription(ParamName.WaferInfoRobotSlot01, "System")] public WaferInfo RobotWaferInfo1 { get; set; } [Subscription(ParamName.WaferInfoRobotSlot02, "System")] public WaferInfo RobotWaferInfo2 { get; set; } [Subscription(ParamName.WaferInfoRobotAligner01, "System")] public WaferInfo AlignerWaferInfo { get; set; } [Subscription(ParamName.LoadportState, DeviceName.LoadportA)] public string LoadportAState { get; set; } [Subscription(ParamName.LoadportState, DeviceName.LoadportB)] public string LoadportBState { get; set; } [Subscription(ParamName.AlignerState, DeviceName.Aligner)] public string AlignerState { get; set; } [Subscription(ParamName.RobotState, DeviceName.Robot)] public string RobotState { get; set; } [Subscription(ParamName.FoupID, DeviceName.RFIDReaderA)] public string FoupAID { get; set; } [Subscription(ParamName.FoupID, DeviceName.RFIDReaderB)] public string FoupBID { get; set; } [Subscription(ParamName.RobotSpeed, DeviceName.Robot)] public string RobotSpeed { get; set; } [Subscription(ParamName.CassetteState, DeviceName.LoadportA)] public LoadportCassetteState LPACassetteState { get; set; } [Subscription(ParamName.CassetteState, DeviceName.LoadportB)] public LoadportCassetteState LPBCassetteState { get; set; } [Subscription(DeviceName.SensorPreAlignerWaferOn, SystemDeviceModule)] public AITSensorData SensorPreAlignerWaferOn { get; set; } [Subscription(DeviceName.SensorRobotFork2WaferOn, SystemDeviceModule)] public AITSensorData SensorRobotFork2WaferOn { get; set; } [Subscription(DeviceName.SensorRobotFork1WaferOn, SystemDeviceModule)] public AITSensorData SensorRobotFork1WaferOn { get; set; } private bool isVacuumSensorON; [Subscription("IsVacuumSensorON", DeviceName.Robot)] public bool IsVacuumSensorON { get { return isVacuumSensorON; } set { isVacuumSensorON = value; isVacuumSensorONAITSensor.Value = value; IsVacuumSensorONAITSensor = isVacuumSensorONAITSensor; } } private AITSensorData isVacuumSensorONAITSensor = new AITSensorData(); public AITSensorData IsVacuumSensorONAITSensor { get { return isVacuumSensorONAITSensor; } set { isVacuumSensorONAITSensor = value; InvokePropertyChanged("IsVacuumSensorONAITSensor"); } } public ICommand LoadPortACommand { get; set; } public ICommand LoadPortBCommand { get; set; } [Subscription(ParamName.IsAutoMode, SystemStateModule)] public bool IsAutoMode { get; set; } [Subscription(ParamName.LocalControlJob, SystemStateModule)] public SorterRecipeXml LocalControlJob { get; set; } [Subscription(ParamName.FoupDoorState, DeviceName.LoadportA)] public FoupDoorState LPADoorState { get; set; } [Subscription(ParamName.FoupDoorState, DeviceName.LoadportB)] public FoupDoorState LPBDoorState { get; set; } [Subscription(ParamName.FoupClampState, DeviceName.LoadportA)] public FoupClampState FoupAClampState { get; set; } [Subscription(ParamName.FoupClampState, DeviceName.LoadportB)] public FoupClampState FoupBClampState { get; set; } #endregion #region Logic public Visibility CycleVisibility { get; set; } public bool IsHomeAllButtonEnabled { get { return !IsAutoMode; } } public bool IsAbortHomeAllButtonEnabled { get { return !IsAutoMode && RoutManagerState != (int)RtState.Idle && RoutManagerState != (int)RtState.Init; } } public bool IsStartCycleButtonEnabled { get { return IsAutoMode; } } public bool IsReturnWaferButtonEnabled { get { return !IsAutoMode; } } public bool IsStopCycleButtonEnabled { get { return IsAutoMode; } } public bool IsManualMode { get { return !IsAutoMode; } } [IgnorePropertyChange] public string SelectedRecipeName { get; set; } public bool IsProcessing { get { return (RtState)RoutManagerState == RtState.PauseProcess || (RtState)RoutManagerState == RtState.Processing; } } public string RtStatus { get { return ((RtState)RoutManagerState).ToString(); } } public bool IsManualButtonEnabled { get { return IsAutoMode; } } public bool IsAutoButtonEnabled { get { return !IsAutoMode; } } public bool IsEnableSelectRecipe { get { return IsAutoMode && !IsProcessing; } } public bool IsEnableStartRecipe { get { return IsAutoMode && !string.IsNullOrEmpty(SelectedRecipeName) && !IsProcessing; } } public bool IsEnablePauseRecipe { get { return IsAutoMode && IsProcessing; } } public bool IsEnableResumeRecipe { get { return IsAutoMode && IsProcessing; } } public bool IsEnableStopRecipe { get { return IsAutoMode && IsProcessing; } } public bool IsMaintenanceMode { get => RoutManagerState == (int)RtState.Maintenance; } #endregion public OperationViewModel() : base("OperationViewModal") { OperationCommand = new DelegateCommand(Operation, x => { if (IsMaintenanceMode) { return false; } switch (x) { case "HomeAll": return IsHomeAllButtonEnabled; case "AbortHomeAll": return IsAbortHomeAllButtonEnabled; case "ReturnWafer": return IsReturnWaferButtonEnabled; case "Cycle": return IsStartCycleButtonEnabled; case "Stop": return IsStopCycleButtonEnabled; default: break; } return true; }); LoadPortACommand = new DelegateCommand(DoLoadPortACmd, x => { if (IsMaintenanceMode) { return false; } bool result = (LoadportAState == DeviceState.Idle.ToString()); if (result) { switch (x) { case OperationName.ReadFoupID: result = (LPACassetteState == LoadportCassetteState.Normal && FoupAClampState != FoupClampState.Close); break; case OperationName.LoadFoup: result = (FoupAClampState == FoupClampState.Close && LPADoorState != FoupDoorState.Open); break; case OperationName.UnloadFoup: result = (LPACassetteState == LoadportCassetteState.Normal && FoupAClampState == FoupClampState.Close); break; default: result = false; break; } } return result; }); LoadPortBCommand = new DelegateCommand(DoLoadPortBCmd, x => { if (IsMaintenanceMode) { return false; } bool result = (LoadportBState == DeviceState.Idle.ToString()); if (result) { switch (x) { case OperationName.ReadFoupID: result = (LPBCassetteState == LoadportCassetteState.Normal && FoupBClampState == FoupClampState.Open); break; case OperationName.LoadFoup: result = (FoupBClampState == FoupClampState.Close && LPBDoorState == FoupDoorState.Close); break; case OperationName.UnloadFoup: result = (LPBCassetteState == LoadportCassetteState.Normal && FoupBClampState == FoupClampState.Close); break; default: result = false; break; } } return result; }); RecipeSelectCommand = new DelegateCommand(SelectRecipe, x => !IsMaintenanceMode && IsEnableSelectRecipe); RecipeStartCommand = new DelegateCommand(StartRecipe, x => !IsMaintenanceMode && IsEnableStartRecipe); RecipePauseCommand = new DelegateCommand(PauseRecipe, x => !IsMaintenanceMode && IsEnablePauseRecipe); RecipeResumeCommand = new DelegateCommand(ResumeRecipe, x => !IsMaintenanceMode && IsEnableResumeRecipe); RecipeStopCommand = new DelegateCommand(StopRecipe, x => !IsMaintenanceMode && IsEnableStopRecipe); } private void DoLoadPortACmd(string cmd) { var deviceName = ModuleName.LP1; var param = new object[] { deviceName }; DeviceOperation(cmd, param); } private void DoLoadPortBCmd(string cmd) { var deviceName = ModuleName.LP2; var param = new object[] { deviceName }; DeviceOperation(cmd, param); } private void DeviceOperation(string cmd, object[] param) { InvokeClient.Instance.Service.DoOperation(cmd, param); } void Operation(string param) { InvokeClient.Instance.Service.DoOperation(param); } protected override void InvokeBeforeUpdateProperty(Dictionary data) { CycleVisibility = ((bool)QueryDataClient.Instance.Service.GetConfig(SorterCommon.ScPathName.Process_CycleEnable)) ? Visibility.Visible : Visibility.Hidden; //data[UIKey(UnitName.LoadportA.ToString(), ParamName.FoupDoorState)] = FoupDoorState.Close; } #region recipe private void SelectRecipe(object param) { RecipeSelectDialog dialog = new RecipeSelectDialog(RecipeClient.Instance.Service.GetXmlRecipeList(ModuleName.System, false)) { Owner = Application.Current.MainWindow }; var ret = dialog.ShowDialog(); if (ret.HasValue && ret.Value) { SelectedRecipeName = dialog.SelectedRecipe; InvokePropertyChanged("SelectedRecipeName"); InvokeClient.Instance.Service.DoOperation(OperationName.SelectRecipe, SelectedRecipeName); } } private void StartRecipe(object param) { if (string.IsNullOrEmpty(SelectedRecipeName)) { return; } InvokeClient.Instance.Service.DoOperation(OperationName.StartRecipe, SelectedRecipeName); } private void PauseRecipe(object param) { if (MessageBox.Show("Are you sure you want to pause the process?", "Sorter", MessageBoxButton.YesNo) == MessageBoxResult.Yes) { InvokeClient.Instance.Service.DoOperation(OperationName.PauseRecipe); } } private void ResumeRecipe(object param) { if (MessageBox.Show("Are you sure you want to resume the process?", "Sorter", MessageBoxButton.YesNo) == MessageBoxResult.Yes) { InvokeClient.Instance.Service.DoOperation(OperationName.ResumeRecipe); } } private void StopRecipe(object param) { if (MessageBox.Show("Are you sure you want to abort the process?", "Sorter", MessageBoxButton.YesNo) == MessageBoxResult.Yes) { InvokeClient.Instance.Service.DoOperation(OperationName.StopRecipe); } } #endregion } }