PlcPointParamsViewModel.cs 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714
  1. using Prism.Commands;
  2. using Prism.Events;
  3. using Prism.Ioc;
  4. using Prism.Mvvm;
  5. using Prism.Regions;
  6. using Prism.Services.Dialogs;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Collections.ObjectModel;
  10. using System.Linq;
  11. using System.Windows;
  12. using TeamAAS_VP.Core;
  13. using TeamAAS_VP.Core.PLCs;
  14. using TeamAAS_VP.Enums;
  15. using TeamAAS_VP.Events;
  16. using TeamAAS_VP.Interfaces;
  17. using TeamAAS_VP.Models;
  18. using TeamAAS_VP.Models.PLC;
  19. using TeamAAS_VP.Models.Robot;
  20. using TeamAAS_VP.Resources.Languages;
  21. namespace TeamAAS_VP.ViewModels.Product
  22. {
  23. public class PlcPointParamsViewModel : BindableBase, IConfirmNavigationRequest
  24. {
  25. IRegionManager _regionManager;
  26. IEventAggregator _eventAggregator;
  27. IContainerProvider _container;
  28. IDialogService _dialogService;
  29. IConfigService _configService;
  30. IRobotService _robotService;
  31. ISystemDatabaseService _systemDatabaseService;
  32. #region 属性
  33. private ProductModel _SelectProduct;
  34. /// <summary>
  35. /// 选中的产品
  36. /// </summary>
  37. public ProductModel SelectProduct
  38. {
  39. get { return _SelectProduct; }
  40. set { SetProperty(ref _SelectProduct, value); }
  41. }
  42. private PlcPoint _SelectedPoint;
  43. public PlcPoint SelectedPoint
  44. {
  45. get { return _SelectedPoint; }
  46. set { SetProperty(ref _SelectedPoint, value); }
  47. }
  48. private PlcPoint _selectedPointInDataGrid;
  49. public PlcPoint SelectedPointInDataGrid
  50. {
  51. get { return _selectedPointInDataGrid; }
  52. set
  53. {
  54. if (SetProperty(ref _selectedPointInDataGrid, value))
  55. {
  56. SelectedPointInComboBox = value;
  57. // update command availability
  58. _MovePointUpCommand?.RaiseCanExecuteChanged();
  59. _MovePointDownCommand?.RaiseCanExecuteChanged();
  60. // 更新依赖可执行状态的命令
  61. _TechPointCommand?.RaiseCanExecuteChanged();
  62. _ExecuteMotion?.RaiseCanExecuteChanged();
  63. }
  64. // 可以同步到 SelectPoint 属性
  65. SelectedPoint = value;
  66. }
  67. }
  68. private PlcPoint _selectedPointInComboBox;
  69. public PlcPoint SelectedPointInComboBox
  70. {
  71. get { return _selectedPointInComboBox; }
  72. set
  73. {
  74. if (SetProperty(ref _selectedPointInComboBox, value))
  75. {
  76. SelectedPointInDataGrid = value;
  77. }
  78. // 可以同步到 SelectPoint 属性
  79. SelectedPoint = value;
  80. }
  81. }
  82. private ObservableCollection<PlcPoint> _Points = new ObservableCollection<PlcPoint>();
  83. /// <summary>
  84. /// 点位集合
  85. /// </summary>
  86. public ObservableCollection<PlcPoint> Points
  87. {
  88. get { return _Points; }
  89. set { SetProperty(ref _Points, value); }
  90. }
  91. private MotionCommand _SelectMotionCommand;
  92. /// <summary>
  93. /// 选中的运动指令
  94. /// </summary>
  95. public MotionCommand SelectMotionCommand
  96. {
  97. get { return _SelectMotionCommand; }
  98. set { SetProperty(ref _SelectMotionCommand, value); }
  99. }
  100. public Management management { get; set; }
  101. private IRobot _Robot;
  102. public IRobot Robot
  103. {
  104. get { return _Robot; }
  105. set
  106. {
  107. SetProperty(ref _Robot, value);
  108. }
  109. }
  110. private int _SelectedIndex;
  111. public int SelectedIndex
  112. {
  113. get { return _SelectedIndex; }
  114. set { SetProperty(ref _SelectedIndex, value); }
  115. }
  116. private double _Distance = 1;
  117. public double Distance
  118. {
  119. get { return _Distance; }
  120. set
  121. {
  122. SetProperty(ref _Distance, value);
  123. try
  124. {
  125. if (Robot == null)
  126. {
  127. return;
  128. }
  129. _configService.UpdateRobotStepDistance(Robot.Id, value);
  130. }
  131. catch (Exception)
  132. {
  133. }
  134. }
  135. }
  136. #endregion
  137. #region 命令
  138. private DelegateCommand _NextCommand;
  139. public DelegateCommand NextCommand =>
  140. _NextCommand ?? (_NextCommand = new DelegateCommand(ExecuteNextCommand));
  141. private DelegateCommand _BackCommand;
  142. public DelegateCommand BackCommand =>
  143. _BackCommand ?? (_BackCommand = new DelegateCommand(ExecuteBackCommand));
  144. private DelegateCommand _LoadedCommand;
  145. public DelegateCommand LoadedCommand =>
  146. _LoadedCommand ?? (_LoadedCommand = new DelegateCommand(ExecuteLoadedCommand));
  147. private DelegateCommand<object> _ExecuteMotion;
  148. public DelegateCommand<object> ExecuteMotion =>
  149. _ExecuteMotion ?? (_ExecuteMotion = new DelegateCommand<object>(ExecuteExecuteMotion).ObservesCanExecute(() => CanExecute).ObservesProperty(() => Robot).ObservesProperty(() => Robot.CanExecute).ObservesProperty(() => SelectedPointInDataGrid));
  150. private DelegateCommand<object> _JogCommand;
  151. public DelegateCommand<object> JogCommand =>
  152. _JogCommand ?? (_JogCommand = new DelegateCommand<object>(ExecuteJogCommand).ObservesCanExecute(() => CanExecute).ObservesProperty(() => Robot).ObservesProperty(() => Robot.CanExecute));
  153. private DelegateCommand _TechPointCommand;
  154. public DelegateCommand TechPointCommand =>
  155. _TechPointCommand ?? (_TechPointCommand = new DelegateCommand(ExecuteTechPointCommand).ObservesCanExecute(() => CanExecute).ObservesProperty(() => Robot).ObservesProperty(() => Robot.CanExecute).ObservesProperty(() => SelectedPointInDataGrid));
  156. private DelegateCommand<string> _MotorCommand;
  157. public DelegateCommand<string> MotorCommand =>
  158. _MotorCommand ?? (_MotorCommand = new DelegateCommand<string>(ExecuteMotorCommand).ObservesCanExecute(() => CanExecute).ObservesProperty(() => Robot).ObservesProperty(() => Robot.CanExecute));
  159. private DelegateCommand _ResetCommand;
  160. public DelegateCommand ResetCommand =>
  161. _ResetCommand ?? (_ResetCommand = new DelegateCommand(ExecuteResetCommand).ObservesCanExecute(() => CanExecute).ObservesProperty(() => Robot).ObservesProperty(() => Robot.CanExecute));
  162. private DelegateCommand _sFreeCommand;
  163. public DelegateCommand sFreeCommand =>
  164. _sFreeCommand ?? (_sFreeCommand = new DelegateCommand(ExecutesFreeCommand).ObservesCanExecute(() => CanExecute).ObservesProperty(() => Robot).ObservesProperty(() => Robot.CanExecute));
  165. private DelegateCommand _SLockCommand;
  166. public DelegateCommand SLockCommand =>
  167. _SLockCommand ?? (_SLockCommand = new DelegateCommand(ExecuteSLockCommand).ObservesCanExecute(() => CanExecute).ObservesProperty(() => Robot).ObservesProperty(() => Robot.CanExecute));
  168. private DelegateCommand _SelectionChangedCommand;
  169. public DelegateCommand SelectionChangedCommand =>
  170. _SelectionChangedCommand ?? (_SelectionChangedCommand = new DelegateCommand(ExecuteSelectionChangedCommand));
  171. private DelegateCommand _AddPointCommand;
  172. public DelegateCommand AddPointCommand =>
  173. _AddPointCommand ?? (_AddPointCommand = new DelegateCommand(ExecuteAddPointCommand));
  174. private DelegateCommand _DeletePointCommand;
  175. public DelegateCommand DeletePointCommand =>
  176. _DeletePointCommand ?? (_DeletePointCommand = new DelegateCommand(ExecuteDeletePointCommand));
  177. private DelegateCommand _MovePointUpCommand;
  178. public DelegateCommand MovePointUpCommand => _MovePointUpCommand ?? (_MovePointUpCommand = new DelegateCommand(ExecuteMovePointUpCommand, CanMovePointUp));
  179. private DelegateCommand _MovePointDownCommand;
  180. public DelegateCommand MovePointDownCommand => _MovePointDownCommand ?? (_MovePointDownCommand = new DelegateCommand(ExecuteMovePointDownCommand, CanMovePointDown));
  181. #endregion
  182. #region 事件
  183. #endregion
  184. public PlcPointParamsViewModel(IRegionManager regionManager, IEventAggregator ea, IContainerProvider container, IDialogService dialogService,
  185. IConfigService configService, IRobotService robotService, ISystemDatabaseService systemDatabaseService)
  186. {
  187. _regionManager = regionManager;
  188. _eventAggregator = ea;
  189. _container = container;
  190. _dialogService = dialogService;
  191. _configService = configService;
  192. _systemDatabaseService = systemDatabaseService;
  193. //订阅权限登录事件
  194. _eventAggregator.GetEvent<UserLoginNotification>().Subscribe(LoginChange);
  195. management = _container.Resolve<Management>();
  196. _robotService = robotService;
  197. }
  198. #region 方法
  199. /// <summary>
  200. /// 下一步
  201. /// </summary>
  202. void ExecuteNextCommand()
  203. {
  204. NavigationParameters param = new NavigationParameters();
  205. param.Add("SelectProduct", SelectProduct);
  206. _regionManager.RequestNavigate("ProductRegionContext", "ProductParams", param);
  207. }
  208. /// <summary>
  209. /// 上一步
  210. /// </summary>
  211. void ExecuteBackCommand()
  212. {
  213. NavigationParameters param = new NavigationParameters();
  214. param.Add("SelectProduct", SelectProduct);
  215. param.Add("SelectedProcedure", null);
  216. _regionManager.RequestNavigate("ProductRegionContext", "ProcessBasics", param);
  217. }
  218. /// <summary>
  219. /// 点动
  220. /// </summary>
  221. /// <param name="obj"></param>
  222. private async void ExecuteJogCommand(object obj)
  223. {
  224. if (Robot == null || !Robot.IsConnected) return;
  225. try
  226. {
  227. Robot.Timeout = 6000000;
  228. var items = ((string)obj).Split(':');
  229. switch (items[0])
  230. {
  231. case "X+":
  232. await Robot.JogAsync("X", double.Parse(items[1]));
  233. break;
  234. case "X-":
  235. await Robot.JogAsync("X", -double.Parse(items[1]));
  236. break;
  237. case "Y+":
  238. await Robot.JogAsync("Y", double.Parse(items[1]));
  239. break;
  240. case "Y-":
  241. await Robot.JogAsync("Y", -double.Parse(items[1]));
  242. break;
  243. case "Z+":
  244. await Robot.JogAsync("Z", double.Parse(items[1]));
  245. break;
  246. case "Z-":
  247. await Robot.JogAsync("Z", -double.Parse(items[1]));
  248. break;
  249. case "U+":
  250. await Robot.JogAsync("U", double.Parse(items[1]));
  251. break;
  252. case "U-":
  253. await Robot.JogAsync("U", -double.Parse(items[1]));
  254. break;
  255. case "V+":
  256. await Robot.JogAsync("V", double.Parse(items[1]));
  257. break;
  258. case "V-":
  259. await Robot.JogAsync("V", -double.Parse(items[1]));
  260. break;
  261. case "W+":
  262. await Robot.JogAsync("W", double.Parse(items[1]));
  263. break;
  264. case "W-":
  265. await Robot.JogAsync("W", -double.Parse(items[1]));
  266. break;
  267. default:
  268. break;
  269. }
  270. Robot.Timeout = 5000;
  271. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = $"{Lang.完成}!", Duration = 0.4 });
  272. }
  273. catch (Exception ex)
  274. {
  275. LogHelper.WriteLogError("机器人点位-机器人点动时出错", ex);
  276. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
  277. }
  278. }
  279. /// <summary>
  280. /// 执行运动
  281. /// </summary>
  282. /// <param name="obj"></param>
  283. async void ExecuteExecuteMotion(object parameter)
  284. {
  285. if (parameter == null)
  286. {
  287. return;
  288. }
  289. var values = (object[])parameter;
  290. var point = values[0] as RPoint;
  291. MotionCommand motionCmd = (MotionCommand)values[1];
  292. if (Robot == null || !Robot.IsConnected) return;
  293. try
  294. {
  295. Robot.Timeout = 6000000;
  296. switch (motionCmd)
  297. {
  298. case MotionCommand.Go:
  299. await Robot.GoAsync(point);
  300. break;
  301. case MotionCommand.Jump:
  302. await Robot.JumpAsync(point, 0);
  303. break;
  304. case MotionCommand.Move:
  305. await Robot.MoveAsync(point);
  306. break;
  307. }
  308. Robot.Timeout = 5000;
  309. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = $"{Lang.完成}!", Duration = 0.4 });
  310. }
  311. catch (Exception ex)
  312. {
  313. LogHelper.WriteLogError("机器人点位-执行点位时出错", ex);
  314. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
  315. }
  316. }
  317. /// <summary>
  318. /// 示教点位
  319. /// </summary>
  320. /// <param name="point"></param>
  321. async void ExecuteTechPointCommand()
  322. {
  323. if (Robot == null || !Robot.IsConnected) return;
  324. if (SelectedPoint == null) return;
  325. try
  326. {
  327. var curpos = await Robot.GetRobotPosAsync();
  328. SelectedPoint.X_Position = curpos.X;
  329. SelectedPoint.Y_Position = curpos.Y;
  330. SelectedPoint.Z_Position_Start = curpos.Z;
  331. SelectedPoint.U_Position = curpos.U;
  332. SelectedPoint.R_Position = curpos.V;
  333. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = $"{Lang.完成}!", Duration = 0.4 });
  334. }
  335. catch (Exception ex)
  336. {
  337. LogHelper.WriteLogError("机器人点位-示教点位时出错", ex);
  338. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
  339. }
  340. }
  341. void ExecuteLoadedCommand()
  342. {
  343. if (_systemDatabaseService.GetCurrentUser().userPart == Enums.UserPart.Operator)
  344. {
  345. IsAllowEdit = false;
  346. }
  347. else
  348. {
  349. IsAllowEdit = true;
  350. }
  351. }
  352. /// <summary>
  353. /// 电机
  354. /// </summary>
  355. /// <param name="obj"></param>
  356. private async void ExecuteMotorCommand(string obj)
  357. {
  358. if (Robot == null || !Robot.IsConnected) return;
  359. try
  360. {
  361. await Robot.MotorAsync(Convert.ToBoolean(obj));
  362. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = $"{Lang.完成}!", Duration = 0.4 });
  363. }
  364. catch (Exception ex)
  365. {
  366. LogHelper.WriteLogError("机器人点击操作时出错!", ex);
  367. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
  368. }
  369. }
  370. /// <summary>
  371. /// 重置
  372. /// </summary>
  373. private async void ExecuteResetCommand()
  374. {
  375. if (Robot == null || !Robot.IsConnected) return;
  376. try
  377. {
  378. await Robot.ResetAsync();
  379. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = $"{Lang.完成}!", Duration = 0.4 });
  380. }
  381. catch (Exception ex)
  382. {
  383. LogHelper.WriteLogError("重置机器人时出错!", ex);
  384. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
  385. }
  386. }
  387. /// <summary>
  388. /// 锁定刹车
  389. /// </summary>
  390. private async void ExecuteSLockCommand()
  391. {
  392. if (Robot == null || !Robot.IsConnected) return;
  393. try
  394. {
  395. await Robot.SLockAsync();
  396. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = $"{Lang.完成}!", Duration = 0.4 });
  397. }
  398. catch (Exception ex)
  399. {
  400. LogHelper.WriteLogError("机器人锁定刹车时出错!", ex);
  401. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
  402. }
  403. }
  404. /// <summary>
  405. /// 释放刹车
  406. /// </summary>
  407. private async void ExecutesFreeCommand()
  408. {
  409. if (Robot == null || !Robot.IsConnected) return;
  410. try
  411. {
  412. await Robot.SFreeAsync();
  413. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = $"{Lang.完成}!", Duration = 0.4 });
  414. }
  415. catch (Exception ex)
  416. {
  417. LogHelper.WriteLogError("机器人释放刹车时出错!", ex);
  418. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
  419. }
  420. }
  421. private bool CanExecute
  422. {
  423. get
  424. {
  425. // 命令可执行仅当机器人可执行且已选择点位
  426. if (Robot != null && Robot.CanExecute)
  427. {
  428. return SelectedPointInDataGrid != null;
  429. }
  430. return false;
  431. }
  432. }
  433. /// <summary>
  434. /// 点位表切换时
  435. /// </summary>
  436. void ExecuteSelectionChangedCommand()
  437. {
  438. switch (SelectedIndex)
  439. {
  440. case 0:
  441. Points = SelectProduct.PickCameraPoints;
  442. break;
  443. case 1:
  444. Points = SelectProduct.PickPoints;
  445. break;
  446. case 2:
  447. Points = SelectProduct.SecPosCameraPoints;
  448. break;
  449. case 3:
  450. Points = SelectProduct.ScrewCameraPoints;
  451. break;
  452. case 4:
  453. Points = SelectProduct.ScrewPoints;
  454. break;
  455. case 5:
  456. Points = SelectProduct.CheckCameraPoints;
  457. break;
  458. default:
  459. break;
  460. }
  461. }
  462. /// <summary>
  463. /// 增加点位
  464. /// </summary>
  465. void ExecuteAddPointCommand()
  466. {
  467. //添加点位
  468. Points.Add(new PlcPoint()
  469. {
  470. Number = Points.Count + 1,
  471. });
  472. // update commands
  473. _MovePointUpCommand?.RaiseCanExecuteChanged();
  474. _MovePointDownCommand?.RaiseCanExecuteChanged();
  475. }
  476. /// <summary>
  477. /// 移除点位
  478. /// </summary>
  479. void ExecuteDeletePointCommand()
  480. {
  481. if (SelectedPoint == null)
  482. {
  483. return;
  484. }
  485. // 确认删除
  486. if (MessageBox.Show("确认要删除选中的点位吗?", "删除点位", MessageBoxButton.YesNo, MessageBoxImage.Question) != MessageBoxResult.Yes)
  487. {
  488. return;
  489. }
  490. int removedIndex = Points.IndexOf(SelectedPoint);
  491. Points.Remove(SelectedPoint);
  492. //重新编号
  493. for (int i = 0; i < Points.Count; i++)
  494. {
  495. Points[i].Number = i + 1;
  496. }
  497. // adjust selection
  498. if (Points.Count > 0)
  499. {
  500. int newIndex = Math.Min(removedIndex, Points.Count - 1);
  501. SelectedPointInDataGrid = Points[newIndex];
  502. }
  503. else
  504. {
  505. SelectedPointInDataGrid = null;
  506. }
  507. // update commands
  508. _MovePointUpCommand?.RaiseCanExecuteChanged();
  509. _MovePointDownCommand?.RaiseCanExecuteChanged();
  510. }
  511. private bool CanMovePointUp()
  512. {
  513. return SelectedPointInDataGrid != null && Points.IndexOf(SelectedPointInDataGrid) > 0;
  514. }
  515. private bool CanMovePointDown()
  516. {
  517. return SelectedPointInDataGrid != null && Points.IndexOf(SelectedPointInDataGrid) >= 0 && Points.IndexOf(SelectedPointInDataGrid) < Points.Count - 1;
  518. }
  519. /// <summary>
  520. /// 向上移动点位
  521. /// </summary>
  522. void ExecuteMovePointUpCommand()
  523. {
  524. if (SelectedPointInDataGrid == null) return;
  525. // 确认移动
  526. if (MessageBox.Show("确认将选中点位上移一位吗?", "移动点位", MessageBoxButton.YesNo, MessageBoxImage.Question) != MessageBoxResult.Yes)
  527. {
  528. return;
  529. }
  530. int idx = Points.IndexOf(SelectedPointInDataGrid);
  531. if (idx <= 0) return;
  532. var item = SelectedPointInDataGrid;
  533. Points.Move(idx, idx - 1);
  534. // renumber
  535. for (int i = 0; i < Points.Count; i++) Points[i].Number = i + 1;
  536. SelectedPointInDataGrid = item;
  537. _MovePointUpCommand?.RaiseCanExecuteChanged();
  538. _MovePointDownCommand?.RaiseCanExecuteChanged();
  539. }
  540. /// <summary>
  541. /// 向下移动点位
  542. /// </summary>
  543. void ExecuteMovePointDownCommand()
  544. {
  545. if (SelectedPointInDataGrid == null) return;
  546. // 确认移动
  547. if (MessageBox.Show("确认将选中点位下移一位吗?", "移动点位", MessageBoxButton.YesNo, MessageBoxImage.Question) != MessageBoxResult.Yes)
  548. {
  549. return;
  550. }
  551. int idx = Points.IndexOf(SelectedPointInDataGrid);
  552. if (idx < 0 || idx >= Points.Count - 1) return;
  553. var item = SelectedPointInDataGrid;
  554. Points.Move(idx, idx + 1);
  555. // renumber
  556. for (int i = 0; i < Points.Count; i++) Points[i].Number = i + 1;
  557. SelectedPointInDataGrid = item;
  558. _MovePointUpCommand?.RaiseCanExecuteChanged();
  559. _MovePointDownCommand?.RaiseCanExecuteChanged();
  560. }
  561. #endregion
  562. #region 继承
  563. /// <summary>
  564. /// 确认导航请求时调用。此方法允许您在导航之前执行一些操作。
  565. /// </summary>
  566. /// <param name="navigationContext"></param>
  567. /// <param name="continuationCallback"></param>
  568. public void ConfirmNavigationRequest(NavigationContext navigationContext, Action<bool> continuationCallback)
  569. {
  570. continuationCallback(true);
  571. }
  572. /// <summary>
  573. /// 接收导航请求时调用。传入导航参数,包含有关导航目标的信息。
  574. /// </summary>
  575. /// <param name="navigationContext"></param>
  576. /// <exception cref="NotImplementedException"></exception>
  577. public async void OnNavigatedTo(NavigationContext navigationContext)
  578. {
  579. try
  580. {
  581. SelectProduct = navigationContext.Parameters.GetValue<ProductModel>("SelectProduct");
  582. SelectedIndex = 0;
  583. Points = SelectProduct.PickCameraPoints;
  584. if (Robot == null)
  585. {
  586. Robot = _robotService.GetRobotByNumber(1);
  587. }
  588. if (Robot != null && Robot.IsConnected)
  589. {
  590. this.Distance = _configService.GetRobotStepDistance(Robot.Id);
  591. Robot.EnterDebugMode = true;
  592. }
  593. else if (Robot != null)
  594. {
  595. Robot.EnterDebugMode = true;
  596. }
  597. }
  598. catch (Exception ex)
  599. {
  600. LogHelper.WriteLogError("机器人点位界面进入时出错!", ex);
  601. }
  602. }
  603. /// <summary>
  604. /// 是否允许导航到此视图模型。
  605. /// </summary>
  606. /// <param name="navigationContext"></param>
  607. /// <returns></returns>
  608. public bool IsNavigationTarget(NavigationContext navigationContext)
  609. {
  610. return true;
  611. }
  612. /// <summary>
  613. /// 导航离开此视图模型时调用。您可以在此处执行清理操作或保存状态。
  614. /// </summary>
  615. /// <param name="navigationContext"></param>
  616. public void OnNavigatedFrom(NavigationContext navigationContext)
  617. {
  618. //if (Robot != null)
  619. //{
  620. // Robot.EnterDebugMode = false;
  621. //}
  622. }
  623. #endregion
  624. private bool _IsAllowEdit = false;
  625. public bool IsAllowEdit
  626. {
  627. get { return _IsAllowEdit; }
  628. set { SetProperty(ref _IsAllowEdit, value); }
  629. }
  630. private void LoginChange(Models.User user)
  631. {
  632. if (user.userPart == Enums.UserPart.Operator)
  633. {
  634. IsAllowEdit = false;
  635. }
  636. else
  637. {
  638. IsAllowEdit = true;
  639. }
  640. }
  641. }
  642. }