diff options
Diffstat (limited to 'Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels')
| -rw-r--r-- | Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/MainViewVM.cs | 138 |
1 files changed, 127 insertions, 11 deletions
diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/MainViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/MainViewVM.cs index 4f7447253..a9e71de5a 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/MainViewVM.cs @@ -16,6 +16,8 @@ using Tango.MachineStudio.Common.StudioApplication; using Tango.SharedUI; using System.Runtime.CompilerServices; using System.Windows.Threading; +using Tango.Settings; +using Tango.MachineStudio.Developer.Views; namespace Tango.MachineStudio.Developer.ViewModels { @@ -23,9 +25,10 @@ namespace Tango.MachineStudio.Developer.ViewModels /// Represents the developer module main view, view model. /// </summary> /// <seealso cref="Tango.SharedUI.ViewModel" /> - public class MainViewVM : ViewModel, IShutdownRequestBlocker + public class MainViewVM : ViewModel<IMainView>, IShutdownRequestBlocker { private INotificationProvider _notification; + private TimeSpan _runningJobEstimatedDuration; #region Properties @@ -233,6 +236,56 @@ namespace Tango.MachineStudio.Developer.ViewModels set { _runningJobProgress = value; RaisePropertyChangedAuto(); } } + private TimeSpan _runningJobRemainingTime; + /// <summary> + /// Gets or sets the job remaining time. + /// </summary> + public TimeSpan RunningJobRemainingTime + { + get { return _runningJobRemainingTime; } + set { _runningJobRemainingTime = value; RaisePropertyChangedAuto(); } + } + + private bool _isJobCompleted; + /// <summary> + /// Gets or sets a value indicating whether the running job has completed successfully. + /// </summary> + public bool IsJobCompleted + { + get { return _isJobCompleted; } + set { _isJobCompleted = value; RaisePropertyChangedAuto(); } + } + + private bool _isJobFailed; + /// <summary> + /// Gets or sets a value indicating whether the running job has failed. + /// </summary> + public bool IsJobFailed + { + get { return _isJobFailed; } + set { _isJobFailed = value; RaisePropertyChangedAuto(); } + } + + private bool _showJobStatus; + /// <summary> + /// Gets or sets a value indicating whether to show all the relevant job status areas. + /// </summary> + public bool ShowJobStatus + { + get { return _showJobStatus; } + set { _showJobStatus = value; RaisePropertyChangedAuto(); } + } + + private bool _isJobCanceled; + /// <summary> + /// Gets or sets a value indicating whether the last running job was canceled. + /// </summary> + public bool IsJobCanceled + { + get { return _isJobCanceled; } + set { _isJobCanceled = value; RaisePropertyChangedAuto(); } + } + #endregion #region Commands @@ -307,6 +360,11 @@ namespace Tango.MachineStudio.Developer.ViewModels /// </summary> public RelayCommand StopJobCommand { get; set; } + /// <summary> + /// Gets or sets the close job completion status command. + /// </summary> + public RelayCommand CloseJobCompletionStatusCommand { get; set; } + #endregion #region Constructors @@ -314,7 +372,7 @@ namespace Tango.MachineStudio.Developer.ViewModels /// <summary> /// Initializes a new instance of the <see cref="MainViewVM"/> class. /// </summary> - public MainViewVM() + public MainViewVM(IMainView view) : base(view, true) { IsSideBarOpened = true; @@ -333,7 +391,7 @@ namespace Tango.MachineStudio.Developer.ViewModels /// <param name="applicationManager">The application manager.</param> /// <param name="notificationProvider">The notification provider.</param> [PreferredConstructor] - public MainViewVM(IStudioApplicationManager applicationManager, INotificationProvider notificationProvider) : this() + public MainViewVM(IStudioApplicationManager applicationManager, INotificationProvider notificationProvider, IMainView view) : this(view) { _notification = notificationProvider; ApplicationManager = applicationManager; @@ -353,6 +411,7 @@ namespace Tango.MachineStudio.Developer.ViewModels SaveJobsCommand = new RelayCommand(SaveJobs, () => SelectedMachine != null); StartJobCommand = new RelayCommand(StartJob, () => SelectedJob != null && !IsJobRunning); StopJobCommand = new RelayCommand(StopJob, () => IsJobRunning); + CloseJobCompletionStatusCommand = new RelayCommand(CloseJobCompletionStatusBar); } #endregion @@ -467,29 +526,57 @@ namespace Tango.MachineStudio.Developer.ViewModels #region Private Methods + private void CloseJobCompletionStatusBar() + { + IsJobCompleted = false; + IsJobFailed = false; + IsJobCanceled = false; + ShowJobStatus = false; + RunningJob = null; + } + private void StopJob() { - RunningJobProgress = 0; IsJobRunning = false; - RunningJob = null; + IsJobCanceled = true; + } + + private void CompleteJob() + { + IsJobRunning = false; + IsJobCompleted = true; } private void StartJob() { + RunningJobRemainingTime = TimeSpan.Zero; + RunningJobProgress = 0; + IsJobFailed = false; + IsJobCanceled = false; + IsJobCompleted = false; IsJobRunning = true; + ShowJobStatus = true; RunningJob = SelectedJob; + _runningJobEstimatedDuration = EstimatedDuration; DispatcherTimer timer = new DispatcherTimer(); - timer.Interval = TimeSpan.FromSeconds(0.1); + timer.Interval = TimeSpan.FromSeconds(0.03); timer.Tick += (x, y) => { - if (RunningJob == null || RunningJobProgress >= RunningJob.Length) + RunningJobRemainingTime = _runningJobEstimatedDuration - TimeSpan.FromSeconds(RunningJobProgress / (SelectedProcessParametersTable.DyeingSpeed / 100d)); + RunningJobProgress += 0.03; + + if (!IsJobRunning) + { + timer.Stop(); + return; + } + else if (RunningJobProgress >= RunningJob.Length) { timer.Stop(); - StopJob(); + CompleteJob(); return; } - RunningJobProgress += 0.1; }; timer.Start(); @@ -497,11 +584,11 @@ namespace Tango.MachineStudio.Developer.ViewModels private async void SaveJobs() { - if (SelectedMachine != null) + if (SelectedJob != null) { using (_notification.PushTaskItem("Saving machine jobs...")) { - await SelectedMachine.SaveAsync(); + await SelectedJob.SaveAsync(); } } } @@ -806,9 +893,38 @@ namespace Tango.MachineStudio.Developer.ViewModels return Task.FromResult(false); } + SettingsManager.Default.MachineStudio.DeveloperModule.LastSelectedMachineGuid = SelectedMachine != null ? SelectedMachine.Guid : null; + SettingsManager.Default.MachineStudio.DeveloperModule.LastSelectedRMLGuid = SelectedRML != null ? SelectedRML.Guid : null; + SettingsManager.Default.MachineStudio.DeveloperModule.LastSelectedJobGuid = SelectedJob != null ? SelectedJob.Guid : null; + SettingsManager.SaveDefaultSettings(); + return Task.FromResult(true); } #endregion + + #region IMainView + + protected override void OnViewAttached() + { + base.OnViewAttached(); + + if (SettingsManager.Default.MachineStudio.DeveloperModule.LastSelectedMachineGuid != null) + { + SelectedMachine = Adapter.Machines.SingleOrDefault(x => x.Guid == SettingsManager.Default.MachineStudio.DeveloperModule.LastSelectedMachineGuid); + } + + if (SettingsManager.Default.MachineStudio.DeveloperModule.LastSelectedRMLGuid != null) + { + SelectedRML = Adapter.Rmls.SingleOrDefault(x => x.Guid == SettingsManager.Default.MachineStudio.DeveloperModule.LastSelectedRMLGuid); + } + + if (SettingsManager.Default.MachineStudio.DeveloperModule.LastSelectedJobGuid != null && SelectedMachine != null) + { + SelectedJob = SelectedMachine.Jobs.SingleOrDefault(x => x.Guid == SettingsManager.Default.MachineStudio.DeveloperModule.LastSelectedJobGuid); + } + } + + #endregion } } |
