AITSignalTower.xaml.cs 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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.Effects;
  12. using System.Windows.Media.Imaging;
  13. using System.Windows.Navigation;
  14. using System.Windows.Shapes;
  15. using Aitex.Core.Common.DeviceData;
  16. using Aitex.Core.UI.ControlDataContext;
  17. namespace Aitex.Core.UI.DeviceControl
  18. {
  19. public partial class AITSignalTower : UserControl
  20. {
  21. public static readonly DependencyProperty DeviceDataProperty = DependencyProperty.Register(
  22. "DeviceData", typeof(AITSignalTowerData), typeof(AITSignalTower),
  23. new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.AffectsRender));
  24. public static readonly DependencyProperty BuzzingWarningConfigCommandProperty = DependencyProperty.Register(
  25. "BuzzingWarningConfigCallback", typeof(Action), typeof(AITSignalTower),
  26. new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.None));
  27. public Action BuzzingWarningConfigCallback
  28. {
  29. get
  30. {
  31. return (Action)GetValue(BuzzingWarningConfigCommandProperty);
  32. }
  33. set
  34. {
  35. SetValue(BuzzingWarningConfigCommandProperty, value);
  36. }
  37. }
  38. public AITSignalTowerData DeviceData
  39. {
  40. get
  41. {
  42. return (AITSignalTowerData)GetValue(DeviceDataProperty);
  43. }
  44. set
  45. {
  46. SetValue(DeviceDataProperty, value);
  47. }
  48. }
  49. DropShadowEffect redLightEffect = new DropShadowEffect();
  50. DropShadowEffect yellowLightEffect = new DropShadowEffect();
  51. DropShadowEffect greenLightEffect = new DropShadowEffect();
  52. DropShadowEffect blueLightEffect = new DropShadowEffect();
  53. DropShadowEffect buzzerLightEffect = new DropShadowEffect();
  54. public double OutLights = 0.2;
  55. public AITSignalTower()
  56. {
  57. InitializeComponent();
  58. redLightEffect.BlurRadius = 20;
  59. redLightEffect.Opacity = 1;
  60. redLightEffect.Color = Colors.Red;
  61. yellowLightEffect.BlurRadius = 20;
  62. yellowLightEffect.Opacity = 1;
  63. yellowLightEffect.Color = Colors.Yellow;
  64. greenLightEffect.BlurRadius = 20;
  65. greenLightEffect.Opacity = 1;
  66. greenLightEffect.Color = Colors.Green;
  67. blueLightEffect.BlurRadius = 20;
  68. blueLightEffect.Opacity = 1;
  69. blueLightEffect.Color = Colors.Blue;
  70. buzzerLightEffect.BlurRadius = 20;
  71. buzzerLightEffect.Opacity = 1;
  72. buzzerLightEffect.Color = Colors.White;
  73. }
  74. protected override void OnRender(DrawingContext drawingContext)
  75. {
  76. base.OnRender(drawingContext);
  77. if (DeviceData == null)
  78. return;
  79. if (DeviceData.IsRedLightOn)
  80. {
  81. if (rectangle1.Opacity != 1)
  82. {
  83. rectangle1.Opacity = 1;
  84. rectangle1.Effect = redLightEffect;
  85. }
  86. }
  87. else
  88. {
  89. if (rectangle1.Opacity != OutLights)
  90. {
  91. rectangle1.Opacity = OutLights;
  92. rectangle1.Effect = null;
  93. }
  94. }
  95. if (DeviceData.IsYellowLightOn)
  96. {
  97. if (rectangle2.Opacity != 1)
  98. {
  99. rectangle2.Opacity = 1;
  100. rectangle2.Effect = yellowLightEffect;
  101. }
  102. }
  103. else
  104. {
  105. if (rectangle2.Opacity != OutLights)
  106. {
  107. rectangle2.Opacity = OutLights;
  108. rectangle2.Effect = null;
  109. }
  110. }
  111. if (DeviceData.IsGreenLightOn)
  112. {
  113. if (rectangle3.Opacity != 1)
  114. {
  115. rectangle3.Opacity = 1;
  116. rectangle3.Effect = greenLightEffect;
  117. }
  118. }
  119. else
  120. {
  121. if (rectangle3.Opacity != OutLights)
  122. {
  123. rectangle3.Opacity = OutLights;
  124. rectangle3.Effect = null;
  125. }
  126. }
  127. if (DeviceData.IsBlueLightOn)
  128. {
  129. if (rectangle4.Opacity != 1)
  130. {
  131. rectangle4.Opacity = 1;
  132. rectangle4.Effect = blueLightEffect;
  133. }
  134. }
  135. else
  136. {
  137. if (rectangle4.Opacity != OutLights)
  138. {
  139. rectangle4.Opacity = OutLights;
  140. rectangle4.Effect = null;
  141. }
  142. }
  143. if (DeviceData.IsBuzzerOn || DeviceData.IsBuzzer1On|| DeviceData.IsBuzzer2On|| DeviceData.IsBuzzer3On|| DeviceData.IsBuzzer4On)
  144. {
  145. if (rectangle5.Opacity != 1)
  146. {
  147. rectangle5.Opacity = 1;
  148. rectangle5.Effect = buzzerLightEffect;
  149. }
  150. }
  151. else
  152. {
  153. if (rectangle5.Opacity != OutLights)
  154. {
  155. rectangle5.Opacity = OutLights;
  156. rectangle5.Effect = null;
  157. }
  158. }
  159. }
  160. private void rectangle2_PreviewMouseDown(object sender, MouseButtonEventArgs e)
  161. {
  162. if (BuzzingWarningConfigCallback != null)
  163. {
  164. BuzzingWarningConfigCallback.Invoke();
  165. }
  166. }
  167. }
  168. }