CalibrationSelectToolViewModel.cs 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. using MathNet.Numerics.LinearAlgebra;
  2. using OpenCvSharp;
  3. using Prism.Commands;
  4. using Prism.Events;
  5. using Prism.Ioc;
  6. using Prism.Mvvm;
  7. using Prism.Regions;
  8. using Prism.Services.Dialogs;
  9. using System;
  10. using System.Collections.Generic;
  11. using System.Linq;
  12. using System.Windows;
  13. using Team.FFFeederService.Interfaces;
  14. using TeamAAS_VP;
  15. using TeamAAS_VP.Core;
  16. using TeamAAS_VP.Events;
  17. using TeamAAS_VP.Interfaces;
  18. using TeamAAS_VP.Models;
  19. using TeamAAS_VP.Models.Calibration;
  20. using TeamAAS_VP.Services;
  21. namespace TeamAAS_VP.ViewModels.Calibration
  22. {
  23. public class CalibrationSelectToolViewModel : BindableBase, IConfirmNavigationRequest
  24. {
  25. IRegionManager _regionManager;
  26. IRegionNavigationService _regionNavigationService;
  27. IContainerProvider _container;
  28. IDialogService _dialogService;
  29. IEventAggregator _eventAggregator;
  30. IConfigService _configService;
  31. IRobotService _robotService;
  32. ICameraService _cameraService;
  33. IFeederService _feederService;
  34. ISystemDatabaseService _systemDatabaseService;
  35. #region 属性
  36. private CalibrationInfo _SelectCalibration;
  37. public CalibrationInfo SelectCalibration
  38. {
  39. get { return _SelectCalibration; }
  40. set { SetProperty(ref _SelectCalibration, value); }
  41. }
  42. public Management management { get; set; }
  43. public IRobot Robot { get; set; }
  44. #endregion
  45. #region 命令
  46. private DelegateCommand _LoadedCommand;
  47. public DelegateCommand LoadedCommand =>
  48. _LoadedCommand ?? (_LoadedCommand = new DelegateCommand(ExecuteLoadedCommand));
  49. private DelegateCommand _NextCommand;
  50. public DelegateCommand NextCommand =>
  51. _NextCommand ?? (_NextCommand = new DelegateCommand(ExecuteNextCommand));
  52. private DelegateCommand _BackCommand;
  53. public DelegateCommand BackCommand =>
  54. _BackCommand ?? (_BackCommand = new DelegateCommand(ExecuteBackCommand));
  55. private DelegateCommand _CalibToolCommand;
  56. public DelegateCommand CalibToolCommand =>
  57. _CalibToolCommand ?? (_CalibToolCommand = new DelegateCommand(ExecuteCalibToolCommand));
  58. #endregion
  59. #region 事件
  60. #endregion
  61. public CalibrationSelectToolViewModel(IRegionManager regionManager, IEventAggregator ea, IRegionNavigationService regionNavigationService, IContainerProvider container, IDialogService dialogService,
  62. IConfigService configService, IRobotService robotService, ICameraService cameraService, IFeederService feederService, ISystemDatabaseService systemDatabaseService)
  63. {
  64. _regionManager = regionManager;
  65. _regionNavigationService = regionNavigationService;
  66. _container = container;
  67. _dialogService = dialogService;
  68. _eventAggregator = ea;
  69. _configService = configService;
  70. _robotService = robotService;
  71. _cameraService = cameraService;
  72. _feederService = feederService;
  73. _systemDatabaseService = systemDatabaseService;
  74. }
  75. #region 方法
  76. void ExecuteLoadedCommand()
  77. {
  78. if (_systemDatabaseService.GetCurrentUser().userPart == Enums.UserPart.Operator)
  79. {
  80. IsAllowEdit = false;
  81. }
  82. else
  83. {
  84. IsAllowEdit = true;
  85. }
  86. }
  87. /// <summary>
  88. /// 跳转至校准工具界面
  89. /// </summary>
  90. void ExecuteCalibToolCommand()
  91. {
  92. try
  93. {
  94. IDialogParameters parameters = new DialogParameters();
  95. parameters.Add("SelectCalibration", SelectCalibration);
  96. _dialogService.Show("CalibTool", parameters, rst =>
  97. {
  98. //对话框关闭之后的回调函数,可以在这解析结果。
  99. ButtonResult result1 = rst.Result;
  100. if (result1 == ButtonResult.OK)
  101. {
  102. var param = rst.Parameters.GetValue<RobotTool>("Tool");
  103. var param1 = rst.Parameters.GetValue<Matrix<double>>("RobotCameraRotationMatrix");
  104. var param2 = rst.Parameters.GetValue<double>("Angle");
  105. if (param != null)
  106. {
  107. SelectCalibration.Tool = param;
  108. }
  109. if (param1 != null)
  110. {
  111. SelectCalibration.RobotCameraRotationMatrix = param1.ToArray();
  112. }
  113. SelectCalibration.Angle = param2;
  114. SelectCalibration.CenterPoint = Robot.GetRobotPos();
  115. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = "完成!", Duration = 1 });
  116. }
  117. });
  118. }
  119. catch (Exception ex)
  120. {
  121. LogHelper.WriteLogError("相机校准-选择工具坐标界面跳转至校准工具界面出错!", ex);
  122. MessageBox.Show(ex.Message);
  123. }
  124. }
  125. /// <summary>
  126. /// 下一步
  127. /// </summary>
  128. void ExecuteNextCommand()
  129. {
  130. NavigationParameters param = new NavigationParameters();
  131. param.Add("SelectCalibration", SelectCalibration);
  132. if (SelectCalibration.CameraMount== Enums.CameraMount.MobileDown_IndependentXYPlatform)
  133. {
  134. _regionManager.RequestNavigate("CalibrationRegionContext", "CalibIndependentCamera", param);
  135. }
  136. else
  137. {
  138. _regionManager.RequestNavigate("CalibrationRegionContext", "CalibrationAuto", param);
  139. }
  140. }
  141. /// <summary>
  142. /// 上一步
  143. /// </summary>
  144. void ExecuteBackCommand()
  145. {
  146. NavigationParameters param = new NavigationParameters();
  147. param.Add("SelectCalibration", SelectCalibration);
  148. _regionManager.RequestNavigate("CalibrationRegionContext", "CalibrationTeachCenterPoint", param);
  149. }
  150. #endregion
  151. #region 继承
  152. /// <summary>
  153. /// 确认导航请求时调用。此方法允许您在导航之前执行一些操作。
  154. /// </summary>
  155. /// <param name="navigationContext"></param>
  156. /// <param name="continuationCallback"></param>
  157. public void ConfirmNavigationRequest(NavigationContext navigationContext, Action<bool> continuationCallback)
  158. {
  159. continuationCallback(true);
  160. }
  161. /// <summary>
  162. /// 接收导航请求时调用。传入导航参数,包含有关导航目标的信息。
  163. /// </summary>
  164. /// <param name="navigationContext"></param>
  165. /// <exception cref="NotImplementedException"></exception>
  166. public async void OnNavigatedTo(NavigationContext navigationContext)
  167. {
  168. SelectCalibration = navigationContext.Parameters.GetValue<CalibrationInfo>("SelectCalibration");
  169. if (SelectCalibration != null)
  170. {
  171. Robot = _robotService.GetRobot(SelectCalibration.RobotId);
  172. }
  173. }
  174. /// <summary>
  175. /// 是否允许导航到此视图模型。
  176. /// </summary>
  177. /// <param name="navigationContext"></param>
  178. /// <returns></returns>
  179. public bool IsNavigationTarget(NavigationContext navigationContext)
  180. {
  181. return true;
  182. }
  183. /// <summary>
  184. /// 导航离开此视图模型时调用。您可以在此处执行清理操作或保存状态。
  185. /// </summary>
  186. /// <param name="navigationContext"></param>
  187. public void OnNavigatedFrom(NavigationContext navigationContext)
  188. {
  189. }
  190. #endregion
  191. private bool _IsAllowEdit = false;
  192. public bool IsAllowEdit
  193. {
  194. get { return _IsAllowEdit; }
  195. set { SetProperty(ref _IsAllowEdit, value); }
  196. }
  197. private void LoginChange(Models.User user)
  198. {
  199. if (user.userPart == Enums.UserPart.Operator)
  200. {
  201. IsAllowEdit = false;
  202. }
  203. else
  204. {
  205. IsAllowEdit = true;
  206. }
  207. }
  208. }
  209. }