SERobot.cs 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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. namespace Venus_Themes.CustomControls
  11. {
  12. public class SERobot : Control
  13. {
  14. public enum SERobotXAction
  15. {
  16. X_Origin,
  17. Extend,
  18. ToVCE,
  19. FromVCE,
  20. FromVCEToVPA,
  21. Retract
  22. }
  23. public enum SERobotTAction
  24. {
  25. T_Origin,
  26. PMA,
  27. PMB,
  28. PMC,
  29. VCE1,
  30. VPA,
  31. RightLocation,
  32. LeftLocation
  33. }
  34. static SERobot()
  35. {
  36. DefaultStyleKeyProperty.OverrideMetadata(typeof(SERobot), new FrameworkPropertyMetadata(typeof(SERobot)));
  37. }
  38. //注册Wafer、ExtendTime、RobotWafer、RobotXAction属性
  39. public static readonly DependencyProperty WaferProperty = DependencyProperty.Register("Wafer", typeof(int), typeof(SERobot));
  40. public int Wafer { get => (int)GetValue(WaferProperty); set => SetValue(WaferProperty, value); }
  41. public static readonly DependencyProperty ExtendTimeProperty = DependencyProperty.Register("ExtendTime", typeof(KeyTime), typeof(SERobot), new PropertyMetadata(KeyTime.FromTimeSpan(TimeSpan.FromSeconds(9))));
  42. public KeyTime ExtendTime { get => (KeyTime)GetValue(ExtendTimeProperty); set => SetValue(ExtendTimeProperty, value); }
  43. public static readonly DependencyProperty RobotWaferProperty = DependencyProperty.Register(
  44. "RobotWafer",
  45. typeof(WaferInfo),
  46. typeof(SERobot));
  47. public WaferInfo RobotWafer
  48. {
  49. get => (WaferInfo)GetValue(RobotWaferProperty);
  50. set => SetValue(RobotWaferProperty, value);
  51. }
  52. public static readonly DependencyProperty RobotXActionProperty = DependencyProperty.Register(
  53. "RobotXAction",
  54. typeof(SERobotXAction),
  55. typeof(SERobot),
  56. new PropertyMetadata(SERobotXAction.X_Origin, RobotXActionPropertyChangedCallback));
  57. public SERobotXAction RobotXAction
  58. {
  59. get => (SERobotXAction)GetValue(RobotXActionProperty);
  60. set => SetValue(RobotXActionProperty, value);
  61. }
  62. //RobotXAction依赖属性的值被改变之后此委托会被调用
  63. private static void RobotXActionPropertyChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
  64. {
  65. //KeyTime value = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(9));
  66. var control = d as SERobot; //d转换为SERobot
  67. var oldAct = (SERobotXAction)e.OldValue; //现在的位置
  68. var newAct = (SERobotXAction)e.NewValue; //下一个位置
  69. switch (newAct)
  70. {
  71. case SERobotXAction.X_Origin:
  72. VisualStateManager.GoToState(control, newAct.ToString(), true);
  73. break;
  74. case SERobotXAction.Extend:
  75. if (newAct != oldAct)
  76. {
  77. VisualStateManager.GoToState(control, newAct.ToString(), true);
  78. }
  79. break;
  80. case SERobotXAction.Retract:
  81. if (newAct != oldAct)
  82. {
  83. VisualStateManager.GoToState(control, newAct.ToString(), true);
  84. }
  85. break;
  86. case SERobotXAction.ToVCE:
  87. if (newAct != oldAct)
  88. {
  89. VisualStateManager.GoToState(control, newAct.ToString(), true);
  90. }
  91. break;
  92. case SERobotXAction.FromVCEToVPA:
  93. if (newAct != oldAct)
  94. {
  95. VisualStateManager.GoToState(control, newAct.ToString(), true);
  96. }
  97. break;
  98. default:
  99. break;
  100. }
  101. }
  102. public static readonly DependencyProperty RobotTActionProperty = DependencyProperty.Register(
  103. "RobotTAction",
  104. typeof(SERobotTAction),
  105. typeof(SERobot),
  106. new PropertyMetadata(SERobotTAction.T_Origin, RobotTActionPropertyChangedCallback));
  107. public SERobotTAction RobotTAction
  108. {
  109. get => (SERobotTAction)GetValue(RobotTActionProperty);
  110. set => SetValue(RobotTActionProperty, value);
  111. }
  112. public static readonly DependencyProperty RobotSpeedProperty = DependencyProperty.Register(
  113. "RobotSpeed",
  114. typeof(double),
  115. typeof(SERobot),
  116. new PropertyMetadata(9.0d, RobotSpeedPropertyChangedCallback));
  117. public double RobotSpeed
  118. {
  119. get => (double)GetValue(RobotSpeedProperty);
  120. set => SetValue(RobotSpeedProperty, value);
  121. }
  122. private static void RobotSpeedPropertyChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
  123. {
  124. }
  125. public string OriginT { get; set; }
  126. private static void RobotTActionPropertyChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
  127. {
  128. var control = d as SERobot;
  129. var oldAct = (SERobotTAction)e.OldValue;
  130. var newAct = (SERobotTAction)e.NewValue;
  131. if (oldAct != newAct)
  132. {
  133. VisualStateManager.GoToState(control, newAct.ToString(), true);//前后动作不一致,改变控件状态
  134. }
  135. }
  136. public override void OnApplyTemplate()
  137. {
  138. base.OnApplyTemplate();
  139. VisualStateManager.GoToState(this, SERobotXAction.X_Origin.ToString(), true);
  140. VisualStateManager.GoToState(this, OriginT, true);
  141. }
  142. }
  143. }