SERobot.cs 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. using OpenSEMI.ClientBase;
  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.Media.Animation;
  10. using CyberX8_Themes.UserControls;
  11. namespace CyberX8_Themes.CustomControls
  12. {
  13. public class SERobot : Control
  14. {
  15. public enum SERobotXAction
  16. {
  17. X_Origin,
  18. Extend,
  19. ToVCE,
  20. FromVCE,
  21. FromVCEToVPA,
  22. Retract,
  23. X_Origin2,
  24. Extend2,
  25. ToVCE2,
  26. FromVCE2,
  27. FromVCEToVPA2,
  28. Retract2
  29. }
  30. public enum SERobotTAction
  31. {
  32. T_Origin,
  33. PMA,
  34. PMB,
  35. PMC,
  36. VCE1,
  37. VPA,
  38. VPARight,
  39. RightLocation,
  40. LeftLocation
  41. }
  42. static SERobot()
  43. {
  44. DefaultStyleKeyProperty.OverrideMetadata(typeof(SERobot), new FrameworkPropertyMetadata(typeof(SERobot)));
  45. }
  46. //注册Wafer、ExtendTime、RobotWafer、RobotXAction属性
  47. public static readonly DependencyProperty PMCIsInstalledProperty = DependencyProperty.Register(
  48. "PMCIsInstalled", typeof(bool), typeof(SERobot));
  49. public bool PMCIsInstalled
  50. {
  51. get { return (bool)this.GetValue(PMCIsInstalledProperty); }
  52. set { SetValue(PMCIsInstalledProperty, value); }
  53. }
  54. public static readonly DependencyProperty WaferProperty = DependencyProperty.Register("Wafer", typeof(int), typeof(SERobot));
  55. public int Wafer { get => (int)GetValue(WaferProperty); set => SetValue(WaferProperty, value); }
  56. public static readonly DependencyProperty ExtendTimeProperty = DependencyProperty.Register("ExtendTime", typeof(KeyTime), typeof(SERobot), new PropertyMetadata(KeyTime.FromTimeSpan(TimeSpan.FromSeconds(9))));
  57. public KeyTime ExtendTime { get => (KeyTime)GetValue(ExtendTimeProperty); set => SetValue(ExtendTimeProperty, value); }
  58. public static readonly DependencyProperty RobotWaferProperty = DependencyProperty.Register(
  59. "RobotWafer",
  60. typeof(WaferInfo),
  61. typeof(SERobot));
  62. public WaferInfo RobotWafer
  63. {
  64. get => (WaferInfo)GetValue(RobotWaferProperty);
  65. set => SetValue(RobotWaferProperty, value);
  66. }
  67. public static readonly DependencyProperty RobotXActionProperty = DependencyProperty.Register(
  68. "RobotXAction",
  69. typeof(SERobotXAction),
  70. typeof(SERobot),
  71. new PropertyMetadata(SERobotXAction.X_Origin, RobotXActionPropertyChangedCallback));
  72. public SERobotXAction RobotXAction
  73. {
  74. get => (SERobotXAction)GetValue(RobotXActionProperty);
  75. set => SetValue(RobotXActionProperty, value);
  76. }
  77. //RobotXAction依赖属性的值被改变之后此委托会被调用
  78. private static void RobotXActionPropertyChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
  79. {
  80. //KeyTime value = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(9));
  81. var control = d as SERobot; //d转换为SERobot
  82. var oldAct = (SERobotXAction)e.OldValue; //现在的位置
  83. var newAct = (SERobotXAction)e.NewValue; //下一个位置
  84. switch (newAct)
  85. {
  86. case SERobotXAction.X_Origin:
  87. VisualStateManager.GoToState(control, newAct.ToString(), true);
  88. break;
  89. case SERobotXAction.Extend:
  90. if (newAct != oldAct)
  91. {
  92. VisualStateManager.GoToState(control, newAct.ToString(), true);
  93. }
  94. break;
  95. case SERobotXAction.Retract:
  96. if (newAct != oldAct)
  97. {
  98. VisualStateManager.GoToState(control, newAct.ToString(), true);
  99. }
  100. break;
  101. case SERobotXAction.ToVCE:
  102. if (newAct != oldAct)
  103. {
  104. VisualStateManager.GoToState(control, newAct.ToString(), true);
  105. }
  106. break;
  107. case SERobotXAction.FromVCEToVPA:
  108. if (newAct != oldAct)
  109. {
  110. VisualStateManager.GoToState(control, newAct.ToString(), true);
  111. }
  112. break;
  113. case SERobotXAction.X_Origin2:
  114. VisualStateManager.GoToState(control, newAct.ToString(), true);
  115. break;
  116. case SERobotXAction.Extend2:
  117. if (newAct != oldAct)
  118. {
  119. VisualStateManager.GoToState(control, newAct.ToString(), true);
  120. }
  121. break;
  122. case SERobotXAction.Retract2:
  123. if (newAct != oldAct)
  124. {
  125. VisualStateManager.GoToState(control, newAct.ToString(), true);
  126. }
  127. break;
  128. case SERobotXAction.ToVCE2:
  129. if (newAct != oldAct)
  130. {
  131. VisualStateManager.GoToState(control, newAct.ToString(), true);
  132. }
  133. break;
  134. case SERobotXAction.FromVCEToVPA2:
  135. if (newAct != oldAct)
  136. {
  137. VisualStateManager.GoToState(control, newAct.ToString(), true);
  138. }
  139. break;
  140. default:
  141. break;
  142. }
  143. }
  144. public static readonly DependencyProperty RobotTActionProperty = DependencyProperty.Register(
  145. "RobotTAction",
  146. typeof(SERobotTAction),
  147. typeof(SERobot),
  148. new PropertyMetadata(SERobotTAction.T_Origin, RobotTActionPropertyChangedCallback));
  149. public SERobotTAction RobotTAction
  150. {
  151. get => (SERobotTAction)GetValue(RobotTActionProperty);
  152. set => SetValue(RobotTActionProperty, value);
  153. }
  154. public static readonly DependencyProperty RobotSpeedProperty = DependencyProperty.Register(
  155. "RobotSpeed",
  156. typeof(double),
  157. typeof(SERobot),
  158. new PropertyMetadata(9.0d, RobotSpeedPropertyChangedCallback));
  159. public double RobotSpeed
  160. {
  161. get => (double)GetValue(RobotSpeedProperty);
  162. set => SetValue(RobotSpeedProperty, value);
  163. }
  164. private static void RobotSpeedPropertyChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
  165. {
  166. }
  167. public string OriginX { get; set; }
  168. public string OriginT { get; set; }
  169. private static void RobotTActionPropertyChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
  170. {
  171. var control = d as SERobot;
  172. var oldAct = (SERobotTAction)e.OldValue;
  173. var newAct = (SERobotTAction)e.NewValue;
  174. while (newAct.ToString() == "VPA"&&!control.PMCIsInstalled)
  175. {
  176. newAct = SERobotTAction.VPARight;
  177. }
  178. if (oldAct != newAct)
  179. {
  180. VisualStateManager.GoToState(control, newAct.ToString(), true);//前后动作不一致,改变控件状态
  181. }
  182. }
  183. public override void OnApplyTemplate()
  184. {
  185. base.OnApplyTemplate();
  186. VisualStateManager.GoToState(this, OriginX, true);
  187. //VisualStateManager.GoToState(this, SERobotXAction.X_Origin.ToString(), true);
  188. VisualStateManager.GoToState(this, OriginT, true);
  189. }
  190. }
  191. }