RobotPointParamsViewModel.cs 25 KB

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