OpticalReadingConfigViewModel.cs 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. using OHV.Common.Events;
  2. using Prism.Commands;
  3. using Prism.Events;
  4. using Prism.Mvvm;
  5. using Prism.Services.Dialogs;
  6. using System;
  7. using System.Collections;
  8. using System.Collections.Generic;
  9. using System.Drawing;
  10. using System.Linq;
  11. using System.Text;
  12. using System.Threading.Tasks;
  13. using System.Windows.Input;
  14. namespace OHV.Module.Interactivity.PopUp
  15. {
  16. public class OpticalReadingConfigViewModel : BindableBase, IDialogAware
  17. {
  18. private DelegateCommand<string> _closeDialogCommand;
  19. public DelegateCommand<string> CloseDialogCommand =>
  20. _closeDialogCommand ?? ( _closeDialogCommand = new DelegateCommand<string>( CloseDialog ) );
  21. Brush _opReaderOutFirst = Brushes.Gray;
  22. Brush _opReaderOutSecond = Brushes.Gray;
  23. Brush _opReaderOutThird = Brushes.Gray;
  24. public Brush OpReaderOutFirst
  25. {
  26. get { return this._opReaderOutFirst; }
  27. set { this.SetProperty( ref this._opReaderOutFirst , value ); }
  28. }
  29. public Brush OpReaderOutSecond
  30. {
  31. get { return this._opReaderOutSecond; }
  32. set { this.SetProperty( ref this._opReaderOutSecond , value ); }
  33. }
  34. public Brush OpreaderOutThird
  35. {
  36. get { return this._opReaderOutThird; }
  37. set { this.SetProperty( ref this._opReaderOutThird , value ); }
  38. }
  39. private int _curvePatternResult;
  40. public int CurvePatternResult
  41. {
  42. get { return this._curvePatternResult; }
  43. set { this.SetProperty( ref this._curvePatternResult , value ); }
  44. }
  45. private int _drivePatternResult;
  46. public int DrivePatternResult
  47. {
  48. get { return this._drivePatternResult; }
  49. set { this.SetProperty( ref this._drivePatternResult , value ); }
  50. }
  51. private bool _resultPatternOne;
  52. public bool ResultPatternOne
  53. {
  54. get { return this._resultPatternOne; }
  55. set
  56. {
  57. this.SetProperty( ref this._resultPatternOne , value );
  58. }
  59. }
  60. private bool _resultPatternTwo;
  61. public bool ResultPatternTwo
  62. {
  63. get { return this._resultPatternTwo; }
  64. set
  65. {
  66. this.SetProperty( ref this._resultPatternTwo , value );
  67. }
  68. }
  69. private bool _resultPatternThree;
  70. public bool ResultPatternThree
  71. {
  72. get { return this._resultPatternThree; }
  73. set
  74. {
  75. this.SetProperty( ref this._resultPatternThree , value );
  76. }
  77. }
  78. private bool _resultPatternFour;
  79. public bool ResultPatternFour
  80. {
  81. get { return this._resultPatternFour; }
  82. set
  83. {
  84. this.SetProperty( ref this._resultPatternFour , value );
  85. }
  86. }
  87. private bool _resultPatternFive;
  88. public bool ResultPatternFive
  89. {
  90. get { return this._resultPatternFive; }
  91. set
  92. {
  93. this.SetProperty( ref this._resultPatternFive , value );
  94. }
  95. }
  96. private string _title = "SteeringConfigView";
  97. public string Title
  98. {
  99. get { return this._title; }
  100. set
  101. {
  102. this.SetProperty( ref this._title , value );
  103. }
  104. }
  105. private int _obstacleDrive;
  106. public int ObstacleDrive
  107. {
  108. get { return this._obstacleDrive; }
  109. set { this.SetProperty( ref this._obstacleDrive , value ); }
  110. }
  111. private int _obstacleCurve;
  112. public int ObstacleCurve
  113. {
  114. get { return this._obstacleCurve; }
  115. set { this.SetProperty( ref this._obstacleCurve , value ); }
  116. }
  117. public ICommand DetectPatternSave { get; set; }
  118. public ICommand ResultPattern { get; set; }
  119. public ICommand PatternResultKyein { get; set; }
  120. public event Action<IDialogResult> RequestClose;
  121. IEventAggregator eventAggregator;
  122. MessageController messageController;
  123. public OpticalReadingConfigViewModel( IEventAggregator _ea, MessageController _msg )
  124. {
  125. this.eventAggregator = _ea;
  126. this.eventAggregator.GetEvent<GUIMessagePubSubEvent>().Unsubscribe( UICallbackCommunication );
  127. this.eventAggregator.GetEvent<GUIMessagePubSubEvent>().Subscribe( UICallbackCommunication, ThreadOption.UIThread );
  128. this.messageController = _msg;
  129. this.DetectPatternSave = new DelegateCommand( ExecuteDetectPatternSave );
  130. this.ResultPattern = new DelegateCommand<object>( ExecuteResultPattern );
  131. this.PatternResultKyein = new DelegateCommand<object>( ExecutePatternResultKyein );
  132. }
  133. private void UICallbackCommunication( GUIMessageEventArgs obj )
  134. {
  135. }
  136. private void ExecutePatternResultKyein( object obj)
  137. {
  138. var numpad = new CalcuratorView();
  139. var result = numpad.ShowDialog(0);
  140. var pattern = obj.ToString();
  141. switch(pattern)
  142. {
  143. case "C":
  144. this.CurvePatternResult = Convert.ToInt32( result );
  145. break;
  146. case "D":
  147. this.DrivePatternResult = Convert.ToInt32( result );
  148. break;
  149. }
  150. }
  151. private void ExecuteResultPattern(object _obj)
  152. {
  153. }
  154. private byte ConvertToByte( BitArray _bitArray)
  155. {
  156. byte[] bytes = new byte[ 1 ];
  157. _bitArray.CopyTo( bytes , 0 );
  158. return bytes[ 0 ];
  159. }
  160. private void ExecuteDetectPatternSave( )
  161. {
  162. this.messageController.ShowConfirmationPopupView( "Pattern Save ?" , r =>
  163. {
  164. if ( r.Result == ButtonResult.OK )
  165. {
  166. //bool[] bitResult = new bool[] { this.ResultPatternOne , this.ResultPatternTwo , this.ResultPatternThree , this.ResultPatternFour , this.ResultPatternFive };
  167. //var result = new System.Collections.BitArray( bitResult );
  168. //this.PatternResult = ConvertToByte( result );
  169. //this.Publish(this.PatternResult);
  170. }
  171. } );
  172. }
  173. #region Dialog Function
  174. public bool CanCloseDialog( )
  175. {
  176. return true;
  177. }
  178. public void OnDialogClosed( )
  179. {
  180. }
  181. public void OnDialogOpened( IDialogParameters parameters )
  182. {
  183. }
  184. private void CloseDialog( string parameter )
  185. {
  186. ButtonResult result = ButtonResult.None;
  187. if ( parameter?.ToLower() == "true" )
  188. result = ButtonResult.OK;
  189. else if ( parameter?.ToLower() == "false" )
  190. result = ButtonResult.Cancel;
  191. RaiseRequestClose( new DialogResult( result ) );
  192. }
  193. public virtual void RaiseRequestClose( IDialogResult dialogResult )
  194. {
  195. RequestClose?.Invoke( dialogResult );
  196. }
  197. #endregion
  198. }
  199. }