AnalogControl2Jet.xaml.cs 15 KB

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