CustomRobot.cs 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. using OpenSEMI.ClientBase;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Globalization;
  5. using System.Windows;
  6. using System.Windows.Controls;
  7. using System.Windows.Data;
  8. using System.Windows.Media;
  9. using System.Windows.Media.Animation;
  10. namespace CyberX8_Themes.CustomControls
  11. {
  12. public class WaferIntToColorConverter : IValueConverter
  13. {
  14. public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
  15. {
  16. return int.Parse(value.ToString()) == 1 ? new SolidColorBrush(Colors.Red) : new SolidColorBrush(Colors.Green);
  17. }
  18. public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
  19. {
  20. throw new NotImplementedException();
  21. }
  22. }
  23. public class WaferIntToVisibilityConverter : IValueConverter
  24. {
  25. public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
  26. {
  27. return int.Parse(value.ToString()) == 1 ? Visibility.Visible : Visibility.Hidden;
  28. }
  29. public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
  30. {
  31. throw new NotImplementedException();
  32. }
  33. }
  34. public enum WaferRobotXAction
  35. {
  36. X_Origin,
  37. Extend,
  38. Retract,
  39. Extend2,
  40. Retract2
  41. }
  42. public enum WaferRobotTAction
  43. {
  44. T_Origin,
  45. PMA,
  46. PMB,
  47. PMC,
  48. PMD,
  49. LLA,
  50. LLB,
  51. LP1,
  52. LP2,
  53. LP3,
  54. Aligner1,
  55. RightLocation,
  56. LeftLocation,
  57. PUF1,
  58. PUF2,
  59. Dummy1,
  60. Dummy2,
  61. SRD1,
  62. SRD2
  63. }
  64. public class WaferRobotControl : Control
  65. {
  66. static WaferRobotControl()
  67. {
  68. DefaultStyleKeyProperty.OverrideMetadata(typeof(WaferRobotControl), new FrameworkPropertyMetadata(typeof(WaferRobotControl)));
  69. }
  70. public static readonly DependencyProperty WaferProperty = DependencyProperty.Register("Wafer", typeof(int), typeof(WaferRobotControl));
  71. public int Wafer { get => (int)GetValue(WaferProperty); set => SetValue(WaferProperty, value); }
  72. public static readonly DependencyProperty ExtendTimeProperty = DependencyProperty.Register("ExtendTime", typeof(KeyTime), typeof(WaferRobotControl),new PropertyMetadata (KeyTime.FromTimeSpan(TimeSpan.FromSeconds(9))));
  73. public KeyTime ExtendTime { get => (KeyTime)GetValue(ExtendTimeProperty); set => SetValue(ExtendTimeProperty, value); }
  74. public static readonly DependencyProperty RobotWaferProperty = DependencyProperty.Register(
  75. "RobotWafer",
  76. typeof(WaferInfo),
  77. typeof(WaferRobotControl));
  78. public WaferInfo RobotWafer
  79. {
  80. get => (WaferInfo)GetValue(RobotWaferProperty);
  81. set => SetValue(RobotWaferProperty, value);
  82. }
  83. public static readonly DependencyProperty RobotXActionProperty = DependencyProperty.Register(
  84. "RobotXAction",
  85. typeof(WaferRobotXAction),
  86. typeof(WaferRobotControl),
  87. new PropertyMetadata(WaferRobotXAction.X_Origin, RobotXActionPropertyChangedCallback));
  88. public WaferRobotXAction RobotXAction
  89. {
  90. get => (WaferRobotXAction)GetValue(RobotXActionProperty);
  91. set => SetValue(RobotXActionProperty, value);
  92. }
  93. private static void RobotXActionPropertyChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
  94. {
  95. //KeyTime value = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(9));
  96. var control = d as WaferRobotControl;
  97. var oldAct = (WaferRobotXAction)e.OldValue;
  98. var newAct = (WaferRobotXAction)e.NewValue;
  99. switch (newAct)
  100. {
  101. case WaferRobotXAction.X_Origin:
  102. VisualStateManager.GoToState(control, newAct.ToString(), true);
  103. break;
  104. case WaferRobotXAction.Extend:
  105. if (newAct != oldAct)
  106. {
  107. VisualStateManager.GoToState(control, newAct.ToString(), true);
  108. }
  109. break;
  110. case WaferRobotXAction.Extend2:
  111. if (newAct != oldAct)
  112. {
  113. VisualStateManager.GoToState(control, newAct.ToString(), true);
  114. }
  115. break;
  116. case WaferRobotXAction.Retract2:
  117. if (newAct != oldAct)
  118. {
  119. VisualStateManager.GoToState(control, newAct.ToString(), true);
  120. }
  121. break;
  122. case WaferRobotXAction.Retract:
  123. if (newAct != oldAct)
  124. {
  125. VisualStateManager.GoToState(control, newAct.ToString(), true);
  126. }
  127. break;
  128. default:
  129. break;
  130. }
  131. }
  132. public static readonly DependencyProperty RobotTActionProperty = DependencyProperty.Register(
  133. "RobotTAction",
  134. typeof(WaferRobotTAction),
  135. typeof(WaferRobotControl),
  136. new PropertyMetadata(WaferRobotTAction.T_Origin, RobotTActionPropertyChangedCallback));
  137. public WaferRobotTAction RobotTAction
  138. {
  139. get => (WaferRobotTAction)GetValue(RobotTActionProperty);
  140. set => SetValue(RobotTActionProperty, value);
  141. }
  142. public static readonly DependencyProperty RobotSpeedProperty = DependencyProperty.Register(
  143. "RobotSpeed",
  144. typeof(double),
  145. typeof(WaferRobotControl),
  146. new PropertyMetadata(9.0d, RobotSpeedPropertyChangedCallback));
  147. public double RobotSpeed
  148. {
  149. get => (double)GetValue(RobotSpeedProperty);
  150. set => SetValue(RobotSpeedProperty, value);
  151. }
  152. private static void RobotSpeedPropertyChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
  153. {
  154. }
  155. public string OriginT { get; set; }
  156. private static void RobotTActionPropertyChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
  157. {
  158. var control = d as WaferRobotControl;
  159. var oldAct = (WaferRobotTAction)e.OldValue;
  160. var newAct = (WaferRobotTAction)e.NewValue;
  161. if(oldAct!=newAct)
  162. {
  163. VisualStateManager.GoToState(control, newAct.ToString(), true);
  164. }
  165. }
  166. public override void OnApplyTemplate()
  167. {
  168. base.OnApplyTemplate();
  169. VisualStateManager.GoToState(this, WaferRobotXAction.X_Origin.ToString(), true);
  170. VisualStateManager.GoToState(this, OriginT, true);
  171. }
  172. }
  173. }