CalibrationSelectToolViewModel.cs 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. using MathNet.Numerics.LinearAlgebra;
  2. using Prism.Commands;
  3. using Prism.Events;
  4. using Prism.Ioc;
  5. using Prism.Mvvm;
  6. using Prism.Regions;
  7. using Prism.Services.Dialogs;
  8. using System;
  9. using System.Collections.Generic;
  10. using System.Linq;
  11. using TeamAAS_VP.Events;
  12. using TeamAAS_VP.Core;
  13. using TeamAAS_VP.Interfaces;
  14. using TeamAAS_VP.Models;
  15. using System.Windows;
  16. using TeamAAS_VP;
  17. using OpenCvSharp;
  18. namespace TeamAAS_VP.ViewModels.Calibration
  19. {
  20. public class CalibrationSelectToolViewModel : BindableBase
  21. {
  22. IRegionManager _regionManager;
  23. IRegionNavigationService _regionNavigationService;
  24. IContainerProvider _container;
  25. IDialogService _dialogService;
  26. IEventAggregator _eventAggregator;
  27. #region 属性
  28. private CalibrationInfo _SelectCalibration;
  29. public CalibrationInfo SelectCalibration
  30. {
  31. get { return _SelectCalibration; }
  32. set { SetProperty(ref _SelectCalibration, value); }
  33. }
  34. public Management management { get; set; }
  35. public RobotService robotService { get; set; }
  36. public IRobot Robot { get; set; }
  37. #endregion
  38. #region 命令
  39. private DelegateCommand _LoadedCommand;
  40. public DelegateCommand LoadedCommand =>
  41. _LoadedCommand ?? (_LoadedCommand = new DelegateCommand(ExecuteLoadedCommand));
  42. private DelegateCommand _NextCommand;
  43. public DelegateCommand NextCommand =>
  44. _NextCommand ?? (_NextCommand = new DelegateCommand(ExecuteNextCommand));
  45. private DelegateCommand _BackCommand;
  46. public DelegateCommand BackCommand =>
  47. _BackCommand ?? (_BackCommand = new DelegateCommand(ExecuteBackCommand));
  48. private DelegateCommand _CalibToolCommand;
  49. public DelegateCommand CalibToolCommand =>
  50. _CalibToolCommand ?? (_CalibToolCommand = new DelegateCommand(ExecuteCalibToolCommand));
  51. #endregion
  52. #region 事件
  53. #endregion
  54. public CalibrationSelectToolViewModel(IRegionManager regionManager, IEventAggregator ea, IRegionNavigationService regionNavigationService, IContainerProvider container, IDialogService dialogService)
  55. {
  56. _regionManager = regionManager;
  57. _regionNavigationService = regionNavigationService;
  58. _container = container;
  59. _dialogService = dialogService;
  60. _eventAggregator = ea;
  61. }
  62. #region 方法
  63. void ExecuteLoadedCommand()
  64. {
  65. if (_container.Resolve<Management>().CurrentUser.userPart == Enums.UserPart.Operator)
  66. {
  67. IsAllowEdit = false;
  68. }
  69. else
  70. {
  71. IsAllowEdit = true;
  72. }
  73. try
  74. {
  75. management = _container.Resolve<Management>();
  76. robotService = management.RobotService;
  77. SelectCalibration = _container.Resolve<CalibrationHomeViewModel>().SelectCalibration;
  78. if (SelectCalibration != null)
  79. {
  80. Robot = robotService.GetRobot(SelectCalibration.RobotId);
  81. }
  82. }
  83. catch (Exception ex)
  84. {
  85. LogHelper.WriteLogError("相机校准-选择工具坐标界面加载时出错!", ex);
  86. MessageBox.Show(ex.Message);
  87. }
  88. }
  89. /// <summary>
  90. /// 跳转至校准工具界面
  91. /// </summary>
  92. void ExecuteCalibToolCommand()
  93. {
  94. try
  95. {
  96. IDialogParameters parameters = new DialogParameters();
  97. parameters.Add("Angle", SelectCalibration.Angle);
  98. _dialogService.Show("CalibTool", parameters, rst => {
  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 = "完成!", 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. _regionManager.RequestNavigate("CalibrationRegionContext", "CalibrationAuto");
  131. }
  132. /// <summary>
  133. /// 上一步
  134. /// </summary>
  135. void ExecuteBackCommand()
  136. {
  137. _regionManager.RequestNavigate("CalibrationRegionContext", "CalibrationTeachCenterPoint");
  138. }
  139. #endregion
  140. private bool _IsAllowEdit = false;
  141. public bool IsAllowEdit
  142. {
  143. get { return _IsAllowEdit; }
  144. set { SetProperty(ref _IsAllowEdit, value); }
  145. }
  146. private void LoginChange(Models.User user)
  147. {
  148. if (user.userPart == Enums.UserPart.Operator)
  149. {
  150. IsAllowEdit = false;
  151. }
  152. else
  153. {
  154. IsAllowEdit = true;
  155. }
  156. }
  157. }
  158. }