AnalogControl4Jet.xaml.cs 20 KB

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