FixedUpCameraFindP0ViewModel.cs 25 KB

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