PlcPointParamsViewModel.cs 73 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800
  1. using Cognex.VisionPro;
  2. using MahApps.Metro.Controls;
  3. using MaterialDesignThemes.Wpf;
  4. using MathNet.Numerics.LinearAlgebra;
  5. using NPOI.SS.Formula.Functions;
  6. using Prism.Commands;
  7. using Prism.Events;
  8. using Prism.Ioc;
  9. using Prism.Mvvm;
  10. using Prism.Regions;
  11. using Prism.Services.Dialogs;
  12. using System;
  13. using System.Collections.Generic;
  14. using System.Collections.ObjectModel;
  15. using System.Drawing;
  16. using System.Linq;
  17. using System.Threading;
  18. using System.Threading.Tasks;
  19. using System.Windows;
  20. using TeamAAS_VP.Controls;
  21. using TeamAAS_VP.Core;
  22. using TeamAAS_VP.Core.PLCs;
  23. using TeamAAS_VP.Core.Robots;
  24. using TeamAAS_VP.DxfModule;
  25. using TeamAAS_VP.Enums;
  26. using TeamAAS_VP.Events;
  27. using TeamAAS_VP.Interfaces;
  28. using TeamAAS_VP.Models;
  29. using TeamAAS_VP.Models.PLC;
  30. using TeamAAS_VP.Models.Robot;
  31. using TeamAAS_VP.Resources.Languages;
  32. using TeamAAS_VP.Services;
  33. using TeamAAS_VP.Views.Product;
  34. using static TeamAAS_VP.ViewModels.Product.AutoCorrectLockPointViewModel;
  35. namespace TeamAAS_VP.ViewModels.Product
  36. {
  37. public class PlcPointParamsViewModel : BindableBase, IConfirmNavigationRequest
  38. {
  39. IRegionManager _regionManager;
  40. IEventAggregator _eventAggregator;
  41. IContainerProvider _container;
  42. IDialogService _dialogService;
  43. IConfigService _configService;
  44. IRobotService _robotService;
  45. ISystemDatabaseService _systemDatabaseService;
  46. IRemoteCommandService _remoteCommandService;
  47. ICalibrationService _calibrationService;
  48. ICameraService _cameraService;
  49. IProductService _productService;
  50. #region 属性
  51. private ObservableCollection<AxisExtended> _AdditionalAxisList;
  52. public ObservableCollection<AxisExtended> AdditionalAxisList
  53. {
  54. get { return _AdditionalAxisList; }
  55. set { SetProperty(ref _AdditionalAxisList, value); }
  56. }
  57. private ProductModel _SelectProduct;
  58. /// <summary>
  59. /// 选中的产品
  60. /// </summary>
  61. public ProductModel SelectProduct
  62. {
  63. get { return _SelectProduct; }
  64. set { SetProperty(ref _SelectProduct, value); }
  65. }
  66. private PlcPoint _SelectedPoint;
  67. public PlcPoint SelectedPoint
  68. {
  69. get { return _SelectedPoint; }
  70. set { SetProperty(ref _SelectedPoint, value); }
  71. }
  72. private PlcPoint _selectedPointInDataGrid;
  73. public PlcPoint SelectedPointInDataGrid
  74. {
  75. get { return _selectedPointInDataGrid; }
  76. set
  77. {
  78. if (SetProperty(ref _selectedPointInDataGrid, value))
  79. {
  80. SelectedPointInComboBox = value;
  81. // update command availability
  82. _MovePointUpCommand?.RaiseCanExecuteChanged();
  83. _MovePointDownCommand?.RaiseCanExecuteChanged();
  84. // 更新依赖可执行状态的命令
  85. _TechPointCommand?.RaiseCanExecuteChanged();
  86. _ExecuteMotion?.RaiseCanExecuteChanged();
  87. }
  88. // 可以同步到 SelectPoint 属性
  89. SelectedPoint = value;
  90. }
  91. }
  92. private PlcPoint _selectedPointInComboBox;
  93. public PlcPoint SelectedPointInComboBox
  94. {
  95. get { return _selectedPointInComboBox; }
  96. set
  97. {
  98. if (SetProperty(ref _selectedPointInComboBox, value))
  99. {
  100. SelectedPointInDataGrid = value;
  101. }
  102. // 可以同步到 SelectPoint 属性
  103. SelectedPoint = value;
  104. }
  105. }
  106. private ObservableCollection<PlcPoint> _Points = new ObservableCollection<PlcPoint>();
  107. /// <summary>
  108. /// 点位集合
  109. /// </summary>
  110. public ObservableCollection<PlcPoint> Points
  111. {
  112. get { return _Points; }
  113. set { SetProperty(ref _Points, value); }
  114. }
  115. private MotionCommand _SelectMotionCommand;
  116. /// <summary>
  117. /// 选中的运动指令
  118. /// </summary>
  119. public MotionCommand SelectMotionCommand
  120. {
  121. get { return _SelectMotionCommand; }
  122. set { SetProperty(ref _SelectMotionCommand, value); }
  123. }
  124. public Management management { get; set; }
  125. private XYZU_Robot _Robot;
  126. public XYZU_Robot Robot
  127. {
  128. get { return _Robot; }
  129. set
  130. {
  131. SetProperty(ref _Robot, value);
  132. }
  133. }
  134. private int _SelectedIndex;
  135. public int SelectedIndex
  136. {
  137. get { return _SelectedIndex; }
  138. set { SetProperty(ref _SelectedIndex, value); }
  139. }
  140. private double _Distance = 1;
  141. public double Distance
  142. {
  143. get { return _Distance; }
  144. set
  145. {
  146. SetProperty(ref _Distance, value);
  147. try
  148. {
  149. if (Robot == null)
  150. {
  151. return;
  152. }
  153. _configService.UpdateRobotStepDistance(Robot.Id, value);
  154. }
  155. catch (Exception)
  156. {
  157. }
  158. }
  159. }
  160. private ObservableCollection<ProcedureModel> _ProcedureModels;
  161. /// <summary>
  162. /// 流程集合
  163. /// </summary>
  164. public ObservableCollection<ProcedureModel> ProcedureModels
  165. {
  166. get { return _ProcedureModels; }
  167. set { SetProperty(ref _ProcedureModels, value); }
  168. }
  169. private ProcedureModel _SelectProcedure;
  170. /// <summary>
  171. /// 选中的流程
  172. /// </summary>
  173. public ProcedureModel SelectProcedure
  174. {
  175. get { return _SelectProcedure; }
  176. set
  177. {
  178. SetProperty(ref _SelectProcedure, value);
  179. }
  180. }
  181. private bool _IsGrap;
  182. public bool IsGrap
  183. {
  184. get { return _IsGrap; }
  185. set { SetProperty(ref _IsGrap, value); }
  186. }
  187. private ObservableCollection<CameraInfo> _CameraList;
  188. public ObservableCollection<CameraInfo> CameraList
  189. {
  190. get { return _CameraList; }
  191. set { SetProperty(ref _CameraList, value); }
  192. }
  193. private CameraInfo _SelectedCamera;
  194. public CameraInfo SelectedCamera
  195. {
  196. get { return _SelectedCamera; }
  197. set
  198. {
  199. SetProperty(ref _SelectedCamera, value);
  200. if (value != null)
  201. {
  202. if (Camera != null)
  203. {
  204. if (Camera.IsGrabbing)
  205. {
  206. Camera.StopGrabbing();
  207. }
  208. Camera.ImageCallbackEvent -= Camera_ImageCallbackEvent;
  209. }
  210. Camera = _cameraService.GetCamera(value.Id);
  211. Camera.ImageCallbackEvent += Camera_ImageCallbackEvent;
  212. }
  213. }
  214. }
  215. private ICamera _Camera;
  216. public ICamera Camera
  217. {
  218. get { return _Camera; }
  219. set { SetProperty(ref _Camera, value); }
  220. }
  221. private ICogImage _Image;
  222. public ICogImage Image
  223. {
  224. get { return _Image; }
  225. set { SetProperty(ref _Image, value); }
  226. }
  227. private string _Message;
  228. public string Message
  229. {
  230. get { return _Message; }
  231. set { SetProperty(ref _Message, value); }
  232. }
  233. private bool _IsLeftDrawerOpen;
  234. public bool IsLeftDrawerOpen
  235. {
  236. get { return _IsLeftDrawerOpen; }
  237. set
  238. {
  239. SetProperty(ref _IsLeftDrawerOpen, value);
  240. if (!value)
  241. {
  242. if (IsGrap)
  243. {
  244. ExecuteStopGrabbingCommand();
  245. }
  246. }
  247. }
  248. }
  249. private int _Inhal = 1;
  250. public int Inhal
  251. {
  252. get { return _Inhal; }
  253. set { SetProperty(ref _Inhal, value); }
  254. }
  255. private PlcPoint _PickP1 = new PlcPoint();
  256. public PlcPoint PickP1
  257. {
  258. get { return _PickP1; }
  259. set { SetProperty(ref _PickP1, value); }
  260. }
  261. private PlcPoint _PickP2 = new PlcPoint();
  262. public PlcPoint PickP2
  263. {
  264. get { return _PickP2; }
  265. set { SetProperty(ref _PickP2, value); }
  266. }
  267. private int _ColumnNum = 18;
  268. public int ColumnNum
  269. {
  270. get { return _ColumnNum; }
  271. set { SetProperty(ref _ColumnNum, value); }
  272. }
  273. #endregion
  274. #region 命令
  275. private DelegateCommand _NextCommand;
  276. public DelegateCommand NextCommand =>
  277. _NextCommand ?? (_NextCommand = new DelegateCommand(ExecuteNextCommand));
  278. private DelegateCommand _BackCommand;
  279. public DelegateCommand BackCommand =>
  280. _BackCommand ?? (_BackCommand = new DelegateCommand(ExecuteBackCommand));
  281. private DelegateCommand _LoadedCommand;
  282. public DelegateCommand LoadedCommand =>
  283. _LoadedCommand ?? (_LoadedCommand = new DelegateCommand(ExecuteLoadedCommand));
  284. private DelegateCommand<object> _ExecuteMotion;
  285. public DelegateCommand<object> ExecuteMotion =>
  286. _ExecuteMotion ?? (_ExecuteMotion = new DelegateCommand<object>(ExecuteExecuteMotion).ObservesCanExecute(() => CanExecutePointCommand).ObservesProperty(() => Robot).ObservesProperty(() => Robot.CanExecute).ObservesProperty(() => SelectedPointInDataGrid));
  287. private DelegateCommand<object> _JogCommand;
  288. public DelegateCommand<object> JogCommand =>
  289. _JogCommand ?? (_JogCommand = new DelegateCommand<object>(ExecuteJogCommand).ObservesCanExecute(() => CanExecute).ObservesProperty(() => Robot).ObservesProperty(() => Robot.CanExecute));
  290. private DelegateCommand _TechPointCommand;
  291. public DelegateCommand TechPointCommand =>
  292. _TechPointCommand ?? (_TechPointCommand = new DelegateCommand(ExecuteTechPointCommand).ObservesCanExecute(() => CanExecutePointCommand).ObservesProperty(() => Robot).ObservesProperty(() => Robot.CanExecute).ObservesProperty(() => SelectedPointInDataGrid));
  293. private DelegateCommand<string> _MotorCommand;
  294. public DelegateCommand<string> MotorCommand =>
  295. _MotorCommand ?? (_MotorCommand = new DelegateCommand<string>(ExecuteMotorCommand).ObservesCanExecute(() => CanExecute).ObservesProperty(() => Robot).ObservesProperty(() => Robot.CanExecute));
  296. private DelegateCommand _ResetCommand;
  297. public DelegateCommand ResetCommand =>
  298. _ResetCommand ?? (_ResetCommand = new DelegateCommand(ExecuteResetCommand).ObservesCanExecute(() => CanExecute).ObservesProperty(() => Robot).ObservesProperty(() => Robot.CanExecute));
  299. private DelegateCommand _sFreeCommand;
  300. public DelegateCommand sFreeCommand =>
  301. _sFreeCommand ?? (_sFreeCommand = new DelegateCommand(ExecutesFreeCommand).ObservesCanExecute(() => CanExecute).ObservesProperty(() => Robot).ObservesProperty(() => Robot.CanExecute));
  302. private DelegateCommand _SLockCommand;
  303. public DelegateCommand SLockCommand =>
  304. _SLockCommand ?? (_SLockCommand = new DelegateCommand(ExecuteSLockCommand).ObservesCanExecute(() => CanExecute).ObservesProperty(() => Robot).ObservesProperty(() => Robot.CanExecute));
  305. private DelegateCommand _SelectionChangedCommand;
  306. public DelegateCommand SelectionChangedCommand =>
  307. _SelectionChangedCommand ?? (_SelectionChangedCommand = new DelegateCommand(ExecuteSelectionChangedCommand));
  308. private DelegateCommand _AddPointCommand;
  309. public DelegateCommand AddPointCommand =>
  310. _AddPointCommand ?? (_AddPointCommand = new DelegateCommand(ExecuteAddPointCommand));
  311. private DelegateCommand _DeletePointCommand;
  312. public DelegateCommand DeletePointCommand =>
  313. _DeletePointCommand ?? (_DeletePointCommand = new DelegateCommand(ExecuteDeletePointCommand, CanExecuteDeletePointCommand).ObservesProperty(() => SelectedPointInDataGrid));
  314. private DelegateCommand _MovePointUpCommand;
  315. public DelegateCommand MovePointUpCommand => _MovePointUpCommand ?? (_MovePointUpCommand = new DelegateCommand(ExecuteMovePointUpCommand, CanMovePointUp));
  316. private DelegateCommand _MovePointDownCommand;
  317. public DelegateCommand MovePointDownCommand => _MovePointDownCommand ?? (_MovePointDownCommand = new DelegateCommand(ExecuteMovePointDownCommand, CanMovePointDown));
  318. private DelegateCommand _ImportCadPointCommand;
  319. public DelegateCommand ImportCadPointCommand =>
  320. _ImportCadPointCommand ?? (_ImportCadPointCommand = new DelegateCommand(ExecuteImportCadPointCommand));
  321. private DelegateCommand _StartGrabbingCommand;
  322. public DelegateCommand StartGrabbingCommand =>
  323. _StartGrabbingCommand ?? (_StartGrabbingCommand = new DelegateCommand(ExecuteStartGrabbingCommand, CanExecuteStartGrabbingCommand).ObservesProperty(() => IsGrap).ObservesProperty(() => SelectedCamera));
  324. private DelegateCommand _StopGrabbingCommand;
  325. public DelegateCommand StopGrabbingCommand =>
  326. _StopGrabbingCommand ?? (_StopGrabbingCommand = new DelegateCommand(ExecuteStopGrabbingCommand, CanExecuteStopGrabbingCommand).ObservesProperty(() => IsGrap).ObservesProperty(() => SelectedCamera));
  327. private DelegateCommand _GoPickCommand;
  328. public DelegateCommand GoPickCommand =>
  329. _GoPickCommand ?? (_GoPickCommand = new DelegateCommand(ExecuteGoPickCommand, CanExecuteCommandGoPickCommandName).ObservesProperty(() => SelectedPoint));
  330. private DelegateCommand _GoRepositionCommand;
  331. public DelegateCommand GoRepositionCommand =>
  332. _GoRepositionCommand ?? (_GoRepositionCommand = new DelegateCommand(ExecuteGoRepositionCommand, CanExecuteCommandGoPickCommandName).ObservesProperty(() => SelectedPoint));
  333. private DelegateCommand _TakeProductPhotoCommand;
  334. public DelegateCommand TakeProductPhotoCommand =>
  335. _TakeProductPhotoCommand ?? (_TakeProductPhotoCommand = new DelegateCommand(ExecuteTakeProductPhotoCommand, CanExecuteCommandGoPickCommandName).ObservesProperty(() => SelectedPoint));
  336. private DelegateCommand _TakeProductCommand;
  337. public DelegateCommand TakeProductCommand =>
  338. _TakeProductCommand ?? (_TakeProductCommand = new DelegateCommand(ExecuteTakeProductCommand, CanExecuteCommandGoPickCommandName).ObservesProperty(() => SelectedPoint));
  339. //附加轴,轴点动+命令
  340. private DelegateCommand<object> _AdditionalAxisJogPlusCommand;
  341. public DelegateCommand<object> AdditionalAxisJogPlusCommand =>
  342. _AdditionalAxisJogPlusCommand ?? (_AdditionalAxisJogPlusCommand = new DelegateCommand<object>(ExecuteAdditionalAxisJogPlusCommand).ObservesCanExecute(() => CanExecute).ObservesProperty(() => Robot).ObservesProperty(() => Robot.CanExecute));
  343. //附加轴,轴点动-命令
  344. private DelegateCommand<object> _AdditionalAxisJogMinusCommand;
  345. public DelegateCommand<object> AdditionalAxisJogMinusCommand =>
  346. _AdditionalAxisJogMinusCommand ?? (_AdditionalAxisJogMinusCommand = new DelegateCommand<object>(ExecuteAdditionalAxisJogMinusCommand).ObservesCanExecute(() => CanExecute).ObservesProperty(() => Robot).ObservesProperty(() => Robot.CanExecute));
  347. private DelegateCommand<object> _AdditionalAxisMotorOnCommand;
  348. public DelegateCommand<object> AdditionalAxisMotorOnCommand =>
  349. _AdditionalAxisMotorOnCommand ?? (_AdditionalAxisMotorOnCommand = new DelegateCommand<object>(ExecuteAdditionalAxisMotorOnCommand).ObservesCanExecute(() => CanExecute).ObservesProperty(() => Robot).ObservesProperty(() => Robot.CanExecute));
  350. private DelegateCommand<object> _AdditionalAxisMotorOffCommand;
  351. public DelegateCommand<object> AdditionalAxisMotorOffCommand =>
  352. _AdditionalAxisMotorOffCommand ?? (_AdditionalAxisMotorOffCommand = new DelegateCommand<object>(ExecuteAdditionalAxisMotorOffCommand).ObservesCanExecute(() => CanExecute).ObservesProperty(() => Robot).ObservesProperty(() => Robot.CanExecute));
  353. private DelegateCommand<string> _PickTechCommand;
  354. public DelegateCommand<string> PickTechCommand =>
  355. _PickTechCommand ?? (_PickTechCommand = new DelegateCommand<string>(ExecutePickTechCommand));
  356. private DelegateCommand<string> _PickMoveCommand;
  357. public DelegateCommand<string> PickMoveCommand =>
  358. _PickMoveCommand ?? (_PickMoveCommand = new DelegateCommand<string>(ExecutePickMoveCommand));
  359. private DelegateCommand _CalPickPosCommand;
  360. public DelegateCommand CalPickPosCommand =>
  361. _CalPickPosCommand ?? (_CalPickPosCommand = new DelegateCommand(ExecuteCalPickPosCommand));
  362. #endregion
  363. #region 事件
  364. #endregion
  365. public PlcPointParamsViewModel(IRegionManager regionManager, IEventAggregator ea, IContainerProvider container, IDialogService dialogService,
  366. IConfigService configService, IRobotService robotService, ISystemDatabaseService systemDatabaseService, IRemoteCommandService remoteCommandService,
  367. ICalibrationService calibrationService, ICameraService cameraService, IProductService productService)
  368. {
  369. _regionManager = regionManager;
  370. _eventAggregator = ea;
  371. _container = container;
  372. _dialogService = dialogService;
  373. _configService = configService;
  374. _systemDatabaseService = systemDatabaseService;
  375. //订阅权限登录事件
  376. _eventAggregator.GetEvent<UserLoginNotification>().Subscribe(LoginChange);
  377. management = _container.Resolve<Management>();
  378. _robotService = robotService;
  379. _remoteCommandService = remoteCommandService;
  380. _calibrationService = calibrationService;
  381. _cameraService = cameraService;
  382. _productService = productService;
  383. }
  384. #region 方法
  385. /// <summary>
  386. /// 下一步
  387. /// </summary>
  388. void ExecuteNextCommand()
  389. {
  390. NavigationParameters param = new NavigationParameters();
  391. param.Add("SelectProduct", SelectProduct);
  392. _regionManager.RequestNavigate("ProductRegionContext", "ProductParams", param);
  393. }
  394. /// <summary>
  395. /// 上一步
  396. /// </summary>
  397. void ExecuteBackCommand()
  398. {
  399. NavigationParameters param = new NavigationParameters();
  400. param.Add("SelectProduct", SelectProduct);
  401. param.Add("SelectedProcedure", null);
  402. _regionManager.RequestNavigate("ProductRegionContext", "ProcessBasics", param);
  403. }
  404. /// <summary>
  405. /// 点动
  406. /// </summary>
  407. /// <param name="obj"></param>
  408. private async void ExecuteJogCommand(object obj)
  409. {
  410. if (Robot == null || !Robot.IsConnected) return;
  411. try
  412. {
  413. var items = ((string)obj).Split(':');
  414. //如果移动距离大于10mm,则提示用户确认
  415. double distance = double.Parse(items[1]);
  416. if (Math.Abs(distance) >= 10)
  417. {
  418. if (MessageBox.Show($"确认要点动距离 {distance} mm 吗?", "确认点动", MessageBoxButton.YesNo, MessageBoxImage.Question) != MessageBoxResult.Yes)
  419. {
  420. return;
  421. }
  422. }
  423. Robot.Timeout = 6000000;
  424. switch (items[0])
  425. {
  426. case "X+":
  427. await Robot.JogAsync("X", distance);
  428. break;
  429. case "X-":
  430. await Robot.JogAsync("X", -distance);
  431. break;
  432. case "Y+":
  433. await Robot.JogAsync("Y", distance);
  434. break;
  435. case "Y-":
  436. await Robot.JogAsync("Y", -distance);
  437. break;
  438. case "Z+":
  439. await Robot.JogAsync("Z", distance);
  440. break;
  441. case "Z-":
  442. await Robot.JogAsync("Z", -distance);
  443. break;
  444. case "U+":
  445. await Robot.JogAsync("U", distance);
  446. break;
  447. case "U-":
  448. await Robot.JogAsync("U", -distance);
  449. break;
  450. case "V+":
  451. await Robot.JogAsync("V", distance);
  452. break;
  453. case "V-":
  454. await Robot.JogAsync("V", -distance);
  455. break;
  456. case "W+":
  457. await Robot.JogAsync("W", distance);
  458. break;
  459. case "W-":
  460. await Robot.JogAsync("W", -distance);
  461. break;
  462. default:
  463. break;
  464. }
  465. Robot.Timeout = 5000;
  466. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = $"{Lang.完成}!", Duration = 0.4 });
  467. }
  468. catch (Exception ex)
  469. {
  470. LogHelper.WriteLogError("机器人点位-机器人点动时出错", ex);
  471. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
  472. }
  473. }
  474. /// <summary>
  475. /// 执行运动
  476. /// </summary>
  477. /// <param name="obj"></param>
  478. async void ExecuteExecuteMotion(object parameter)
  479. {
  480. if (parameter == null)
  481. {
  482. return;
  483. }
  484. if (SelectedPoint == null)
  485. {
  486. return;
  487. }
  488. var values = (object[])parameter;
  489. var point = new RPoint()
  490. {
  491. X = SelectedPoint.X_Position,
  492. Y = SelectedPoint.Y_Position,
  493. Z = SelectedPoint.Z_Position_Start,
  494. U = SelectedPoint.U_Position,
  495. V = SelectedPoint.R_Position,
  496. };
  497. MotionCommand motionCmd = (MotionCommand)values[1];
  498. if (Robot == null || !Robot.IsConnected) return;
  499. try
  500. {
  501. //确认要执行该点位的该运动指令吗
  502. if (MessageBox.Show($"确认要执行点位 {SelectedPoint.Number} 的 {motionCmd} 指令吗?", "执行点位", MessageBoxButton.YesNo, MessageBoxImage.Question) != MessageBoxResult.Yes)
  503. {
  504. return;
  505. }
  506. //Robot.Timeout = 6000000;
  507. switch (motionCmd)
  508. {
  509. case MotionCommand.Go:
  510. await Robot.GoAsync(point);
  511. break;
  512. case MotionCommand.Jump:
  513. await Robot.JumpAsync(point, 0);
  514. break;
  515. case MotionCommand.Move:
  516. await Robot.MoveAsync(point);
  517. break;
  518. }
  519. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = $"{Lang.完成}!", Duration = 0.4 });
  520. }
  521. catch (Exception ex)
  522. {
  523. LogHelper.WriteLogError("机器人点位-执行点位时出错", ex);
  524. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
  525. }
  526. }
  527. /// <summary>
  528. /// 示教点位
  529. /// </summary>
  530. /// <param name="point"></param>
  531. async void ExecuteTechPointCommand()
  532. {
  533. if (Robot == null || !Robot.IsConnected) return;
  534. if (SelectedPoint == null) return;
  535. try
  536. {
  537. //如果当前的选项卡处于锁付点位,则提示用户当前模式不允许进行示教
  538. if (SelectedIndex == 4)
  539. {
  540. //如果local为空,则必须先通过相机定位产品,否则无法示教锁付点位
  541. if (toolCoord == null)
  542. {
  543. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = "当前模式不允许直接示教贴敷点位,请先通过相机定位产品和定位辅料!", Duration = 1 });
  544. return;
  545. }
  546. //弹窗用户是否确认要示教该点位
  547. if (MessageBox.Show($"确认要示教点位 {SelectedPoint.Number} 吗?", "示教点位", MessageBoxButton.YesNo, MessageBoxImage.Question) != MessageBoxResult.Yes)
  548. {
  549. return;
  550. }
  551. var curpos1 = await Robot.GetRobotPosAsync();
  552. //将当前点位转换为产品Local坐标系下的点位
  553. SelectedPoint.X_Position = (float)curpos1.X;
  554. SelectedPoint.Y_Position = (float)curpos1.Y;
  555. SelectedPoint.Z_Position_Start = curpos1.Z;
  556. SelectedPoint.U_Position = curpos1.U;
  557. SelectedPoint.R_Position = curpos1.V;
  558. SelectProduct.FixedUpCameraTempletAngle = _FixedUpCameraTempletAngle;
  559. SelectProduct.MoveDownCamerTempletAngle = _MoveCameraTempletAngle;
  560. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = $"{Lang.完成}!", Duration = 0.4 });
  561. return;
  562. }
  563. else if (SelectedIndex == 1)
  564. {
  565. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = "当前模式不允许直接示教取料点!", Duration = 1 });
  566. return;
  567. }
  568. else
  569. {
  570. //弹窗用户是否确认要示教该点位
  571. if (MessageBox.Show($"确认要示教点位 {SelectedPoint.Number} 吗?", "示教点位", MessageBoxButton.YesNo, MessageBoxImage.Question) != MessageBoxResult.Yes)
  572. {
  573. return;
  574. }
  575. var curpos = await Robot.GetRobotPosAsync();
  576. SelectedPoint.X_Position = curpos.X;
  577. SelectedPoint.Y_Position = curpos.Y;
  578. SelectedPoint.Z_Position_Start = curpos.Z;
  579. SelectedPoint.U_Position = curpos.U;
  580. SelectedPoint.R_Position = curpos.V;
  581. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = $"{Lang.完成}!", Duration = 0.4 });
  582. }
  583. }
  584. catch (Exception ex)
  585. {
  586. LogHelper.WriteLogError("机器人点位-示教点位时出错", ex);
  587. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
  588. }
  589. }
  590. void ExecuteLoadedCommand()
  591. {
  592. if (_systemDatabaseService.GetCurrentUser().userPart == Enums.UserPart.Operator)
  593. {
  594. IsAllowEdit = false;
  595. }
  596. else
  597. {
  598. IsAllowEdit = true;
  599. }
  600. }
  601. /// <summary>
  602. /// 电机
  603. /// </summary>
  604. /// <param name="obj"></param>
  605. private async void ExecuteMotorCommand(string obj)
  606. {
  607. if (Robot == null || !Robot.IsConnected) return;
  608. try
  609. {
  610. await Robot.MotorAsync(Convert.ToBoolean(obj));
  611. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = $"{Lang.完成}!", Duration = 0.4 });
  612. }
  613. catch (Exception ex)
  614. {
  615. LogHelper.WriteLogError("机器人点击操作时出错!", ex);
  616. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
  617. }
  618. }
  619. /// <summary>
  620. /// 重置
  621. /// </summary>
  622. private async void ExecuteResetCommand()
  623. {
  624. if (Robot == null || !Robot.IsConnected) return;
  625. try
  626. {
  627. await Robot.ResetAsync();
  628. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = $"{Lang.完成}!", Duration = 0.4 });
  629. }
  630. catch (Exception ex)
  631. {
  632. LogHelper.WriteLogError("重置机器人时出错!", ex);
  633. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
  634. }
  635. }
  636. /// <summary>
  637. /// 锁定刹车
  638. /// </summary>
  639. private async void ExecuteSLockCommand()
  640. {
  641. if (Robot == null || !Robot.IsConnected) return;
  642. try
  643. {
  644. await Robot.SLockAsync();
  645. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = $"{Lang.完成}!", Duration = 0.4 });
  646. }
  647. catch (Exception ex)
  648. {
  649. LogHelper.WriteLogError("机器人锁定刹车时出错!", ex);
  650. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
  651. }
  652. }
  653. /// <summary>
  654. /// 释放刹车
  655. /// </summary>
  656. private async void ExecutesFreeCommand()
  657. {
  658. if (Robot == null || !Robot.IsConnected) return;
  659. try
  660. {
  661. await Robot.SFreeAsync();
  662. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = $"{Lang.完成}!", Duration = 0.4 });
  663. }
  664. catch (Exception ex)
  665. {
  666. LogHelper.WriteLogError("机器人释放刹车时出错!", ex);
  667. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
  668. }
  669. }
  670. private bool CanExecute
  671. {
  672. get
  673. {
  674. // 命令可执行仅当机器人可执行且已选择点位
  675. if (Robot != null && Robot.IsConnected && Robot.CanExecute)
  676. {
  677. return true;
  678. }
  679. return false;
  680. }
  681. }
  682. //是否可以示教或者执行点位
  683. private bool CanExecutePointCommand
  684. {
  685. get
  686. {
  687. if (Robot != null && Robot.IsConnected && Robot.CanExecute)
  688. {
  689. return SelectedPointInDataGrid != null;
  690. }
  691. return false;
  692. }
  693. }
  694. /// <summary>
  695. /// 点位表切换时
  696. /// </summary>
  697. void ExecuteSelectionChangedCommand()
  698. {
  699. switch (SelectedIndex)
  700. {
  701. case 0:
  702. Points = SelectProduct.PickCameraPoints;
  703. break;
  704. case 1:
  705. Points = SelectProduct.PickPoints;
  706. break;
  707. case 2:
  708. Points = SelectProduct.SecPosCameraPoints;
  709. break;
  710. case 3:
  711. Points = SelectProduct.ScrewCameraPoints;
  712. break;
  713. case 4:
  714. Points = SelectProduct.ScrewPoints;
  715. break;
  716. case 5:
  717. Points = SelectProduct.CheckCameraPoints;
  718. break;
  719. default:
  720. break;
  721. }
  722. }
  723. /// <summary>
  724. /// 增加点位
  725. /// </summary>
  726. void ExecuteAddPointCommand()
  727. {
  728. //添加点位
  729. Points.Add(new PlcPoint()
  730. {
  731. Number = Points.Count + 1,
  732. X_Velocity = 100,
  733. Y_Velocity = 100,
  734. Z_Velocity_Start = 100,
  735. Z_Velocity_Stop = 100,
  736. U_Velocity = 100,
  737. R_Velocity = 100,
  738. });
  739. // update commands
  740. _MovePointUpCommand?.RaiseCanExecuteChanged();
  741. _MovePointDownCommand?.RaiseCanExecuteChanged();
  742. }
  743. /// <summary>
  744. /// 移除点位
  745. /// </summary>
  746. void ExecuteDeletePointCommand()
  747. {
  748. if (SelectedPoint == null)
  749. {
  750. return;
  751. }
  752. // 确认删除
  753. if (MessageBox.Show("确认要删除选中的点位吗?", "删除点位", MessageBoxButton.YesNo, MessageBoxImage.Question) != MessageBoxResult.Yes)
  754. {
  755. return;
  756. }
  757. int removedIndex = Points.IndexOf(SelectedPoint);
  758. Points.Remove(SelectedPoint);
  759. //重新编号
  760. for (int i = 0; i < Points.Count; i++)
  761. {
  762. Points[i].Number = i + 1;
  763. }
  764. // adjust selection
  765. if (Points.Count > 0)
  766. {
  767. int newIndex = Math.Min(removedIndex, Points.Count - 1);
  768. SelectedPointInDataGrid = Points[newIndex];
  769. }
  770. else
  771. {
  772. SelectedPointInDataGrid = null;
  773. }
  774. // update commands
  775. _MovePointUpCommand?.RaiseCanExecuteChanged();
  776. _MovePointDownCommand?.RaiseCanExecuteChanged();
  777. }
  778. bool CanExecuteDeletePointCommand()
  779. {
  780. return SelectedPointInDataGrid != null;
  781. }
  782. private bool CanMovePointUp()
  783. {
  784. return SelectedPointInDataGrid != null && Points.IndexOf(SelectedPointInDataGrid) > 0;
  785. }
  786. private bool CanMovePointDown()
  787. {
  788. return SelectedPointInDataGrid != null && Points.IndexOf(SelectedPointInDataGrid) >= 0 && Points.IndexOf(SelectedPointInDataGrid) < Points.Count - 1;
  789. }
  790. /// <summary>
  791. /// 向上移动点位
  792. /// </summary>
  793. void ExecuteMovePointUpCommand()
  794. {
  795. if (SelectedPointInDataGrid == null) return;
  796. // 确认移动
  797. if (MessageBox.Show("确认将选中点位上移一位吗?", "移动点位", MessageBoxButton.YesNo, MessageBoxImage.Question) != MessageBoxResult.Yes)
  798. {
  799. return;
  800. }
  801. int idx = Points.IndexOf(SelectedPointInDataGrid);
  802. if (idx <= 0) return;
  803. var item = SelectedPointInDataGrid;
  804. Points.Move(idx, idx - 1);
  805. // renumber
  806. for (int i = 0; i < Points.Count; i++) Points[i].Number = i + 1;
  807. SelectedPointInDataGrid = item;
  808. _MovePointUpCommand?.RaiseCanExecuteChanged();
  809. _MovePointDownCommand?.RaiseCanExecuteChanged();
  810. }
  811. /// <summary>
  812. /// 向下移动点位
  813. /// </summary>
  814. void ExecuteMovePointDownCommand()
  815. {
  816. if (SelectedPointInDataGrid == null) return;
  817. // 确认移动
  818. if (MessageBox.Show("确认将选中点位下移一位吗?", "移动点位", MessageBoxButton.YesNo, MessageBoxImage.Question) != MessageBoxResult.Yes)
  819. {
  820. return;
  821. }
  822. int idx = Points.IndexOf(SelectedPointInDataGrid);
  823. if (idx < 0 || idx >= Points.Count - 1) return;
  824. var item = SelectedPointInDataGrid;
  825. Points.Move(idx, idx + 1);
  826. // renumber
  827. for (int i = 0; i < Points.Count; i++) Points[i].Number = i + 1;
  828. SelectedPointInDataGrid = item;
  829. _MovePointUpCommand?.RaiseCanExecuteChanged();
  830. _MovePointDownCommand?.RaiseCanExecuteChanged();
  831. }
  832. /// <summary>
  833. /// CAD导入点位
  834. /// </summary>
  835. async void ExecuteImportCadPointCommand()
  836. {
  837. try
  838. {
  839. var view = new DxfView();
  840. //show the dialog
  841. var result = await DialogHost.Show(view, "RootDialog", null, null, null);
  842. if (result != null)
  843. {
  844. var cadPoints = view.Points;
  845. if (cadPoints != null && cadPoints.Count > 0)
  846. {
  847. //要导入的开始点编号
  848. int startNumber = view.StartIndex;
  849. //弹窗提示用户是否确认要导入从该编号开始的点位,点位数量为cadPoints.Count
  850. if (MessageBox.Show($"确认要从点位编号 {startNumber} 开始导入 {cadPoints.Count} 个点位吗?", "导入点位", MessageBoxButton.YesNo, MessageBoxImage.Question) != MessageBoxResult.Yes)
  851. {
  852. return;
  853. }
  854. //导入点位
  855. for (int i = 0; i < cadPoints.Count; i++)
  856. {
  857. //如果点位编号已存在,则更新该点位,否则新增点位,只更新XY坐标
  858. var point = cadPoints[i];
  859. var existingPoint = Points.FirstOrDefault(p => p.Number == startNumber + i);
  860. if (existingPoint != null)
  861. {
  862. existingPoint.X_Position = point.X;
  863. existingPoint.Y_Position = point.Y;
  864. }
  865. else
  866. {
  867. Points.Add(new PlcPoint()
  868. {
  869. Number = startNumber + i,
  870. X_Position = point.X,
  871. Y_Position = point.Y,
  872. X_Velocity = 100,
  873. Y_Velocity = 100,
  874. Z_Velocity_Start = 100,
  875. Z_Velocity_Stop = 100,
  876. U_Velocity = 100,
  877. R_Velocity = 100,
  878. });
  879. }
  880. }
  881. //对所有的点位重新编号,确保编号连续
  882. var sortedPoints = Points.OrderBy(p => p.Number).ToList();
  883. Points.Clear();
  884. for (int i = 0; i < sortedPoints.Count; i++)
  885. {
  886. sortedPoints[i].Number = i + 1;
  887. Points.Add(sortedPoints[i]);
  888. }
  889. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = $"{Lang.完成}!", Duration = 0.4 });
  890. }
  891. }
  892. }
  893. catch (Exception ex)
  894. {
  895. LogHelper.WriteLogError("导入CAD点位时出错!", ex);
  896. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
  897. }
  898. }
  899. /// <summary>
  900. /// 停止采集
  901. /// </summary>
  902. void ExecuteStopGrabbingCommand()
  903. {
  904. if (Camera != null)
  905. Camera.StopGrabbing();
  906. IsGrap = false;
  907. }
  908. bool CanExecuteStopGrabbingCommand()
  909. {
  910. return IsGrap;
  911. }
  912. /// <summary>
  913. /// 开始采集
  914. /// </summary>
  915. void ExecuteStartGrabbingCommand()
  916. {
  917. if (Camera != null)
  918. Camera.StartGrabbing();
  919. IsGrap = true;
  920. }
  921. bool CanExecuteStartGrabbingCommand()
  922. {
  923. return SelectedCamera != null && !IsGrap;
  924. }
  925. private void Camera_ImageCallbackEvent(ICogImage image, TimeSpan totaltime, string errormessage)
  926. {
  927. Image = image;
  928. App.Current.Dispatcher.Invoke(new
  929. Action(() =>
  930. {
  931. if (errormessage != null && !string.IsNullOrEmpty(errormessage))
  932. {
  933. Message = $"{Lang.耗时}:{totaltime.TotalMilliseconds.ToString("F1")} ms Error:{errormessage}";
  934. }
  935. else
  936. {
  937. Message = $"{Lang.耗时}:{totaltime.TotalMilliseconds.ToString("F1")} ms";
  938. }
  939. }));
  940. }
  941. /// <summary>
  942. /// 去取料
  943. /// </summary>
  944. async void ExecuteGoPickCommand()
  945. {
  946. try
  947. {
  948. if (SelectedPoint == null)
  949. {
  950. return;
  951. }
  952. if (Robot == null || !Robot.IsConnected)
  953. {
  954. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = "机器人未连接,无法执行取料!", Duration = 1 });
  955. return;
  956. }
  957. if (MessageBox.Show("确认要执行取料吗?", "去取料", MessageBoxButton.YesNo, MessageBoxImage.Question) != MessageBoxResult.Yes)
  958. {
  959. return;
  960. }
  961. var waiting = new WaitingControl();
  962. //show the dialog
  963. var task = DialogHost.Show(waiting, "RootDialog", null, null, null);
  964. // 1. 控制机器人移动至拍照点位
  965. var rpoint = new RPoint()
  966. {
  967. X = SelectedPoint.X_Position,
  968. Y = SelectedPoint.Y_Position,
  969. Z = SelectedPoint.Z_Position_Start,
  970. U = SelectedPoint.U_Position,
  971. V = SelectedPoint.R_Position,
  972. };
  973. await Robot.CalibMotionAsync(rpoint, 0);
  974. await Robot.CalibParameAsync(new PickInfo() { Inhal = Inhal, Blow = 1 }, 20, 20, true, 200, 200);
  975. //打开吸真空
  976. await Robot.CalibOutIOAsync(true);
  977. await Task.Delay(500);
  978. rpoint.Z = 0;
  979. await Robot.CalibMotionAsync(rpoint, 0);
  980. if (DialogHost.IsDialogOpen("RootDialog"))
  981. {
  982. DialogHost.Close("RootDialog");
  983. }
  984. await task;
  985. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = "取料完成!", Duration = 0.4 });
  986. }
  987. catch (Exception ex)
  988. {
  989. LogHelper.WriteLogError("取料时出错!", ex);
  990. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
  991. }
  992. }
  993. bool CanExecuteCommandGoPickCommandName()
  994. {
  995. return SelectedPoint != null;
  996. }
  997. ToolCoord toolCoord = null;
  998. double _FixedUpCameraTempletAngle = 0;
  999. double _MoveCameraTempletAngle = 0;
  1000. PointF _PutPoint = new PointF();
  1001. /// <summary>
  1002. /// 去二次定位
  1003. /// </summary>
  1004. async void ExecuteGoRepositionCommand()
  1005. {
  1006. try
  1007. {
  1008. if (SelectedPoint == null)
  1009. {
  1010. return;
  1011. }
  1012. if (Robot == null || !Robot.IsConnected)
  1013. {
  1014. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = "机器人未连接,无法执行二次定位!", Duration = 1 });
  1015. return;
  1016. }
  1017. if (MessageBox.Show("确认要执行下相机拍产二次定位吗?", "去下相机拍照", MessageBoxButton.YesNo, MessageBoxImage.Question) != MessageBoxResult.Yes)
  1018. {
  1019. return;
  1020. }
  1021. var waiting = new WaitingControl();
  1022. //show the dialog
  1023. var task = DialogHost.Show(waiting, "RootDialog", null, null, null);
  1024. // 1. 控制机器人移动至拍照点位
  1025. var rpoint = new RPoint()
  1026. {
  1027. X = SelectedPoint.X_Position,
  1028. Y = SelectedPoint.Y_Position,
  1029. Z = SelectedPoint.Z_Position_Start,
  1030. U = SelectedPoint.U_Position,
  1031. V = SelectedPoint.R_Position,
  1032. };
  1033. await Robot.CalibMotionAsync(rpoint, 0);
  1034. await Task.Delay(200);
  1035. //获取固定向上相机1的流程
  1036. var process1 = _productService.GetCurrentProductProcedureModelById(SelectProduct.FixedUpCamera1ProcedureId);
  1037. if (process1 == null)
  1038. {
  1039. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = $"固定向上相机1视觉流程,流程ID:{SelectProduct.FixedUpCamera1ProcedureId} 未找到!", Duration = 1 });
  1040. if (DialogHost.IsDialogOpen("RootDialog"))
  1041. {
  1042. DialogHost.Close("RootDialog");
  1043. }
  1044. await task;
  1045. return;
  1046. }
  1047. //获取固定向上相机2的流程
  1048. var process2 = _productService.GetCurrentProductProcedureModelById(SelectProduct.FixedUpCamera2ProcedureId);
  1049. if (process2 == null)
  1050. {
  1051. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = $"固定向上相机2视觉流程,流程ID:{SelectProduct.FixedUpCamera2ProcedureId} 未找到!", Duration = 1 });
  1052. if (DialogHost.IsDialogOpen("RootDialog"))
  1053. {
  1054. DialogHost.Close("RootDialog");
  1055. }
  1056. await task;
  1057. return;
  1058. }
  1059. // 执行视觉任务
  1060. var _cts = new CancellationTokenSource();
  1061. var task1 = _remoteCommandService.ExecutePhotoGetSinglePoint(process1, null, new double[] { rpoint.X, rpoint.Y, rpoint.U }, _cts.Token);
  1062. var task2 = _remoteCommandService.ExecutePhotoGetSinglePoint(process2, null, new double[] { rpoint.X, rpoint.Y, rpoint.U }, _cts.Token);
  1063. var visionResults = await Task.WhenAll(task1, task2);
  1064. if (visionResults[0].IsSucceed && visionResults[1].IsSucceed)
  1065. {
  1066. float toolX = (float)(visionResults[0].X + visionResults[1].X) / 2;
  1067. float toolY = (float)(visionResults[0].Y + visionResults[1].Y) / 2;
  1068. _FixedUpCameraTempletAngle = Common.CalculateAngleBetweenPointsDegrees(new PointF((float)visionResults[0].X, (float)visionResults[0].Y), new PointF((float)visionResults[1].X, (float)visionResults[1].Y));
  1069. toolCoord = new ToolCoord();
  1070. toolCoord.SetTool(toolX, toolY);
  1071. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = "视觉定位成功!", Duration = 0.4 });
  1072. if (DialogHost.IsDialogOpen("RootDialog"))
  1073. {
  1074. DialogHost.Close("RootDialog");
  1075. }
  1076. await task;
  1077. return;
  1078. }
  1079. else
  1080. {
  1081. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = "视觉定位失败,无法进行二次定位!", Duration = 1 });
  1082. if (DialogHost.IsDialogOpen("RootDialog"))
  1083. {
  1084. DialogHost.Close("RootDialog");
  1085. }
  1086. await task;
  1087. return;
  1088. }
  1089. }
  1090. catch (Exception ex)
  1091. {
  1092. LogHelper.WriteLogError("二次定位时出错!", ex);
  1093. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
  1094. if (DialogHost.IsDialogOpen("RootDialog"))
  1095. {
  1096. DialogHost.Close("RootDialog");
  1097. }
  1098. }
  1099. }
  1100. /// <summary>
  1101. /// 执行产品拍照
  1102. /// </summary>
  1103. async void ExecuteTakeProductPhotoCommand()
  1104. {
  1105. try
  1106. {
  1107. if (SelectedPoint == null)
  1108. {
  1109. return;
  1110. }
  1111. if (Robot == null || !Robot.IsConnected)
  1112. {
  1113. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = "机器人未连接,无法执行产品拍照!", Duration = 1 });
  1114. return;
  1115. }
  1116. if (MessageBox.Show("确认要执行产品拍照吗?", "去产品位置拍照", MessageBoxButton.YesNo, MessageBoxImage.Question) != MessageBoxResult.Yes)
  1117. {
  1118. return;
  1119. }
  1120. //如果二次定位的工具坐标为空,则提示用户先进行二次定位
  1121. if (toolCoord == null)
  1122. {
  1123. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = "二次定位的工具坐标为空,无法执行产品拍照!", Duration = 1 });
  1124. return;
  1125. }
  1126. var waiting = new WaitingControl();
  1127. //show the dialog
  1128. var task = DialogHost.Show(waiting, "RootDialog", null, null, null);
  1129. // 1. 控制机器人移动至拍照点位
  1130. var rpoint = new RPoint()
  1131. {
  1132. X = SelectedPoint.X_Position,
  1133. Y = SelectedPoint.Y_Position,
  1134. Z = SelectedPoint.Z_Position_Start,
  1135. U = SelectedPoint.U_Position,
  1136. V = SelectedPoint.R_Position,
  1137. };
  1138. await Robot.CalibMotionAsync(rpoint, 0);
  1139. await Task.Delay(200);
  1140. //获取移动向下相机1的流程
  1141. var process1 = _productService.GetCurrentProductProcedureModelById(SelectProduct.MoveDownCamera1LockPhotoProcedureId);
  1142. if (process1 == null)
  1143. {
  1144. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = $"移动向下相机1视觉流程,流程ID:{SelectProduct.MoveDownCamera1LockPhotoProcedureId} 未找到!", Duration = 1 });
  1145. if (DialogHost.IsDialogOpen("RootDialog"))
  1146. {
  1147. DialogHost.Close("RootDialog");
  1148. }
  1149. await task;
  1150. return;
  1151. }
  1152. //获取移动向下相机2的流程
  1153. var process2 = _productService.GetCurrentProductProcedureModelById(SelectProduct.MoveDownCamera2LockPhotoProcedureId);
  1154. if (process2 == null)
  1155. {
  1156. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = $"移动向下相机2视觉流程,流程ID:{SelectProduct.MoveDownCamera2LockPhotoProcedureId} 未找到!", Duration = 1 });
  1157. if (DialogHost.IsDialogOpen("RootDialog"))
  1158. {
  1159. DialogHost.Close("RootDialog");
  1160. }
  1161. await task;
  1162. return;
  1163. }
  1164. // 执行视觉任务
  1165. var _cts = new CancellationTokenSource();
  1166. var task1 = _remoteCommandService.ExecutePhotoGetSinglePoint(process1, null, new double[] { rpoint.X, rpoint.Y, rpoint.U }, _cts.Token);
  1167. var task2 = _remoteCommandService.ExecutePhotoGetSinglePoint(process2, null, new double[] { rpoint.X, rpoint.Y, rpoint.U }, _cts.Token);
  1168. var visionResults = await Task.WhenAll(task1, task2);
  1169. if (visionResults[0].IsSucceed && visionResults[1].IsSucceed)
  1170. {
  1171. float centerX = (float)(visionResults[0].X + visionResults[1].X) / 2;
  1172. float centerY = (float)(visionResults[0].Y + visionResults[1].Y) / 2;
  1173. _MoveCameraTempletAngle = Common.CalculateAngleBetweenPointsDegrees(new PointF((float)visionResults[0].X, (float)visionResults[0].Y), new PointF((float)visionResults[1].X, (float)visionResults[1].Y));
  1174. _PutPoint = new PointF(centerX, centerY);
  1175. if (DialogHost.IsDialogOpen("RootDialog"))
  1176. {
  1177. DialogHost.Close("RootDialog");
  1178. }
  1179. await task;
  1180. return;
  1181. }
  1182. else
  1183. {
  1184. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = "视觉定位失败,无法进行产品拍照!", Duration = 1 });
  1185. if (DialogHost.IsDialogOpen("RootDialog"))
  1186. {
  1187. DialogHost.Close("RootDialog");
  1188. }
  1189. await task;
  1190. return;
  1191. }
  1192. }
  1193. catch (Exception ex)
  1194. {
  1195. LogHelper.WriteLogError("执行产品拍照时出错!", ex);
  1196. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
  1197. if (DialogHost.IsDialogOpen("RootDialog"))
  1198. {
  1199. DialogHost.Close("RootDialog");
  1200. }
  1201. }
  1202. }
  1203. /// <summary>
  1204. /// 执行产品贴敷
  1205. /// </summary>
  1206. async void ExecuteTakeProductCommand()
  1207. {
  1208. try
  1209. {
  1210. if (SelectedPoint == null)
  1211. {
  1212. return;
  1213. }
  1214. if (Robot == null || !Robot.IsConnected)
  1215. {
  1216. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = "机器人未连接,无法执行产品贴敷!", Duration = 1 });
  1217. return;
  1218. }
  1219. if (MessageBox.Show("确认要执行产品贴敷吗?", "去产品贴敷", MessageBoxButton.YesNo, MessageBoxImage.Question) != MessageBoxResult.Yes)
  1220. {
  1221. return;
  1222. }
  1223. //如果二次定位的工具坐标为空,则提示用户先进行二次定位
  1224. if (toolCoord == null)
  1225. {
  1226. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = "二次定位的工具坐标为空,无法执行产品拍照!", Duration = 1 });
  1227. return;
  1228. }
  1229. if (_PutPoint.X == 0 && _PutPoint.Y == 0)
  1230. {
  1231. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = "检测到未定位产品", Duration = 1 });
  1232. return;
  1233. }
  1234. var waiting = new WaitingControl();
  1235. //show the dialog
  1236. var task = DialogHost.Show(waiting, "RootDialog", null, null, null);
  1237. var pn = Vector<double>.Build.Dense(new double[] { _PutPoint.X, _PutPoint.Y });
  1238. //目标角度:
  1239. double angle = SelectedPoint.U_Position + (_FixedUpCameraTempletAngle - SelectProduct.FixedUpCameraTempletAngle) + (_MoveCameraTempletAngle - SelectProduct.MoveDownCamerTempletAngle);
  1240. //将_PutPoint转换为Tool0下要走的点
  1241. var p0 = toolCoord.GetTool0Coord(pn, angle);
  1242. // 1. 控制机器人移动至拍照点位
  1243. var rpoint = new RPoint()
  1244. {
  1245. X = (float)p0[0],
  1246. Y = (float)p0[1],
  1247. Z = SelectedPoint.Z_Position_Start,
  1248. U = (float)angle,
  1249. V = SelectedPoint.R_Position,
  1250. };
  1251. await Robot.CalibMotionAsync(rpoint, 0);
  1252. if (DialogHost.IsDialogOpen("RootDialog"))
  1253. {
  1254. DialogHost.Close("RootDialog");
  1255. }
  1256. await task;
  1257. return;
  1258. }
  1259. catch (Exception ex)
  1260. {
  1261. LogHelper.WriteLogError("执行产品贴敷时出错!", ex);
  1262. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
  1263. if (DialogHost.IsDialogOpen("RootDialog"))
  1264. {
  1265. DialogHost.Close("RootDialog");
  1266. }
  1267. }
  1268. }
  1269. /// <summary>
  1270. /// 附加轴+点动
  1271. /// </summary>
  1272. /// <param name="obj"></param>
  1273. async void ExecuteAdditionalAxisJogPlusCommand(object obj)
  1274. {
  1275. if (Robot == null || !Robot.IsConnected) return;
  1276. try
  1277. {
  1278. if (obj is AxisExtended axis)
  1279. {
  1280. //如果移动距离大于10mm,则提示用户确认
  1281. if (Math.Abs(Distance) >= 10)
  1282. {
  1283. if (MessageBox.Show($"确认要点动距离 {Distance} mm 吗?", "确认点动", MessageBoxButton.YesNo, MessageBoxImage.Question) != MessageBoxResult.Yes)
  1284. {
  1285. return;
  1286. }
  1287. }
  1288. await Robot.AdditionalAxisJogAsync(axis.Name, Distance);
  1289. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = $"{Lang.完成}!", Duration = 0.4 });
  1290. }
  1291. }
  1292. catch (Exception ex)
  1293. {
  1294. LogHelper.WriteLogError("附加轴点动+时出错!", ex);
  1295. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
  1296. }
  1297. }
  1298. /// <summary>
  1299. /// 附加轴-点动
  1300. /// </summary>
  1301. /// <param name="obj"></param>
  1302. async void ExecuteAdditionalAxisJogMinusCommand(object obj)
  1303. {
  1304. if (Robot == null || !Robot.IsConnected) return;
  1305. try
  1306. {
  1307. if (obj is AxisExtended axis)
  1308. {
  1309. //如果移动距离大于10mm,则提示用户确认
  1310. if (Math.Abs(Distance) >= 10)
  1311. {
  1312. if (MessageBox.Show($"确认要点动距离 {Distance} mm 吗?", "确认点动", MessageBoxButton.YesNo, MessageBoxImage.Question) != MessageBoxResult.Yes)
  1313. {
  1314. return;
  1315. }
  1316. }
  1317. await Robot.AdditionalAxisJogNegAsync(axis.Name, Distance);
  1318. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = $"{Lang.完成}!", Duration = 0.4 });
  1319. }
  1320. }
  1321. catch (Exception ex)
  1322. {
  1323. LogHelper.WriteLogError("附加轴点动-时出错!", ex);
  1324. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
  1325. }
  1326. }
  1327. /// <summary>
  1328. /// 附加轴下使能
  1329. /// </summary>
  1330. /// <param name="obj"></param>
  1331. async void ExecuteAdditionalAxisMotorOffCommand(object obj)
  1332. {
  1333. if (Robot == null || !Robot.IsConnected) return;
  1334. try
  1335. {
  1336. if (obj is AxisExtended axis)
  1337. {
  1338. await Robot.AdditionalAxisMotorAsync(axis.Name, false);
  1339. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = $"{Lang.完成}!", Duration = 0.4 });
  1340. }
  1341. }
  1342. catch (Exception ex)
  1343. {
  1344. LogHelper.WriteLogError("附加轴上使能时出错!", ex);
  1345. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
  1346. }
  1347. }
  1348. /// <summary>
  1349. /// 附加轴上使能
  1350. /// </summary>
  1351. /// <param name="obj"></param>
  1352. async void ExecuteAdditionalAxisMotorOnCommand(object obj)
  1353. {
  1354. if (Robot == null || !Robot.IsConnected) return;
  1355. try
  1356. {
  1357. if (obj is AxisExtended axis)
  1358. {
  1359. await Robot.AdditionalAxisMotorAsync(axis.Name, true);
  1360. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = $"{Lang.完成}!", Duration = 0.4 });
  1361. }
  1362. }
  1363. catch (Exception ex)
  1364. {
  1365. LogHelper.WriteLogError("附加轴下使能时出错!", ex);
  1366. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
  1367. }
  1368. }
  1369. /// <summary>
  1370. /// 移动取料托盘点
  1371. /// </summary>
  1372. async void ExecutePickMoveCommand(string parameter)
  1373. {
  1374. if (Robot == null || !Robot.IsConnected) return;
  1375. try
  1376. {
  1377. //弹窗用户是否确认要示教该点位
  1378. if (MessageBox.Show($"确认要移动取料点位 {parameter} 吗?", "移动点位", MessageBoxButton.YesNo, MessageBoxImage.Question) != MessageBoxResult.Yes)
  1379. {
  1380. return;
  1381. }
  1382. int index = int.Parse(parameter);
  1383. var curpos = await Robot.GetRobotPosAsync();
  1384. var addpos = await Robot.GetAdditionalAxisCurrentPosAsync(Robot.AdditionalAxisList[0].Name);
  1385. if (index == 1)
  1386. {
  1387. curpos.Z = 0;
  1388. await Robot.CalibMotionAsync(curpos, 0);
  1389. await Robot.AdditionalAxisMoveAsync(Robot.AdditionalAxisList[0].Name, PickP1.Z_Position_Stop);
  1390. curpos.X = PickP1.X_Position;
  1391. curpos.Y = PickP1.Y_Position;
  1392. curpos.Z = PickP1.Z_Position_Start;
  1393. curpos.U = PickP1.U_Position;
  1394. await Robot.CalibMotionAsync(curpos, 0);
  1395. }
  1396. else if (index == 2)
  1397. {
  1398. curpos.Z = 0;
  1399. await Robot.CalibMotionAsync(curpos, 0);
  1400. await Robot.AdditionalAxisMoveAsync(Robot.AdditionalAxisList[0].Name, PickP2.Z_Position_Stop);
  1401. curpos.X = PickP2.X_Position;
  1402. curpos.Y = PickP2.Y_Position;
  1403. curpos.Z = PickP2.Z_Position_Start;
  1404. curpos.U = PickP2.U_Position;
  1405. await Robot.CalibMotionAsync(curpos, 0);
  1406. }
  1407. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = $"{Lang.完成}!", Duration = 0.4 });
  1408. }
  1409. catch (Exception ex)
  1410. {
  1411. LogHelper.WriteLogError("示教取料托盘点时出错!", ex);
  1412. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
  1413. }
  1414. }
  1415. /// <summary>
  1416. /// 示教取料托盘点
  1417. /// </summary>
  1418. /// <param name="parameter"></param>
  1419. async void ExecutePickTechCommand(string parameter)
  1420. {
  1421. if (Robot == null || !Robot.IsConnected) return;
  1422. try
  1423. {
  1424. //弹窗用户是否确认要示教该点位
  1425. if (MessageBox.Show($"确认要示教取料点位 {parameter} 吗?", "示教点位", MessageBoxButton.YesNo, MessageBoxImage.Question) != MessageBoxResult.Yes)
  1426. {
  1427. return;
  1428. }
  1429. int index = int.Parse(parameter);
  1430. var curpos = await Robot.GetRobotPosAsync();
  1431. var addpos = await Robot.GetAdditionalAxisCurrentPosAsync(Robot.AdditionalAxisList[0].Name);
  1432. if (index == 1)
  1433. {
  1434. PickP1.X_Position = curpos.X;
  1435. PickP1.Y_Position = curpos.Y;
  1436. PickP1.Z_Position_Start = curpos.Z;
  1437. PickP1.U_Position = curpos.U;
  1438. PickP1.Z_Position_Stop = addpos;
  1439. }
  1440. else if (index == 2)
  1441. {
  1442. PickP2.X_Position = curpos.X;
  1443. PickP2.Y_Position = curpos.Y;
  1444. PickP2.Z_Position_Start = curpos.Z;
  1445. PickP2.U_Position = curpos.U;
  1446. PickP2.Z_Position_Stop = addpos;
  1447. }
  1448. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = $"{Lang.完成}!", Duration = 0.4 });
  1449. }
  1450. catch (Exception ex)
  1451. {
  1452. LogHelper.WriteLogError("示教取料托盘点时出错!", ex);
  1453. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
  1454. }
  1455. }
  1456. /// <summary>
  1457. /// 计算所有托盘点
  1458. /// </summary>
  1459. void ExecuteCalPickPosCommand()
  1460. {
  1461. try
  1462. {
  1463. if (ColumnNum < 1)
  1464. {
  1465. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = $"请设置托盘列数!", Duration = 1 });
  1466. return;
  1467. }
  1468. //弹窗用户是否确认要示教该点位
  1469. if (MessageBox.Show($"确认要计算托盘 吗?", "计算托盘", MessageBoxButton.YesNo, MessageBoxImage.Question) != MessageBoxResult.Yes)
  1470. {
  1471. return;
  1472. }
  1473. //托盘间隔
  1474. double invt = (PickP2.Z_Position_Stop - PickP1.Z_Position_Stop) / (ColumnNum - 1);
  1475. for (int i = 0; i < ColumnNum; i++)
  1476. {
  1477. if (Points.Count - 1 <= i)
  1478. {
  1479. Points[i].Number = i + 1;
  1480. Points[i].X_Position = PickP1.X_Position;
  1481. Points[i].X_Velocity = 100;
  1482. Points[i].Y_Position = PickP1.Y_Position;
  1483. Points[i].Y_Velocity = 100;
  1484. Points[i].Z_Position_Start = PickP1.Z_Position_Start;
  1485. Points[i].Z_Velocity_Start = 100;
  1486. Points[i].U_Position = PickP1.U_Position;
  1487. Points[i].U_Velocity = 100;
  1488. Points[i].Z_Position_Stop = (float)(PickP1.Z_Position_Stop + i * invt);
  1489. Points[i].Z_Velocity_Stop = 100;
  1490. }
  1491. else
  1492. {
  1493. Points.Add(new PlcPoint()
  1494. {
  1495. Number= i + 1,
  1496. X_Position = PickP1.X_Position,
  1497. X_Velocity = 100,
  1498. Y_Position = PickP1.Y_Position,
  1499. Y_Velocity = 100,
  1500. Z_Position_Start = PickP1.Z_Position_Start,
  1501. Z_Velocity_Start = 100,
  1502. U_Position = PickP1.U_Position,
  1503. U_Velocity = 100,
  1504. Z_Position_Stop = (float)(PickP1.Z_Position_Stop + i * invt),
  1505. Z_Velocity_Stop = 100
  1506. });
  1507. }
  1508. }
  1509. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = $"{Lang.完成}!", Duration = 0.4 });
  1510. }
  1511. catch (Exception ex)
  1512. {
  1513. LogHelper.WriteLogError("示教取料托盘点时出错!", ex);
  1514. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
  1515. }
  1516. }
  1517. #endregion
  1518. #region 继承
  1519. /// <summary>
  1520. /// 确认导航请求时调用。此方法允许您在导航之前执行一些操作。
  1521. /// </summary>
  1522. /// <param name="navigationContext"></param>
  1523. /// <param name="continuationCallback"></param>
  1524. public void ConfirmNavigationRequest(NavigationContext navigationContext, Action<bool> continuationCallback)
  1525. {
  1526. continuationCallback(true);
  1527. }
  1528. /// <summary>
  1529. /// 接收导航请求时调用。传入导航参数,包含有关导航目标的信息。
  1530. /// </summary>
  1531. /// <param name="navigationContext"></param>
  1532. /// <exception cref="NotImplementedException"></exception>
  1533. public async void OnNavigatedTo(NavigationContext navigationContext)
  1534. {
  1535. try
  1536. {
  1537. toolCoord = null;
  1538. _PutPoint = new PointF();
  1539. SelectProduct = navigationContext.Parameters.GetValue<ProductModel>("SelectProduct");
  1540. SelectedIndex = 0;
  1541. Points = SelectProduct.PickCameraPoints;
  1542. if (Robot == null)
  1543. {
  1544. Robot = _robotService.GetRobotByNumber(1) as XYZU_Robot;
  1545. }
  1546. if (Robot != null && Robot.IsConnected)
  1547. {
  1548. this.Distance = _configService.GetRobotStepDistance(Robot.Id);
  1549. Robot.EnterDebugMode = true;
  1550. AdditionalAxisList = Robot.AdditionalAxisList;
  1551. }
  1552. else if (Robot != null)
  1553. {
  1554. Robot.EnterDebugMode = true;
  1555. }
  1556. ProcedureModels = new ObservableCollection<ProcedureModel>();
  1557. foreach (var item in SelectProduct.CameraProcedures)
  1558. {
  1559. foreach (var item1 in item.ProcedureModels)
  1560. {
  1561. ProcedureModels.Add(item1);
  1562. }
  1563. }
  1564. CameraList = new ObservableCollection<CameraInfo>(_configService.GetAllCameras());
  1565. if (SelectProduct.PickPoints!=null && SelectProduct.PickPoints.Count>0)
  1566. {
  1567. PickP1 = SelectProduct.PickPoints.FirstOrDefault().Clone();
  1568. PickP2 = SelectProduct.PickPoints.LastOrDefault().Clone();
  1569. ColumnNum = SelectProduct.PickPoints.Count;
  1570. }
  1571. }
  1572. catch (Exception ex)
  1573. {
  1574. LogHelper.WriteLogError("机器人点位界面进入时出错!", ex);
  1575. }
  1576. }
  1577. /// <summary>
  1578. /// 是否允许导航到此视图模型。
  1579. /// </summary>
  1580. /// <param name="navigationContext"></param>
  1581. /// <returns></returns>
  1582. public bool IsNavigationTarget(NavigationContext navigationContext)
  1583. {
  1584. return true;
  1585. }
  1586. /// <summary>
  1587. /// 导航离开此视图模型时调用。您可以在此处执行清理操作或保存状态。
  1588. /// </summary>
  1589. /// <param name="navigationContext"></param>
  1590. public void OnNavigatedFrom(NavigationContext navigationContext)
  1591. {
  1592. //if (Robot != null)
  1593. //{
  1594. // Robot.EnterDebugMode = false;
  1595. //}
  1596. try
  1597. {
  1598. IsGrap = false;
  1599. if (Camera != null)
  1600. {
  1601. if (Camera.IsGrabbing)
  1602. {
  1603. Camera.StopGrabbing();
  1604. }
  1605. Camera.ImageCallbackEvent -= Camera_ImageCallbackEvent;
  1606. Camera = null;
  1607. }
  1608. SelectedCamera = null;
  1609. IsLeftDrawerOpen = false;
  1610. }
  1611. catch (Exception)
  1612. {
  1613. }
  1614. }
  1615. #endregion
  1616. private bool _IsAllowEdit = false;
  1617. public bool IsAllowEdit
  1618. {
  1619. get { return _IsAllowEdit; }
  1620. set { SetProperty(ref _IsAllowEdit, value); }
  1621. }
  1622. private void LoginChange(Models.User user)
  1623. {
  1624. if (user.userPart == Enums.UserPart.Operator)
  1625. {
  1626. IsAllowEdit = false;
  1627. }
  1628. else
  1629. {
  1630. IsAllowEdit = true;
  1631. }
  1632. }
  1633. }
  1634. }