GasSingularLine.xaml.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384
  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. using System.Windows.Media.Animation;
  16. using MECF.Framework.UI.Client.IndustrialControl.Converters;
  17. namespace MECF.Framework.UI.Client.IndustrialControl
  18. {
  19. /// <summary>
  20. /// UserControl1.xaml 的交互逻辑
  21. /// </summary>
  22. public partial class GasSingularLine : UserControl
  23. {
  24. #region Contructor
  25. /// <summary>
  26. /// 实例化一个管道对象
  27. /// </summary>
  28. public GasSingularLine()
  29. {
  30. InitializeComponent();
  31. //Binding binding = new Binding( );
  32. //binding.Source = grid1;
  33. //binding.Path = new PropertyPath( "ActualHeight" );
  34. //binding.Converter = new MultiplesValueConverter( );
  35. //binding.ConverterParameter = -1;
  36. //ellipe1.SetBinding( Canvas.TopProperty, binding );
  37. }
  38. #endregion
  39. #region Property Dependency
  40. #region LeftDirection Property
  41. /// <summary>
  42. /// 设置左边的方向
  43. /// </summary>
  44. public HslPipeTurnDirection LeftDirection
  45. {
  46. get { return (HslPipeTurnDirection)GetValue(LeftDirectionProperty); }
  47. set { SetValue(LeftDirectionProperty, value); }
  48. }
  49. // Using a DependencyProperty as the backing store for LeftDirection. This enables animation, styling, binding, etc...
  50. public static readonly DependencyProperty LeftDirectionProperty =
  51. DependencyProperty.Register("LeftDirection", typeof(HslPipeTurnDirection), typeof(GasSingularLine),
  52. new PropertyMetadata(HslPipeTurnDirection.Left, new PropertyChangedCallback(LeftDirectionPropertyChangedCallback)));
  53. public static void LeftDirectionPropertyChangedCallback(System.Windows.DependencyObject dependency, System.Windows.DependencyPropertyChangedEventArgs e)
  54. {
  55. GasSingularLine pipeLine = (GasSingularLine)dependency;
  56. pipeLine.UpdateLeftDirectionBinding();
  57. }
  58. public void UpdateLeftDirectionBinding()
  59. {
  60. BindingOperations.ClearBinding(ellipe1, Canvas.TopProperty);
  61. if (LeftDirection == HslPipeTurnDirection.Left)
  62. {
  63. canvas1.Visibility = Visibility.Visible;
  64. Binding binding = new Binding();
  65. binding.Source = grid1;
  66. binding.Path = new PropertyPath("ActualHeight");
  67. binding.Converter = new MultiplesValueConverter();
  68. binding.ConverterParameter = 0;
  69. ellipe1.SetBinding(Canvas.TopProperty, binding);
  70. }
  71. else if (LeftDirection == HslPipeTurnDirection.Right)
  72. {
  73. canvas1.Visibility = Visibility.Visible;
  74. Binding binding = new Binding();
  75. binding.Source = grid1;
  76. binding.Path = new PropertyPath("ActualHeight");
  77. binding.Converter = new MultiplesValueConverter();
  78. binding.ConverterParameter = -1;
  79. ellipe1.SetBinding(Canvas.TopProperty, binding);
  80. }
  81. else
  82. {
  83. canvas1.Visibility = Visibility.Collapsed;
  84. }
  85. // UpdatePathData();
  86. }
  87. #endregion
  88. #region RightDirection Property
  89. /// <summary>
  90. /// 设置右边的方向
  91. /// </summary>
  92. public HslPipeTurnDirection RightDirection
  93. {
  94. get { return (HslPipeTurnDirection)GetValue(RightDirectionProperty); }
  95. set { SetValue(RightDirectionProperty, value); }
  96. }
  97. // Using a DependencyProperty as the backing store for LeftDirection. This enables animation, styling, binding, etc...
  98. public static readonly DependencyProperty RightDirectionProperty =
  99. DependencyProperty.Register("RightDirection", typeof(HslPipeTurnDirection), typeof(GasSingularLine),
  100. new PropertyMetadata(HslPipeTurnDirection.Right, new PropertyChangedCallback(RightDirectionPropertyChangedCallback)));
  101. public static void RightDirectionPropertyChangedCallback(System.Windows.DependencyObject dependency, System.Windows.DependencyPropertyChangedEventArgs e)
  102. {
  103. GasSingularLine pipeLine = (GasSingularLine)dependency;
  104. pipeLine.UpdateRightDirectionBinding();
  105. }
  106. public void UpdateRightDirectionBinding()
  107. {
  108. BindingOperations.ClearBinding(ellipe2, Canvas.TopProperty);
  109. if (RightDirection == HslPipeTurnDirection.Left)
  110. {
  111. canvas2.Visibility = Visibility.Visible;
  112. Binding binding = new Binding();
  113. binding.Source = grid1;
  114. binding.Path = new PropertyPath("ActualHeight");
  115. binding.Converter = new MultiplesValueConverter();
  116. binding.ConverterParameter = 0;
  117. ellipe2.SetBinding(Canvas.TopProperty, binding);
  118. }
  119. else if (RightDirection == HslPipeTurnDirection.Right)
  120. {
  121. canvas2.Visibility = Visibility.Visible;
  122. Binding binding = new Binding();
  123. binding.Source = grid1;
  124. binding.Path = new PropertyPath("ActualHeight");
  125. binding.Converter = new MultiplesValueConverter();
  126. binding.ConverterParameter = -1;
  127. ellipe2.SetBinding(Canvas.TopProperty, binding);
  128. }
  129. else
  130. {
  131. canvas2.Visibility = Visibility.Collapsed;
  132. }
  133. // UpdatePathData();
  134. }
  135. #endregion
  136. #region PipeLineActive Property
  137. public bool PipeLineActive
  138. {
  139. get { return (bool)GetValue(PipeLineActiveProperty); }
  140. set { SetValue(PipeLineActiveProperty, value); }
  141. }
  142. // Using a DependencyProperty as the backing store for PipeLineActive. This enables animation, styling, binding, etc...
  143. public static readonly DependencyProperty PipeLineActiveProperty =
  144. DependencyProperty.Register("PipeLineActive", typeof(bool), typeof(GasSingularLine), new PropertyMetadata(false));
  145. #endregion
  146. protected override void OnRenderSizeChanged(SizeChangedInfo sizeInfo)
  147. {
  148. // UpdatePathData();
  149. base.OnRenderSizeChanged(sizeInfo);
  150. }
  151. #region LineOffect Property
  152. public double LineOffect
  153. {
  154. get { return (double)GetValue(LineOffectProperty); }
  155. set { SetValue(LineOffectProperty, value); }
  156. }
  157. // Using a DependencyProperty as the backing store for LineOffect. This enables animation, styling, binding, etc...
  158. public static readonly DependencyProperty LineOffectProperty =
  159. DependencyProperty.Register("LineOffect", typeof(double), typeof(GasSingularLine), new PropertyMetadata(0d));
  160. StreamGeometry sg = new StreamGeometry();
  161. public void UpdatePathData()
  162. {
  163. //Console.WriteLine( "Size Changed" );
  164. double height = Height;
  165. double width = Width;
  166. using (StreamGeometryContext context = sg.Open())
  167. {
  168. if (LeftDirection == HslPipeTurnDirection.Left)
  169. {
  170. context.BeginFigure(new Point(height * 0.5, height), false, false);
  171. context.ArcTo(new Point(height, height * 0.5), new Size(height * 0.5, height * 0.5), 0, false, SweepDirection.Clockwise, true, false);
  172. }
  173. else if (LeftDirection == HslPipeTurnDirection.Right)
  174. {
  175. context.BeginFigure(new Point(height * 0.5, 0), false, false);
  176. context.ArcTo(new Point(height, height * 0.5), new Size(height * 0.5, height * 0.5), 0, false, SweepDirection.Counterclockwise, true, false);
  177. }
  178. else
  179. {
  180. context.BeginFigure(new Point(0, height * 0.5), false, false);
  181. context.LineTo(new Point(height, height * 0.5), true, false);
  182. }
  183. context.LineTo(new Point(width - height, height * 0.5), true, false);
  184. if (RightDirection == HslPipeTurnDirection.Left)
  185. {
  186. context.ArcTo(new Point(width - height * 0.5, height), new Size(height * 0.5, height * 0.5), 0, false, SweepDirection.Clockwise, true, false);
  187. }
  188. else if (RightDirection == HslPipeTurnDirection.Right)
  189. {
  190. context.ArcTo(new Point(width - height * 0.5, 0), new Size(height * 0.5, height * 0.5), 0, false, SweepDirection.Counterclockwise, true, false);
  191. }
  192. else
  193. {
  194. context.LineTo(new Point(width, height * 0.5), true, false);
  195. }
  196. }
  197. //sg.Freeze();
  198. path1.Data = sg;
  199. }
  200. #endregion
  201. #region MoveSpeed Property
  202. /// <summary>
  203. /// 获取或设置流动的速度
  204. /// </summary>
  205. public double MoveSpeed
  206. {
  207. get { return (double)GetValue(MoveSpeedProperty); }
  208. set { SetValue(MoveSpeedProperty, value); }
  209. }
  210. // Using a DependencyProperty as the backing store for MoveSpeed. This enables animation, styling, binding, etc...
  211. public static readonly DependencyProperty MoveSpeedProperty =
  212. DependencyProperty.Register("MoveSpeed", typeof(double), typeof(GasSingularLine), new PropertyMetadata(0.0d, new PropertyChangedCallback(MoveSpeedPropertyChangedCallback)));
  213. public static void MoveSpeedPropertyChangedCallback(DependencyObject dependency, DependencyPropertyChangedEventArgs e)
  214. {
  215. GasSingularLine pipeLine = (GasSingularLine)dependency;
  216. pipeLine.UpdateMoveSpeed();
  217. }
  218. private Storyboard storyboard = new Storyboard();
  219. public void UpdateMoveSpeed()
  220. {
  221. //jet炉管删除流向动画
  222. if (path1.Data != null)
  223. {
  224. path1.Data = null;
  225. //offectDoubleAnimation.FillBehavior = FillBehavior.Stop;
  226. //offectDoubleAnimation = null;
  227. path1.Visibility = Visibility.Hidden;
  228. }
  229. return;
  230. if (MoveSpeed > 0)
  231. {
  232. UpdatePathData();
  233. path1.Visibility = Visibility.Visible;
  234. VisualStateManager.GoToState(this, "WEFlowState", false);
  235. //offectDoubleAnimation = new DoubleAnimation(0d, 10d, TimeSpan.FromMilliseconds(300 / MoveSpeed));
  236. //offectDoubleAnimation.RepeatBehavior = RepeatBehavior.Forever;
  237. //BeginAnimation(LineOffectProperty, offectDoubleAnimation);
  238. //Storyboard.SetTarget(offectDoubleAnimation, path1);
  239. //Storyboard.SetTargetProperty(offectDoubleAnimation, "X");
  240. //storyboard.Children.Add(offectDoubleAnimation);
  241. //storyboard.Begin();
  242. }
  243. else if (MoveSpeed < 0)
  244. {
  245. UpdatePathData();
  246. path1.Visibility = Visibility.Visible;
  247. VisualStateManager.GoToState(this, "EWFlowState", false);
  248. //offectDoubleAnimation = new DoubleAnimation(0d, -10d, TimeSpan.FromMilliseconds(300 / Math.Abs(MoveSpeed)));
  249. //offectDoubleAnimation.FillBehavior = FillBehavior.HoldEnd;
  250. //offectDoubleAnimation.RepeatBehavior = RepeatBehavior.Forever;
  251. //BeginAnimation(LineOffectProperty, offectDoubleAnimation);
  252. //Storyboard.SetTarget(offectDoubleAnimation, path1);
  253. ////Storyboard.SetTargetProperty(offectDoubleAnimation, "(UIElement.RenderTransform).(CompositeTransform.ScaleY)");
  254. //storyboard.Children.Add(offectDoubleAnimation);
  255. //storyboard.Begin();
  256. }
  257. else
  258. {
  259. if (path1.Data != null)
  260. {
  261. path1.Data = null;
  262. //offectDoubleAnimation.FillBehavior = FillBehavior.Stop;
  263. //offectDoubleAnimation = null;
  264. path1.Visibility = Visibility.Hidden;
  265. }
  266. }
  267. }
  268. #endregion
  269. #region CenterColor Property
  270. /// <summary>
  271. /// 管道的中心颜色
  272. /// </summary>
  273. public Color CenterColor
  274. {
  275. get { return (Color)GetValue(CenterColorProperty); }
  276. set { SetValue(CenterColorProperty, value); }
  277. }
  278. // Using a DependencyProperty as the backing store for CenterColor. This enables animation, styling, binding, etc...
  279. public static readonly DependencyProperty CenterColorProperty =
  280. DependencyProperty.Register("CenterColor", typeof(Color), typeof(GasSingularLine), new PropertyMetadata(Colors.Green));
  281. #endregion
  282. #region PipeLineWidth Property
  283. /// <summary>
  284. /// 管道活动状态时的中心线的线条宽度
  285. /// </summary>
  286. public int PipeLineWidth
  287. {
  288. get { return (int)GetValue(PipeLineWidthProperty); }
  289. set { SetValue(PipeLineWidthProperty, value); }
  290. }
  291. // Using a DependencyProperty as the backing store for PipeLineWidth. This enables animation, styling, binding, etc...
  292. public static readonly DependencyProperty PipeLineWidthProperty =
  293. DependencyProperty.Register("PipeLineWidth", typeof(int), typeof(GasSingularLine), new PropertyMetadata(2));
  294. #endregion
  295. #region ActiveLineCenterColor Property
  296. /// <summary>
  297. /// 管道活动状态时的中心线的颜色信息
  298. /// </summary>
  299. public Color ActiveLineCenterColor
  300. {
  301. get { return (Color)GetValue(ActiveLineCenterColorProperty); }
  302. set { SetValue(ActiveLineCenterColorProperty, value); }
  303. }
  304. // Using a DependencyProperty as the backing store for ActiveLineCenterColor. This enables animation, styling, binding, etc...
  305. public static readonly DependencyProperty ActiveLineCenterColorProperty =
  306. DependencyProperty.Register("ActiveLineCenterColor", typeof(Color), typeof(GasSingularLine), new PropertyMetadata(Colors.DodgerBlue));
  307. #endregion
  308. #region MyRegion
  309. /// <summary>
  310. /// 管道控件的边缘颜色
  311. /// </summary>
  312. public Color EdgeColor
  313. {
  314. get { return (Color)GetValue(EdgeColorProperty); }
  315. set { SetValue(EdgeColorProperty, value); }
  316. }
  317. // Using a DependencyProperty as the backing store for EdgeColor. This enables animation, styling, binding, etc...
  318. public static readonly DependencyProperty EdgeColorProperty =
  319. DependencyProperty.Register("EdgeColor", typeof(Color), typeof(GasSingularLine), new PropertyMetadata(Colors.Black));
  320. #endregion
  321. #endregion
  322. }
  323. }