CarrierContentControl.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407
  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 CarrierDragDropHandler(object sender, CarrierDragDropEventArgs e);
  19. public class CarrierDragDropEventArgs : EventArgs
  20. {
  21. public CarrierContentControl TranferFrom { get; set; }
  22. public CarrierContentControl TranferTo { get; set; }
  23. public CarrierDragDropEventArgs(CarrierContentControl p_TranferFrom, CarrierContentControl p_TranferTo)
  24. {
  25. this.TranferFrom = p_TranferFrom;
  26. this.TranferTo = p_TranferTo;
  27. }
  28. }
  29. [Flags]
  30. public enum CarrierBorderStatus
  31. {
  32. MouseOver = 1,
  33. TransferSource = 2,
  34. TransferTarget = 4,
  35. Selected = 8,
  36. None = 16
  37. }
  38. public class CarrierContentControl : ContentControl
  39. {
  40. public event MouseButtonEventHandler StageMouseButtonDown;
  41. public event CarrierDragDropHandler WaferTransferStarted;
  42. static CarrierContentControl()
  43. {
  44. DefaultStyleKeyProperty.OverrideMetadata(typeof(CarrierContentControl), new FrameworkPropertyMetadata(typeof(CarrierContentControl)));
  45. }
  46. public bool IsDraggable { get; set; }
  47. public bool IsLeftMouseDown { get; set; } //confirm drag source is current Stage
  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(CarrierContentControl),
  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(CarrierContentControl),
  63. new UIPropertyMetadata(0, new PropertyChangedCallback(WaferStatusChangedCallBack)));
  64. public int CarrierID
  65. {
  66. get { return (int)GetValue(CarrierIDProperty); }
  67. set { SetValue(CarrierIDProperty, value); }
  68. }
  69. public static readonly DependencyProperty CarrierIDProperty =
  70. DependencyProperty.Register("CarrierID", typeof(int), typeof(CarrierContentControl), 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(CarrierContentControl), 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(CarrierContentControl),
  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(CarrierContentControl),
  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(CarrierContentControl),
  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(CarrierContentControl),
  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(CarrierContentControl),
  117. new UIPropertyMetadata(false, HasWaferChanged));
  118. public CarrierBorderStatus BorderStatus
  119. {
  120. get { return (CarrierBorderStatus)GetValue(BorderStatusProperty); }
  121. set { SetValue(BorderStatusProperty, value); }
  122. }
  123. public static readonly DependencyProperty BorderStatusProperty =
  124. DependencyProperty.Register("BorderStatus", typeof(CarrierBorderStatus), typeof(CarrierContentControl),
  125. new UIPropertyMetadata(CarrierBorderStatus.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(CarrierContentControl), 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(CarrierContentControl), 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(CarrierContentControl), 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(CarrierContentControl), new PropertyMetadata(string.Empty));
  154. public string SeasoningWaferType
  155. {
  156. get { return (string)GetValue(SeasoningWaferTypeProperty); }
  157. set { SetValue(SeasoningWaferTypeProperty, value); }
  158. }
  159. public static readonly DependencyProperty SeasoningWaferTypeProperty =
  160. DependencyProperty.Register("SeasoningWaferType", typeof(string), typeof(CarrierContentControl), new PropertyMetadata(string.Empty));
  161. public Visibility DuplicatedVisibility
  162. {
  163. get { return (Visibility)GetValue(DuplicatedVisibilityProperty); }
  164. set { SetValue(DuplicatedVisibilityProperty, value); }
  165. }
  166. public static readonly DependencyProperty DuplicatedVisibilityProperty =
  167. DependencyProperty.Register("DuplicatedVisibility", typeof(Visibility), typeof(CarrierContentControl), new UIPropertyMetadata(Visibility.Collapsed));
  168. public override void OnApplyTemplate()
  169. {
  170. base.OnApplyTemplate();
  171. DragDropStatusControl(this);
  172. }
  173. protected override void OnDragEnter(DragEventArgs e)
  174. {
  175. base.OnDragEnter(e);
  176. this.IsDragEnter = true;
  177. }
  178. protected override void OnDragLeave(DragEventArgs e)
  179. {
  180. base.OnDragLeave(e);
  181. this.IsDragEnter = false;
  182. }
  183. protected override void OnMouseDown(MouseButtonEventArgs e)
  184. {
  185. base.OnMouseDown(e);
  186. if (MouseButtonState.Pressed == e.LeftButton)
  187. IsLeftMouseDown = true;
  188. e.Handled = true;
  189. }
  190. protected override void OnMouseUp(MouseButtonEventArgs e)
  191. {
  192. base.OnMouseUp(e);
  193. IsLeftMouseDown = false;
  194. MouseButtonEventHandler handler = StageMouseButtonDown;
  195. if (handler != null)
  196. {
  197. handler(this, e);
  198. }
  199. }
  200. protected override void OnMouseEnter(MouseEventArgs e)
  201. {
  202. base.OnMouseEnter(e);
  203. this.BorderStatus = this.BorderStatus | CarrierBorderStatus.MouseOver;
  204. }
  205. protected override void OnMouseLeave(MouseEventArgs e)
  206. {
  207. base.OnMouseLeave(e);
  208. IsLeftMouseDown = false;
  209. this.BorderStatus = this.BorderStatus & (~CarrierBorderStatus.MouseOver);
  210. }
  211. private static void DragDropStatusControl(CarrierContentControl p_Stage)
  212. {
  213. p_Stage.AllowDrop = false;
  214. p_Stage.IsDraggable = false;
  215. if (p_Stage.CanDragDrop)
  216. {
  217. if (!p_Stage.IsDropTarget && p_Stage.WaferStatus == 0)
  218. p_Stage.AllowDrop = true;
  219. if (!p_Stage.IsDragSource && p_Stage.WaferStatus != 0)
  220. p_Stage.IsDraggable = true;
  221. }
  222. }
  223. private static void IsDropTargetPropertyChangedCallBack(DependencyObject d, DependencyPropertyChangedEventArgs args)
  224. {
  225. CarrierContentControl m_Stage = d as CarrierContentControl;
  226. if (m_Stage.IsDropTarget)
  227. m_Stage.BorderStatus = m_Stage.BorderStatus | CarrierBorderStatus.TransferTarget; //add
  228. else
  229. m_Stage.BorderStatus = m_Stage.BorderStatus & (~CarrierBorderStatus.TransferTarget); //remove
  230. DragDropStatusControl(m_Stage);
  231. }
  232. private static void IsDragSourcePropertyChangedCallBack(DependencyObject d, DependencyPropertyChangedEventArgs args)
  233. {
  234. CarrierContentControl m_Stage = d as CarrierContentControl;
  235. if (m_Stage.IsDragSource)
  236. m_Stage.BorderStatus = m_Stage.BorderStatus | CarrierBorderStatus.TransferSource; //add
  237. else
  238. m_Stage.BorderStatus = m_Stage.BorderStatus & (~CarrierBorderStatus.TransferSource); //remove
  239. DragDropStatusControl(m_Stage);
  240. }
  241. private static void IsSelectedPropertyChangedCallBack(DependencyObject d, DependencyPropertyChangedEventArgs args)
  242. {
  243. CarrierContentControl m_Stage = d as CarrierContentControl;
  244. if (m_Stage.IsSelected)
  245. m_Stage.BorderStatus = m_Stage.BorderStatus | CarrierBorderStatus.Selected; //add
  246. else
  247. m_Stage.BorderStatus = m_Stage.BorderStatus & (~CarrierBorderStatus.Selected); //remove
  248. }
  249. private static void CanDragDropPropertyChangedCallBack(DependencyObject d, DependencyPropertyChangedEventArgs args)
  250. {
  251. CarrierContentControl m_Stage = d as CarrierContentControl;
  252. DragDropStatusControl(m_Stage);
  253. }
  254. private static void IsDragEnterPropertyChangedCallBack(DependencyObject d, DependencyPropertyChangedEventArgs args)
  255. {
  256. CarrierContentControl m_Stage = d as CarrierContentControl;
  257. if (m_Stage.IsDragEnter)
  258. m_Stage.BorderStatus = m_Stage.BorderStatus | CarrierBorderStatus.TransferTarget; //add
  259. else
  260. m_Stage.BorderStatus = m_Stage.BorderStatus & (~CarrierBorderStatus.TransferTarget); //remove
  261. }
  262. private static void WaferStatusChangedCallBack(DependencyObject d, DependencyPropertyChangedEventArgs args)
  263. {
  264. CarrierContentControl m_Stage = d as CarrierContentControl;
  265. m_Stage.IsDragSource = false;
  266. m_Stage.IsDropTarget = false;
  267. m_Stage.IsDragEnter = false;
  268. DragDropStatusControl(m_Stage);
  269. }
  270. public static void HasWaferChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
  271. {
  272. CarrierContentControl m_Stage = d as CarrierContentControl;
  273. if (m_Stage != null)
  274. {
  275. if (m_Stage.HasWafer)
  276. m_Stage.WaferStatus = 7;
  277. else
  278. m_Stage.WaferStatus = 0;
  279. }
  280. }
  281. protected override void OnPreviewMouseMove(MouseEventArgs e)
  282. {
  283. base.OnPreviewMouseMove(e);
  284. if (e.LeftButton == MouseButtonState.Pressed && IsDraggable && IsLeftMouseDown)
  285. {
  286. DataObject data = new DataObject(typeof(CarrierContentControl), this);
  287. DragDrop.DoDragDrop(this, data, DragDropEffects.Move);
  288. }
  289. }
  290. protected override void OnDrop(DragEventArgs e)
  291. {
  292. if (this.AllowDrop)
  293. {
  294. try
  295. {
  296. IDataObject data = e.Data;
  297. if (data.GetDataPresent(typeof(CarrierContentControl)))
  298. {
  299. CarrierContentControl m_dragSource = (CarrierContentControl)data.GetData(typeof(CarrierContentControl));
  300. m_dragSource.IsDragSource = true; //source
  301. this.IsDropTarget = true; //target
  302. if (WaferTransferStarted != null)
  303. {
  304. CarrierDragDropEventArgs m_arg = new CarrierDragDropEventArgs(m_dragSource, this);
  305. WaferTransferStarted(this, m_arg);
  306. }
  307. }
  308. else //to support another type of wafer
  309. {
  310. //var sourceWafer = (WaferInfo)e.Data.GetData("Object");
  311. var sourceStation = e.Data.GetData("Station").ToString();
  312. var sourceStage = (int)e.Data.GetData("Stage");
  313. CarrierContentControl m_dragSource = new CarrierContentControl() { ModuleID = sourceStation, CarrierID = sourceStage };
  314. if (WaferTransferStarted != null)
  315. {
  316. CarrierDragDropEventArgs m_arg = new CarrierDragDropEventArgs(m_dragSource, this);
  317. WaferTransferStarted(this, m_arg);
  318. }
  319. }
  320. }
  321. catch
  322. {
  323. }
  324. }
  325. }
  326. public bool IsValidStage()
  327. {
  328. if (this.ModuleID.Length >0 && this.CarrierID >= 0)
  329. return true;
  330. else
  331. return false;
  332. }
  333. public bool IsSameStage(CarrierContentControl Stage)
  334. {
  335. if (Stage.IsValidStage() && this.IsValidStage())
  336. {
  337. if (this.ModuleID == Stage.ModuleID && this.CarrierID == Stage.CarrierID)
  338. return true;
  339. }
  340. return false;
  341. }
  342. public void ClearDragDropStatus()
  343. {
  344. this.IsDragEnter = false;
  345. this.IsDragSource = false;
  346. this.IsDropTarget = false;
  347. }
  348. }
  349. }