DriveServoViewModel.cs 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903
  1. using GSG.NET.Concurrent;
  2. using GSG.NET.Extensions;
  3. using GSG.NET.Utils;
  4. using MaterialDesignThemes.Wpf;
  5. using OHV.Common.Events;
  6. using OHV.Common.Model;
  7. using OHV.Common.Shareds;
  8. using OHV.SqliteDAL;
  9. using Prism.Commands;
  10. using Prism.Events;
  11. using Prism.Mvvm;
  12. using Prism.Services.Dialogs;
  13. using System;
  14. using System.Collections.Generic;
  15. using System.Collections.ObjectModel;
  16. using System.Linq;
  17. using System.Threading.Tasks;
  18. using System.Windows.Controls;
  19. using System.Windows.Input;
  20. using System.Windows.Media;
  21. using VehicleControlSystem;
  22. using VehicleControlSystem.ControlLayer;
  23. using VehicleControlSystem.ControlLayer.IO;
  24. using VehicleControlSystem.ControlLayer.MQ;
  25. using VehicleControlSystem.Managers;
  26. using static OHV.Common.Events.TCZEventArgs;
  27. namespace OHV.Module.Interactivity.PopUp
  28. {
  29. public class DriveServoViewModel : BindableBase, IDialogAware
  30. {
  31. private DelegateCommand<string> _closeDialogCommand;
  32. public DelegateCommand<string> CloseDialogCommand =>
  33. _closeDialogCommand ?? ( _closeDialogCommand = new DelegateCommand<string>( CloseDialog ) );
  34. private string _title = "DriveServoView";
  35. public string Title
  36. {
  37. get { return this._title; }
  38. set
  39. {
  40. this.SetProperty( ref this._title , value );
  41. }
  42. }
  43. private string _selectedPosition = string.Empty;
  44. public string SelectedPosition
  45. {
  46. get => this._selectedPosition;
  47. set
  48. {
  49. this.SetProperty( ref this._selectedPosition , value );
  50. }
  51. }
  52. private string _selectDirection = string.Empty;
  53. public string SelectDirection
  54. {
  55. get => this._selectDirection;
  56. set { this.SetProperty( ref this._selectDirection , value ); }
  57. }
  58. private eDriveState driveState;
  59. public eDriveState DriveState
  60. {
  61. get { return driveState; }
  62. set { SetProperty(ref this.driveState, value); }
  63. }
  64. private bool isBreakOff;
  65. public bool IsBreakOff
  66. {
  67. get { return isBreakOff; }
  68. set { SetProperty(ref this.isBreakOff, value); }
  69. }
  70. #region Motor Left Binding Value
  71. private double _driveTargetPos;
  72. public double DriveTargetPos
  73. {
  74. get { return this._driveTargetPos; }
  75. set { this.SetProperty( ref this._driveTargetPos , value ); }
  76. }
  77. private double _currentPosition;
  78. /// <summary>
  79. /// * Drive Current Position
  80. /// </summary>
  81. public double CurrentPosition
  82. {
  83. get { return this._currentPosition; }
  84. set { this.SetProperty( ref this._currentPosition , value ); }
  85. }
  86. private double _differenceDrive;
  87. public double DifferenceDrive
  88. {
  89. get { return this._differenceDrive; }
  90. set { this.SetProperty( ref this._differenceDrive , value ); }
  91. }
  92. private double _jogVelocity = 3.0;
  93. public double JogVelocity
  94. {
  95. get { return this._jogVelocity; }
  96. set { this.SetProperty( ref this._jogVelocity , value ); }
  97. }
  98. #endregion
  99. public event Action<IDialogResult> RequestClose;
  100. #region Commands
  101. public ICommand SelectAxisCommand { get; set; }
  102. public ICommand KeyInTargetPosCommand { get; set; }
  103. public ICommand SelectPosCommand { get; set; }
  104. public ICommand MoveToCommand { get; set; }
  105. public ICommand CurrentToTargetCommand { get; set; }
  106. public ICommand ServoOnCommand { get; set; }
  107. public ICommand ServoOffCommand { get; set; }
  108. public ICommand FaultResetCommand { get; set; }
  109. public ICommand OriginCommand { get; set; }
  110. public IEventAggregator eventAggregator;
  111. public ICommand PositionAddCommand { get; set; }
  112. public ICommand PositionDeleteCommand { get; set; }
  113. public ICommand PositionSaveCommand { get; set; }
  114. public ICommand SteeringMoveCommand { get; set; }
  115. public ICommand SelectedDirection { get; set; }
  116. public ICommand JogVelPopupCommand { get; set; }
  117. public ICommand JogCommand { get; set; }
  118. public ICommand BreakOffCommand { get; set; }
  119. #endregion
  120. #region Brushes
  121. private Brush steeringLeftBrush = Brushes.Gray;
  122. public Brush SteeringLeftBrushProperty
  123. {
  124. get { return steeringLeftBrush; }
  125. set { SetProperty( ref this.steeringLeftBrush , value ); }
  126. }
  127. private Brush steeringRightBrush = Brushes.Gray;
  128. public Brush SteeringRightBrushProperty
  129. {
  130. get { return steeringRightBrush; }
  131. set { SetProperty( ref this.steeringRightBrush , value ); }
  132. }
  133. Brush driveOnStateBrush = Brushes.DodgerBlue;
  134. public Brush DriveOnStateBrush
  135. {
  136. get { return this.driveOnStateBrush; }
  137. set { SetProperty( ref this.driveOnStateBrush , value ); }
  138. }
  139. Brush driveOffStateBrush = Brushes.DodgerBlue;
  140. public Brush DriveOffStateBrush
  141. {
  142. get { return this.driveOffStateBrush; }
  143. set { SetProperty( ref this.driveOffStateBrush , value ); }
  144. }
  145. private Brush driveFaultStateBrush = Brushes.DodgerBlue;
  146. public Brush DriveFaultStateBrush
  147. {
  148. get { return driveFaultStateBrush; }
  149. set { SetProperty( ref this.driveFaultStateBrush , value ); }
  150. }
  151. #endregion
  152. #region Property
  153. private ObservableCollection<Route> _routeList;
  154. public ObservableCollection<Route> RouteList
  155. {
  156. get { return this._routeList; }
  157. set { SetProperty(ref this._routeList, value); }
  158. }
  159. private string autoReadyFlag = "NG";
  160. public string AutoReadyFlag
  161. {
  162. get { return autoReadyFlag; }
  163. set { this.SetProperty(ref this.autoReadyFlag, value); }
  164. }
  165. Brush autoReadyFlagColor = Brushes.Gray;
  166. public Brush AutoReadyFlagColor
  167. {
  168. get { return this.autoReadyFlagColor; }
  169. set { this.SetProperty(ref this.autoReadyFlagColor, value); }
  170. }
  171. private string currentMCR = "None";
  172. public string CurrentMCR
  173. {
  174. get { return currentMCR; }
  175. set { this.SetProperty(ref this.currentMCR, value); }
  176. }
  177. private string currentTag = "None";
  178. public string CurrentTag
  179. {
  180. get { return currentTag; }
  181. set { SetProperty(ref this.currentTag, value); }
  182. }
  183. private bool isBusy;
  184. public bool IsBusy
  185. {
  186. get { return isBusy; }
  187. set { SetProperty(ref this.isBusy, value); }
  188. }
  189. private string busyText;
  190. public string BusyText
  191. {
  192. get { return busyText; }
  193. set { SetProperty(ref this.busyText, value); }
  194. }
  195. eOcsState ocsState = eOcsState.DisConnect;
  196. public eOcsState OcsState
  197. {
  198. get { return this.ocsState; }
  199. set { this.SetProperty(ref this.ocsState, value); }
  200. }
  201. eTCZState isTCZ = eTCZState.None;
  202. public eTCZState IsTCZ
  203. {
  204. get { return this.isTCZ; }
  205. set { this.SetProperty(ref this.isTCZ, value); }
  206. }
  207. eOperatationMode operationMode = eOperatationMode.ManualMode;
  208. public eOperatationMode OperationMode
  209. {
  210. get { return this.operationMode; }
  211. set { this.SetProperty(ref this.operationMode, value); }
  212. }
  213. #endregion
  214. VCSystem vcSystem;
  215. ZmqManager zmqManager;
  216. HostManager hostManager;
  217. SqliteManager sql;
  218. MessageController messageController;
  219. public DriveServoViewModel(IEventAggregator _ea , SqliteManager _sql , MessageController _messageController , VCSystem system)
  220. {
  221. this.eventAggregator = _ea;
  222. this.eventAggregator.GetEvent<DriveControlPubSubEvent>().Unsubscribe( DriveControlCallBack );
  223. this.eventAggregator.GetEvent<DriveControlPubSubEvent>().Subscribe( DriveControlCallBack , ThreadOption.UIThread );
  224. this.eventAggregator.GetEvent<GUIMessagePubSubEvent>().Unsubscribe( UICallBackCommunication );
  225. this.eventAggregator.GetEvent<GUIMessagePubSubEvent>().Subscribe( UICallBackCommunication , ThreadOption.UIThread );
  226. this.eventAggregator.GetEvent<HostConnectedPubSubEvent>().Unsubscribe(OcsConnectCallBack);
  227. this.eventAggregator.GetEvent<HostConnectedPubSubEvent>().Subscribe(OcsConnectCallBack, ThreadOption.UIThread);
  228. this.eventAggregator.GetEvent<TCZStatePubsubEvent>().Unsubscribe(TCZStateCallBack);
  229. this.eventAggregator.GetEvent<TCZStatePubsubEvent>().Subscribe(TCZStateCallBack, ThreadOption.UIThread);
  230. this.sql = _sql;
  231. this.messageController = _messageController;
  232. this.vcSystem = system;
  233. this.zmqManager = system.ZmqManager;
  234. system.ZmqManager.PropertyChanged += ZmqManager_PropertyChanged;
  235. this.hostManager = system.hostManager;
  236. this.SelectPosCommand = new DelegateCommand<object>( ExecuteSelectPosCommand );
  237. this.MoveToCommand = new DelegateCommand( ExecuteMoveToCommand );
  238. this.CurrentToTargetCommand = new DelegateCommand( ExecuteCurrentToTargetCommand );
  239. this.KeyInTargetPosCommand = new DelegateCommand<object>( ExecuteKeyInCommadn );
  240. this.ServoOnCommand = new DelegateCommand( ExecuteServoOnCommand );
  241. this.ServoOffCommand = new DelegateCommand( ExecuteServoOffCommand );
  242. this.FaultResetCommand = new DelegateCommand( ExecuteFaultResetCommand );
  243. this.OriginCommand = new DelegateCommand( ExecuteOriginCommand );
  244. this.PositionAddCommand = new DelegateCommand( ExecutePositionAddCommand );
  245. this.PositionDeleteCommand = new DelegateCommand( ExecutePositionDeleteCommand );
  246. this.PositionSaveCommand = new DelegateCommand( ExecutePositionSaveCommand );
  247. this.SelectedDirection = new DelegateCommand<object>( ExecuteSelectedDirection );
  248. this.SteeringMoveCommand = new DelegateCommand<object>( ExecuteSteeringMove );
  249. this.JogVelPopupCommand = new DelegateCommand( ExecuteJogVelPopupCommand );
  250. this.JogCommand = new DelegateCommand<object>( ExecuteJogCommand );
  251. this.BreakOffCommand = new DelegateCommand(ExecuteBreakOffCommand);
  252. this.IsBreakOff = this.vcSystem.IO.IsOn("OUT_DRIVE_BRAKE_OFF", false);
  253. var ezIO = this.vcSystem.IO as EzIO;
  254. ezIO.OnChangedIO += EzIO_OnChangedIO;
  255. }
  256. private void TCZStateCallBack(TCZEventArgs obj)
  257. {
  258. var state = obj.TCZState;
  259. switch (state)
  260. {
  261. case eTCZState.TCZ:
  262. this.IsTCZ = eTCZState.TCZ;
  263. break;
  264. case eTCZState.None:
  265. this.IsTCZ = eTCZState.None;
  266. break;
  267. }
  268. }
  269. private void ExecuteBreakOffCommand()
  270. {
  271. if (isBreakOff)
  272. this.vcSystem.IO.OutputOff("OUT_DRIVE_BRAKE_OFF");
  273. else
  274. this.vcSystem.IO.OutputOn("OUT_DRIVE_BRAKE_OFF");
  275. }
  276. private void EzIO_OnChangedIO(BitBlock bit)
  277. {
  278. if (bit.Tag.Equals("OUT_DRIVE_BRAKE_OFF"))
  279. this.IsBreakOff = bit.IsBitOn;
  280. }
  281. private void InitializeData()
  282. {
  283. this.CurrentMCR = this.zmqManager.CurrentMCR;
  284. this.CurrentTag = this.zmqManager.CurrentPointNo.ToString();
  285. this.DriveAutoReadyState(this.zmqManager.IsCanStanbyLocation);
  286. this.UpdateDriveState(this.zmqManager.DriveState);
  287. if (hostManager.IsConnected)
  288. {
  289. this.OcsState = eOcsState.Connect;
  290. }
  291. //if (vcSystem.ZmqManager.SetOperationState(eOperatationMode.ManualMode))
  292. //{
  293. // if (!zmqManager.IsTCZ)
  294. // {
  295. // this.IsTCZ = eTCZState.TCZ;
  296. // }
  297. //}
  298. if (!vcSystem.ZmqManager.SetOperationState(eOperatationMode.ManualMode))
  299. messageController.ShowNotificationView("Drive Manual Mode Change Fail", false);
  300. }
  301. void UpdateDriveState(eDriveState state)
  302. {
  303. this.DriveState = state;
  304. //switch ( state )
  305. //{
  306. // case eDriveState.None:
  307. // this.DriveOnStateBrush = Brushes.Gray;
  308. // break;
  309. // case eDriveState.ServoOff:
  310. // this.DriveOnStateBrush = Brushes.Gray;
  311. // break;
  312. // case eDriveState.ServoOn:
  313. // this.DriveOnStateBrush = Brushes.LimeGreen;
  314. // this.DriveFaultStateBrush = Brushes.DodgerBlue;
  315. // break;
  316. // case eDriveState.Fault:
  317. // this.DriveFaultStateBrush = Brushes.Red;
  318. // this.DriveOnStateBrush = Brushes.Gray;
  319. // break;
  320. // default:
  321. // break;
  322. //}
  323. }
  324. private void ZmqManager_PropertyChanged(object sender , System.ComponentModel.PropertyChangedEventArgs e)
  325. {
  326. var property = sender.GetType().GetProperty( e.PropertyName );
  327. var newValue = property.GetValue( sender , null );
  328. switch ( e.PropertyName )
  329. {
  330. case "CurrentPointNo":
  331. this.CurrentTag = CastTo<int>.From<object>( newValue ).ToString();
  332. break;
  333. case "CurrentMCR":
  334. this.CurrentMCR = CastTo<string>.From<object>( newValue );
  335. break;
  336. case "IsCanStanbyLocation":
  337. {
  338. var result = CastTo<bool>.From<object>( newValue );
  339. DriveAutoReadyState( result );
  340. }
  341. break;
  342. case "DriveState":
  343. {
  344. var result = CastTo<eDriveState>.From<object>( newValue );
  345. this.UpdateDriveState( result );
  346. }
  347. break;
  348. default:
  349. break;
  350. }
  351. }
  352. private void ExecuteSteeringMove(object obj)
  353. {
  354. var msg = new DriveControlEventArgs
  355. {
  356. EventDir = DriveControlEventArgs.eEventDir.ToBack ,
  357. ControlKind = DriveControlEventArgs.eControlKind.Steering ,
  358. };
  359. if ( obj.ToString().Equals( "CW" ) )
  360. msg.MoveDir = DriveControlEventArgs.eMoveDir.LEFT;
  361. else
  362. msg.MoveDir = DriveControlEventArgs.eMoveDir.RIGHT;
  363. this.PublishEvent( msg );
  364. }
  365. private void UICallBackCommunication(GUIMessageEventArgs obj)
  366. {
  367. if ( obj.Kind == GUIMessageEventArgs.eGUIMessageKind.ModelPropertyChange )
  368. {
  369. if ( obj.MessageKey.Equals( MessageKey.Vehicle ) )
  370. {
  371. switch ( obj.ModelPropertyName )
  372. {
  373. case "SteeringState":
  374. {
  375. var dir = CastTo<eSteeringState>.From<object>( obj.Args );
  376. this.ChangeSteeringDirection( dir );
  377. }
  378. break;
  379. case "VehicleStateProperty":
  380. {
  381. var v = CastTo<eVehicleState>.From<object>( obj.Args );
  382. this.ChagneVehicleState( v );
  383. }
  384. break;
  385. case "CurrentPosition":
  386. {
  387. var v = CastTo<double>.From<object>( obj.Args );
  388. this.CurrentPosition = v;
  389. }
  390. break;
  391. case "CurrentSpeed":
  392. break;
  393. case "CurrentTorque":
  394. break;
  395. default:
  396. break;
  397. }
  398. }
  399. }
  400. if ( obj.Kind == GUIMessageEventArgs.eGUIMessageKind.RspRouteManager )
  401. {
  402. }
  403. }
  404. void DriveAutoReadyState(bool state)
  405. {
  406. if ( state )
  407. {
  408. this.AutoReadyFlag = "OK";
  409. this.AutoReadyFlagColor = Brushes.LimeGreen;
  410. }
  411. else
  412. {
  413. this.AutoReadyFlag = "NG";
  414. this.AutoReadyFlagColor = Brushes.Gray;
  415. }
  416. }
  417. private void ChagneVehicleState(eVehicleState v)
  418. {
  419. switch ( v )
  420. {
  421. case eVehicleState.None:
  422. break;
  423. case eVehicleState.Idle:
  424. break;
  425. case eVehicleState.Move:
  426. break;
  427. case eVehicleState.Load:
  428. break;
  429. case eVehicleState.Unload:
  430. break;
  431. case eVehicleState.Charge:
  432. break;
  433. case eVehicleState.Abnormal:
  434. break;
  435. case eVehicleState.Blocked:
  436. break;
  437. case eVehicleState.Decelerate:
  438. break;
  439. }
  440. }
  441. private void DriveControlCallBack(DriveControlEventArgs args)
  442. {
  443. if ( args.EventDir == DriveControlEventArgs.eEventDir.ToFront )
  444. {
  445. switch ( args.ControlKind )
  446. {
  447. case DriveControlEventArgs.eControlKind.MOVE:
  448. ResponseMove( args );
  449. break;
  450. case DriveControlEventArgs.eControlKind.STOP:
  451. break;
  452. case DriveControlEventArgs.eControlKind.Steering:
  453. //if ( args.Result.IsSuccess )
  454. //{
  455. // var dir = args.Result.ToResult<eSteeringState>().Value;
  456. // this.ChangeSteeringDirection( dir );
  457. //}
  458. break;
  459. case DriveControlEventArgs.eControlKind.SteeringState:
  460. if ( args.Result.IsSuccess )
  461. {
  462. var dir = CastTo<eSteeringState>.From<object>( args.Args );
  463. this.ChangeSteeringDirection( dir );
  464. }
  465. else
  466. {
  467. this.ChangeSteeringDirection( eSteeringState.None );
  468. }
  469. break;
  470. case DriveControlEventArgs.eControlKind.ReqCurrentPos:
  471. this.CurrentPosition = args.CurrentPosition;
  472. break;
  473. case DriveControlEventArgs.eControlKind.ReqStopCurrentPos:
  474. break;
  475. case DriveControlEventArgs.eControlKind.FaultReset:
  476. if (args.Result.IsSuccess)
  477. this.messageController.ShowNotificationView("Fault Reset Success");
  478. else
  479. this.messageController.ShowNotificationView("Fault Reset Fail", false);
  480. break;
  481. case DriveControlEventArgs.eControlKind.DriveON:
  482. if (args.Result.IsSuccess)
  483. {
  484. this.messageController.ShowNotificationView("Drive On Success");
  485. }
  486. else
  487. {
  488. this.messageController.ShowNotificationView("Drive On Fail", false);
  489. }
  490. break;
  491. case DriveControlEventArgs.eControlKind.DriveOFF:
  492. break;
  493. case DriveControlEventArgs.eControlKind.JOG:
  494. break;
  495. case DriveControlEventArgs.eControlKind.VehicleState:
  496. ResponseVehicleState( args );
  497. break;
  498. default:
  499. break;
  500. }
  501. }
  502. }
  503. private void ResponseVehicleState(DriveControlEventArgs args)
  504. {
  505. var state = CastTo<VehicleInfo>.From<object>( args.Args );
  506. this.CurrentPosition = state.CurrentPosition;
  507. }
  508. private void ResponseMove(DriveControlEventArgs args)
  509. {
  510. var msg = string.Empty;
  511. if ( args.Result.IsSuccess )
  512. {
  513. msg = "Move Success";
  514. }
  515. else
  516. {
  517. var error = args.Result.Errors.FirstOrDefault();
  518. var alarm = error.Metadata[ "Alarm" ] as Alarm;
  519. msg = alarm.Name + " " + alarm.Text;
  520. }
  521. this.messageController.ShowNotificationView( msg );
  522. }
  523. void PublishEvent(DriveControlEventArgs args)
  524. {
  525. args.EventDir = DriveControlEventArgs.eEventDir.ToBack;
  526. this.eventAggregator.GetEvent<DriveControlPubSubEvent>().Publish( args );
  527. }
  528. void ChangeSteeringDirection(eSteeringState state)
  529. {
  530. if ( state == eSteeringState.Left )
  531. {
  532. this.SteeringLeftBrushProperty = ( Brush )new BrushConverter().ConvertFromString( "#FF00FFD3" );
  533. this.SteeringRightBrushProperty = Brushes.Gray;
  534. }
  535. else if ( state == eSteeringState.Right )
  536. {
  537. this.SteeringLeftBrushProperty = Brushes.Gray;
  538. this.SteeringRightBrushProperty = ( Brush )new BrushConverter().ConvertFromString( "#FF00FFD3" );
  539. }
  540. else
  541. {
  542. this.SteeringLeftBrushProperty = Brushes.Gray;
  543. this.SteeringRightBrushProperty = Brushes.Gray;
  544. }
  545. }
  546. #region Execute Method
  547. private void OcsConnectCallBack(HostConnectedEventArgs obj)
  548. {
  549. var state = obj.State;
  550. switch (state)
  551. {
  552. case HostConnectedEventArgs.eConnectedState.Connected:
  553. this.OcsState = eOcsState.Connect;
  554. break;
  555. case HostConnectedEventArgs.eConnectedState.Disconnected:
  556. this.OcsState = eOcsState.DisConnect;
  557. break;
  558. }
  559. }
  560. private void ExecuteJogCommand(object obj)
  561. {
  562. if ( this.JogVelocity <= 0 )
  563. {
  564. this.messageController.ShowNotificationView( "Check Jog Velocity" );
  565. return;
  566. }
  567. if(this.vcSystem.vehicle.IsChargeCylinderForword())
  568. {
  569. this.messageController.ShowNotificationView("Battery Charge Cylinder FWD !");
  570. return;
  571. }
  572. var msg = new DriveControlEventArgs
  573. {
  574. EventDir = DriveControlEventArgs.eEventDir.ToBack ,
  575. ControlKind = DriveControlEventArgs.eControlKind.JOG ,
  576. };
  577. if ( obj.ToString().Equals( "+" ) )
  578. msg.JogDir = DriveControlEventArgs.eJogMoveDir.Positive;
  579. else
  580. msg.JogDir = DriveControlEventArgs.eJogMoveDir.Negative;
  581. this.PublishEvent( msg );
  582. }
  583. private void ExecuteJogVelPopupCommand()
  584. {
  585. var numPad = new CalcuratorView();
  586. var result = numPad.ShowDialog( this.JogVelocity );
  587. this.JogVelocity = result;
  588. }
  589. private void ExecuteSelectedDirection(object obj)
  590. {
  591. this.SelectDirection = obj.ToString();
  592. }
  593. private void ExecutePositionSaveCommand()
  594. {
  595. this.messageController.ShowConfirmationPopupView("Save To Data ?", r =>
  596. {
  597. if (r.Result == ButtonResult.OK)
  598. {
  599. var result = this.RouteList.Any(x => x.IsSelected != false);
  600. if (!result)
  601. {
  602. this.messageController.ShowNotificationView("Pos Not Selected");
  603. return;
  604. }
  605. var ll = this.RouteList.Where(x => x.IsSelected).FirstOrDefault();
  606. }
  607. });
  608. }
  609. private void ExecutePositionDeleteCommand()
  610. {
  611. this.messageController.ShowConfirmationPopupView( "Select To Delete ?" , r =>
  612. {
  613. if ( r.Result == ButtonResult.OK )
  614. {
  615. var deleteList = new List<Route>();
  616. foreach ( var item in this.RouteList )
  617. {
  618. if ( item.IsSelected )
  619. deleteList.Add( item );
  620. }
  621. deleteList.ForEach( x => { this.RouteList.Remove( x ); } );
  622. }
  623. } );
  624. }
  625. private void ExecutePositionAddCommand()
  626. {
  627. this.messageController.ShowConfirmationPopupView( "Position Add ?" , r =>
  628. {
  629. if ( r.Result == ButtonResult.OK )
  630. {
  631. this.RouteList.Add( new Route() );
  632. this.messageController.ShowNotificationView( "Create Success" );
  633. }
  634. } );
  635. }
  636. private void ExecuteKeyInCommadn(object obj)
  637. {
  638. var numPad = new CalcuratorView();
  639. var result = numPad.ShowDialog( this.DriveTargetPos );
  640. this.DriveTargetPos = result;
  641. }
  642. private void ExecuteOriginCommand()
  643. {
  644. this.messageController.ShowConfirmationPopupView( "Origin ?" , r =>
  645. {
  646. if ( r.Result == ButtonResult.OK )
  647. {
  648. }
  649. } );
  650. }
  651. private void ExecuteFaultResetCommand()
  652. {
  653. var msg = new DriveControlEventArgs
  654. {
  655. EventDir = DriveControlEventArgs.eEventDir.ToBack ,
  656. ControlKind = DriveControlEventArgs.eControlKind.FaultReset ,
  657. };
  658. this.PublishEvent( msg );
  659. }
  660. private void ExecuteServoOffCommand()
  661. {
  662. var msg = new DriveControlEventArgs
  663. {
  664. EventDir = DriveControlEventArgs.eEventDir.ToBack ,
  665. ControlKind = DriveControlEventArgs.eControlKind.DriveOFF ,
  666. };
  667. this.PublishEvent( msg );
  668. }
  669. private void ExecuteServoOnCommand()
  670. {
  671. //this.IsBusy = true;
  672. var msg = new DriveControlEventArgs
  673. {
  674. EventDir = DriveControlEventArgs.eEventDir.ToBack ,
  675. ControlKind = DriveControlEventArgs.eControlKind.DriveON ,
  676. };
  677. this.PublishEvent( msg );
  678. }
  679. private void ExecuteCurrentToTargetCommand()
  680. {
  681. this.messageController.ShowConfirmationPopupView( "Current To Target ?" , r =>
  682. {
  683. if ( r.Result == ButtonResult.OK )
  684. {
  685. this.DriveTargetPos = this.CurrentPosition;
  686. }
  687. } );
  688. }
  689. private void ExecuteMoveToCommand()
  690. {
  691. this.messageController.ShowConfirmationPopupView( "Move To Selected Position ?" , r =>
  692. {
  693. if ( r.Result == ButtonResult.OK )
  694. {
  695. var result = this.RouteList.Any( x => x.IsSelected != false );
  696. if ( !result )
  697. {
  698. this.messageController.ShowNotificationView( "Pos Not Selected" );
  699. return;
  700. }
  701. var ll = this.RouteList.Where( x => x.IsSelected ).FirstOrDefault();
  702. var msg = new DriveControlEventArgs
  703. {
  704. EventDir = DriveControlEventArgs.eEventDir.ToBack ,
  705. ControlKind = DriveControlEventArgs.eControlKind.MOVE ,
  706. TargetRouteID = ll.Id ,
  707. };
  708. this.PublishEvent( msg );
  709. }
  710. } );
  711. }
  712. private void ExecuteSelectPosCommand(object obj)
  713. {
  714. this.SelectedPosition = obj.ToString();
  715. }
  716. #endregion
  717. #region Dialog Function
  718. public bool CanCloseDialog()
  719. {
  720. return true;
  721. }
  722. public void OnDialogClosed()
  723. {
  724. this.eventAggregator.GetEvent<DriveControlPubSubEvent>().Publish( new DriveControlEventArgs { EventDir = DriveControlEventArgs.eEventDir.ToBack , ControlKind = DriveControlEventArgs.eControlKind.ReqStopCurrentPos } );
  725. this.eventAggregator.GetEvent<DriveControlPubSubEvent>().Unsubscribe( DriveControlCallBack );
  726. this.eventAggregator.GetEvent<GUIMessagePubSubEvent>().Unsubscribe( UICallBackCommunication );
  727. }
  728. public async void OnDialogOpened(IDialogParameters parameters)
  729. {
  730. Task task = Task.Run( () =>
  731. {
  732. var msg = new DriveControlEventArgs
  733. {
  734. EventDir = DriveControlEventArgs.eEventDir.ToBack ,
  735. ControlKind = DriveControlEventArgs.eControlKind.SteeringState ,
  736. };
  737. this.PublishEvent( msg );
  738. this.eventAggregator.GetEvent<DriveControlPubSubEvent>().Publish( new DriveControlEventArgs { EventDir = DriveControlEventArgs.eEventDir.ToBack , ControlKind = DriveControlEventArgs.eControlKind.VehicleState } );
  739. var vcsMsg = new VCSMessageEventArgs() { Kind = VCSMessageEventArgs.eVCSMessageKind.ReqRouteManager };
  740. this.eventAggregator.GetEvent<VCSMessagePubSubEvent>().Publish( vcsMsg );
  741. //var sT = SwUtils.CurrentTimeMillis;
  742. //this.RouteList = new ObservableCollection<Route>(sql.RouteDal.GetAll());
  743. //Console.WriteLine( SwUtils.Elapsed( sT ) );
  744. });
  745. this.InitializeData();
  746. await task;
  747. }
  748. private void CloseDialog(string parameter)
  749. {
  750. ButtonResult result = ButtonResult.None;
  751. if ( parameter?.ToLower() == "true" )
  752. result = ButtonResult.OK;
  753. else if ( parameter?.ToLower() == "false" )
  754. result = ButtonResult.Cancel;
  755. RaiseRequestClose( new DialogResult( result ) );
  756. }
  757. public virtual void RaiseRequestClose(IDialogResult dialogResult)
  758. {
  759. RequestClose?.Invoke( dialogResult );
  760. }
  761. #endregion
  762. }
  763. }