FlowPipeV2.xaml.cs 5.2 KB

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