ProcessControl.xaml.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353
  1. using Aitex.Core.RT.Fsm;
  2. using Aitex.Core.Util;
  3. using MECF.Framework.Common.CommonData;
  4. using MECF.Framework.Common.DataCenter;
  5. using MECF.Framework.Common.Equipment;
  6. using MECF.Framework.Common.Layout;
  7. using MECF.Framework.Common.ProcessCell;
  8. using MECF.Framework.Common.Reservior;
  9. using MECF.Framework.Common.Utilities;
  10. using PunkHPX8_Core;
  11. using System;
  12. using System.Collections;
  13. using System.Collections.Concurrent;
  14. using System.Collections.Generic;
  15. using System.Linq;
  16. using System.Reflection;
  17. using System.Text;
  18. using System.Threading.Tasks;
  19. using System.Timers;
  20. using System.Windows;
  21. using System.Windows.Controls;
  22. using System.Windows.Data;
  23. using System.Windows.Documents;
  24. using System.Windows.Input;
  25. using System.Windows.Media;
  26. using System.Windows.Media.Imaging;
  27. using System.Windows.Navigation;
  28. using System.Windows.Shapes;
  29. using System.Windows.Threading;
  30. using System.Runtime.InteropServices;
  31. namespace PunkHPX8_Themes.UserControls
  32. {
  33. /// <summary>
  34. /// ProcessControl.xaml 的交互逻辑
  35. /// </summary>
  36. public partial class ProcessControl : UserControl
  37. {
  38. #region 常量
  39. private const int RESERVIOR_MARGIN_LEFT = 10;
  40. #endregion
  41. public ProcessControl()
  42. {
  43. InitializeComponent();
  44. }
  45. public static readonly DependencyProperty ControlLoadProperty = DependencyProperty.Register("ControlLoad", typeof(bool), typeof(ProcessControl),
  46. new PropertyMetadata(false));
  47. public bool ControlLoad
  48. {
  49. get { return (bool)this.GetValue(ControlLoadProperty); }
  50. set
  51. {
  52. this.SetValue(ControlLoadProperty, value);
  53. }
  54. }
  55. public static readonly DependencyProperty LoaderTransoprterWaferHolderVisibleProperty = DependencyProperty.Register("LoaderTransoprterWaferHolderVisible", typeof(bool), typeof(ProcessControl),
  56. new PropertyMetadata(false));
  57. public bool LoaderTransoprterWaferHolderVisible
  58. {
  59. get { return (bool)this.GetValue(LoaderTransoprterWaferHolderVisibleProperty); }
  60. set
  61. {
  62. this.SetValue(LoaderTransoprterWaferHolderVisibleProperty, value);
  63. }
  64. }
  65. public static readonly DependencyProperty LoaderGantryPositionProperty = DependencyProperty.Register("LoaderGantryPosition", typeof(double), typeof(ProcessControl));
  66. public double LoaderGantryPosition
  67. {
  68. get { return (double)this.GetValue(LoaderGantryPositionProperty); }
  69. set
  70. {
  71. this.SetValue(LoaderGantryPositionProperty, value);
  72. }
  73. }
  74. public static readonly DependencyProperty ProcessGantryPositionProperty = DependencyProperty.Register("ProcessGantryPosition", typeof(double), typeof(ProcessControl),new PropertyMetadata((double)1725));
  75. public double ProcessGantryPosition
  76. {
  77. get { return (double)this.GetValue(ProcessGantryPositionProperty); }
  78. set
  79. {
  80. this.SetValue(ProcessGantryPositionProperty, value);
  81. }
  82. }
  83. public static readonly DependencyProperty LoaderVerticalPositionProperty = DependencyProperty.Register("LoaderVerticalPosition", typeof(double), typeof(ProcessControl), new PropertyMetadata((double)100));
  84. public double LoaderVerticalPosition
  85. {
  86. get { return (double)this.GetValue(LoaderVerticalPositionProperty); }
  87. set
  88. {
  89. this.SetValue(LoaderVerticalPositionProperty, value);
  90. }
  91. }
  92. public static readonly DependencyProperty ProcessVerticalPositionProperty = DependencyProperty.Register("ProcessVerticalPosition", typeof(double), typeof(ProcessControl), new PropertyMetadata((double)100));
  93. public double ProcessVerticalPosition
  94. {
  95. get { return (double)this.GetValue(ProcessVerticalPositionProperty); }
  96. set
  97. {
  98. this.SetValue(ProcessVerticalPositionProperty, value);
  99. }
  100. }
  101. public static readonly DependencyProperty ProcessTransoprterWaferHolderVisibleProperty = DependencyProperty.Register("ProcessTransoprterWaferHolderVisible", typeof(bool), typeof(ProcessControl),
  102. new PropertyMetadata(true));
  103. public bool ProcessTransoprterWaferHolderVisible
  104. {
  105. get { return (bool)this.GetValue(ProcessTransoprterWaferHolderVisibleProperty); }
  106. set
  107. {
  108. this.SetValue(ProcessTransoprterWaferHolderVisibleProperty, value);
  109. }
  110. }
  111. public static readonly DependencyProperty LoaderTransoprterWaferHolderEnableProperty = DependencyProperty.Register("LoaderTransoprterWaferHolderEnable", typeof(bool), typeof(ProcessControl),
  112. new PropertyMetadata(true));
  113. public bool LoaderTransoprterWaferHolderEnable
  114. {
  115. get { return (bool)this.GetValue(LoaderTransoprterWaferHolderEnableProperty); }
  116. set
  117. {
  118. this.SetValue(LoaderTransoprterWaferHolderEnableProperty, value);
  119. }
  120. }
  121. public static readonly DependencyProperty ProcessTransoprterWaferHolderEnableProperty = DependencyProperty.Register("ProcessTransoprterWaferHolderEnable", typeof(bool), typeof(ProcessControl),
  122. new PropertyMetadata(false));
  123. public bool ProcessTransoprterWaferHolderEnable
  124. {
  125. get { return (bool)this.GetValue(ProcessTransoprterWaferHolderEnableProperty); }
  126. set
  127. {
  128. this.SetValue(ProcessTransoprterWaferHolderEnableProperty, value);
  129. }
  130. }
  131. private ConcurrentDictionary<string, bool> _cellWaferHolderDictionary=new ConcurrentDictionary<string, bool>();
  132. /// <summary>
  133. /// RT查询data集合
  134. /// </summary>
  135. private Dictionary<string, object> _rtDataValues;
  136. /// <summary>
  137. /// RT查询key集合
  138. /// </summary>
  139. private List<string> _rtDataKeys = new List<string>();
  140. /// <summary>
  141. /// layout对象
  142. /// </summary>
  143. private ProcessLayout _processLayout;
  144. /// <summary>
  145. /// Reservoir-Metals
  146. /// </summary>
  147. private SerializableDictionary<string, List<string>> _reservoirMetals;
  148. /// <summary>
  149. /// 定时器
  150. /// </summary>
  151. DispatcherTimer _timer = null;
  152. /// <summary>
  153. /// 可见变化事件
  154. /// </summary>
  155. /// <param name="sender"></param>
  156. /// <param name="e"></param>
  157. private void UserControl_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
  158. {
  159. if(!ControlLoad)
  160. {
  161. return;
  162. }
  163. if (e.NewValue != null)
  164. {
  165. bool isShow = (bool)e.NewValue;
  166. if (isShow)
  167. {
  168. LoadCells();
  169. if (_timer == null)
  170. {
  171. _timer = new DispatcherTimer();
  172. _timer.Interval = TimeSpan.FromSeconds(0.2);
  173. _timer.Tick += Timer_Tick;
  174. }
  175. InitialKeys();
  176. _timer.Start();
  177. }
  178. else
  179. {
  180. if (_timer != null)
  181. {
  182. _timer.Stop();
  183. _timer.IsEnabled = false;
  184. _timer = null;
  185. }
  186. }
  187. }
  188. }
  189. private void LoadCells()
  190. {
  191. _rtDataKeys.Clear();
  192. _rtDataKeys.Add("System.Layout");
  193. _rtDataKeys.Add("System.ReservoirMetals");
  194. _rtDataValues = QueryDataClient.Instance.Service.PollData(_rtDataKeys);
  195. if (_rtDataValues != null)
  196. {
  197. _processLayout = CommonFunction.GetValue<ProcessLayout>(_rtDataValues, "System.Layout");
  198. _reservoirMetals = CommonFunction.GetValue<SerializableDictionary<string, List<string>>>(_rtDataValues, "System.ReservoirMetals");
  199. if (_processLayout != null && _processLayout.Items.Count != 0)
  200. {
  201. totalCanvas.Children.Clear();
  202. foreach (ProcessLayoutCellItem item in _processLayout.Items)
  203. {
  204. if (string.IsNullOrEmpty(item.ModuleName))
  205. {
  206. continue;
  207. }
  208. if (item.Type == "Cell")
  209. {
  210. AddCellControl(item);
  211. }
  212. else if (item.Type == "Buffer")
  213. {
  214. }
  215. }
  216. }
  217. if (_reservoirMetals != null && _reservoirMetals.Keys.Count != 0)
  218. {
  219. foreach(string item in _reservoirMetals.Keys)
  220. {
  221. ReserviorControl reserviorControl = new ReserviorControl();
  222. reserviorControl.ReserviorName = item;
  223. var maxmin = GetReserviorWidth(_reservoirMetals[item]);
  224. reserviorControl.ReserviorInfo = GenerateReserviorInfo($"Res{item.Substring(item.Length - 1, 1)}", maxmin.max - maxmin.min + 2 * RESERVIOR_MARGIN_LEFT);
  225. Canvas.SetLeft(reserviorControl, maxmin.min - RESERVIOR_MARGIN_LEFT);
  226. Canvas.SetTop(reserviorControl, maxmin.minTop);
  227. Canvas.SetZIndex(reserviorControl, -1);
  228. totalCanvas.Children.Add(reserviorControl);
  229. }
  230. }
  231. }
  232. }
  233. /// <summary>
  234. /// 初始化Keys
  235. /// </summary>
  236. private void InitialKeys()
  237. {
  238. _rtDataKeys.Clear();
  239. _rtDataKeys.Add("System.CellWaferHolderDictionary");
  240. foreach (ProcessLayoutCellItem item in _processLayout.Items)
  241. {
  242. if (item.Type == "Cell"&&!string.IsNullOrEmpty(item.ModuleName))
  243. {
  244. _rtDataKeys.Add($"{item.ModuleName}.IsInit");
  245. _rtDataKeys.Add($"{item.ModuleName}.IsIdle");
  246. _rtDataKeys.Add($"{item.ModuleName}.IsError");
  247. _rtDataKeys.Add($"{item.ModuleName}.IsBusy");
  248. _rtDataKeys.Add($"{item.ModuleName}.IsDisable");
  249. }
  250. }
  251. foreach(string key in _reservoirMetals.Keys)
  252. {
  253. _rtDataKeys.Add($"{key}.IsInit");
  254. _rtDataKeys.Add($"{key}.IsIdle");
  255. _rtDataKeys.Add($"{key}.IsError");
  256. _rtDataKeys.Add($"{key}.IsBusy");
  257. _rtDataKeys.Add($"{key}.IsDisable");
  258. }
  259. }
  260. /// <summary>
  261. /// 获取Reservior属性信息
  262. /// </summary>
  263. /// <param name="item"></param>
  264. /// <param name="width"></param>
  265. /// <returns></returns>
  266. private ReserviorInfo GenerateReserviorInfo(string item,int width)
  267. {
  268. ReserviorInfo info = new ReserviorInfo();
  269. info.Name = item;
  270. info.Width = width;
  271. info.Cells = new List<ProcessCellInfo>();
  272. return info;
  273. }
  274. /// <summary>
  275. /// 定时器执行
  276. /// </summary>
  277. /// <param name="sender"></param>
  278. /// <param name="e"></param>
  279. private void Timer_Tick(object sender, EventArgs e)
  280. {
  281. if (_rtDataKeys.Count != 0)
  282. {
  283. _rtDataValues = QueryDataClient.Instance.Service.PollData(_rtDataKeys);
  284. if (_rtDataValues != null)
  285. {
  286. _cellWaferHolderDictionary = CommonFunction.GetValue<ConcurrentDictionary<string, bool>>(_rtDataValues, "System.CellWaferHolderDictionary");
  287. //判断Chanmber状态
  288. foreach (DependencyObject child in totalCanvas.Children)
  289. {
  290. if (child is ReserviorControl)
  291. {
  292. ReserviorControl reservior = child as ReserviorControl;
  293. }
  294. }
  295. }
  296. }
  297. }
  298. /// <summary>
  299. /// 增加Cell元素
  300. /// </summary>
  301. /// <param name="item"></param>
  302. private void AddCellControl(ProcessLayoutCellItem item)
  303. {
  304. }
  305. /// <summary>
  306. /// 获取Reservior宽度
  307. /// </summary>
  308. /// <param name="item"></param>
  309. /// <returns></returns>
  310. private (int max,int min,int minTop) GetReserviorWidth(List<string> metals)
  311. {
  312. int min = int.MaxValue;
  313. int max = 0;
  314. int minTop = int.MaxValue;
  315. foreach (ProcessLayoutCellItem subitem in _processLayout.Items)
  316. {
  317. if (metals.Contains(subitem.ModuleName))
  318. {
  319. if (subitem.Left < min)
  320. {
  321. min = subitem.Left;
  322. }
  323. if (subitem.Left + subitem.Width > max)
  324. {
  325. max = subitem.Left + subitem.Width;
  326. }
  327. if (subitem.Top < min)
  328. {
  329. minTop = subitem.Top;
  330. }
  331. }
  332. }
  333. return (max,min,minTop);
  334. }
  335. }
  336. }