Axes2D.xaml.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  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 CyberX8_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. Fill = point.arm == 1 ? new SolidColorBrush(Colors.Blue) : new SolidColorBrush(Colors.Yellow),
  109. };
  110. Canvas.SetZIndex(ellipse, 10);//显示层级
  111. double bottom = (point.y / 10000 + 5) * (CanvasInPath.Height) / 10 - rc / 2 - .8;
  112. double left = (point.x / 10000 + 5) * (CanvasInPath.Width) / 10 - rc / 2 + .4;
  113. Canvas.SetLeft(ellipse, left);//x位置
  114. Canvas.SetBottom(ellipse, bottom);//y位置
  115. CanvasInPath.Children.Add(ellipse);
  116. }
  117. //晶圆半径示意图
  118. if (WaferRadius > 0)
  119. {
  120. double radius = (WaferRadius / 100) * (CanvasInPath.Width) / 10 * 2;
  121. Ellipse wafer = new Ellipse()
  122. {
  123. Width = radius,
  124. Height = radius,
  125. Stroke = new SolidColorBrush(Colors.Blue),
  126. StrokeThickness = 1
  127. };
  128. Canvas.SetLeft(wafer, (WaferRadius / 100 + 5) * (CanvasInPath.Width) / 10 - radius);
  129. Canvas.SetTop(wafer, (WaferRadius / 100 + 5) * (CanvasInPath.Height) / 10 - radius);
  130. Canvas.SetZIndex(wafer, 1);
  131. CanvasInPath.Children.Add(wafer);
  132. }
  133. if (SafeRadius > 0)
  134. {
  135. double radius = SafeRadius / 100 * (CanvasInPath.Width) / 10 * 2;
  136. Ellipse safer = new Ellipse()
  137. {
  138. Width = radius,
  139. Height = radius,
  140. Stroke = new SolidColorBrush(Colors.Yellow),
  141. StrokeThickness = 1
  142. };
  143. Canvas.SetLeft(safer, (SafeRadius / 100 + 5) * (CanvasInPath.Width) / 10 - radius);
  144. Canvas.SetTop(safer, (SafeRadius / 100 + 5) * (CanvasInPath.Height) / 10 - radius);
  145. Canvas.SetZIndex(safer, 1);
  146. CanvasInPath.Children.Add(safer);
  147. }
  148. }
  149. public static readonly DependencyProperty AxesWidthProperty = DependencyProperty.Register(
  150. "AxesWidth", typeof(double), typeof(Axes2D));
  151. public static readonly DependencyProperty AxesHeightProperty = DependencyProperty.Register(
  152. "AxesHeight", typeof(double), typeof(Axes2D));
  153. public static readonly DependencyProperty WaferRadiusProperty = DependencyProperty.Register(
  154. "WaferRadius", typeof(double), typeof(Axes2D));
  155. public static readonly DependencyProperty SafeRadiusProperty = DependencyProperty.Register(
  156. "SafeRadius", typeof(double), typeof(Axes2D));
  157. public static readonly DependencyProperty PositionAndKeyProperty = DependencyProperty.Register(
  158. "PositionAndKey", typeof(List<(double, double, int, string)>), typeof(Axes2D),
  159. new PropertyMetadata(null, OnDataPropertyChanged));
  160. private static void OnDataPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
  161. {
  162. if (d is Axes2D axes2)
  163. {
  164. if (e.NewValue is List<(double x, double y, int arm, string info)> postiondata)
  165. {
  166. axes2.PositionAndKey = postiondata;
  167. }
  168. }
  169. }
  170. private void DrawAxisAndText()
  171. {
  172. CanvasInPath.Width = AxesWidth;
  173. CanvasInPath.Height = AxesHeight;
  174. //笛卡尔坐标系
  175. for (int i = 0; i < 11; ++i)
  176. {
  177. //坐标线
  178. Line lineX = new Line()
  179. {
  180. X1 = (double)((decimal)CanvasInPath.Width / 10) * i,
  181. X2 = (double)((decimal)CanvasInPath.Width / 10) * i,
  182. Y1 = 0,
  183. Y2 = CanvasInPath.Height,
  184. Stroke = new SolidColorBrush(Colors.DarkGray),
  185. StrokeThickness = 1,
  186. };
  187. Line lineY = new Line()
  188. {
  189. X1 = 0,
  190. X2 = CanvasInPath.Width,
  191. Y1 = (double)((decimal)CanvasInPath.Height / 10) * i,
  192. Y2 = (double)((decimal)CanvasInPath.Height / 10) * i,
  193. Stroke = new SolidColorBrush(Colors.DarkGray),
  194. StrokeThickness = 1,
  195. };
  196. //中心和边缘线换色加重
  197. if (i == 0 || i == 10 || i == 5)
  198. {
  199. lineX.Stroke = new SolidColorBrush(Colors.Black);
  200. lineY.Stroke = new SolidColorBrush(Colors.Black);
  201. lineX.StrokeThickness = 1;
  202. lineY.StrokeThickness = 1;
  203. }
  204. else
  205. {
  206. lineX.StrokeDashArray = new DoubleCollection() { 2, 2 };
  207. lineY.StrokeDashArray = new DoubleCollection() { 2, 2 };
  208. }
  209. Canvas.SetZIndex(lineX, 0);
  210. Canvas.SetZIndex(lineY, 0);
  211. CanvasInPath.Children.Add(lineX);
  212. CanvasInPath.Children.Add(lineY);
  213. //刻度
  214. if (i < 11)
  215. {
  216. TextBlock xblock = new TextBlock();
  217. xblock.Foreground = new SolidColorBrush(Colors.Black);
  218. xblock.FontSize = 10;
  219. TranslateTransform translateTransform = new TranslateTransform(0, xblock.ActualHeight);
  220. ScaleTransform scaleTransform = new ScaleTransform();
  221. scaleTransform.ScaleY = -1;
  222. xblock.Text = (i - 5) + "";
  223. Canvas.SetLeft(xblock, TransFromX((i) * 10));
  224. Canvas.SetTop(xblock, CanvasInPath.Width + 12);
  225. CanvasInPath.Children.Add(xblock);
  226. Canvas.SetZIndex(xblock, 1);
  227. TextBlock yblock = new TextBlock();
  228. yblock.Foreground = new SolidColorBrush(Colors.Black);
  229. yblock.FontSize = 10;
  230. translateTransform = new TranslateTransform(0, yblock.ActualHeight);
  231. scaleTransform = new ScaleTransform();
  232. scaleTransform.ScaleY = -1;
  233. yblock.Text = -(i - 5) + "";
  234. Canvas.SetLeft(yblock, -12);
  235. Canvas.SetTop(yblock, TransFromY((i) * 10));
  236. CanvasInPath.Children.Add(yblock);
  237. Canvas.SetZIndex(yblock, 1);
  238. }
  239. }
  240. }
  241. private double TransFromX(double value)
  242. {
  243. return (double)(((decimal)value / 10) * (decimal)(CanvasInPath.Width) / 10 - (decimal)5);
  244. }
  245. private double TransFromY(double value)
  246. {
  247. return (double)(((decimal)value / 10) * (decimal)(CanvasInPath.Height) / 10 - (decimal)3);
  248. }
  249. protected override void OnRender(DrawingContext drawingContext)
  250. {
  251. base.OnRender(drawingContext);
  252. }
  253. }
  254. }