AnalogControl4Jet.xaml.cs 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540
  1. using Aitex.Core.UI.ControlDataContext;
  2. using MECF.Framework.UI.Core.ExtendedControls;
  3. using System;
  4. using System.Windows;
  5. using System.Windows.Controls;
  6. using System.Windows.Input;
  7. using System.Windows.Media;
  8. namespace Aitex.Core.UI.Control
  9. {
  10. /// <summary>
  11. /// Interaction logic for AnalogControl.xaml
  12. /// </summary>
  13. public partial class AnalogControl4Jet : UserControl
  14. {
  15. public AnalogControl4Jet()
  16. {
  17. InitializeComponent();
  18. }
  19. public string ViewName
  20. {
  21. get { return (string)this.GetValue(ViewNameProperty); }
  22. set { this.SetValue(ViewNameProperty, value); }
  23. }
  24. // Using a DependencyProperty as the backing store for MenuVisibility. This enables animation, styling, binding, etc...
  25. public static readonly DependencyProperty ViewNameProperty =
  26. DependencyProperty.Register("ViewName", typeof(string), typeof(AnalogControl4Jet),
  27. new FrameworkPropertyMetadata(""));
  28. public bool IsExecute
  29. {
  30. get { return (bool)this.GetValue(IsExecuteProperty); }
  31. set { this.SetValue(IsExecuteProperty, value); }
  32. }
  33. // Using a DependencyProperty as the backing store for MenuVisibility. This enables animation, styling, binding, etc...
  34. public static readonly DependencyProperty IsExecuteProperty =
  35. DependencyProperty.Register("IsExecute", typeof(bool), typeof(AnalogControl4Jet),
  36. new FrameworkPropertyMetadata(true));
  37. // define dependency properties
  38. public static readonly DependencyProperty CommandProperty = DependencyProperty.Register(
  39. "Command", typeof(ICommand), typeof(AnalogControl4Jet),
  40. new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.AffectsRender));
  41. public static readonly DependencyProperty DeviceDataProperty = DependencyProperty.Register(
  42. "DeviceData", typeof(AnalogDeviceDataItem), typeof(AnalogControl4Jet),
  43. new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.AffectsRender,
  44. new PropertyChangedCallback(OnDeviceDataChanged)));
  45. public static readonly DependencyProperty TagNameProperty = DependencyProperty.Register(
  46. "TagName", typeof(string), typeof(AnalogControl4Jet),
  47. new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.AffectsRender));
  48. public static readonly DependencyProperty OperationNameProperty = DependencyProperty.Register(
  49. "OperationName", typeof(string), typeof(AnalogControl4Jet),
  50. new FrameworkPropertyMetadata(AnalogDeviceOperation.Ramp, FrameworkPropertyMetadataOptions.AffectsRender));
  51. public static readonly DependencyProperty BackColorProperty = DependencyProperty.Register(
  52. "BackColor", typeof(Brush), typeof(AnalogControl4Jet),
  53. new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.AffectsRender));
  54. public static readonly DependencyProperty HideDialogProperty = DependencyProperty.Register(
  55. "HideDialog", typeof(bool), typeof(AnalogControl4Jet),
  56. new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.AffectsRender));
  57. private double oldFeedBack;
  58. public static readonly DependencyProperty GasStateTypeProperty = DependencyProperty.Register(
  59. "GasStateType", typeof(GasPanelStateType), typeof(AnalogControl4Jet),
  60. new FrameworkPropertyMetadata(GasPanelStateType.Manual, FrameworkPropertyMetadataOptions.AffectsRender,new PropertyChangedCallback(OnDeviceStateTypeChanged)));
  61. public GasPanelStateType GasStateType
  62. {
  63. get
  64. {
  65. return (GasPanelStateType)this.GetValue(GasStateTypeProperty);
  66. }
  67. set
  68. {
  69. this.SetValue(GasStateTypeProperty, value);
  70. }
  71. }
  72. public static readonly DependencyProperty ShowValueProperty = DependencyProperty.Register(
  73. "ShowValue", typeof(string), typeof(AnalogControl4Jet),
  74. new FrameworkPropertyMetadata(0.ToString("f3"), FrameworkPropertyMetadataOptions.AffectsArrange));
  75. public string ShowValue
  76. {
  77. get
  78. {
  79. return (string)this.GetValue(ShowValueProperty);
  80. }
  81. set
  82. {
  83. this.SetValue(ShowValueProperty, value);
  84. }
  85. }
  86. public string TagName
  87. {
  88. get
  89. {
  90. return (string)this.GetValue(TagNameProperty);
  91. }
  92. set
  93. {
  94. this.SetValue(TagNameProperty, value);
  95. }
  96. }
  97. private static void OnDeviceStateTypeChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
  98. {
  99. SetDataChanged(d);
  100. }
  101. private static void OnDeviceDataChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
  102. {
  103. SetDataChanged(d);
  104. }
  105. private static void SetDataChanged(DependencyObject d)
  106. {
  107. var self = (AnalogControl4Jet)d;
  108. var data = self.DeviceData;
  109. var gasStateType = self.GasStateType;
  110. if (data != null)
  111. {
  112. switch (gasStateType)
  113. {
  114. case GasPanelStateType.Manual:
  115. self.ShowValue = data.SetPoint.ToString("f3");
  116. break;
  117. case GasPanelStateType.Monitor:
  118. self.ShowValue = data.FeedBack.ToString("f3");
  119. break;
  120. case GasPanelStateType.Recipe:
  121. self.ShowValue = data.VirtualFeedBack.ToString("f3");
  122. break;
  123. default:
  124. self.ShowValue = 0.ToString("f3");
  125. break;
  126. }
  127. self.oldFeedBack = data.FeedBack;
  128. if (data.DeviceId.Contains("MFM"))
  129. {
  130. self.ViewName = data.DeviceId;
  131. }
  132. else
  133. {
  134. self.ViewName = data.DeviceId.Replace("MFC", "");
  135. }
  136. ChangedBackground(self);
  137. }
  138. }
  139. /// <summary>
  140. /// 输入值是否百分比,默认否
  141. /// </summary>
  142. public bool IsPercent { get; set; }
  143. public Visibility RampVisibility { get; set; } = Visibility.Collapsed;
  144. public ICommand Command
  145. {
  146. get
  147. {
  148. return (ICommand)this.GetValue(CommandProperty);
  149. }
  150. set
  151. {
  152. this.SetValue(CommandProperty, value);
  153. }
  154. }
  155. /// <summary>
  156. /// set, get current progress value AnalogDeviceData
  157. /// </summary>
  158. public AnalogDeviceDataItem DeviceData
  159. {
  160. get
  161. {
  162. return (AnalogDeviceDataItem)this.GetValue(DeviceDataProperty);
  163. }
  164. set
  165. {
  166. this.SetValue(DeviceDataProperty, value);
  167. }
  168. }
  169. public Brush BackColor
  170. {
  171. get
  172. {
  173. return (Brush)this.GetValue(BackColorProperty);
  174. }
  175. set
  176. {
  177. this.SetValue(BackColorProperty, value);
  178. }
  179. }
  180. public bool HideDialog
  181. {
  182. get
  183. {
  184. return (bool)this.GetValue(HideDialogProperty);
  185. }
  186. set
  187. {
  188. this.SetValue(HideDialogProperty, value);
  189. }
  190. }
  191. protected override void OnRender(DrawingContext drawingContext)
  192. {
  193. base.OnRender(drawingContext);
  194. //draw background color
  195. // RefreshMFCData();
  196. }
  197. private void RefreshMFCData()
  198. {
  199. #region FeedBack
  200. if (DeviceData == null) return;
  201. //draw red board if mfc meets a warning
  202. //draw reading value
  203. //if (IsPercent)
  204. // labelValue.Content = (DeviceData.FeedBack * 100).ToString("F1");
  205. //else
  206. // labelValue.Content = DeviceData.FeedBack.ToString("F1");
  207. labelValue1.Foreground = DeviceData.IsWarning ? Brushes.Pink : Brushes.Black;
  208. //if (dialogBox != null)
  209. //{
  210. // if (IsPercent)
  211. // dialogBox.RealValue = (DeviceData.FeedBack * 100).ToString("F1") + "%";
  212. // else
  213. // dialogBox.RealValue = DeviceData.FeedBack.ToString("F1");
  214. //}
  215. //draw red board if mfc meets a warning
  216. //draw reading value
  217. //if (IsPercent)
  218. // labelSetPoint.Content = (DeviceData.SetPoint * 100).ToString("F1");
  219. //else
  220. // labelSetPoint.Content = DeviceData.SetPoint.ToString("F1");
  221. //if (DeviceData.DeviceId.Contains("MFM"))
  222. //{
  223. // labelSetPoint.Content = DeviceData.DeviceId;
  224. //}
  225. //else
  226. //{
  227. // labelSetPoint.Content = DeviceData.DeviceId.Replace("MFC", "");
  228. //}
  229. labelSetPoint.Foreground = DeviceData.IsWarning ? Brushes.Pink : Brushes.Black;
  230. if (DeviceData != null)
  231. {
  232. ChangedBackground();
  233. }
  234. #endregion
  235. }
  236. private void ChangedBackground()
  237. {
  238. BrushConverter brushConverter = new BrushConverter();
  239. switch (GasStateType)
  240. {
  241. case GasPanelStateType.Manual:
  242. ShowValue = DeviceData.SetPoint.ToString("f3");
  243. //if (DeviceData.IsCharge)
  244. //{
  245. // topBorder.Background = (Brush)brushConverter.ConvertFromString("#FFFFD2");
  246. // downBorder.Background = (Brush)brushConverter.ConvertFromString("#FFFFD2");
  247. //}
  248. //else
  249. //{
  250. // topBorder.Background = (Brush)brushConverter.ConvertFromString("#B0D1F1");
  251. // downBorder.Background = (Brush)brushConverter.ConvertFromString("#B0D1F1");
  252. //}
  253. break;
  254. case GasPanelStateType.Monitor:
  255. ShowValue = DeviceData.FeedBack.ToString("f3");
  256. //topBorder.Background = (Brush)brushConverter.ConvertFromString("#B0D1F1");
  257. //downBorder.Background = (Brush)brushConverter.ConvertFromString("#B0D1F1");
  258. break;
  259. case GasPanelStateType.Recipe:
  260. ShowValue = DeviceData.VirtualFeedBack.ToString("f3");
  261. break;
  262. default:
  263. ShowValue = 0.ToString("f3");
  264. break;
  265. }
  266. topBorder.Background = Math.Abs(float.Parse(ShowValue)) > 0.00001 ? (Brush)brushConverter.ConvertFromString("#FFFFD2") : (Brush)brushConverter.ConvertFromString("#B0D1F1");
  267. downBorder.Background = Math.Abs(float.Parse(ShowValue)) > 0.00001 ? (Brush)brushConverter.ConvertFromString("#FFFFD2") : (Brush)brushConverter.ConvertFromString("#B0D1F1");
  268. }
  269. private static void ChangedBackground(AnalogControl4Jet analog4Jet)
  270. {
  271. BrushConverter brushConverter = new BrushConverter();
  272. //switch (analog4Jet.GasStateType)
  273. //{
  274. // case GasPanelStateType.Manual:
  275. // if (analog4Jet.DeviceData.IsCharge)
  276. // {
  277. // analog4Jet.topBorder.Background = (Brush)brushConverter.ConvertFromString("#FFFFD2");
  278. // analog4Jet.downBorder.Background = (Brush)brushConverter.ConvertFromString("#FFFFD2");
  279. // }
  280. // else
  281. // {
  282. // analog4Jet.topBorder.Background = (Brush)brushConverter.ConvertFromString("#B0D1F1");
  283. // analog4Jet.downBorder.Background = (Brush)brushConverter.ConvertFromString("#B0D1F1");
  284. // }
  285. // break;
  286. // case GasPanelStateType.Monitor:
  287. // analog4Jet.topBorder.Background = (Brush)brushConverter.ConvertFromString("#B0D1F1");
  288. // analog4Jet.downBorder.Background = (Brush)brushConverter.ConvertFromString("#B0D1F1");
  289. // break;
  290. // case GasPanelStateType.Recipe:
  291. // break;
  292. // default:
  293. // break;
  294. //}
  295. analog4Jet.topBorder.Background = Math.Abs(float.Parse(analog4Jet.ShowValue)) > 0.00001 ? (Brush)brushConverter.ConvertFromString("#FFFFD2") : (Brush)brushConverter.ConvertFromString("#B0D1F1");
  296. analog4Jet.downBorder.Background = Math.Abs(float.Parse(analog4Jet.ShowValue)) > 0.00001 ? (Brush)brushConverter.ConvertFromString("#FFFFD2") : (Brush)brushConverter.ConvertFromString("#B0D1F1");
  297. analog4Jet.UpdateLayout();
  298. }
  299. private void RefreshMFCData(AnalogDeviceDataItem data)
  300. {
  301. #region FeedBack
  302. if (data == null) return;
  303. //draw red board if mfc meets a warning
  304. //draw reading value
  305. //if (IsPercent)
  306. // labelValue.Content = (data.FeedBack * 100).ToString("F1");
  307. //else
  308. // labelValue.Content = data.FeedBack.ToString("F1");
  309. labelValue1.Foreground = data.IsWarning ? Brushes.Pink : Brushes.Black;
  310. //if (dialogBox != null)
  311. //{
  312. // if (IsPercent)
  313. // dialogBox.RealValue = (data.FeedBack * 100).ToString("F1") + "%";
  314. // else
  315. // dialogBox.RealValue = data.FeedBack.ToString("F1");
  316. //}
  317. //draw red board if mfc meets a warning
  318. //draw reading value
  319. //if (IsPercent)
  320. // labelSetPoint.Content = (DeviceData.SetPoint * 100).ToString("F1");
  321. //else
  322. // labelSetPoint.Content = DeviceData.SetPoint.ToString("F1");
  323. if (data.DeviceId.Contains("MFM"))
  324. {
  325. labelSetPoint.Content = data.DeviceId.Replace("MFM", "");
  326. }
  327. else
  328. {
  329. labelSetPoint.Content = data.DeviceId.Replace("MFC", "");
  330. }
  331. if (DeviceData != null)
  332. {
  333. switch (GasStateType)
  334. {
  335. case GasPanelStateType.Manual:
  336. case GasPanelStateType.Monitor:
  337. ShowValue = data.FeedBack.ToString("f3");
  338. break;
  339. case GasPanelStateType.Recipe:
  340. ShowValue = data.VirtualFeedBack.ToString("f3");
  341. break;
  342. default:
  343. ShowValue = 0.ToString("f3");
  344. break;
  345. }
  346. }
  347. labelSetPoint.Foreground = data.IsWarning ? Brushes.Pink : Brushes.Black;
  348. #endregion
  349. }
  350. ///// <summary>
  351. ///// 设置鼠标的坐标
  352. ///// </summary>
  353. ///// <param name="x">横坐标</param>
  354. ///// <param name="y">纵坐标</param>
  355. //[DllImport("User32")]
  356. //public extern static void SetCursorPos(int x, int y);
  357. // private InputDialogBox dialogBox;
  358. public Window AnalogOwner { get; set; }
  359. private void Grid_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
  360. {
  361. if (e.StylusDevice != null) e.Handled = true;//认为误触
  362. else Grid_TouchUp(sender, null);
  363. }
  364. private void Execute(double value, double? ramp)
  365. {
  366. if (!IsExecute)
  367. {
  368. return;
  369. }
  370. switch (GasStateType)
  371. {
  372. case GasPanelStateType.Manual:
  373. if (ramp != null)
  374. {
  375. Command.Execute(new object[] { DeviceData.DeviceName, DeviceData.Type.Equals("MFC") ? "SetMfcValue" : "SetMfmValue", value, ramp });
  376. }
  377. else
  378. {
  379. Command.Execute(new object[] { DeviceData.DeviceName, DeviceData.Type.Equals("MFC") ? "SetMfcValue" : "SetMfmValue", value });
  380. }
  381. break;
  382. case GasPanelStateType.Monitor:
  383. break;
  384. case GasPanelStateType.Recipe:
  385. Command.Execute(new object[] { DeviceData.DeviceName, DeviceData.Type.Equals("MFC") ? "SetMfcVirtualValue" : "SetMfmValue", value });
  386. ShowValue = value.ToString("f3");
  387. ChangedBackground(this);
  388. break;
  389. default:
  390. break;
  391. }
  392. }
  393. private void Grid_MouseEnter(object sender, MouseEventArgs e)
  394. {
  395. if (DeviceData != null)
  396. {
  397. string tooltipValue =
  398. string.Format("{0}:{1}\r\n\r\nID:{2}\r\nScale:{3} {4}\r\nSetPoint:{5} {4} \r\nFeedback:{6} {4}\r\nTolerance:{7}%\r\nStatus:{8}",
  399. DeviceData.Type,
  400. DeviceData.DisplayName,
  401. DeviceData.DeviceId,
  402. DeviceData.Scale,
  403. DeviceData.Unit,
  404. IsPercent ? (DeviceData.SetPoint * 100).ToString("F1") + "%" : DeviceData.SetPoint.ToString("F1"),
  405. IsPercent ? (DeviceData.FeedBack * 100).ToString("F1") + "%" : DeviceData.FeedBack.ToString("F1"),
  406. DeviceData.Scale > 0 ? ((DeviceData.FeedBack - DeviceData.SetPoint) / DeviceData.Scale * 100).ToString("F1") : "0",
  407. DeviceData.IsWarning ? "Tolerance Warning" : "Normal");
  408. ToolTip = tooltipValue;
  409. }
  410. }
  411. private void Grid_TouchUp(object sender, TouchEventArgs e)
  412. {
  413. if (DeviceData == null)
  414. return;
  415. if (GasStateType == GasPanelStateType.Monitor) return;
  416. if (HideDialog)
  417. return;
  418. BrushConverter brushConverter = new BrushConverter();
  419. InputDialogBox dialogBox = new InputDialogBox
  420. {
  421. CommandDelegate = Execute,
  422. DeviceName = string.Format("{0}: {1}", DeviceData.Type, DeviceData.DisplayName),
  423. DeviceId = DeviceData.DeviceId,
  424. DefaultValue = DeviceData.DefaultValue,
  425. RealValue = DeviceData.FeedBack.ToString("F1"),
  426. SetPoint = Math.Round(DeviceData.SetPoint, 1),
  427. MaxValue = DeviceData.Scale,
  428. Unit = DeviceData.Unit,
  429. TagName = TagName,
  430. RampValue = DeviceData.RampValue,
  431. RampMaxValue = DeviceData.RampMaxValue,
  432. RampMinValue = DeviceData.RampMinValue,
  433. RampVisibility = (GasStateType == GasPanelStateType.Manual && RampVisibility == Visibility.Visible) ? Visibility.Visible : Visibility.Collapsed
  434. };
  435. dialogBox.IsPercent = IsPercent;
  436. if (IsPercent)
  437. dialogBox.SetPoint = Math.Round(DeviceData.SetPoint * 100.0, 1);
  438. if (AnalogOwner != null)
  439. dialogBox.Owner = AnalogOwner;
  440. dialogBox.Topmost = false;
  441. dialogBox.WindowStartupLocation = WindowStartupLocation.CenterScreen;
  442. //dialogBox.FocasAll();
  443. if ((bool)dialogBox.ShowDialog())
  444. {
  445. if (!string.IsNullOrEmpty(dialogBox.inputBox.Text))
  446. {
  447. if (double.Parse(dialogBox.inputBox.Text) != DeviceData.FeedBack)
  448. {
  449. DeviceData.IsCharge = true;
  450. }
  451. else
  452. {
  453. DeviceData.IsCharge = false;
  454. }
  455. DeviceData.SetValue = double.Parse(dialogBox.inputBox.Text);
  456. ShowValue = DeviceData.SetValue.ToString("f3");
  457. }
  458. if (RampVisibility == Visibility.Visible && GasStateType == GasPanelStateType.Manual)
  459. {
  460. if (!string.IsNullOrEmpty(dialogBox.inputRampBox.Text))
  461. {
  462. if (double.Parse(dialogBox.inputRampBox.Text) != DeviceData.RampValue)
  463. {
  464. DeviceData.IsRampCharge = true;
  465. }
  466. else
  467. {
  468. DeviceData.IsRampCharge = false;
  469. }
  470. DeviceData.SetRampValue = double.Parse(dialogBox.inputRampBox.Text);
  471. }
  472. }
  473. }
  474. //SetCursorPos(0, 0);
  475. dialogBox.Close();
  476. dialogBox.Dispose();
  477. }
  478. }
  479. }