FoupList.xaml.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using System.Windows;
  8. using System.Windows.Controls;
  9. using System.Windows.Data;
  10. using System.Windows.Documents;
  11. using System.Windows.Input;
  12. using System.Windows.Media;
  13. using System.Windows.Media.Animation;
  14. using System.Windows.Media.Imaging;
  15. using System.Windows.Navigation;
  16. using System.Windows.Shapes;
  17. namespace FurnaceUI.Controls
  18. {
  19. /// <summary>
  20. /// FoupList.xaml 的交互逻辑
  21. /// </summary>
  22. public partial class FoupList : UserControl
  23. {
  24. public FoupList()
  25. {
  26. InitializeComponent();
  27. }
  28. /// <summary>
  29. /// 使用动画的方式来更新值
  30. /// </summary>
  31. /// <param name="value">当前的数据值信息</param>
  32. /// <param name="time">动画的时间,单位,毫秒</param>
  33. public void SetValue(float value, double time = 300)
  34. {
  35. SingleAnimation animation = new SingleAnimation(value, TimeSpan.FromMilliseconds(time));
  36. BeginAnimation(ValueProperty, animation);
  37. }
  38. // Using a DependencyProperty as the backing store for Value. This enables animation, styling, binding, etc...
  39. public static readonly DependencyProperty ValueProperty =
  40. DependencyProperty.Register("Value", typeof(float), typeof(FoupList),
  41. new PropertyMetadata(0f, new PropertyChangedCallback(RenderUpdateByPropertyChanged)));
  42. /// <summary>
  43. /// 获取或设置数值的当前值,应该处于最小值和最大值之间
  44. /// </summary>
  45. public float Value
  46. {
  47. get { return (float)GetValue(ValueProperty); }
  48. set { SetValue(ValueProperty, value); }
  49. }
  50. /// <summary>
  51. /// 获取或设置数值的起始值,默认为0
  52. /// </summary>
  53. public float ValueStart
  54. {
  55. get { return (float)GetValue(ValueStartProperty); }
  56. set { SetValue(ValueStartProperty, value); }
  57. }
  58. // Using a DependencyProperty as the backing store for ValueStart. This enables animation, styling, binding, etc...
  59. public static readonly DependencyProperty ValueStartProperty =
  60. DependencyProperty.Register("ValueStart", typeof(float), typeof(FoupList),
  61. new PropertyMetadata(0f, new PropertyChangedCallback(RenderUpdateByPropertyChanged)));
  62. /// <summary>
  63. /// 获取或设置Wafer的分割段数,最小为2,最大1000,默认为10
  64. /// </summary>
  65. public int SegmentCount
  66. {
  67. get { return (int)GetValue(SegmentCountProperty); }
  68. set { SetValue(SegmentCountProperty, value); }
  69. }
  70. // Using a DependencyProperty as the backing store for SegmentCount. This enables animation, styling, binding, etc...
  71. public static readonly DependencyProperty SegmentCountProperty =
  72. DependencyProperty.Register("SegmentCount", typeof(int), typeof(FoupList),
  73. new PropertyMetadata(25, new PropertyChangedCallback(RenderUpdateByPropertyChanged)));
  74. /// <summary>
  75. /// 获取或设置WaferList的颜色
  76. /// </summary>
  77. public Color FoupListColor
  78. {
  79. get { return (Color)GetValue(FoupListProperty); }
  80. set { SetValue(FoupListProperty, value); }
  81. }
  82. // Using a DependencyProperty as the backing store for TemperatureColor. This enables animation, styling, binding, etc...
  83. public static readonly DependencyProperty FoupListProperty =
  84. DependencyProperty.Register("FoupListColor", typeof(Color), typeof(FoupList),
  85. new PropertyMetadata(Colors.Tomato, new PropertyChangedCallback(RenderUpdateByPropertyChanged)));
  86. /// <summary>
  87. /// 获取或设置WaferList的颜色
  88. /// </summary>
  89. public Color FoupListBackColor
  90. {
  91. get { return (Color)GetValue(FoupListBackColorProperty); }
  92. set { SetValue(FoupListBackColorProperty, value); }
  93. }
  94. // Using a DependencyProperty as the backing store for TemperatureBackColor. This enables animation, styling, binding, etc...
  95. public static readonly DependencyProperty FoupListBackColorProperty =
  96. DependencyProperty.Register("FoupListBackColor", typeof(Color), typeof(FoupList),
  97. new PropertyMetadata(Colors.Silver, new PropertyChangedCallback(RenderUpdateByPropertyChanged)));
  98. /// <summary>
  99. /// 获取或设置是否显示WaferList的数值
  100. /// </summary>
  101. public bool IsRenderText
  102. {
  103. get { return (bool)GetValue(IsRenderTextProperty); }
  104. set { SetValue(IsRenderTextProperty, value); }
  105. }
  106. // Using a DependencyProperty as the backing store for IsRenderText. This enables animation, styling, binding, etc...
  107. public static readonly DependencyProperty IsRenderTextProperty =
  108. DependencyProperty.Register("IsRenderText", typeof(bool), typeof(FoupList),
  109. new PropertyMetadata(false, new PropertyChangedCallback(RenderUpdateByPropertyChanged)));
  110. /// <summary>
  111. /// 获取或设置左侧的单位显示文本,默认是空
  112. /// </summary>
  113. public string LeftUnitText
  114. {
  115. get { return (string)GetValue(LeftUnitTextProperty); }
  116. set { SetValue(LeftUnitTextProperty, value); }
  117. }
  118. // Using a DependencyProperty as the backing store for LeftUnitText. This enables animation, styling, binding, etc...
  119. public static readonly DependencyProperty LeftUnitTextProperty =
  120. DependencyProperty.Register("LeftUnitText", typeof(string), typeof(FoupList),
  121. new PropertyMetadata(" ", new PropertyChangedCallback(RenderUpdateByPropertyChanged)));
  122. /// <summary>
  123. /// 获取或设置右侧的单位显示文本,默认是空
  124. /// </summary>
  125. public string RightUnitText
  126. {
  127. get { return (string)GetValue(RightUnitTextProperty); }
  128. set { SetValue(RightUnitTextProperty, value); }
  129. }
  130. // Using a DependencyProperty as the backing store for RightUnitText. This enables animation, styling, binding, etc...
  131. public static readonly DependencyProperty RightUnitTextProperty =
  132. DependencyProperty.Register("RightUnitText", typeof(string), typeof(FoupList),
  133. new PropertyMetadata(" ", new PropertyChangedCallback(RenderUpdateByPropertyChanged)));
  134. /// <summary>
  135. /// 获取或设置右侧轴的数值和左边的关系
  136. /// </summary>
  137. [Browsable(false)]
  138. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  139. public Func<float, float> RightDataTransfer { get; set; }
  140. /// <summary>
  141. /// 获取或设置数值的最大值,默认为100
  142. /// </summary>
  143. public float ValueMax
  144. {
  145. get { return (float)GetValue(ValueMaxProperty); }
  146. set { SetValue(ValueMaxProperty, value); }
  147. }
  148. // Using a DependencyProperty as the backing store for ValueMax. This enables animation, styling, binding, etc...
  149. public static readonly DependencyProperty ValueMaxProperty =
  150. DependencyProperty.Register("ValueMax", typeof(float), typeof(FoupList),
  151. new PropertyMetadata(100f, new PropertyChangedCallback(RenderUpdateByPropertyChanged)));
  152. /// <summary>
  153. /// 当属性刷新的时候,进行强制更新绘图
  154. /// </summary>
  155. /// <param name="dependency"></param>
  156. /// <param name="e"></param>
  157. public static void RenderUpdateByPropertyChanged(DependencyObject dependency, DependencyPropertyChangedEventArgs e)
  158. {
  159. if (dependency is FoupList hslThermometer)
  160. {
  161. hslThermometer.FoupListUpdate();
  162. }
  163. }
  164. /// <inheritdoc/>
  165. protected override void OnRender(DrawingContext drawingContext)
  166. {
  167. base.OnRender(drawingContext);
  168. FoupListUpdate();
  169. }
  170. private Color colorCenter = Colors.WhiteSmoke;
  171. private Color colorBorder = Colors.Silver;
  172. private SolidColorBrush SolidColorBrush = new SolidColorBrush();
  173. /// <summary>
  174. /// 刷新界面信息
  175. /// </summary>
  176. public void FoupListUpdate()
  177. {
  178. canvas1.Children.Clear();
  179. int Width = (int)ActualWidth;
  180. int Height = (int)ActualHeight;
  181. if (Width < 20) return;
  182. if (Height < 50) return;
  183. float radius_mini = Height * 0.1f;
  184. float radius_large = Height * 0.2f;
  185. float top = radius_mini + 10;
  186. float height_mid = Height - top - 10;
  187. LinearGradientBrush linear = new LinearGradientBrush(
  188. new GradientStopCollection(new List<GradientStop>()
  189. {
  190. new GradientStop(colorCenter, 0.0f),
  191. new GradientStop(colorBorder, 0.3f),
  192. new GradientStop(colorCenter, 0.8f),
  193. new GradientStop(colorBorder, 1.0f)
  194. }),
  195. new Point(0, 0),
  196. new Point(1, 0));
  197. //WpfUtils.FillRectangle(canvas1, Width / 2.0f - radius_mini, top, radius_mini * 2, height_mid-10, FoupListBackColor);
  198. //WpfUtils.DrawRectangle(canvas1, Width / 2.0f - radius_mini, top, radius_mini * 2, height_mid - 10, FoupListBackColor, 2);
  199. double x = Width / 2.0f - radius_mini;
  200. double y = top-4;
  201. double width = radius_mini * 2;
  202. double height = height_mid;
  203. WpfUtils.DrawLine(canvas1, x, y,x+width,y, linear, 4);
  204. WpfUtils.DrawLine(canvas1, x, y+height,x+width,y+height, linear, 4);
  205. WpfUtils.DrawLine(canvas1, x+width/2.0f, y, x + width / 2.0f, y+height, linear, 8);
  206. WpfUtils.DrawLine(canvas1, x+width-15, y, x + width-15, y+height, linear, 8);
  207. // 绘制刻度线,以及刻度文本
  208. for (int i = 0; i <= SegmentCount; i++)
  209. {
  210. float valueTmp = i * (ValueMax - ValueStart) / SegmentCount + ValueStart;
  211. float paintTmp = height_mid - 10 - (valueTmp - ValueStart) / (ValueMax - ValueStart) * (height_mid - 10) + top;
  212. double lineLength = width / 2.0f;
  213. double startX = x + width / 4.0f;
  214. if (i > 0)
  215. {
  216. for (int j = 1; j < 10; j++)
  217. {
  218. // 绘制细小的刻度
  219. float segment_min = (height_mid - 10) / SegmentCount / 10 * j;
  220. if (j == 5)
  221. {
  222. WpfUtils.DrawLine(canvas1, startX - lineLength * 0.12f, paintTmp + segment_min, startX+lineLength, paintTmp + segment_min, Foreground, 1);
  223. }
  224. else
  225. {
  226. WpfUtils.DrawLine(canvas1, startX, paintTmp + segment_min, startX+lineLength, paintTmp + segment_min, Foreground, 1);
  227. }
  228. }
  229. }
  230. //WpfUtils.DrawLine(canvas1, Width / 2.0f - radius_mini - Width * 0.14f, paintTmp, Width / 2.0f - radius_mini - 4, paintTmp, Foreground, 1);
  231. // 左坐标轴
  232. //WpfUtils.DrawLine(canvas1, Width / 2.0f - radius_mini - Width * 0.1f, paintTmp, Width / 2.0f - radius_mini - 4, paintTmp, Foreground, 1);
  233. WpfUtils.DrawLine(canvas1, startX - lineLength * 0.2f, paintTmp, startX + lineLength, paintTmp, Foreground, 1);
  234. WpfUtils.DrawString(canvas1, RightUnitText, Foreground, new System.Drawing.RectangleF(5, 0, Width - 10, top - radius_mini), HorizontalAlignment.Right, VerticalAlignment.Center);
  235. //WpfUtils.DrawString(canvas1, valueTmp.ToString(), Foreground, new System.Drawing.RectangleF(-5f, paintTmp - 90, Width / 2.0f - radius_mini - Width * 0.13f, 100f), HorizontalAlignment.Right, VerticalAlignment.Bottom);
  236. float stringX = (float)(x-40);
  237. float stringY = paintTmp-20;
  238. float stringWidth = 40;
  239. float stringHeight = 40;
  240. WpfUtils.DrawString(canvas1, valueTmp.ToString(), Foreground, new System.Drawing.RectangleF(stringX, stringY, stringWidth, stringHeight), HorizontalAlignment.Left, VerticalAlignment.Center);
  241. WpfUtils.FillTriangle(canvas1,new Point(stringX+stringWidth*0.8, stringY+stringHeight*0.5),Colors.LightGreen,8,GraphDirection.Rightward);
  242. WpfUtils.DrawString(canvas1, LeftUnitText, Foreground, new System.Drawing.RectangleF(5, 0, Width - 10, top - radius_mini), HorizontalAlignment.Left, VerticalAlignment.Center);
  243. }
  244. // 绘制温度计的背景
  245. //WpfUtils.FillRectangle(canvas1, Width / 2.0f - radius_mini * 0.7f, top, radius_mini * 1.4f, height_mid - 10, linear);
  246. if (IsRenderText)
  247. {
  248. WpfUtils.DrawString(canvas1, (170-Value+1).ToString(), Foreground, Width / 2.0f - radius_large, top + height_mid+20, radius_large * 2, radius_large * 2, HorizontalAlignment.Center, VerticalAlignment.Center);
  249. }
  250. }
  251. }
  252. }