CustomRobot.cs 5.6 KB

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