TVSettingDialogView.xaml.cs 13 KB

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