Axes2D.xaml.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Windows;
  7. using System.Windows.Controls;
  8. using System.Windows.Data;
  9. using System.Windows.Documents;
  10. using System.Windows.Input;
  11. using System.Windows.Media;
  12. using System.Windows.Media.Imaging;
  13. using System.Windows.Navigation;
  14. using System.Windows.Shapes;
  15. namespace Venus_Themes.UserControls
  16. {
  17. /// <summary>
  18. /// Axes2D.xaml 的交互逻辑
  19. /// </summary>
  20. public partial class Axes2D : UserControl
  21. {
  22. bool flag = false;
  23. public Axes2D()
  24. {
  25. InitializeComponent();
  26. }
  27. private void axes_Loaded(object sender, RoutedEventArgs e)
  28. {
  29. //仅触发一次绘制 不允许重复绘制
  30. if (!flag)
  31. {
  32. DrawAxisAndText();
  33. flag = true;
  34. }
  35. //DrawPoint();
  36. }
  37. //晶圆实际半径
  38. public double WaferRadius
  39. {
  40. get
  41. {
  42. return (double)GetValue(WaferRadiusProperty);
  43. }
  44. set
  45. {
  46. SetValue(WaferRadiusProperty, value);
  47. }
  48. }
  49. //传送安全半径阈值
  50. public double SafeRadius
  51. {
  52. get
  53. {
  54. return (double)GetValue(SafeRadiusProperty);
  55. }
  56. set
  57. {
  58. SetValue(SafeRadiusProperty, value);
  59. }
  60. }
  61. public double AxesWidth
  62. {
  63. get { return (double)GetValue(AxesWidthProperty); }
  64. set
  65. {
  66. SetValue(AxesWidthProperty, value);
  67. }
  68. }
  69. public double AxesHeight
  70. {
  71. get { return (double)GetValue(AxesHeightProperty); }
  72. set
  73. {
  74. SetValue(AxesHeightProperty, value);
  75. }
  76. }
  77. /// <summary>
  78. /// 存储x,y,点位信息的List
  79. /// </summary>
  80. public List<(double x, double y, int arm, string info)> PositionAndKey
  81. {
  82. get { return (List<(double x, double y, int arm, string info)>)GetValue(PositionAndKeyProperty); }
  83. set
  84. {
  85. SetValue(PositionAndKeyProperty, value);
  86. //在更新的同时 对点位数据进行重新绘制
  87. if (value != null)
  88. DrawPoint();
  89. }
  90. }
  91. private void DrawPoint()
  92. {
  93. List<UIElement> needdelete = new List<UIElement>();
  94. foreach (UIElement child in CanvasInPath.Children)
  95. {
  96. if (child.GetType() == typeof(Ellipse)) needdelete.Add(child);
  97. }
  98. foreach (UIElement i in needdelete)
  99. CanvasInPath.Children.Remove(i);
  100. float rc = 5;
  101. foreach ((double x, double y, int arm, string info) point in PositionAndKey)
  102. {
  103. Ellipse ellipse = new Ellipse()
  104. {
  105. Width = rc,
  106. Height = rc,
  107. ToolTip = point.info,
  108. Cursor = Cursors.Hand,
  109. Fill = point.arm == 1 ? new SolidColorBrush(Colors.Blue) : new SolidColorBrush(Colors.Yellow),
  110. };
  111. ToolTipService.SetShowOnDisabled(ellipse, false);
  112. ToolTipService.SetShowDuration(ellipse, 10000);
  113. Canvas.SetZIndex(ellipse, 10);//显示层级
  114. double bottom = (point.y / 10000 + 5) * (CanvasInPath.Height) / 10 - rc / 2 - .8;
  115. double left = (point.x / 10000 + 5) * (CanvasInPath.Width) / 10 - rc / 2 + .4;
  116. Canvas.SetLeft(ellipse, left);//x位置
  117. Canvas.SetBottom(ellipse, bottom);//y位置
  118. CanvasInPath.Children.Add(ellipse);
  119. }
  120. //晶圆半径示意图
  121. if (WaferRadius > 0)
  122. {
  123. double radius = (WaferRadius / 100) * (CanvasInPath.Width) / 10 * 2;
  124. Ellipse wafer = new Ellipse()
  125. {
  126. Width = radius,
  127. Height = radius,
  128. Stroke = new SolidColorBrush(Colors.Blue),
  129. StrokeThickness = 1
  130. };
  131. Canvas.SetLeft(wafer, (WaferRadius / 100 + 5) * (CanvasInPath.Width) / 10 - radius);
  132. Canvas.SetTop(wafer, (WaferRadius / 100 + 5) * (CanvasInPath.Height) / 10 - radius);
  133. Canvas.SetZIndex(wafer, 1);
  134. CanvasInPath.Children.Add(wafer);
  135. }
  136. if (SafeRadius > 0)
  137. {
  138. double radius = SafeRadius / 100 * (CanvasInPath.Width) / 10 * 2;
  139. Ellipse safer = new Ellipse()
  140. {
  141. Width = radius,
  142. Height = radius,
  143. Stroke = new SolidColorBrush(Colors.Yellow),
  144. StrokeThickness = 1
  145. };
  146. Canvas.SetLeft(safer, (SafeRadius / 100 + 5) * (CanvasInPath.Width) / 10 - radius);
  147. Canvas.SetTop(safer, (SafeRadius / 100 + 5) * (CanvasInPath.Height) / 10 - radius);
  148. Canvas.SetZIndex(safer, 1);
  149. CanvasInPath.Children.Add(safer);
  150. }
  151. }
  152. public static readonly DependencyProperty AxesWidthProperty = DependencyProperty.Register(
  153. "AxesWidth", typeof(double), typeof(Axes2D));
  154. public static readonly DependencyProperty AxesHeightProperty = DependencyProperty.Register(
  155. "AxesHeight", typeof(double), typeof(Axes2D));
  156. public static readonly DependencyProperty WaferRadiusProperty = DependencyProperty.Register(
  157. "WaferRadius", typeof(double), typeof(Axes2D));
  158. public static readonly DependencyProperty SafeRadiusProperty = DependencyProperty.Register(
  159. "SafeRadius", typeof(double), typeof(Axes2D));
  160. public static readonly DependencyProperty PositionAndKeyProperty = DependencyProperty.Register(
  161. "PositionAndKey", typeof(List<(double, double, int, string)>), typeof(Axes2D),
  162. new PropertyMetadata(null, OnDataPropertyChanged));
  163. private static void OnDataPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
  164. {
  165. if (d is Axes2D axes2)
  166. {
  167. if (e.NewValue is List<(double x, double y, int arm, string info)> postiondata)
  168. {
  169. axes2.PositionAndKey = postiondata;
  170. }
  171. }
  172. }
  173. private void DrawAxisAndText()
  174. {
  175. CanvasInPath.Width = AxesWidth;
  176. CanvasInPath.Height = AxesHeight;
  177. //笛卡尔坐标系
  178. for (int i = 0; i < 11; ++i)
  179. {
  180. //坐标线
  181. Line lineX = new Line()
  182. {
  183. X1 = (double)((decimal)CanvasInPath.Width / 10) * i,
  184. X2 = (double)((decimal)CanvasInPath.Width / 10) * i,
  185. Y1 = 0,
  186. Y2 = CanvasInPath.Height,
  187. Stroke = new SolidColorBrush(Colors.DarkGray),
  188. StrokeThickness = 1,
  189. };
  190. Line lineY = new Line()
  191. {
  192. X1 = 0,
  193. X2 = CanvasInPath.Width,
  194. Y1 = (double)((decimal)CanvasInPath.Height / 10) * i,
  195. Y2 = (double)((decimal)CanvasInPath.Height / 10) * i,
  196. Stroke = new SolidColorBrush(Colors.DarkGray),
  197. StrokeThickness = 1,
  198. };
  199. //中心和边缘线换色加重
  200. if (i == 0 || i == 10 || i == 5)
  201. {
  202. lineX.Stroke = new SolidColorBrush(Colors.Black);
  203. lineY.Stroke = new SolidColorBrush(Colors.Black);
  204. lineX.StrokeThickness = 1;
  205. lineY.StrokeThickness = 1;
  206. }
  207. else
  208. {
  209. lineX.StrokeDashArray = new DoubleCollection() { 2, 2 };
  210. lineY.StrokeDashArray = new DoubleCollection() { 2, 2 };
  211. }
  212. Canvas.SetZIndex(lineX, 0);
  213. Canvas.SetZIndex(lineY, 0);
  214. CanvasInPath.Children.Add(lineX);
  215. CanvasInPath.Children.Add(lineY);
  216. //刻度
  217. if (i < 11)
  218. {
  219. TextBlock xblock = new TextBlock();
  220. xblock.Foreground = new SolidColorBrush(Colors.Black);
  221. xblock.FontSize = 10;
  222. TranslateTransform translateTransform = new TranslateTransform(0, xblock.ActualHeight);
  223. ScaleTransform scaleTransform = new ScaleTransform();
  224. scaleTransform.ScaleY = -1;
  225. xblock.Text = (i - 5) + "";
  226. Canvas.SetLeft(xblock, TransFromX((i) * 10));
  227. Canvas.SetTop(xblock, CanvasInPath.Width + 12);
  228. CanvasInPath.Children.Add(xblock);
  229. Canvas.SetZIndex(xblock, 1);
  230. TextBlock yblock = new TextBlock();
  231. yblock.Foreground = new SolidColorBrush(Colors.Black);
  232. yblock.FontSize = 10;
  233. translateTransform = new TranslateTransform(0, yblock.ActualHeight);
  234. scaleTransform = new ScaleTransform();
  235. scaleTransform.ScaleY = -1;
  236. yblock.Text = -(i - 5) + "";
  237. Canvas.SetLeft(yblock, -12);
  238. Canvas.SetTop(yblock, TransFromY((i) * 10));
  239. CanvasInPath.Children.Add(yblock);
  240. Canvas.SetZIndex(yblock, 1);
  241. }
  242. }
  243. }
  244. private double TransFromX(double value)
  245. {
  246. return (double)(((decimal)value / 10) * (decimal)(CanvasInPath.Width) / 10 - (decimal)5);
  247. }
  248. private double TransFromY(double value)
  249. {
  250. return (double)(((decimal)value / 10) * (decimal)(CanvasInPath.Height) / 10 - (decimal)3);
  251. }
  252. protected override void OnRender(DrawingContext drawingContext)
  253. {
  254. base.OnRender(drawingContext);
  255. }
  256. }
  257. }