FlowPipe.xaml.cs 5.5 KB

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