FlowPipeV2.xaml.cs 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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 N2Brush = new SolidColorBrush(Colors.LightYellow);
  83. private static readonly SolidColorBrush HydrideBrush = new SolidColorBrush(Colors.Navy);
  84. private static readonly SolidColorBrush ExhaustBrush = new SolidColorBrush(Colors.Gray);
  85. private Brush _pathStrokeBrush = CarrierGasBrush;
  86. protected override void OnRender(DrawingContext drawingContext)
  87. {
  88. base.OnRender(drawingContext);
  89. if (FlowOrientation == LineOrientation.Vertical)
  90. rotateTransform.Angle = 90;
  91. path1.Visibility = IsFlowing ? Visibility.Visible : Visibility.Hidden;
  92. if (!DesignerProperties.GetIsInDesignMode(this))
  93. {
  94. this.Visibility = IsFlowing ? Visibility.Visible : Visibility.Hidden;
  95. }
  96. switch (GasType)
  97. {
  98. //case GasTypeEnum.Fast:
  99. // _pathStrokeBrush = CarrierGasBrush;
  100. // path1.StrokeThickness = 5;
  101. // break;
  102. //case GasTypeEnum.Slow:
  103. // _pathStrokeBrush = CarrierGasBrush;
  104. // path1.StrokeThickness = 3;
  105. // break;
  106. case GasTypeEnum.CarrierGas:
  107. _pathStrokeBrush = CarrierGasBrush;
  108. break;
  109. case GasTypeEnum.MO:
  110. _pathStrokeBrush = MOBrush;
  111. break;
  112. case GasTypeEnum.Hydride:
  113. _pathStrokeBrush = HydrideBrush;
  114. break;
  115. case GasTypeEnum.Exhaust:
  116. _pathStrokeBrush = ExhaustBrush;
  117. break;
  118. case GasTypeEnum.N2:
  119. _pathStrokeBrush = N2Brush;
  120. break;
  121. }
  122. if (_pathStrokeBrush != path1.Stroke)
  123. path1.Stroke = _pathStrokeBrush;
  124. if (IsSlowFlowing && !IsFlowing)
  125. path1.StrokeThickness = 3;
  126. else if (IsFlowing)
  127. path1.StrokeThickness = 5;
  128. }
  129. }
  130. }