FlowPipe.xaml.cs 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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. public enum GasTypeEnum
  20. {
  21. MO,
  22. CarrierGas,
  23. N2,
  24. Hydride,
  25. Exhaust,
  26. Fast,
  27. Slow
  28. }
  29. /// <summary>
  30. /// Interaction logic for FlowPipe.xaml
  31. /// </summary>
  32. public partial class FlowPipe : UserControl
  33. {
  34. public FlowPipe()
  35. {
  36. InitializeComponent();
  37. }
  38. public static readonly DependencyProperty IsFlowingProperty = DependencyProperty.Register(
  39. "IsFlowing", typeof(GasValveDataItem), typeof(FlowPipe),
  40. new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.AffectsRender));
  41. public static readonly DependencyProperty IsSlowFlowingProperty = DependencyProperty.Register(
  42. "IsSlowFlowing", typeof(GasValveDataItem), typeof(FlowPipe),
  43. new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.AffectsRender));
  44. public static readonly DependencyProperty IsReverseProperty = DependencyProperty.Register(
  45. "IsReverse", typeof(bool), typeof(FlowPipe),
  46. new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.AffectsRender));
  47. public static readonly DependencyProperty GasTypeProperty = DependencyProperty.Register(
  48. "GasType", typeof(GasTypeEnum), typeof(FlowPipe),
  49. new FrameworkPropertyMetadata(GasTypeEnum.CarrierGas, FrameworkPropertyMetadataOptions.AffectsRender));
  50. /// <summary>
  51. /// When 'IsFlowing' is true, the gas will flow; otherwise, there is no gas flow.
  52. /// default fast valve
  53. /// </summary>
  54. public GasValveDataItem IsFlowing
  55. {
  56. get
  57. {
  58. return (GasValveDataItem)this.GetValue(IsFlowingProperty);
  59. }
  60. set
  61. {
  62. this.SetValue(IsFlowingProperty, value);
  63. }
  64. }
  65. public GasValveDataItem IsSlowFlowing
  66. {
  67. get
  68. {
  69. return (GasValveDataItem)this.GetValue(IsSlowFlowingProperty);
  70. }
  71. set
  72. {
  73. this.SetValue(IsSlowFlowingProperty, value);
  74. }
  75. }
  76. public GasTypeEnum GasType
  77. {
  78. get
  79. {
  80. return (GasTypeEnum)this.GetValue(GasTypeProperty);
  81. }
  82. set
  83. {
  84. this.SetValue(GasTypeProperty, value);
  85. }
  86. }
  87. /// <summary>
  88. /// When 'IsReverse' is true, the gas flows from right to left, or bottom to top.
  89. /// When 'IsReverse' is false, the gas flows from left to right, or top to bottom.
  90. /// </summary>
  91. public bool IsReverse
  92. {
  93. get
  94. {
  95. return (bool)this.GetValue(IsReverseProperty);
  96. }
  97. set
  98. {
  99. this.SetValue(IsReverseProperty, value);
  100. }
  101. }
  102. public bool IsVertical { get; set; }
  103. public bool IsShowFlowing { get { return (IsFlowing != null && IsFlowing.Feedback) || (IsSlowFlowing != null && IsSlowFlowing.Feedback); } }
  104. static readonly SolidColorBrush CarrierGasBrush = new SolidColorBrush(Colors.Green);
  105. static readonly SolidColorBrush MOBrush = new SolidColorBrush(Colors.DarkRed);
  106. static readonly SolidColorBrush HydrideBrush = new SolidColorBrush(Colors.Navy);
  107. static readonly SolidColorBrush ExhaustBrush = new SolidColorBrush(Colors.Gray);
  108. Brush pathStrokeBrush = CarrierGasBrush;
  109. protected override void OnRender(DrawingContext drawingContext)
  110. {
  111. base.OnRender(drawingContext);
  112. if (IsVertical)
  113. rotateTransform.Angle = 90;
  114. path1.Visibility = (IsFlowing != null && IsFlowing.Feedback) || (IsSlowFlowing != null && IsSlowFlowing.Feedback) ? Visibility.Visible : Visibility.Hidden;
  115. switch (GasType)
  116. {
  117. //case GasTypeEnum.Fast:
  118. // pathStrokeBrush = CarrierGasBrush;
  119. // path1.StrokeThickness = 5;
  120. // break;
  121. //case GasTypeEnum.Slow:
  122. // pathStrokeBrush = CarrierGasBrush;
  123. // path1.StrokeThickness = 3;
  124. // break;
  125. case GasTypeEnum.CarrierGas:
  126. pathStrokeBrush = CarrierGasBrush;
  127. break;
  128. case GasTypeEnum.MO:
  129. pathStrokeBrush = MOBrush;
  130. break;
  131. case GasTypeEnum.Hydride:
  132. pathStrokeBrush = HydrideBrush;
  133. break;
  134. case GasTypeEnum.Exhaust:
  135. pathStrokeBrush = ExhaustBrush;
  136. break;
  137. }
  138. if (pathStrokeBrush != path1.Stroke)
  139. path1.Stroke = pathStrokeBrush;
  140. if ((IsSlowFlowing != null && IsSlowFlowing.Feedback) && !(IsFlowing != null && IsFlowing.Feedback))
  141. path1.StrokeThickness = 3;
  142. else if ((IsFlowing!=null &&IsFlowing.Feedback))
  143. path1.StrokeThickness = 5;
  144. }
  145. }
  146. }