SusceptorNotchControl.xaml.cs 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Windows;
  6. using System.Windows.Controls;
  7. using System.Windows.Data;
  8. using System.Windows.Documents;
  9. using System.Windows.Input;
  10. using System.Windows.Media;
  11. using System.Windows.Media.Imaging;
  12. using System.Windows.Navigation;
  13. using System.Windows.Shapes;
  14. using Aitex.Core.Equipment.SusceptorDefine;
  15. namespace Aitex.Core.UI.Control
  16. {
  17. /// <summary>
  18. /// Interaction logic for SusceptorNotchControl.xaml
  19. /// </summary>
  20. public partial class SusceptorNotchControl : UserControl
  21. {
  22. public Action<SusceptorNotchControl, bool> MouseDownCallback;
  23. public int Index { get; set; }
  24. public bool IsInputValid { private set; get; }
  25. public static readonly DependencyProperty DisplayIndexProperty = DependencyProperty.Register(
  26. "DisplayIndex", typeof(int), typeof(SusceptorNotchControl),
  27. new FrameworkPropertyMetadata(0, FrameworkPropertyMetadataOptions.AffectsRender));
  28. public int DisplayIndex
  29. {
  30. get
  31. {
  32. return (int)GetValue(DisplayIndexProperty);
  33. }
  34. set
  35. {
  36. SetValue(DisplayIndexProperty, value);
  37. }
  38. }
  39. public static readonly DependencyProperty CurrentSusceptorStatusProperty = DependencyProperty.Register(
  40. "CurrentSusceptorStatus", typeof(SusceptorStatus), typeof(SusceptorNotchControl),
  41. new FrameworkPropertyMetadata(SusceptorStatus.Empty, FrameworkPropertyMetadataOptions.AffectsRender));
  42. public SusceptorStatus CurrentSusceptorStatus
  43. {
  44. get
  45. {
  46. return (SusceptorStatus)GetValue(CurrentSusceptorStatusProperty);
  47. }
  48. set
  49. {
  50. SetValue(CurrentSusceptorStatusProperty, value);
  51. }
  52. }
  53. public static readonly DependencyProperty CurrentWaferStatusProperty = DependencyProperty.Register(
  54. "CurrentWaferStatus", typeof(WaferStatus), typeof(SusceptorNotchControl),
  55. new FrameworkPropertyMetadata(WaferStatus.Normal, FrameworkPropertyMetadataOptions.AffectsRender));
  56. public WaferStatus CurrentWaferStatus
  57. {
  58. get
  59. {
  60. return (WaferStatus)GetValue(CurrentWaferStatusProperty);
  61. }
  62. set
  63. {
  64. SetValue(CurrentWaferStatusProperty, value);
  65. }
  66. }
  67. public static readonly DependencyProperty CurrentWaferTypeProperty = DependencyProperty.Register(
  68. "CurrentWaferType", typeof(WaferType), typeof(SusceptorNotchControl),
  69. new FrameworkPropertyMetadata(WaferType.Empty, FrameworkPropertyMetadataOptions.AffectsRender));
  70. public WaferType CurrentWaferType
  71. {
  72. get
  73. {
  74. return (WaferType)GetValue(CurrentWaferTypeProperty);
  75. }
  76. set
  77. {
  78. SetValue(CurrentWaferTypeProperty, value);
  79. }
  80. }
  81. //如果Ture,鼠标在notch上面移动,显示颜色变化
  82. public static readonly DependencyProperty IsActiveProperty = DependencyProperty.Register(
  83. "IsActive", typeof(Boolean), typeof(SusceptorNotchControl),
  84. new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.AffectsRender));
  85. public bool IsActive
  86. {
  87. get
  88. {
  89. return (bool)GetValue(IsActiveProperty);
  90. }
  91. set
  92. {
  93. SetValue(IsActiveProperty, value);
  94. }
  95. }
  96. //如果Ture,nnotch可以编辑
  97. public static readonly DependencyProperty IsReadonlyProperty = DependencyProperty.Register(
  98. "IsReadonly", typeof(Boolean), typeof(SusceptorNotchControl),
  99. new FrameworkPropertyMetadata(true, FrameworkPropertyMetadataOptions.AffectsRender));
  100. public bool IsReadonly
  101. {
  102. get
  103. {
  104. return (bool)GetValue(IsReadonlyProperty);
  105. }
  106. set
  107. {
  108. SetValue(IsReadonlyProperty, value);
  109. }
  110. }
  111. public SusceptorNotchControl()
  112. {
  113. InitializeComponent();
  114. }
  115. public void Update()
  116. {
  117. textBoxWafer.Text = DisplayIndex.ToString();
  118. textBoxWafer.Background = SusceptorBrush.GetNotchBackgroundBrush(CurrentSusceptorStatus, CurrentWaferType, CurrentWaferStatus);
  119. }
  120. protected override void OnRender(DrawingContext drawingContext)
  121. {
  122. Update();
  123. }
  124. private void Label_MouseEnter(object sender, MouseEventArgs e)
  125. {
  126. if (!IsActive) return;
  127. if (CurrentWaferType == WaferType.Empty)
  128. textBoxWafer.Background = SusceptorBrush.OnEnteringBrush;
  129. }
  130. private void Label_MouseLeave(object sender, MouseEventArgs e)
  131. {
  132. if (!IsActive) return;
  133. if (CurrentWaferType == WaferType.Empty)
  134. textBoxWafer.Background = SusceptorBrush.EmptyBrush;
  135. }
  136. private void Label_MouseDown(object sender, MouseButtonEventArgs e)
  137. {
  138. if (IsActive && MouseDownCallback != null)
  139. {
  140. MouseDownCallback.Invoke(this, IsReadonly &&( Keyboard.IsKeyDown(Key.LeftShift)||Keyboard.IsKeyDown(Key.RightShift)));
  141. }
  142. e.Handled = false;
  143. }
  144. private void textBoxWafer_TextChanged(object sender, TextChangedEventArgs e)
  145. {
  146. int result;
  147. IsInputValid = !string.IsNullOrWhiteSpace(textBoxWafer.Text) && int.TryParse(textBoxWafer.Text, out result);
  148. Rectangle r = FindFirstVisualChild<Rectangle>(textBoxWafer, "rectangle1");
  149. if (r != null)
  150. r.Stroke = new SolidColorBrush(IsInputValid ? Colors.Black : Colors.Red);
  151. }
  152. T FindFirstVisualChild<T>(DependencyObject obj, string childName) where T : DependencyObject
  153. {
  154. for (int i = 0; i < VisualTreeHelper.GetChildrenCount(obj); i++)
  155. {
  156. DependencyObject child = VisualTreeHelper.GetChild(obj, i);
  157. if (child is T && child.GetValue(NameProperty).ToString() == childName)
  158. {
  159. return (T)child;
  160. }
  161. else
  162. {
  163. T childOfChild = FindFirstVisualChild<T>(child, childName);
  164. if (childOfChild != null)
  165. {
  166. return childOfChild;
  167. }
  168. }
  169. }
  170. return null;
  171. }
  172. }
  173. }