PocketRawDataChart.xaml.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  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 Abt.Controls.SciChart.Visuals.Annotations;
  15. using Aitex.Core.UI.ControlDataContext;
  16. using Aitex.Core.Equipment.SusceptorDefine;
  17. namespace Aitex.Core.UI.Control
  18. {
  19. /// <summary>
  20. /// Interaction logic for PocketRawDataChart.xaml
  21. /// </summary>
  22. public partial class PocketRawDataChart : UserControl
  23. {
  24. public static readonly DependencyProperty SetDummyCommandProperty = DependencyProperty.Register(
  25. "SetDummyCommand", typeof(ICommand), typeof(PocketRawDataChart),
  26. new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.AffectsRender));
  27. public ICommand SetDummyCommand
  28. {
  29. get
  30. {
  31. return (ICommand)this.GetValue(SetDummyCommandProperty);
  32. }
  33. set
  34. {
  35. this.SetValue(SetDummyCommandProperty, value);
  36. }
  37. }
  38. public static readonly DependencyProperty PocketInfoProperty = DependencyProperty.Register(
  39. "PocketInfo", typeof(PocketItem[]), typeof(PocketRawDataChart), new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.AffectsRender));
  40. public PocketItem[] PocketInfo
  41. {
  42. get
  43. {
  44. return (PocketItem[])this.GetValue(PocketInfoProperty);
  45. }
  46. set
  47. {
  48. this.SetValue(PocketInfoProperty, value);
  49. }
  50. }
  51. public static readonly DependencyProperty EnableTemperatureProperty = DependencyProperty.Register(
  52. "EnableTemperature", typeof(bool), typeof(PocketRawDataChart), new PropertyMetadata(false));
  53. public bool EnableTemperature
  54. {
  55. get { return (bool)GetValue(EnableTemperatureProperty); }
  56. set { SetValue(EnableTemperatureProperty, value); }
  57. }
  58. VerticalLineAnnotation[] _pocketLines;
  59. VerticalLineAnnotation[] _pocketNumbers;
  60. BoxAnnotation[] _waferBoxs;
  61. PocketItem[] _currentPocketInfo;
  62. public PocketRawDataChart()
  63. {
  64. InitializeComponent();
  65. SetBinding(PocketRawDataChart.PocketInfoProperty, new Binding("PocketInfo") { });
  66. SetBinding(PocketRawDataChart.SetDummyCommandProperty, new Binding("SetDummyCommand") { });
  67. }
  68. protected override void OnRender(DrawingContext drawingContext)
  69. {
  70. base.OnRender(drawingContext);
  71. bool isPocketEqual = false;
  72. if (PocketInfo!=null && _currentPocketInfo != null && _currentPocketInfo.Length==PocketInfo.Length)
  73. {
  74. for (int i=0; i<_currentPocketInfo.Length; i++)
  75. {
  76. if ((_currentPocketInfo[i].DisplayIndex != PocketInfo[i].DisplayIndex)
  77. ||(_currentPocketInfo[i].Status != PocketInfo[i].Status)
  78. || (_currentPocketInfo[i].Type != PocketInfo[i].Type))
  79. {
  80. isPocketEqual = false;
  81. break;
  82. }
  83. isPocketEqual = true;
  84. }
  85. }
  86. if (isPocketEqual)
  87. return;
  88. if (_pocketLines != null)
  89. {
  90. foreach (VerticalLineAnnotation ann in _pocketLines)
  91. sciChart.Annotations.Remove(ann);
  92. }
  93. if (_pocketNumbers != null)
  94. {
  95. foreach (VerticalLineAnnotation ann in _pocketNumbers)
  96. sciChart.Annotations.Remove(ann);
  97. }
  98. if (_waferBoxs != null)
  99. {
  100. foreach (BoxAnnotation ann in _waferBoxs)
  101. sciChart.Annotations.Remove(ann);
  102. }
  103. if (PocketInfo!=null && PocketInfo.Length>0)
  104. {
  105. _pocketLines = new VerticalLineAnnotation[PocketInfo.Length - 1];
  106. for (int i = 0; i < _pocketLines.Length; i++)
  107. {
  108. _pocketLines[i] = new VerticalLineAnnotation();
  109. _pocketLines[i].YAxisId = "TemperatureYAxis";
  110. sciChart.Annotations.Add(_pocketLines[i]);
  111. }
  112. _pocketNumbers = new VerticalLineAnnotation[PocketInfo.Length];
  113. for (int i = 0; i < PocketInfo.Length; i++)
  114. {
  115. _pocketNumbers[i] = new VerticalLineAnnotation();
  116. _pocketNumbers[i].YAxisId = "TemperatureYAxis";
  117. _pocketNumbers[i].ShowLabel = true;
  118. _pocketNumbers[i].LabelValue = PocketInfo[i].DisplayIndex;
  119. _pocketNumbers[i].StrokeThickness = 0;
  120. _pocketNumbers[i].Stroke = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Color.FromRgb(214, 214, 214));
  121. sciChart.Annotations.Add(_pocketNumbers[i]);
  122. }
  123. _waferBoxs = new BoxAnnotation[PocketInfo.Length];
  124. for (int i = 0; i < PocketInfo.Length; i++)
  125. {
  126. _waferBoxs[i] = new BoxAnnotation();
  127. _waferBoxs[i].YAxisId = "TemperatureYAxis";
  128. _waferBoxs[i].Visibility = Visibility.Hidden;
  129. _waferBoxs[i].Background = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Color.FromArgb(0x55, 0x55, 0x55, 0x55));
  130. _waferBoxs[i].BorderBrush = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Color.FromRgb(0x55, 0x55, 0x55));
  131. _waferBoxs[i].CornerRadius = new CornerRadius(3);
  132. _waferBoxs[i].X1 = 0;
  133. }
  134. XAxis_Arranged(null, null);
  135. }
  136. _currentPocketInfo = PocketInfo;
  137. if (_waferBoxs != null)
  138. {
  139. for (int i = 0; i < _waferBoxs.Length; i++)
  140. {
  141. if (_currentPocketInfo != null && (_currentPocketInfo[i].Status != WaferStatus.Dummy) && (_currentPocketInfo[i].Type != WaferType.Empty))
  142. {
  143. if (!sciChart.Annotations.Contains(_waferBoxs[i]))
  144. sciChart.Annotations.Add(_waferBoxs[i]);
  145. }
  146. else
  147. {
  148. sciChart.Annotations.Remove(_waferBoxs[i]);
  149. }
  150. }
  151. }
  152. }
  153. private void sciChart_MouseLeave(object sender, MouseEventArgs e)
  154. {
  155. if (DataContext == null)
  156. return;
  157. maskAnnotation.X1 = maskAnnotation.X2 = 0;
  158. }
  159. private void sciChart_MouseMove(object sender, MouseEventArgs e)
  160. {
  161. if (PocketInfo == null)
  162. return;
  163. int pocketIndex = (int)((e.GetPosition(sciChart).X - 40) / ((sciChart.ActualWidth - 40 - 35 - 35) / PocketInfo.Length)) + 1;
  164. double maskInterval = sciChart.XAxis.VisibleRange.AsDoubleRange().Diff / PocketInfo.Length;
  165. maskAnnotation.X1 = sciChart.XAxis.VisibleRange.AsDoubleRange().Min + maskInterval * (pocketIndex - 1) + maskInterval * 0.1;
  166. maskAnnotation.X2 = sciChart.XAxis.VisibleRange.AsDoubleRange().Min + maskInterval * pocketIndex - maskInterval * 0.1;
  167. }
  168. private void TemperatureYAxis_Arranged(object sender, EventArgs e)
  169. {
  170. if (PocketInfo == null)
  171. return;
  172. if (sciChart.YAxes[0].VisibleRange != null)
  173. {
  174. maskAnnotation.Y1 = sciChart.YAxes[0].VisibleRange.AsDoubleRange().Max;
  175. maskAnnotation.Y2 = sciChart.YAxes[0].VisibleRange.AsDoubleRange().Min;
  176. if (_waferBoxs != null)
  177. {
  178. for (int i = 0; i < _waferBoxs.Length; i++)
  179. {
  180. _waferBoxs[i].Y1 = sciChart.YAxes[0].VisibleRange.AsDoubleRange().Max;
  181. _waferBoxs[i].Y2 = sciChart.YAxes[0].VisibleRange.AsDoubleRange().Min;
  182. }
  183. }
  184. }
  185. }
  186. private void XAxis_Arranged(object sender, EventArgs e)
  187. {
  188. if (PocketInfo == null)
  189. return;
  190. int pocketNumber = PocketInfo.Length;
  191. if (pocketNumber == 0)
  192. return;
  193. double pocketInterval = sciChart.XAxis.VisibleRange.AsDoubleRange().Diff / pocketNumber;
  194. if (_pocketLines != null)
  195. {
  196. for (int i = 0; i < _pocketLines.Length; i++)
  197. {
  198. _pocketLines[i].X1 = sciChart.XAxis.VisibleRange.AsDoubleRange().Min + (i + 1) * pocketInterval;
  199. _pocketLines[i].X2 = sciChart.XAxis.VisibleRange.AsDoubleRange().Min + (i + 1) * pocketInterval;
  200. _pocketLines[i].Y1 = sciChart.YAxes[0].VisibleRange.AsDoubleRange().Max;
  201. _pocketLines[i].Y2 = 0;
  202. }
  203. }
  204. if (_pocketNumbers != null)
  205. {
  206. for (int i = 0; i < _pocketNumbers.Length; i++)
  207. {
  208. _pocketNumbers[i].X1 = sciChart.XAxis.VisibleRange.AsDoubleRange().Min + pocketInterval * i + pocketInterval / 2;
  209. }
  210. }
  211. if (_waferBoxs != null)
  212. {
  213. double maskInterval = sciChart.XAxis.VisibleRange.AsDoubleRange().Diff / pocketNumber;
  214. for (int i = 0; i < _waferBoxs.Length; i++)
  215. {
  216. _waferBoxs[i].X1 = sciChart.XAxis.VisibleRange.AsDoubleRange().Min + maskInterval * i + maskInterval * 0.1;
  217. _waferBoxs[i].X2 = sciChart.XAxis.VisibleRange.AsDoubleRange().Min + maskInterval * (i + 1) - maskInterval * 0.1;
  218. }
  219. }
  220. }
  221. private void sciChart_MouseDoubleClick(object sender, MouseButtonEventArgs e)
  222. {
  223. if (SetDummyCommand == null)
  224. return;
  225. if (!this.IsEnabled)
  226. return;
  227. if (PocketInfo == null)
  228. return;
  229. int pocketIndex = (int)((e.GetPosition(sciChart).X - 40) / ((sciChart.ActualWidth - 40 - 35 - 35) / PocketInfo.Length));
  230. if (PocketInfo[pocketIndex].Type == WaferType.Empty)
  231. return;
  232. if (MessageBox.Show(String.Format("请确认是否将第{0}片设置为{1}?", PocketInfo[pocketIndex].DisplayIndex, PocketInfo[pocketIndex].Status == WaferStatus.Dummy ? "正片" : "陪片"), "确认", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.No)
  233. return;
  234. SetDummyCommand.Execute(new object[] { PocketInfo[pocketIndex].Index, PocketInfo[pocketIndex].Status == WaferStatus.Dummy ? WaferStatus.Normal : WaferStatus.Dummy});
  235. }
  236. }
  237. }