AnalogControl3Jet.xaml.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386
  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.Navigation;
  13. using System.Windows.Shapes;
  14. using Aitex.Core.UI.Control;
  15. using Aitex.Core.Util;
  16. using Aitex.Core.UI.ControlDataContext;
  17. using System.Windows.Media.Animation;
  18. using MECF.Framework.UI.Core.ExtendedControls;
  19. using MECF.Framework.Common.OperationCenter;
  20. namespace Aitex.Core.UI.Control
  21. {
  22. /// <summary>
  23. /// Interaction logic for AnalogControl.xaml
  24. /// </summary>
  25. public partial class AnalogControl3Jet : UserControl
  26. {
  27. public AnalogControl3Jet()
  28. {
  29. InitializeComponent();
  30. }
  31. // define dependency properties
  32. public static readonly DependencyProperty CommandProperty = DependencyProperty.Register(
  33. "Command", typeof(ICommand), typeof(AnalogControl3Jet),
  34. new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.AffectsRender));
  35. public static readonly DependencyProperty DeviceDataProperty = DependencyProperty.Register(
  36. "DeviceData", typeof(AnalogDeviceDataItem), typeof(AnalogControl3Jet),
  37. new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.AffectsRender,
  38. new PropertyChangedCallback(OnDeviceDataChanged)));
  39. public static readonly DependencyProperty OperationNameProperty = DependencyProperty.Register(
  40. "OperationName", typeof(string), typeof(AnalogControl3Jet),
  41. new FrameworkPropertyMetadata(AnalogDeviceOperation.Ramp, FrameworkPropertyMetadataOptions.AffectsRender));
  42. public static readonly DependencyProperty BackColorProperty = DependencyProperty.Register(
  43. "BackColor", typeof(Brush), typeof(AnalogControl3Jet),
  44. new FrameworkPropertyMetadata(Brushes.Green, FrameworkPropertyMetadataOptions.AffectsRender));
  45. public static readonly DependencyProperty HideDialogProperty = DependencyProperty.Register(
  46. "HideDialog", typeof(bool), typeof(AnalogControl3Jet),
  47. new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.AffectsRender));
  48. private double oldFeedBack;
  49. public static readonly DependencyProperty GasPanelStateTypeProperty = DependencyProperty.Register(
  50. "GasStateType", typeof(GasPanelStateType), typeof(AnalogControl3Jet),
  51. new FrameworkPropertyMetadata(GasPanelStateType.Manual, FrameworkPropertyMetadataOptions.AffectsRender));
  52. public GasPanelStateType GasStateType
  53. {
  54. get
  55. {
  56. return (GasPanelStateType)this.GetValue(GasPanelStateTypeProperty);
  57. }
  58. set
  59. {
  60. this.SetValue(GasPanelStateTypeProperty, value);
  61. }
  62. }
  63. public static readonly DependencyProperty ShowValueProperty = DependencyProperty.Register(
  64. "ShowValue", typeof(string), typeof(AnalogControl3Jet),
  65. new FrameworkPropertyMetadata(0.ToString("f3"), FrameworkPropertyMetadataOptions.AffectsRender));
  66. public string ShowValue
  67. {
  68. get
  69. {
  70. return (string)this.GetValue(ShowValueProperty);
  71. }
  72. set
  73. {
  74. this.SetValue(ShowValueProperty, value);
  75. }
  76. }
  77. public static readonly DependencyProperty MFCDisplayNameProperty = DependencyProperty.Register(
  78. "MFCDisplayName", typeof(string), typeof(AnalogControl3Jet),
  79. new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.AffectsRender));
  80. public string MFCDisplayName
  81. {
  82. get
  83. {
  84. return (string)this.GetValue(MFCDisplayNameProperty);
  85. }
  86. set
  87. {
  88. this.SetValue(MFCDisplayNameProperty, value);
  89. }
  90. }
  91. private static void OnDeviceDataChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
  92. {
  93. }
  94. /// <summary>
  95. /// 输入值是否百分比,默认否
  96. /// </summary>
  97. public bool IsPercent { get; set; }
  98. public ICommand Command
  99. {
  100. get
  101. {
  102. return (ICommand)this.GetValue(CommandProperty);
  103. }
  104. set
  105. {
  106. this.SetValue(CommandProperty, value);
  107. }
  108. }
  109. /// <summary>
  110. /// set, get current progress value AnalogDeviceData
  111. /// </summary>
  112. public AnalogDeviceDataItem DeviceData
  113. {
  114. get
  115. {
  116. //var data = (AnalogDeviceDataItem)this.GetValue(DeviceDataProperty);
  117. //if (data!=null && data.FeedBack != oldFeedBack)
  118. //{
  119. // RefreshMFCData(data);
  120. // oldFeedBack = data.FeedBack;
  121. //}
  122. //return data;
  123. return (AnalogDeviceDataItem)this.GetValue(DeviceDataProperty);
  124. }
  125. set
  126. {
  127. this.SetValue(DeviceDataProperty, value);
  128. }
  129. }
  130. public Brush BackColor
  131. {
  132. get
  133. {
  134. return (Brush)this.GetValue(BackColorProperty);
  135. }
  136. set
  137. {
  138. this.SetValue(BackColorProperty, value);
  139. }
  140. }
  141. public bool HideDialog
  142. {
  143. get
  144. {
  145. return (bool)this.GetValue(HideDialogProperty);
  146. }
  147. set
  148. {
  149. this.SetValue(HideDialogProperty, value);
  150. }
  151. }
  152. protected override void OnRender(DrawingContext drawingContext)
  153. {
  154. base.OnRender(drawingContext);
  155. //draw background color
  156. rectBkground.Fill = BackColor;
  157. RefreshMFCData();
  158. }
  159. private void RefreshMFCData()
  160. {
  161. #region FeedBack
  162. if (DeviceData == null) return;
  163. //draw red board if mfc meets a warning
  164. rectBkground.Stroke = DeviceData.IsWarning ? Brushes.Red : Brushes.Gray;
  165. //draw reading value
  166. //if (IsPercent)
  167. // labelValue.Content = (DeviceData.FeedBack * 100).ToString("F1");
  168. //else
  169. // labelValue.Content = DeviceData.FeedBack.ToString("F1");
  170. labelValue1.Foreground = DeviceData.IsWarning ? Brushes.Pink : Brushes.LightYellow;
  171. rectBkground.StrokeThickness = DeviceData.IsWarning ? 2 : 1;
  172. if (dialogBox != null)
  173. {
  174. if (IsPercent)
  175. dialogBox.RealValue = (DeviceData.FeedBack * 100).ToString("F1") + "%";
  176. else
  177. dialogBox.RealValue = DeviceData.FeedBack.ToString("F1");
  178. }
  179. rectSetPoint.Stroke = DeviceData.IsWarning ? Brushes.Red : Brushes.Gray;
  180. //draw red board if mfc meets a warning
  181. //draw reading value
  182. //if (IsPercent)
  183. // labelSetPoint.Content = (DeviceData.SetPoint * 100).ToString("F1");
  184. //else
  185. // labelSetPoint.Content = DeviceData.SetPoint.ToString("F1");
  186. if (DeviceData.DeviceId.Contains("MFM"))
  187. {
  188. labelSetPoint.Text = DeviceData.DeviceId.Replace("MFM", "");
  189. }
  190. else
  191. {
  192. labelSetPoint.Text = DeviceData.DeviceId.Replace("MFC", "");
  193. }
  194. labelSetPoint.Foreground = DeviceData.IsWarning ? Brushes.Pink : Brushes.LightYellow;
  195. rectSetPoint.StrokeThickness = DeviceData.IsWarning ? 2 : 1;
  196. if (DeviceData != null)
  197. {
  198. switch (GasStateType)
  199. {
  200. case GasPanelStateType.Manual:
  201. case GasPanelStateType.Monitor:
  202. // ShowValue = DeviceData.FeedBack.ToString("f3");
  203. break;
  204. case GasPanelStateType.Recipe:
  205. ShowValue = DeviceData.VirtualFeedBack.ToString("f3");
  206. break;
  207. default:
  208. ShowValue = 0.ToString("f3");
  209. break;
  210. }
  211. }
  212. #endregion
  213. }
  214. private void RefreshMFCData(AnalogDeviceDataItem data)
  215. {
  216. #region FeedBack
  217. if (data == null) return;
  218. //draw red board if mfc meets a warning
  219. rectBkground.Stroke = data.IsWarning ? Brushes.Red : Brushes.Gray;
  220. //draw reading value
  221. //if (IsPercent)
  222. // labelValue.Content = (data.FeedBack * 100).ToString("F1");
  223. //else
  224. // labelValue.Content = data.FeedBack.ToString("F1");
  225. labelValue1.Foreground = data.IsWarning ? Brushes.Pink : Brushes.LightYellow;
  226. rectBkground.StrokeThickness = data.IsWarning ? 2 : 1;
  227. if (dialogBox != null)
  228. {
  229. if (IsPercent)
  230. dialogBox.RealValue = (data.FeedBack * 100).ToString("F1") + "%";
  231. else
  232. dialogBox.RealValue = data.FeedBack.ToString("F1");
  233. }
  234. rectSetPoint.Stroke = data.IsWarning ? Brushes.Red : Brushes.Gray;
  235. //draw red board if mfc meets a warning
  236. //draw reading value
  237. //if (IsPercent)
  238. // labelSetPoint.Content = (DeviceData.SetPoint * 100).ToString("F1");
  239. //else
  240. // labelSetPoint.Content = DeviceData.SetPoint.ToString("F1");
  241. if (data.DeviceId.Contains("MFM"))
  242. {
  243. labelSetPoint.Text = data.DeviceId.Replace("MFM", "");
  244. }
  245. else
  246. {
  247. labelSetPoint.Text = data.DeviceId.Replace("MFC", "");
  248. }
  249. if (DeviceData != null)
  250. {
  251. switch (GasStateType)
  252. {
  253. case GasPanelStateType.Manual:
  254. case GasPanelStateType.Monitor:
  255. break;
  256. case GasPanelStateType.Recipe:
  257. ShowValue = data.VirtualFeedBack.ToString("f3");
  258. break;
  259. default:
  260. ShowValue = 0.ToString("f3");
  261. break;
  262. }
  263. }
  264. labelSetPoint.Foreground = data.IsWarning ? Brushes.Pink : Brushes.LightYellow;
  265. rectSetPoint.StrokeThickness = data.IsWarning ? 2 : 1;
  266. #endregion
  267. }
  268. private InputDialogBox dialogBox;
  269. public Window AnalogOwner { get; set; }
  270. private void Grid_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
  271. {
  272. if (DeviceData == null)
  273. return;
  274. if (GasStateType == GasPanelStateType.Monitor)
  275. { return; }
  276. if (HideDialog)
  277. return;
  278. dialogBox = new InputDialogBox
  279. {
  280. CommandDelegate = Execute,
  281. DeviceName = string.Format("{0}: {1}", DeviceData.Type, DeviceData.DisplayName),
  282. DeviceId = DeviceData.DeviceId,
  283. DefaultValue = DeviceData.DefaultValue,
  284. RealValue = DeviceData.FeedBack.ToString("F1"),
  285. SetPoint = Math.Round(DeviceData.SetPoint, 1),
  286. MaxValue = DeviceData.Scale,
  287. Unit = DeviceData.Unit,
  288. };
  289. dialogBox.IsPercent = IsPercent;
  290. if (IsPercent)
  291. dialogBox.SetPoint = Math.Round(DeviceData.SetPoint * 100.0, 1);
  292. if (AnalogOwner != null)
  293. dialogBox.Owner = AnalogOwner;
  294. dialogBox.Topmost = false;
  295. dialogBox.WindowStartupLocation = WindowStartupLocation.CenterScreen;
  296. //dialogBox.FocasAll();
  297. dialogBox.ShowDialog();
  298. dialogBox = null;
  299. }
  300. private void Execute(double value, double? ramp)
  301. {
  302. switch (GasStateType)
  303. {
  304. case GasPanelStateType.Manual:
  305. if (DeviceData != null)
  306. {
  307. DeviceData.FeedBack = value;
  308. DeviceData.SetPoint = value;
  309. ShowValue = value.ToString("f3");
  310. }
  311. //Command.Execute(new object[] { DeviceData.DeviceName, "SetMfcValue", value });
  312. break;
  313. case GasPanelStateType.Monitor:
  314. break;
  315. case GasPanelStateType.Recipe:
  316. Command.Execute(new object[] { DeviceData.DeviceName,"SetMfcVirtualValue", value });
  317. break;
  318. default:
  319. break;
  320. }
  321. }
  322. private void Grid_MouseEnter(object sender, MouseEventArgs e)
  323. {
  324. if (DeviceData != null)
  325. {
  326. string tooltipValue =
  327. 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}",
  328. DeviceData.Type,
  329. DeviceData.DisplayName,
  330. DeviceData.DeviceId,
  331. DeviceData.Scale,
  332. DeviceData.Unit,
  333. IsPercent ? (DeviceData.SetPoint * 100).ToString("F1") + "%" : DeviceData.SetPoint.ToString("F1"),
  334. IsPercent ? (DeviceData.FeedBack * 100).ToString("F1") + "%" : DeviceData.FeedBack.ToString("F1"),
  335. DeviceData.Scale > 0 ? ((DeviceData.FeedBack - DeviceData.SetPoint) / DeviceData.Scale * 100).ToString("F1") : "0",
  336. DeviceData.IsWarning ? "Tolerance Warning" : "Normal");
  337. ToolTip = tooltipValue;
  338. }
  339. }
  340. }
  341. }