AITThrottleValveInputDialogBox.xaml.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  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.Common.DeviceData;
  15. using Aitex.Core.RT.Log;
  16. namespace MECF.Framework.UI.Client.Ctrlib.UnitControls
  17. {
  18. /// <summary>
  19. /// Interaction logic for InputDialogBox.xaml
  20. /// </summary>
  21. public partial class AITThrottleValveInputDialogBox : Window
  22. {
  23. public AITThrottleValveInputDialogBox()
  24. {
  25. InitializeComponent();
  26. DataContext = this;
  27. WindowStartupLocation = WindowStartupLocation.CenterOwner;
  28. }
  29. public void FocasAll()
  30. {
  31. inputBoxPosition.Text = Math.Round(SetPointPosition, 2).ToString();
  32. if (IsPositionMode)
  33. {
  34. inputBoxPosition.Focus();
  35. inputBoxPosition.SelectAll();
  36. }
  37. inputBoxPressure.Text = Math.Round(SetPointPressure, 2).ToString();
  38. if (IsPressureMode)
  39. {
  40. inputBoxPressure.Focus();
  41. inputBoxPressure.SelectAll();
  42. }
  43. }
  44. /// <summary>
  45. /// Vilidate input range
  46. /// </summary>
  47. /// <param name="sender"></param>
  48. /// <param name="e"></param>
  49. private void InputTextBoxPosition_TextChanged(object sender, TextChangedEventArgs e)
  50. {
  51. double input;
  52. if (!double.TryParse(inputBoxPosition.Text, out input)) buttonSet.IsEnabled = false;
  53. else if (input < 0 || input > MaxValuePosition) buttonSet.IsEnabled = false;
  54. else buttonSet.IsEnabled = true;
  55. inputBoxPosition.Foreground = buttonSet.IsEnabled ?
  56. System.Windows.Media.Brushes.Black : System.Windows.Media.Brushes.Red;
  57. }
  58. private void InputTextBoxPressure_TextChanged(object sender, TextChangedEventArgs e)
  59. {
  60. double input;
  61. if (!double.TryParse(inputBoxPressure.Text, out input)) buttonSet.IsEnabled = false;
  62. else if (input < 0 || input > MaxValuePressure) buttonSet.IsEnabled = false;
  63. else buttonSet.IsEnabled = true;
  64. inputBoxPressure.Foreground = buttonSet.IsEnabled ?
  65. System.Windows.Media.Brushes.Black : System.Windows.Media.Brushes.Red;
  66. }
  67. public static readonly DependencyProperty DeviceNameProperty = DependencyProperty.Register(
  68. "DeviceName", typeof(string), typeof(AITThrottleValveInputDialogBox),
  69. new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.AffectsRender));
  70. public static readonly DependencyProperty DeviceIdProperty = DependencyProperty.Register(
  71. "DeviceId", typeof(string), typeof(AITThrottleValveInputDialogBox),
  72. new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.AffectsRender));
  73. public static readonly DependencyProperty MaxValuePositionProperty = DependencyProperty.Register(
  74. "MaxValuePosition", typeof(double), typeof(AITThrottleValveInputDialogBox),
  75. new FrameworkPropertyMetadata(0.0, FrameworkPropertyMetadataOptions.AffectsRender));
  76. public static readonly DependencyProperty MaxValuePressureProperty = DependencyProperty.Register(
  77. "MaxValuePressure", typeof(double), typeof(AITThrottleValveInputDialogBox),
  78. new FrameworkPropertyMetadata(0.0, FrameworkPropertyMetadataOptions.AffectsRender));
  79. public static readonly DependencyProperty UnitPositionProperty = DependencyProperty.Register(
  80. "UnitPosition", typeof(string), typeof(AITThrottleValveInputDialogBox),
  81. new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.AffectsRender));
  82. public static readonly DependencyProperty UnitPressureProperty = DependencyProperty.Register(
  83. "UnitPressure", typeof(string), typeof(AITThrottleValveInputDialogBox),
  84. new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.AffectsRender));
  85. public static readonly DependencyProperty SetPointPositionProperty = DependencyProperty.Register(
  86. "SetPointPosition", typeof(double), typeof(AITThrottleValveInputDialogBox),
  87. new FrameworkPropertyMetadata(0.0, FrameworkPropertyMetadataOptions.AffectsRender));
  88. public static readonly DependencyProperty SetPointPressureProperty = DependencyProperty.Register(
  89. "SetPointPressure", typeof(double), typeof(AITThrottleValveInputDialogBox),
  90. new FrameworkPropertyMetadata(0.0, FrameworkPropertyMetadataOptions.AffectsRender));
  91. public static readonly DependencyProperty FeedbackPositionProperty = DependencyProperty.Register(
  92. "FeedbackPosition", typeof(double), typeof(AITThrottleValveInputDialogBox),
  93. new FrameworkPropertyMetadata(0.0, FrameworkPropertyMetadataOptions.AffectsRender));
  94. public static readonly DependencyProperty FeedbackPressureProperty = DependencyProperty.Register(
  95. "FeedbackPressure", typeof(double), typeof(AITThrottleValveInputDialogBox),
  96. new FrameworkPropertyMetadata(0.0, FrameworkPropertyMetadataOptions.AffectsRender));
  97. public static readonly DependencyProperty IsPositionModeProperty = DependencyProperty.Register(
  98. "IsPositionMode", typeof(bool), typeof(AITThrottleValveInputDialogBox),
  99. new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.AffectsRender));
  100. public static readonly DependencyProperty IsPressureModeProperty = DependencyProperty.Register(
  101. "IsPressureMode", typeof(bool), typeof(AITThrottleValveInputDialogBox),
  102. new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.AffectsRender));
  103. /// <summary>
  104. /// 是否百分比显示
  105. /// </summary>
  106. public bool IsPercent { get; set; }
  107. public string DeviceName
  108. {
  109. get
  110. {
  111. return (string)this.GetValue(DeviceNameProperty);
  112. }
  113. set
  114. {
  115. if (!string.IsNullOrEmpty(value) && !value.StartsWith("_"))
  116. value = "_" + value;
  117. this.SetValue(DeviceNameProperty, value);
  118. }
  119. }
  120. public string DeviceId
  121. {
  122. get
  123. {
  124. return (string)this.GetValue(DeviceIdProperty);
  125. }
  126. set
  127. {
  128. this.SetValue(DeviceIdProperty, value);
  129. }
  130. }
  131. public double MaxValuePosition
  132. {
  133. get
  134. {
  135. return (double)this.GetValue(MaxValuePositionProperty);
  136. }
  137. set
  138. {
  139. this.SetValue(MaxValuePositionProperty, value);
  140. }
  141. }
  142. public double MaxValuePressure
  143. {
  144. get
  145. {
  146. return (double)this.GetValue(MaxValuePressureProperty);
  147. }
  148. set
  149. {
  150. this.SetValue(MaxValuePressureProperty, value);
  151. }
  152. }
  153. public string UnitPosition
  154. {
  155. get
  156. {
  157. return (string)this.GetValue(UnitPositionProperty);
  158. }
  159. set
  160. {
  161. this.SetValue(UnitPositionProperty, value);
  162. }
  163. }
  164. public string UnitPressure
  165. {
  166. get
  167. {
  168. return (string)this.GetValue(UnitPressureProperty);
  169. }
  170. set
  171. {
  172. this.SetValue(UnitPressureProperty, value);
  173. }
  174. }
  175. public double SetPointPosition
  176. {
  177. get
  178. {
  179. return (double)this.GetValue(SetPointPositionProperty);
  180. }
  181. set
  182. {
  183. this.SetValue(SetPointPositionProperty, value);
  184. }
  185. }
  186. public double SetPointPressure
  187. {
  188. get
  189. {
  190. return (double)this.GetValue(SetPointPressureProperty);
  191. }
  192. set
  193. {
  194. this.SetValue(SetPointPressureProperty, value);
  195. }
  196. }
  197. public double FeedbackPosition
  198. {
  199. get
  200. {
  201. return (double)this.GetValue(FeedbackPositionProperty);
  202. }
  203. set
  204. {
  205. this.SetValue(FeedbackPositionProperty, value);
  206. }
  207. }
  208. public double FeedbackPressure
  209. {
  210. get
  211. {
  212. return (double)this.GetValue(FeedbackPressureProperty);
  213. }
  214. set
  215. {
  216. this.SetValue(FeedbackPressureProperty, value);
  217. }
  218. }
  219. public bool IsPositionMode
  220. {
  221. get
  222. {
  223. return (bool)this.GetValue(IsPositionModeProperty);
  224. }
  225. set
  226. {
  227. this.SetValue(IsPositionModeProperty, value);
  228. ckPosition.IsChecked = IsPositionMode;
  229. }
  230. }
  231. public bool IsPressureMode
  232. {
  233. get
  234. {
  235. return (bool)this.GetValue(IsPressureModeProperty);
  236. }
  237. set
  238. {
  239. this.SetValue(IsPressureModeProperty, value);
  240. ckPressure.IsChecked = IsPressureMode;
  241. }
  242. }
  243. public Action<PressureCtrlMode> SetThrottleModeCommandDelegate;
  244. public Action<double> SetPositionCommandDelegate;
  245. public Action<double> SetPressureCommandDelegate;
  246. private void ButtonSet_Click(object sender, RoutedEventArgs e)
  247. {
  248. if (IsPressureMode)
  249. SetPressureCommandDelegate(Convert.ToDouble(inputBoxPressure.Text));
  250. else if (IsPositionMode)
  251. SetPositionCommandDelegate(Convert.ToDouble(inputBoxPosition.Text));
  252. //Close();
  253. }
  254. private void OnEnterKeyIsHit(object sender, KeyEventArgs e)
  255. {
  256. try
  257. {
  258. if (!buttonSet.IsEnabled) return;
  259. if (e.Key == Key.Return)
  260. {
  261. ButtonSet_Click(null, null);
  262. }
  263. }
  264. catch (Exception ex)
  265. {
  266. LOG.Error(ex.Message);
  267. }
  268. }
  269. private void ButtonCancel_Click(object sender, RoutedEventArgs e)
  270. {
  271. Close();
  272. }
  273. private void CkPosition_OnChecked(object sender, RoutedEventArgs e)
  274. {
  275. if (IsPositionMode)
  276. return;
  277. ckPosition.IsChecked = false;
  278. try
  279. {
  280. if (SetThrottleModeCommandDelegate != null)
  281. {
  282. SetThrottleModeCommandDelegate(PressureCtrlMode.TVPositionCtrl);
  283. }
  284. }
  285. catch (Exception ex)
  286. {
  287. LOG.Error(ex.Message);
  288. }
  289. }
  290. private void CkPressure_OnChecked(object sender, RoutedEventArgs e)
  291. {
  292. if (IsPressureMode)
  293. return;
  294. ckPressure.IsChecked = false;
  295. try
  296. {
  297. if (SetThrottleModeCommandDelegate != null)
  298. {
  299. SetThrottleModeCommandDelegate(PressureCtrlMode.TVPressureCtrl);
  300. }
  301. }
  302. catch (Exception ex)
  303. {
  304. LOG.Error(ex.Message);
  305. }
  306. }
  307. private void CkPosition_OnClick(object sender, RoutedEventArgs e)
  308. {
  309. ckPosition.IsChecked = IsPositionMode;
  310. }
  311. private void CkPressure_OnClick(object sender, RoutedEventArgs e)
  312. {
  313. ckPressure.IsChecked = IsPressureMode;
  314. }
  315. }
  316. }