ContextMenuManager.cs 3.9 KB

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