| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175 |
- using MathNet.Numerics.LinearAlgebra;
- using Prism.Commands;
- using Prism.Events;
- using Prism.Ioc;
- using Prism.Mvvm;
- using Prism.Regions;
- using Prism.Services.Dialogs;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using TeamAAS_VP.Events;
- using TeamAAS_VP.Core;
- using TeamAAS_VP.Interfaces;
- using TeamAAS_VP.Models;
- using System.Windows;
- using TeamAAS_VP;
- using OpenCvSharp;
- namespace TeamAAS_VP.ViewModels.Calibration
- {
- public class CalibrationSelectToolViewModel : BindableBase
- {
- IRegionManager _regionManager;
- IRegionNavigationService _regionNavigationService;
- IContainerProvider _container;
- IDialogService _dialogService;
- IEventAggregator _eventAggregator;
- #region 属性
- private CalibrationInfo _SelectCalibration;
- public CalibrationInfo SelectCalibration
- {
- get { return _SelectCalibration; }
- set { SetProperty(ref _SelectCalibration, value); }
- }
- public Management management { get; set; }
- public RobotService robotService { get; set; }
- public IRobot Robot { get; set; }
- #endregion
- #region 命令
- private DelegateCommand _LoadedCommand;
- public DelegateCommand LoadedCommand =>
- _LoadedCommand ?? (_LoadedCommand = new DelegateCommand(ExecuteLoadedCommand));
- private DelegateCommand _NextCommand;
- public DelegateCommand NextCommand =>
- _NextCommand ?? (_NextCommand = new DelegateCommand(ExecuteNextCommand));
- private DelegateCommand _BackCommand;
- public DelegateCommand BackCommand =>
- _BackCommand ?? (_BackCommand = new DelegateCommand(ExecuteBackCommand));
- private DelegateCommand _CalibToolCommand;
- public DelegateCommand CalibToolCommand =>
- _CalibToolCommand ?? (_CalibToolCommand = new DelegateCommand(ExecuteCalibToolCommand));
-
- #endregion
- #region 事件
- #endregion
- public CalibrationSelectToolViewModel(IRegionManager regionManager, IEventAggregator ea, IRegionNavigationService regionNavigationService, IContainerProvider container, IDialogService dialogService)
- {
- _regionManager = regionManager;
- _regionNavigationService = regionNavigationService;
- _container = container;
- _dialogService = dialogService;
- _eventAggregator = ea;
- }
- #region 方法
- void ExecuteLoadedCommand()
- {
- if (_container.Resolve<Management>().CurrentUser.userPart == Enums.UserPart.Operator)
- {
- IsAllowEdit = false;
- }
- else
- {
- IsAllowEdit = true;
- }
- try
- {
- management = _container.Resolve<Management>();
- robotService = management.RobotService;
- SelectCalibration = _container.Resolve<CalibrationHomeViewModel>().SelectCalibration;
- if (SelectCalibration != null)
- {
- Robot = robotService.GetRobot(SelectCalibration.RobotId);
- }
- }
- catch (Exception ex)
- {
- LogHelper.WriteLogError("相机校准-选择工具坐标界面加载时出错!", ex);
- MessageBox.Show(ex.Message);
- }
- }
- /// <summary>
- /// 跳转至校准工具界面
- /// </summary>
- void ExecuteCalibToolCommand()
- {
- try
- {
- IDialogParameters parameters = new DialogParameters();
- parameters.Add("Angle", SelectCalibration.Angle);
- _dialogService.Show("CalibTool", parameters, rst => {
- //对话框关闭之后的回调函数,可以在这解析结果。
- ButtonResult result1 = rst.Result;
- if (result1 == ButtonResult.OK)
- {
- var param = rst.Parameters.GetValue<RobotTool>("Tool");
- var param1 = rst.Parameters.GetValue<Matrix<double>>("RobotCameraRotationMatrix");
- var param2 = rst.Parameters.GetValue<double>("Angle");
- if (param != null)
- {
- SelectCalibration.Tool = param;
- }
- if (param1 != null)
- {
- SelectCalibration.RobotCameraRotationMatrix = param1.ToArray();
- }
- SelectCalibration.Angle = param2;
- _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = "完成!", Duration = 1 });
- }
- });
- }
- catch (Exception ex)
- {
- LogHelper.WriteLogError("相机校准-选择工具坐标界面跳转至校准工具界面出错!", ex);
- MessageBox.Show(ex.Message);
- }
- }
- /// <summary>
- /// 下一步
- /// </summary>
- void ExecuteNextCommand()
- {
- _regionManager.RequestNavigate("CalibrationRegionContext", "CalibrationAuto");
- }
- /// <summary>
- /// 上一步
- /// </summary>
- void ExecuteBackCommand()
- {
- _regionManager.RequestNavigate("CalibrationRegionContext", "CalibrationTeachCenterPoint");
- }
- #endregion
- private bool _IsAllowEdit = false;
- public bool IsAllowEdit
- {
- get { return _IsAllowEdit; }
- set { SetProperty(ref _IsAllowEdit, value); }
- }
- private void LoginChange(Models.User user)
- {
- if (user.userPart == Enums.UserPart.Operator)
- {
- IsAllowEdit = false;
- }
- else
- {
- IsAllowEdit = true;
- }
- }
- }
- }
|