AITRfInputDialogBox.xaml.cs 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589
  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.Shapes;
  13. using System.Globalization;
  14. using Aitex.Core.Common.DeviceData;
  15. using Aitex.Core.RT.Log;
  16. namespace Aitex.Core.UI.Control
  17. {
  18. /// <summary>
  19. /// Interaction logic for InputDialogBox.xaml
  20. /// </summary>
  21. public partial class AITRfInputDialogBox : Window
  22. {
  23. public AITRfInputDialogBox()
  24. {
  25. InitializeComponent();
  26. DataContext = this;
  27. WindowStartupLocation = WindowStartupLocation.CenterOwner;
  28. }
  29. public void FocasAll()
  30. {
  31. inputBoxDuty.Text = Math.Round(SetPointDuty, 2).ToString();
  32. inputBoxFrequency.Text = Math.Round(SetPointFrequency, 2).ToString();
  33. inputBoxPower.Text = Math.Round(SetPointPower, 2).ToString();
  34. inputBoxPower.Focus();
  35. inputBoxPower.SelectAll();
  36. }
  37. /// <summary>
  38. /// Vilidate input range
  39. /// </summary>
  40. /// <param name="sender"></param>
  41. /// <param name="e"></param>
  42. private void InputTextBoxPower_TextChanged(object sender, TextChangedEventArgs e)
  43. {
  44. double input;
  45. if (!double.TryParse(inputBoxPower.Text, out input)) buttonSet.IsEnabled = false;
  46. else if (input < 0 || input > MaxValuePower) buttonSet.IsEnabled = false;
  47. else buttonSet.IsEnabled = true;
  48. inputBoxPower.Foreground = buttonSet.IsEnabled ?
  49. System.Windows.Media.Brushes.Black : System.Windows.Media.Brushes.Red;
  50. }
  51. private void InputTextBoxFrequency_TextChanged(object sender, TextChangedEventArgs e)
  52. {
  53. double input;
  54. if (!double.TryParse(inputBoxFrequency.Text, out input)) buttonSet.IsEnabled = false;
  55. else if (input < 0 || input > MaxValueFrequency) buttonSet.IsEnabled = false;
  56. else buttonSet.IsEnabled = true;
  57. inputBoxFrequency.Foreground = buttonSet.IsEnabled ?
  58. System.Windows.Media.Brushes.Black : System.Windows.Media.Brushes.Red;
  59. }
  60. private void InputTextBoxDuty_TextChanged(object sender, TextChangedEventArgs e)
  61. {
  62. double input;
  63. if (!double.TryParse(inputBoxDuty.Text, out input)) buttonSet.IsEnabled = false;
  64. else if (input < 0 || input > MaxValueDuty) buttonSet.IsEnabled = false;
  65. else buttonSet.IsEnabled = true;
  66. inputBoxDuty.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(AITRfInputDialogBox),
  71. new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.AffectsRender));
  72. public static readonly DependencyProperty DeviceIdProperty = DependencyProperty.Register(
  73. "DeviceId", typeof(string), typeof(AITRfInputDialogBox),
  74. new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.AffectsRender));
  75. public static readonly DependencyProperty ForwardPowerProperty = DependencyProperty.Register(
  76. "ForwardPower", typeof(float), typeof(AITRfInputDialogBox),
  77. new FrameworkPropertyMetadata(0.0f, FrameworkPropertyMetadataOptions.AffectsRender));
  78. public static readonly DependencyProperty ReflectPowerProperty = DependencyProperty.Register(
  79. "ReflectPower", typeof(float), typeof(AITRfInputDialogBox),
  80. new FrameworkPropertyMetadata(0.0f, FrameworkPropertyMetadataOptions.AffectsRender));
  81. public static readonly DependencyProperty UnitPowerProperty = DependencyProperty.Register(
  82. "UnitPower", typeof(string), typeof(AITRfInputDialogBox),
  83. new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.AffectsRender));
  84. public static readonly DependencyProperty SetPointPowerProperty = DependencyProperty.Register(
  85. "SetPointPower", typeof(double), typeof(AITRfInputDialogBox),
  86. new FrameworkPropertyMetadata(0.0, FrameworkPropertyMetadataOptions.AffectsRender));
  87. public static readonly DependencyProperty MaxValuePowerProperty = DependencyProperty.Register(
  88. "MaxValuePower", typeof(double), typeof(AITRfInputDialogBox),
  89. new FrameworkPropertyMetadata(0.0, FrameworkPropertyMetadataOptions.AffectsRender));
  90. public static readonly DependencyProperty VoltageProperty = DependencyProperty.Register(
  91. "Voltage", typeof(double), typeof(AITRfInputDialogBox),
  92. new FrameworkPropertyMetadata(0.0, FrameworkPropertyMetadataOptions.AffectsRender));
  93. public static readonly DependencyProperty CurrentProperty = DependencyProperty.Register(
  94. "Current", typeof(double), typeof(AITRfInputDialogBox),
  95. new FrameworkPropertyMetadata(0.0, FrameworkPropertyMetadataOptions.AffectsRender));
  96. public static readonly DependencyProperty UnitFrequencyProperty = DependencyProperty.Register(
  97. "UnitFrequency", typeof(string), typeof(AITRfInputDialogBox),
  98. new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.AffectsRender));
  99. public static readonly DependencyProperty SetPointFrequencyProperty = DependencyProperty.Register(
  100. "SetPointFrequency", typeof(double), typeof(AITRfInputDialogBox),
  101. new FrameworkPropertyMetadata(0.0, FrameworkPropertyMetadataOptions.AffectsRender));
  102. public static readonly DependencyProperty MaxValueFrequencyProperty = DependencyProperty.Register(
  103. "MaxValueFrequency", typeof(double), typeof(AITRfInputDialogBox),
  104. new FrameworkPropertyMetadata(0.0, FrameworkPropertyMetadataOptions.AffectsRender));
  105. public static readonly DependencyProperty UnitDutyProperty = DependencyProperty.Register(
  106. "UnitDuty", typeof(string), typeof(AITRfInputDialogBox),
  107. new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.AffectsRender));
  108. public static readonly DependencyProperty SetPointDutyProperty = DependencyProperty.Register(
  109. "SetPointDuty", typeof(double), typeof(AITRfInputDialogBox),
  110. new FrameworkPropertyMetadata(0.0, FrameworkPropertyMetadataOptions.AffectsRender));
  111. public static readonly DependencyProperty MaxValueDutyProperty = DependencyProperty.Register(
  112. "MaxValueDuty", typeof(double), typeof(AITRfInputDialogBox),
  113. new FrameworkPropertyMetadata(0.0, FrameworkPropertyMetadataOptions.AffectsRender));
  114. public static readonly DependencyProperty IsRfOnProperty = DependencyProperty.Register(
  115. "IsRfOn", typeof(bool), typeof(AITRfInputDialogBox),
  116. new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.AffectsRender));
  117. public static readonly DependencyProperty IsContinuousModeProperty = DependencyProperty.Register(
  118. "IsContinuousMode", typeof(bool), typeof(AITRfInputDialogBox),
  119. new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.AffectsRender));
  120. public static readonly DependencyProperty IsPulsingModeProperty = DependencyProperty.Register(
  121. "IsPulsingMode", typeof(bool), typeof(AITRfInputDialogBox),
  122. new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.AffectsRender));
  123. public static readonly DependencyProperty EnablePulsingProperty = DependencyProperty.Register(
  124. "EnablePulsing", typeof(bool), typeof(AITRfInputDialogBox),
  125. new FrameworkPropertyMetadata(true, FrameworkPropertyMetadataOptions.AffectsRender));
  126. public static readonly DependencyProperty EnableReflectProperty = DependencyProperty.Register(
  127. "EnableReflect", typeof(bool), typeof(AITRfInputDialogBox),
  128. new FrameworkPropertyMetadata(true, FrameworkPropertyMetadataOptions.AffectsRender));
  129. public static readonly DependencyProperty EnableVoltageCurrentProperty = DependencyProperty.Register(
  130. "EnableVoltageCurrent", typeof(bool), typeof(AITRfInputDialogBox),
  131. new FrameworkPropertyMetadata(true, FrameworkPropertyMetadataOptions.AffectsRender));
  132. public static readonly DependencyProperty GridLengthReflectProperty = DependencyProperty.Register(
  133. "GridLengthReflect", typeof(GridLength), typeof(AITRfInputDialogBox),
  134. new FrameworkPropertyMetadata(GridLength.Auto, FrameworkPropertyMetadataOptions.AffectsRender));
  135. public static readonly DependencyProperty GridLengthVoltageCurrentProperty = DependencyProperty.Register(
  136. "GridLengthVoltageCurrent", typeof(GridLength), typeof(AITRfInputDialogBox),
  137. new FrameworkPropertyMetadata(GridLength.Auto, FrameworkPropertyMetadataOptions.AffectsRender));
  138. /// <summary>
  139. /// 是否百分比显示
  140. /// </summary>
  141. public bool IsPercent { get; set; }
  142. public string DeviceName
  143. {
  144. get
  145. {
  146. return (string)this.GetValue(DeviceNameProperty);
  147. }
  148. set
  149. {
  150. if (!string.IsNullOrEmpty(value) && !value.StartsWith("_"))
  151. value = "_" + value;
  152. this.SetValue(DeviceNameProperty, value);
  153. }
  154. }
  155. public string DeviceId
  156. {
  157. get
  158. {
  159. return (string)this.GetValue(DeviceIdProperty);
  160. }
  161. set
  162. {
  163. this.SetValue(DeviceIdProperty, value);
  164. }
  165. }
  166. public string UnitPower
  167. {
  168. get
  169. {
  170. return (string)this.GetValue(UnitPowerProperty);
  171. }
  172. set
  173. {
  174. this.SetValue(UnitPowerProperty, value);
  175. }
  176. }
  177. public double SetPointPower
  178. {
  179. get
  180. {
  181. return (double)this.GetValue(SetPointPowerProperty);
  182. }
  183. set
  184. {
  185. this.SetValue(SetPointPowerProperty, value);
  186. }
  187. }
  188. public double MaxValuePower
  189. {
  190. get
  191. {
  192. return (double)this.GetValue(MaxValuePowerProperty);
  193. }
  194. set
  195. {
  196. this.SetValue(MaxValuePowerProperty, value);
  197. }
  198. }
  199. public string UnitFrequency
  200. {
  201. get
  202. {
  203. return (string)this.GetValue(UnitFrequencyProperty);
  204. }
  205. set
  206. {
  207. this.SetValue(UnitFrequencyProperty, value);
  208. }
  209. }
  210. public double SetPointFrequency
  211. {
  212. get
  213. {
  214. return (double)this.GetValue(SetPointFrequencyProperty);
  215. }
  216. set
  217. {
  218. this.SetValue(SetPointFrequencyProperty, value);
  219. }
  220. }
  221. public double MaxValueFrequency
  222. {
  223. get
  224. {
  225. return (double)this.GetValue(MaxValueFrequencyProperty);
  226. }
  227. set
  228. {
  229. this.SetValue(MaxValueFrequencyProperty, value);
  230. }
  231. }
  232. public double Voltage
  233. {
  234. get
  235. {
  236. return (double)this.GetValue(VoltageProperty);
  237. }
  238. set
  239. {
  240. this.SetValue(VoltageProperty, value);
  241. }
  242. }
  243. public double Current
  244. {
  245. get
  246. {
  247. return (double)this.GetValue(CurrentProperty);
  248. }
  249. set
  250. {
  251. this.SetValue(CurrentProperty, value);
  252. }
  253. }
  254. public string UnitDuty
  255. {
  256. get
  257. {
  258. return (string)this.GetValue(UnitDutyProperty);
  259. }
  260. set
  261. {
  262. this.SetValue(UnitDutyProperty, value);
  263. }
  264. }
  265. public double SetPointDuty
  266. {
  267. get
  268. {
  269. return (double)this.GetValue(SetPointDutyProperty);
  270. }
  271. set
  272. {
  273. this.SetValue(SetPointDutyProperty, value);
  274. }
  275. }
  276. public double MaxValueDuty
  277. {
  278. get
  279. {
  280. return (double)this.GetValue(MaxValueDutyProperty);
  281. }
  282. set
  283. {
  284. this.SetValue(MaxValueDutyProperty, value);
  285. }
  286. }
  287. public float ForwardPower
  288. {
  289. get
  290. {
  291. return (float)this.GetValue(ForwardPowerProperty);
  292. }
  293. set
  294. {
  295. this.SetValue(ForwardPowerProperty, value);
  296. }
  297. }
  298. public float ReflectPower
  299. {
  300. get
  301. {
  302. return (float)this.GetValue(ReflectPowerProperty);
  303. }
  304. set
  305. {
  306. this.SetValue(ReflectPowerProperty, value);
  307. }
  308. }
  309. public bool IsRfOn
  310. {
  311. get
  312. {
  313. return (bool)this.GetValue(IsRfOnProperty);
  314. }
  315. set
  316. {
  317. this.SetValue(IsRfOnProperty, value);
  318. buttonRFOff.IsEnabled = value;
  319. buttonRFOn.IsEnabled = !value;
  320. //if (!value)
  321. // buttonSet.IsEnabled = false;
  322. }
  323. }
  324. public bool IsContinuousMode
  325. {
  326. get
  327. {
  328. return (bool)this.GetValue(IsContinuousModeProperty);
  329. }
  330. set
  331. {
  332. this.SetValue(IsContinuousModeProperty, value);
  333. ckContinuous.IsChecked = IsContinuousMode;
  334. lblFrequency.Foreground = IsPulsingMode ? Brushes.Black : Brushes.Gray;
  335. lblDuty.Foreground = IsPulsingMode ? Brushes.Black : Brushes.Gray;
  336. inputBoxFrequency.IsEnabled = IsPulsingMode;
  337. inputBoxDuty.IsEnabled = IsPulsingMode;
  338. }
  339. }
  340. public bool IsPulsingMode
  341. {
  342. get
  343. {
  344. return (bool)this.GetValue(IsPulsingModeProperty);
  345. }
  346. set
  347. {
  348. this.SetValue(IsPulsingModeProperty, value);
  349. ckPulsing.IsChecked = IsPulsingMode;
  350. lblFrequency.Foreground = IsPulsingMode ? Brushes.Black : Brushes.Gray;
  351. lblDuty.Foreground = IsPulsingMode ? Brushes.Black : Brushes.Gray;
  352. inputBoxFrequency.IsEnabled = IsPulsingMode;
  353. inputBoxDuty.IsEnabled = IsPulsingMode;
  354. }
  355. }
  356. public bool EnablePulsing
  357. {
  358. get
  359. {
  360. return (bool)this.GetValue(EnablePulsingProperty);
  361. }
  362. set
  363. {
  364. this.SetValue(EnablePulsingProperty, value);
  365. ckPulsing.Visibility = value ? Visibility.Visible : Visibility.Hidden;
  366. }
  367. }
  368. public bool EnableReflect
  369. {
  370. get
  371. {
  372. return (bool)this.GetValue(EnableReflectProperty);
  373. }
  374. set
  375. {
  376. this.SetValue(EnableReflectProperty, value);
  377. }
  378. }
  379. public bool EnableVoltageCurrent
  380. {
  381. get
  382. {
  383. return (bool)this.GetValue(EnableVoltageCurrentProperty);
  384. }
  385. set
  386. {
  387. this.SetValue(EnableVoltageCurrentProperty, value);
  388. }
  389. }
  390. public GridLength GridLengthReflect
  391. {
  392. get
  393. {
  394. return (GridLength)this.GetValue(GridLengthReflectProperty);
  395. }
  396. set
  397. {
  398. this.SetValue(GridLengthReflectProperty, value);
  399. }
  400. }
  401. public GridLength GridLengthWorkMode
  402. {
  403. get;
  404. set;
  405. }
  406. public GridLength GridLengthVoltageCurrent
  407. {
  408. get
  409. {
  410. return (GridLength)this.GetValue(GridLengthVoltageCurrentProperty);
  411. }
  412. set
  413. {
  414. this.SetValue(GridLengthVoltageCurrentProperty, value);
  415. }
  416. }
  417. public Action<RfMode> SetRfModeCommandDelegate;
  418. public Action<bool> SetRfPowerOnOffCommandDelegate;
  419. public Action<double> SetContinuousCommandDelegate;
  420. public Action<double, double, double> SetPulsingCommandDelegate;
  421. private void ButtonSet_Click(object sender, RoutedEventArgs e)
  422. {
  423. try
  424. {
  425. if (IsContinuousMode)
  426. SetContinuousCommandDelegate(Convert.ToDouble(inputBoxPower.Text));
  427. else if (IsPulsingMode)
  428. SetPulsingCommandDelegate(Convert.ToDouble(inputBoxPower.Text), Convert.ToDouble(inputBoxFrequency.Text), Convert.ToDouble(inputBoxDuty.Text));
  429. Close();
  430. }
  431. catch (Exception ex)
  432. {
  433. LOG.Error(ex.Message);
  434. }
  435. }
  436. private void OnEnterKeyIsHit(object sender, KeyEventArgs e)
  437. {
  438. try
  439. {
  440. if (!buttonSet.IsEnabled) return;
  441. if (e.Key == Key.Return)
  442. {
  443. ButtonSet_Click(null, null);
  444. }
  445. }
  446. catch (Exception ex)
  447. {
  448. LOG.Error(ex.Message);
  449. }
  450. }
  451. private void ButtonCancel_Click(object sender, RoutedEventArgs e)
  452. {
  453. Close();
  454. }
  455. private void CkPulsing_OnChecked(object sender, RoutedEventArgs e)
  456. {
  457. if (IsPulsingMode)
  458. return;
  459. ckPulsing.IsChecked = false;
  460. try
  461. {
  462. if (SetRfModeCommandDelegate != null)
  463. {
  464. SetRfModeCommandDelegate(RfMode.PulsingMode);
  465. }
  466. }
  467. catch (Exception ex)
  468. {
  469. LOG.Error(ex.Message);
  470. }
  471. }
  472. private void CkContinuous_OnChecked(object sender, RoutedEventArgs e)
  473. {
  474. if (IsContinuousMode)
  475. return;
  476. ckContinuous.IsChecked = false;
  477. try
  478. {
  479. if (SetRfModeCommandDelegate != null)
  480. {
  481. SetRfModeCommandDelegate(RfMode.ContinuousWaveMode);
  482. }
  483. }
  484. catch (Exception ex)
  485. {
  486. LOG.Error(ex.Message);
  487. }
  488. }
  489. private void CkContinuous_OnClick(object sender, RoutedEventArgs e)
  490. {
  491. ckContinuous.IsChecked = IsContinuousMode;
  492. }
  493. private void CkPulsing_OnClick(object sender, RoutedEventArgs e)
  494. {
  495. ckPulsing.IsChecked = IsPulsingMode;
  496. }
  497. private void ButtonRFOn_Click(object sender, RoutedEventArgs e)
  498. {
  499. try
  500. {
  501. if (SetRfPowerOnOffCommandDelegate != null)
  502. {
  503. SetRfPowerOnOffCommandDelegate(true);
  504. }
  505. }
  506. catch (Exception ex)
  507. {
  508. LOG.Error(ex.Message);
  509. }
  510. }
  511. private void ButtonRFOff_Click(object sender, RoutedEventArgs e)
  512. {
  513. try
  514. {
  515. if (SetRfPowerOnOffCommandDelegate != null)
  516. {
  517. SetRfPowerOnOffCommandDelegate(false);
  518. }
  519. }
  520. catch (Exception ex)
  521. {
  522. LOG.Error(ex.Message);
  523. }
  524. }
  525. }
  526. }