CalibrationSelectToolViewModel.cs 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  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. ButtonResult result1 = rst.Result;
  99. if (result1 == ButtonResult.OK)
  100. {
  101. var param = rst.Parameters.GetValue<RobotTool>("Tool");
  102. var param1 = rst.Parameters.GetValue<Matrix<double>>("RobotCameraRotationMatrix");
  103. var param2 = rst.Parameters.GetValue<double>("Angle");
  104. if (param != null)
  105. {
  106. SelectCalibration.Tool = param;
  107. }
  108. if (param1 != null)
  109. {
  110. SelectCalibration.RobotCameraRotationMatrix = param1.ToArray();
  111. }
  112. SelectCalibration.Angle = param2;
  113. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = "完成!", Duration = 1 });
  114. }
  115. });
  116. }
  117. catch (Exception ex)
  118. {
  119. LogHelper.WriteLogError("相机校准-选择工具坐标界面跳转至校准工具界面出错!", ex);
  120. MessageBox.Show(ex.Message);
  121. }
  122. }
  123. /// <summary>
  124. /// 下一步
  125. /// </summary>
  126. void ExecuteNextCommand()
  127. {
  128. NavigationParameters param = new NavigationParameters();
  129. param.Add("SelectCalibration", SelectCalibration);
  130. _regionManager.RequestNavigate("CalibrationRegionContext", "CalibrationAuto", param);
  131. }
  132. /// <summary>
  133. /// 上一步
  134. /// </summary>
  135. void ExecuteBackCommand()
  136. {
  137. NavigationParameters param = new NavigationParameters();
  138. param.Add("SelectCalibration", SelectCalibration);
  139. _regionManager.RequestNavigate("CalibrationRegionContext", "CalibrationTeachCenterPoint", param);
  140. }
  141. #endregion
  142. #region 继承
  143. /// <summary>
  144. /// 确认导航请求时调用。此方法允许您在导航之前执行一些操作。
  145. /// </summary>
  146. /// <param name="navigationContext"></param>
  147. /// <param name="continuationCallback"></param>
  148. public void ConfirmNavigationRequest(NavigationContext navigationContext, Action<bool> continuationCallback)
  149. {
  150. continuationCallback(true);
  151. }
  152. /// <summary>
  153. /// 接收导航请求时调用。传入导航参数,包含有关导航目标的信息。
  154. /// </summary>
  155. /// <param name="navigationContext"></param>
  156. /// <exception cref="NotImplementedException"></exception>
  157. public async void OnNavigatedTo(NavigationContext navigationContext)
  158. {
  159. SelectCalibration = navigationContext.Parameters.GetValue<CalibrationInfo>("SelectCalibration");
  160. if (SelectCalibration != null)
  161. {
  162. Robot = _robotService.GetRobot(SelectCalibration.RobotId);
  163. }
  164. }
  165. /// <summary>
  166. /// 是否允许导航到此视图模型。
  167. /// </summary>
  168. /// <param name="navigationContext"></param>
  169. /// <returns></returns>
  170. public bool IsNavigationTarget(NavigationContext navigationContext)
  171. {
  172. return true;
  173. }
  174. /// <summary>
  175. /// 导航离开此视图模型时调用。您可以在此处执行清理操作或保存状态。
  176. /// </summary>
  177. /// <param name="navigationContext"></param>
  178. public void OnNavigatedFrom(NavigationContext navigationContext)
  179. {
  180. }
  181. #endregion
  182. private bool _IsAllowEdit = false;
  183. public bool IsAllowEdit
  184. {
  185. get { return _IsAllowEdit; }
  186. set { SetProperty(ref _IsAllowEdit, value); }
  187. }
  188. private void LoginChange(Models.User user)
  189. {
  190. if (user.userPart == Enums.UserPart.Operator)
  191. {
  192. IsAllowEdit = false;
  193. }
  194. else
  195. {
  196. IsAllowEdit = true;
  197. }
  198. }
  199. }
  200. }