PlcPointParamsViewModel.cs 50 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289
  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;
  13. using System.Threading.Tasks;
  14. using System.Windows;
  15. using TeamAAS_VP.Controls;
  16. using TeamAAS_VP.Core;
  17. using TeamAAS_VP.Core.PLCs;
  18. using TeamAAS_VP.DxfModule;
  19. using TeamAAS_VP.Enums;
  20. using TeamAAS_VP.Events;
  21. using TeamAAS_VP.Interfaces;
  22. using TeamAAS_VP.Models;
  23. using TeamAAS_VP.Models.PLC;
  24. using TeamAAS_VP.Models.Robot;
  25. using TeamAAS_VP.Resources.Languages;
  26. using TeamAAS_VP.Services;
  27. using TeamAAS_VP.Views.Product;
  28. namespace TeamAAS_VP.ViewModels.Product
  29. {
  30. public class PlcPointParamsViewModel : BindableBase, IConfirmNavigationRequest
  31. {
  32. IRegionManager _regionManager;
  33. IEventAggregator _eventAggregator;
  34. IContainerProvider _container;
  35. IDialogService _dialogService;
  36. IConfigService _configService;
  37. IRobotService _robotService;
  38. ISystemDatabaseService _systemDatabaseService;
  39. IRemoteCommandService _remoteCommandService;
  40. #region 属性
  41. private ProductModel _SelectProduct;
  42. /// <summary>
  43. /// 选中的产品
  44. /// </summary>
  45. public ProductModel SelectProduct
  46. {
  47. get { return _SelectProduct; }
  48. set { SetProperty(ref _SelectProduct, value); }
  49. }
  50. private PlcPoint _SelectedPoint;
  51. public PlcPoint SelectedPoint
  52. {
  53. get { return _SelectedPoint; }
  54. set { SetProperty(ref _SelectedPoint, value); }
  55. }
  56. private PlcPoint _selectedPointInDataGrid;
  57. public PlcPoint SelectedPointInDataGrid
  58. {
  59. get { return _selectedPointInDataGrid; }
  60. set
  61. {
  62. if (SetProperty(ref _selectedPointInDataGrid, value))
  63. {
  64. SelectedPointInComboBox = value;
  65. // update command availability
  66. _MovePointUpCommand?.RaiseCanExecuteChanged();
  67. _MovePointDownCommand?.RaiseCanExecuteChanged();
  68. // 更新依赖可执行状态的命令
  69. _TechPointCommand?.RaiseCanExecuteChanged();
  70. _ExecuteMotion?.RaiseCanExecuteChanged();
  71. }
  72. // 可以同步到 SelectPoint 属性
  73. SelectedPoint = value;
  74. }
  75. }
  76. private PlcPoint _selectedPointInComboBox;
  77. public PlcPoint SelectedPointInComboBox
  78. {
  79. get { return _selectedPointInComboBox; }
  80. set
  81. {
  82. if (SetProperty(ref _selectedPointInComboBox, value))
  83. {
  84. SelectedPointInDataGrid = value;
  85. }
  86. // 可以同步到 SelectPoint 属性
  87. SelectedPoint = value;
  88. }
  89. }
  90. private ObservableCollection<PlcPoint> _Points = new ObservableCollection<PlcPoint>();
  91. /// <summary>
  92. /// 点位集合
  93. /// </summary>
  94. public ObservableCollection<PlcPoint> Points
  95. {
  96. get { return _Points; }
  97. set { SetProperty(ref _Points, value); }
  98. }
  99. private MotionCommand _SelectMotionCommand;
  100. /// <summary>
  101. /// 选中的运动指令
  102. /// </summary>
  103. public MotionCommand SelectMotionCommand
  104. {
  105. get { return _SelectMotionCommand; }
  106. set { SetProperty(ref _SelectMotionCommand, value); }
  107. }
  108. public Management management { get; set; }
  109. private IRobot _Robot;
  110. public IRobot Robot
  111. {
  112. get { return _Robot; }
  113. set
  114. {
  115. SetProperty(ref _Robot, value);
  116. }
  117. }
  118. private int _SelectedIndex;
  119. public int SelectedIndex
  120. {
  121. get { return _SelectedIndex; }
  122. set { SetProperty(ref _SelectedIndex, value); }
  123. }
  124. private double _Distance = 1;
  125. public double Distance
  126. {
  127. get { return _Distance; }
  128. set
  129. {
  130. SetProperty(ref _Distance, value);
  131. try
  132. {
  133. if (Robot == null)
  134. {
  135. return;
  136. }
  137. _configService.UpdateRobotStepDistance(Robot.Id, value);
  138. }
  139. catch (Exception)
  140. {
  141. }
  142. }
  143. }
  144. private ObservableCollection<ProcedureModel> _ProcedureModels;
  145. /// <summary>
  146. /// 流程集合
  147. /// </summary>
  148. public ObservableCollection<ProcedureModel> ProcedureModels
  149. {
  150. get { return _ProcedureModels; }
  151. set { SetProperty(ref _ProcedureModels, value); }
  152. }
  153. private ProcedureModel _SelectProcedure;
  154. /// <summary>
  155. /// 选中的流程
  156. /// </summary>
  157. public ProcedureModel SelectProcedure
  158. {
  159. get { return _SelectProcedure; }
  160. set
  161. {
  162. SetProperty(ref _SelectProcedure, value);
  163. }
  164. }
  165. private float _LockPointStartZ;
  166. /// <summary>
  167. /// 批量设置锁付点的起始Z坐标
  168. /// </summary>
  169. public float LockPointStartZ
  170. {
  171. get { return _LockPointStartZ; }
  172. set { SetProperty(ref _LockPointStartZ, value); }
  173. }
  174. private float _LockZDepth;
  175. /// <summary>
  176. /// 批量设置锁付点Z深度
  177. /// </summary>
  178. public float LockZDepth
  179. {
  180. get { return _LockZDepth; }
  181. set { SetProperty(ref _LockZDepth, value); }
  182. }
  183. private float _LockXSpeed;
  184. /// <summary>
  185. /// 批量设置锁付点X轴速度
  186. /// </summary>
  187. public float LockXSpeed
  188. {
  189. get { return _LockXSpeed; }
  190. set { SetProperty(ref _LockXSpeed, value); }
  191. }
  192. private float _LockYSpeed;
  193. /// <summary>
  194. /// 批量设置锁付点Y轴速度
  195. /// </summary>
  196. public float LockYSpeed
  197. {
  198. get { return _LockYSpeed; }
  199. set { SetProperty(ref _LockYSpeed, value); }
  200. }
  201. private float _LockZSpeed;
  202. /// <summary>
  203. /// 批量设置锁付点Z轴速度
  204. /// </summary>
  205. public float LockZSpeed
  206. {
  207. get { return _LockZSpeed; }
  208. set { SetProperty(ref _LockZSpeed, value); }
  209. }
  210. private float _LockZDescendSpeed;
  211. /// <summary>
  212. /// 批量设置锁付点Z轴下降速度
  213. /// </summary>
  214. public float LockZDescendSpeed
  215. {
  216. get { return _LockZDescendSpeed; }
  217. set { SetProperty(ref _LockZDescendSpeed, value); }
  218. }
  219. private Int16 _LockFeederNumber;
  220. /// <summary>
  221. /// 批量设置锁付点供料器编号
  222. /// </summary>
  223. public Int16 LockFeederNumber
  224. {
  225. get { return _LockFeederNumber; }
  226. set { SetProperty(ref _LockFeederNumber, value); }
  227. }
  228. private Int16 _LockScrewProgramNumber;
  229. /// <summary>
  230. /// 批量设置锁付点螺丝程序编号
  231. /// </summary>
  232. public Int16 LockScrewProgramNumber
  233. {
  234. get { return _LockScrewProgramNumber; }
  235. set { SetProperty(ref _LockScrewProgramNumber, value); }
  236. }
  237. #endregion
  238. #region 命令
  239. private DelegateCommand _NextCommand;
  240. public DelegateCommand NextCommand =>
  241. _NextCommand ?? (_NextCommand = new DelegateCommand(ExecuteNextCommand));
  242. private DelegateCommand _BackCommand;
  243. public DelegateCommand BackCommand =>
  244. _BackCommand ?? (_BackCommand = new DelegateCommand(ExecuteBackCommand));
  245. private DelegateCommand _LoadedCommand;
  246. public DelegateCommand LoadedCommand =>
  247. _LoadedCommand ?? (_LoadedCommand = new DelegateCommand(ExecuteLoadedCommand));
  248. private DelegateCommand<object> _ExecuteMotion;
  249. public DelegateCommand<object> ExecuteMotion =>
  250. _ExecuteMotion ?? (_ExecuteMotion = new DelegateCommand<object>(ExecuteExecuteMotion).ObservesCanExecute(() => CanExecutePointCommand).ObservesProperty(() => Robot).ObservesProperty(() => Robot.CanExecute).ObservesProperty(() => SelectedPointInDataGrid));
  251. private DelegateCommand<object> _JogCommand;
  252. public DelegateCommand<object> JogCommand =>
  253. _JogCommand ?? (_JogCommand = new DelegateCommand<object>(ExecuteJogCommand).ObservesCanExecute(() => CanExecute).ObservesProperty(() => Robot).ObservesProperty(() => Robot.CanExecute));
  254. private DelegateCommand _TechPointCommand;
  255. public DelegateCommand TechPointCommand =>
  256. _TechPointCommand ?? (_TechPointCommand = new DelegateCommand(ExecuteTechPointCommand).ObservesCanExecute(() => CanExecutePointCommand).ObservesProperty(() => Robot).ObservesProperty(() => Robot.CanExecute).ObservesProperty(() => SelectedPointInDataGrid));
  257. private DelegateCommand<string> _MotorCommand;
  258. public DelegateCommand<string> MotorCommand =>
  259. _MotorCommand ?? (_MotorCommand = new DelegateCommand<string>(ExecuteMotorCommand).ObservesCanExecute(() => CanExecute).ObservesProperty(() => Robot).ObservesProperty(() => Robot.CanExecute));
  260. private DelegateCommand _ResetCommand;
  261. public DelegateCommand ResetCommand =>
  262. _ResetCommand ?? (_ResetCommand = new DelegateCommand(ExecuteResetCommand).ObservesCanExecute(() => CanExecute).ObservesProperty(() => Robot).ObservesProperty(() => Robot.CanExecute));
  263. private DelegateCommand _sFreeCommand;
  264. public DelegateCommand sFreeCommand =>
  265. _sFreeCommand ?? (_sFreeCommand = new DelegateCommand(ExecutesFreeCommand).ObservesCanExecute(() => CanExecute).ObservesProperty(() => Robot).ObservesProperty(() => Robot.CanExecute));
  266. private DelegateCommand _SLockCommand;
  267. public DelegateCommand SLockCommand =>
  268. _SLockCommand ?? (_SLockCommand = new DelegateCommand(ExecuteSLockCommand).ObservesCanExecute(() => CanExecute).ObservesProperty(() => Robot).ObservesProperty(() => Robot.CanExecute));
  269. private DelegateCommand _SelectionChangedCommand;
  270. public DelegateCommand SelectionChangedCommand =>
  271. _SelectionChangedCommand ?? (_SelectionChangedCommand = new DelegateCommand(ExecuteSelectionChangedCommand));
  272. private DelegateCommand _AddPointCommand;
  273. public DelegateCommand AddPointCommand =>
  274. _AddPointCommand ?? (_AddPointCommand = new DelegateCommand(ExecuteAddPointCommand));
  275. private DelegateCommand _DeletePointCommand;
  276. public DelegateCommand DeletePointCommand =>
  277. _DeletePointCommand ?? (_DeletePointCommand = new DelegateCommand(ExecuteDeletePointCommand, CanExecuteDeletePointCommand).ObservesProperty(()=>SelectedPointInDataGrid));
  278. private DelegateCommand _MovePointUpCommand;
  279. public DelegateCommand MovePointUpCommand => _MovePointUpCommand ?? (_MovePointUpCommand = new DelegateCommand(ExecuteMovePointUpCommand, CanMovePointUp));
  280. private DelegateCommand _MovePointDownCommand;
  281. public DelegateCommand MovePointDownCommand => _MovePointDownCommand ?? (_MovePointDownCommand = new DelegateCommand(ExecuteMovePointDownCommand, CanMovePointDown));
  282. private DelegateCommand _ImportCadPointCommand;
  283. public DelegateCommand ImportCadPointCommand =>
  284. _ImportCadPointCommand ?? (_ImportCadPointCommand = new DelegateCommand(ExecuteImportCadPointCommand));
  285. private DelegateCommand _ImportCadLockCameraPointCommand;
  286. public DelegateCommand ImportCadLockCameraPointCommand =>
  287. _ImportCadLockCameraPointCommand ?? (_ImportCadLockCameraPointCommand = new DelegateCommand(ExecuteImportCadLockCameraPointCommand));
  288. private DelegateCommand _ApplyLockPointStartZCommand;
  289. public DelegateCommand ApplyLockPointStartZCommand =>
  290. _ApplyLockPointStartZCommand ?? (_ApplyLockPointStartZCommand = new DelegateCommand(ExecuteApplyLockPointStartZCommand));
  291. private DelegateCommand _ApplyLockPointDepthCommand;
  292. public DelegateCommand ApplyLockPointDepthCommand =>
  293. _ApplyLockPointDepthCommand ?? (_ApplyLockPointDepthCommand = new DelegateCommand(ExecuteApplyLockPointDepthCommand));
  294. private DelegateCommand _ApplyLockPointSpeedCommand;
  295. public DelegateCommand ApplyLockPointSpeedCommand =>
  296. _ApplyLockPointSpeedCommand ?? (_ApplyLockPointSpeedCommand = new DelegateCommand(ExecuteApplyLockPointSpeedCommand));
  297. private DelegateCommand _ApplyLockPointFeederAndScrewProgramCommand;
  298. public DelegateCommand ApplyLockPointFeederAndScrewProgramCommand =>
  299. _ApplyLockPointFeederAndScrewProgramCommand ?? (_ApplyLockPointFeederAndScrewProgramCommand = new DelegateCommand(ExecuteApplyLockPointFeederAndScrewProgramCommand));
  300. private DelegateCommand _AutoCorrectLockPoint;
  301. public DelegateCommand AutoCorrectLockPoint =>
  302. _AutoCorrectLockPoint ?? (_AutoCorrectLockPoint = new DelegateCommand(ExecuteAutoCorrectLockPoint));
  303. #endregion
  304. #region 事件
  305. #endregion
  306. public PlcPointParamsViewModel(IRegionManager regionManager, IEventAggregator ea, IContainerProvider container, IDialogService dialogService,
  307. IConfigService configService, IRobotService robotService, ISystemDatabaseService systemDatabaseService, IRemoteCommandService remoteCommandService)
  308. {
  309. _regionManager = regionManager;
  310. _eventAggregator = ea;
  311. _container = container;
  312. _dialogService = dialogService;
  313. _configService = configService;
  314. _systemDatabaseService = systemDatabaseService;
  315. //订阅权限登录事件
  316. _eventAggregator.GetEvent<UserLoginNotification>().Subscribe(LoginChange);
  317. management = _container.Resolve<Management>();
  318. _robotService = robotService;
  319. _remoteCommandService = remoteCommandService;
  320. }
  321. #region 方法
  322. /// <summary>
  323. /// 下一步
  324. /// </summary>
  325. void ExecuteNextCommand()
  326. {
  327. NavigationParameters param = new NavigationParameters();
  328. param.Add("SelectProduct", SelectProduct);
  329. _regionManager.RequestNavigate("ProductRegionContext", "ProductParams", param);
  330. }
  331. /// <summary>
  332. /// 上一步
  333. /// </summary>
  334. void ExecuteBackCommand()
  335. {
  336. NavigationParameters param = new NavigationParameters();
  337. param.Add("SelectProduct", SelectProduct);
  338. param.Add("SelectedProcedure", null);
  339. _regionManager.RequestNavigate("ProductRegionContext", "ProcessBasics", param);
  340. }
  341. /// <summary>
  342. /// 点动
  343. /// </summary>
  344. /// <param name="obj"></param>
  345. private async void ExecuteJogCommand(object obj)
  346. {
  347. if (Robot == null || !Robot.IsConnected) return;
  348. try
  349. {
  350. Robot.Timeout = 6000000;
  351. var items = ((string)obj).Split(':');
  352. switch (items[0])
  353. {
  354. case "X+":
  355. await Robot.JogAsync("X", double.Parse(items[1]));
  356. break;
  357. case "X-":
  358. await Robot.JogAsync("X", -double.Parse(items[1]));
  359. break;
  360. case "Y+":
  361. await Robot.JogAsync("Y", double.Parse(items[1]));
  362. break;
  363. case "Y-":
  364. await Robot.JogAsync("Y", -double.Parse(items[1]));
  365. break;
  366. case "Z+":
  367. await Robot.JogAsync("Z", double.Parse(items[1]));
  368. break;
  369. case "Z-":
  370. await Robot.JogAsync("Z", -double.Parse(items[1]));
  371. break;
  372. case "U+":
  373. await Robot.JogAsync("U", double.Parse(items[1]));
  374. break;
  375. case "U-":
  376. await Robot.JogAsync("U", -double.Parse(items[1]));
  377. break;
  378. case "V+":
  379. await Robot.JogAsync("V", double.Parse(items[1]));
  380. break;
  381. case "V-":
  382. await Robot.JogAsync("V", -double.Parse(items[1]));
  383. break;
  384. case "W+":
  385. await Robot.JogAsync("W", double.Parse(items[1]));
  386. break;
  387. case "W-":
  388. await Robot.JogAsync("W", -double.Parse(items[1]));
  389. break;
  390. default:
  391. break;
  392. }
  393. Robot.Timeout = 5000;
  394. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = $"{Lang.完成}!", Duration = 0.4 });
  395. }
  396. catch (Exception ex)
  397. {
  398. LogHelper.WriteLogError("机器人点位-机器人点动时出错", ex);
  399. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
  400. }
  401. }
  402. /// <summary>
  403. /// 执行运动
  404. /// </summary>
  405. /// <param name="obj"></param>
  406. async void ExecuteExecuteMotion(object parameter)
  407. {
  408. if (parameter == null)
  409. {
  410. return;
  411. }
  412. if (SelectedPoint==null)
  413. {
  414. return;
  415. }
  416. var values = (object[])parameter;
  417. var point = new RPoint()
  418. {
  419. X= SelectedPoint.X_Position,
  420. Y= SelectedPoint.Y_Position,
  421. Z= SelectedPoint.Z_Position_Start,
  422. U=SelectedPoint.U_Position,
  423. V= SelectedPoint.R_Position,
  424. };
  425. MotionCommand motionCmd = (MotionCommand)values[1];
  426. if (Robot == null || !Robot.IsConnected) return;
  427. try
  428. {
  429. Robot.Timeout = 6000000;
  430. switch (motionCmd)
  431. {
  432. case MotionCommand.Go:
  433. await Robot.GoAsync(point);
  434. break;
  435. case MotionCommand.Jump:
  436. await Robot.JumpAsync(point, 0);
  437. break;
  438. case MotionCommand.Move:
  439. await Robot.MoveAsync(point);
  440. break;
  441. }
  442. Robot.Timeout = 5000;
  443. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = $"{Lang.完成}!", Duration = 0.4 });
  444. }
  445. catch (Exception ex)
  446. {
  447. LogHelper.WriteLogError("机器人点位-执行点位时出错", ex);
  448. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
  449. }
  450. }
  451. /// <summary>
  452. /// 示教点位
  453. /// </summary>
  454. /// <param name="point"></param>
  455. async void ExecuteTechPointCommand()
  456. {
  457. if (Robot == null || !Robot.IsConnected) return;
  458. if (SelectedPoint == null) return;
  459. try
  460. {
  461. var curpos = await Robot.GetRobotPosAsync();
  462. SelectedPoint.X_Position = curpos.X;
  463. SelectedPoint.Y_Position = curpos.Y;
  464. SelectedPoint.Z_Position_Start = curpos.Z;
  465. SelectedPoint.U_Position = curpos.U;
  466. SelectedPoint.R_Position = curpos.V;
  467. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = $"{Lang.完成}!", Duration = 0.4 });
  468. }
  469. catch (Exception ex)
  470. {
  471. LogHelper.WriteLogError("机器人点位-示教点位时出错", ex);
  472. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
  473. }
  474. }
  475. void ExecuteLoadedCommand()
  476. {
  477. if (_systemDatabaseService.GetCurrentUser().userPart == Enums.UserPart.Operator)
  478. {
  479. IsAllowEdit = false;
  480. }
  481. else
  482. {
  483. IsAllowEdit = true;
  484. }
  485. }
  486. /// <summary>
  487. /// 电机
  488. /// </summary>
  489. /// <param name="obj"></param>
  490. private async void ExecuteMotorCommand(string obj)
  491. {
  492. if (Robot == null || !Robot.IsConnected) return;
  493. try
  494. {
  495. await Robot.MotorAsync(Convert.ToBoolean(obj));
  496. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = $"{Lang.完成}!", Duration = 0.4 });
  497. }
  498. catch (Exception ex)
  499. {
  500. LogHelper.WriteLogError("机器人点击操作时出错!", ex);
  501. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
  502. }
  503. }
  504. /// <summary>
  505. /// 重置
  506. /// </summary>
  507. private async void ExecuteResetCommand()
  508. {
  509. if (Robot == null || !Robot.IsConnected) return;
  510. try
  511. {
  512. await Robot.ResetAsync();
  513. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = $"{Lang.完成}!", Duration = 0.4 });
  514. }
  515. catch (Exception ex)
  516. {
  517. LogHelper.WriteLogError("重置机器人时出错!", ex);
  518. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
  519. }
  520. }
  521. /// <summary>
  522. /// 锁定刹车
  523. /// </summary>
  524. private async void ExecuteSLockCommand()
  525. {
  526. if (Robot == null || !Robot.IsConnected) return;
  527. try
  528. {
  529. await Robot.SLockAsync();
  530. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = $"{Lang.完成}!", Duration = 0.4 });
  531. }
  532. catch (Exception ex)
  533. {
  534. LogHelper.WriteLogError("机器人锁定刹车时出错!", ex);
  535. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
  536. }
  537. }
  538. /// <summary>
  539. /// 释放刹车
  540. /// </summary>
  541. private async void ExecutesFreeCommand()
  542. {
  543. if (Robot == null || !Robot.IsConnected) return;
  544. try
  545. {
  546. await Robot.SFreeAsync();
  547. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = $"{Lang.完成}!", Duration = 0.4 });
  548. }
  549. catch (Exception ex)
  550. {
  551. LogHelper.WriteLogError("机器人释放刹车时出错!", ex);
  552. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
  553. }
  554. }
  555. private bool CanExecute
  556. {
  557. get
  558. {
  559. // 命令可执行仅当机器人可执行且已选择点位
  560. if (Robot != null && Robot.IsConnected && Robot.CanExecute)
  561. {
  562. return true;
  563. }
  564. return false;
  565. }
  566. }
  567. //是否可以示教或者执行点位
  568. private bool CanExecutePointCommand
  569. {
  570. get
  571. {
  572. if (Robot != null && Robot.IsConnected && Robot.CanExecute)
  573. {
  574. return SelectedPointInDataGrid != null;
  575. }
  576. return false;
  577. }
  578. }
  579. /// <summary>
  580. /// 点位表切换时
  581. /// </summary>
  582. void ExecuteSelectionChangedCommand()
  583. {
  584. switch (SelectedIndex)
  585. {
  586. case 0:
  587. Points = SelectProduct.PickCameraPoints;
  588. PickPoints= SelectProduct.PickPoints;
  589. break;
  590. case 1:
  591. Points = SelectProduct.PickPoints;
  592. break;
  593. case 2:
  594. Points = SelectProduct.SecPosCameraPoints;
  595. break;
  596. case 3:
  597. Points = SelectProduct.ScrewCameraPoints;
  598. break;
  599. case 4:
  600. Points = SelectProduct.ScrewPoints;
  601. break;
  602. case 5:
  603. Points = SelectProduct.CheckCameraPoints;
  604. break;
  605. default:
  606. break;
  607. }
  608. }
  609. /// <summary>
  610. /// 增加点位
  611. /// </summary>
  612. void ExecuteAddPointCommand()
  613. {
  614. //添加点位
  615. Points.Add(new PlcPoint()
  616. {
  617. Number = Points.Count + 1,
  618. X_Velocity = 100,
  619. Y_Velocity = 100,
  620. Z_Velocity_Start = 100,
  621. Z_Velocity_Stop = 100,
  622. U_Velocity = 100,
  623. R_Velocity = 100,
  624. });
  625. // update commands
  626. _MovePointUpCommand?.RaiseCanExecuteChanged();
  627. _MovePointDownCommand?.RaiseCanExecuteChanged();
  628. }
  629. /// <summary>
  630. /// 移除点位
  631. /// </summary>
  632. void ExecuteDeletePointCommand()
  633. {
  634. if (SelectedPoint == null)
  635. {
  636. return;
  637. }
  638. // 确认删除
  639. if (MessageBox.Show("确认要删除选中的点位吗?", "删除点位", MessageBoxButton.YesNo, MessageBoxImage.Question) != MessageBoxResult.Yes)
  640. {
  641. return;
  642. }
  643. int removedIndex = Points.IndexOf(SelectedPoint);
  644. Points.Remove(SelectedPoint);
  645. //重新编号
  646. for (int i = 0; i < Points.Count; i++)
  647. {
  648. Points[i].Number = i + 1;
  649. }
  650. // adjust selection
  651. if (Points.Count > 0)
  652. {
  653. int newIndex = Math.Min(removedIndex, Points.Count - 1);
  654. SelectedPointInDataGrid = Points[newIndex];
  655. }
  656. else
  657. {
  658. SelectedPointInDataGrid = null;
  659. }
  660. // update commands
  661. _MovePointUpCommand?.RaiseCanExecuteChanged();
  662. _MovePointDownCommand?.RaiseCanExecuteChanged();
  663. }
  664. bool CanExecuteDeletePointCommand()
  665. {
  666. return SelectedPointInDataGrid != null;
  667. }
  668. private bool CanMovePointUp()
  669. {
  670. return SelectedPointInDataGrid != null && Points.IndexOf(SelectedPointInDataGrid) > 0;
  671. }
  672. private bool CanMovePointDown()
  673. {
  674. return SelectedPointInDataGrid != null && Points.IndexOf(SelectedPointInDataGrid) >= 0 && Points.IndexOf(SelectedPointInDataGrid) < Points.Count - 1;
  675. }
  676. /// <summary>
  677. /// 向上移动点位
  678. /// </summary>
  679. void ExecuteMovePointUpCommand()
  680. {
  681. if (SelectedPointInDataGrid == null) return;
  682. // 确认移动
  683. if (MessageBox.Show("确认将选中点位上移一位吗?", "移动点位", MessageBoxButton.YesNo, MessageBoxImage.Question) != MessageBoxResult.Yes)
  684. {
  685. return;
  686. }
  687. int idx = Points.IndexOf(SelectedPointInDataGrid);
  688. if (idx <= 0) return;
  689. var item = SelectedPointInDataGrid;
  690. Points.Move(idx, idx - 1);
  691. // renumber
  692. for (int i = 0; i < Points.Count; i++) Points[i].Number = i + 1;
  693. SelectedPointInDataGrid = item;
  694. _MovePointUpCommand?.RaiseCanExecuteChanged();
  695. _MovePointDownCommand?.RaiseCanExecuteChanged();
  696. }
  697. /// <summary>
  698. /// 向下移动点位
  699. /// </summary>
  700. void ExecuteMovePointDownCommand()
  701. {
  702. if (SelectedPointInDataGrid == null) return;
  703. // 确认移动
  704. if (MessageBox.Show("确认将选中点位下移一位吗?", "移动点位", MessageBoxButton.YesNo, MessageBoxImage.Question) != MessageBoxResult.Yes)
  705. {
  706. return;
  707. }
  708. int idx = Points.IndexOf(SelectedPointInDataGrid);
  709. if (idx < 0 || idx >= Points.Count - 1) return;
  710. var item = SelectedPointInDataGrid;
  711. Points.Move(idx, idx + 1);
  712. // renumber
  713. for (int i = 0; i < Points.Count; i++) Points[i].Number = i + 1;
  714. SelectedPointInDataGrid = item;
  715. _MovePointUpCommand?.RaiseCanExecuteChanged();
  716. _MovePointDownCommand?.RaiseCanExecuteChanged();
  717. }
  718. /// <summary>
  719. /// CAD导入点位
  720. /// </summary>
  721. async void ExecuteImportCadPointCommand()
  722. {
  723. try
  724. {
  725. var view = new DxfView();
  726. //show the dialog
  727. var result = await DialogHost.Show(view, "RootDialog", null, null, null);
  728. if (result != null)
  729. {
  730. var cadPoints = view.Points;
  731. if (cadPoints != null && cadPoints.Count > 0)
  732. {
  733. //要导入的开始点编号
  734. int startNumber = view.StartIndex;
  735. //弹窗提示用户是否确认要导入从该编号开始的点位,点位数量为cadPoints.Count
  736. if (MessageBox.Show($"确认要从点位编号 {startNumber} 开始导入 {cadPoints.Count} 个点位吗?", "导入点位", MessageBoxButton.YesNo, MessageBoxImage.Question) != MessageBoxResult.Yes)
  737. {
  738. return;
  739. }
  740. //导入点位
  741. for (int i = 0; i < cadPoints.Count; i++)
  742. {
  743. //如果点位编号已存在,则更新该点位,否则新增点位,只更新XY坐标
  744. var point = cadPoints[i];
  745. var existingPoint = Points.FirstOrDefault(p => p.Number == startNumber + i);
  746. if (existingPoint != null)
  747. {
  748. existingPoint.X_Position = point.X;
  749. existingPoint.Y_Position = point.Y;
  750. }
  751. else
  752. {
  753. Points.Add(new PlcPoint()
  754. {
  755. Number = startNumber + i,
  756. X_Position = point.X,
  757. Y_Position = point.Y,
  758. X_Velocity=100,
  759. Y_Velocity=100,
  760. Z_Velocity_Start=100,
  761. Z_Velocity_Stop=100,
  762. U_Velocity=100,
  763. R_Velocity=100,
  764. });
  765. }
  766. }
  767. //对所有的点位重新编号,确保编号连续
  768. var sortedPoints = Points.OrderBy(p => p.Number).ToList();
  769. Points.Clear();
  770. for (int i = 0; i < sortedPoints.Count; i++)
  771. {
  772. sortedPoints[i].Number = i + 1;
  773. Points.Add(sortedPoints[i]);
  774. }
  775. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = $"{Lang.完成}!", Duration = 0.4 });
  776. }
  777. }
  778. }
  779. catch (Exception ex)
  780. {
  781. LogHelper.WriteLogError("导入CAD点位时出错!", ex);
  782. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
  783. }
  784. }
  785. /// <summary>
  786. /// 导入锁付拍照引导的产品坐标系中的点位
  787. /// </summary>
  788. async void ExecuteImportCadLockCameraPointCommand()
  789. {
  790. try
  791. {
  792. var view = new DxfView();
  793. //show the dialog
  794. var result = await DialogHost.Show(view, "RootDialog", null, null, null);
  795. if (result != null)
  796. {
  797. var cadPoints = view.Points;
  798. if (cadPoints != null && cadPoints.Count == 2)
  799. {
  800. //弹窗提示用户是否确认要导入锁付拍照引导的起始点和结束点
  801. if (MessageBox.Show($"确认要导入锁付拍照引导的起始点和结束点吗?", "导入点位", MessageBoxButton.YesNo, MessageBoxImage.Question) != MessageBoxResult.Yes)
  802. {
  803. return;
  804. }
  805. //导入点位
  806. //起始点
  807. var startPoint = cadPoints[0];
  808. SelectProduct.ScrewCameraLocalPos1.X_Position = startPoint.X;
  809. SelectProduct.ScrewCameraLocalPos1.Y_Position = startPoint.Y;
  810. //结束点
  811. var endPoint = cadPoints[1];
  812. SelectProduct.ScrewCameraLocalPos2.X_Position = endPoint.X;
  813. SelectProduct.ScrewCameraLocalPos2.Y_Position = endPoint.Y;
  814. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = $"{Lang.完成}!", Duration = 0.4 });
  815. }
  816. else
  817. {
  818. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = "请导入两个点,分别为锁付拍照引导的起始点和结束点!", Duration = 1 });
  819. }
  820. }
  821. }
  822. catch (Exception ex)
  823. {
  824. LogHelper.WriteLogError("导入CAD点位时出错!", ex);
  825. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
  826. }
  827. }
  828. /// <summary>
  829. /// 批量设置锁付点的供料器编号和螺丝程序编号
  830. /// </summary>
  831. void ExecuteApplyLockPointFeederAndScrewProgramCommand()
  832. {
  833. //检查供料器编号和螺丝程序编号是否大于0,如果小于等于0,则提示用户编号是否正确,是否继续写入
  834. if (LockFeederNumber <= 0 || LockScrewProgramNumber <= 0)
  835. {
  836. var result = MessageBox.Show("供料器编号或螺丝程序编号小于等于0,是否继续写入?", "确认", MessageBoxButton.YesNo, MessageBoxImage.Question);
  837. if (result != MessageBoxResult.Yes)
  838. {
  839. return;
  840. }
  841. }
  842. //遍历所有点位,设置供料器编号和螺丝程序编号
  843. foreach (var point in Points)
  844. {
  845. point.Feeder = LockFeederNumber;
  846. point.ScrewProNum = LockScrewProgramNumber;
  847. }
  848. }
  849. /// <summary>
  850. /// 批量设置锁付点的速度
  851. /// </summary>
  852. void ExecuteApplyLockPointSpeedCommand()
  853. {
  854. //检查速度是否大于0,如果小于等于0,则提示用户速度是否正确,是否继续写入
  855. if (LockXSpeed <= 0 || LockYSpeed <= 0 || LockZSpeed <= 0 || LockZDescendSpeed <= 0)
  856. {
  857. var result = MessageBox.Show("速度小于等于0,是否继续写入?", "确认", MessageBoxButton.YesNo, MessageBoxImage.Question);
  858. if (result != MessageBoxResult.Yes)
  859. {
  860. return;
  861. }
  862. }
  863. //遍历所有点位,设置速度
  864. foreach (var point in Points)
  865. {
  866. point.X_Velocity = LockXSpeed;
  867. point.Y_Velocity = LockYSpeed;
  868. point.Z_Velocity_Start = LockZSpeed;
  869. point.Z_Velocity_Stop = LockZDescendSpeed;
  870. }
  871. }
  872. /// <summary>
  873. /// 批量设置锁付点的Z深度
  874. /// </summary>
  875. void ExecuteApplyLockPointDepthCommand()
  876. {
  877. //检查深度是否大于0,如果小于等于0,则提示用户深度是否正确,是否继续写入
  878. if (LockZDepth <= 0)
  879. {
  880. var result = MessageBox.Show("深度小于等于0,是否继续写入?", "确认", MessageBoxButton.YesNo, MessageBoxImage.Question);
  881. if (result != MessageBoxResult.Yes)
  882. {
  883. return;
  884. }
  885. }
  886. //遍历所有点位,设置Z深度
  887. foreach (var point in Points)
  888. {
  889. point.Z_Position_Stop = point.Z_Position_Start - LockZDepth;
  890. }
  891. }
  892. /// <summary>
  893. /// 批量设置锁付点的起始Z坐标
  894. /// </summary>
  895. void ExecuteApplyLockPointStartZCommand()
  896. {
  897. //检查起始Z坐标是否小于0,如果大于等于0,则提示用户坐标是否正确,是否继续写入
  898. if (LockPointStartZ >= 0)
  899. {
  900. var result = MessageBox.Show("起始Z坐标大于等于0,是否继续写入?", "确认", MessageBoxButton.YesNo, MessageBoxImage.Question);
  901. if (result != MessageBoxResult.Yes)
  902. {
  903. return;
  904. }
  905. }
  906. //遍历所有点位,设置起始Z坐标
  907. foreach (var point in Points)
  908. {
  909. point.Z_Position_Start = LockPointStartZ;
  910. }
  911. //检查终点坐标是否小于等于起始坐标,如果不是,则提示用户终点坐标大于等于起始坐标,用户需要去调整终点坐标
  912. foreach (var point in Points)
  913. {
  914. if (point.Z_Position_Stop >= point.Z_Position_Start)
  915. {
  916. MessageBox.Show($"点位编号 {point.Number} 的终点坐标大于等于起始坐标,请调整终点坐标!", "警告", MessageBoxButton.OK, MessageBoxImage.Warning);
  917. }
  918. }
  919. }
  920. /// <summary>
  921. /// 通过相机自动矫正锁附点位
  922. /// </summary>
  923. async void ExecuteAutoCorrectLockPoint()
  924. {
  925. try
  926. {
  927. //弹窗提示用户是否确认要通过相机自动矫正锁附点位
  928. var resultConfirm = MessageBox.Show("确认要通过相机自动矫正锁附点位吗?", "确认", MessageBoxButton.YesNo, MessageBoxImage.Question);
  929. if (resultConfirm != MessageBoxResult.Yes)
  930. {
  931. return;
  932. }
  933. var view = new AutoCorrectLockPoint();
  934. var vm = view.DataContext as AutoCorrectLockPointViewModel;
  935. vm.Robot = Robot;
  936. vm.AllScrewPoint = new List<PlcPoint>(Points.ToArray());
  937. //show the dialog
  938. var result = await DialogHost.Show(view, "RootDialog", null, null, null);
  939. if (result != null)
  940. {
  941. }
  942. }
  943. catch (Exception ex)
  944. {
  945. LogHelper.WriteLogError("通过相机自动矫正锁附点位时出错!", ex);
  946. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
  947. }
  948. }
  949. #endregion
  950. #region 继承
  951. /// <summary>
  952. /// 确认导航请求时调用。此方法允许您在导航之前执行一些操作。
  953. /// </summary>
  954. /// <param name="navigationContext"></param>
  955. /// <param name="continuationCallback"></param>
  956. public void ConfirmNavigationRequest(NavigationContext navigationContext, Action<bool> continuationCallback)
  957. {
  958. continuationCallback(true);
  959. }
  960. /// <summary>
  961. /// 接收导航请求时调用。传入导航参数,包含有关导航目标的信息。
  962. /// </summary>
  963. /// <param name="navigationContext"></param>
  964. /// <exception cref="NotImplementedException"></exception>
  965. public async void OnNavigatedTo(NavigationContext navigationContext)
  966. {
  967. try
  968. {
  969. SelectProduct = navigationContext.Parameters.GetValue<ProductModel>("SelectProduct");
  970. SelectedIndex = 0;
  971. PickPoints = SelectProduct.PickPoints;
  972. Points = SelectProduct.PickCameraPoints;
  973. if (Robot == null)
  974. {
  975. Robot = _robotService.GetRobotByNumber(1);
  976. }
  977. if (Robot != null && Robot.IsConnected)
  978. {
  979. this.Distance = _configService.GetRobotStepDistance(Robot.Id);
  980. Robot.EnterDebugMode = true;
  981. }
  982. else if (Robot != null)
  983. {
  984. Robot.EnterDebugMode = true;
  985. }
  986. ProcedureModels = new ObservableCollection<ProcedureModel>();
  987. foreach (var item in SelectProduct.CameraProcedures)
  988. {
  989. foreach (var item1 in item.ProcedureModels)
  990. {
  991. ProcedureModels.Add(item1);
  992. }
  993. }
  994. //对锁付点的批量设置进行初始化
  995. LockPointStartZ = SelectProduct.ScrewPoints.FirstOrDefault()?.Z_Position_Start ?? 0;
  996. LockZDepth= SelectProduct.ScrewPoints.FirstOrDefault() != null ? (SelectProduct.ScrewPoints.FirstOrDefault().Z_Position_Start - SelectProduct.ScrewPoints.FirstOrDefault().Z_Position_Stop) : 0;
  997. LockXSpeed= SelectProduct.ScrewPoints.FirstOrDefault()?.X_Velocity ?? 100;
  998. LockYSpeed= SelectProduct.ScrewPoints.FirstOrDefault()?.Y_Velocity ?? 100;
  999. LockZSpeed= SelectProduct.ScrewPoints.FirstOrDefault()?.Z_Velocity_Start ?? 100;
  1000. LockZDescendSpeed= SelectProduct.ScrewPoints.FirstOrDefault()?.Z_Velocity_Stop ?? 100;
  1001. LockFeederNumber= SelectProduct.ScrewPoints.FirstOrDefault()?.Feeder ?? 1;
  1002. LockScrewProgramNumber= SelectProduct.ScrewPoints.FirstOrDefault()?.ScrewProNum ?? 1;
  1003. }
  1004. catch (Exception ex)
  1005. {
  1006. LogHelper.WriteLogError("机器人点位界面进入时出错!", ex);
  1007. }
  1008. }
  1009. /// <summary>
  1010. /// 是否允许导航到此视图模型。
  1011. /// </summary>
  1012. /// <param name="navigationContext"></param>
  1013. /// <returns></returns>
  1014. public bool IsNavigationTarget(NavigationContext navigationContext)
  1015. {
  1016. return true;
  1017. }
  1018. /// <summary>
  1019. /// 导航离开此视图模型时调用。您可以在此处执行清理操作或保存状态。
  1020. /// </summary>
  1021. /// <param name="navigationContext"></param>
  1022. public void OnNavigatedFrom(NavigationContext navigationContext)
  1023. {
  1024. //if (Robot != null)
  1025. //{
  1026. // Robot.EnterDebugMode = false;
  1027. //}
  1028. }
  1029. #endregion
  1030. #region 取料拍照点位矫正
  1031. private PlcPoint _SelectedCameraForPickPoint;
  1032. public PlcPoint SelectedCameraForPickPoint
  1033. {
  1034. get { return _SelectedCameraForPickPoint; }
  1035. set { SetProperty(ref _SelectedCameraForPickPoint, value); }
  1036. }
  1037. private ObservableCollection<PlcPoint> _PickPoints = new ObservableCollection<PlcPoint>();
  1038. /// <summary>
  1039. /// 取料点位集合
  1040. /// </summary>
  1041. public ObservableCollection<PlcPoint> PickPoints
  1042. {
  1043. get { return _PickPoints; }
  1044. set { SetProperty(ref _PickPoints, value); }
  1045. }
  1046. //
  1047. private PlcPoint _SelectedPickPoint;
  1048. /// <summary>
  1049. /// 选中的取料点位
  1050. /// </summary>
  1051. public PlcPoint SelectedPickPoint
  1052. {
  1053. get { return _SelectedPickPoint; }
  1054. set { SetProperty(ref _SelectedPickPoint, value); }
  1055. }
  1056. private DelegateCommand _AutoCorrectPickPointCommand;
  1057. public DelegateCommand AutoCorrectPickPointCommand =>
  1058. _AutoCorrectPickPointCommand ?? (_AutoCorrectPickPointCommand = new DelegateCommand(ExecuteAutoCorrectPickPointCommand, CanExecuteAutoCorrectPickPointCommand)
  1059. .ObservesProperty(()=> SelectedCameraForPickPoint).ObservesProperty(() => SelectedPickPoint).ObservesProperty(() => SelectProcedure).ObservesProperty(() => IsExecutingAutoCorrectPickPoint));
  1060. //
  1061. private bool _IsExecutingAutoCorrectPickPoint = false;
  1062. /// <summary>
  1063. /// 正在执行取料拍照点位矫正
  1064. /// </summary>
  1065. public bool IsExecutingAutoCorrectPickPoint
  1066. {
  1067. get { return _IsExecutingAutoCorrectPickPoint; }
  1068. set { SetProperty(ref _IsExecutingAutoCorrectPickPoint, value); }
  1069. }
  1070. async void ExecuteAutoCorrectPickPointCommand()
  1071. {
  1072. try
  1073. {
  1074. IsExecutingAutoCorrectPickPoint = true;
  1075. if (SelectedCameraForPickPoint == null || SelectedPickPoint == null || SelectProcedure == null)
  1076. {
  1077. return;
  1078. }
  1079. if (Robot == null || !Robot.IsConnected)
  1080. {
  1081. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = "机器人未连接,无法执行取料拍照点位矫正!", Duration = 1 });
  1082. return;
  1083. }
  1084. if (MessageBox.Show("确认要执行取料拍照点位矫正吗?", "取料拍照点位矫正", MessageBoxButton.YesNo, MessageBoxImage.Question) != MessageBoxResult.Yes)
  1085. {
  1086. return;
  1087. }
  1088. var waiting = new WaitingControl();
  1089. //show the dialog
  1090. var task = DialogHost.Show(waiting, "RootDialog", null, null, null);
  1091. // 1. 控制机器人移动至拍照点位
  1092. var rpoint = new RPoint()
  1093. {
  1094. X = SelectedCameraForPickPoint.X_Position,
  1095. Y = SelectedCameraForPickPoint.Y_Position,
  1096. Z = SelectedCameraForPickPoint.Z_Position_Start,
  1097. U = SelectedCameraForPickPoint.U_Position,
  1098. V = SelectedCameraForPickPoint.R_Position,
  1099. };
  1100. await Robot.CalibMotionAsync(rpoint, 0);
  1101. var _cts = new CancellationTokenSource();
  1102. // 2. 执行拍照并获取识别结果
  1103. var recognitionResult =await _remoteCommandService.ExecutePhotoGetSinglePoint(SelectProcedure, null, new double[] { rpoint.X, rpoint.Y, 0 }, _cts.Token);
  1104. if (!recognitionResult.IsSucceed)
  1105. {
  1106. if (DialogHost.IsDialogOpen("RootDialog"))
  1107. {
  1108. DialogHost.Close("RootDialog");
  1109. }
  1110. await task;
  1111. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = "取料拍照点位矫正失败,识别未成功!", Duration = 1 });
  1112. return;
  1113. }
  1114. // 3. 根据识别结果更新取料点位坐标
  1115. SelectedPickPoint.X_Position = (float)recognitionResult.X;
  1116. SelectedPickPoint.Y_Position = (float)recognitionResult.Y;
  1117. if (DialogHost.IsDialogOpen("RootDialog"))
  1118. {
  1119. DialogHost.Close("RootDialog");
  1120. }
  1121. await task;
  1122. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = "取料拍照点位矫正完成!", Duration = 0.4 });
  1123. }
  1124. catch (Exception ex)
  1125. {
  1126. LogHelper.WriteLogError("取料拍照点位矫正时出错!", ex);
  1127. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
  1128. }
  1129. finally
  1130. {
  1131. IsExecutingAutoCorrectPickPoint = false;
  1132. }
  1133. }
  1134. bool CanExecuteAutoCorrectPickPointCommand()
  1135. {
  1136. return SelectedCameraForPickPoint!=null && SelectedPickPoint!=null && SelectProcedure!=null && !IsExecutingAutoCorrectPickPoint;
  1137. }
  1138. #endregion
  1139. private bool _IsAllowEdit = false;
  1140. public bool IsAllowEdit
  1141. {
  1142. get { return _IsAllowEdit; }
  1143. set { SetProperty(ref _IsAllowEdit, value); }
  1144. }
  1145. private void LoginChange(Models.User user)
  1146. {
  1147. if (user.userPart == Enums.UserPart.Operator)
  1148. {
  1149. IsAllowEdit = false;
  1150. }
  1151. else
  1152. {
  1153. IsAllowEdit = true;
  1154. }
  1155. }
  1156. }
  1157. }