Slot.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510
  1. using System.Windows;
  2. using System.Windows.Controls;
  3. using System.Windows.Input;
  4. namespace OpenSEMI.Ctrlib.Controls
  5. {
  6. public class Slot : ContentControl
  7. {
  8. public static readonly DependencyProperty ViewTypeProperty;
  9. public static readonly DependencyProperty WaferStatusProperty;
  10. public static readonly DependencyProperty SlotIDProperty;
  11. public static readonly DependencyProperty ModuleIDProperty;
  12. public static readonly DependencyProperty IsDragSourceProperty;
  13. public static readonly DependencyProperty IsDropTargetProperty;
  14. public static readonly DependencyProperty IsDragEnterProperty;
  15. public static readonly DependencyProperty IsSelectedProperty;
  16. public static readonly DependencyProperty HasWaferProperty;
  17. public static readonly DependencyProperty BorderStatusProperty;
  18. public static readonly DependencyProperty SourceNameProperty;
  19. public static readonly DependencyProperty CanDragDropProperty;
  20. public static readonly DependencyProperty WaferTooltipProperty;
  21. public static readonly DependencyProperty WaferTooltipExtProperty;
  22. public static readonly DependencyProperty SeasoningWaferTypeProperty;
  23. public static readonly DependencyProperty DuplicatedVisibilityProperty;
  24. public static readonly DependencyProperty SlotWidthProperty;
  25. public bool IsDraggable
  26. {
  27. get;
  28. set;
  29. }
  30. public bool IsLeftMouseDown
  31. {
  32. get;
  33. set;
  34. }
  35. public string ViewType
  36. {
  37. get
  38. {
  39. return (string)GetValue(ViewTypeProperty);
  40. }
  41. set
  42. {
  43. SetValue(ViewTypeProperty, value);
  44. }
  45. }
  46. public int WaferStatus
  47. {
  48. get
  49. {
  50. return (int)GetValue(WaferStatusProperty);
  51. }
  52. set
  53. {
  54. SetValue(WaferStatusProperty, value);
  55. }
  56. }
  57. public int SlotID
  58. {
  59. get
  60. {
  61. return (int)GetValue(SlotIDProperty);
  62. }
  63. set
  64. {
  65. SetValue(SlotIDProperty, value);
  66. }
  67. }
  68. public string ModuleID
  69. {
  70. get
  71. {
  72. return (string)GetValue(ModuleIDProperty);
  73. }
  74. set
  75. {
  76. SetValue(ModuleIDProperty, value);
  77. }
  78. }
  79. public bool IsDragSource
  80. {
  81. get
  82. {
  83. return (bool)GetValue(IsDragSourceProperty);
  84. }
  85. set
  86. {
  87. SetValue(IsDragSourceProperty, value);
  88. }
  89. }
  90. public bool IsDropTarget
  91. {
  92. get
  93. {
  94. return (bool)GetValue(IsDropTargetProperty);
  95. }
  96. set
  97. {
  98. SetValue(IsDropTargetProperty, value);
  99. }
  100. }
  101. public bool IsDragEnter
  102. {
  103. get
  104. {
  105. return (bool)GetValue(IsDragEnterProperty);
  106. }
  107. set
  108. {
  109. SetValue(IsDragEnterProperty, value);
  110. }
  111. }
  112. public bool IsSelected
  113. {
  114. get
  115. {
  116. return (bool)GetValue(IsSelectedProperty);
  117. }
  118. set
  119. {
  120. SetValue(IsSelectedProperty, value);
  121. }
  122. }
  123. public bool HasWafer
  124. {
  125. get
  126. {
  127. return (bool)GetValue(HasWaferProperty);
  128. }
  129. set
  130. {
  131. SetValue(HasWaferProperty, value);
  132. }
  133. }
  134. public SlotBorderStatus BorderStatus
  135. {
  136. get
  137. {
  138. return (SlotBorderStatus)GetValue(BorderStatusProperty);
  139. }
  140. set
  141. {
  142. SetValue(BorderStatusProperty, value);
  143. }
  144. }
  145. public string SourceName
  146. {
  147. get
  148. {
  149. return (string)GetValue(SourceNameProperty);
  150. }
  151. set
  152. {
  153. SetValue(SourceNameProperty, value);
  154. }
  155. }
  156. public bool CanDragDrop
  157. {
  158. get
  159. {
  160. return (bool)GetValue(CanDragDropProperty);
  161. }
  162. set
  163. {
  164. SetValue(CanDragDropProperty, value);
  165. }
  166. }
  167. public string WaferTooltip
  168. {
  169. get
  170. {
  171. return (string)GetValue(WaferTooltipProperty);
  172. }
  173. set
  174. {
  175. SetValue(WaferTooltipProperty, value);
  176. }
  177. }
  178. public string WaferTooltipExt
  179. {
  180. get
  181. {
  182. return (string)GetValue(WaferTooltipExtProperty);
  183. }
  184. set
  185. {
  186. SetValue(WaferTooltipExtProperty, value);
  187. }
  188. }
  189. public string SeasoningWaferType
  190. {
  191. get
  192. {
  193. return (string)GetValue(SeasoningWaferTypeProperty);
  194. }
  195. set
  196. {
  197. SetValue(SeasoningWaferTypeProperty, value);
  198. }
  199. }
  200. public Visibility DuplicatedVisibility
  201. {
  202. get
  203. {
  204. return (Visibility)GetValue(DuplicatedVisibilityProperty);
  205. }
  206. set
  207. {
  208. SetValue(DuplicatedVisibilityProperty, value);
  209. }
  210. }
  211. public int SlotWidth
  212. {
  213. get
  214. {
  215. return (int)GetValue(SlotWidthProperty);
  216. }
  217. set
  218. {
  219. SetValue(SlotWidthProperty, value);
  220. }
  221. }
  222. public event MouseButtonEventHandler SlotMouseButtonDown;
  223. public event DragDropHandler WaferTransferStarted;
  224. static Slot()
  225. {
  226. ViewTypeProperty = DependencyProperty.Register("ViewType", typeof(string), typeof(Slot), new UIPropertyMetadata("Front"));
  227. WaferStatusProperty = DependencyProperty.Register("WaferStatus", typeof(int), typeof(Slot), new UIPropertyMetadata(0, WaferStatusChangedCallBack));
  228. SlotIDProperty = DependencyProperty.Register("SlotID", typeof(int), typeof(Slot), new UIPropertyMetadata(-1));
  229. ModuleIDProperty = DependencyProperty.Register("ModuleID", typeof(string), typeof(Slot), new UIPropertyMetadata(string.Empty));
  230. IsDragSourceProperty = DependencyProperty.Register("IsDragSource", typeof(bool), typeof(Slot), new UIPropertyMetadata(false, IsDragSourcePropertyChangedCallBack));
  231. IsDropTargetProperty = DependencyProperty.Register("IsDropTarget", typeof(bool), typeof(Slot), new UIPropertyMetadata(false, IsDropTargetPropertyChangedCallBack));
  232. IsDragEnterProperty = DependencyProperty.Register("IsDragEnter", typeof(bool), typeof(Slot), new UIPropertyMetadata(false, IsDragEnterPropertyChangedCallBack));
  233. IsSelectedProperty = DependencyProperty.Register("IsSelected", typeof(bool), typeof(Slot), new UIPropertyMetadata(false, IsSelectedPropertyChangedCallBack));
  234. HasWaferProperty = DependencyProperty.Register("HasWafer", typeof(bool), typeof(Slot), new UIPropertyMetadata(false, HasWaferChanged));
  235. BorderStatusProperty = DependencyProperty.Register("BorderStatus", typeof(SlotBorderStatus), typeof(Slot), new UIPropertyMetadata(SlotBorderStatus.None));
  236. SourceNameProperty = DependencyProperty.Register("SourceName", typeof(string), typeof(Slot), new UIPropertyMetadata(string.Empty));
  237. CanDragDropProperty = DependencyProperty.Register("CanDragDrop", typeof(bool), typeof(Slot), new UIPropertyMetadata(true, CanDragDropPropertyChangedCallBack));
  238. WaferTooltipProperty = DependencyProperty.Register("WaferTooltip", typeof(string), typeof(Slot), new PropertyMetadata(string.Empty));
  239. WaferTooltipExtProperty = DependencyProperty.Register("WaferTooltipExt", typeof(string), typeof(Slot), new PropertyMetadata(string.Empty));
  240. SeasoningWaferTypeProperty = DependencyProperty.Register("SeasoningWaferType", typeof(string), typeof(Slot), new PropertyMetadata(string.Empty));
  241. DuplicatedVisibilityProperty = DependencyProperty.Register("DuplicatedVisibility", typeof(Visibility), typeof(Slot), new UIPropertyMetadata(Visibility.Collapsed));
  242. SlotWidthProperty = DependencyProperty.Register("SlotWidth", typeof(int), typeof(Slot), new UIPropertyMetadata(90));
  243. FrameworkElement.DefaultStyleKeyProperty.OverrideMetadata(typeof(Slot), new FrameworkPropertyMetadata(typeof(Slot)));
  244. }
  245. public override void OnApplyTemplate()
  246. {
  247. base.OnApplyTemplate();
  248. DragDropStatusControl(this);
  249. }
  250. protected override void OnDragEnter(DragEventArgs e)
  251. {
  252. base.OnDragEnter(e);
  253. IsDragEnter = true;
  254. }
  255. protected override void OnDragLeave(DragEventArgs e)
  256. {
  257. base.OnDragLeave(e);
  258. IsDragEnter = false;
  259. }
  260. protected override void OnMouseDown(MouseButtonEventArgs e)
  261. {
  262. base.OnMouseDown(e);
  263. if (MouseButtonState.Pressed == e.LeftButton)
  264. {
  265. IsLeftMouseDown = true;
  266. }
  267. e.Handled = true;
  268. }
  269. protected override void OnMouseUp(MouseButtonEventArgs e)
  270. {
  271. base.OnMouseUp(e);
  272. IsLeftMouseDown = false;
  273. this.SlotMouseButtonDown?.Invoke(this, e);
  274. }
  275. protected override void OnMouseEnter(MouseEventArgs e)
  276. {
  277. base.OnMouseEnter(e);
  278. BorderStatus |= SlotBorderStatus.MouseOver;
  279. }
  280. protected override void OnMouseLeave(MouseEventArgs e)
  281. {
  282. base.OnMouseLeave(e);
  283. IsLeftMouseDown = false;
  284. BorderStatus &= ~SlotBorderStatus.MouseOver;
  285. }
  286. private static void DragDropStatusControl(Slot p_slot)
  287. {
  288. p_slot.AllowDrop = false;
  289. p_slot.IsDraggable = false;
  290. if (p_slot.CanDragDrop)
  291. {
  292. if (!p_slot.IsDropTarget && p_slot.WaferStatus == 0)
  293. {
  294. p_slot.AllowDrop = true;
  295. }
  296. if (!p_slot.IsDragSource && p_slot.WaferStatus != 0)
  297. {
  298. p_slot.IsDraggable = true;
  299. }
  300. }
  301. }
  302. private static void IsDropTargetPropertyChangedCallBack(DependencyObject d, DependencyPropertyChangedEventArgs args)
  303. {
  304. Slot slot = d as Slot;
  305. if (slot.IsDropTarget)
  306. {
  307. slot.BorderStatus |= SlotBorderStatus.TransferTarget;
  308. }
  309. else
  310. {
  311. slot.BorderStatus &= ~SlotBorderStatus.TransferTarget;
  312. }
  313. DragDropStatusControl(slot);
  314. }
  315. private static void IsDragSourcePropertyChangedCallBack(DependencyObject d, DependencyPropertyChangedEventArgs args)
  316. {
  317. Slot slot = d as Slot;
  318. if (slot.IsDragSource)
  319. {
  320. slot.BorderStatus |= SlotBorderStatus.TransferSource;
  321. }
  322. else
  323. {
  324. slot.BorderStatus &= ~SlotBorderStatus.TransferSource;
  325. }
  326. DragDropStatusControl(slot);
  327. }
  328. private static void IsSelectedPropertyChangedCallBack(DependencyObject d, DependencyPropertyChangedEventArgs args)
  329. {
  330. Slot slot = d as Slot;
  331. if (slot.IsSelected)
  332. {
  333. slot.BorderStatus |= SlotBorderStatus.Selected;
  334. }
  335. else
  336. {
  337. slot.BorderStatus &= ~SlotBorderStatus.Selected;
  338. }
  339. }
  340. private static void CanDragDropPropertyChangedCallBack(DependencyObject d, DependencyPropertyChangedEventArgs args)
  341. {
  342. Slot p_slot = d as Slot;
  343. DragDropStatusControl(p_slot);
  344. }
  345. private static void IsDragEnterPropertyChangedCallBack(DependencyObject d, DependencyPropertyChangedEventArgs args)
  346. {
  347. Slot slot = d as Slot;
  348. if (slot.IsDragEnter)
  349. {
  350. slot.BorderStatus |= SlotBorderStatus.TransferTarget;
  351. }
  352. else
  353. {
  354. slot.BorderStatus &= ~SlotBorderStatus.TransferTarget;
  355. }
  356. }
  357. private static void WaferStatusChangedCallBack(DependencyObject d, DependencyPropertyChangedEventArgs args)
  358. {
  359. Slot slot = d as Slot;
  360. slot.IsDragSource = false;
  361. slot.IsDropTarget = false;
  362. slot.IsDragEnter = false;
  363. DragDropStatusControl(slot);
  364. }
  365. public static void HasWaferChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
  366. {
  367. Slot slot = d as Slot;
  368. if (slot != null)
  369. {
  370. if (slot.HasWafer)
  371. {
  372. slot.WaferStatus = 7;
  373. }
  374. else
  375. {
  376. slot.WaferStatus = 0;
  377. }
  378. }
  379. }
  380. protected override void OnPreviewMouseMove(MouseEventArgs e)
  381. {
  382. base.OnPreviewMouseMove(e);
  383. if (e.LeftButton == MouseButtonState.Pressed && IsDraggable && IsLeftMouseDown)
  384. {
  385. DataObject data = new DataObject(typeof(Slot), this);
  386. DragDrop.DoDragDrop(this, data, DragDropEffects.Move);
  387. }
  388. }
  389. protected override void OnDrop(DragEventArgs e)
  390. {
  391. if (base.AllowDrop)
  392. {
  393. try
  394. {
  395. IDataObject data = e.Data;
  396. if (data.GetDataPresent(typeof(Slot)))
  397. {
  398. Slot slot = (Slot)data.GetData(typeof(Slot));
  399. slot.IsDragSource = true;
  400. IsDropTarget = true;
  401. if (this.WaferTransferStarted != null)
  402. {
  403. DragDropEventArgs e2 = new DragDropEventArgs(slot, this);
  404. this.WaferTransferStarted(this, e2);
  405. }
  406. }
  407. else
  408. {
  409. string moduleID = e.Data.GetData("Station").ToString();
  410. int slotID = (int)e.Data.GetData("Slot");
  411. Slot p_TranferFrom = new Slot
  412. {
  413. ModuleID = moduleID,
  414. SlotID = slotID
  415. };
  416. if (this.WaferTransferStarted != null)
  417. {
  418. DragDropEventArgs e3 = new DragDropEventArgs(p_TranferFrom, this);
  419. this.WaferTransferStarted(this, e3);
  420. }
  421. }
  422. }
  423. catch
  424. {
  425. }
  426. }
  427. }
  428. public bool IsValidSlot()
  429. {
  430. if (ModuleID.Length > 0 && SlotID >= 0)
  431. {
  432. return true;
  433. }
  434. return false;
  435. }
  436. public bool IsSameSlot(Slot slot)
  437. {
  438. if (slot.IsValidSlot() && IsValidSlot() && ModuleID == slot.ModuleID && SlotID == slot.SlotID)
  439. {
  440. return true;
  441. }
  442. return false;
  443. }
  444. public void ClearDragDropStatus()
  445. {
  446. IsDragEnter = false;
  447. IsDragSource = false;
  448. IsDropTarget = false;
  449. }
  450. }
  451. }