PipeLineThree.xaml.cs 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434
  1. using DocumentFormat.OpenXml.InkML;
  2. using System;
  3. using System.Collections.Generic;
  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 MECF.Framework.UI.Client.IndustrialControl
  18. {
  19. /// <summary>
  20. /// HslPipeLineThree.xaml 的交互逻辑
  21. /// </summary>
  22. public partial class PipeLineThree : UserControl
  23. {
  24. public PipeLineThree()
  25. {
  26. InitializeComponent();
  27. }
  28. protected override void OnInitialized(EventArgs e)
  29. {
  30. base.OnInitialized(e);
  31. PipeWidthUpdate();
  32. }
  33. /// <summary>
  34. /// 获取或设置管道控件的边缘颜色
  35. /// </summary>
  36. public Color EdgeColor
  37. {
  38. get { return (Color)GetValue(EdgeColorProperty); }
  39. set { SetValue(EdgeColorProperty, value); }
  40. }
  41. // Using a DependencyProperty as the backing store for EdgeColor. This enables animation, styling, binding, etc...
  42. public static readonly DependencyProperty EdgeColorProperty =
  43. DependencyProperty.Register("EdgeColor", typeof(Color), typeof(PipeLineThree), new PropertyMetadata(Colors.DimGray));
  44. /// <summary>
  45. /// 管道的中心颜色
  46. /// </summary>
  47. public Color CenterColor
  48. {
  49. get { return (Color)GetValue(CenterColorProperty); }
  50. set { SetValue(CenterColorProperty, value); }
  51. }
  52. // Using a DependencyProperty as the backing store for CenterColor. This enables animation, styling, binding, etc...
  53. public static readonly DependencyProperty CenterColorProperty =
  54. DependencyProperty.Register("CenterColor", typeof(Color), typeof(PipeLineThree), new PropertyMetadata(Colors.LightGray));
  55. /// <summary>
  56. /// 获取或设置管道1号线是否激活液体显示
  57. /// </summary>
  58. public bool PipeLineActive1
  59. {
  60. get { return (bool)GetValue(PipeLineActive1Property); }
  61. set { SetValue(PipeLineActive1Property, value); }
  62. }
  63. // Using a DependencyProperty as the backing store for PipeLineActive1. This enables animation, styling, binding, etc...
  64. public static readonly DependencyProperty PipeLineActive1Property =
  65. DependencyProperty.Register("PipeLineActive1", typeof(bool), typeof(PipeLineThree), new PropertyMetadata(false));
  66. /// <summary>
  67. /// 获取或设置管道2号线是否激活液体显示
  68. /// </summary>
  69. public bool PipeLineActive2
  70. {
  71. get { return (bool)GetValue(PipeLineActive2Property); }
  72. set { SetValue(PipeLineActive2Property, value); }
  73. }
  74. // Using a DependencyProperty as the backing store for PipeLineActive2. This enables animation, styling, binding, etc...
  75. public static readonly DependencyProperty PipeLineActive2Property =
  76. DependencyProperty.Register("PipeLineActive2", typeof(bool), typeof(PipeLineThree), new PropertyMetadata(false));
  77. /// <summary>
  78. /// 获取或设置管道3号线是否激活液体显示
  79. /// </summary>
  80. public bool PipeLineActive3
  81. {
  82. get { return (bool)GetValue(PipeLineActive3Property); }
  83. set { SetValue(PipeLineActive3Property, value); }
  84. }
  85. // Using a DependencyProperty as the backing store for PipeLineActive3. This enables animation, styling, binding, etc...
  86. public static readonly DependencyProperty PipeLineActive3Property =
  87. DependencyProperty.Register("PipeLineActive3", typeof(bool), typeof(PipeLineThree), new PropertyMetadata(false));
  88. /// <summary>
  89. /// 获取或设置管道1号线液体流动的速度,0为静止,正数为正向流动,负数为反向流动
  90. /// </summary>
  91. public double MoveSpeed1
  92. {
  93. get { return (double)GetValue(MoveSpeed1Property); }
  94. set { SetValue(MoveSpeed1Property, value); }
  95. }
  96. // Using a DependencyProperty as the backing store for MoveSpeed1. This enables animation, styling, binding, etc...
  97. public static readonly DependencyProperty MoveSpeed1Property =
  98. DependencyProperty.Register("MoveSpeed1", typeof(double), typeof(PipeLineThree),
  99. new PropertyMetadata(0d, new PropertyChangedCallback(MoveSpeed1PropertyChangedCallback)));
  100. public static void MoveSpeed1PropertyChangedCallback(DependencyObject dependency, DependencyPropertyChangedEventArgs e)
  101. {
  102. PipeLineThree pipeLine = (PipeLineThree)dependency;
  103. pipeLine.UpdateMoveSpeed1();
  104. }
  105. private DoubleAnimation offect1DoubleAnimation = null;
  106. public void UpdateMoveSpeed1()
  107. {
  108. return;
  109. if (MoveSpeed1 > 0)
  110. {
  111. UpdatePathDataSG1();
  112. path1.Visibility = Visibility.Visible;
  113. offect1DoubleAnimation = new DoubleAnimation(0d, 10d, TimeSpan.FromMilliseconds(300 / MoveSpeed1), FillBehavior.Stop);
  114. offect1DoubleAnimation.RepeatBehavior = RepeatBehavior.Forever;
  115. BeginAnimation(LineOffect1Property, offect1DoubleAnimation);
  116. }
  117. else if (MoveSpeed1 < 0)
  118. {
  119. UpdatePathDataSG1();
  120. path1.Visibility = Visibility.Visible;
  121. offect1DoubleAnimation = new DoubleAnimation(10d, 0d, TimeSpan.FromMilliseconds(300 / Math.Abs(MoveSpeed1)), FillBehavior.Stop);
  122. offect1DoubleAnimation.RepeatBehavior = RepeatBehavior.Forever;
  123. BeginAnimation(LineOffect1Property, offect1DoubleAnimation);
  124. }
  125. else
  126. {
  127. path1.Data = null;
  128. if (offect1DoubleAnimation != null)
  129. {
  130. offect1DoubleAnimation.FillBehavior = FillBehavior.Stop;
  131. offect1DoubleAnimation = null;
  132. }
  133. path1.Visibility = Visibility.Hidden;
  134. }
  135. }
  136. /// <summary>
  137. /// 获取或设置管道2号线液体流动的速度,0为静止,正数为正向流动,负数为反向流动
  138. /// </summary>
  139. public double MoveSpeed2
  140. {
  141. get { return (double)GetValue(MoveSpeed2Property); }
  142. set { SetValue(MoveSpeed2Property, value); }
  143. }
  144. // Using a DependencyProperty as the backing store for MoveSpeed2. This enables animation, styling, binding, etc...
  145. public static readonly DependencyProperty MoveSpeed2Property =
  146. DependencyProperty.Register("MoveSpeed2", typeof(double), typeof(PipeLineThree),
  147. new PropertyMetadata(0d, new PropertyChangedCallback(MoveSpeed2PropertyChangedCallback)));
  148. public static void MoveSpeed2PropertyChangedCallback(DependencyObject dependency, DependencyPropertyChangedEventArgs e)
  149. {
  150. PipeLineThree pipeLine = (PipeLineThree)dependency;
  151. pipeLine.UpdateMoveSpeed2();
  152. }
  153. private DoubleAnimation offect2DoubleAnimation = null;
  154. public void UpdateMoveSpeed2()
  155. {
  156. return;
  157. if (MoveSpeed2 > 0)
  158. {
  159. UpdatePathDataSG2();
  160. path2.Visibility = Visibility.Visible;
  161. offect2DoubleAnimation = new DoubleAnimation(0d, 10d, TimeSpan.FromMilliseconds(300 / MoveSpeed2), FillBehavior.Stop);
  162. offect2DoubleAnimation.RepeatBehavior = RepeatBehavior.Forever;
  163. BeginAnimation(LineOffect2Property, offect2DoubleAnimation);
  164. }
  165. else if (MoveSpeed2 < 0)
  166. {
  167. UpdatePathDataSG2();
  168. path2.Visibility = Visibility.Visible;
  169. offect2DoubleAnimation = new DoubleAnimation(10d, 0d, TimeSpan.FromMilliseconds(300 / Math.Abs(MoveSpeed2)), FillBehavior.Stop);
  170. offect2DoubleAnimation.RepeatBehavior = RepeatBehavior.Forever;
  171. BeginAnimation(LineOffect2Property, offect2DoubleAnimation);
  172. }
  173. else
  174. {
  175. path2.Data = null;
  176. if (offect2DoubleAnimation != null)
  177. {
  178. offect2DoubleAnimation.FillBehavior = FillBehavior.Stop;
  179. offect2DoubleAnimation = null;
  180. }
  181. path2.Visibility = Visibility.Hidden;
  182. }
  183. }
  184. /// <summary>
  185. /// 获取或设置管道3号线液体流动的速度,0为静止,正数为正向流动,负数为反向流动
  186. /// </summary>
  187. public double MoveSpeed3
  188. {
  189. get { return (double)GetValue(MoveSpeed3Property); }
  190. set { SetValue(MoveSpeed3Property, value); }
  191. }
  192. // Using a DependencyProperty as the backing store for MoveSpeed3. This enables animation, styling, binding, etc...
  193. public static readonly DependencyProperty MoveSpeed3Property =
  194. DependencyProperty.Register("MoveSpeed3", typeof(double), typeof(PipeLineThree),
  195. new PropertyMetadata(0d, new PropertyChangedCallback(MoveSpeed3PropertyChangedCallback)));
  196. public static void MoveSpeed3PropertyChangedCallback(DependencyObject dependency, DependencyPropertyChangedEventArgs e)
  197. {
  198. PipeLineThree pipeLine = (PipeLineThree)dependency;
  199. pipeLine.UpdateMoveSpeed3();
  200. }
  201. private DoubleAnimation offect3DoubleAnimation = null;
  202. public void UpdateMoveSpeed3()
  203. {
  204. return;
  205. if (MoveSpeed3 > 0)
  206. {
  207. UpdatePathDataSG3();
  208. path3.Visibility = Visibility.Visible;
  209. offect3DoubleAnimation = new DoubleAnimation(0d, 10d, TimeSpan.FromMilliseconds(300 / MoveSpeed3), FillBehavior.Stop);
  210. offect3DoubleAnimation.RepeatBehavior = RepeatBehavior.Forever;
  211. BeginAnimation(LineOffect3Property, offect3DoubleAnimation);
  212. }
  213. else if (MoveSpeed3 < 0)
  214. {
  215. UpdatePathDataSG3();
  216. path3.Visibility = Visibility.Visible;
  217. offect3DoubleAnimation = new DoubleAnimation(10d, 0d, TimeSpan.FromMilliseconds(300 / Math.Abs(MoveSpeed3)), FillBehavior.Stop);
  218. offect3DoubleAnimation.RepeatBehavior = RepeatBehavior.Forever;
  219. BeginAnimation(LineOffect3Property, offect3DoubleAnimation);
  220. }
  221. else
  222. {
  223. path3.Data = null;
  224. if (offect3DoubleAnimation != null)
  225. {
  226. offect3DoubleAnimation.FillBehavior = FillBehavior.Stop;
  227. offect3DoubleAnimation = null;
  228. }
  229. path3.Visibility = Visibility.Hidden;
  230. }
  231. }
  232. /// <summary>
  233. /// 管道1的偏移
  234. /// </summary>
  235. public double LineOffect1
  236. {
  237. get { return (double)GetValue(LineOffect1Property); }
  238. set { SetValue(LineOffect1Property, value); }
  239. }
  240. // Using a DependencyProperty as the backing store for LineOffect1. This enables animation, styling, binding, etc...
  241. public static readonly DependencyProperty LineOffect1Property =
  242. DependencyProperty.Register("LineOffect1", typeof(double), typeof(PipeLineThree), new PropertyMetadata(0d));
  243. /// <summary>
  244. /// 管道2的偏移
  245. /// </summary>
  246. public double LineOffect2
  247. {
  248. get { return (double)GetValue(LineOffect2Property); }
  249. set { SetValue(LineOffect2Property, value); }
  250. }
  251. // Using a DependencyProperty as the backing store for LineOffect2. This enables animation, styling, binding, etc...
  252. public static readonly DependencyProperty LineOffect2Property =
  253. DependencyProperty.Register("LineOffect2", typeof(double), typeof(PipeLineThree), new PropertyMetadata(0d));
  254. /// <summary>
  255. /// 管道3的偏移
  256. /// </summary>
  257. public double LineOffect3
  258. {
  259. get { return (double)GetValue(LineOffect3Property); }
  260. set { SetValue(LineOffect3Property, value); }
  261. }
  262. // Using a DependencyProperty as the backing store for LineOffect3. This enables animation, styling, binding, etc...
  263. public static readonly DependencyProperty LineOffect3Property =
  264. DependencyProperty.Register("LineOffect3", typeof(double), typeof(PipeLineThree), new PropertyMetadata(0d));
  265. /// <summary>
  266. /// 获取或设置中间管道线的宽度信息,默认为3
  267. /// </summary>
  268. public int PipeLineWidth
  269. {
  270. get { return (int)GetValue(PipeLineWidthProperty); }
  271. set { SetValue(PipeLineWidthProperty, value); }
  272. }
  273. // Using a DependencyProperty as the backing store for PipeLineWidth. This enables animation, styling, binding, etc...
  274. public static readonly DependencyProperty PipeLineWidthProperty =
  275. DependencyProperty.Register("PipeLineWidth", typeof(int), typeof(PipeLineThree), new PropertyMetadata(2));
  276. /// <summary>
  277. /// 获取或设置流动状态时管道控件的中心颜色
  278. /// </summary>
  279. public Color ActiveLineCenterColor
  280. {
  281. get { return (Color)GetValue(ActiveLineCenterColorProperty); }
  282. set { SetValue(ActiveLineCenterColorProperty, value); }
  283. }
  284. // Using a DependencyProperty as the backing store for ActiveLineCenterColor. This enables animation, styling, binding, etc...
  285. public static readonly DependencyProperty ActiveLineCenterColorProperty =
  286. DependencyProperty.Register("ActiveLineCenterColor", typeof(Color), typeof(PipeLineThree), new PropertyMetadata(Colors.DodgerBlue));
  287. /// <summary>
  288. /// 获取或设置管道的宽度,默认为30
  289. /// </summary>
  290. public int PipeWidth
  291. {
  292. get { return (int)GetValue(PipeWidthProperty); }
  293. set { SetValue(PipeWidthProperty, value); }
  294. }
  295. // Using a DependencyProperty as the backing store for PipeWidth. This enables animation, styling, binding, etc...
  296. public static readonly DependencyProperty PipeWidthProperty =
  297. DependencyProperty.Register("PipeWidth", typeof(int), typeof(PipeLineThree),
  298. new PropertyMetadata(30, new PropertyChangedCallback(PipeWidthPropertyChangedCallback)));
  299. public static void PipeWidthPropertyChangedCallback(DependencyObject dependency, DependencyPropertyChangedEventArgs e)
  300. {
  301. PipeLineThree pipeLine = (PipeLineThree)dependency;
  302. pipeLine.PipeWidthUpdate();
  303. }
  304. public void PipeWidthUpdate()
  305. {
  306. UpdatePath();
  307. }
  308. public double RouWidth
  309. {
  310. get
  311. {
  312. return canvas1.ActualWidth / 2;
  313. }
  314. }
  315. protected override void OnRenderSizeChanged(SizeChangedInfo sizeInfo)
  316. {
  317. UpdatePath();
  318. base.OnRenderSizeChanged(sizeInfo);
  319. UpdateMoveSpeed1();
  320. UpdateMoveSpeed2();
  321. UpdateMoveSpeed3();
  322. }
  323. StreamGeometry sg1 = new StreamGeometry();
  324. public void UpdatePathDataSG1()
  325. {
  326. using (StreamGeometryContext context = sg1.Open())
  327. {
  328. context.BeginFigure(new Point(0, PipeWidth * 0.5), false, false);
  329. context.LineTo(new Point(ActualWidth, PipeWidth * 0.5), true, false);
  330. }
  331. path1.Data = sg1;
  332. }
  333. StreamGeometry sg2 = new StreamGeometry();
  334. public void UpdatePathDataSG2()
  335. {
  336. using (StreamGeometryContext context = sg2.Open())
  337. {
  338. context.BeginFigure(new Point(0, PipeWidth * 0.5), false, false);
  339. context.LineTo(new Point(ActualWidth * 0.5 - PipeWidth * 0.5, PipeWidth * 0.5), true, false);
  340. context.ArcTo(new Point(ActualWidth * 0.5, PipeWidth), new Size(PipeWidth * 0.5, PipeWidth * 0.5), 0, false, SweepDirection.Clockwise, true, false);
  341. context.LineTo(new Point(ActualWidth * 0.5, ActualHeight), true, false);
  342. }
  343. path2.Data = sg2;
  344. }
  345. StreamGeometry sg3 = new StreamGeometry();
  346. public void UpdatePathDataSG3()
  347. {
  348. using (StreamGeometryContext context = sg3.Open())
  349. {
  350. context.BeginFigure(new Point(ActualWidth, PipeWidth * 0.5), false, false);
  351. context.LineTo(new Point(ActualWidth * 0.5 + PipeWidth * 0.5, PipeWidth * 0.5), true, false);
  352. context.ArcTo(new Point(ActualWidth * 0.5, PipeWidth), new Size(PipeWidth * 0.5, PipeWidth * 0.5), 0, false, SweepDirection.Counterclockwise, true, false);
  353. context.LineTo(new Point(ActualWidth * 0.5, ActualHeight), true, false);
  354. }
  355. path3.Data = sg3;
  356. }
  357. public void UpdatePath()
  358. {
  359. polygon1.Points = new PointCollection(new Point[]
  360. {
  361. new Point(ActualWidth * 0.5 - PipeWidth *0.5, PipeWidth),
  362. new Point(ActualWidth * 0.5, PipeWidth *0.5),
  363. new Point(ActualWidth * 0.5 + PipeWidth *0.5, PipeWidth),
  364. new Point(ActualWidth * 0.5 + PipeWidth *0.5, ActualHeight),
  365. new Point(ActualWidth * 0.5 - PipeWidth *0.5, ActualHeight),
  366. new Point(ActualWidth * 0.5 - PipeWidth *0.5, PipeWidth),
  367. });
  368. }
  369. }
  370. }