RobotControl.xaml.cs 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. using Aitex.Core.UI.MVVM;
  2. using Aitex.Core.Util;
  3. using Aitex.Sorter.Common;
  4. using Aitex.Sorter.UI.Controls.Common;
  5. using MECF.Framework.Common.OperationCenter;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. using System.Windows;
  12. using System.Windows.Controls;
  13. using System.Windows.Data;
  14. using System.Windows.Documents;
  15. using System.Windows.Input;
  16. using System.Windows.Media;
  17. using System.Windows.Media.Imaging;
  18. using System.Windows.Navigation;
  19. using System.Windows.Shapes;
  20. using MECF.Framework.Common.Equipment;
  21. using System.Globalization;
  22. namespace Aitex.Sorter.UI.Controls
  23. {
  24. /// <summary>
  25. /// RobotControl.xaml 的交互逻辑
  26. /// </summary>
  27. public partial class RobotControl : ViewModelControl
  28. {
  29. public Dictionary<ModuleName, int> Target
  30. {
  31. get { return (Dictionary<ModuleName, int>)GetValue(TargetProperty); }
  32. set { SetValue(TargetProperty, value); }
  33. }
  34. // Using a DependencyProperty as the backing store for Target. This enables animation, styling, binding, etc...
  35. public static readonly DependencyProperty TargetProperty =
  36. DependencyProperty.Register("Target", typeof(Dictionary<ModuleName, int>), typeof(RobotControl), new PropertyMetadata(null));
  37. public bool EnableHighSpeed
  38. {
  39. get { return (bool)GetValue(EnableHighSpeedProperty); }
  40. set { SetValue(EnableHighSpeedProperty, value); }
  41. }
  42. // Using a DependencyProperty as the backing store for Target. This enables animation, styling, binding, etc...
  43. public static readonly DependencyProperty EnableHighSpeedProperty =
  44. DependencyProperty.Register("EnableHighSpeed", typeof(bool), typeof(RobotControl), new PropertyMetadata(null));
  45. public RobotControl()
  46. {
  47. InitializeComponent();
  48. OperationCommand = new DelegateCommand<DependencyObject>(Operation, x => !IsMaintenanceMode && !IsAutoMode);
  49. Command = new DelegateCommand<DependencyObject>(DoCommand, x => !IsMaintenanceMode && !IsAutoMode);
  50. SetSpeedCommand = new DelegateCommand<DependencyObject>(Operation, CanSetSpeed);
  51. var hands = new List<Hand>();
  52. hands.Add(Hand.Blade1);
  53. hands.Add(Hand.Blade2);
  54. Hands = hands.ToArray();
  55. EnableHighSpeed = true;
  56. root.DataContext = this;
  57. }
  58. private bool CanSetSpeed(DependencyObject sender)
  59. {
  60. var command = CommandHelper.GetCommandItem(sender);
  61. var lstParameter = new List<object>(command.Parameters);
  62. if (lstParameter[0].ToString() == RobotSpeed)
  63. return false;
  64. return true;
  65. }
  66. [Subscription(ParamName.RTStatus, "System")]
  67. public int RoutManagerState
  68. {
  69. get;
  70. set;
  71. }
  72. public bool IsMaintenanceMode
  73. {
  74. get => RoutManagerState == (int)RtState.Maintenance;
  75. }
  76. [Subscription(ParamName.IsAutoMode, "System")]
  77. public bool IsAutoMode { get; set; }
  78. public ICommand OperationCommand
  79. {
  80. get;
  81. private set;
  82. }
  83. public ICommand Command
  84. {
  85. get;
  86. private set;
  87. }
  88. public ICommand SetSpeedCommand
  89. {
  90. get;
  91. private set;
  92. }
  93. void Operation(DependencyObject sender)
  94. {
  95. var command = CommandHelper.GetCommandItem(sender);
  96. InvokeClient.Instance.Service.DoOperation(command.CommandName, command.Parameters);
  97. }
  98. private void DoCommand(DependencyObject sender)
  99. {
  100. var command = CommandHelper.GetCommandItem(sender);
  101. var lstParameter = new List<object>(command.Parameters);
  102. lstParameter.Insert(0, command.Target);
  103. lstParameter.Insert(1, command.CommandName);
  104. InvokeClient.Instance.Service.DoOperation(OperationName.DeviceOperation, lstParameter.ToArray());
  105. }
  106. [Subscription(ParamName.RobotState, DeviceName.Robot)]
  107. public string Status
  108. {
  109. get;
  110. set;
  111. }
  112. [Subscription(ParamName.RobotPosRotationAxis, DeviceName.Robot)]
  113. public string RobotPosRotationAxis
  114. {
  115. get;
  116. set;
  117. }
  118. [Subscription(ParamName.RobotPosExtensionAxis, DeviceName.Robot)]
  119. public string RobotPosExtensionAxis
  120. {
  121. get; set;
  122. }
  123. [Subscription(ParamName.RobotPosWrist1Axis, DeviceName.Robot)]
  124. public string RobotPosWrist1Axis
  125. {
  126. get;
  127. set;
  128. }
  129. [Subscription(ParamName.RobotPosWrist2Axis, DeviceName.Robot)]
  130. public string RobotPosWrist2Axis
  131. {
  132. get;
  133. set;
  134. }
  135. [Subscription(ParamName.RobotPosEvevationAxis, DeviceName.Robot)]
  136. public string RobotPosEvevationAxis
  137. {
  138. get;
  139. set;
  140. }
  141. [Subscription(ParamName.RobotBlade1Traget, DeviceName.Robot)]
  142. public string RobotBlade1Traget
  143. {
  144. get;
  145. set;
  146. }
  147. [Subscription(ParamName.RobotBlade2Traget, DeviceName.Robot)]
  148. public string RobotBlade2Traget
  149. {
  150. get;
  151. set;
  152. }
  153. [Subscription(ParamName.RobotSpeed, DeviceName.Robot)]
  154. public string RobotSpeed
  155. {
  156. get;
  157. set;
  158. }
  159. [Subscription(ParamName.RobotError, DeviceName.Robot)]
  160. public string ErrorCode
  161. {
  162. get;
  163. set;
  164. }
  165. public Hand[] Hands
  166. {
  167. get;
  168. set;
  169. }
  170. }
  171. public class TargetSlotConverter : IValueConverter
  172. {
  173. public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
  174. {
  175. if (value != null)
  176. {
  177. var count = (int)value;
  178. return Enumerable.Range(0, count).ToDictionary(x => x + 1, x => x);
  179. }
  180. return new Dictionary<int, int>();
  181. }
  182. public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
  183. {
  184. throw new NotImplementedException();
  185. }
  186. }
  187. public class TargetKeyValueConverter : IValueConverter
  188. {
  189. public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
  190. {
  191. if (value != null)
  192. {
  193. var kvp = (KeyValuePair<ModuleName,int>)value;
  194. return Enum.Parse(typeof(ModuleName),kvp.Key.ToString());
  195. }
  196. return "";
  197. }
  198. public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
  199. {
  200. throw new NotImplementedException();
  201. }
  202. }
  203. }