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. if (Camera != null)
  78. {
  79. try
  80. {
  81. SelectCalibration.FixedUpCameraFindP0Info.ExposureTime = value;
  82. Camera.SetExposureTime(value);
  83. }
  84. catch (Exception)
  85. {
  86. }
  87. }
  88. }
  89. }
  90. private float _Gain;
  91. /// <summary>
  92. /// 相机增益
  93. /// </summary>
  94. public float Gain
  95. {
  96. get { return _Gain; }
  97. set
  98. {
  99. SetProperty(ref _Gain, value);
  100. if (Camera != null)
  101. {
  102. try
  103. {
  104. SelectCalibration.FixedUpCameraFindP0Info.Gain = value;
  105. Camera.SetGain(value);
  106. }
  107. catch (Exception)
  108. {
  109. }
  110. }
  111. }
  112. }
  113. private ObservableCollection<CameraInfo> _Cameras;
  114. public ObservableCollection<CameraInfo> Cameras
  115. {
  116. get { return _Cameras; }
  117. set { SetProperty(ref _Cameras, value); }
  118. }
  119. private CameraInfo _SelectCamera;
  120. public CameraInfo SelectCamera
  121. {
  122. get { return _SelectCamera; }
  123. set
  124. {
  125. SetProperty(ref _SelectCamera, value);
  126. if (value != null)
  127. {
  128. Camera = _cameraService.GetCamera(value.Id);
  129. SelectCalibration.FixedUpCameraFindP0Info.CameraId = value.Id;
  130. SelectCalibration.FixedUpCameraFindP0Info.CameraName = value.CameraName;
  131. }
  132. }
  133. }
  134. private ObservableCollection<CalibrationInfo> _CalibrationList;
  135. public ObservableCollection<CalibrationInfo> CalibrationList
  136. {
  137. get { return _CalibrationList; }
  138. set { SetProperty(ref _CalibrationList, value); }
  139. }
  140. private CalibrationInfo _SelectedCalibration;
  141. public CalibrationInfo SelectedCalibration
  142. {
  143. get { return _SelectedCalibration; }
  144. set
  145. {
  146. SetProperty(ref _SelectedCalibration, value);
  147. if (value != null)
  148. {
  149. SelectCalibration.FixedUpCameraFindP0Info.CalibrationId = value.Id;
  150. SelectCalibration.FixedUpCameraFindP0Info.CalibrationName = value.Name;
  151. }
  152. }
  153. }
  154. #endregion
  155. #region 命令
  156. private DelegateCommand _LoadedCommand;
  157. public DelegateCommand LoadedCommand =>
  158. _LoadedCommand ?? (_LoadedCommand = new DelegateCommand(ExecuteLoadedCommand));
  159. private DelegateCommand _NextCommand;
  160. public DelegateCommand NextCommand =>
  161. _NextCommand ?? (_NextCommand = new DelegateCommand(ExecuteNextCommand));
  162. private DelegateCommand _BackCommand;
  163. public DelegateCommand BackCommand =>
  164. _BackCommand ?? (_BackCommand = new DelegateCommand(ExecuteBackCommand));
  165. private DelegateCommand _RunVisionProcessCommand;
  166. public DelegateCommand RunVisionProcessCommand =>
  167. _RunVisionProcessCommand ?? (_RunVisionProcessCommand = new DelegateCommand(ExecuteRunVisionProcessCommand));
  168. private DelegateCommand _FindP0Command;
  169. public DelegateCommand FindP0Command =>
  170. _FindP0Command ?? (_FindP0Command = new DelegateCommand(ExecuteFindP0Command));
  171. private DelegateCommand _TeachPutPosCommand;
  172. public DelegateCommand TeachPutPosCommand =>
  173. _TeachPutPosCommand ?? (_TeachPutPosCommand = new DelegateCommand(ExecuteTeachPutPosCommand));
  174. private DelegateCommand _MovePutPosCommand;
  175. public DelegateCommand MovePutPosCommand =>
  176. _MovePutPosCommand ?? (_MovePutPosCommand = new DelegateCommand(ExecuteMovePutPosCommand));
  177. private DelegateCommand _TeachDownCameraPosCommand;
  178. public DelegateCommand TeachDownCameraPosCommand =>
  179. _TeachDownCameraPosCommand ?? (_TeachDownCameraPosCommand = new DelegateCommand(ExecuteTeachDownCameraPosCommand));
  180. private DelegateCommand _MoveDownCameraPosCommand;
  181. public DelegateCommand MoveDownCameraPosCommand =>
  182. _MoveDownCameraPosCommand ?? (_MoveDownCameraPosCommand = new DelegateCommand(ExecuteMoveDownCameraPosCommand));
  183. private DelegateCommand _StartCalibP0Command;
  184. public DelegateCommand StartCalibP0Command =>
  185. _StartCalibP0Command ?? (_StartCalibP0Command = new DelegateCommand(ExecuteStartCalibP0Command));
  186. #endregion
  187. #region 事件
  188. #endregion
  189. public FixedUpCameraFindP0ViewModel(IRegionManager regionManager, IEventAggregator ea, IRegionNavigationService regionNavigationService, IContainerProvider container, IDialogService dialogService,
  190. IConfigService configService, IRobotService robotService, ICameraService cameraService, IFeederService feederService, ISystemDatabaseService systemDatabaseService, ICalibrationService calibrationService)
  191. {
  192. _regionManager = regionManager;
  193. _regionNavigationService = regionNavigationService;
  194. _container = container;
  195. _dialogService = dialogService;
  196. _eventAggregator = ea;
  197. _configService = configService;
  198. _robotService = robotService;
  199. _cameraService = cameraService;
  200. _feederService = feederService;
  201. _systemDatabaseService = systemDatabaseService;
  202. _calibrationServvice = calibrationService;
  203. }
  204. #region 方法
  205. void ExecuteLoadedCommand()
  206. {
  207. try
  208. {
  209. if (_systemDatabaseService.GetCurrentUser().userPart == Enums.UserPart.Operator)
  210. {
  211. IsAllowEdit = false;
  212. }
  213. else
  214. {
  215. IsAllowEdit = true;
  216. }
  217. }
  218. catch (Exception ex)
  219. {
  220. LogHelper.WriteLogError("相机校准加载视觉工具处理界面时出错!", ex);
  221. MessageBox.Show(ex.Message);
  222. }
  223. }
  224. /// <summary>
  225. /// 下一步
  226. /// </summary>
  227. void ExecuteNextCommand()
  228. {
  229. try
  230. {
  231. string prcPath = FilePath.CalibrationPath + "//" + SelectCalibration.Name + "//" + "FixedUpCameraTool.vpp";
  232. if (!Directory.Exists(System.IO.Path.GetDirectoryName(prcPath)))
  233. {
  234. Directory.CreateDirectory(System.IO.Path.GetDirectoryName(prcPath));
  235. }
  236. CogSerializer.SaveObjectToFile(ToolBlockEdit.Subject, prcPath);
  237. NavigationParameters param = new NavigationParameters();
  238. param.Add("SelectCalibration", SelectCalibration);
  239. _regionManager.RequestNavigate("CalibrationRegionContext", "CalibrationAuto", param);
  240. }
  241. catch (Exception ex)
  242. {
  243. LogHelper.WriteLogError("相机校准-下相机示教P0界面点击下一步时出错!", ex);
  244. MessageBox.Show(ex.Message);
  245. }
  246. }
  247. /// <summary>
  248. /// 上一步
  249. /// </summary>
  250. void ExecuteBackCommand()
  251. {
  252. try
  253. {
  254. NavigationParameters param = new NavigationParameters();
  255. param.Add("SelectCalibration", SelectCalibration);
  256. _regionManager.RequestNavigate("CalibrationRegionContext", "CalibrationTeachCenterPoint", param);
  257. }
  258. catch (Exception ex)
  259. {
  260. LogHelper.WriteLogError("相机校准-下相机示教P0界面点击上一步时出错!", ex);
  261. MessageBox.Show(ex.Message);
  262. }
  263. }
  264. /// <summary>
  265. /// 运行视觉流程
  266. /// </summary>
  267. void ExecuteRunVisionProcessCommand()
  268. {
  269. try
  270. {
  271. if (Camera == null)
  272. {
  273. MessageBox.Show("请先选择相机!");
  274. return;
  275. }
  276. ToolBlockEdit.Subject.Inputs["InputImage"].Value = Camera.Grab();
  277. ToolBlockEdit.Subject.Run();
  278. }
  279. catch (Exception ex)
  280. {
  281. LogHelper.WriteLogError("相机校准-运行流程时出错时出错", ex);
  282. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
  283. }
  284. }
  285. /// <summary>
  286. /// 自动计算P0点
  287. /// </summary>
  288. async void ExecuteFindP0Command()
  289. {
  290. if (Camera == null)
  291. {
  292. MessageBox.Show("请先选择相机!");
  293. return;
  294. }
  295. if (SelectedCalibration == null)
  296. {
  297. MessageBox.Show("请先选择标定!");
  298. return;
  299. }
  300. var result = await CaptureAndProcess(null);
  301. if (result.IsSuccess)
  302. {
  303. if (SelectCalibration.MarkPoint == null)
  304. {
  305. SelectCalibration.MarkPoint = new RPoint();
  306. }
  307. SelectCalibration.MarkPoint.X = (float)result.X;
  308. SelectCalibration.MarkPoint.Y = (float)result.Y;
  309. MessageBox.Show($"P0点计算成功!X:{result.X},Y:{result.Y}");
  310. }
  311. else
  312. {
  313. MessageBox.Show("未找到P0点,请调整工件位置后重试!");
  314. }
  315. }
  316. /// <summary>
  317. /// 通过下相机开始标定P0点
  318. /// </summary>
  319. async void ExecuteStartCalibP0Command()
  320. {
  321. //弹窗确认是否开始标定
  322. var result = MessageBox.Show("确认通过下相机开始标定P0点?", "提示", MessageBoxButton.YesNo, MessageBoxImage.Question);
  323. if (result != MessageBoxResult.Yes)
  324. {
  325. return;
  326. }
  327. try
  328. {
  329. // 1.移动至标定块放置位置,取标定块
  330. //移动机器人至下相机位置
  331. bool isSuccess = await Robot.CalibMotionAsync(SelectCalibration.PutPoint, 0);
  332. if (!isSuccess)
  333. {
  334. MessageBox.Show("移动至移动至标定块放置位置,取标定块失败!");
  335. return;
  336. }
  337. //打开吸气
  338. Robot.CalibOutIO(true);
  339. await Task.Delay(300);
  340. // 2.移动至下相机位置,拍照,计算P0点
  341. isSuccess = await Robot.CalibMotionAsync(SelectCalibration.DownCameraPoint, 0);
  342. if (!isSuccess)
  343. {
  344. MessageBox.Show("移动至下相机位置失败!");
  345. return;
  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. return;
  371. }
  372. // 3.移动至标定块放置位置,放下标定块
  373. isSuccess = await Robot.CalibMotionAsync(SelectCalibration.PutPoint, 0);
  374. if (isSuccess)
  375. {
  376. //关闭吸气
  377. Robot.CalibOutIO(false);
  378. await Task.Delay(300);
  379. }
  380. else
  381. {
  382. MessageBox.Show("移动至标定块放置位置,放下标定块失败!");
  383. return;
  384. }
  385. // 4.Z轴上升安全高度
  386. RPoint safePoint = SelectCalibration.PutPoint.Clone();
  387. safePoint.Z = 0;
  388. isSuccess = await Robot.CalibMotionAsync(safePoint, 0);
  389. if (!isSuccess)
  390. {
  391. MessageBox.Show("Z轴上升至安全高度失败!");
  392. return;
  393. }
  394. //完成提示
  395. MessageBox.Show("通过下相机标定P0点完成!");
  396. }
  397. catch (Exception ex)
  398. {
  399. LogHelper.WriteLogError("相机校准-通过下相机开始标定P0点时出错!", ex);
  400. MessageBox.Show(ex.Message);
  401. }
  402. }
  403. /// <summary>
  404. /// 移动至下相机位置
  405. /// </summary>
  406. async void ExecuteMoveDownCameraPosCommand()
  407. {
  408. try
  409. {
  410. //弹窗确认是否移动
  411. var result = MessageBox.Show("确认移动至下相机位置?", "提示", MessageBoxButton.YesNo, MessageBoxImage.Question);
  412. if (result != MessageBoxResult.Yes)
  413. {
  414. return;
  415. }
  416. //移动机器人至下相机位置
  417. bool isSuccess = await Robot.CalibMotionAsync(SelectCalibration.DownCameraPoint, 0);
  418. if (isSuccess)
  419. {
  420. MessageBox.Show("移动至下相机位置成功!");
  421. }
  422. else
  423. {
  424. MessageBox.Show("移动至下相机位置失败!");
  425. }
  426. }
  427. catch (Exception ex)
  428. {
  429. MessageBox.Show(ex.Message);
  430. }
  431. }
  432. /// <summary>
  433. /// 示教下相机位置
  434. /// </summary>
  435. void ExecuteTeachDownCameraPosCommand()
  436. {
  437. try
  438. {
  439. //弹窗确认是否示教
  440. var result = MessageBox.Show("确认示教下相机位置?", "提示", MessageBoxButton.YesNo, MessageBoxImage.Question);
  441. if (result != MessageBoxResult.Yes)
  442. {
  443. return;
  444. }
  445. //获取机器人当前位置
  446. SelectCalibration.DownCameraPoint = Robot.GetRobotPos();
  447. MessageBox.Show("示教下相机位置成功!");
  448. }
  449. catch (Exception ex)
  450. {
  451. MessageBox.Show(ex.Message);
  452. }
  453. }
  454. /// <summary>
  455. /// 移动至标定块放位置
  456. /// </summary>
  457. async void ExecuteMovePutPosCommand()
  458. {
  459. try
  460. {
  461. //弹窗确认是否移动
  462. var result = MessageBox.Show("确认移动至标定块放位置?", "提示", MessageBoxButton.YesNo, MessageBoxImage.Question);
  463. if (result != MessageBoxResult.Yes)
  464. {
  465. return;
  466. }
  467. //移动机器人至标定块放位置
  468. bool isSuccess = await Robot.CalibMotionAsync(SelectCalibration.PutPoint, 0);
  469. if (isSuccess)
  470. {
  471. MessageBox.Show("移动至标定块放位置成功!");
  472. }
  473. else
  474. {
  475. MessageBox.Show("移动至标定块放位置失败!");
  476. }
  477. }
  478. catch (Exception ex)
  479. {
  480. MessageBox.Show(ex.Message);
  481. }
  482. }
  483. /// <summary>
  484. /// 示教标定块放位置
  485. /// </summary>
  486. void ExecuteTeachPutPosCommand()
  487. {
  488. try
  489. {
  490. //弹窗确认是否示教
  491. var result = MessageBox.Show("确认示教标定块放位置?", "提示", MessageBoxButton.YesNo, MessageBoxImage.Question);
  492. if (result != MessageBoxResult.Yes)
  493. {
  494. return;
  495. }
  496. //获取机器人当前位置
  497. SelectCalibration.PutPoint = Robot.GetRobotPos();
  498. MessageBox.Show("示教标定块放位置成功!");
  499. }
  500. catch (Exception ex)
  501. {
  502. MessageBox.Show(ex.Message);
  503. }
  504. }
  505. /// <summary>
  506. /// 相机拍照
  507. /// </summary>
  508. /// <returns></returns>
  509. private async Task<(bool IsSuccess, double X, double Y, double U, int ImageWidth, int ImageHeight)> CaptureAndProcess(double[] robotCoord)
  510. {
  511. ICogImage image = null;
  512. //采集图像
  513. if (Camera != null)
  514. {
  515. image = Camera.Grab();
  516. ToolBlockEdit.Subject.Inputs["InputImage"].Value = image;
  517. }
  518. ToolBlockEdit.Subject.Run();
  519. CogToolBlockTerminalCollection outputCollection = ToolBlockEdit.Subject.Outputs;
  520. bool Found = (bool)(outputCollection["Found"].Value);
  521. if (Found)
  522. {
  523. var strpoints = outputCollection["Point"].Value.ToString();
  524. string[] items = strpoints.Split(',');
  525. double x = double.Parse(items[0]);
  526. double y = double.Parse(items[1]);
  527. //校准转换
  528. var calibResult = _calibrationServvice.ConvertPixelToPosition((x, y, 0), robotCoord, SelectedCalibration, Robot.Brand);
  529. if (calibResult.IsSucceed)
  530. {
  531. x = calibResult.X;
  532. y = calibResult.Y;
  533. return (true, x, y, 0, image.Width, image.Height);
  534. }
  535. return (false, 0, 0, 0, image.Width, image.Height);
  536. }
  537. else
  538. {
  539. return (false, 0, 0, 0, image.Width, image.Height);
  540. }
  541. }
  542. #endregion
  543. #region 继承
  544. /// <summary>
  545. /// 确认导航请求时调用。此方法允许您在导航之前执行一些操作。
  546. /// </summary>
  547. /// <param name="navigationContext"></param>
  548. /// <param name="continuationCallback"></param>
  549. public void ConfirmNavigationRequest(NavigationContext navigationContext, Action<bool> continuationCallback)
  550. {
  551. continuationCallback(true);
  552. }
  553. /// <summary>
  554. /// 接收导航请求时调用。传入导航参数,包含有关导航目标的信息。
  555. /// </summary>
  556. /// <param name="navigationContext"></param>
  557. /// <exception cref="NotImplementedException"></exception>
  558. public async void OnNavigatedTo(NavigationContext navigationContext)
  559. {
  560. SelectCalibration = navigationContext.Parameters.GetValue<CalibrationInfo>("SelectCalibration");
  561. if (SelectCalibration.FixedUpCameraFindP0Info == null)
  562. {
  563. SelectCalibration.FixedUpCameraFindP0Info = new FixedUpCameraFindP0Info();
  564. }
  565. string prcPath = FilePath.CalibrationPath + "//" + SelectCalibration.Name + "//" + "FixedUpCameraTool.vpp";
  566. if (File.Exists(prcPath))
  567. {
  568. ToolBlockEdit.Subject = CogSerializer.LoadObjectFromFile(prcPath) as CogToolBlock;
  569. }
  570. else
  571. {
  572. ToolBlockEdit.Subject = CogSerializer.LoadObjectFromFile(FilePath.CalibrationToolblockPath) as CogToolBlock;
  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.FixedUpCameraFindP0Info.ExposureTime==0?5000: SelectCalibration.FixedUpCameraFindP0Info.ExposureTime;
  589. Gain = SelectCalibration.FixedUpCameraFindP0Info.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. }