RobotPointParamsViewModel.cs 25 KB

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