AnalogControl4Jet.xaml.cs 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504
  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));
  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 OnDeviceDataChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
  98. {
  99. var self = (AnalogControl4Jet)d;
  100. var data = self.DeviceData;
  101. var gasStateType = self.GasStateType;
  102. if (data != null)
  103. {
  104. switch (gasStateType)
  105. {
  106. case GasPanelStateType.Manual:
  107. self.ShowValue = data.SetPoint.ToString("f3");
  108. break;
  109. case GasPanelStateType.Monitor:
  110. self.ShowValue = data.FeedBack.ToString("f3");
  111. break;
  112. case GasPanelStateType.Recipe:
  113. self.ShowValue = data.VirtualFeedBack.ToString("f3");
  114. break;
  115. default:
  116. self.ShowValue = 0.ToString("f3");
  117. break;
  118. }
  119. self.oldFeedBack = data.FeedBack;
  120. }
  121. }
  122. /// <summary>
  123. /// 输入值是否百分比,默认否
  124. /// </summary>
  125. public bool IsPercent { get; set; }
  126. public Visibility RampVisibility { get; set; } = Visibility.Collapsed;
  127. public ICommand Command
  128. {
  129. get
  130. {
  131. return (ICommand)this.GetValue(CommandProperty);
  132. }
  133. set
  134. {
  135. this.SetValue(CommandProperty, value);
  136. }
  137. }
  138. /// <summary>
  139. /// set, get current progress value AnalogDeviceData
  140. /// </summary>
  141. public AnalogDeviceDataItem DeviceData
  142. {
  143. get
  144. {
  145. return (AnalogDeviceDataItem)this.GetValue(DeviceDataProperty);
  146. }
  147. set
  148. {
  149. this.SetValue(DeviceDataProperty, value);
  150. }
  151. }
  152. public Brush BackColor
  153. {
  154. get
  155. {
  156. return (Brush)this.GetValue(BackColorProperty);
  157. }
  158. set
  159. {
  160. this.SetValue(BackColorProperty, value);
  161. }
  162. }
  163. public bool HideDialog
  164. {
  165. get
  166. {
  167. return (bool)this.GetValue(HideDialogProperty);
  168. }
  169. set
  170. {
  171. this.SetValue(HideDialogProperty, value);
  172. }
  173. }
  174. protected override void OnRender(DrawingContext drawingContext)
  175. {
  176. base.OnRender(drawingContext);
  177. //draw background color
  178. RefreshMFCData();
  179. }
  180. public void RefreshMFCData()
  181. {
  182. #region FeedBack
  183. if (DeviceData == null) return;
  184. //draw red board if mfc meets a warning
  185. //draw reading value
  186. //if (IsPercent)
  187. // labelValue.Content = (DeviceData.FeedBack * 100).ToString("F1");
  188. //else
  189. // labelValue.Content = DeviceData.FeedBack.ToString("F1");
  190. labelValue1.Foreground = DeviceData.IsWarning ? Brushes.Pink : Brushes.Black;
  191. //if (dialogBox != null)
  192. //{
  193. // if (IsPercent)
  194. // dialogBox.RealValue = (DeviceData.FeedBack * 100).ToString("F1") + "%";
  195. // else
  196. // dialogBox.RealValue = DeviceData.FeedBack.ToString("F1");
  197. //}
  198. //draw red board if mfc meets a warning
  199. //draw reading value
  200. //if (IsPercent)
  201. // labelSetPoint.Content = (DeviceData.SetPoint * 100).ToString("F1");
  202. //else
  203. // labelSetPoint.Content = DeviceData.SetPoint.ToString("F1");
  204. if (DeviceData.DeviceId.Contains("MFM"))
  205. {
  206. labelSetPoint.Content = DeviceData.DeviceId;
  207. }
  208. else
  209. {
  210. labelSetPoint.Content = DeviceData.DeviceId.Replace("MFC", "");
  211. }
  212. labelSetPoint.Foreground = DeviceData.IsWarning ? Brushes.Pink : Brushes.Black;
  213. if (DeviceData != null)
  214. {
  215. BrushConverter brushConverter = new BrushConverter();
  216. switch (GasStateType)
  217. {
  218. case GasPanelStateType.Manual:
  219. ShowValue = DeviceData.SetPoint.ToString("f3");
  220. if (DeviceData.IsCharge)
  221. {
  222. topBorder.Background = (Brush)brushConverter.ConvertFromString("#FFFFD2");
  223. downBorder.Background = (Brush)brushConverter.ConvertFromString("#FFFFD2");
  224. }
  225. else
  226. {
  227. topBorder.Background = (Brush)brushConverter.ConvertFromString("#B0D1F1");
  228. downBorder.Background = (Brush)brushConverter.ConvertFromString("#B0D1F1");
  229. }
  230. break;
  231. case GasPanelStateType.Monitor:
  232. ShowValue = DeviceData.FeedBack.ToString("f3");
  233. topBorder.Background = (Brush)brushConverter.ConvertFromString("#B0D1F1");
  234. downBorder.Background = (Brush)brushConverter.ConvertFromString("#B0D1F1");
  235. break;
  236. case GasPanelStateType.Recipe:
  237. ShowValue = DeviceData.VirtualFeedBack.ToString("f3");
  238. if ("RecipeView".Equals(ViewName))
  239. {
  240. if (DeviceData.IsCharge || (float.Parse(ShowValue) > 0))
  241. {
  242. topBorder.Background = (Brush)brushConverter.ConvertFromString("#FFFFD2");
  243. downBorder.Background = (Brush)brushConverter.ConvertFromString("#FFFFD2");
  244. }
  245. else
  246. {
  247. topBorder.Background = (Brush)brushConverter.ConvertFromString("#B0D1F1");
  248. downBorder.Background = (Brush)brushConverter.ConvertFromString("#B0D1F1");
  249. }
  250. }
  251. break;
  252. default:
  253. ShowValue = 0.ToString("f3");
  254. break;
  255. }
  256. }
  257. #endregion
  258. }
  259. private void RefreshMFCData(AnalogDeviceDataItem data)
  260. {
  261. #region FeedBack
  262. if (data == null) return;
  263. //draw red board if mfc meets a warning
  264. //draw reading value
  265. //if (IsPercent)
  266. // labelValue.Content = (data.FeedBack * 100).ToString("F1");
  267. //else
  268. // labelValue.Content = data.FeedBack.ToString("F1");
  269. labelValue1.Foreground = data.IsWarning ? Brushes.Pink : Brushes.Black;
  270. //if (dialogBox != null)
  271. //{
  272. // if (IsPercent)
  273. // dialogBox.RealValue = (data.FeedBack * 100).ToString("F1") + "%";
  274. // else
  275. // dialogBox.RealValue = data.FeedBack.ToString("F1");
  276. //}
  277. //draw red board if mfc meets a warning
  278. //draw reading value
  279. //if (IsPercent)
  280. // labelSetPoint.Content = (DeviceData.SetPoint * 100).ToString("F1");
  281. //else
  282. // labelSetPoint.Content = DeviceData.SetPoint.ToString("F1");
  283. if (data.DeviceId.Contains("MFM"))
  284. {
  285. labelSetPoint.Content = data.DeviceId.Replace("MFM", "");
  286. }
  287. else
  288. {
  289. labelSetPoint.Content = data.DeviceId.Replace("MFC", "");
  290. }
  291. if (DeviceData != null)
  292. {
  293. switch (GasStateType)
  294. {
  295. case GasPanelStateType.Manual:
  296. case GasPanelStateType.Monitor:
  297. ShowValue = data.FeedBack.ToString("f3");
  298. break;
  299. case GasPanelStateType.Recipe:
  300. ShowValue = data.VirtualFeedBack.ToString("f3");
  301. break;
  302. default:
  303. ShowValue = 0.ToString("f3");
  304. break;
  305. }
  306. }
  307. labelSetPoint.Foreground = data.IsWarning ? Brushes.Pink : Brushes.Black;
  308. #endregion
  309. }
  310. ///// <summary>
  311. ///// 设置鼠标的坐标
  312. ///// </summary>
  313. ///// <param name="x">横坐标</param>
  314. ///// <param name="y">纵坐标</param>
  315. //[DllImport("User32")]
  316. //public extern static void SetCursorPos(int x, int y);
  317. // private InputDialogBox dialogBox;
  318. public Window AnalogOwner { get; set; }
  319. private void Grid_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
  320. {
  321. if (e.StylusDevice != null) e.Handled = true;//认为误触
  322. else Grid_TouchUp(sender, null);
  323. }
  324. private void ExecuteOrNull(double value, double? ramp)
  325. {
  326. Execute(value, ramp);
  327. }
  328. private void Execute(double value, double? ramp)
  329. {
  330. if (!IsExecute)
  331. {
  332. return;
  333. }
  334. switch (GasStateType)
  335. {
  336. case GasPanelStateType.Manual:
  337. if (ramp != null)
  338. {
  339. Command.Execute(new object[] { DeviceData.DeviceName, DeviceData.Type.Equals("MFC") ? "SetMfcValue" : "SetMfmValue", value, ramp });
  340. }
  341. else
  342. {
  343. Command.Execute(new object[] { DeviceData.DeviceName, DeviceData.Type.Equals("MFC") ? "SetMfcValue" : "SetMfmValue", value });
  344. }
  345. break;
  346. case GasPanelStateType.Monitor:
  347. break;
  348. case GasPanelStateType.Recipe:
  349. Command.Execute(new object[] { DeviceData.DeviceName, DeviceData.Type.Equals("MFC") ? "SetMfcVirtualValue" : "SetMfmValue", value });
  350. break;
  351. default:
  352. break;
  353. }
  354. }
  355. private void Grid_MouseEnter(object sender, MouseEventArgs e)
  356. {
  357. if (DeviceData != null)
  358. {
  359. string tooltipValue =
  360. 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}",
  361. DeviceData.Type,
  362. DeviceData.DisplayName,
  363. DeviceData.DeviceId,
  364. DeviceData.Scale,
  365. DeviceData.Unit,
  366. IsPercent ? (DeviceData.SetPoint * 100).ToString("F1") + "%" : DeviceData.SetPoint.ToString("F1"),
  367. IsPercent ? (DeviceData.FeedBack * 100).ToString("F1") + "%" : DeviceData.FeedBack.ToString("F1"),
  368. DeviceData.Scale > 0 ? ((DeviceData.FeedBack - DeviceData.SetPoint) / DeviceData.Scale * 100).ToString("F1") : "0",
  369. DeviceData.IsWarning ? "Tolerance Warning" : "Normal");
  370. ToolTip = tooltipValue;
  371. }
  372. }
  373. private void Grid_TouchUp(object sender, TouchEventArgs e)
  374. {
  375. if (DeviceData == null)
  376. return;
  377. if (GasStateType == GasPanelStateType.Monitor) return;
  378. if (HideDialog)
  379. return;
  380. BrushConverter brushConverter = new BrushConverter();
  381. InputDialogBox dialogBox = new InputDialogBox
  382. {
  383. CommandDelegate = ExecuteOrNull,
  384. DeviceName = string.Format("{0}: {1}", DeviceData.Type, DeviceData.DisplayName),
  385. DeviceId = DeviceData.DeviceId,
  386. DefaultValue = DeviceData.DefaultValue,
  387. RealValue = DeviceData.FeedBack.ToString("F1"),
  388. SetPoint = Math.Round(DeviceData.SetPoint, 1),
  389. MaxValue = DeviceData.Scale,
  390. Unit = DeviceData.Unit,
  391. TagName = TagName,
  392. RampValue = DeviceData.RampValue,
  393. RampMaxValue = DeviceData.RampMaxValue,
  394. RampMinValue = DeviceData.RampMinValue,
  395. RampVisibility = (GasStateType == GasPanelStateType.Manual && RampVisibility == Visibility.Visible) ? Visibility.Visible : Visibility.Collapsed
  396. };
  397. dialogBox.IsPercent = IsPercent;
  398. if (IsPercent)
  399. dialogBox.SetPoint = Math.Round(DeviceData.SetPoint * 100.0, 1);
  400. if (AnalogOwner != null)
  401. dialogBox.Owner = AnalogOwner;
  402. dialogBox.Topmost = false;
  403. dialogBox.WindowStartupLocation = WindowStartupLocation.CenterScreen;
  404. //dialogBox.FocasAll();
  405. if ((bool)dialogBox.ShowDialog())
  406. {
  407. if (!string.IsNullOrEmpty(dialogBox.inputBox.Text))
  408. {
  409. ShowValue = dialogBox.inputBox.Text;
  410. if (double.Parse(dialogBox.inputBox.Text) != DeviceData.FeedBack)
  411. {
  412. DeviceData.IsCharge = true;
  413. }
  414. else
  415. {
  416. DeviceData.IsCharge = false;
  417. }
  418. DeviceData.SetValue = double.Parse(dialogBox.inputBox.Text);
  419. }
  420. if (RampVisibility == Visibility.Visible && GasStateType == GasPanelStateType.Manual)
  421. {
  422. if (!string.IsNullOrEmpty(dialogBox.inputRampBox.Text))
  423. {
  424. if (double.Parse(dialogBox.inputRampBox.Text) != DeviceData.RampValue)
  425. {
  426. DeviceData.IsRampCharge = true;
  427. }
  428. else
  429. {
  430. DeviceData.IsRampCharge = false;
  431. }
  432. DeviceData.SetRampValue = double.Parse(dialogBox.inputRampBox.Text);
  433. }
  434. }
  435. }
  436. //SetCursorPos(0, 0);
  437. dialogBox.Close();
  438. dialogBox.Dispose();
  439. RefreshMFCData();
  440. }
  441. }
  442. }