ShellView.xaml.cs 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521
  1. using Prism.Regions;
  2. using System.Collections.Generic;
  3. using System.Windows;
  4. using Venus_Themes.CustomControls;
  5. using Venus_UI.Themes.Attach;
  6. using Venus_Unity;
  7. using System.Linq;
  8. using System.Threading;
  9. using System;
  10. using Venus_MainPages.Views;
  11. using System.Windows.Controls;
  12. using Aitex.Core.UI.View.Frame;
  13. using System.Windows.Media;
  14. using Venus_Core;
  15. using System.Reflection;
  16. using Venus_MainPages.Unity;
  17. using MECF.Framework.Common.DataCenter;
  18. using MECF.Framework.Common.OperationCenter;
  19. using Aitex.Core.RT.OperationCenter;
  20. using Venus_MainPages.ViewModels;
  21. using MECF.Framework.Common.CommonData;
  22. using System.Windows.Controls.Primitives;
  23. using System.Timers;
  24. using System.Windows.Threading;
  25. using Venus_Themes.Unity;
  26. using Venus_Themes.UserControls;
  27. using OpenSEMI.Ctrlib.Controls;
  28. using OpenSEMI.ClientBase;
  29. using MECF.Framework.Common.Equipment;
  30. using WinInterop = System.Windows.Interop;
  31. using System.Runtime.InteropServices;
  32. namespace Venus_UI.Views
  33. {
  34. /// <summary>
  35. /// ShellView.xaml 的交互逻辑
  36. /// </summary>
  37. public partial class ShellView : Window
  38. {
  39. IRegionManager m_regionManager;
  40. IRegionNavigationService m_regionNavigationService;
  41. List<VenusMenu> VenusMenu;
  42. List<TabControl> centerTabViews = new List<TabControl>();
  43. List<Button> buttonList = new List<Button>();
  44. DispatcherTimer timer = new DispatcherTimer();
  45. private bool IsMaxed = false;
  46. public ShellView(IRegionManager regionManager, IRegionNavigationService regionNavigationService)
  47. {
  48. InitializeComponent();
  49. m_regionManager = regionManager;
  50. m_regionNavigationService = regionNavigationService;
  51. m_regionManager.RegisterViewWithRegion("TopRegion", typeof(Venus_MainPages.Views.TopView));
  52. VenusGlobalEvents.SlotRightClickChangedEvent += Instance_SlotRightClickChangedEvent;
  53. VenusGlobalEvents.SlotWaferTransferEvent += Instance_SlotStartTransferEvent;
  54. timer.Tick += timer_Tick;
  55. timer.Interval = TimeSpan.FromSeconds(0.5);
  56. timer.Start();
  57. UIEvents.PMDoorRaiseChangedEvent += UIEvents_PMDoorRaiseChangedEvent;
  58. UIEvents.LLTDoorRaiseChangedEvent += UIEvents_LLTDoorRaiseChangedEvent;
  59. UIEvents.LLEDoorRaiseChangedEvent += UIEvents_LLEDoorRaiseChangedEvent;
  60. UIEvents.ChamberCreateDeleteWaferEvent += UIEvents_ChamberCreateDeleteWaferEvent;
  61. this.SourceInitialized += (o, e) =>
  62. {
  63. System.IntPtr handler = (new WinInterop.WindowInteropHelper(this)).Handle;
  64. WinInterop.HwndSource.FromHwnd(handler).AddHook(new WinInterop.HwndSourceHook(WindowProc));
  65. };
  66. this.MaxHeight = SystemParameters.WorkArea.Height;
  67. ResizeMode = ResizeMode.CanMinimize;
  68. this.WindowState = this.WindowState == WindowState.Maximized ? WindowState.Normal : WindowState.Maximized;
  69. }
  70. void timer_Tick(object sender, EventArgs e)
  71. {
  72. if (Anychange.needchange)
  73. {
  74. Anystationchange(Anychange.menuname, Anychange.args);
  75. Anychange.needchange = false;
  76. }
  77. }
  78. private void Instance_SlotRightClickChangedEvent(OpenSEMI.Ctrlib.Controls.Slot slot)
  79. {
  80. if (slot != null)
  81. {
  82. ContextMenu cm = ContextMenuManager.Instance.GetSlotMenus(slot);
  83. if (cm != null)
  84. {
  85. slot.ContextMenu = cm;
  86. }
  87. return;
  88. }
  89. }
  90. private void Instance_SlotStartTransferEvent(OpenSEMI.Ctrlib.Controls.DragDropEventArgs e)
  91. {
  92. string info = " from " + e.TranferFrom.ModuleID + " slot " + (e.TranferFrom.SlotID + 1).ToString() + " to " + e.TranferTo.ModuleID + " slot " + (e.TranferTo.SlotID + 1).ToString();
  93. string message = "Are you sure to transfer the wafer: \n" + info;
  94. WaferDialogViewModel vm = new WaferDialogViewModel();
  95. vm.ConfirmText = message;
  96. WaferDialogView dialog = new WaferDialogView()
  97. {
  98. Owner = Application.Current.MainWindow,
  99. };
  100. dialog.DataContext = vm;
  101. dialog.Height = 300;
  102. dialog.Width = 400;
  103. bool alignflag = false;
  104. bool coolingflag = false;
  105. double angel = 0;
  106. double coolingtime = 0;
  107. if (dialog.ShowDialog() == true)
  108. {
  109. alignflag = (bool)dialog.AlignFlag;
  110. coolingflag = (bool)dialog.CoolingFlag;
  111. if (alignflag && !string.IsNullOrEmpty(dialog.Angle))
  112. {
  113. angel = Convert.ToDouble(dialog.Angle);
  114. }
  115. if (coolingflag && !string.IsNullOrEmpty(dialog.CoolingTime))
  116. {
  117. coolingtime = Convert.ToDouble(dialog.CoolingTime);
  118. }
  119. //from robot to robot is illegal. Must be stop
  120. if (e.TranferFrom.ModuleID == e.TranferTo.ModuleID && (e.TranferTo.ModuleID == ModuleName.EfemRobot.ToString() || e.TranferTo.ModuleID == ModuleName.TMRobot.ToString()))
  121. {
  122. }
  123. else
  124. InvokeClient.Instance.Service.DoOperation("System.MoveWafer",
  125. e.TranferFrom.ModuleID, e.TranferFrom.SlotID, e.TranferTo.ModuleID, e.TranferTo.SlotID, alignflag, angel, coolingflag, coolingtime, "");
  126. }
  127. else
  128. {
  129. ModuleManager.OnFlashWafer(new FlashWaferInformation() { ModuleName = e.TranferFrom.ModuleID, SoltId = e.TranferFrom.SlotID });
  130. //ModuleManager.OnFlashWafer(new FlashWaferInformation() { ModuleName = e.TranferTo.ModuleID, SoltId = e.TranferTo.SlotID });
  131. }
  132. e.TranferFrom.ClearDragDropStatus();
  133. e.TranferTo.ClearDragDropStatus();
  134. }
  135. private void CustomWnd_Loaded(object sender, RoutedEventArgs e)
  136. {
  137. var h1 = SystemParameters.WorkArea.Height;
  138. var h2 = SystemParameters.PrimaryScreenHeight;
  139. //this.ResizeMode = ResizeMode.CanResize;
  140. //System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width / SystemParameters.PrimaryScreenWidth
  141. VenusMenu = SerializeHelper.Instance.ReadFromJsonFile<List<VenusMenu>>($"Config/UIMenu.json");
  142. int index = 0;
  143. for (int i = 0; i < VenusMenu.Count; i++)
  144. {
  145. if (VenusMenu[i].IsShow == false)
  146. {
  147. continue;
  148. }
  149. string[] allModules = QueryDataClient.Instance.Service.GetConfig($"System.InstalledModules").ToString().Split(',');
  150. if (VenusMenu[i].Id == "PMA" || VenusMenu[i].Id == "PMB" || VenusMenu[i].Id == "PMC" || VenusMenu[i].Id == "PMD" || VenusMenu[i].Id == "TM")
  151. {
  152. if (!allModules.Contains(VenusMenu[i].Id))
  153. {
  154. continue;
  155. }
  156. }
  157. //if (VenusMenu[i].Id == "SETM" && SC.GetStringValue("System.ChamberSelect") !="4" && SC.GetStringValue("System.ChamberSelect") != "5")
  158. //{
  159. // //不是SE DE
  160. // continue;
  161. //}
  162. AduRadioButtonIcon aduRadioButtonIcon = new AduRadioButtonIcon();
  163. if (i == 0)
  164. {
  165. aduRadioButtonIcon.IsChecked = true;
  166. }
  167. IconElement.SetPathData(aduRadioButtonIcon, (Geometry)aduRadioButtonIcon.FindResource($"Icon_{VenusMenu[i].Id}"));
  168. aduRadioButtonIcon.Content = VenusMenu[i].Name;
  169. aduRadioButtonIcon.Click += AduRadioButtonIcon_Click;
  170. aduRadioButtonIcon.SelectBackground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#6AD7FF"));
  171. aduRadioButtonIcon.SelectColor = new SolidColorBrush((Colors.Black));
  172. aduRadioButtonIcon.DefaultBackground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#94BCD7"));
  173. //aduRadioButtonIcon.DefaultBackground = new SolidColorBrush(Colors.DarkGray);
  174. aduRadioButtonIcon.Width = 180;
  175. aduRadioButtonIcon.Height = 40;
  176. //aduRadioButtonIcon.Foreground=Brushes.White;
  177. aduRadioButtonIcon.Tag = index;
  178. index += 1;
  179. Bottom_Frame.Children.Add(aduRadioButtonIcon);
  180. TabControl tabControl = new TabControl();
  181. for (int j = 0; j < VenusMenu[i].MenuItem.Count; j++)
  182. {
  183. if (VenusMenu[i].MenuItem[j].IsShow == false)
  184. {
  185. continue;
  186. }
  187. string className;
  188. if ((VenusMenu[i].Id == "PMA" || VenusMenu[i].Id == "PMB" || VenusMenu[i].Id == "PMC" || VenusMenu[i].Id == "PMD") && VenusMenu[i].MenuItem[j].Id == "Operation")
  189. {
  190. JetChamber jetChamber = (JetChamber)(Convert.ToInt32(QueryDataClient.Instance.Service.GetConfig($"{VenusMenu[i].Id}.ChamberType")));
  191. className = $"Venus_MainPages.Views.Over{jetChamber.ToString()}View";
  192. }
  193. else
  194. {
  195. className = $"Venus_MainPages.Views.{VenusMenu[i].MenuItem[j].View}";
  196. }
  197. Type t = Type.GetType($"{className},Venus_MainPages");
  198. var obj = System.Activator.CreateInstance(t);
  199. if (VenusMenu[i].Id == "PMA" || VenusMenu[i].Id == "PMB" || VenusMenu[i].Id == "PMC" || VenusMenu[i].Id == "PMD" || VenusMenu[i].Id == "TM" || VenusMenu[i].Id == "SETM")
  200. {
  201. MethodInfo methodInfo = t.GetMethod("Init", new Type[] { typeof(string) });
  202. methodInfo?.Invoke(obj, new object[] { VenusMenu[i].Id });
  203. }
  204. tabControl.Items.Add(new TabItem() { Header = VenusMenu[i].MenuItem[j].Name, Content = obj });
  205. }
  206. centerTabViews.Add(tabControl);
  207. }
  208. Main_Frame.Content = centerTabViews[0];
  209. ModuleManager.Initialize();
  210. }
  211. public void Anystationchange(string menuviewItem, WaferHistoryWafer queryFilter)
  212. {
  213. UserControl address = new ProcessHistoryView();
  214. ProcessHistoryViewModel vm = new ProcessHistoryViewModel() { };
  215. vm.searchlot(queryFilter.WaferGuid);
  216. //vm.OnDataGridSelectionChanged(vm.Recipes[0]);
  217. address.DataContext = vm;
  218. int s = 0;
  219. for (int i = 0; i < centerTabViews.Count; i++)
  220. {
  221. var item = centerTabViews[i];
  222. foreach (TabItem v in item.Items)
  223. {
  224. if (v.Header.ToString() == "Process History")
  225. {
  226. s = i;
  227. }
  228. }
  229. }
  230. if (s != 0)
  231. {
  232. centerTabViews[s].Items[2] = new TabItem() { Header = menuviewItem, Content = address };
  233. centerTabViews[s].SelectedIndex = 2;
  234. Main_Frame.Content = centerTabViews[s];
  235. }
  236. }
  237. private void AduRadioButtonIcon_Click(object sender, RoutedEventArgs e)
  238. {
  239. var currentButton = sender as AduRadioButtonIcon;
  240. Main_Frame.Content = centerTabViews[Convert.ToInt32(currentButton.Tag)];
  241. }
  242. private void CustomWnd_Closed(object sender, EventArgs e)
  243. {
  244. System.Diagnostics.Process.GetCurrentProcess().Kill();
  245. }
  246. private void UIEvents_ChamberCreateDeleteWaferEvent(WaferOperation obj)
  247. {
  248. if (obj.IsCreate == true)
  249. {
  250. InvokeClient.Instance.Service.DoOperation("CreateWafer", obj.ModuleName, 0);
  251. }
  252. else
  253. {
  254. InvokeClient.Instance.Service.DoOperation("DeleteWafer", obj.ModuleName, 0);
  255. }
  256. }
  257. private void UIEvents_PMDoorRaiseChangedEvent(DoorPara obj)
  258. {
  259. //InvokeClient.Instance.Service.DoOperation($"{obj?.ModuleName}.SlitDoor.{obj?.IsOpen}");
  260. InvokeClient.Instance.Service.DoOperation($"{obj?.ModuleName}.SetSlitDoor", obj.IsOpen == "Open" ? true : false);
  261. }
  262. private void UIEvents_LLTDoorRaiseChangedEvent(DoorPara obj)
  263. {
  264. InvokeClient.Instance.Service.DoOperation($"TM.SetMFSlitDoor", obj.ModuleName, obj.IsOpen == "Open" ? true : false);
  265. }
  266. private void UIEvents_LLEDoorRaiseChangedEvent(DoorPara obj)
  267. {
  268. InvokeClient.Instance.Service.DoOperation($"TM.SetEFEMSlitDoor", obj.ModuleName, obj.IsOpen == "Open" ? true : false);
  269. }
  270. #region 调用api功能部分
  271. void win_SourceInitialized(object sender, EventArgs e)
  272. {
  273. System.IntPtr handle = (new WinInterop.WindowInteropHelper(this)).Handle;
  274. WinInterop.HwndSource.FromHwnd(handle).AddHook(new WinInterop.HwndSourceHook(WindowProc));
  275. }
  276. private static System.IntPtr WindowProc(
  277. System.IntPtr hwnd,
  278. int msg,
  279. System.IntPtr wParam,
  280. System.IntPtr lParam,
  281. ref bool handled)
  282. {
  283. switch (msg)
  284. {
  285. case 0x0024:
  286. WmGetMinMaxInfo(hwnd, lParam);
  287. handled = true;
  288. break;
  289. }
  290. return (System.IntPtr)0;
  291. }
  292. private static void WmGetMinMaxInfo(System.IntPtr hwnd, System.IntPtr lParam)
  293. {
  294. MINMAXINFO mmi = (MINMAXINFO)Marshal.PtrToStructure(lParam, typeof(MINMAXINFO));
  295. // Adjust the maximized size and position to fit the work area of the correct monitor
  296. int MONITOR_DEFAULTTONEAREST = 0x00000002;
  297. System.IntPtr monitor = MonitorFromWindow(hwnd, MONITOR_DEFAULTTONEAREST);
  298. if (monitor != System.IntPtr.Zero)
  299. {
  300. MONITORINFO monitorInfo = new MONITORINFO();
  301. GetMonitorInfo(monitor, monitorInfo);
  302. RECT rcWorkArea = monitorInfo.rcWork;
  303. RECT rcMonitorArea = monitorInfo.rcMonitor;
  304. mmi.ptMaxPosition.x = Math.Abs(rcWorkArea.left - rcMonitorArea.left);
  305. mmi.ptMaxPosition.y = Math.Abs(rcWorkArea.top - rcMonitorArea.top);
  306. mmi.ptMaxSize.x = Math.Abs(rcWorkArea.right - rcWorkArea.left);
  307. mmi.ptMaxSize.y = Math.Abs(rcWorkArea.bottom - rcWorkArea.top);
  308. }
  309. Marshal.StructureToPtr(mmi, lParam, true);
  310. }
  311. /// <summary>
  312. /// POINT aka POINTAPI
  313. /// </summary>
  314. [StructLayout(LayoutKind.Sequential)]
  315. public struct POINT
  316. {
  317. /// <summary>
  318. /// x coordinate of point.
  319. /// </summary>
  320. public int x;
  321. /// <summary>
  322. /// y coordinate of point.
  323. /// </summary>
  324. public int y;
  325. /// <summary>
  326. /// Construct a point of coordinates (x,y).
  327. /// </summary>
  328. public POINT(int x, int y)
  329. {
  330. this.x = x;
  331. this.y = y;
  332. }
  333. }
  334. [StructLayout(LayoutKind.Sequential)]
  335. public struct MINMAXINFO
  336. {
  337. public POINT ptReserved;
  338. public POINT ptMaxSize;
  339. public POINT ptMaxPosition;
  340. public POINT ptMinTrackSize;
  341. public POINT ptMaxTrackSize;
  342. };
  343. /// <summary>
  344. /// </summary>
  345. [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
  346. public class MONITORINFO
  347. {
  348. /// <summary>
  349. /// </summary>
  350. public int cbSize = Marshal.SizeOf(typeof(MONITORINFO));
  351. /// <summary>
  352. /// </summary>
  353. public RECT rcMonitor = new RECT();
  354. /// <summary>
  355. /// </summary>
  356. public RECT rcWork = new RECT();
  357. /// <summary>
  358. /// </summary>
  359. public int dwFlags = 0;
  360. }
  361. /// <summary> Win32 </summary>
  362. [StructLayout(LayoutKind.Sequential, Pack = 0)]
  363. public struct RECT
  364. {
  365. /// <summary> Win32 </summary>
  366. public int left;
  367. /// <summary> Win32 </summary>
  368. public int top;
  369. /// <summary> Win32 </summary>
  370. public int right;
  371. /// <summary> Win32 </summary>
  372. public int bottom;
  373. /// <summary> Win32 </summary>
  374. public static readonly RECT Empty = new RECT();
  375. /// <summary> Win32 </summary>
  376. public int Width
  377. {
  378. get { return Math.Abs(right - left); } // Abs needed for BIDI OS
  379. }
  380. /// <summary> Win32 </summary>
  381. public int Height
  382. {
  383. get { return bottom - top; }
  384. }
  385. /// <summary> Win32 </summary>
  386. public RECT(int left, int top, int right, int bottom)
  387. {
  388. this.left = left;
  389. this.top = top;
  390. this.right = right;
  391. this.bottom = bottom;
  392. }
  393. /// <summary> Win32 </summary>
  394. public RECT(RECT rcSrc)
  395. {
  396. this.left = rcSrc.left;
  397. this.top = rcSrc.top;
  398. this.right = rcSrc.right;
  399. this.bottom = rcSrc.bottom;
  400. }
  401. /// <summary> Win32 </summary>
  402. public bool IsEmpty
  403. {
  404. get
  405. {
  406. // BUGBUG : On Bidi OS (hebrew arabic) left > right
  407. return left >= right || top >= bottom;
  408. }
  409. }
  410. /// <summary> Return a user friendly representation of this struct </summary>
  411. public override string ToString()
  412. {
  413. if (this == RECT.Empty) { return "RECT {Empty}"; }
  414. return "RECT { left : " + left + " / top : " + top + " / right : " + right + " / bottom : " + bottom + " }";
  415. }
  416. /// <summary> Determine if 2 RECT are equal (deep compare) </summary>
  417. public override bool Equals(object obj)
  418. {
  419. if (!(obj is Rect)) { return false; }
  420. return (this == (RECT)obj);
  421. }
  422. /// <summary>Return the HashCode for this struct (not garanteed to be unique)</summary>
  423. public override int GetHashCode()
  424. {
  425. return left.GetHashCode() + top.GetHashCode() + right.GetHashCode() + bottom.GetHashCode();
  426. }
  427. /// <summary> Determine if 2 RECT are equal (deep compare)</summary>
  428. public static bool operator ==(RECT rect1, RECT rect2)
  429. {
  430. return (rect1.left == rect2.left && rect1.top == rect2.top && rect1.right == rect2.right && rect1.bottom == rect2.bottom);
  431. }
  432. /// <summary> Determine if 2 RECT are different(deep compare)</summary>
  433. public static bool operator !=(RECT rect1, RECT rect2)
  434. {
  435. return !(rect1 == rect2);
  436. }
  437. }
  438. [DllImport("user32")]
  439. internal static extern bool GetMonitorInfo(IntPtr hMonitor, MONITORINFO lpmi);
  440. /// <summary>
  441. ///
  442. /// </summary>
  443. [DllImport("User32")]
  444. internal static extern IntPtr MonitorFromWindow(IntPtr handle, int flags);
  445. #endregion
  446. }
  447. }