Slot.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416
  1. using OpenSEMI.Ctrlib.Types;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using System.Windows;
  8. using System.Windows.Controls;
  9. using System.Windows.Data;
  10. using System.Windows.Documents;
  11. using System.Windows.Input;
  12. using System.Windows.Media;
  13. using System.Windows.Media.Imaging;
  14. using System.Windows.Navigation;
  15. using System.Windows.Shapes;
  16. namespace OpenSEMI.Ctrlib.Controls
  17. {
  18. public delegate void DragDropHandler(object sender, DragDropEventArgs e);
  19. public class DragDropEventArgs : EventArgs
  20. {
  21. public Slot TranferFrom { get; set; }
  22. public Slot TranferTo { get; set; }
  23. public DragDropEventArgs(Slot p_TranferFrom, Slot p_TranferTo)
  24. {
  25. this.TranferFrom = p_TranferFrom;
  26. this.TranferTo = p_TranferTo;
  27. }
  28. }
  29. [Flags]
  30. public enum SlotBorderStatus
  31. {
  32. MouseOver = 1,
  33. TransferSource = 2,
  34. TransferTarget = 4,
  35. Selected = 8,
  36. None = 16
  37. }
  38. public class Slot : ContentControl
  39. {
  40. public event MouseButtonEventHandler SlotMouseButtonDown;
  41. public event DragDropHandler WaferTransferStarted;
  42. static Slot()
  43. {
  44. DefaultStyleKeyProperty.OverrideMetadata(typeof(Slot), new FrameworkPropertyMetadata(typeof(Slot)));
  45. }
  46. public bool IsDraggable { get; set; }
  47. public bool IsLeftMouseDown { get; set; } //confirm drag source is current slot
  48. public string ViewType
  49. {
  50. get { return (string)GetValue(ViewTypeProperty); }
  51. set { SetValue(ViewTypeProperty, value); }
  52. }
  53. public static readonly DependencyProperty ViewTypeProperty =
  54. DependencyProperty.Register("ViewType", typeof(string), typeof(Slot),
  55. new UIPropertyMetadata("Front"));
  56. public int WaferStatus
  57. {
  58. get { return (int)GetValue(WaferStatusProperty); }
  59. set { SetValue(WaferStatusProperty, value); }
  60. }
  61. public static readonly DependencyProperty WaferStatusProperty =
  62. DependencyProperty.Register("WaferStatus", typeof(int), typeof(Slot),
  63. new UIPropertyMetadata(0, new PropertyChangedCallback(WaferStatusChangedCallBack)));
  64. public int SlotID
  65. {
  66. get { return (int)GetValue(SlotIDProperty); }
  67. set { SetValue(SlotIDProperty, value); }
  68. }
  69. public static readonly DependencyProperty SlotIDProperty =
  70. DependencyProperty.Register("SlotID", typeof(int), typeof(Slot), new UIPropertyMetadata(-1));
  71. public string ModuleID
  72. {
  73. get { return (string)GetValue(ModuleIDProperty); }
  74. set { SetValue(ModuleIDProperty, value); }
  75. }
  76. public static readonly DependencyProperty ModuleIDProperty =
  77. DependencyProperty.Register("ModuleID", typeof(string), typeof(Slot), new UIPropertyMetadata(string.Empty));
  78. public bool IsDragSource
  79. {
  80. get { return (bool)GetValue(IsDragSourceProperty); }
  81. set { SetValue(IsDragSourceProperty, value); }
  82. }
  83. public static readonly DependencyProperty IsDragSourceProperty =
  84. DependencyProperty.Register("IsDragSource", typeof(bool), typeof(Slot),
  85. new UIPropertyMetadata(false, new PropertyChangedCallback(IsDragSourcePropertyChangedCallBack)));
  86. public bool IsDropTarget
  87. {
  88. get { return (bool)GetValue(IsDropTargetProperty); }
  89. set { SetValue(IsDropTargetProperty, value); }
  90. }
  91. public static readonly DependencyProperty IsDropTargetProperty =
  92. DependencyProperty.Register("IsDropTarget", typeof(bool), typeof(Slot),
  93. new UIPropertyMetadata(false, new PropertyChangedCallback(IsDropTargetPropertyChangedCallBack)));
  94. public bool IsDragEnter
  95. {
  96. get { return (bool)GetValue(IsDragEnterProperty); }
  97. set { SetValue(IsDragEnterProperty, value); }
  98. }
  99. public static readonly DependencyProperty IsDragEnterProperty =
  100. DependencyProperty.Register("IsDragEnter", typeof(bool), typeof(Slot),
  101. new UIPropertyMetadata(false, new PropertyChangedCallback(IsDragEnterPropertyChangedCallBack)));
  102. public bool IsSelected
  103. {
  104. get { return (bool)GetValue(IsSelectedProperty); }
  105. set { SetValue(IsSelectedProperty, value); }
  106. }
  107. public static readonly DependencyProperty IsSelectedProperty =
  108. DependencyProperty.Register("IsSelected", typeof(bool), typeof(Slot),
  109. new UIPropertyMetadata(false, new PropertyChangedCallback(IsSelectedPropertyChangedCallBack)));
  110. public bool HasWafer
  111. {
  112. get { return (bool)GetValue(HasWaferProperty); }
  113. set { SetValue(HasWaferProperty, value); }
  114. }
  115. public static readonly DependencyProperty HasWaferProperty =
  116. DependencyProperty.Register("HasWafer", typeof(bool), typeof(Slot),
  117. new UIPropertyMetadata(false, HasWaferChanged));
  118. public SlotBorderStatus BorderStatus
  119. {
  120. get { return (SlotBorderStatus)GetValue(BorderStatusProperty); }
  121. set { SetValue(BorderStatusProperty, value); }
  122. }
  123. public static readonly DependencyProperty BorderStatusProperty =
  124. DependencyProperty.Register("BorderStatus", typeof(SlotBorderStatus), typeof(Slot),
  125. new UIPropertyMetadata(SlotBorderStatus.None));
  126. public string SourceName
  127. {
  128. get { return (string)GetValue(SourceNameProperty); }
  129. set { SetValue(SourceNameProperty, value); }
  130. }
  131. public static readonly DependencyProperty SourceNameProperty =
  132. DependencyProperty.Register("SourceName", typeof(string), typeof(Slot), new UIPropertyMetadata(string.Empty));
  133. public bool CanDragDrop
  134. {
  135. get { return (bool)GetValue(CanDragDropProperty); }
  136. set { SetValue(CanDragDropProperty, value); }
  137. }
  138. public static readonly DependencyProperty CanDragDropProperty =
  139. DependencyProperty.Register("CanDragDrop", typeof(bool), typeof(Slot), new UIPropertyMetadata(true, new PropertyChangedCallback(CanDragDropPropertyChangedCallBack)));
  140. public string WaferTooltip
  141. {
  142. get { return (string)GetValue(WaferTooltipProperty); }
  143. set { SetValue(WaferTooltipProperty, value); }
  144. }
  145. public static readonly DependencyProperty WaferTooltipProperty =
  146. DependencyProperty.Register("WaferTooltip", typeof(string), typeof(Slot), new PropertyMetadata(string.Empty));
  147. public string WaferTooltipExt
  148. {
  149. get { return (string)GetValue(WaferTooltipExtProperty); }
  150. set { SetValue(WaferTooltipExtProperty, value); }
  151. }
  152. public static readonly DependencyProperty WaferTooltipExtProperty =
  153. DependencyProperty.Register("WaferTooltipExt", typeof(string), typeof(Slot), new PropertyMetadata(string.Empty));
  154. public Visibility DuplicatedVisibility
  155. {
  156. get { return (Visibility)GetValue(DuplicatedVisibilityProperty); }
  157. set { SetValue(DuplicatedVisibilityProperty, value); }
  158. }
  159. public static readonly DependencyProperty DuplicatedVisibilityProperty =
  160. DependencyProperty.Register("DuplicatedVisibility", typeof(Visibility), typeof(Slot), new UIPropertyMetadata(Visibility.Collapsed));
  161. public Visibility WaferVisibility
  162. {
  163. get { return (Visibility)GetValue(WaferVisibilityProperty); }
  164. set { SetValue(WaferVisibilityProperty, value); }
  165. }
  166. public static readonly DependencyProperty WaferVisibilityProperty =
  167. DependencyProperty.Register("WaferVisibility", typeof(Visibility), typeof(Slot), new UIPropertyMetadata(Visibility.Visible));
  168. public Visibility WaferSamllVisibility
  169. {
  170. get { return (Visibility)GetValue(WaferSamllVisibilityProperty); }
  171. set { SetValue(WaferSamllVisibilityProperty, value); }
  172. }
  173. public static readonly DependencyProperty WaferSamllVisibilityProperty =
  174. DependencyProperty.Register("WaferSamllVisibility", typeof(Visibility), typeof(Slot), new UIPropertyMetadata(Visibility.Collapsed));
  175. public override void OnApplyTemplate()
  176. {
  177. base.OnApplyTemplate();
  178. DragDropStatusControl(this);
  179. }
  180. protected override void OnDragEnter(DragEventArgs e)
  181. {
  182. base.OnDragEnter(e);
  183. this.IsDragEnter = true;
  184. }
  185. protected override void OnDragLeave(DragEventArgs e)
  186. {
  187. base.OnDragLeave(e);
  188. this.IsDragEnter = false;
  189. }
  190. protected override void OnMouseDown(MouseButtonEventArgs e)
  191. {
  192. base.OnMouseDown(e);
  193. if (MouseButtonState.Pressed == e.LeftButton)
  194. IsLeftMouseDown = true;
  195. e.Handled = true;
  196. }
  197. protected override void OnMouseUp(MouseButtonEventArgs e)
  198. {
  199. base.OnMouseUp(e);
  200. IsLeftMouseDown = false;
  201. MouseButtonEventHandler handler = SlotMouseButtonDown;
  202. if (handler != null)
  203. {
  204. handler(this, e);
  205. }
  206. }
  207. protected override void OnMouseEnter(MouseEventArgs e)
  208. {
  209. base.OnMouseEnter(e);
  210. this.BorderStatus = this.BorderStatus | SlotBorderStatus.MouseOver;
  211. }
  212. protected override void OnMouseLeave(MouseEventArgs e)
  213. {
  214. base.OnMouseLeave(e);
  215. IsLeftMouseDown = false;
  216. this.BorderStatus = this.BorderStatus & (~SlotBorderStatus.MouseOver);
  217. }
  218. private static void DragDropStatusControl(Slot p_slot)
  219. {
  220. p_slot.AllowDrop = false;
  221. p_slot.IsDraggable = false;
  222. if (p_slot.CanDragDrop)
  223. {
  224. if (!p_slot.IsDropTarget && p_slot.WaferStatus == 0)
  225. p_slot.AllowDrop = true;
  226. if (!p_slot.IsDragSource && p_slot.WaferStatus != 0)
  227. p_slot.IsDraggable = true;
  228. }
  229. }
  230. private static void IsDropTargetPropertyChangedCallBack(DependencyObject d, DependencyPropertyChangedEventArgs args)
  231. {
  232. Slot m_slot = d as Slot;
  233. if (m_slot.IsDropTarget)
  234. m_slot.BorderStatus = m_slot.BorderStatus | SlotBorderStatus.TransferTarget; //add
  235. else
  236. m_slot.BorderStatus = m_slot.BorderStatus & (~SlotBorderStatus.TransferTarget); //remove
  237. DragDropStatusControl(m_slot);
  238. }
  239. private static void IsDragSourcePropertyChangedCallBack(DependencyObject d, DependencyPropertyChangedEventArgs args)
  240. {
  241. Slot m_slot = d as Slot;
  242. if (m_slot.IsDragSource)
  243. m_slot.BorderStatus = m_slot.BorderStatus | SlotBorderStatus.TransferSource; //add
  244. else
  245. m_slot.BorderStatus = m_slot.BorderStatus & (~SlotBorderStatus.TransferSource); //remove
  246. DragDropStatusControl(m_slot);
  247. }
  248. private static void IsSelectedPropertyChangedCallBack(DependencyObject d, DependencyPropertyChangedEventArgs args)
  249. {
  250. Slot m_slot = d as Slot;
  251. if (m_slot.IsSelected)
  252. m_slot.BorderStatus = m_slot.BorderStatus | SlotBorderStatus.Selected; //add
  253. else
  254. m_slot.BorderStatus = m_slot.BorderStatus & (~SlotBorderStatus.Selected); //remove
  255. }
  256. private static void CanDragDropPropertyChangedCallBack(DependencyObject d, DependencyPropertyChangedEventArgs args)
  257. {
  258. Slot m_slot = d as Slot;
  259. DragDropStatusControl(m_slot);
  260. }
  261. private static void IsDragEnterPropertyChangedCallBack(DependencyObject d, DependencyPropertyChangedEventArgs args)
  262. {
  263. Slot m_slot = d as Slot;
  264. if (m_slot.IsDragEnter)
  265. m_slot.BorderStatus = m_slot.BorderStatus | SlotBorderStatus.TransferTarget; //add
  266. else
  267. m_slot.BorderStatus = m_slot.BorderStatus & (~SlotBorderStatus.TransferTarget); //remove
  268. }
  269. private static void WaferStatusChangedCallBack(DependencyObject d, DependencyPropertyChangedEventArgs args)
  270. {
  271. Slot m_slot = d as Slot;
  272. m_slot.IsDragSource = false;
  273. m_slot.IsDropTarget = false;
  274. m_slot.IsDragEnter = false;
  275. DragDropStatusControl(m_slot);
  276. }
  277. public static void HasWaferChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
  278. {
  279. Slot m_slot = d as Slot;
  280. if (m_slot != null)
  281. {
  282. if (m_slot.HasWafer)
  283. m_slot.WaferStatus = 7;
  284. else
  285. m_slot.WaferStatus = 0;
  286. }
  287. }
  288. protected override void OnPreviewMouseMove(MouseEventArgs e)
  289. {
  290. base.OnPreviewMouseMove(e);
  291. if (e.LeftButton == MouseButtonState.Pressed && IsDraggable && IsLeftMouseDown)
  292. {
  293. DataObject data = new DataObject(typeof(Slot), this);
  294. DragDrop.DoDragDrop(this, data, DragDropEffects.Move);
  295. }
  296. }
  297. protected override void OnDrop(DragEventArgs e)
  298. {
  299. if (this.AllowDrop)
  300. {
  301. try
  302. {
  303. IDataObject data = e.Data;
  304. if (data.GetDataPresent(typeof(Slot)))
  305. {
  306. Slot m_dragSource = (Slot)data.GetData(typeof(Slot));
  307. m_dragSource.IsDragSource = true; //source
  308. this.IsDropTarget = true; //target
  309. if (WaferTransferStarted != null)
  310. {
  311. DragDropEventArgs m_arg = new DragDropEventArgs(m_dragSource, this);
  312. WaferTransferStarted(this, m_arg);
  313. }
  314. }
  315. else //to support another type of wafer
  316. {
  317. //var sourceWafer = (WaferInfo)e.Data.GetData("Object");
  318. var sourceStation = e.Data.GetData("Station").ToString();
  319. var sourceSlot = (int)e.Data.GetData("Slot");
  320. Slot m_dragSource = new Slot() { ModuleID = sourceStation, SlotID = sourceSlot };
  321. if (WaferTransferStarted != null)
  322. {
  323. DragDropEventArgs m_arg = new DragDropEventArgs(m_dragSource, this);
  324. WaferTransferStarted(this, m_arg);
  325. }
  326. }
  327. }
  328. catch
  329. {
  330. }
  331. }
  332. }
  333. public bool IsValidSlot()
  334. {
  335. if (this.ModuleID.Length >0 && this.SlotID >= 0)
  336. return true;
  337. else
  338. return false;
  339. }
  340. public bool IsSameSlot(Slot slot)
  341. {
  342. if (slot.IsValidSlot() && this.IsValidSlot())
  343. {
  344. if (this.ModuleID == slot.ModuleID && this.SlotID == slot.SlotID)
  345. return true;
  346. }
  347. return false;
  348. }
  349. public void ClearDragDropStatus()
  350. {
  351. this.IsDragEnter = false;
  352. this.IsDragSource = false;
  353. this.IsDropTarget = false;
  354. }
  355. }
  356. }