| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294 |
- using Prism.Commands;
- using Prism.Events;
- using Prism.Ioc;
- using Prism.Mvvm;
- using Prism.Regions;
- using Prism.Services.Dialogs;
- using SixLabors.Fonts.Unicode;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Security.Cryptography;
- using TeamAAS_VP.Events;
- using TeamAAS_VP.Core;
- using TeamAAS_VP.Interfaces;
- using TeamAAS_VP.Models;
- using TeamAAS_VP.ViewModels.Product;
- using System.Windows;
- using TeamAAS_VP;
- namespace TeamAAS_VP.ViewModels.Calibration
- {
- public class CalibrationTeachCenterPointViewModel : 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); }
- }
- private bool _IsShowTechHome=false;
- public bool IsShowTechHome
- {
- get { return _IsShowTechHome; }
- set { SetProperty(ref _IsShowTechHome, value); }
- }
- public Management management { get; set; }
- public RobotService robotService { get; set; }
- private IRobot _Robot;
- public IRobot Robot
- {
- get { return _Robot; }
- set { SetProperty(ref _Robot, value); }
- }
- #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 _TechCenterCommand;
- public DelegateCommand TechCenterCommand =>
- _TechCenterCommand ?? (_TechCenterCommand = new DelegateCommand(ExecuteTechCenterCommand));
- private DelegateCommand _TechHomeCommand;
- public DelegateCommand TechHomeCommand =>
- _TechHomeCommand ?? (_TechHomeCommand = new DelegateCommand(ExecuteTechHomeCommand));
- private DelegateCommand<object> _BlowOrInhalControlCommand;
- public DelegateCommand<object> BlowOrInhalControlCommand =>
- _BlowOrInhalControlCommand ?? (_BlowOrInhalControlCommand = new DelegateCommand<object>(ExecuteBlowOrInhalControlCommand));
- private DelegateCommand _TechMarkPointCommand;
- public DelegateCommand TechMarkPointCommand =>
- _TechMarkPointCommand ?? (_TechMarkPointCommand = new DelegateCommand(ExecuteTechMarkPointCommand));
-
- #endregion
- #region 事件
- #endregion
- public CalibrationTeachCenterPointViewModel(IRegionManager regionManager, IEventAggregator ea, IRegionNavigationService regionNavigationService, IContainerProvider container, IDialogService dialogService)
- {
- _regionManager = regionManager;
- _regionNavigationService = regionNavigationService;
- _container = container;
- _dialogService = dialogService;
- _eventAggregator = ea;
- SelectCalibration = _container.Resolve<CalibrationHomeViewModel>().SelectCalibration;
- }
- #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);
- if (SelectCalibration.CameraMount == Enums.CameraMount.FixedDown)
- {
- IsShowTechHome = true;
- }
- }
- else
- {
- IsShowTechHome = false;
- }
- }
- catch (Exception ex)
- {
- LogHelper.WriteLogError("相机校准-示教中心点界面加载时出错!", ex);
- MessageBox.Show(ex.Message);
- }
- }
- /// <summary>
- /// 下一步
- /// </summary>
- void ExecuteNextCommand()
- {
- if (SelectCalibration.CameraMount== Enums.CameraMount.MobileDown_XYPlatform)
- {
- _regionManager.RequestNavigate("CalibrationRegionContext", "CalibrationAuto");
- }
- else
- {
- _regionManager.RequestNavigate("CalibrationRegionContext", "CalibrationSelectTool");
- }
- }
- /// <summary>
- /// 上一步
- /// </summary>
- void ExecuteBackCommand()
- {
- _regionManager.RequestNavigate("CalibrationRegionContext", "CalibrationEditVision");
- }
- /// <summary>
- /// 示教中心点
- /// </summary>
- async void ExecuteTechCenterCommand()
- {
- if (Robot == null || !Robot.IsConnected) return;
- try
- {
- var curpos = await Robot.GetRobotPosAsync();
- if (SelectCalibration.CenterPoint==null)
- {
- SelectCalibration.CenterPoint = new RPoint();
- }
- SelectCalibration.CenterPoint.X = curpos.X;
- SelectCalibration.CenterPoint.Y = curpos.Y;
- SelectCalibration.CenterPoint.Z = curpos.Z;
- SelectCalibration.CenterPoint.U = curpos.U;
- SelectCalibration.CenterPoint.V = curpos.V;
- SelectCalibration.CenterPoint.W = curpos.W;
- SelectCalibration.CenterPoint.Hand = curpos.Hand;
- SelectCalibration.CenterPoint.Local = curpos.Local;
- SelectCalibration.CenterPoint.Tool = curpos.Tool;
- LogHelper.WriteLogInfo($"相机校准-示教中心点界面示教待机点:X:{SelectCalibration.CenterPoint.X} Y:{SelectCalibration.CenterPoint.Y} Z:{SelectCalibration.CenterPoint.Z} ");
- _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = $"成功! X:{SelectCalibration.CenterPoint.X} Y:{SelectCalibration.CenterPoint.Y} Z:{SelectCalibration.CenterPoint.Z}", Duration = 1 });
- }
- catch (Exception ex)
- {
- LogHelper.WriteLogError("相机校准-示教中心点界面示教中心点时出错!", ex);
- _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
- }
- }
- /// <summary>
- /// 示教待机点
- /// </summary>
- async void ExecuteTechHomeCommand()
- {
- if (Robot == null || !Robot.IsConnected) return;
- try
- {
- var curpos = await Robot.GetRobotPosAsync();
- if (SelectCalibration.HomePoint == null)
- {
- SelectCalibration.HomePoint = new RPoint();
- }
- SelectCalibration.HomePoint.X = curpos.X;
- SelectCalibration.HomePoint.Y = curpos.Y;
- SelectCalibration.HomePoint.Z = curpos.Z;
- SelectCalibration.HomePoint.U = curpos.U;
- SelectCalibration.HomePoint.V = curpos.V;
- SelectCalibration.HomePoint.W = curpos.W;
- SelectCalibration.HomePoint.Hand = curpos.Hand;
- SelectCalibration.HomePoint.Local = curpos.Local;
- SelectCalibration.HomePoint.Tool = curpos.Tool;
- _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = "成功!", Duration = 1 });
- }
- catch (Exception ex)
- {
- LogHelper.WriteLogError("相机校准-示教中心点界面示教待机点时出错!", ex);
- _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
- }
- }
- /// <summary>
- /// 夹爪打开/关闭
- /// </summary>
- /// <param name="obj"></param>
- async void ExecuteBlowOrInhalControlCommand(object obj)
- {
- try
- {
- await Robot.CalibOutIOAsync(!(bool)obj);
- }
- catch (Exception ex)
- {
- LogHelper.WriteLogError("相机校准-夹爪打开/关闭点时出错!", ex);
- _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
- }
- }
- /// <summary>
- /// 示教P0
- /// </summary>
- async void ExecuteTechMarkPointCommand()
- {
- if (Robot == null || !Robot.IsConnected) return;
- try
- {
- var curpos = await Robot.GetRobotPosAsync();
- if (SelectCalibration.MarkPoint == null)
- {
- SelectCalibration.MarkPoint = new RPoint();
- }
- SelectCalibration.MarkPoint.X = curpos.X;
- SelectCalibration.MarkPoint.Y = curpos.Y;
- SelectCalibration.MarkPoint.Z = curpos.Z;
- SelectCalibration.MarkPoint.U = curpos.U;
- SelectCalibration.MarkPoint.V = curpos.V;
- SelectCalibration.MarkPoint.W = curpos.W;
- SelectCalibration.MarkPoint.Hand = curpos.Hand;
- SelectCalibration.MarkPoint.Local = curpos.Local;
- SelectCalibration.MarkPoint.Tool = curpos.Tool;
- _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = "成功!", Duration = 1 });
- }
- catch (Exception ex)
- {
- LogHelper.WriteLogError("相机校准-示教中心点界面示教P0时出错!", ex);
- _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
- }
- }
- #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;
- }
- }
- }
- }
|