CustomRobot.cs 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  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 PunkHPX8_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. Dummy1,
  58. Dummy2,
  59. SRD1,
  60. SRD2,
  61. VPW1,
  62. VPW2,
  63. PlatingCell1,
  64. PlatingCell2,
  65. PlatingCell3,
  66. PlatingCell4
  67. }
  68. public class WaferRobotControl : Control
  69. {
  70. static WaferRobotControl()
  71. {
  72. DefaultStyleKeyProperty.OverrideMetadata(typeof(WaferRobotControl), new FrameworkPropertyMetadata(typeof(WaferRobotControl)));
  73. }
  74. public static readonly DependencyProperty WaferProperty = DependencyProperty.Register("Wafer", typeof(int), typeof(WaferRobotControl));
  75. public int Wafer { get => (int)GetValue(WaferProperty); set => SetValue(WaferProperty, value); }
  76. public static readonly DependencyProperty ExtendTimeProperty = DependencyProperty.Register("ExtendTime", typeof(KeyTime), typeof(WaferRobotControl),new PropertyMetadata (KeyTime.FromTimeSpan(TimeSpan.FromSeconds(9))));
  77. public KeyTime ExtendTime { get => (KeyTime)GetValue(ExtendTimeProperty); set => SetValue(ExtendTimeProperty, value); }
  78. public static readonly DependencyProperty RobotWaferProperty = DependencyProperty.Register(
  79. "RobotWafer",
  80. typeof(WaferInfo),
  81. typeof(WaferRobotControl));
  82. public WaferInfo RobotWafer
  83. {
  84. get => (WaferInfo)GetValue(RobotWaferProperty);
  85. set => SetValue(RobotWaferProperty, value);
  86. }
  87. public static readonly DependencyProperty RobotXActionProperty = DependencyProperty.Register(
  88. "RobotXAction",
  89. typeof(WaferRobotXAction),
  90. typeof(WaferRobotControl),
  91. new PropertyMetadata(WaferRobotXAction.X_Origin, RobotXActionPropertyChangedCallback));
  92. public WaferRobotXAction RobotXAction
  93. {
  94. get => (WaferRobotXAction)GetValue(RobotXActionProperty);
  95. set => SetValue(RobotXActionProperty, value);
  96. }
  97. private static void RobotXActionPropertyChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
  98. {
  99. //KeyTime value = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(9));
  100. var control = d as WaferRobotControl;
  101. var oldAct = (WaferRobotXAction)e.OldValue;
  102. var newAct = (WaferRobotXAction)e.NewValue;
  103. switch (newAct)
  104. {
  105. case WaferRobotXAction.X_Origin:
  106. VisualStateManager.GoToState(control, newAct.ToString(), true);
  107. break;
  108. case WaferRobotXAction.Extend:
  109. if (newAct != oldAct)
  110. {
  111. VisualStateManager.GoToState(control, newAct.ToString(), true);
  112. }
  113. break;
  114. case WaferRobotXAction.Extend2:
  115. if (newAct != oldAct)
  116. {
  117. VisualStateManager.GoToState(control, newAct.ToString(), true);
  118. }
  119. break;
  120. case WaferRobotXAction.Retract2:
  121. if (newAct != oldAct)
  122. {
  123. VisualStateManager.GoToState(control, newAct.ToString(), true);
  124. }
  125. break;
  126. case WaferRobotXAction.Retract:
  127. if (newAct != oldAct)
  128. {
  129. VisualStateManager.GoToState(control, newAct.ToString(), true);
  130. }
  131. break;
  132. default:
  133. break;
  134. }
  135. }
  136. public static readonly DependencyProperty RobotTActionProperty = DependencyProperty.Register(
  137. "RobotTAction",
  138. typeof(WaferRobotTAction),
  139. typeof(WaferRobotControl),
  140. new PropertyMetadata(WaferRobotTAction.T_Origin, RobotTActionPropertyChangedCallback));
  141. public WaferRobotTAction RobotTAction
  142. {
  143. get => (WaferRobotTAction)GetValue(RobotTActionProperty);
  144. set => SetValue(RobotTActionProperty, value);
  145. }
  146. public static readonly DependencyProperty RobotSpeedProperty = DependencyProperty.Register(
  147. "RobotSpeed",
  148. typeof(double),
  149. typeof(WaferRobotControl),
  150. new PropertyMetadata(9.0d, RobotSpeedPropertyChangedCallback));
  151. public double RobotSpeed
  152. {
  153. get => (double)GetValue(RobotSpeedProperty);
  154. set => SetValue(RobotSpeedProperty, value);
  155. }
  156. private static void RobotSpeedPropertyChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
  157. {
  158. }
  159. public string OriginT { get; set; }
  160. private static void RobotTActionPropertyChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
  161. {
  162. var control = d as WaferRobotControl;
  163. var oldAct = (WaferRobotTAction)e.OldValue;
  164. var newAct = (WaferRobotTAction)e.NewValue;
  165. if(oldAct!=newAct)
  166. {
  167. VisualStateManager.GoToState(control, newAct.ToString(), true);
  168. }
  169. }
  170. public override void OnApplyTemplate()
  171. {
  172. base.OnApplyTemplate();
  173. VisualStateManager.GoToState(this, WaferRobotXAction.X_Origin.ToString(), true);
  174. VisualStateManager.GoToState(this, OriginT, true);
  175. }
  176. }
  177. }