FixedUpCameraFindP0ViewModel.cs 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716
  1. using Cognex.VisionPro;
  2. using Cognex.VisionPro.ToolBlock;
  3. using MathNet.Numerics.LinearAlgebra;
  4. using Prism.Commands;
  5. using Prism.Events;
  6. using Prism.Ioc;
  7. using Prism.Mvvm;
  8. using Prism.Regions;
  9. using Prism.Services.Dialogs;
  10. using System;
  11. using System.Collections.Generic;
  12. using System.Collections.ObjectModel;
  13. using System.Drawing;
  14. using System.IO;
  15. using System.Linq;
  16. using System.Threading.Tasks;
  17. using System.Windows;
  18. using System.Windows.Shapes;
  19. using Team.FFFeederService.Interfaces;
  20. using TeamAAS_VP.Core;
  21. using TeamAAS_VP.Enums;
  22. using TeamAAS_VP.Events;
  23. using TeamAAS_VP.Interfaces;
  24. using TeamAAS_VP.Models;
  25. using TeamAAS_VP.Models.Calibration;
  26. using TeamAAS_VP.Resources.Languages;
  27. using TeamAAS_VP.Services;
  28. namespace TeamAAS_VP.ViewModels.Calibration
  29. {
  30. public class FixedUpCameraFindP0ViewModel : BindableBase, IConfirmNavigationRequest
  31. {
  32. IRegionManager _regionManager;
  33. IRegionNavigationService _regionNavigationService;
  34. IContainerProvider _container;
  35. IDialogService _dialogService;
  36. IEventAggregator _eventAggregator;
  37. IConfigService _configService;
  38. IRobotService _robotService;
  39. ICameraService _cameraService;
  40. IFeederService _feederService;
  41. ISystemDatabaseService _systemDatabaseService;
  42. ICalibrationService _calibrationServvice;
  43. #region 属性
  44. private CogToolBlockEditV2 _ToolBlockEdit;
  45. public CogToolBlockEditV2 ToolBlockEdit
  46. {
  47. get { return _ToolBlockEdit; }
  48. set { SetProperty(ref _ToolBlockEdit, value); }
  49. }
  50. private CalibrationInfo _SelectCalibration;
  51. public CalibrationInfo SelectCalibration
  52. {
  53. get { return _SelectCalibration; }
  54. set { SetProperty(ref _SelectCalibration, value); }
  55. }
  56. private IRobot _Robot;
  57. public IRobot Robot
  58. {
  59. get { return _Robot; }
  60. set { SetProperty(ref _Robot, value); }
  61. }
  62. private ICamera _Camera;
  63. public ICamera Camera
  64. {
  65. get { return _Camera; }
  66. set { SetProperty(ref _Camera, value); }
  67. }
  68. private float _ExposureTime;
  69. /// <summary>
  70. /// 相机曝光时间
  71. /// </summary>
  72. public float ExposureTime
  73. {
  74. get { return _ExposureTime; }
  75. set
  76. {
  77. SetProperty(ref _ExposureTime, value);
  78. if (Camera != null)
  79. {
  80. try
  81. {
  82. SelectCalibration.FixedUpCameraFindP0Info.ExposureTime = value;
  83. Camera.SetExposureTime(value);
  84. }
  85. catch (Exception)
  86. {
  87. }
  88. }
  89. }
  90. }
  91. private float _Gain;
  92. /// <summary>
  93. /// 相机增益
  94. /// </summary>
  95. public float Gain
  96. {
  97. get { return _Gain; }
  98. set
  99. {
  100. SetProperty(ref _Gain, value);
  101. if (Camera != null)
  102. {
  103. try
  104. {
  105. SelectCalibration.FixedUpCameraFindP0Info.Gain = value;
  106. Camera.SetGain(value);
  107. }
  108. catch (Exception)
  109. {
  110. }
  111. }
  112. }
  113. }
  114. private ObservableCollection<CameraInfo> _Cameras;
  115. public ObservableCollection<CameraInfo> Cameras
  116. {
  117. get { return _Cameras; }
  118. set { SetProperty(ref _Cameras, value); }
  119. }
  120. private CameraInfo _SelectCamera;
  121. public CameraInfo SelectCamera
  122. {
  123. get { return _SelectCamera; }
  124. set
  125. {
  126. SetProperty(ref _SelectCamera, value);
  127. if (value != null)
  128. {
  129. Camera = _cameraService.GetCamera(value.Id);
  130. SelectCalibration.FixedUpCameraFindP0Info.CameraId = value.Id;
  131. SelectCalibration.FixedUpCameraFindP0Info.CameraName = value.CameraName;
  132. }
  133. }
  134. }
  135. private ObservableCollection<CalibrationInfo> _CalibrationList;
  136. public ObservableCollection<CalibrationInfo> CalibrationList
  137. {
  138. get { return _CalibrationList; }
  139. set { SetProperty(ref _CalibrationList, value); }
  140. }
  141. private CalibrationInfo _SelectedCalibration;
  142. public CalibrationInfo SelectedCalibration
  143. {
  144. get { return _SelectedCalibration; }
  145. set
  146. {
  147. SetProperty(ref _SelectedCalibration, value);
  148. if (value != null)
  149. {
  150. SelectCalibration.FixedUpCameraFindP0Info.CalibrationId = value.Id;
  151. SelectCalibration.FixedUpCameraFindP0Info.CalibrationName = value.Name;
  152. }
  153. }
  154. }
  155. #endregion
  156. #region 命令
  157. private DelegateCommand _LoadedCommand;
  158. public DelegateCommand LoadedCommand =>
  159. _LoadedCommand ?? (_LoadedCommand = new DelegateCommand(ExecuteLoadedCommand));
  160. private DelegateCommand _NextCommand;
  161. public DelegateCommand NextCommand =>
  162. _NextCommand ?? (_NextCommand = new DelegateCommand(ExecuteNextCommand));
  163. private DelegateCommand _BackCommand;
  164. public DelegateCommand BackCommand =>
  165. _BackCommand ?? (_BackCommand = new DelegateCommand(ExecuteBackCommand));
  166. private DelegateCommand _RunVisionProcessCommand;
  167. public DelegateCommand RunVisionProcessCommand =>
  168. _RunVisionProcessCommand ?? (_RunVisionProcessCommand = new DelegateCommand(ExecuteRunVisionProcessCommand));
  169. private DelegateCommand _FindP0Command;
  170. public DelegateCommand FindP0Command =>
  171. _FindP0Command ?? (_FindP0Command = new DelegateCommand(ExecuteFindP0Command));
  172. private DelegateCommand _TeachPutPosCommand;
  173. public DelegateCommand TeachPutPosCommand =>
  174. _TeachPutPosCommand ?? (_TeachPutPosCommand = new DelegateCommand(ExecuteTeachPutPosCommand));
  175. private DelegateCommand _MovePutPosCommand;
  176. public DelegateCommand MovePutPosCommand =>
  177. _MovePutPosCommand ?? (_MovePutPosCommand = new DelegateCommand(ExecuteMovePutPosCommand));
  178. private DelegateCommand _TeachDownCameraPosCommand;
  179. public DelegateCommand TeachDownCameraPosCommand =>
  180. _TeachDownCameraPosCommand ?? (_TeachDownCameraPosCommand = new DelegateCommand(ExecuteTeachDownCameraPosCommand));
  181. private DelegateCommand _MoveDownCameraPosCommand;
  182. public DelegateCommand MoveDownCameraPosCommand =>
  183. _MoveDownCameraPosCommand ?? (_MoveDownCameraPosCommand = new DelegateCommand(ExecuteMoveDownCameraPosCommand));
  184. private DelegateCommand _StartCalibP0Command;
  185. public DelegateCommand StartCalibP0Command =>
  186. _StartCalibP0Command ?? (_StartCalibP0Command = new DelegateCommand(ExecuteStartCalibP0Command));
  187. #endregion
  188. #region 事件
  189. #endregion
  190. public FixedUpCameraFindP0ViewModel(IRegionManager regionManager, IEventAggregator ea, IRegionNavigationService regionNavigationService, IContainerProvider container, IDialogService dialogService,
  191. IConfigService configService, IRobotService robotService, ICameraService cameraService, IFeederService feederService, ISystemDatabaseService systemDatabaseService, ICalibrationService calibrationService)
  192. {
  193. _regionManager = regionManager;
  194. _regionNavigationService = regionNavigationService;
  195. _container = container;
  196. _dialogService = dialogService;
  197. _eventAggregator = ea;
  198. _configService = configService;
  199. _robotService = robotService;
  200. _cameraService = cameraService;
  201. _feederService = feederService;
  202. _systemDatabaseService = systemDatabaseService;
  203. _calibrationServvice = calibrationService;
  204. }
  205. #region 方法
  206. void ExecuteLoadedCommand()
  207. {
  208. try
  209. {
  210. if (_systemDatabaseService.GetCurrentUser().userPart == Enums.UserPart.Operator)
  211. {
  212. IsAllowEdit = false;
  213. }
  214. else
  215. {
  216. IsAllowEdit = true;
  217. }
  218. }
  219. catch (Exception ex)
  220. {
  221. LogHelper.WriteLogError("相机校准加载视觉工具处理界面时出错!", ex);
  222. MessageBox.Show(ex.Message);
  223. }
  224. }
  225. /// <summary>
  226. /// 下一步
  227. /// </summary>
  228. void ExecuteNextCommand()
  229. {
  230. try
  231. {
  232. string prcPath = FilePath.CalibrationPath + "//" + SelectCalibration.Name + "//" + "FixedUpCameraTool.vpp";
  233. if (!Directory.Exists(System.IO.Path.GetDirectoryName(prcPath)))
  234. {
  235. Directory.CreateDirectory(System.IO.Path.GetDirectoryName(prcPath));
  236. }
  237. VisionProFileHelper.SaveObjectToFileSafe(ToolBlockEdit.Subject, prcPath);
  238. NavigationParameters param = new NavigationParameters();
  239. param.Add("SelectCalibration", SelectCalibration);
  240. _regionManager.RequestNavigate("CalibrationRegionContext", "CalibrationAuto", param);
  241. }
  242. catch (Exception ex)
  243. {
  244. LogHelper.WriteLogError("相机校准-下相机示教P0界面点击下一步时出错!", ex);
  245. MessageBox.Show(ex.Message);
  246. }
  247. }
  248. /// <summary>
  249. /// 上一步
  250. /// </summary>
  251. void ExecuteBackCommand()
  252. {
  253. try
  254. {
  255. NavigationParameters param = new NavigationParameters();
  256. param.Add("SelectCalibration", SelectCalibration);
  257. _regionManager.RequestNavigate("CalibrationRegionContext", "CalibrationTeachCenterPoint", param);
  258. }
  259. catch (Exception ex)
  260. {
  261. LogHelper.WriteLogError("相机校准-下相机示教P0界面点击上一步时出错!", ex);
  262. MessageBox.Show(ex.Message);
  263. }
  264. }
  265. /// <summary>
  266. /// 运行视觉流程
  267. /// </summary>
  268. void ExecuteRunVisionProcessCommand()
  269. {
  270. try
  271. {
  272. if (Camera == null)
  273. {
  274. MessageBox.Show(Lang.请先选择相机);
  275. return;
  276. }
  277. ToolBlockEdit.Subject.Inputs["InputImage"].Value = Camera.Grab();
  278. ToolBlockEdit.Subject.Run();
  279. }
  280. catch (Exception ex)
  281. {
  282. LogHelper.WriteLogError("相机校准-运行流程时出错时出错", ex);
  283. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
  284. }
  285. }
  286. /// <summary>
  287. /// 自动计算P0点
  288. /// </summary>
  289. async void ExecuteFindP0Command()
  290. {
  291. if (Camera == null)
  292. {
  293. MessageBox.Show(Lang.请先选择相机);
  294. return;
  295. }
  296. if (SelectedCalibration == null)
  297. {
  298. MessageBox.Show(Lang.请先选择标定);
  299. return;
  300. }
  301. var result = await CaptureAndProcess(null);
  302. if (result.IsSuccess)
  303. {
  304. if (SelectCalibration.MarkPoint == null)
  305. {
  306. SelectCalibration.MarkPoint = new RPoint();
  307. }
  308. SelectCalibration.MarkPoint.X = (float)result.X;
  309. SelectCalibration.MarkPoint.Y = (float)result.Y;
  310. MessageBox.Show($"P0点计算成功!X:{result.X},Y:{result.Y}");
  311. }
  312. else
  313. {
  314. MessageBox.Show("未找到P0点,请调整工件位置后重试!");
  315. }
  316. }
  317. /// <summary>
  318. /// 通过下相机开始标定P0点
  319. /// </summary>
  320. async void ExecuteStartCalibP0Command()
  321. {
  322. //弹窗确认是否开始标定
  323. var result = MessageBox.Show(Lang.确认通过下相机开始标定P0点, Lang.提示, MessageBoxButton.YesNo, MessageBoxImage.Question);
  324. if (result != MessageBoxResult.Yes)
  325. {
  326. return;
  327. }
  328. try
  329. {
  330. // 1.移动至标定块放置位置,取标定块
  331. //移动机器人至下相机位置
  332. bool isSuccess = await Robot.CalibMotionAsync(SelectCalibration.PutPoint, null);
  333. if (!isSuccess)
  334. {
  335. MessageBox.Show(Lang.移动至移动至标定块放置位置取标定块失败);
  336. return;
  337. }
  338. //打开吸气
  339. Robot.CalibOutIO(true);
  340. await Task.Delay(300);
  341. // 2.移动至下相机位置,拍照,计算P0点
  342. isSuccess = await Robot.CalibMotionAsync(SelectCalibration.DownCameraPoint, null);
  343. if (!isSuccess)
  344. {
  345. MessageBox.Show(Lang.移动至下相机位置失败);
  346. return;
  347. }
  348. var calibResult = await CaptureAndProcess(new double[] { SelectCalibration.DownCameraPoint.X, SelectCalibration.DownCameraPoint.Y, SelectCalibration.DownCameraPoint.U });
  349. if (calibResult.IsSuccess)
  350. {
  351. //工具坐标
  352. double toolX = calibResult.X;
  353. double toolY = calibResult.Y;
  354. //创建工具坐标
  355. ToolCoord toolCoord = new ToolCoord();
  356. toolCoord.SetTool(toolX, toolY);
  357. Vector<double> P10 = Vector<double>.Build.Dense(new double[] { SelectCalibration.PutPoint.X, SelectCalibration.PutPoint.Y });
  358. var p0 = toolCoord.GetToolnCoord(P10, SelectCalibration.PutPoint.U);
  359. //计算P0点
  360. if (SelectCalibration.MarkPoint == null)
  361. {
  362. SelectCalibration.MarkPoint = new RPoint();
  363. }
  364. SelectCalibration.MarkPoint.X = (float)p0[0];
  365. SelectCalibration.MarkPoint.Y = (float)p0[1];
  366. //MessageBox.Show($"P0点计算成功!X:{calibResult.X},Y:{calibResult.Y}");
  367. }
  368. else
  369. {
  370. MessageBox.Show(Lang.未找到P0点请调整工件位置后重试);
  371. return;
  372. }
  373. // 3.移动至标定块放置位置,放下标定块
  374. isSuccess = await Robot.CalibMotionAsync(SelectCalibration.PutPoint, null);
  375. if (isSuccess)
  376. {
  377. //关闭吸气
  378. Robot.CalibOutIO(false);
  379. await Task.Delay(300);
  380. }
  381. else
  382. {
  383. MessageBox.Show(Lang.移动至标定块放置位置放下标定块失败);
  384. return;
  385. }
  386. // 4.Z轴上升安全高度
  387. RPoint safePoint = SelectCalibration.PutPoint.Clone();
  388. safePoint.Z = 0;
  389. isSuccess = await Robot.CalibMotionAsync(safePoint, null);
  390. if (!isSuccess)
  391. {
  392. MessageBox.Show(Lang.Z轴上升至安全高度失败);
  393. return;
  394. }
  395. //完成提示
  396. MessageBox.Show(Lang.通过下相机标定P0点完成);
  397. }
  398. catch (Exception ex)
  399. {
  400. LogHelper.WriteLogError("相机校准-通过下相机开始标定P0点时出错!", ex);
  401. MessageBox.Show(ex.Message);
  402. }
  403. }
  404. /// <summary>
  405. /// 移动至下相机位置
  406. /// </summary>
  407. async void ExecuteMoveDownCameraPosCommand()
  408. {
  409. try
  410. {
  411. //弹窗确认是否移动
  412. var result = MessageBox.Show(Lang.确认移动至下相机位置, Lang.提示, MessageBoxButton.YesNo, MessageBoxImage.Question);
  413. if (result != MessageBoxResult.Yes)
  414. {
  415. return;
  416. }
  417. //移动机器人至下相机位置
  418. bool isSuccess = await Robot.CalibMotionAsync(SelectCalibration.DownCameraPoint, null);
  419. if (isSuccess)
  420. {
  421. MessageBox.Show(Lang.移动至下相机位置成功);
  422. }
  423. else
  424. {
  425. MessageBox.Show(Lang.移动至下相机位置失败);
  426. }
  427. }
  428. catch (Exception ex)
  429. {
  430. MessageBox.Show(ex.Message);
  431. }
  432. }
  433. /// <summary>
  434. /// 示教下相机位置
  435. /// </summary>
  436. void ExecuteTeachDownCameraPosCommand()
  437. {
  438. try
  439. {
  440. //弹窗确认是否示教
  441. var result = MessageBox.Show(Lang.确认示教下相机位置, Lang.提示, MessageBoxButton.YesNo, MessageBoxImage.Question);
  442. if (result != MessageBoxResult.Yes)
  443. {
  444. return;
  445. }
  446. //获取机器人当前位置
  447. SelectCalibration.DownCameraPoint = Robot.GetRobotPos();
  448. MessageBox.Show(Lang.示教下相机位置成功);
  449. }
  450. catch (Exception ex)
  451. {
  452. MessageBox.Show(ex.Message);
  453. }
  454. }
  455. /// <summary>
  456. /// 移动至标定块放位置
  457. /// </summary>
  458. async void ExecuteMovePutPosCommand()
  459. {
  460. try
  461. {
  462. //弹窗确认是否移动
  463. var result = MessageBox.Show(Lang.确认移动至标定块放位置, Lang.提示, MessageBoxButton.YesNo, MessageBoxImage.Question);
  464. if (result != MessageBoxResult.Yes)
  465. {
  466. return;
  467. }
  468. //移动机器人至标定块放位置
  469. bool isSuccess = await Robot.CalibMotionAsync(SelectCalibration.PutPoint, null);
  470. if (isSuccess)
  471. {
  472. MessageBox.Show(Lang.移动至标定块放位置成功);
  473. }
  474. else
  475. {
  476. MessageBox.Show(Lang.移动至标定块放位置失败);
  477. }
  478. }
  479. catch (Exception ex)
  480. {
  481. MessageBox.Show(ex.Message);
  482. }
  483. }
  484. /// <summary>
  485. /// 示教标定块放位置
  486. /// </summary>
  487. void ExecuteTeachPutPosCommand()
  488. {
  489. try
  490. {
  491. //弹窗确认是否示教
  492. var result = MessageBox.Show(Lang.确认示教标定块放位置, Lang.提示, MessageBoxButton.YesNo, MessageBoxImage.Question);
  493. if (result != MessageBoxResult.Yes)
  494. {
  495. return;
  496. }
  497. //获取机器人当前位置
  498. SelectCalibration.PutPoint = Robot.GetRobotPos();
  499. MessageBox.Show(Lang.示教标定块放位置成功);
  500. }
  501. catch (Exception ex)
  502. {
  503. MessageBox.Show(ex.Message);
  504. }
  505. }
  506. /// <summary>
  507. /// 相机拍照
  508. /// </summary>
  509. /// <returns></returns>
  510. private async Task<(bool IsSuccess, double X, double Y, double U, int ImageWidth, int ImageHeight)> CaptureAndProcess(double[] robotCoord)
  511. {
  512. ICogImage image = null;
  513. //采集图像
  514. if (Camera != null)
  515. {
  516. image = Camera.Grab();
  517. if (SelectedCalibration.IsDistortionCorrection)
  518. {
  519. if (SelectedCalibration.CalibCheckerboardTool==null)
  520. {
  521. string prcPath = FilePath.CalibrationPath + "//" + SelectedCalibration.Name + "//" + "CalibCheckerboardTool.vpp";
  522. if (File.Exists(prcPath))
  523. {
  524. SelectedCalibration.CalibCheckerboardTool = VisionProFileHelper.LoadObjectFromFileSafe<Cognex.VisionPro.CalibFix.CogCalibCheckerboardTool>(prcPath);
  525. SelectedCalibration.CalibCheckerboardTool.InputImage = image;
  526. SelectedCalibration.CalibCheckerboardTool.Run();
  527. image = SelectedCalibration.CalibCheckerboardTool.OutputImage;
  528. }
  529. }
  530. }
  531. ToolBlockEdit.Subject.Inputs["InputImage"].Value = image;
  532. }
  533. ToolBlockEdit.Subject.Run();
  534. CogToolBlockTerminalCollection outputCollection = ToolBlockEdit.Subject.Outputs;
  535. bool Found = (bool)(outputCollection["Found"].Value);
  536. if (Found)
  537. {
  538. var strpoints = outputCollection["Point"].Value.ToString();
  539. string[] items = strpoints.Split(',');
  540. double x = double.Parse(items[0]);
  541. double y = double.Parse(items[1]);
  542. //校准转换
  543. var calibResult = _calibrationServvice.ConvertPixelToPosition((x, y, 0), robotCoord, SelectedCalibration, Robot.Brand);
  544. if (calibResult.IsSucceed)
  545. {
  546. x = calibResult.X;
  547. y = calibResult.Y;
  548. return (true, x, y, 0, image.Width, image.Height);
  549. }
  550. return (false, 0, 0, 0, image.Width, image.Height);
  551. }
  552. else
  553. {
  554. return (false, 0, 0, 0, image.Width, image.Height);
  555. }
  556. }
  557. #endregion
  558. #region 继承
  559. /// <summary>
  560. /// 确认导航请求时调用。此方法允许您在导航之前执行一些操作。
  561. /// </summary>
  562. /// <param name="navigationContext"></param>
  563. /// <param name="continuationCallback"></param>
  564. public void ConfirmNavigationRequest(NavigationContext navigationContext, Action<bool> continuationCallback)
  565. {
  566. continuationCallback(true);
  567. }
  568. /// <summary>
  569. /// 接收导航请求时调用。传入导航参数,包含有关导航目标的信息。
  570. /// </summary>
  571. /// <param name="navigationContext"></param>
  572. /// <exception cref="NotImplementedException"></exception>
  573. public async void OnNavigatedTo(NavigationContext navigationContext)
  574. {
  575. SelectCalibration = navigationContext.Parameters.GetValue<CalibrationInfo>("SelectCalibration");
  576. if (SelectCalibration.FixedUpCameraFindP0Info == null)
  577. {
  578. SelectCalibration.FixedUpCameraFindP0Info = new FixedUpCameraFindP0Info();
  579. }
  580. string prcPath = FilePath.CalibrationPath + "//" + SelectCalibration.Name + "//" + "FixedUpCameraTool.vpp";
  581. if (File.Exists(prcPath))
  582. {
  583. ToolBlockEdit.Subject = VisionProFileHelper.LoadObjectFromFileSafe<CogToolBlock>(prcPath);
  584. }
  585. else
  586. {
  587. ToolBlockEdit.Subject = VisionProFileHelper.LoadObjectFromFileSafe<CogToolBlock>(FilePath.CalibrationToolblockPath);
  588. }
  589. if (SelectCalibration.RobotId != Guid.Empty)
  590. {
  591. Robot = _robotService.GetRobot(SelectCalibration.RobotId);
  592. }
  593. Cameras = new ObservableCollection<CameraInfo>(_configService.GetAllCameras());
  594. if (SelectCalibration.FixedUpCameraFindP0Info.CameraId != Guid.Empty)
  595. {
  596. SelectCamera = Cameras.FirstOrDefault(c => c.Id == SelectCalibration.FixedUpCameraFindP0Info.CameraId);
  597. }
  598. CalibrationList = new ObservableCollection<CalibrationInfo>(_calibrationServvice.GetAllCalibrations());
  599. if (SelectCalibration.FixedUpCameraFindP0Info.CalibrationId != Guid.Empty)
  600. {
  601. SelectedCalibration = CalibrationList.FirstOrDefault(c => c.Id == SelectCalibration.FixedUpCameraFindP0Info.CalibrationId);
  602. }
  603. ExposureTime = SelectCalibration.FixedUpCameraFindP0Info.ExposureTime==0?5000: SelectCalibration.FixedUpCameraFindP0Info.ExposureTime;
  604. Gain = SelectCalibration.FixedUpCameraFindP0Info.Gain;
  605. }
  606. /// <summary>
  607. /// 是否允许导航到此视图模型。
  608. /// </summary>
  609. /// <param name="navigationContext"></param>
  610. /// <returns></returns>
  611. public bool IsNavigationTarget(NavigationContext navigationContext)
  612. {
  613. return true;
  614. }
  615. /// <summary>
  616. /// 导航离开此视图模型时调用。您可以在此处执行清理操作或保存状态。
  617. /// </summary>
  618. /// <param name="navigationContext"></param>
  619. public void OnNavigatedFrom(NavigationContext navigationContext)
  620. {
  621. }
  622. #endregion
  623. private bool _IsAllowEdit = false;
  624. public bool IsAllowEdit
  625. {
  626. get { return _IsAllowEdit; }
  627. set { SetProperty(ref _IsAllowEdit, value); }
  628. }
  629. private void LoginChange(Models.User user)
  630. {
  631. if (user.userPart == Enums.UserPart.Operator)
  632. {
  633. IsAllowEdit = false;
  634. }
  635. else
  636. {
  637. IsAllowEdit = true;
  638. }
  639. }
  640. }
  641. }