FlowPipeV2.xaml.cs 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Linq;
  5. using System.Text;
  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.Threading;
  16. using System.Windows.Media.Animation;
  17. using Aitex.Core.UI.ControlDataContext;
  18. namespace Aitex.Core.UI.Control
  19. {
  20. /// <summary>
  21. /// Interaction logic for FlowPipe.xaml
  22. /// </summary>
  23. public partial class FlowPipeV2 : UserControl
  24. {
  25. public FlowPipeV2()
  26. {
  27. InitializeComponent();
  28. }
  29. public static readonly DependencyProperty IsFlowingProperty = DependencyProperty.Register(
  30. "IsFlowing", typeof(bool), typeof(FlowPipeV2),
  31. new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.AffectsRender));
  32. public static readonly DependencyProperty IsSlowFlowingProperty = DependencyProperty.Register(
  33. "IsSlowFlowing", typeof(bool), typeof(FlowPipeV2),
  34. new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.AffectsRender));
  35. public static readonly DependencyProperty ValveOpenOrientationProperty = DependencyProperty.Register(
  36. "FlowOrientation", typeof(LineOrientation), typeof(FlowPipeV2),
  37. new FrameworkPropertyMetadata(LineOrientation.Horizontal, FrameworkPropertyMetadataOptions.AffectsRender));
  38. public static readonly DependencyProperty IsReverseProperty = DependencyProperty.Register(
  39. "IsReverse", typeof(bool), typeof(FlowPipeV2),
  40. new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.AffectsRender));
  41. public static readonly DependencyProperty GasTypeProperty = DependencyProperty.Register(
  42. "GasType", typeof(GasTypeEnum), typeof(FlowPipeV2),
  43. new FrameworkPropertyMetadata(GasTypeEnum.CarrierGas, FrameworkPropertyMetadataOptions.AffectsRender));
  44. public LineOrientation FlowOrientation
  45. {
  46. get { return (LineOrientation)GetValue(ValveOpenOrientationProperty); }
  47. set { SetValue(ValveOpenOrientationProperty, value); }
  48. }
  49. /// <summary>
  50. /// When 'IsFlowing' is true, the gas will flow; otherwise, there is no gas flow.
  51. /// default fast valve
  52. /// </summary>
  53. public bool IsFlowing
  54. {
  55. get { return (bool)this.GetValue(IsFlowingProperty); }
  56. set { this.SetValue(IsFlowingProperty, value); }
  57. }
  58. public bool IsSlowFlowing
  59. {
  60. get { return (bool)this.GetValue(IsSlowFlowingProperty); }
  61. set { this.SetValue(IsSlowFlowingProperty, value); }
  62. }
  63. public GasTypeEnum GasType
  64. {
  65. get { return (GasTypeEnum)this.GetValue(GasTypeProperty); }
  66. set { this.SetValue(GasTypeProperty, value); }
  67. }
  68. public bool IsReverse
  69. {
  70. get
  71. {
  72. return (bool)this.GetValue(IsReverseProperty);
  73. }
  74. set
  75. {
  76. this.SetValue(IsReverseProperty, value);
  77. }
  78. }
  79. public bool IsVertical { get; set; }
  80. private static readonly SolidColorBrush CarrierGasBrush = new SolidColorBrush(Colors.Green);
  81. private static readonly SolidColorBrush MOBrush = new SolidColorBrush(Colors.DarkRed);
  82. private static readonly SolidColorBrush HydrideBrush = new SolidColorBrush(Colors.Navy);
  83. private static readonly SolidColorBrush ExhaustBrush = new SolidColorBrush(Colors.Gray);
  84. private Brush _pathStrokeBrush = CarrierGasBrush;
  85. protected override void OnRender(DrawingContext drawingContext)
  86. {
  87. base.OnRender(drawingContext);
  88. if (FlowOrientation == LineOrientation.Vertical)
  89. rotateTransform.Angle = 90;
  90. path1.Visibility = IsFlowing ? Visibility.Visible : Visibility.Hidden;
  91. if (!DesignerProperties.GetIsInDesignMode(this))
  92. {
  93. this.Visibility = IsFlowing ? Visibility.Visible : Visibility.Hidden;
  94. }
  95. switch (GasType)
  96. {
  97. //case GasTypeEnum.Fast:
  98. // _pathStrokeBrush = CarrierGasBrush;
  99. // path1.StrokeThickness = 5;
  100. // break;
  101. //case GasTypeEnum.Slow:
  102. // _pathStrokeBrush = CarrierGasBrush;
  103. // path1.StrokeThickness = 3;
  104. // break;
  105. case GasTypeEnum.CarrierGas:
  106. _pathStrokeBrush = CarrierGasBrush;
  107. break;
  108. case GasTypeEnum.MO:
  109. _pathStrokeBrush = MOBrush;
  110. break;
  111. case GasTypeEnum.Hydride:
  112. _pathStrokeBrush = HydrideBrush;
  113. break;
  114. case GasTypeEnum.Exhaust:
  115. _pathStrokeBrush = ExhaustBrush;
  116. break;
  117. }
  118. if (_pathStrokeBrush != path1.Stroke)
  119. path1.Stroke = _pathStrokeBrush;
  120. if (IsSlowFlowing && !IsFlowing)
  121. path1.StrokeThickness = 3;
  122. else if (IsFlowing)
  123. path1.StrokeThickness = 5;
  124. }
  125. }
  126. }