|
|
@@ -1,4 +1,7 @@
|
|
|
-using Prism.Commands;
|
|
|
+using OHV.Common.Events;
|
|
|
+using OHV.Common.Shareds;
|
|
|
+using Prism.Commands;
|
|
|
+using Prism.Events;
|
|
|
using Prism.Mvvm;
|
|
|
using Prism.Services.Dialogs;
|
|
|
using System;
|
|
|
@@ -12,10 +15,10 @@ namespace OHV.Module.Interactivity.PopUp
|
|
|
{
|
|
|
public class LockServoViewModel : BindableBase, IDialogAware
|
|
|
{
|
|
|
+
|
|
|
private DelegateCommand<string> _closeDialogCommand;
|
|
|
public DelegateCommand<string> CloseDialogCommand =>
|
|
|
- _closeDialogCommand ?? ( _closeDialogCommand = new DelegateCommand<string>( CloseDialog ) );
|
|
|
-
|
|
|
+ _closeDialogCommand ?? (_closeDialogCommand = new DelegateCommand<string>(CloseDialog));
|
|
|
|
|
|
private string _title = "LockServoView";
|
|
|
public string Title
|
|
|
@@ -23,7 +26,7 @@ namespace OHV.Module.Interactivity.PopUp
|
|
|
get { return this._title; }
|
|
|
set
|
|
|
{
|
|
|
- this.SetProperty( ref this._title , value );
|
|
|
+ this.SetProperty(ref this._title, value);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -31,7 +34,7 @@ namespace OHV.Module.Interactivity.PopUp
|
|
|
public string SelectAxis
|
|
|
{
|
|
|
get => this._selectAxis;
|
|
|
- set { this.SetProperty( ref this._selectAxis , value ); }
|
|
|
+ set { this.SetProperty(ref this._selectAxis, value); }
|
|
|
}
|
|
|
|
|
|
private string _selectedPosition = string.Empty;
|
|
|
@@ -40,7 +43,7 @@ namespace OHV.Module.Interactivity.PopUp
|
|
|
get => this._selectedPosition;
|
|
|
set
|
|
|
{
|
|
|
- this.SetProperty( ref this._selectedPosition , value );
|
|
|
+ this.SetProperty(ref this._selectedPosition, value);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -49,21 +52,21 @@ namespace OHV.Module.Interactivity.PopUp
|
|
|
public double TargetPosLockLeft
|
|
|
{
|
|
|
get { return this._targetPosLockLeft; }
|
|
|
- set { this.SetProperty( ref this._targetPosLockLeft , value ); }
|
|
|
+ set { this.SetProperty(ref this._targetPosLockLeft, value); }
|
|
|
}
|
|
|
|
|
|
private double _currentLockLeft;
|
|
|
public double CurrentLockLeft
|
|
|
{
|
|
|
get { return this._currentLockLeft; }
|
|
|
- set { this.SetProperty( ref this._currentLockLeft , value ); }
|
|
|
+ set { this.SetProperty(ref this._currentLockLeft, value); }
|
|
|
}
|
|
|
|
|
|
private double _differenceLockLeft;
|
|
|
public double DifferenceLockLeft
|
|
|
{
|
|
|
get { return this._differenceLockLeft; }
|
|
|
- set { this.SetProperty( ref this._differenceLockLeft , value ); }
|
|
|
+ set { this.SetProperty(ref this._differenceLockLeft, value); }
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
@@ -72,21 +75,21 @@ namespace OHV.Module.Interactivity.PopUp
|
|
|
public double TargetPosLockRight
|
|
|
{
|
|
|
get { return this._targetPosLockRight; }
|
|
|
- set { this.SetProperty( ref this._targetPosLockRight , value ); }
|
|
|
+ set { this.SetProperty(ref this._targetPosLockRight, value); }
|
|
|
}
|
|
|
|
|
|
private double _currentLockRight;
|
|
|
public double CurrentLockRight
|
|
|
{
|
|
|
get { return this._currentLockRight; }
|
|
|
- set { this.SetProperty( ref this._currentLockRight , value ); }
|
|
|
+ set { this.SetProperty(ref this._currentLockRight, value); }
|
|
|
}
|
|
|
|
|
|
private double _differenceLockRight;
|
|
|
public double DifferenceLockRight
|
|
|
{
|
|
|
get { return this._differenceLockRight; }
|
|
|
- set { this.SetProperty( ref this._differenceLockRight , value ); }
|
|
|
+ set { this.SetProperty(ref this._differenceLockRight, value); }
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
@@ -100,74 +103,138 @@ namespace OHV.Module.Interactivity.PopUp
|
|
|
public ICommand ServoOffCommand { get; set; }
|
|
|
public ICommand FaultResetCommand { get; set; }
|
|
|
public ICommand OriginCommand { get; set; }
|
|
|
+ public ICommand JogCommand { get; set; }
|
|
|
|
|
|
public event Action<IDialogResult> RequestClose;
|
|
|
|
|
|
- public LockServoViewModel( )
|
|
|
+ IEventAggregator eventAggregator;
|
|
|
+
|
|
|
+ public LockServoViewModel(IEventAggregator ea)
|
|
|
+ {
|
|
|
+ this.SelectAxisCommand = new DelegateCommand<object>(ExecuteSelectAxisCommand);
|
|
|
+ this.SelectPosCommand = new DelegateCommand<object>(ExecuteSelectPosCommand);
|
|
|
+ this.MoveToCommand = new DelegateCommand(ExecuteMoveToCommand);
|
|
|
+ this.CurrentToTargetCommand = new DelegateCommand(ExecuteCurrentToTargetCommand);
|
|
|
+ this.KeyInTargetPosCommand = new DelegateCommand<object>(ExecuteKeyInCommadn);
|
|
|
+
|
|
|
+ this.ServoOnCommand = new DelegateCommand(ExecuteServoOnCommand);
|
|
|
+ this.ServoOffCommand = new DelegateCommand(ExecuteServoOffCommand);
|
|
|
+ this.FaultResetCommand = new DelegateCommand(ExecuteFaultResetCommand);
|
|
|
+ this.OriginCommand = new DelegateCommand(ExecuteOriginCommand);
|
|
|
+
|
|
|
+ this.JogCommand = new DelegateCommand<object>(ExecuteJogCommand);
|
|
|
+
|
|
|
+ this.eventAggregator = ea;
|
|
|
+ this.eventAggregator.GetEvent<AxisControlPubSubEvent>().Unsubscribe(UICallbackCommunication);
|
|
|
+ this.eventAggregator.GetEvent<AxisControlPubSubEvent>().Subscribe(UICallbackCommunication, ThreadOption.UIThread);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private void ExecuteJogCommand(object obj)
|
|
|
+ {
|
|
|
+ var msg = new AxisControlEventArgs
|
|
|
+ {
|
|
|
+ Dir = AxisControlEventArgs.eEventDir.ToBack,
|
|
|
+ Kind = AxisControlEventArgs.eAxisControlKind.Jog,
|
|
|
+ AxisName = this.SelectAxis,
|
|
|
+ };
|
|
|
+
|
|
|
+ if (obj.ToString().Equals("+"))
|
|
|
+ msg.JogDir = AxisControlEventArgs.eJogMoveDir.Positive;
|
|
|
+ else
|
|
|
+ msg.JogDir = AxisControlEventArgs.eJogMoveDir.Negative;
|
|
|
+
|
|
|
+ PublishEvent(msg);
|
|
|
+ }
|
|
|
+
|
|
|
+ void PublishEvent(AxisControlEventArgs args)
|
|
|
{
|
|
|
- this.SelectAxisCommand = new DelegateCommand<object>( ExecuteSelectAxisCommand );
|
|
|
- this.SelectPosCommand = new DelegateCommand<object>( ExecuteSelectPosCommand );
|
|
|
- this.MoveToCommand = new DelegateCommand( ExecuteMoveToCommand );
|
|
|
- this.CurrentToTargetCommand = new DelegateCommand( ExecuteCurrentToTargetCommand );
|
|
|
- this.KeyInTargetPosCommand = new DelegateCommand<object>( ExecuteKeyInCommadn );
|
|
|
+ this.eventAggregator.GetEvent<AxisControlPubSubEvent>().Publish(args);
|
|
|
+ }
|
|
|
|
|
|
- this.ServoOnCommand = new DelegateCommand( ExecuteServoOnCommand );
|
|
|
- this.ServoOffCommand = new DelegateCommand( ExecuteServoOffCommand );
|
|
|
- this.FaultResetCommand = new DelegateCommand( ExecuteFaultResetCommand );
|
|
|
- this.OriginCommand = new DelegateCommand( ExecuteOriginCommand );
|
|
|
+ void UICallbackCommunication(AxisControlEventArgs args)
|
|
|
+ {
|
|
|
+ if (args.Dir == AxisControlEventArgs.eEventDir.ToFront)
|
|
|
+ {
|
|
|
+ switch (args.Kind)
|
|
|
+ {
|
|
|
+ case AxisControlEventArgs.eAxisControlKind.Stop:
|
|
|
+ break;
|
|
|
+ case AxisControlEventArgs.eAxisControlKind.EStop:
|
|
|
+ break;
|
|
|
+ case AxisControlEventArgs.eAxisControlKind.Move:
|
|
|
+ break;
|
|
|
+ case AxisControlEventArgs.eAxisControlKind.Jog:
|
|
|
+ break;
|
|
|
+ case AxisControlEventArgs.eAxisControlKind.CurrentPosition:
|
|
|
+ if (args.AxisName.Equals(ConstString.AXIS_CARRIER_LOCK_LEFT))
|
|
|
+ this.CurrentLockLeft = args.CurrentPosition;
|
|
|
+ else
|
|
|
+ this.CurrentLockRight = args.CurrentPosition;
|
|
|
+ break;
|
|
|
+ case AxisControlEventArgs.eAxisControlKind.ServoOn:
|
|
|
+ break;
|
|
|
+ case AxisControlEventArgs.eAxisControlKind.ServoOff:
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- private void ExecuteOriginCommand( )
|
|
|
+ private void ExecuteOriginCommand()
|
|
|
{
|
|
|
}
|
|
|
|
|
|
- private void ExecuteFaultResetCommand( )
|
|
|
+ private void ExecuteFaultResetCommand()
|
|
|
{
|
|
|
}
|
|
|
|
|
|
- private void ExecuteServoOffCommand( )
|
|
|
+ private void ExecuteServoOffCommand()
|
|
|
{
|
|
|
}
|
|
|
|
|
|
- private void ExecuteServoOnCommand( )
|
|
|
+ private void ExecuteServoOnCommand()
|
|
|
{
|
|
|
}
|
|
|
|
|
|
- private void ExecuteKeyInCommadn( object obj )
|
|
|
+ private void ExecuteKeyInCommadn(object obj)
|
|
|
{
|
|
|
- if ( obj.ToString().Equals( "Left" ) )
|
|
|
+ if (obj.ToString().Equals("Left"))
|
|
|
{
|
|
|
var numPad = new CalcuratorView();
|
|
|
- var result = numPad.ShowDialog( this.TargetPosLockLeft );
|
|
|
+ var result = numPad.ShowDialog(this.TargetPosLockLeft);
|
|
|
this.TargetPosLockLeft = result;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
var numPad = new CalcuratorView();
|
|
|
- var result = numPad.ShowDialog( this.TargetPosLockRight );
|
|
|
+ var result = numPad.ShowDialog(this.TargetPosLockRight);
|
|
|
this.TargetPosLockRight = result;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private void ExecuteCurrentToTargetCommand( )
|
|
|
+ private void ExecuteCurrentToTargetCommand()
|
|
|
{
|
|
|
this.TargetPosLockLeft = this.CurrentLockLeft;
|
|
|
this.TargetPosLockRight = this.CurrentLockRight;
|
|
|
}
|
|
|
|
|
|
- private async void ExecuteMoveToCommand( )
|
|
|
+ private async void ExecuteMoveToCommand()
|
|
|
{
|
|
|
- await Task.Run( ( ) =>
|
|
|
- {
|
|
|
+ await Task.Run(() =>
|
|
|
+ {
|
|
|
//Axis.Move(this.SelectPosition);
|
|
|
- } );
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
- private void ExecuteSelectPosCommand( object obj )
|
|
|
+ private void ExecuteSelectPosCommand(object obj)
|
|
|
{
|
|
|
this.SelectedPosition = obj.ToString();
|
|
|
|
|
|
- switch ( this.SelectedPosition )
|
|
|
+ switch (this.SelectedPosition)
|
|
|
{
|
|
|
case "Lock":
|
|
|
break;
|
|
|
@@ -178,43 +245,44 @@ namespace OHV.Module.Interactivity.PopUp
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private void ExecuteSelectAxisCommand( object obj )
|
|
|
+ private void ExecuteSelectAxisCommand(object obj)
|
|
|
{
|
|
|
this.SelectAxis = obj.ToString();
|
|
|
}
|
|
|
|
|
|
#region Dialog
|
|
|
- public bool CanCloseDialog( )
|
|
|
+ public bool CanCloseDialog()
|
|
|
{
|
|
|
//throw new NotImplementedException();
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
- public void OnDialogClosed( )
|
|
|
+ public void OnDialogClosed()
|
|
|
{
|
|
|
- //throw new NotImplementedException();
|
|
|
+ this.eventAggregator.GetEvent<AxisControlPubSubEvent>().Publish(new AxisControlEventArgs { Dir = AxisControlEventArgs.eEventDir.ToBack, Kind = AxisControlEventArgs.eAxisControlKind.ReqStopCurrentPosition});
|
|
|
+ this.eventAggregator.GetEvent<AxisControlPubSubEvent>().Unsubscribe(UICallbackCommunication);
|
|
|
}
|
|
|
|
|
|
- public void OnDialogOpened( IDialogParameters parameters )
|
|
|
+ public void OnDialogOpened(IDialogParameters parameters)
|
|
|
{
|
|
|
- //throw new NotImplementedException();
|
|
|
+ this.eventAggregator.GetEvent<AxisControlPubSubEvent>().Publish(new AxisControlEventArgs { Dir = AxisControlEventArgs.eEventDir.ToBack, Kind = AxisControlEventArgs.eAxisControlKind.ReqCurrentPosition });
|
|
|
}
|
|
|
|
|
|
- public virtual void RaiseRequestClose( IDialogResult dialogResult )
|
|
|
+ public virtual void RaiseRequestClose(IDialogResult dialogResult)
|
|
|
{
|
|
|
- RequestClose?.Invoke( dialogResult );
|
|
|
+ RequestClose?.Invoke(dialogResult);
|
|
|
}
|
|
|
|
|
|
- private void CloseDialog( string parameter )
|
|
|
+ private void CloseDialog(string parameter)
|
|
|
{
|
|
|
ButtonResult result = ButtonResult.None;
|
|
|
|
|
|
- if ( parameter?.ToLower() == "true" )
|
|
|
+ if (parameter?.ToLower() == "true")
|
|
|
result = ButtonResult.OK;
|
|
|
- else if ( parameter?.ToLower() == "false" )
|
|
|
+ else if (parameter?.ToLower() == "false")
|
|
|
result = ButtonResult.Cancel;
|
|
|
|
|
|
- RaiseRequestClose( new DialogResult( result ) );
|
|
|
+ RaiseRequestClose(new DialogResult(result));
|
|
|
}
|
|
|
#endregion
|
|
|
}
|