SERobot.cs 5.5 KB

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