GasValveV6.xaml.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  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 Aitex.Core.UI.ControlDataContext;
  15. using Aitex.Core.Util;
  16. using Aitex.Core.RT.Log;
  17. namespace Aitex.Core.UI.Control
  18. {
  19. /// <summary>
  20. /// Interaction logic for GasValveV6.xaml
  21. /// </summary>
  22. public partial class GasValveV6 : UserControl
  23. {
  24. public GasValveV6()
  25. {
  26. InitializeComponent();
  27. }
  28. public static readonly DependencyProperty CoupleValve_V6MainProperty = DependencyProperty.Register(
  29. "CoupleValve_V6Main", typeof(SwithType), typeof(GasValveV6),
  30. new FrameworkPropertyMetadata(SwithType.Left, FrameworkPropertyMetadataOptions.AffectsRender));
  31. public static readonly DependencyProperty GasValveV6DirectionProperty = DependencyProperty.Register(
  32. "GasValveV6Direction", typeof(ValveDirection), typeof(GasValveV6),
  33. new FrameworkPropertyMetadata(ValveDirection.ToBottom, FrameworkPropertyMetadataOptions.AffectsRender));
  34. public static readonly DependencyProperty GasValveV6DataProperty = DependencyProperty.Register(
  35. "GasValveV6Data", typeof(GasValveDataItem), typeof(GasValveV6),
  36. new FrameworkPropertyMetadata(default(GasValveDataItem), FrameworkPropertyMetadataOptions.AffectsRender));
  37. public static readonly DependencyProperty CommandProperty = DependencyProperty.Register(
  38. "Command", typeof(ICommand), typeof(GasValveV6),
  39. new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.AffectsRender));
  40. public ICommand Command
  41. {
  42. get
  43. {
  44. return GetValue(CommandProperty) as ICommand;
  45. }
  46. set
  47. {
  48. SetValue(CommandProperty, value);
  49. }
  50. }
  51. public ValveDirection GasValveV6Direction
  52. {
  53. get
  54. {
  55. return (ValveDirection)GetValue(GasValveV6DirectionProperty);
  56. }
  57. set
  58. {
  59. SetValue(GasValveV6DirectionProperty, value);
  60. }
  61. }
  62. public GasValveDataItem GasValveV6Data
  63. {
  64. get
  65. {
  66. return (GasValveDataItem)GetValue(GasValveV6DataProperty);
  67. }
  68. set
  69. {
  70. SetValue(GasValveV6DataProperty, value);
  71. }
  72. }
  73. /// <summary>
  74. /// 指出哪个是双向阀的主阀,双向阀的开关状态即指主阀开关状态
  75. /// </summary>
  76. public SwithType CoupleValve_V6Main
  77. {
  78. get
  79. {
  80. return (SwithType)GetValue(CoupleValve_V6MainProperty);
  81. }
  82. set
  83. {
  84. SetValue(CoupleValve_V6MainProperty, value);
  85. }
  86. }
  87. public string LeftValveTag { get; set; }
  88. public string RightValveTag { get; set; }
  89. public Thickness nothick = new Thickness(0);
  90. bool _needBlinding = false;
  91. bool _blindingTag = false;
  92. TimeSpan tsBlindTime = new TimeSpan(0, 0, 3);
  93. /// <summary>
  94. /// 容许设定值和真实值不同的时间段 ,在这段时间内不一致可以接受,超出时间就显示警告色
  95. /// </summary>
  96. TimeSpan tsTolerateTime = new TimeSpan(0, 0, 0, 500);
  97. DateTime _startBindingTime = new DateTime();
  98. bool _vCurrentOnOff = false;
  99. bool _vPreviousOnOff = false;
  100. DeviceTimer timer = new DeviceTimer();
  101. /// <summary>
  102. /// 设置警告时显示
  103. /// </summary>
  104. /// <param name="tooltipmessage"></param>
  105. void SetWarning(string tooltipmessage)
  106. {
  107. nopass.Fill = Brushes.Red;
  108. passtrigle.Fill = Brushes.Red;
  109. nopass2.Fill = Brushes.Red;
  110. passtrigle2.Fill = Brushes.Red;
  111. this.ToolTip = tooltipmessage;
  112. }
  113. bool IsWarningSet()
  114. {
  115. return nopass.Fill == Brushes.Red;
  116. }
  117. /// <summary>
  118. /// over rendering behavior
  119. /// </summary>
  120. /// <param name="drawingContext"></param>
  121. protected override void OnRender(DrawingContext drawingContext)
  122. {
  123. try
  124. {
  125. base.OnRender(drawingContext);
  126. //两阀有关联
  127. if (GasValveV6Data != null)
  128. {
  129. this.ToolTip = string.Format("阀门名称:{0} \r\n设备编号:{1}\r\n默认设定:{2}\r\n当前设定:{3} \r\n实际状态:{4}",
  130. GasValveV6Data.DisplayName,
  131. GasValveV6Data.DeviceId,
  132. GasValveV6Data.DefaultValue,
  133. GasValveV6Data.SetValue,
  134. GasValveV6Data.Feedback);
  135. if (GasValveV6Data.Feedback != GasValveV6Data.SetValue)
  136. {
  137. if (timer.IsIdle())
  138. timer.Start(500);
  139. else
  140. {
  141. if (timer.IsTimeout())
  142. {
  143. //if (!IsWarningSet())
  144. SetWarning(string.Format("设定值和实际值不一致!设定:{0},实际:{1}\r\n", GasValveV6Data.SetValue ? "打开" : "关闭", GasValveV6Data.Feedback ? "打开" : "关闭") + this.ToolTip);
  145. }
  146. }
  147. }
  148. else
  149. {
  150. if (!timer.IsIdle())
  151. timer.Stop();
  152. if (nopass.Fill == Brushes.Red)
  153. {
  154. nopass.Fill = Brushes.Black;
  155. passtrigle.Fill = Brushes.Green;
  156. nopass2.Fill = Brushes.Black;
  157. passtrigle2.Fill = Brushes.Green;
  158. }
  159. }
  160. }
  161. _vCurrentOnOff = GasValveV6Data == null ? false : (CoupleValve_V6Main== SwithType.Right)? !GasValveV6Data.Feedback : GasValveV6Data.Feedback;
  162. if (_vCurrentOnOff)
  163. {
  164. passtrigle.Visibility = Visibility.Visible;
  165. nopass.Visibility = Visibility.Hidden;
  166. passtrigle2.Visibility = Visibility.Hidden;
  167. nopass2.Visibility = Visibility.Visible;
  168. }
  169. else
  170. {
  171. passtrigle.Visibility = Visibility.Hidden;
  172. nopass.Visibility = Visibility.Visible;
  173. passtrigle2.Visibility = Visibility.Visible;
  174. nopass2.Visibility = Visibility.Hidden;
  175. }
  176. if (_needBlinding)
  177. {
  178. if (_blindingTag)
  179. {
  180. nopass.Fill = Brushes.LightCoral;
  181. nopass2.Fill = Brushes.LightCoral;
  182. passtrigle.Fill = Brushes.Gold;
  183. passtrigle2.Fill = Brushes.Gold;
  184. }
  185. else
  186. {
  187. nopass.Fill = Brushes.Black;
  188. passtrigle.Fill = Brushes.Green;
  189. nopass2.Fill = Brushes.Black;
  190. passtrigle2.Fill = Brushes.Green;
  191. }
  192. _blindingTag = !_blindingTag;
  193. }
  194. if (_vPreviousOnOff != _vCurrentOnOff)
  195. {
  196. _needBlinding = true;
  197. _startBindingTime = DateTime.Now;
  198. _vPreviousOnOff = _vCurrentOnOff;
  199. }
  200. else
  201. {
  202. if (_startBindingTime < DateTime.Now.Subtract(tsBlindTime))
  203. {
  204. //停止闪烁
  205. if (_needBlinding)
  206. {
  207. _needBlinding = false;
  208. nopass.Fill = Brushes.Black;
  209. passtrigle.Fill = Brushes.Green;
  210. nopass2.Fill = Brushes.Black;
  211. passtrigle2.Fill = Brushes.Green;
  212. }
  213. }
  214. }
  215. }
  216. catch (Exception ex)
  217. {
  218. LOG.Error(ex.Message);
  219. }
  220. }
  221. void SetRectVisible()
  222. {
  223. }
  224. void SetValveDirection(ValveDirection Valve_Direction, RotateTransform rotateTransform)
  225. {
  226. switch (Valve_Direction)
  227. {
  228. case ValveDirection.ToBottom:
  229. rotateTransform.Angle = 90;
  230. break;
  231. case ValveDirection.ToTop:
  232. rotateTransform.Angle = -90;
  233. break;
  234. case ValveDirection.ToLeft:
  235. rotateTransform.Angle = 180;
  236. break;
  237. case ValveDirection.ToRight:
  238. break;
  239. default:
  240. break;
  241. }
  242. }
  243. private void SwitchValve(object sender, RoutedEventArgs e)
  244. {
  245. if ((Command != null) && (GasValveV6Data != null))
  246. {
  247. Command.Execute(new object[] { GasValveV6Data.DeviceName, GasValveOperation.GVTurnValve, !GasValveV6Data.Feedback });
  248. }
  249. }
  250. private void canvasmain_MouseRightButtonUp(object sender, MouseButtonEventArgs e)
  251. {
  252. if (GasValveV6Data == null || string.IsNullOrEmpty(GasValveV6Data.DeviceName))
  253. return;
  254. ContextMenu mouseClickMenu = new ContextMenu();
  255. MenuItem item = new MenuItem();
  256. item.Header = "_" + GasValveV6Data.DisplayName;
  257. item.Background = Brushes.Gray;
  258. item.Foreground = Brushes.White;
  259. item.IsEnabled = false;
  260. mouseClickMenu.Items.Add(item);
  261. item = new MenuItem();
  262. item.Header = "切换 (_C)";
  263. item.Tag = this.Tag;
  264. item.Click += SwitchValve;
  265. mouseClickMenu.Items.Add(item);
  266. mouseClickMenu.IsOpen = true;
  267. }
  268. }
  269. }