using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using Aitex.Core.RT.Log; using OpenSEMI.Ctrlib.Controls; using MECF.Framework.Common.OperationCenter; using OpenSEMI.ClientBase; using Aitex.Core.Util; namespace VirgoUI.Client { public class MenuElement { public string Name { get; set; } public string Invoke { get; set; } public bool IsSeparator { get; set; } } public class ContextMenuManager { #region single Instance private static ContextMenuManager m_Instance = null; public static ContextMenuManager Instance { get { if (m_Instance == null) { m_Instance = new ContextMenuManager(); } return m_Instance; } } #endregion private ContextMenu _slotMenus; public ContextMenu SlotMenus { get { return _slotMenus; } } public ContextMenuManager() { _slotMenus = InitMenus(_SlotMenuElements); } private readonly List _SlotMenuElements = new List() { new MenuElement(){ Name="Create Wafer", Invoke="CreateWafer"}, new MenuElement(){ Name="Delete Wafer", Invoke="DeleteWafer"}, new MenuElement(){ Name="-", IsSeparator = true}, new MenuElement(){ Name="Return Wafer", Invoke="ReturnWafer"} }; public void OnContextMenuClick(object sender, RoutedEventArgs args) { try { MenuItem m_menu = sender as MenuItem; Slot CurrentSlot = ContextMenuService.GetPlacementTarget(LogicalTreeHelper.GetParent(m_menu)) as Slot; if (CurrentSlot == null) return; MenuElement ele = m_menu.Tag as MenuElement; string m_modID = CurrentSlot.ModuleID; int slotId = CurrentSlot.SlotID; InvokeClient.Instance.Service.DoOperation(ele.Invoke, CurrentSlot.ModuleID, CurrentSlot.SlotID); } catch (Exception ex) { LOG.Write(ex); } } private ContextMenu InitMenus(List menus) { ContextMenu cm = new ContextMenu(); foreach (MenuElement element in menus) { if (element.IsSeparator) { cm.Items.Add(new Separator()); } else { MenuItem m_item = new MenuItem(); m_item.Header = element.Name; m_item.Tag = element; m_item.Click += new RoutedEventHandler(OnContextMenuClick); m_item.IsEnabled = true; cm.Items.Add(m_item); } } return cm; } public bool IsAutoMode { get; set; } public bool EnableAuto { get { return !IsAutoMode; } } public ContextMenu GetSlotMenus(Slot slot) { if (slot != null) { MenuItem createWafer = _slotMenus.Items.GetItemAt(0) as MenuItem; MenuItem deleteWafer = _slotMenus.Items.GetItemAt(1) as MenuItem; MenuItem returnWafer = _slotMenus.Items.GetItemAt(3) as MenuItem; createWafer.IsEnabled = ((WaferStatus)slot.WaferStatus == WaferStatus.Empty ? true : false)&& EnableAuto; deleteWafer.IsEnabled = ((WaferStatus)slot.WaferStatus == WaferStatus.Empty ? false : true) && EnableAuto; returnWafer.IsEnabled = (WaferStatus)slot.WaferStatus != WaferStatus.Empty && !slot.ModuleID.StartsWith("LP"); } return _slotMenus; } } }