DriveServoViewModel.cs 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897
  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; //kkm 주석
  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 ExecuteBreakOffCommand()
  257. {
  258. if (isBreakOff)
  259. this.vcSystem.IO.OutputOff("OUT_DRIVE_BRAKE_OFF");
  260. else
  261. this.vcSystem.IO.OutputOn("OUT_DRIVE_BRAKE_OFF");
  262. }
  263. private void EzIO_OnChangedIO(BitBlock bit)
  264. {
  265. if (bit.Tag.Equals("OUT_DRIVE_BRAKE_OFF"))
  266. this.IsBreakOff = bit.IsBitOn;
  267. }
  268. private void InitializeData()
  269. {
  270. this.CurrentMCR = this.zmqManager.CurrentMCR;
  271. this.CurrentTag = this.zmqManager.CurrentPointNo.ToString();
  272. this.DriveAutoReadyState(this.zmqManager.IsCanStanbyLocation);
  273. this.UpdateDriveState(this.zmqManager.DriveState);
  274. if (hostManager.IsConnected)
  275. {
  276. this.OcsState = eOcsState.Connect;
  277. }
  278. if(!zmqManager.IsTCZ) //Kkm TCZ -> None 변경
  279. this.IsTCZ = eTCZState.None;
  280. if (!vcSystem.ZmqManager.SetOperationState(eOperatationMode.ManualMode))
  281. messageController.ShowNotificationView("Drive Manual Mode Change Fail", false);
  282. }
  283. void UpdateDriveState(eDriveState state)
  284. {
  285. this.DriveState = state;
  286. //switch ( state )
  287. //{
  288. // case eDriveState.None:
  289. // this.DriveOnStateBrush = Brushes.Gray;
  290. // break;
  291. // case eDriveState.ServoOff:
  292. // this.DriveOnStateBrush = Brushes.Gray;
  293. // break;
  294. // case eDriveState.ServoOn:
  295. // this.DriveOnStateBrush = Brushes.LimeGreen;
  296. // this.DriveFaultStateBrush = Brushes.DodgerBlue;
  297. // break;
  298. // case eDriveState.Fault:
  299. // this.DriveFaultStateBrush = Brushes.Red;
  300. // this.DriveOnStateBrush = Brushes.Gray;
  301. // break;
  302. // default:
  303. // break;
  304. //}
  305. }
  306. private void ZmqManager_PropertyChanged(object sender , System.ComponentModel.PropertyChangedEventArgs e)
  307. {
  308. var property = sender.GetType().GetProperty( e.PropertyName );
  309. var newValue = property.GetValue( sender , null );
  310. switch ( e.PropertyName )
  311. {
  312. case "CurrentPointNo":
  313. this.CurrentTag = CastTo<int>.From<object>( newValue ).ToString();
  314. break;
  315. case "CurrentMCR":
  316. this.CurrentMCR = CastTo<string>.From<object>( newValue );
  317. break;
  318. case "IsCanStanbyLocation":
  319. {
  320. var result = CastTo<bool>.From<object>( newValue );
  321. DriveAutoReadyState( result );
  322. }
  323. break;
  324. case "DriveState":
  325. {
  326. var result = CastTo<eDriveState>.From<object>( newValue );
  327. this.UpdateDriveState( result );
  328. }
  329. break;
  330. default:
  331. break;
  332. }
  333. }
  334. private void ExecuteSteeringMove(object obj)
  335. {
  336. var msg = new DriveControlEventArgs
  337. {
  338. EventDir = DriveControlEventArgs.eEventDir.ToBack ,
  339. ControlKind = DriveControlEventArgs.eControlKind.Steering ,
  340. };
  341. if ( obj.ToString().Equals( "CW" ) )
  342. msg.MoveDir = DriveControlEventArgs.eMoveDir.LEFT;
  343. else
  344. msg.MoveDir = DriveControlEventArgs.eMoveDir.RIGHT;
  345. this.PublishEvent( msg );
  346. }
  347. private void UICallBackCommunication(GUIMessageEventArgs obj)
  348. {
  349. if ( obj.Kind == GUIMessageEventArgs.eGUIMessageKind.ModelPropertyChange )
  350. {
  351. if ( obj.MessageKey.Equals( MessageKey.Vehicle ) )
  352. {
  353. switch ( obj.ModelPropertyName )
  354. {
  355. case "SteeringState":
  356. {
  357. var dir = CastTo<eSteeringState>.From<object>( obj.Args );
  358. this.ChangeSteeringDirection( dir );
  359. }
  360. break;
  361. case "VehicleStateProperty":
  362. {
  363. var v = CastTo<eVehicleState>.From<object>( obj.Args );
  364. this.ChagneVehicleState( v );
  365. }
  366. break;
  367. case "CurrentPosition":
  368. {
  369. var v = CastTo<double>.From<object>( obj.Args );
  370. this.CurrentPosition = v;
  371. }
  372. break;
  373. case "CurrentSpeed":
  374. break;
  375. case "CurrentTorque":
  376. break;
  377. default:
  378. break;
  379. }
  380. }
  381. }
  382. if ( obj.Kind == GUIMessageEventArgs.eGUIMessageKind.RspRouteManager )
  383. {
  384. }
  385. }
  386. void DriveAutoReadyState(bool state)
  387. {
  388. if ( state )
  389. {
  390. this.AutoReadyFlag = "OK";
  391. this.AutoReadyFlagColor = Brushes.LimeGreen;
  392. }
  393. else
  394. {
  395. this.AutoReadyFlag = "NG";
  396. this.AutoReadyFlagColor = Brushes.Gray;
  397. }
  398. }
  399. private void ChagneVehicleState(eVehicleState v)
  400. {
  401. switch ( v )
  402. {
  403. case eVehicleState.None:
  404. break;
  405. case eVehicleState.Idle:
  406. break;
  407. case eVehicleState.Move:
  408. break;
  409. case eVehicleState.Load:
  410. break;
  411. case eVehicleState.Unload:
  412. break;
  413. case eVehicleState.Charge:
  414. break;
  415. case eVehicleState.Abnormal:
  416. break;
  417. case eVehicleState.Blocked:
  418. break;
  419. case eVehicleState.Decelerate:
  420. break;
  421. }
  422. }
  423. private void DriveControlCallBack(DriveControlEventArgs args)
  424. {
  425. if ( args.EventDir == DriveControlEventArgs.eEventDir.ToFront )
  426. {
  427. switch ( args.ControlKind )
  428. {
  429. case DriveControlEventArgs.eControlKind.MOVE:
  430. ResponseMove( args );
  431. break;
  432. case DriveControlEventArgs.eControlKind.STOP:
  433. break;
  434. case DriveControlEventArgs.eControlKind.Steering:
  435. //if ( args.Result.IsSuccess )
  436. //{
  437. // var dir = args.Result.ToResult<eSteeringState>().Value;
  438. // this.ChangeSteeringDirection( dir );
  439. //}
  440. break;
  441. case DriveControlEventArgs.eControlKind.SteeringState:
  442. if ( args.Result.IsSuccess )
  443. {
  444. var dir = CastTo<eSteeringState>.From<object>( args.Args );
  445. this.ChangeSteeringDirection( dir );
  446. }
  447. else
  448. {
  449. this.ChangeSteeringDirection( eSteeringState.None );
  450. }
  451. break;
  452. case DriveControlEventArgs.eControlKind.ReqCurrentPos:
  453. this.CurrentPosition = args.CurrentPosition;
  454. break;
  455. case DriveControlEventArgs.eControlKind.ReqStopCurrentPos:
  456. break;
  457. case DriveControlEventArgs.eControlKind.FaultReset:
  458. if (args.Result.IsSuccess)
  459. this.messageController.ShowNotificationView("Fault Reset Success");
  460. else
  461. this.messageController.ShowNotificationView("Fault Reset Fail", false);
  462. break;
  463. case DriveControlEventArgs.eControlKind.DriveON:
  464. if (args.Result.IsSuccess)
  465. {
  466. this.messageController.ShowNotificationView("Drive On Success");
  467. }
  468. else
  469. {
  470. this.messageController.ShowNotificationView("Drive On Fail", false);
  471. }
  472. break;
  473. case DriveControlEventArgs.eControlKind.DriveOFF:
  474. break;
  475. case DriveControlEventArgs.eControlKind.JOG:
  476. break;
  477. case DriveControlEventArgs.eControlKind.VehicleState:
  478. ResponseVehicleState( args );
  479. break;
  480. default:
  481. break;
  482. }
  483. }
  484. }
  485. private void ResponseVehicleState(DriveControlEventArgs args)
  486. {
  487. var state = CastTo<VehicleInfo>.From<object>( args.Args );
  488. this.CurrentPosition = state.CurrentPosition;
  489. }
  490. private void ResponseMove(DriveControlEventArgs args)
  491. {
  492. var msg = string.Empty;
  493. if ( args.Result.IsSuccess )
  494. {
  495. msg = "Move Success";
  496. }
  497. else
  498. {
  499. var error = args.Result.Errors.FirstOrDefault();
  500. var alarm = error.Metadata[ "Alarm" ] as Alarm;
  501. msg = alarm.Name + " " + alarm.Text;
  502. }
  503. this.messageController.ShowNotificationView( msg );
  504. }
  505. void PublishEvent(DriveControlEventArgs args)
  506. {
  507. args.EventDir = DriveControlEventArgs.eEventDir.ToBack;
  508. this.eventAggregator.GetEvent<DriveControlPubSubEvent>().Publish( args );
  509. }
  510. void ChangeSteeringDirection(eSteeringState state)
  511. {
  512. if ( state == eSteeringState.Left )
  513. {
  514. this.SteeringLeftBrushProperty = ( Brush )new BrushConverter().ConvertFromString( "#FF00FFD3" );
  515. this.SteeringRightBrushProperty = Brushes.Gray;
  516. }
  517. else if ( state == eSteeringState.Right )
  518. {
  519. this.SteeringLeftBrushProperty = Brushes.Gray;
  520. this.SteeringRightBrushProperty = ( Brush )new BrushConverter().ConvertFromString( "#FF00FFD3" );
  521. }
  522. else
  523. {
  524. this.SteeringLeftBrushProperty = Brushes.Gray;
  525. this.SteeringRightBrushProperty = Brushes.Gray;
  526. }
  527. }
  528. #region Execute Method
  529. private void OcsConnectCallBack(HostConnectedEventArgs obj)
  530. {
  531. var state = obj.State;
  532. switch (state)
  533. {
  534. case HostConnectedEventArgs.eConnectedState.Connected:
  535. this.OcsState = eOcsState.Connect;
  536. break;
  537. case HostConnectedEventArgs.eConnectedState.Disconnected:
  538. this.OcsState = eOcsState.DisConnect;
  539. break;
  540. }
  541. }
  542. private void TCZStateCallBack(TCZEventArgs obj)
  543. {
  544. var state = obj.TCZState;
  545. switch (state)
  546. {
  547. case TCZEventArgs.eTCZState.TCZ: //Kkm TCZEventArgs 추가
  548. this.IsTCZ = eTCZState.TCZ;
  549. break;
  550. case TCZEventArgs.eTCZState.None:
  551. this.IsTCZ = eTCZState.None;
  552. break;
  553. }
  554. }
  555. private void ExecuteJogCommand(object obj)
  556. {
  557. if ( this.JogVelocity <= 0 )
  558. {
  559. this.messageController.ShowNotificationView( "Check Jog Velocity" );
  560. return;
  561. }
  562. if(this.vcSystem.vehicle.IsChargeCylinderForword())
  563. {
  564. this.messageController.ShowNotificationView("Battery Charge Cylinder FWD !");
  565. return;
  566. }
  567. var msg = new DriveControlEventArgs
  568. {
  569. EventDir = DriveControlEventArgs.eEventDir.ToBack ,
  570. ControlKind = DriveControlEventArgs.eControlKind.JOG ,
  571. };
  572. if ( obj.ToString().Equals( "+" ) )
  573. msg.JogDir = DriveControlEventArgs.eJogMoveDir.Positive;
  574. else
  575. msg.JogDir = DriveControlEventArgs.eJogMoveDir.Negative;
  576. this.PublishEvent( msg );
  577. }
  578. private void ExecuteJogVelPopupCommand()
  579. {
  580. var numPad = new CalcuratorView();
  581. var result = numPad.ShowDialog( this.JogVelocity );
  582. this.JogVelocity = result;
  583. }
  584. private void ExecuteSelectedDirection(object obj)
  585. {
  586. this.SelectDirection = obj.ToString();
  587. }
  588. private void ExecutePositionSaveCommand()
  589. {
  590. this.messageController.ShowConfirmationPopupView("Save To Data ?", r =>
  591. {
  592. if (r.Result == ButtonResult.OK)
  593. {
  594. var result = this.RouteList.Any(x => x.IsSelected != false);
  595. if (!result)
  596. {
  597. this.messageController.ShowNotificationView("Pos Not Selected");
  598. return;
  599. }
  600. var ll = this.RouteList.Where(x => x.IsSelected).FirstOrDefault();
  601. }
  602. });
  603. }
  604. private void ExecutePositionDeleteCommand()
  605. {
  606. this.messageController.ShowConfirmationPopupView( "Select To Delete ?" , r =>
  607. {
  608. if ( r.Result == ButtonResult.OK )
  609. {
  610. var deleteList = new List<Route>();
  611. foreach ( var item in this.RouteList )
  612. {
  613. if ( item.IsSelected )
  614. deleteList.Add( item );
  615. }
  616. deleteList.ForEach( x => { this.RouteList.Remove( x ); } );
  617. }
  618. } );
  619. }
  620. private void ExecutePositionAddCommand()
  621. {
  622. this.messageController.ShowConfirmationPopupView( "Position Add ?" , r =>
  623. {
  624. if ( r.Result == ButtonResult.OK )
  625. {
  626. this.RouteList.Add( new Route() );
  627. this.messageController.ShowNotificationView( "Create Success" );
  628. }
  629. } );
  630. }
  631. private void ExecuteKeyInCommadn(object obj)
  632. {
  633. var numPad = new CalcuratorView();
  634. var result = numPad.ShowDialog( this.DriveTargetPos );
  635. this.DriveTargetPos = result;
  636. }
  637. private void ExecuteOriginCommand()
  638. {
  639. this.messageController.ShowConfirmationPopupView( "Origin ?" , r =>
  640. {
  641. if ( r.Result == ButtonResult.OK )
  642. {
  643. }
  644. } );
  645. }
  646. private void ExecuteFaultResetCommand()
  647. {
  648. var msg = new DriveControlEventArgs
  649. {
  650. EventDir = DriveControlEventArgs.eEventDir.ToBack ,
  651. ControlKind = DriveControlEventArgs.eControlKind.FaultReset ,
  652. };
  653. this.PublishEvent( msg );
  654. }
  655. private void ExecuteServoOffCommand()
  656. {
  657. var msg = new DriveControlEventArgs
  658. {
  659. EventDir = DriveControlEventArgs.eEventDir.ToBack ,
  660. ControlKind = DriveControlEventArgs.eControlKind.DriveOFF ,
  661. };
  662. this.PublishEvent( msg );
  663. }
  664. private void ExecuteServoOnCommand()
  665. {
  666. //this.IsBusy = true;
  667. var msg = new DriveControlEventArgs
  668. {
  669. EventDir = DriveControlEventArgs.eEventDir.ToBack ,
  670. ControlKind = DriveControlEventArgs.eControlKind.DriveON ,
  671. };
  672. this.PublishEvent( msg );
  673. }
  674. private void ExecuteCurrentToTargetCommand()
  675. {
  676. this.messageController.ShowConfirmationPopupView( "Current To Target ?" , r =>
  677. {
  678. if ( r.Result == ButtonResult.OK )
  679. {
  680. this.DriveTargetPos = this.CurrentPosition;
  681. }
  682. } );
  683. }
  684. private void ExecuteMoveToCommand()
  685. {
  686. this.messageController.ShowConfirmationPopupView( "Move To Selected Position ?" , r =>
  687. {
  688. if ( r.Result == ButtonResult.OK )
  689. {
  690. var result = this.RouteList.Any( x => x.IsSelected != false );
  691. if ( !result )
  692. {
  693. this.messageController.ShowNotificationView( "Pos Not Selected" );
  694. return;
  695. }
  696. var ll = this.RouteList.Where( x => x.IsSelected ).FirstOrDefault();
  697. var msg = new DriveControlEventArgs
  698. {
  699. EventDir = DriveControlEventArgs.eEventDir.ToBack ,
  700. ControlKind = DriveControlEventArgs.eControlKind.MOVE ,
  701. TargetRouteID = ll.Id ,
  702. };
  703. this.PublishEvent( msg );
  704. }
  705. } );
  706. }
  707. private void ExecuteSelectPosCommand(object obj)
  708. {
  709. this.SelectedPosition = obj.ToString();
  710. }
  711. #endregion
  712. #region Dialog Function
  713. public bool CanCloseDialog()
  714. {
  715. return true;
  716. }
  717. public void OnDialogClosed()
  718. {
  719. this.eventAggregator.GetEvent<DriveControlPubSubEvent>().Publish( new DriveControlEventArgs { EventDir = DriveControlEventArgs.eEventDir.ToBack , ControlKind = DriveControlEventArgs.eControlKind.ReqStopCurrentPos } );
  720. this.eventAggregator.GetEvent<DriveControlPubSubEvent>().Unsubscribe( DriveControlCallBack );
  721. this.eventAggregator.GetEvent<GUIMessagePubSubEvent>().Unsubscribe( UICallBackCommunication );
  722. }
  723. public async void OnDialogOpened(IDialogParameters parameters)
  724. {
  725. Task task = Task.Run( () =>
  726. {
  727. var msg = new DriveControlEventArgs
  728. {
  729. EventDir = DriveControlEventArgs.eEventDir.ToBack ,
  730. ControlKind = DriveControlEventArgs.eControlKind.SteeringState ,
  731. };
  732. this.PublishEvent( msg );
  733. this.eventAggregator.GetEvent<DriveControlPubSubEvent>().Publish( new DriveControlEventArgs { EventDir = DriveControlEventArgs.eEventDir.ToBack , ControlKind = DriveControlEventArgs.eControlKind.VehicleState } );
  734. var vcsMsg = new VCSMessageEventArgs() { Kind = VCSMessageEventArgs.eVCSMessageKind.ReqRouteManager };
  735. this.eventAggregator.GetEvent<VCSMessagePubSubEvent>().Publish( vcsMsg );
  736. //var sT = SwUtils.CurrentTimeMillis;
  737. //this.RouteList = new ObservableCollection<Route>(sql.RouteDal.GetAll());
  738. //Console.WriteLine( SwUtils.Elapsed( sT ) );
  739. });
  740. this.InitializeData();
  741. await task;
  742. }
  743. private void CloseDialog(string parameter)
  744. {
  745. ButtonResult result = ButtonResult.None;
  746. if ( parameter?.ToLower() == "true" )
  747. result = ButtonResult.OK;
  748. else if ( parameter?.ToLower() == "false" )
  749. result = ButtonResult.Cancel;
  750. RaiseRequestClose( new DialogResult( result ) );
  751. }
  752. public virtual void RaiseRequestClose(IDialogResult dialogResult)
  753. {
  754. RequestClose?.Invoke( dialogResult );
  755. }
  756. #endregion
  757. }
  758. }