CalibrationTeachCenterPointViewModel.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. using Prism.Commands;
  2. using Prism.Events;
  3. using Prism.Ioc;
  4. using Prism.Mvvm;
  5. using Prism.Regions;
  6. using Prism.Services.Dialogs;
  7. using SixLabors.Fonts.Unicode;
  8. using System;
  9. using System.Collections.Generic;
  10. using System.Linq;
  11. using System.Security.Cryptography;
  12. using TeamAAS_VP.Events;
  13. using TeamAAS_VP.Core;
  14. using TeamAAS_VP.Interfaces;
  15. using TeamAAS_VP.Models;
  16. using TeamAAS_VP.ViewModels.Product;
  17. using System.Windows;
  18. using TeamAAS_VP;
  19. namespace TeamAAS_VP.ViewModels.Calibration
  20. {
  21. public class CalibrationTeachCenterPointViewModel : BindableBase
  22. {
  23. IRegionManager _regionManager;
  24. IRegionNavigationService _regionNavigationService;
  25. IContainerProvider _container;
  26. IDialogService _dialogService;
  27. IEventAggregator _eventAggregator;
  28. #region 属性
  29. private CalibrationInfo _SelectCalibration;
  30. public CalibrationInfo SelectCalibration
  31. {
  32. get { return _SelectCalibration; }
  33. set { SetProperty(ref _SelectCalibration, value); }
  34. }
  35. private bool _IsShowTechHome=false;
  36. public bool IsShowTechHome
  37. {
  38. get { return _IsShowTechHome; }
  39. set { SetProperty(ref _IsShowTechHome, value); }
  40. }
  41. public Management management { get; set; }
  42. public RobotService robotService { get; set; }
  43. private IRobot _Robot;
  44. public IRobot Robot
  45. {
  46. get { return _Robot; }
  47. set { SetProperty(ref _Robot, value); }
  48. }
  49. #endregion
  50. #region 命令
  51. private DelegateCommand _LoadedCommand;
  52. public DelegateCommand LoadedCommand =>
  53. _LoadedCommand ?? (_LoadedCommand = new DelegateCommand(ExecuteLoadedCommand));
  54. private DelegateCommand _NextCommand;
  55. public DelegateCommand NextCommand =>
  56. _NextCommand ?? (_NextCommand = new DelegateCommand(ExecuteNextCommand));
  57. private DelegateCommand _BackCommand;
  58. public DelegateCommand BackCommand =>
  59. _BackCommand ?? (_BackCommand = new DelegateCommand(ExecuteBackCommand));
  60. private DelegateCommand _TechCenterCommand;
  61. public DelegateCommand TechCenterCommand =>
  62. _TechCenterCommand ?? (_TechCenterCommand = new DelegateCommand(ExecuteTechCenterCommand));
  63. private DelegateCommand _TechHomeCommand;
  64. public DelegateCommand TechHomeCommand =>
  65. _TechHomeCommand ?? (_TechHomeCommand = new DelegateCommand(ExecuteTechHomeCommand));
  66. private DelegateCommand<object> _BlowOrInhalControlCommand;
  67. public DelegateCommand<object> BlowOrInhalControlCommand =>
  68. _BlowOrInhalControlCommand ?? (_BlowOrInhalControlCommand = new DelegateCommand<object>(ExecuteBlowOrInhalControlCommand));
  69. private DelegateCommand _TechMarkPointCommand;
  70. public DelegateCommand TechMarkPointCommand =>
  71. _TechMarkPointCommand ?? (_TechMarkPointCommand = new DelegateCommand(ExecuteTechMarkPointCommand));
  72. #endregion
  73. #region 事件
  74. #endregion
  75. public CalibrationTeachCenterPointViewModel(IRegionManager regionManager, IEventAggregator ea, IRegionNavigationService regionNavigationService, IContainerProvider container, IDialogService dialogService)
  76. {
  77. _regionManager = regionManager;
  78. _regionNavigationService = regionNavigationService;
  79. _container = container;
  80. _dialogService = dialogService;
  81. _eventAggregator = ea;
  82. SelectCalibration = _container.Resolve<CalibrationHomeViewModel>().SelectCalibration;
  83. }
  84. #region 方法
  85. void ExecuteLoadedCommand()
  86. {
  87. if (_container.Resolve<Management>().CurrentUser.userPart == Enums.UserPart.Operator)
  88. {
  89. IsAllowEdit = false;
  90. }
  91. else
  92. {
  93. IsAllowEdit = true;
  94. }
  95. try
  96. {
  97. management = _container.Resolve<Management>();
  98. robotService = management.RobotService;
  99. SelectCalibration = _container.Resolve<CalibrationHomeViewModel>().SelectCalibration;
  100. if (SelectCalibration != null)
  101. {
  102. Robot = robotService.GetRobot(SelectCalibration.RobotId);
  103. if (SelectCalibration.CameraMount == Enums.CameraMount.FixedDown)
  104. {
  105. IsShowTechHome = true;
  106. }
  107. }
  108. else
  109. {
  110. IsShowTechHome = false;
  111. }
  112. }
  113. catch (Exception ex)
  114. {
  115. LogHelper.WriteLogError("相机校准-示教中心点界面加载时出错!", ex);
  116. MessageBox.Show(ex.Message);
  117. }
  118. }
  119. /// <summary>
  120. /// 下一步
  121. /// </summary>
  122. void ExecuteNextCommand()
  123. {
  124. if (SelectCalibration.CameraMount== Enums.CameraMount.MobileDown_XYPlatform)
  125. {
  126. _regionManager.RequestNavigate("CalibrationRegionContext", "CalibrationAuto");
  127. }
  128. else
  129. {
  130. _regionManager.RequestNavigate("CalibrationRegionContext", "CalibrationSelectTool");
  131. }
  132. }
  133. /// <summary>
  134. /// 上一步
  135. /// </summary>
  136. void ExecuteBackCommand()
  137. {
  138. _regionManager.RequestNavigate("CalibrationRegionContext", "CalibrationEditVision");
  139. }
  140. /// <summary>
  141. /// 示教中心点
  142. /// </summary>
  143. async void ExecuteTechCenterCommand()
  144. {
  145. if (Robot == null || !Robot.IsConnected) return;
  146. try
  147. {
  148. var curpos = await Robot.GetRobotPosAsync();
  149. if (SelectCalibration.CenterPoint==null)
  150. {
  151. SelectCalibration.CenterPoint = new RPoint();
  152. }
  153. SelectCalibration.CenterPoint.X = curpos.X;
  154. SelectCalibration.CenterPoint.Y = curpos.Y;
  155. SelectCalibration.CenterPoint.Z = curpos.Z;
  156. SelectCalibration.CenterPoint.U = curpos.U;
  157. SelectCalibration.CenterPoint.V = curpos.V;
  158. SelectCalibration.CenterPoint.W = curpos.W;
  159. SelectCalibration.CenterPoint.Hand = curpos.Hand;
  160. SelectCalibration.CenterPoint.Local = curpos.Local;
  161. SelectCalibration.CenterPoint.Tool = curpos.Tool;
  162. LogHelper.WriteLogInfo($"相机校准-示教中心点界面示教待机点:X:{SelectCalibration.CenterPoint.X} Y:{SelectCalibration.CenterPoint.Y} Z:{SelectCalibration.CenterPoint.Z} ");
  163. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = $"成功! X:{SelectCalibration.CenterPoint.X} Y:{SelectCalibration.CenterPoint.Y} Z:{SelectCalibration.CenterPoint.Z}", Duration = 1 });
  164. }
  165. catch (Exception ex)
  166. {
  167. LogHelper.WriteLogError("相机校准-示教中心点界面示教中心点时出错!", ex);
  168. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
  169. }
  170. }
  171. /// <summary>
  172. /// 示教待机点
  173. /// </summary>
  174. async void ExecuteTechHomeCommand()
  175. {
  176. if (Robot == null || !Robot.IsConnected) return;
  177. try
  178. {
  179. var curpos = await Robot.GetRobotPosAsync();
  180. if (SelectCalibration.HomePoint == null)
  181. {
  182. SelectCalibration.HomePoint = new RPoint();
  183. }
  184. SelectCalibration.HomePoint.X = curpos.X;
  185. SelectCalibration.HomePoint.Y = curpos.Y;
  186. SelectCalibration.HomePoint.Z = curpos.Z;
  187. SelectCalibration.HomePoint.U = curpos.U;
  188. SelectCalibration.HomePoint.V = curpos.V;
  189. SelectCalibration.HomePoint.W = curpos.W;
  190. SelectCalibration.HomePoint.Hand = curpos.Hand;
  191. SelectCalibration.HomePoint.Local = curpos.Local;
  192. SelectCalibration.HomePoint.Tool = curpos.Tool;
  193. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = "成功!", Duration = 1 });
  194. }
  195. catch (Exception ex)
  196. {
  197. LogHelper.WriteLogError("相机校准-示教中心点界面示教待机点时出错!", ex);
  198. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
  199. }
  200. }
  201. /// <summary>
  202. /// 夹爪打开/关闭
  203. /// </summary>
  204. /// <param name="obj"></param>
  205. async void ExecuteBlowOrInhalControlCommand(object obj)
  206. {
  207. try
  208. {
  209. await Robot.CalibOutIOAsync(!(bool)obj);
  210. }
  211. catch (Exception ex)
  212. {
  213. LogHelper.WriteLogError("相机校准-夹爪打开/关闭点时出错!", ex);
  214. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
  215. }
  216. }
  217. /// <summary>
  218. /// 示教P0
  219. /// </summary>
  220. async void ExecuteTechMarkPointCommand()
  221. {
  222. if (Robot == null || !Robot.IsConnected) return;
  223. try
  224. {
  225. var curpos = await Robot.GetRobotPosAsync();
  226. if (SelectCalibration.MarkPoint == null)
  227. {
  228. SelectCalibration.MarkPoint = new RPoint();
  229. }
  230. SelectCalibration.MarkPoint.X = curpos.X;
  231. SelectCalibration.MarkPoint.Y = curpos.Y;
  232. SelectCalibration.MarkPoint.Z = curpos.Z;
  233. SelectCalibration.MarkPoint.U = curpos.U;
  234. SelectCalibration.MarkPoint.V = curpos.V;
  235. SelectCalibration.MarkPoint.W = curpos.W;
  236. SelectCalibration.MarkPoint.Hand = curpos.Hand;
  237. SelectCalibration.MarkPoint.Local = curpos.Local;
  238. SelectCalibration.MarkPoint.Tool = curpos.Tool;
  239. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = "成功!", Duration = 1 });
  240. }
  241. catch (Exception ex)
  242. {
  243. LogHelper.WriteLogError("相机校准-示教中心点界面示教P0时出错!", ex);
  244. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
  245. }
  246. }
  247. #endregion
  248. private bool _IsAllowEdit = false;
  249. public bool IsAllowEdit
  250. {
  251. get { return _IsAllowEdit; }
  252. set { SetProperty(ref _IsAllowEdit, value); }
  253. }
  254. private void LoginChange(Models.User user)
  255. {
  256. if (user.userPart == Enums.UserPart.Operator)
  257. {
  258. IsAllowEdit = false;
  259. }
  260. else
  261. {
  262. IsAllowEdit = true;
  263. }
  264. }
  265. }
  266. }