| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799 |
- using MaterialDesignThemes.Wpf;
- 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.Collections.ObjectModel;
- using System.Linq;
- using System.Windows;
- using TeamAAS_VP.Core;
- using TeamAAS_VP.Core.PLCs;
- using TeamAAS_VP.DxfModule;
- using TeamAAS_VP.Enums;
- using TeamAAS_VP.Events;
- using TeamAAS_VP.Interfaces;
- using TeamAAS_VP.Models;
- using TeamAAS_VP.Models.PLC;
- using TeamAAS_VP.Models.Robot;
- using TeamAAS_VP.Resources.Languages;
- using TeamAAS_VP.Views.Product;
- namespace TeamAAS_VP.ViewModels.Product
- {
- public class PlcPointParamsViewModel : BindableBase, IConfirmNavigationRequest
- {
- IRegionManager _regionManager;
- IEventAggregator _eventAggregator;
- IContainerProvider _container;
- IDialogService _dialogService;
- IConfigService _configService;
- IRobotService _robotService;
- ISystemDatabaseService _systemDatabaseService;
- #region 属性
- private ProductModel _SelectProduct;
- /// <summary>
- /// 选中的产品
- /// </summary>
- public ProductModel SelectProduct
- {
- get { return _SelectProduct; }
- set { SetProperty(ref _SelectProduct, value); }
- }
- private PlcPoint _SelectedPoint;
- public PlcPoint SelectedPoint
- {
- get { return _SelectedPoint; }
- set { SetProperty(ref _SelectedPoint, value); }
- }
- private PlcPoint _selectedPointInDataGrid;
- public PlcPoint SelectedPointInDataGrid
- {
- get { return _selectedPointInDataGrid; }
- set
- {
- if (SetProperty(ref _selectedPointInDataGrid, value))
- {
- SelectedPointInComboBox = value;
- // update command availability
- _MovePointUpCommand?.RaiseCanExecuteChanged();
- _MovePointDownCommand?.RaiseCanExecuteChanged();
- // 更新依赖可执行状态的命令
- _TechPointCommand?.RaiseCanExecuteChanged();
- _ExecuteMotion?.RaiseCanExecuteChanged();
- }
- // 可以同步到 SelectPoint 属性
- SelectedPoint = value;
- }
- }
- private PlcPoint _selectedPointInComboBox;
- public PlcPoint SelectedPointInComboBox
- {
- get { return _selectedPointInComboBox; }
- set
- {
- if (SetProperty(ref _selectedPointInComboBox, value))
- {
- SelectedPointInDataGrid = value;
- }
- // 可以同步到 SelectPoint 属性
- SelectedPoint = value;
- }
- }
- private ObservableCollection<PlcPoint> _Points = new ObservableCollection<PlcPoint>();
- /// <summary>
- /// 点位集合
- /// </summary>
- public ObservableCollection<PlcPoint> Points
- {
- get { return _Points; }
- set { SetProperty(ref _Points, value); }
- }
- private MotionCommand _SelectMotionCommand;
- /// <summary>
- /// 选中的运动指令
- /// </summary>
- public MotionCommand SelectMotionCommand
- {
- get { return _SelectMotionCommand; }
- set { SetProperty(ref _SelectMotionCommand, value); }
- }
- public Management management { get; set; }
- private IRobot _Robot;
- public IRobot Robot
- {
- get { return _Robot; }
- set
- {
- SetProperty(ref _Robot, value);
- }
- }
- private int _SelectedIndex;
- public int SelectedIndex
- {
- get { return _SelectedIndex; }
- set { SetProperty(ref _SelectedIndex, value); }
- }
- private double _Distance = 1;
- public double Distance
- {
- get { return _Distance; }
- set
- {
- SetProperty(ref _Distance, value);
- try
- {
- if (Robot == null)
- {
- return;
- }
- _configService.UpdateRobotStepDistance(Robot.Id, value);
- }
- catch (Exception)
- {
- }
- }
- }
- #endregion
- #region 命令
- private DelegateCommand _NextCommand;
- public DelegateCommand NextCommand =>
- _NextCommand ?? (_NextCommand = new DelegateCommand(ExecuteNextCommand));
- private DelegateCommand _BackCommand;
- public DelegateCommand BackCommand =>
- _BackCommand ?? (_BackCommand = new DelegateCommand(ExecuteBackCommand));
- private DelegateCommand _LoadedCommand;
- public DelegateCommand LoadedCommand =>
- _LoadedCommand ?? (_LoadedCommand = new DelegateCommand(ExecuteLoadedCommand));
- private DelegateCommand<object> _ExecuteMotion;
- public DelegateCommand<object> ExecuteMotion =>
- _ExecuteMotion ?? (_ExecuteMotion = new DelegateCommand<object>(ExecuteExecuteMotion).ObservesCanExecute(() => CanExecute).ObservesProperty(() => Robot).ObservesProperty(() => Robot.CanExecute).ObservesProperty(() => SelectedPointInDataGrid));
- private DelegateCommand<object> _JogCommand;
- public DelegateCommand<object> JogCommand =>
- _JogCommand ?? (_JogCommand = new DelegateCommand<object>(ExecuteJogCommand).ObservesCanExecute(() => CanExecute).ObservesProperty(() => Robot).ObservesProperty(() => Robot.CanExecute));
- private DelegateCommand _TechPointCommand;
- public DelegateCommand TechPointCommand =>
- _TechPointCommand ?? (_TechPointCommand = new DelegateCommand(ExecuteTechPointCommand).ObservesCanExecute(() => CanExecute).ObservesProperty(() => Robot).ObservesProperty(() => Robot.CanExecute).ObservesProperty(() => SelectedPointInDataGrid));
- private DelegateCommand<string> _MotorCommand;
- public DelegateCommand<string> MotorCommand =>
- _MotorCommand ?? (_MotorCommand = new DelegateCommand<string>(ExecuteMotorCommand).ObservesCanExecute(() => CanExecute).ObservesProperty(() => Robot).ObservesProperty(() => Robot.CanExecute));
- private DelegateCommand _ResetCommand;
- public DelegateCommand ResetCommand =>
- _ResetCommand ?? (_ResetCommand = new DelegateCommand(ExecuteResetCommand).ObservesCanExecute(() => CanExecute).ObservesProperty(() => Robot).ObservesProperty(() => Robot.CanExecute));
- private DelegateCommand _sFreeCommand;
- public DelegateCommand sFreeCommand =>
- _sFreeCommand ?? (_sFreeCommand = new DelegateCommand(ExecutesFreeCommand).ObservesCanExecute(() => CanExecute).ObservesProperty(() => Robot).ObservesProperty(() => Robot.CanExecute));
- private DelegateCommand _SLockCommand;
- public DelegateCommand SLockCommand =>
- _SLockCommand ?? (_SLockCommand = new DelegateCommand(ExecuteSLockCommand).ObservesCanExecute(() => CanExecute).ObservesProperty(() => Robot).ObservesProperty(() => Robot.CanExecute));
- private DelegateCommand _SelectionChangedCommand;
- public DelegateCommand SelectionChangedCommand =>
- _SelectionChangedCommand ?? (_SelectionChangedCommand = new DelegateCommand(ExecuteSelectionChangedCommand));
- private DelegateCommand _AddPointCommand;
- public DelegateCommand AddPointCommand =>
- _AddPointCommand ?? (_AddPointCommand = new DelegateCommand(ExecuteAddPointCommand));
- private DelegateCommand _DeletePointCommand;
- public DelegateCommand DeletePointCommand =>
- _DeletePointCommand ?? (_DeletePointCommand = new DelegateCommand(ExecuteDeletePointCommand));
- private DelegateCommand _MovePointUpCommand;
- public DelegateCommand MovePointUpCommand => _MovePointUpCommand ?? (_MovePointUpCommand = new DelegateCommand(ExecuteMovePointUpCommand, CanMovePointUp));
- private DelegateCommand _MovePointDownCommand;
- public DelegateCommand MovePointDownCommand => _MovePointDownCommand ?? (_MovePointDownCommand = new DelegateCommand(ExecuteMovePointDownCommand, CanMovePointDown));
- private DelegateCommand _ImportCadPointCommand;
- public DelegateCommand ImportCadPointCommand =>
- _ImportCadPointCommand ?? (_ImportCadPointCommand = new DelegateCommand(ExecuteImportCadPointCommand));
-
- #endregion
- #region 事件
- #endregion
- public PlcPointParamsViewModel(IRegionManager regionManager, IEventAggregator ea, IContainerProvider container, IDialogService dialogService,
- IConfigService configService, IRobotService robotService, ISystemDatabaseService systemDatabaseService)
- {
- _regionManager = regionManager;
- _eventAggregator = ea;
- _container = container;
- _dialogService = dialogService;
- _configService = configService;
- _systemDatabaseService = systemDatabaseService;
- //订阅权限登录事件
- _eventAggregator.GetEvent<UserLoginNotification>().Subscribe(LoginChange);
- management = _container.Resolve<Management>();
- _robotService = robotService;
- }
- #region 方法
- /// <summary>
- /// 下一步
- /// </summary>
- void ExecuteNextCommand()
- {
- NavigationParameters param = new NavigationParameters();
- param.Add("SelectProduct", SelectProduct);
- _regionManager.RequestNavigate("ProductRegionContext", "ProductParams", param);
- }
- /// <summary>
- /// 上一步
- /// </summary>
- void ExecuteBackCommand()
- {
- NavigationParameters param = new NavigationParameters();
- param.Add("SelectProduct", SelectProduct);
- param.Add("SelectedProcedure", null);
- _regionManager.RequestNavigate("ProductRegionContext", "ProcessBasics", param);
- }
- /// <summary>
- /// 点动
- /// </summary>
- /// <param name="obj"></param>
- private async void ExecuteJogCommand(object obj)
- {
- if (Robot == null || !Robot.IsConnected) return;
- try
- {
- Robot.Timeout = 6000000;
- var items = ((string)obj).Split(':');
- switch (items[0])
- {
- case "X+":
- await Robot.JogAsync("X", double.Parse(items[1]));
- break;
- case "X-":
- await Robot.JogAsync("X", -double.Parse(items[1]));
- break;
- case "Y+":
- await Robot.JogAsync("Y", double.Parse(items[1]));
- break;
- case "Y-":
- await Robot.JogAsync("Y", -double.Parse(items[1]));
- break;
- case "Z+":
- await Robot.JogAsync("Z", double.Parse(items[1]));
- break;
- case "Z-":
- await Robot.JogAsync("Z", -double.Parse(items[1]));
- break;
- case "U+":
- await Robot.JogAsync("U", double.Parse(items[1]));
- break;
- case "U-":
- await Robot.JogAsync("U", -double.Parse(items[1]));
- break;
- case "V+":
- await Robot.JogAsync("V", double.Parse(items[1]));
- break;
- case "V-":
- await Robot.JogAsync("V", -double.Parse(items[1]));
- break;
- case "W+":
- await Robot.JogAsync("W", double.Parse(items[1]));
- break;
- case "W-":
- await Robot.JogAsync("W", -double.Parse(items[1]));
- break;
- default:
- break;
- }
- Robot.Timeout = 5000;
- _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = $"{Lang.完成}!", Duration = 0.4 });
- }
- 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 ExecuteExecuteMotion(object parameter)
- {
- if (parameter == null)
- {
- return;
- }
- var values = (object[])parameter;
- var point = values[0] as RPoint;
- MotionCommand motionCmd = (MotionCommand)values[1];
- if (Robot == null || !Robot.IsConnected) return;
- try
- {
- Robot.Timeout = 6000000;
- switch (motionCmd)
- {
- case MotionCommand.Go:
- await Robot.GoAsync(point);
- break;
- case MotionCommand.Jump:
- await Robot.JumpAsync(point, 0);
- break;
- case MotionCommand.Move:
- await Robot.MoveAsync(point);
- break;
- }
- Robot.Timeout = 5000;
- _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = $"{Lang.完成}!", Duration = 0.4 });
- }
- catch (Exception ex)
- {
- LogHelper.WriteLogError("机器人点位-执行点位时出错", ex);
- _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
- }
- }
- /// <summary>
- /// 示教点位
- /// </summary>
- /// <param name="point"></param>
- async void ExecuteTechPointCommand()
- {
- if (Robot == null || !Robot.IsConnected) return;
- if (SelectedPoint == null) return;
- try
- {
- var curpos = await Robot.GetRobotPosAsync();
- SelectedPoint.X_Position = curpos.X;
- SelectedPoint.Y_Position = curpos.Y;
- SelectedPoint.Z_Position_Start = curpos.Z;
- SelectedPoint.U_Position = curpos.U;
- SelectedPoint.R_Position = curpos.V;
- _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = $"{Lang.完成}!", Duration = 0.4 });
- }
- catch (Exception ex)
- {
- LogHelper.WriteLogError("机器人点位-示教点位时出错", ex);
- _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
- }
- }
- void ExecuteLoadedCommand()
- {
- if (_systemDatabaseService.GetCurrentUser().userPart == Enums.UserPart.Operator)
- {
- IsAllowEdit = false;
- }
- else
- {
- IsAllowEdit = true;
- }
- }
- /// <summary>
- /// 电机
- /// </summary>
- /// <param name="obj"></param>
- private async void ExecuteMotorCommand(string obj)
- {
- if (Robot == null || !Robot.IsConnected) return;
- try
- {
- await Robot.MotorAsync(Convert.ToBoolean(obj));
- _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = $"{Lang.完成}!", Duration = 0.4 });
- }
- catch (Exception ex)
- {
- LogHelper.WriteLogError("机器人点击操作时出错!", ex);
- _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
- }
- }
- /// <summary>
- /// 重置
- /// </summary>
- private async void ExecuteResetCommand()
- {
- if (Robot == null || !Robot.IsConnected) return;
- try
- {
- await Robot.ResetAsync();
- _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = $"{Lang.完成}!", Duration = 0.4 });
- }
- catch (Exception ex)
- {
- LogHelper.WriteLogError("重置机器人时出错!", ex);
- _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
- }
- }
- /// <summary>
- /// 锁定刹车
- /// </summary>
- private async void ExecuteSLockCommand()
- {
- if (Robot == null || !Robot.IsConnected) return;
- try
- {
- await Robot.SLockAsync();
- _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = $"{Lang.完成}!", Duration = 0.4 });
- }
- catch (Exception ex)
- {
- LogHelper.WriteLogError("机器人锁定刹车时出错!", ex);
- _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
- }
- }
- /// <summary>
- /// 释放刹车
- /// </summary>
- private async void ExecutesFreeCommand()
- {
- if (Robot == null || !Robot.IsConnected) return;
- try
- {
- await Robot.SFreeAsync();
- _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = $"{Lang.完成}!", Duration = 0.4 });
- }
- catch (Exception ex)
- {
- LogHelper.WriteLogError("机器人释放刹车时出错!", ex);
- _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
- }
- }
- private bool CanExecute
- {
- get
- {
- // 命令可执行仅当机器人可执行且已选择点位
- if (Robot != null && Robot.CanExecute)
- {
- return SelectedPointInDataGrid != null;
- }
- return false;
- }
- }
- /// <summary>
- /// 点位表切换时
- /// </summary>
- void ExecuteSelectionChangedCommand()
- {
- switch (SelectedIndex)
- {
- case 0:
- Points = SelectProduct.PickCameraPoints;
- break;
- case 1:
- Points = SelectProduct.PickPoints;
- break;
- case 2:
- Points = SelectProduct.SecPosCameraPoints;
- break;
- case 3:
- Points = SelectProduct.ScrewCameraPoints;
- break;
- case 4:
- Points = SelectProduct.ScrewPoints;
- break;
- case 5:
- Points = SelectProduct.CheckCameraPoints;
- break;
- default:
- break;
- }
- }
- /// <summary>
- /// 增加点位
- /// </summary>
- void ExecuteAddPointCommand()
- {
- //添加点位
- Points.Add(new PlcPoint()
- {
- Number = Points.Count + 1,
- X_Velocity = 100,
- Y_Velocity = 100,
- Z_Velocity_Start = 100,
- Z_Velocity_Stop = 100,
- U_Velocity = 100,
- R_Velocity = 100,
- });
- // update commands
- _MovePointUpCommand?.RaiseCanExecuteChanged();
- _MovePointDownCommand?.RaiseCanExecuteChanged();
- }
- /// <summary>
- /// 移除点位
- /// </summary>
- void ExecuteDeletePointCommand()
- {
- if (SelectedPoint == null)
- {
- return;
- }
- // 确认删除
- if (MessageBox.Show("确认要删除选中的点位吗?", "删除点位", MessageBoxButton.YesNo, MessageBoxImage.Question) != MessageBoxResult.Yes)
- {
- return;
- }
- int removedIndex = Points.IndexOf(SelectedPoint);
- Points.Remove(SelectedPoint);
- //重新编号
- for (int i = 0; i < Points.Count; i++)
- {
- Points[i].Number = i + 1;
- }
- // adjust selection
- if (Points.Count > 0)
- {
- int newIndex = Math.Min(removedIndex, Points.Count - 1);
- SelectedPointInDataGrid = Points[newIndex];
- }
- else
- {
- SelectedPointInDataGrid = null;
- }
- // update commands
- _MovePointUpCommand?.RaiseCanExecuteChanged();
- _MovePointDownCommand?.RaiseCanExecuteChanged();
- }
- private bool CanMovePointUp()
- {
- return SelectedPointInDataGrid != null && Points.IndexOf(SelectedPointInDataGrid) > 0;
- }
- private bool CanMovePointDown()
- {
- return SelectedPointInDataGrid != null && Points.IndexOf(SelectedPointInDataGrid) >= 0 && Points.IndexOf(SelectedPointInDataGrid) < Points.Count - 1;
- }
- /// <summary>
- /// 向上移动点位
- /// </summary>
- void ExecuteMovePointUpCommand()
- {
- if (SelectedPointInDataGrid == null) return;
- // 确认移动
- if (MessageBox.Show("确认将选中点位上移一位吗?", "移动点位", MessageBoxButton.YesNo, MessageBoxImage.Question) != MessageBoxResult.Yes)
- {
- return;
- }
- int idx = Points.IndexOf(SelectedPointInDataGrid);
- if (idx <= 0) return;
- var item = SelectedPointInDataGrid;
- Points.Move(idx, idx - 1);
- // renumber
- for (int i = 0; i < Points.Count; i++) Points[i].Number = i + 1;
- SelectedPointInDataGrid = item;
- _MovePointUpCommand?.RaiseCanExecuteChanged();
- _MovePointDownCommand?.RaiseCanExecuteChanged();
- }
- /// <summary>
- /// 向下移动点位
- /// </summary>
- void ExecuteMovePointDownCommand()
- {
- if (SelectedPointInDataGrid == null) return;
- // 确认移动
- if (MessageBox.Show("确认将选中点位下移一位吗?", "移动点位", MessageBoxButton.YesNo, MessageBoxImage.Question) != MessageBoxResult.Yes)
- {
- return;
- }
- int idx = Points.IndexOf(SelectedPointInDataGrid);
- if (idx < 0 || idx >= Points.Count - 1) return;
- var item = SelectedPointInDataGrid;
- Points.Move(idx, idx + 1);
- // renumber
- for (int i = 0; i < Points.Count; i++) Points[i].Number = i + 1;
- SelectedPointInDataGrid = item;
- _MovePointUpCommand?.RaiseCanExecuteChanged();
- _MovePointDownCommand?.RaiseCanExecuteChanged();
- }
- /// <summary>
- /// CAD导入点位
- /// </summary>
- async void ExecuteImportCadPointCommand()
- {
- try
- {
- var view = new DxfView();
- //show the dialog
- var result = await DialogHost.Show(view, "RootDialog", null, null, null);
- if (result != null)
- {
- var cadPoints = view.Points;
- if (cadPoints != null && cadPoints.Count > 0)
- {
- //要导入的开始点编号
- int startNumber = view.StartIndex;
- //弹窗提示用户是否确认要导入从该编号开始的点位,点位数量为cadPoints.Count
- if (MessageBox.Show($"确认要从点位编号 {startNumber} 开始导入 {cadPoints.Count} 个点位吗?", "导入点位", MessageBoxButton.YesNo, MessageBoxImage.Question) != MessageBoxResult.Yes)
- {
- return;
- }
- //导入点位
- for (int i = 0; i < cadPoints.Count; i++)
- {
- //如果点位编号已存在,则更新该点位,否则新增点位,只更新XY坐标
- var point = cadPoints[i];
- var existingPoint = Points.FirstOrDefault(p => p.Number == startNumber + i);
- if (existingPoint != null)
- {
- existingPoint.X_Position = point.X;
- existingPoint.Y_Position = point.Y;
- }
- else
- {
- Points.Add(new PlcPoint()
- {
- Number = startNumber + i,
- X_Position = point.X,
- Y_Position = point.Y,
- X_Velocity=100,
- Y_Velocity=100,
- Z_Velocity_Start=100,
- Z_Velocity_Stop=100,
- U_Velocity=100,
- R_Velocity=100,
- });
- }
- }
- //对所有的点位重新编号,确保编号连续
- var sortedPoints = Points.OrderBy(p => p.Number).ToList();
- Points.Clear();
- for (int i = 0; i < sortedPoints.Count; i++)
- {
- sortedPoints[i].Number = i + 1;
- Points.Add(sortedPoints[i]);
- }
- _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = $"{Lang.完成}!", Duration = 0.4 });
- }
- }
- }
- catch (Exception ex)
- {
- LogHelper.WriteLogError("导入CAD点位时出错!", ex);
- _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
- }
- }
- #endregion
- #region 继承
- /// <summary>
- /// 确认导航请求时调用。此方法允许您在导航之前执行一些操作。
- /// </summary>
- /// <param name="navigationContext"></param>
- /// <param name="continuationCallback"></param>
- public void ConfirmNavigationRequest(NavigationContext navigationContext, Action<bool> continuationCallback)
- {
- continuationCallback(true);
- }
- /// <summary>
- /// 接收导航请求时调用。传入导航参数,包含有关导航目标的信息。
- /// </summary>
- /// <param name="navigationContext"></param>
- /// <exception cref="NotImplementedException"></exception>
- public async void OnNavigatedTo(NavigationContext navigationContext)
- {
- try
- {
- SelectProduct = navigationContext.Parameters.GetValue<ProductModel>("SelectProduct");
- SelectedIndex = 0;
- Points = SelectProduct.PickCameraPoints;
- if (Robot == null)
- {
- Robot = _robotService.GetRobotByNumber(1);
- }
- if (Robot != null && Robot.IsConnected)
- {
- this.Distance = _configService.GetRobotStepDistance(Robot.Id);
- Robot.EnterDebugMode = true;
- }
- else if (Robot != null)
- {
- Robot.EnterDebugMode = true;
- }
- }
- catch (Exception ex)
- {
- LogHelper.WriteLogError("机器人点位界面进入时出错!", ex);
- }
- }
- /// <summary>
- /// 是否允许导航到此视图模型。
- /// </summary>
- /// <param name="navigationContext"></param>
- /// <returns></returns>
- public bool IsNavigationTarget(NavigationContext navigationContext)
- {
- return true;
- }
- /// <summary>
- /// 导航离开此视图模型时调用。您可以在此处执行清理操作或保存状态。
- /// </summary>
- /// <param name="navigationContext"></param>
- public void OnNavigatedFrom(NavigationContext navigationContext)
- {
- //if (Robot != null)
- //{
- // Robot.EnterDebugMode = false;
- //}
- }
- #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;
- }
- }
- }
- }
|