CustomRobot.cs 5.3 KB

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