终端一体化运控平台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

346 lines
14 KiB

  1. using BPASmartClient.Compiler;
  2. using Newtonsoft.Json;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Collections.ObjectModel;
  6. using System.ComponentModel;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using System.Windows;
  11. using System.Windows.Controls;
  12. using System.Windows.Data;
  13. using System.Windows.Documents;
  14. using System.Windows.Input;
  15. using System.Windows.Media;
  16. using System.Windows.Media.Animation;
  17. using System.Windows.Media.Imaging;
  18. using System.Windows.Navigation;
  19. using System.Windows.Shapes;
  20. namespace BPASmartClient.SCADAControl.CustomerControls
  21. {
  22. /// <summary>
  23. /// 滚筒线
  24. /// NewConveyorBelt.xaml 的交互逻辑
  25. /// </summary>
  26. public partial class NewConveyorBelt : UserControl, IExecutable
  27. {
  28. #region 临时变量
  29. TextBlock textBlock = null;
  30. Path Path_mp = null;
  31. Path Path_cb = null;
  32. Storyboard storyboard = new Storyboard();
  33. Storyboard storyboard1 = new Storyboard();
  34. #endregion
  35. public event EventHandler PropertyChange; //声明一个事件
  36. public NewConveyorBelt()
  37. {
  38. InitializeComponent();
  39. Width = 1200;
  40. Height = 400;
  41. this.SizeChanged += ConveyorBelt_SizeChanged;
  42. ConveyorBeltWidth = 70;
  43. Direction = 0;
  44. StrokeBrush = new SolidColorBrush((System.Windows.Media.Color)System.Windows.Media.ColorConverter.ConvertFromString("#00BEFA"));
  45. StrokeDashArray = new DoubleCollection { 1.5, 1.5 };
  46. StrokeFillBrush = new SolidColorBrush((System.Windows.Media.Color)System.Windows.Media.ColorConverter.ConvertFromString("#00BEFA"));
  47. StrokeThickness = 2;
  48. }
  49. public string ControlType => "滚动线";
  50. private bool isExecuteState;
  51. public bool IsExecuteState
  52. {
  53. get { return isExecuteState; }
  54. set
  55. {
  56. isExecuteState = value;
  57. if (IsExecuteState)
  58. {
  59. IsEnabled = true;
  60. Register();
  61. }
  62. }
  63. }
  64. #region 内部函数
  65. public void VisualStateManagerData()
  66. {
  67. storyboard.RepeatBehavior = RepeatBehavior.Forever;
  68. DoubleAnimation dbAscending = new DoubleAnimation
  69. {
  70. From = 0,
  71. To = 100,
  72. Duration = new Duration(new TimeSpan(0, 0, 20)),
  73. };
  74. storyboard.Children.Add(dbAscending);
  75. Storyboard.SetTarget(dbAscending, Path_mp);
  76. Storyboard.SetTargetProperty(dbAscending, new PropertyPath("StrokeDashOffset"));
  77. storyboard1.RepeatBehavior = RepeatBehavior.Forever;
  78. DoubleAnimation dbAscending1 = new DoubleAnimation
  79. {
  80. From = 0,
  81. To = -100,
  82. Duration = new Duration(new TimeSpan(0, 0, 20)),
  83. };
  84. storyboard1.Children.Add(dbAscending1);
  85. Storyboard.SetTarget(dbAscending1, Path_mp);
  86. Storyboard.SetTargetProperty(dbAscending1, new PropertyPath("StrokeDashOffset"));
  87. Refursh();
  88. }
  89. private void ConveyorBelt_SizeChanged(object sender, SizeChangedEventArgs e)
  90. {
  91. //查找
  92. if (!(Path_cb != null && Path_mp != null))
  93. {
  94. foreach (Path tb in FindVisualChildren<Path>(this))
  95. {
  96. // do something with tb here
  97. if (tb.Tag != null)
  98. {
  99. if (tb.Tag.ToString() == "cb")
  100. {
  101. Path_cb = tb;
  102. }
  103. else if (tb.Tag.ToString() == "mp")
  104. {
  105. Path_mp = tb;
  106. }
  107. }
  108. }
  109. VisualStateManagerData();
  110. }
  111. if (textBlock == null)
  112. {
  113. foreach (TextBlock tb in FindVisualChildren<TextBlock>(this))
  114. {
  115. // do something with tb here
  116. if (tb.Tag != null)
  117. {
  118. if (tb.Tag.ToString() == "标题")
  119. {
  120. textBlock = tb;
  121. }
  122. }
  123. }
  124. }
  125. if (this.Height > 0 && this.Width > 0)
  126. {
  127. try
  128. {
  129. //传送带外边框绘制
  130. PathGeometry geometry = new PathGeometry();
  131. PathFigure pathFigure = new PathFigure();
  132. pathFigure.StartPoint = new Point(this.Height / 2, 0);
  133. pathFigure.Segments.Add(new ArcSegment(new Point(this.Height / 2, this.Height), new Size(this.Height / 2, this.Height / 2), 0, false, SweepDirection.Counterclockwise, true));
  134. pathFigure.Segments.Add(new LineSegment(new Point(this.Width, this.Height), true));
  135. pathFigure.Segments.Add(new LineSegment(new Point(this.Width, this.Height - ConveyorBeltWidth), true));
  136. double innerCircle = (this.Height - (ConveyorBeltWidth * 2)) / 2;//内圆半径
  137. pathFigure.Segments.Add(new LineSegment(new Point(ConveyorBeltWidth + innerCircle, this.Height - ConveyorBeltWidth), true));
  138. pathFigure.Segments.Add(new ArcSegment(new Point(ConveyorBeltWidth + innerCircle, ConveyorBeltWidth), new Size(innerCircle, innerCircle), 0, false, SweepDirection.Clockwise, true));
  139. pathFigure.Segments.Add(new LineSegment(new Point(this.Width, ConveyorBeltWidth), true));
  140. pathFigure.Segments.Add(new LineSegment(new Point(this.Width, 0), true));
  141. pathFigure.Segments.Add(new LineSegment(new Point(this.Height / 2, 0), true));
  142. geometry.Figures.Add(pathFigure);
  143. Path_cb.Data = geometry;
  144. //传送带内部皮带绘制
  145. PathGeometry geometry1 = new PathGeometry();
  146. PathFigure pathFigure1 = new PathFigure();
  147. pathFigure1.StartPoint = new Point(this.Width, ConveyorBeltWidth / 2);
  148. double innerCircle1 = (this.Height - ConveyorBeltWidth) / 2;//内圆半径
  149. pathFigure1.Segments.Add(new LineSegment(new Point(innerCircle1 + ConveyorBeltWidth / 2, ConveyorBeltWidth / 2), true));
  150. pathFigure1.Segments.Add(new ArcSegment(new Point(innerCircle1 + ConveyorBeltWidth / 2, this.Height - ConveyorBeltWidth / 2), new Size(innerCircle1, innerCircle1), 0, false, SweepDirection.Counterclockwise, true));
  151. pathFigure1.Segments.Add(new LineSegment(new Point(this.Width, this.Height - ConveyorBeltWidth / 2), true));
  152. geometry1.Figures.Add(pathFigure1);
  153. Path_mp.Data = geometry1;
  154. }
  155. catch (Exception ex)
  156. {
  157. }
  158. }
  159. }
  160. public static IEnumerable<T> FindVisualChildren<T>(DependencyObject depObj) where T : DependencyObject
  161. {
  162. if (depObj != null)
  163. {
  164. for (int i = 0; i < VisualTreeHelper.GetChildrenCount(depObj); i++)
  165. {
  166. DependencyObject child = VisualTreeHelper.GetChild(depObj, i);
  167. if (child != null && child is T)
  168. {
  169. yield return (T)child;
  170. }
  171. foreach (T childOfChild in FindVisualChildren<T>(child))
  172. {
  173. yield return childOfChild;
  174. }
  175. }
  176. }
  177. }
  178. #endregion
  179. #region 属性
  180. private static void OnPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
  181. {
  182. (d as NewConveyorBelt)?.Refursh();
  183. }
  184. public DoubleCollection StrokeDashArray
  185. {
  186. get { return (DoubleCollection)GetValue(StrokeDashArrayProperty); }
  187. set { SetValue(StrokeDashArrayProperty, value); }
  188. }
  189. public static readonly DependencyProperty StrokeDashArrayProperty =
  190. DependencyProperty.Register("StrokeDashArray", typeof(DoubleCollection), typeof(NewConveyorBelt),
  191. new PropertyMetadata(default, new PropertyChangedCallback(OnPropertyChanged)));
  192. public double ConveyorBeltWidth
  193. {
  194. get { return (double)GetValue(ConveyorBeltWidthProperty); }
  195. set { SetValue(ConveyorBeltWidthProperty, value); }
  196. }
  197. public static readonly DependencyProperty ConveyorBeltWidthProperty =
  198. DependencyProperty.Register("ConveyorBeltWidth", typeof(double), typeof(NewConveyorBelt),
  199. new PropertyMetadata(50.0, new PropertyChangedCallback(OnPropertyChanged)));
  200. public Brush StrokeFillBrush
  201. {
  202. get { return (Brush)GetValue(StrokeFillBrushProperty); }
  203. set { SetValue(StrokeFillBrushProperty, value); }
  204. }
  205. public static readonly DependencyProperty StrokeFillBrushProperty =
  206. DependencyProperty.Register("StrokeFillBrush", typeof(Brush), typeof(NewConveyorBelt),
  207. new PropertyMetadata(Brushes.LightBlue, new PropertyChangedCallback(OnPropertyChanged)));
  208. public Brush StrokeBrush
  209. {
  210. get { return (Brush)GetValue(StrokeBrushProperty); }
  211. set { SetValue(StrokeBrushProperty, value); }
  212. }
  213. public static readonly DependencyProperty StrokeBrushProperty =
  214. DependencyProperty.Register("StrokeBrush", typeof(Brush), typeof(NewConveyorBelt),
  215. new PropertyMetadata(Brushes.LightBlue, new PropertyChangedCallback(OnPropertyChanged)));
  216. public double StrokeThickness
  217. {
  218. get { return (double)GetValue(StrokeThicknessProperty); }
  219. set { SetValue(StrokeThicknessProperty, value); }
  220. }
  221. public static readonly DependencyProperty StrokeThicknessProperty =
  222. DependencyProperty.Register("StrokeThickness", typeof(double), typeof(NewConveyorBelt),
  223. new PropertyMetadata(1.0, new PropertyChangedCallback(OnPropertyChanged)));
  224. [Category("值设定")]
  225. public int Direction
  226. {
  227. get { return (int)GetValue(DirectionProperty); }
  228. set { SetValue(DirectionProperty, value); }
  229. }
  230. public static readonly DependencyProperty DirectionProperty =
  231. DependencyProperty.Register("Direction", typeof(int), typeof(NewConveyorBelt),
  232. new PropertyMetadata(0, new PropertyChangedCallback(OnPropertyChanged)));
  233. [Category("值设定")]
  234. public string Text
  235. {
  236. get { return (string)GetValue(TextProperty); }
  237. set { SetValue(TextProperty, value); }
  238. }
  239. public static readonly DependencyProperty TextProperty =
  240. DependencyProperty.Register("Text", typeof(string), typeof(NewConveyorBelt), new PropertyMetadata(new PropertyChangedCallback(onTargetChanged)));
  241. private static void onTargetChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) => (d as NewConveyorBelt)?.TargetRefresh();
  242. [Category("主题订阅")]
  243. public string ConveyorBeltLeft
  244. {
  245. get { return (string)GetValue(ConveyorBeltLeftProperty); }
  246. set { SetValue(ConveyorBeltLeftProperty, value); }
  247. }
  248. public static readonly DependencyProperty ConveyorBeltLeftProperty =
  249. DependencyProperty.Register("ConveyorBeltLeft", typeof(string), typeof(NewConveyorBelt), new PropertyMetadata(string.Empty));
  250. [Category("主题订阅")]
  251. public string ConveyorBeltRight
  252. {
  253. get { return (string)GetValue(ConveyorBeltRightProperty); }
  254. set { SetValue(ConveyorBeltRightProperty, value); }
  255. }
  256. public static readonly DependencyProperty ConveyorBeltRightProperty =
  257. DependencyProperty.Register("ConveyorBeltRight", typeof(string), typeof(NewConveyorBelt), new PropertyMetadata(string.Empty));
  258. [Category("主题订阅")]
  259. public string ConveyorBeltStop
  260. {
  261. get { return (string)GetValue(ConveyorBeltStopProperty); }
  262. set { SetValue(ConveyorBeltStopProperty, value); }
  263. }
  264. public static readonly DependencyProperty ConveyorBeltStopProperty =
  265. DependencyProperty.Register("ConveyorBeltStop", typeof(string), typeof(NewConveyorBelt), new PropertyMetadata(string.Empty));
  266. #endregion
  267. #region 属性变更事件
  268. List<string> MessageNameL = null;
  269. public void Register()
  270. {
  271. }
  272. private void Refursh()
  273. {
  274. if (Direction == 1)
  275. {
  276. storyboard.Begin();
  277. storyboard1.Stop();
  278. }
  279. else if (Direction == 2)
  280. {
  281. storyboard.Stop();
  282. storyboard1.Begin();
  283. }
  284. else
  285. {
  286. storyboard.Stop();
  287. storyboard1.Stop();
  288. }
  289. }
  290. /// <summary>
  291. /// 目标属性刷新
  292. /// </summary>
  293. public void TargetRefresh()
  294. {
  295. if (textBlock != null )
  296. {
  297. textBlock.Text = Text;
  298. }
  299. }
  300. public void RunNameRefresh()
  301. {
  302. }
  303. /// <summary>
  304. /// 接收数据改变
  305. /// </summary>
  306. public void ReceiveNameRefresh()
  307. {
  308. }
  309. #endregion
  310. }
  311. }