TVControl.xaml.cs 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  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. using Caliburn.Micro;
  17. using MECF.Framework.Common.OperationCenter;
  18. namespace MECF.Framework.UI.Client.Ctrlib.UnitControls
  19. {
  20. /// <summary>
  21. /// AITThrottleValve.xaml 的交互逻辑
  22. /// </summary>
  23. public partial class TVControl : UserControl
  24. {
  25. public TVControl()
  26. {
  27. InitializeComponent();
  28. }
  29. // define dependency properties
  30. public static readonly DependencyProperty CommandProperty = DependencyProperty.Register(
  31. "Command", typeof(ICommand), typeof(TVControl),
  32. new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.AffectsRender));
  33. public static readonly DependencyProperty DeviceDataProperty = DependencyProperty.Register(
  34. "DeviceData", typeof(AITThrottleValveData), typeof(TVControl),
  35. new FrameworkPropertyMetadata(new AITThrottleValveData(), FrameworkPropertyMetadataOptions.AffectsRender));
  36. public ICommand Command
  37. {
  38. get
  39. {
  40. return (ICommand)this.GetValue(CommandProperty);
  41. }
  42. set
  43. {
  44. this.SetValue(CommandProperty, value);
  45. }
  46. }
  47. /// <summary>
  48. /// set, get current progress value AnalogDeviceData
  49. /// </summary>
  50. public AITThrottleValveData DeviceData
  51. {
  52. get
  53. {
  54. return (AITThrottleValveData)this.GetValue(DeviceDataProperty);
  55. }
  56. set
  57. {
  58. this.SetValue(DeviceDataProperty, value);
  59. }
  60. }
  61. private TVSettingDialogViewModel _dialog;
  62. protected override void OnRender(DrawingContext drawingContext)
  63. {
  64. base.OnRender(drawingContext);
  65. if (DeviceData != null)
  66. {
  67. if (DeviceData.Mode == (int)PressureCtrlMode.TVPressureCtrl)
  68. {
  69. //rotateTransform.Angle = DeviceData.PressureFeedback * 90.0 / DeviceData.MaxValuePressure;
  70. rectPosition.Stroke = Brushes.Gray;
  71. rectPressure.Stroke = Brushes.LightCyan;
  72. }
  73. else if (DeviceData.Mode == (int)PressureCtrlMode.TVPositionCtrl)
  74. {
  75. rectPosition.Stroke = Brushes.LightCyan;
  76. rectPressure.Stroke = Brushes.Gray;
  77. }
  78. else
  79. {
  80. rectPosition.Stroke = Brushes.Gray;
  81. rectPressure.Stroke = Brushes.Gray;
  82. }
  83. rotateTransform.Angle = DeviceData.PositionFeedback * 180.0 / DeviceData.MaxValuePosition;
  84. PositionValue.Content = DeviceData.PositionFeedback.ToString("F1") + " %";
  85. //PositionUnit.Content = "%";
  86. PressureValue.Content = DeviceData.PressureSetPoint.ToString("F1") + " Torr";
  87. //PressureUnit.Content = !string.IsNullOrEmpty(DeviceData.UnitPressure) ? DeviceData.UnitPressure : "mTorr";
  88. if (_dialog != null)
  89. {
  90. _dialog.DeviceData = DeviceData;
  91. }
  92. //if (_dialogBox != null)
  93. //{
  94. // _dialogBox.IsPositionMode = DeviceData.Mode == (int)PressureCtrlMode.TVPositionCtrl;
  95. // _dialogBox.IsPressureMode = DeviceData.Mode == (int)PressureCtrlMode.TVPressureCtrl;
  96. // //_dialogBox.SetPointPosition = DeviceData.PositionSetPoint;
  97. // //_dialogBox.SetPointPressure = DeviceData.PressureSetPoint;
  98. //}
  99. }
  100. }
  101. private void Grid_MouseEnter(object sender, MouseEventArgs e)
  102. {
  103. //if (DeviceData != null)
  104. //{
  105. // string tooltipValue =
  106. // string.Format(Application.Current.Resources["GlobalLableThrottleValveToolTip"].ToString(),
  107. // DeviceData.Type,
  108. // DeviceData.DisplayName,
  109. // DeviceData.DeviceSchematicId,
  110. // DeviceData.Mode == (int)PressureCtrlMode.TVPressureCtrl ? "Pressure" : (DeviceData.Mode == (int)PressureCtrlMode.TVPositionCtrl ? "Position" : ""),
  111. // DeviceData.PositionFeedback.ToString("F1"),
  112. // DeviceData.PressureFeedback.ToString("F1"));
  113. // ToolTip = tooltipValue;
  114. //}
  115. }
  116. private void Grid_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
  117. {
  118. if (DeviceData == null)
  119. return;
  120. _dialog = new TVSettingDialogViewModel($"{DeviceData.DisplayName} Setting");
  121. _dialog.DeviceData = DeviceData;
  122. _dialog.InputSetPointPosition = DeviceData.PositionSetPoint.ToString("F1");
  123. _dialog.InputSetPointPressure = DeviceData.PressureSetPoint.ToString("F1");
  124. WindowManager wm = new WindowManager();
  125. Window owner = Application.Current.MainWindow;
  126. if (owner != null)
  127. {
  128. Mouse.Capture(owner);
  129. Point pointToWindow = Mouse.GetPosition(owner);
  130. Point pointToScreen = owner.PointToScreen(pointToWindow);
  131. pointToScreen.X = pointToScreen.X + 50;
  132. pointToScreen.Y = pointToScreen.Y - 150;
  133. Mouse.Capture(null);
  134. wm.ShowDialog(_dialog, pointToScreen);
  135. }
  136. else
  137. {
  138. wm.ShowDialog(_dialog);
  139. }
  140. //_dialogBox = new AITThrottleValveInputDialogBox
  141. //{
  142. // SetThrottleModeCommandDelegate = SetThrottleModeExecute,
  143. // SetPressureCommandDelegate = SetPressureExecute,
  144. // SetPositionCommandDelegate = SetPositionExecute,
  145. // DeviceName = string.Format("{0}: {1}", DeviceData.Type, DeviceData.DisplayName),
  146. // DeviceId = DeviceData.DeviceSchematicId,
  147. // SetPointPosition = Math.Round(DeviceData.PositionSetPoint, 1),
  148. // SetPointPressure = Math.Round(DeviceData.PressureSetPoint, 1),
  149. // MaxValuePressure = DeviceData.MaxValuePressure,
  150. // MaxValuePosition = DeviceData.MaxValuePosition,
  151. // UnitPosition = DeviceData.UnitPosition,
  152. // UnitPressure = DeviceData.UnitPressure,
  153. // FeedbackPosition = DeviceData.PositionFeedback,
  154. // FeedbackPressure = DeviceData.PressureFeedback,
  155. // IsPositionMode = DeviceData.Mode == (int)PressureCtrlMode.TVPositionCtrl,
  156. // IsPressureMode = DeviceData.Mode == (int)PressureCtrlMode.TVPressureCtrl,
  157. //};
  158. //if (AnalogOwner != null)
  159. // _dialogBox.Owner = AnalogOwner;
  160. //_dialogBox.Topmost = true;
  161. //_dialogBox.WindowStartupLocation = WindowStartupLocation.CenterScreen;
  162. //_dialogBox.FocasAll();
  163. //_dialogBox.ShowDialog();
  164. //_dialogBox = null;
  165. }
  166. private void SetThrottleModeExecute(PressureCtrlMode value)
  167. {
  168. InvokeClient.Instance.Service.DoOperation($"{DeviceData.Module}.{DeviceData.DeviceName}.{AITThrottleValveOperation.SetMode}", value.ToString());
  169. }
  170. private void SetPressureExecute(double value)
  171. {
  172. InvokeClient.Instance.Service.DoOperation($"{DeviceData.Module}.{DeviceData.DeviceName}.{AITThrottleValveOperation.SetPressure}", (float)value);
  173. }
  174. private void SetPositionExecute(double value)
  175. {
  176. InvokeClient.Instance.Service.DoOperation($"{DeviceData.Module}.{DeviceData.DeviceName}.{AITThrottleValveOperation.SetPosition}", (float)value);
  177. }
  178. }
  179. }