AtmRobot.xaml.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502
  1. using Aitex.Core.Common;
  2. using Aitex.Sorter.Common;
  3. using System;
  4. using System.Globalization;
  5. using System.Windows;
  6. using System.Windows.Controls;
  7. using System.Windows.Input;
  8. using System.Windows.Media;
  9. using MECF.Framework.Common.Equipment;
  10. namespace Aitex.Sorter.UI.Controls
  11. {
  12. /// <summary>
  13. /// AtmRobot.xaml 的交互逻辑
  14. /// </summary>
  15. public partial class AtmRobot : UserControl
  16. {
  17. private const int ms = 300;
  18. public int RotateAngle
  19. {
  20. get { return (int)GetValue(RotateAngleProperty); }
  21. set { SetValue(RotateAngleProperty, value); }
  22. }
  23. // Using a DependencyProperty as the backing store for RotateAngel. This enables animation, styling, binding, etc...
  24. public static readonly DependencyProperty RotateAngleProperty =
  25. DependencyProperty.Register("RotateAngel", typeof(int), typeof(AtmRobot), new PropertyMetadata(0));
  26. public int RobotWidth
  27. {
  28. get { return (int)GetValue(RobotWidthProperty); }
  29. set { SetValue(RobotWidthProperty, value); }
  30. }
  31. // Using a DependencyProperty as the backing store for RobotWidth. This enables animation, styling, binding, etc...
  32. public static readonly DependencyProperty RobotWidthProperty =
  33. DependencyProperty.Register("RobotWidth", typeof(int), typeof(AtmRobot), new PropertyMetadata(0));
  34. public int RobotHeight
  35. {
  36. get { return (int)GetValue(RobotHeightProperty); }
  37. set { SetValue(RobotHeightProperty, value); }
  38. }
  39. // Using a DependencyProperty as the backing store for RobotHeight. This enables animation, styling, binding, etc...
  40. public static readonly DependencyProperty RobotHeightProperty =
  41. DependencyProperty.Register("RobotHeight", typeof(int), typeof(AtmRobot), new PropertyMetadata(60));
  42. public int DockerWidth
  43. {
  44. get { return (int)GetValue(DockerWidthProperty); }
  45. set { SetValue(DockerWidthProperty, value); }
  46. }
  47. // Using a DependencyProperty as the backing store for DockerWidth. This enables animation, styling, binding, etc...
  48. public static readonly DependencyProperty DockerWidthProperty =
  49. DependencyProperty.Register("DockerWidth", typeof(int), typeof(AtmRobot), new PropertyMetadata(0));
  50. public WaferInfo Wafer1
  51. {
  52. get { return (WaferInfo)GetValue(Wafer1Property); }
  53. set { SetValue(Wafer1Property, value); }
  54. }
  55. // Using a DependencyProperty as the backing store for WaferItem. This enables animation, styling, binding, etc...
  56. public static readonly DependencyProperty Wafer1Property =
  57. DependencyProperty.Register("Wafer1", typeof(WaferInfo), typeof(AtmRobot), new PropertyMetadata(null));
  58. public WaferInfo Wafer2
  59. {
  60. get { return (WaferInfo)GetValue(Wafer2Property); }
  61. set { SetValue(Wafer2Property, value); }
  62. }
  63. // Using a DependencyProperty as the backing store for WaferItem. This enables animation, styling, binding, etc...
  64. public static readonly DependencyProperty Wafer2Property =
  65. DependencyProperty.Register("Wafer2", typeof(WaferInfo), typeof(AtmRobot), new PropertyMetadata(null));
  66. public ModuleName Station
  67. {
  68. get { return (ModuleName)GetValue(StationProperty); }
  69. set { SetValue(StationProperty, value); }
  70. }
  71. // Using a DependencyProperty as the backing store for Station. This enables animation, styling, binding, etc...
  72. public static readonly DependencyProperty StationProperty =
  73. DependencyProperty.Register("Station", typeof(ModuleName), typeof(AtmRobot), new PropertyMetadata(ModuleName.Robot));
  74. public ICommand Command
  75. {
  76. get { return (ICommand)GetValue(CommandProperty); }
  77. set { SetValue(CommandProperty, value); }
  78. }
  79. // Using a DependencyProperty as the backing store for Command. This enables animation, styling, binding, etc...
  80. public static readonly DependencyProperty CommandProperty =
  81. DependencyProperty.Register("Command", typeof(ICommand), typeof(AtmRobot), new PropertyMetadata(null));
  82. public ModuleName RobotBladeTarget
  83. {
  84. get { return (ModuleName)GetValue(RobotBladeTargetProperty); }
  85. set { SetValue(RobotBladeTargetProperty, value); }
  86. }
  87. public static readonly DependencyProperty RobotBladeTargetProperty =
  88. DependencyProperty.Register("RobotBladeTarget", typeof(ModuleName), typeof(AtmRobot), new FrameworkPropertyMetadata(ModuleName.System, FrameworkPropertyMetadataOptions.AffectsRender));
  89. public AtmRobot()
  90. {
  91. InitializeComponent();
  92. root.DataContext = this;
  93. canvas1.Rotate(90);
  94. canvas2.Rotate(180);
  95. canvas3.Rotate(180);
  96. canvas23.Rotate(180);
  97. Blade1Status = BladeStatus.Retract;
  98. Blade2Status = BladeStatus.Retract;
  99. }
  100. protected override void OnRender(DrawingContext drawingContext)
  101. {
  102. base.OnRender(drawingContext);
  103. //var text = new FormattedText(RobotBladeTarget.ToString(), CultureInfo.GetCultureInfo("en-us"), FlowDirection.LeftToRight, new Typeface("Verdana"), 10, Brushes.Black);
  104. //drawingContext.DrawText(text, new Point(10, 0));
  105. if (Blade1Status == BladeStatus.Extend && (RobotBladeTarget == ModuleName.System || RobotBladeTarget == ModuleName.Robot))
  106. {
  107. RetractBlade1();
  108. RetractBlade2();
  109. }
  110. if (Blade1Status == BladeStatus.Retract && RobotBladeTarget != ModuleName.System && RobotBladeTarget != ModuleName.Robot)
  111. {
  112. ExtendBlade1();
  113. ExtendBlade2();
  114. }
  115. if (Blade1Status == BladeStatus.Retract && Blade2Status == BladeStatus.Retract)
  116. {
  117. MoveToHome();
  118. return;
  119. }
  120. if (Blade1Status == BladeStatus.Extend || Blade2Status == BladeStatus.Extend)
  121. {
  122. MoveRobot(RobotBladeTarget);
  123. }
  124. }
  125. private bool MoveRobot(ModuleName chamberSet)
  126. {
  127. switch (chamberSet)
  128. {
  129. case ModuleName.System:
  130. break;
  131. case ModuleName.LP1:
  132. return MoveToLP1();
  133. case ModuleName.LP2:
  134. return MoveToLP2();
  135. case ModuleName.LP3:
  136. break;
  137. case ModuleName.LP4:
  138. break;
  139. case ModuleName.Robot:
  140. return MoveToHome();
  141. case ModuleName.Aligner:
  142. return MoveToAligner();
  143. default:
  144. break;
  145. }
  146. return false;
  147. }
  148. public RobotPostion CurrentPosition
  149. {
  150. get; set;
  151. }
  152. public BladeStatus Blade1Status
  153. {
  154. get; set;
  155. }
  156. public BladeStatus Blade2Status
  157. {
  158. get; set;
  159. }
  160. private void MenuItem_Click(object sender, RoutedEventArgs e)
  161. {
  162. var cmd = ((MenuItem)sender).Tag;
  163. Command.Execute(new[] { Station.ToString(), cmd });
  164. }
  165. private bool MoveToLP1()
  166. {
  167. switch (CurrentPosition)
  168. {
  169. case RobotPostion.Home:
  170. HomeToLP1();
  171. return true;
  172. case RobotPostion.LP1:
  173. break;
  174. case RobotPostion.LP2:
  175. LP2ToLP1();
  176. return true;
  177. case RobotPostion.Aligner:
  178. AlignerToLP1();
  179. return true;
  180. default:
  181. break;
  182. }
  183. return false;
  184. }
  185. private bool MoveToLP2()
  186. {
  187. switch (CurrentPosition)
  188. {
  189. case RobotPostion.Home:
  190. HomeToLP2();
  191. return true;
  192. case RobotPostion.LP1:
  193. LP1ToLP2();
  194. return true;
  195. case RobotPostion.LP2:
  196. break;
  197. case RobotPostion.Aligner:
  198. AlignerToLP2();
  199. return true;
  200. default:
  201. break;
  202. }
  203. return false;
  204. }
  205. private bool MoveToAligner()
  206. {
  207. switch (CurrentPosition)
  208. {
  209. case RobotPostion.Home:
  210. HomeToAligner();
  211. return true;
  212. case RobotPostion.LP1:
  213. LP1ToAligner();
  214. return true;
  215. case RobotPostion.LP2:
  216. LP2ToAligner();
  217. return true;
  218. case RobotPostion.Aligner:
  219. break;
  220. default:
  221. break;
  222. }
  223. return false;
  224. }
  225. private bool MoveToHome()
  226. {
  227. switch (CurrentPosition)
  228. {
  229. case RobotPostion.Home:
  230. break;
  231. case RobotPostion.LP1:
  232. LP1ToHome();
  233. return true;
  234. case RobotPostion.LP2:
  235. LP2ToHome();
  236. return true;
  237. case RobotPostion.Aligner:
  238. AlignerToHome();
  239. return true;
  240. default:
  241. break;
  242. }
  243. return false;
  244. }
  245. private void ExtendBlade1()
  246. {
  247. canvas3.Rotate(0, true, ms);
  248. Blade1Status = BladeStatus.Extend;
  249. }
  250. private void RetractBlade1()
  251. {
  252. canvas3.Rotate(180, true, ms);
  253. Blade1Status = BladeStatus.Retract;
  254. }
  255. private void ExtendBlade2()
  256. {
  257. canvas23.Rotate(0, true, ms);
  258. Blade2Status = BladeStatus.Extend;
  259. }
  260. private void RetractBlade2()
  261. {
  262. canvas23.Rotate(180, true, ms);
  263. Blade2Status = BladeStatus.Retract;
  264. }
  265. private void RetractBlade()
  266. {
  267. canvas3.Rotate(180, true);
  268. canvas23.Rotate(180, true);
  269. }
  270. private void ExtendBlade(int angle)
  271. {
  272. canvas3.Rotate(angle, true);
  273. canvas23.Rotate(angle, true);
  274. }
  275. private void HomeToLP1()
  276. {
  277. ToLP1Start(ToLP1End);
  278. }
  279. private void LP1ToAligner()
  280. {
  281. ToLP1Start(() => ToAlignerStart(ToAlignerEnd));
  282. }
  283. private void LP1ToLP2()
  284. {
  285. ToLP1Start(() => ToLP2Start(ToLP2End));
  286. }
  287. private void HomeToLP2()
  288. {
  289. ToLP2Start(ToLP2End);
  290. }
  291. private void LP2ToLP1()
  292. {
  293. ToLP2Start(() => ToLP1Start(ToLP1End));
  294. }
  295. private void LP2ToAligner()
  296. {
  297. ToLP2Start(() =>
  298. {
  299. RetractBlade();
  300. ToAlignerStart(() =>
  301. {
  302. ExtendBlade(0);
  303. ToAlignerEnd();
  304. });
  305. });
  306. }
  307. private void HomeToAligner()
  308. {
  309. ToAlignerStart(ToAlignerEnd);
  310. }
  311. private void AlignerToLP1()
  312. {
  313. ToAlignerStart(() => ToLP1Start(ToLP1End));
  314. }
  315. private void AlignerToLP2()
  316. {
  317. ToAlignerStart(
  318. () =>
  319. {
  320. RetractBlade();
  321. ToLP2Start(() =>
  322. {
  323. ExtendBlade(90);
  324. ToLP2End();
  325. });
  326. }
  327. );
  328. }
  329. private void LP1ToHome()
  330. {
  331. ToLP1Start(ToHome);
  332. }
  333. private void LP2ToHome()
  334. {
  335. ToLP2Start(ToHome);
  336. }
  337. private void AlignerToHome()
  338. {
  339. ToAlignerStart(ToHome);
  340. }
  341. private void ToLP1Start(Action action = null)
  342. {
  343. canvas1.Rotate(105, true, ms, 0, 0, () => { if (action != null) action(); });
  344. canvas2.Rotate(255, true, ms, 0.5);
  345. if (Blade1Status == BladeStatus.Extend)
  346. canvas3.Rotate(270, true, ms);
  347. if (Blade2Status == BladeStatus.Extend)
  348. canvas23.Rotate(270, true, ms);
  349. CurrentPosition = RobotPostion.LP1;
  350. }
  351. private void ToLP2Start(Action action = null)
  352. {
  353. canvas1.Rotate(70, true, ms, 0, 0, () => { if (action != null) action(); });
  354. canvas2.Rotate(110, true, ms, 0.5);
  355. if (Blade1Status == BladeStatus.Extend)
  356. canvas3.Rotate(90, true, ms);
  357. if (Blade2Status == BladeStatus.Extend)
  358. canvas23.Rotate(90, true, ms);
  359. CurrentPosition = RobotPostion.LP2;
  360. }
  361. private void ToAlignerStart(Action action = null)
  362. {
  363. canvas1.Rotate(45, true, ms, 0, 0, () => { if (action != null) action(); });
  364. canvas2.Rotate(135, true, ms, 0);
  365. if (Blade1Status == BladeStatus.Extend)
  366. canvas3.Rotate(0, true, ms);
  367. if (Blade2Status == BladeStatus.Extend)
  368. canvas23.Rotate(0, true, ms);
  369. CurrentPosition = RobotPostion.Aligner;
  370. }
  371. private void ToLP1End()
  372. {
  373. canvas1.Rotate(80, true, ms, 0);
  374. canvas2.Rotate(220, true, ms, 0);
  375. if (Blade1Status == BladeStatus.Extend) canvas3.Rotate(330, true, ms, 0);
  376. if (Blade2Status == BladeStatus.Extend) canvas23.Rotate(330, true, ms, 0);
  377. CurrentPosition = RobotPostion.LP1;
  378. }
  379. private void ToLP2End()
  380. {
  381. canvas1.Rotate(95, true, ms, 0);
  382. canvas2.Rotate(145, true, ms, 0);
  383. if (Blade1Status == BladeStatus.Extend) canvas3.Rotate(30, true, ms, 0);
  384. if (Blade2Status == BladeStatus.Extend) canvas23.Rotate(30, true, ms, 0);
  385. CurrentPosition = RobotPostion.LP2;
  386. }
  387. private void ToAlignerEnd()
  388. {
  389. canvas1.Rotate(115, true, ms, 0);
  390. canvas2.Rotate(80, true, ms, 0);
  391. if (Blade1Status == BladeStatus.Extend) canvas3.Rotate(-15, true, ms, 0);
  392. if (Blade2Status == BladeStatus.Extend) canvas23.Rotate(-15, true, ms, 0);
  393. CurrentPosition = RobotPostion.Aligner;
  394. }
  395. private void ToHome()
  396. {
  397. canvas1.Rotate(90, true, ms);
  398. canvas2.Rotate(180, true, ms);
  399. if (Blade1Status == BladeStatus.Extend) canvas3.Rotate(180, true, ms);
  400. if (Blade2Status == BladeStatus.Extend) canvas23.Rotate(180, true, ms);
  401. CurrentPosition = RobotPostion.Home;
  402. }
  403. private void mnuToLP1_Click(object sender, RoutedEventArgs e)
  404. {
  405. MoveToLP1();
  406. }
  407. private void mnuToLP2_Click(object sender, RoutedEventArgs e)
  408. {
  409. MoveToLP2();
  410. }
  411. private void mnuToHome_Click(object sender, RoutedEventArgs e)
  412. {
  413. MoveToHome();
  414. }
  415. private void mnuToAligner_Click(object sender, RoutedEventArgs e)
  416. {
  417. MoveToAligner();
  418. }
  419. }
  420. public enum RobotPostion
  421. {
  422. Home,
  423. LP1,
  424. LP2,
  425. Aligner
  426. }
  427. public enum BladeStatus
  428. {
  429. Extend,
  430. Retract
  431. }
  432. }