AITHeaterControl.xaml.cs 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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.Common.DeviceData;
  15. using Aitex.Core.UI.Control;
  16. namespace Aitex.Core.UI.DeviceControl
  17. {
  18. /// <summary>
  19. /// AITHeaterControl.xaml 的交互逻辑
  20. /// </summary>
  21. public partial class AITHeaterControl : UserControl
  22. {
  23. public AITHeaterControl()
  24. {
  25. InitializeComponent();
  26. }
  27. // define dependency properties
  28. public static readonly DependencyProperty CommandProperty = DependencyProperty.Register(
  29. "Command", typeof(ICommand), typeof(AITHeaterControl),
  30. new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.AffectsRender));
  31. public static readonly DependencyProperty DeviceDataProperty = DependencyProperty.Register(
  32. "DeviceData", typeof(AITHeaterData), typeof(AITHeaterControl),
  33. new FrameworkPropertyMetadata(new AITHeaterData(), FrameworkPropertyMetadataOptions.AffectsRender));
  34. public static readonly DependencyProperty BackColorProperty = DependencyProperty.Register(
  35. "BackColor", typeof(Brush), typeof(AITHeaterControl),
  36. new FrameworkPropertyMetadata(Brushes.DarkMagenta, FrameworkPropertyMetadataOptions.AffectsRender));
  37. /// <summary>
  38. /// 输入值是否百分比,默认否
  39. /// </summary>
  40. public bool IsPercent { get; set; }
  41. public ICommand Command
  42. {
  43. get
  44. {
  45. return (ICommand)this.GetValue(CommandProperty);
  46. }
  47. set
  48. {
  49. this.SetValue(CommandProperty, value);
  50. }
  51. }
  52. /// <summary>
  53. /// set, get current progress value AnalogDeviceData
  54. /// </summary>
  55. public AITHeaterData DeviceData
  56. {
  57. get
  58. {
  59. return (AITHeaterData)this.GetValue(DeviceDataProperty);
  60. }
  61. set
  62. {
  63. this.SetValue(DeviceDataProperty, value);
  64. }
  65. }
  66. public Brush BackColor
  67. {
  68. get
  69. {
  70. return (Brush)this.GetValue(BackColorProperty);
  71. }
  72. set
  73. {
  74. this.SetValue(BackColorProperty, value);
  75. }
  76. }
  77. protected override void OnRender(DrawingContext drawingContext)
  78. {
  79. base.OnRender(drawingContext);
  80. //draw background color
  81. if (DeviceData != null)
  82. {
  83. rectBkground.Fill = DeviceData.IsPowerOn ? Brushes.DarkMagenta : Brushes.Gray;
  84. //draw red board if mfc meets a warning
  85. rectBkground.Stroke = DeviceData.IsWarning ? Brushes.Red : new SolidColorBrush(System.Windows.Media.Color.FromRgb(0X37, 0X37, 0X37));
  86. labelValue.Foreground = DeviceData.IsWarning ? Brushes.Pink : Brushes.LightYellow;
  87. rectBkground.StrokeThickness = DeviceData.IsWarning ? 2 : 1;
  88. if (dialogBox != null)
  89. {
  90. dialogBox.RealValue = DeviceData.FeedBack.ToString("F1");
  91. dialogBox.IsHeaterOn = DeviceData.IsPowerOn;
  92. dialogBox.SetPoint = DeviceData.SetPoint;
  93. }
  94. }
  95. }
  96. private void ExecutePowerOnOff(bool value)
  97. {
  98. Command.Execute(new object[] { DeviceData.DeviceName, AITHeaterOperation.SetPowerOnOff.ToString(), value.ToString() });
  99. }
  100. private void ExecuteSetHeaterValue(double power)
  101. {
  102. Command.Execute(new object[] { DeviceData.DeviceName, AITHeaterOperation.Ramp.ToString(), power.ToString() });
  103. }
  104. private AITHeaterInputDialogBox dialogBox;
  105. public Window AnalogOwner { get; set; }
  106. private void Grid_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
  107. {
  108. if (DeviceData == null)
  109. return;
  110. dialogBox = new AITHeaterInputDialogBox
  111. {
  112. SetHeaterValueCommandDelegate = ExecuteSetHeaterValue,
  113. SetHeaterPowerOnOffCommandDelegate = ExecutePowerOnOff,
  114. DeviceName = DeviceData.DisplayName,
  115. DeviceId = DeviceData.DeviceSchematicId,
  116. DefaultValue = DeviceData.DefaultValue,
  117. RealValue = DeviceData.FeedBack.ToString("F1"),
  118. SetPoint = Math.Round(DeviceData.SetPoint, 1),
  119. MaxValue = DeviceData.Scale,
  120. Unit = DeviceData.Unit,
  121. IsHeaterOn = DeviceData.IsPowerOn,
  122. };
  123. if (AnalogOwner != null)
  124. dialogBox.Owner = AnalogOwner;
  125. dialogBox.Topmost = true;
  126. dialogBox.WindowStartupLocation = WindowStartupLocation.CenterScreen;
  127. dialogBox.FocasAll();
  128. dialogBox.ShowDialog();
  129. dialogBox = null;
  130. }
  131. private void Grid_MouseEnter(object sender, MouseEventArgs e)
  132. {
  133. if (DeviceData != null)
  134. {
  135. string tooltipValue =
  136. string.Format("{0}:{1}\r\n\r\nID:{2}\r\nScale:{3} {4}\r\nSetPoint:{5} {4} \r\nFeedback:{6} {4}\r\nHeaterPower:{7}",
  137. DeviceData.Type,
  138. DeviceData.DisplayName,
  139. DeviceData.DeviceSchematicId,
  140. DeviceData.Scale,
  141. DeviceData.Unit,
  142. DeviceData.SetPoint.ToString("F1"),
  143. DeviceData.FeedBack.ToString("F1"),
  144. DeviceData.IsPowerOn ? "On" : "Off");
  145. ToolTip = tooltipValue;
  146. }
  147. }
  148. }
  149. }