ContextMenuManager.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Windows;
  7. using System.Windows.Controls;
  8. using Aitex.Core.RT.Log;
  9. using OpenSEMI.Ctrlib.Controls;
  10. using MECF.Framework.Common.OperationCenter;
  11. using OpenSEMI.ClientBase;
  12. namespace Virgo_DUI.Client
  13. {
  14. public class MenuElement
  15. {
  16. public string Name { get; set; }
  17. public string Invoke { get; set; }
  18. public bool IsSeparator { get; set; }
  19. }
  20. public class ContextMenuManager
  21. {
  22. #region single Instance
  23. private static ContextMenuManager m_Instance = null;
  24. public static ContextMenuManager Instance
  25. {
  26. get
  27. {
  28. if (m_Instance == null)
  29. {
  30. m_Instance = new ContextMenuManager();
  31. }
  32. return m_Instance;
  33. }
  34. }
  35. #endregion
  36. private ContextMenu _slotMenus;
  37. public ContextMenu SlotMenus
  38. {
  39. get { return _slotMenus; }
  40. }
  41. public ContextMenuManager()
  42. {
  43. _slotMenus = InitMenus(_SlotMenuElements);
  44. }
  45. private readonly List<MenuElement> _SlotMenuElements = new List<MenuElement>() {
  46. new MenuElement(){ Name="Create Wafer", Invoke="CreateWafer"},
  47. new MenuElement(){ Name="Delete Wafer", Invoke="DeleteWafer"},
  48. new MenuElement(){ Name="-", IsSeparator = true},
  49. new MenuElement(){ Name="Return Wafer", Invoke="ReturnWafer"}
  50. };
  51. public void OnContextMenuClick(object sender, RoutedEventArgs args)
  52. {
  53. try
  54. {
  55. MenuItem m_menu = sender as MenuItem;
  56. Slot CurrentSlot = ContextMenuService.GetPlacementTarget(LogicalTreeHelper.GetParent(m_menu)) as Slot;
  57. if (CurrentSlot == null)
  58. return;
  59. MenuElement ele = m_menu.Tag as MenuElement;
  60. string m_modID = CurrentSlot.ModuleID;
  61. int slotId = CurrentSlot.SlotID;
  62. InvokeClient.Instance.Service.DoOperation(ele.Invoke, CurrentSlot.ModuleID, CurrentSlot.SlotID);
  63. }
  64. catch (Exception ex)
  65. {
  66. LOG.Write(ex);
  67. }
  68. }
  69. private ContextMenu InitMenus(List<MenuElement> menus)
  70. {
  71. ContextMenu cm = new ContextMenu();
  72. foreach (MenuElement element in menus)
  73. {
  74. if (element.IsSeparator)
  75. {
  76. cm.Items.Add(new Separator());
  77. }
  78. else
  79. {
  80. MenuItem m_item = new MenuItem();
  81. m_item.Header = element.Name;
  82. m_item.Tag = element;
  83. m_item.Click += new RoutedEventHandler(OnContextMenuClick);
  84. m_item.IsEnabled = true;
  85. cm.Items.Add(m_item);
  86. }
  87. }
  88. return cm;
  89. }
  90. public ContextMenu GetSlotMenus(Slot slot)
  91. {
  92. if (slot != null)
  93. {
  94. MenuItem createWafer = _slotMenus.Items.GetItemAt(0) as MenuItem;
  95. MenuItem deleteWafer = _slotMenus.Items.GetItemAt(1) as MenuItem;
  96. MenuItem returnWafer = _slotMenus.Items.GetItemAt(3) as MenuItem;
  97. createWafer.IsEnabled = (WaferStatus)slot.WaferStatus == WaferStatus.Empty ? true : false;
  98. deleteWafer.IsEnabled = (WaferStatus)slot.WaferStatus == WaferStatus.Empty ? false : true;
  99. returnWafer.IsEnabled = (WaferStatus)slot.WaferStatus != WaferStatus.Empty && !slot.ModuleID.StartsWith("LP");
  100. }
  101. return _slotMenus;
  102. }
  103. }
  104. }