DriveServoViewModel.cs 30 KB

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