using MECF.Framework.Common.CommonData; using MECF.Framework.Common.DataCenter; using OpenSEMI.ClientBase; using Prism.Commands; using Prism.Mvvm; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Threading; using Venus_MainPages.Unity; using Venus_Themes.CustomControls; namespace Venus_MainPages.ViewModels { public class OperationOverViewModel : BindableBase { #region 私有字段 private bool m_TabIsChecked=true; private ModuleInfo m_LP1ModuleInfo; private ModuleInfo m_LP2ModuleInfo; private ModuleInfo m_LP3ModuleInfo; private WaferRobotTAction m_Robot1TAction; private WaferRobotXAction m_Robot1XAction; private WaferRobotTAction m_Robot2TAction; private WaferRobotXAction m_Robot2XAction; private RobotMoveInfo m_robotMoveInfo; int arm1oldWaferStatus = 100; int arm2oldWaferStatus = 100; private WaferInfo m_PMAWafer; private WaferInfo m_PMBWafer; private WaferInfo m_PMCWafer; private WaferInfo m_PMDWafer; private WaferInfo m_LLAWafer; private WaferInfo m_LLBWafer; private WaferInfo m_TMBladeAWafer; private WaferInfo m_TMBladeBWafer; private List m_RtDataKeys = new List(); private Dictionary m_RtDataValues; private bool m_PMAIsInstalled; private bool m_PMBIsInstalled; private bool m_PMCIsInstalled; private bool m_PMDIsInstalled; private bool m_LLAIsInstalled; private bool m_LLBIsInstalled; private bool m_TMIsInstalled; private bool m_EFEMIsInstalled; private WaferInfo m_EFEMBladeAWafer; private WaferInfo m_EFEMBladeBWafer; private WaferInfo m_Aligner1Wafer; private int m_LP1WaferCount; private int m_LP2WaferCount; private int m_LP3WaferCount; private WaferAssociationInfo _lp1WaferAssociation; private WaferAssociationInfo _lp2WaferAssociation; private WaferAssociationInfo _lp3WaferAssociation; #endregion #region 属性 public bool TabIsChecked { get { return m_TabIsChecked; } set { SetProperty(ref m_TabIsChecked, value); } } public ModuleInfo LP1ModuleInfo { get { return m_LP1ModuleInfo; } set { SetProperty(ref m_LP1ModuleInfo, value); } } public ModuleInfo LP2ModuleInfo { get { return m_LP2ModuleInfo; } set { SetProperty(ref m_LP2ModuleInfo, value); } } public ModuleInfo LP3ModuleInfo { get { return m_LP3ModuleInfo; } set { SetProperty(ref m_LP3ModuleInfo, value); } } public WaferRobotTAction Robot1TAction { get { return m_Robot1TAction; } set { SetProperty(ref m_Robot1TAction, value); } } public WaferRobotXAction Robot1XAction { get { return m_Robot1XAction; } set { SetProperty(ref m_Robot1XAction, value); } } public WaferRobotTAction Robot2TAction { get { return m_Robot2TAction; } set { SetProperty(ref m_Robot2TAction, value); } } public WaferRobotXAction Robot2XAction { get { return m_Robot2XAction; } set { SetProperty(ref m_Robot2XAction, value); } } public RobotMoveInfo RobotMoveInfo { get { return m_robotMoveInfo; } set { RobotMoveInfoChanged(m_robotMoveInfo, value); m_robotMoveInfo = value; } } public WaferInfo LLAWafer { get { return m_LLAWafer; } set { SetProperty(ref m_LLAWafer, value); } } public WaferInfo LLBWafer { get { return m_LLBWafer; } set { SetProperty(ref m_LLBWafer, value); } } public WaferInfo PMAWafer { get { return m_PMAWafer; } set { SetProperty(ref m_PMAWafer, value); } } public WaferInfo PMBWafer { get { return m_PMBWafer; } set { SetProperty(ref m_PMBWafer, value); } } public WaferInfo PMCWafer { get { return m_PMCWafer; } set { SetProperty(ref m_PMCWafer, value); } } public WaferInfo PMDWafer { get { return m_PMDWafer; } set { SetProperty(ref m_PMDWafer, value); } } public WaferInfo TMBladeAWafer { get { return m_TMBladeAWafer; } set { SetProperty(ref m_TMBladeAWafer, value); } } public WaferInfo TMBladeBWafer { get { return m_TMBladeBWafer; } set { SetProperty(ref m_TMBladeBWafer, value); } } public Dictionary RtDataValues { get { return m_RtDataValues; } set { SetProperty(ref m_RtDataValues, value); } } public bool PMAIsInstalled { get { return m_PMAIsInstalled; } set { SetProperty(ref m_PMAIsInstalled, value); } } public bool PMBIsInstalled { get { return m_PMBIsInstalled; } set { SetProperty(ref m_PMBIsInstalled, value); } } public bool PMCIsInstalled { get { return m_PMCIsInstalled; } set { SetProperty(ref m_PMCIsInstalled, value); } } public bool PMDIsInstalled { get { return m_PMDIsInstalled; } set { SetProperty(ref m_PMDIsInstalled, value); } } public bool LLAIsInstalled { get { return m_LLAIsInstalled; } set { SetProperty(ref m_LLAIsInstalled, value); } } public bool LLBIsInstalled { get { return m_LLBIsInstalled; } set { SetProperty(ref m_LLBIsInstalled, value); } } public bool TMIsInstalled { get { return m_TMIsInstalled; } set { SetProperty(ref m_TMIsInstalled, value); } } public bool EFEMIsInstalled { get { return m_EFEMIsInstalled; } set { SetProperty(ref m_EFEMIsInstalled, value); } } public WaferInfo EFEMBladeAWafer { get { return m_EFEMBladeAWafer; } set { SetProperty(ref m_EFEMBladeAWafer, value); } } public WaferInfo EFEMBladeBWafer { get { return m_EFEMBladeBWafer; } set { SetProperty(ref m_EFEMBladeBWafer, value); } } public WaferInfo Aligner1Wafer { get { return m_Aligner1Wafer; } set { SetProperty(ref m_Aligner1Wafer, value); } } public int LP1WaferCount { get { return m_LP1WaferCount; } set { SetProperty(ref m_LP1WaferCount, value); } } public int LP2WaferCount { get { return m_LP2WaferCount; } set { SetProperty(ref m_LP2WaferCount, value); } } public int LP3WaferCount { get { return m_LP3WaferCount; } set { SetProperty(ref m_LP3WaferCount, value); } } public WaferAssociationInfo LP1WaferAssociation { get { return _lp1WaferAssociation; } set { SetProperty(ref _lp1WaferAssociation, value); } } public WaferAssociationInfo LP2WaferAssociation { get { return _lp2WaferAssociation; } set { SetProperty(ref _lp2WaferAssociation, value); } } public WaferAssociationInfo LP3WaferAssociation { get { return _lp3WaferAssociation; } set { SetProperty(ref _lp3WaferAssociation, value); } } #endregion #region 命令 private DelegateCommand _LoadCommand; public DelegateCommand LoadCommand => _LoadCommand ?? (_LoadCommand = new DelegateCommand(OnLoad)); #endregion #region 构造函数 public OperationOverViewModel() { DispatcherTimer timer = new DispatcherTimer(); timer.Interval = TimeSpan.FromSeconds(0.5); timer.Tick += Timer_Tick; timer.Start(); addDataKeys(); string allModules = QueryDataClient.Instance.Service.GetConfig($"System.InstalledModules").ToString(); PMAIsInstalled = allModules.Contains("PMA"); PMBIsInstalled = allModules.Contains("PMB"); PMCIsInstalled = allModules.Contains("PMC"); PMDIsInstalled = allModules.Contains("PMD"); LLAIsInstalled = allModules.Contains("LLA"); LLBIsInstalled = allModules.Contains("LLB"); EFEMIsInstalled = allModules.Contains("EFEM"); } #endregion #region 命令方法 private void OnLoad() { LP1WaferAssociation = new WaferAssociationInfo(); LP1WaferAssociation.ModuleData = ModuleManager.ModuleInfos["LP1"]; LP2WaferAssociation = new WaferAssociationInfo(); LP2WaferAssociation.ModuleData = ModuleManager.ModuleInfos["LP2"]; LP3WaferAssociation = new WaferAssociationInfo(); LP3WaferAssociation.ModuleData = ModuleManager.ModuleInfos["LP3"]; } #endregion #region 私有方法 private void Timer_Tick(object sender, EventArgs e) { LP1ModuleInfo = ModuleManager.ModuleInfos["LP1"]; LP2ModuleInfo = ModuleManager.ModuleInfos["LP2"]; LP3ModuleInfo = ModuleManager.ModuleInfos["LP3"]; if (LLAIsInstalled == true) { LLAWafer = ModuleManager.ModuleInfos["LLA"].WaferManager.Wafers.FirstOrDefault(x => x.WaferStatus != 0); } if (LLBIsInstalled == true) { LLBWafer = ModuleManager.ModuleInfos["LLB"].WaferManager.Wafers.FirstOrDefault(x => x.WaferStatus != 0); } if (PMAIsInstalled == true) { PMAWafer = ModuleManager.ModuleInfos["PMA"].WaferManager.Wafers[0]; } if (PMBIsInstalled == true) { PMBWafer = ModuleManager.ModuleInfos["PMB"].WaferManager.Wafers[0]; } if (PMCIsInstalled == true) { PMCWafer = ModuleManager.ModuleInfos["PMC"].WaferManager.Wafers[0]; } if (PMDIsInstalled == true) { PMDWafer = ModuleManager.ModuleInfos["PMD"].WaferManager.Wafers[0]; } if (TMIsInstalled == true) { TMBladeAWafer = ModuleManager.ModuleInfos["TMRobot"].WaferManager.Wafers[0]; TMBladeBWafer = ModuleManager.ModuleInfos["TMRobot"].WaferManager.Wafers[1]; } if (EFEMIsInstalled == true) { EFEMBladeAWafer = ModuleManager.ModuleInfos["EfemRobot"].WaferManager.Wafers[0]; EFEMBladeBWafer = ModuleManager.ModuleInfos["EfemRobot"].WaferManager.Wafers[1]; Aligner1Wafer = ModuleManager.ModuleInfos["Aligner1"].WaferManager.Wafers[0]; } RobotMoveInfo = (RobotMoveInfo)QueryDataClient.Instance.Service.GetData("TM.RobotMoveAction"); RtDataValues = QueryDataClient.Instance.Service.PollData(m_RtDataKeys); LP1WaferCount = LP1ModuleInfo.WaferManager.Wafers.Where(x=>x.WaferStatus!=0).Count(); LP2WaferCount = LP2ModuleInfo.WaferManager.Wafers.Where(x => x.WaferStatus != 0).Count(); LP3WaferCount = LP3ModuleInfo.WaferManager.Wafers.Where(x => x.WaferStatus != 0).Count(); } private async void RobotMoveInfoChanged(RobotMoveInfo oldValue, RobotMoveInfo newValue) { string RobotTarget; if (oldValue == null || newValue == null) { return; } #region pick 和 place LL if (oldValue.Action == RobotAction.None && (newValue.Action == RobotAction.Placing || newValue.Action == RobotAction.Picking)) { var TMRobotMoveActionBladeTarget = newValue.BladeTarget; if (TMRobotMoveActionBladeTarget != null) { RobotTarget = TMRobotMoveActionBladeTarget.ToString(); } else { return; } var values = RobotTarget.Split('.'); var arm = values[0]; var module = values[1]; if (arm == "ArmA") { Robot1TAction = (WaferRobotTAction)Enum.Parse(typeof(WaferRobotTAction), module, true); await Task.Delay(1500); Robot1XAction = WaferRobotXAction.Extend; await Task.Delay(3000); Robot1XAction = WaferRobotXAction.Retract; } else if (arm == "ArmB") { Robot2TAction = (WaferRobotTAction)Enum.Parse(typeof(WaferRobotTAction), module, true); await Task.Delay(1500); Robot2XAction = WaferRobotXAction.Extend; await Task.Delay(3000); Robot2XAction = WaferRobotXAction.Retract; } } #endregion #region pick 和 place pm if (oldValue.Action == RobotAction.None && newValue.Action == RobotAction.Extending) { var TMRobotMoveActionBladeTarget = newValue.BladeTarget; if (TMRobotMoveActionBladeTarget != null) { RobotTarget = TMRobotMoveActionBladeTarget.ToString(); } else { return; } var values = RobotTarget.Split('.'); var arm = values[0]; var module = values[1]; if (arm == "ArmA") { Robot1TAction = (WaferRobotTAction)Enum.Parse(typeof(WaferRobotTAction), module, true); await Task.Delay(1500); Robot1XAction = WaferRobotXAction.Extend; } else if (arm == "ArmB") { Robot2TAction = (WaferRobotTAction)Enum.Parse(typeof(WaferRobotTAction), module, true); await Task.Delay(1500); Robot2XAction = WaferRobotXAction.Extend; } } if (oldValue.Action == RobotAction.None && newValue.Action == RobotAction.Retracting) { var TMRobotMoveActionBladeTarget = newValue.BladeTarget; if (TMRobotMoveActionBladeTarget != null) { RobotTarget = TMRobotMoveActionBladeTarget.ToString(); } else { return; } var values = RobotTarget.Split('.'); var arm = values[0]; if (arm == "ArmA") { Robot1XAction = WaferRobotXAction.Retract; } else if (arm == "ArmB") { Robot2XAction = WaferRobotXAction.Retract; } } #endregion arm1oldWaferStatus = ModuleManager.ModuleInfos["TMRobot"].WaferManager.Wafers[0].WaferStatus; arm2oldWaferStatus = ModuleManager.ModuleInfos["TMRobot"].WaferManager.Wafers[1].WaferStatus; } private void addDataKeys() { m_RtDataKeys.Add("PMA.IsSlitDoorClosed"); m_RtDataKeys.Add("PMB.IsSlitDoorClosed"); m_RtDataKeys.Add("PMC.IsSlitDoorClosed"); m_RtDataKeys.Add("PMD.IsSlitDoorClosed"); m_RtDataKeys.Add("TM.LLATSlitDoor.IsClosed"); m_RtDataKeys.Add("TM.LLBTSlitDoor.IsClosed"); } #endregion } }