CustomRobot.cs 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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 Venus_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. }
  40. public enum WaferRobotTAction
  41. {
  42. T_Origin,
  43. PMA,
  44. PMB,
  45. PMC,
  46. PMD,
  47. LLA,
  48. LLB,
  49. }
  50. public class WaferRobotControl : Control
  51. {
  52. static WaferRobotControl()
  53. {
  54. DefaultStyleKeyProperty.OverrideMetadata(typeof(WaferRobotControl), new FrameworkPropertyMetadata(typeof(WaferRobotControl)));
  55. }
  56. public static readonly DependencyProperty WaferProperty = DependencyProperty.Register("Wafer", typeof(int), typeof(WaferRobotControl));
  57. public int Wafer { get => (int)GetValue(WaferProperty); set => SetValue(WaferProperty, value); }
  58. public static readonly DependencyProperty ExtendTimeProperty = DependencyProperty.Register("ExtendTime", typeof(KeyTime), typeof(WaferRobotControl),new PropertyMetadata (KeyTime.FromTimeSpan(TimeSpan.FromSeconds(9))));
  59. public KeyTime ExtendTime { get => (KeyTime)GetValue(ExtendTimeProperty); set => SetValue(ExtendTimeProperty, value); }
  60. public static readonly DependencyProperty RobotWaferProperty = DependencyProperty.Register(
  61. "RobotWafer",
  62. typeof(WaferInfo),
  63. typeof(WaferRobotControl));
  64. public WaferInfo RobotWafer
  65. {
  66. get => (WaferInfo)GetValue(RobotWaferProperty);
  67. set => SetValue(RobotWaferProperty, value);
  68. }
  69. public static readonly DependencyProperty RobotXActionProperty = DependencyProperty.Register(
  70. "RobotXAction",
  71. typeof(WaferRobotXAction),
  72. typeof(WaferRobotControl),
  73. new PropertyMetadata(WaferRobotXAction.X_Origin, RobotXActionPropertyChangedCallback));
  74. public WaferRobotXAction RobotXAction
  75. {
  76. get => (WaferRobotXAction)GetValue(RobotXActionProperty);
  77. set => SetValue(RobotXActionProperty, value);
  78. }
  79. private static void RobotXActionPropertyChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
  80. {
  81. //KeyTime value = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(9));
  82. var control = d as WaferRobotControl;
  83. var oldAct = (WaferRobotXAction)e.OldValue;
  84. var newAct = (WaferRobotXAction)e.NewValue;
  85. switch (newAct)
  86. {
  87. case WaferRobotXAction.X_Origin:
  88. VisualStateManager.GoToState(control, newAct.ToString(), true);
  89. break;
  90. case WaferRobotXAction.Extend:
  91. if (newAct != oldAct)
  92. {
  93. VisualStateManager.GoToState(control, newAct.ToString(), true);
  94. }
  95. break;
  96. case WaferRobotXAction.Retract:
  97. if (newAct != oldAct)
  98. {
  99. VisualStateManager.GoToState(control, newAct.ToString(), true);
  100. }
  101. break;
  102. default:
  103. break;
  104. }
  105. }
  106. public static readonly DependencyProperty RobotTActionProperty = DependencyProperty.Register(
  107. "RobotTAction",
  108. typeof(WaferRobotTAction),
  109. typeof(WaferRobotControl),
  110. new PropertyMetadata(WaferRobotTAction.T_Origin, RobotTActionPropertyChangedCallback));
  111. public WaferRobotTAction RobotTAction
  112. {
  113. get => (WaferRobotTAction)GetValue(RobotTActionProperty);
  114. set => SetValue(RobotTActionProperty, value);
  115. }
  116. public string OriginT { get; set; }
  117. private static void RobotTActionPropertyChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
  118. {
  119. var control = d as WaferRobotControl;
  120. var oldAct = (WaferRobotTAction)e.OldValue;
  121. var newAct = (WaferRobotTAction)e.NewValue;
  122. if(oldAct!=newAct)
  123. {
  124. VisualStateManager.GoToState(control, newAct.ToString(), true);
  125. }
  126. }
  127. public override void OnApplyTemplate()
  128. {
  129. base.OnApplyTemplate();
  130. VisualStateManager.GoToState(this, WaferRobotXAction.X_Origin.ToString(), true);
  131. VisualStateManager.GoToState(this, OriginT, true);
  132. }
  133. }
  134. }