CalibrationSelectToolViewModel.cs 7.9 KB

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