From 06ad24ef8a414fc89c0cf42b9f5264d584292afe Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Thu, 1 Feb 2018 11:39:19 +0200 Subject: Improved RequestShutDown Mechanism on machine studio UI implementation. Fixed issue with job brush markers visibility. Implemented Job Progress Indicator. --- .../Converters/JobProgressToPositionConverter.cs | 43 ++++++ .../Converters/ObjectsNotEqualToBooleanConveter.cs | 30 ++++ .../Converters/SegmentLengthToWidthConverter.cs | 22 ++- .../Tango.MachineStudio.Developer.csproj | 2 + .../ViewModels/MainViewVM.cs | 75 +++++++++- .../Views/MainView.xaml | 153 ++++++++++++++++++--- .../Views/MainView.xaml.cs | 5 + .../DefaultStudioApplicationManager.cs | 29 ++-- 8 files changed, 322 insertions(+), 37 deletions(-) create mode 100644 Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Converters/JobProgressToPositionConverter.cs create mode 100644 Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Converters/ObjectsNotEqualToBooleanConveter.cs (limited to 'Software/Visual_Studio/MachineStudio') diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Converters/JobProgressToPositionConverter.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Converters/JobProgressToPositionConverter.cs new file mode 100644 index 000000000..9865b26f8 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Converters/JobProgressToPositionConverter.cs @@ -0,0 +1,43 @@ +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Data; +using Tango.Integration.Observables; + +namespace Tango.MachineStudio.Developer.Converters +{ + public class JobProgressToPositionConverter : IMultiValueConverter + { + public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) + { + try + { + Job job = values[0] as Job; + + if (job != null) + { + double progress = System.Convert.ToDouble(values[1]); + double parentElementWidth = System.Convert.ToDouble(values[2]); + + return (progress / job.Length) * parentElementWidth; + } + else + { + return 0d; + } + } + catch + { + return 0d; + } + } + + public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture) + { + throw new NotImplementedException(); + } + } +} diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Converters/ObjectsNotEqualToBooleanConveter.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Converters/ObjectsNotEqualToBooleanConveter.cs new file mode 100644 index 000000000..15bfd6add --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Converters/ObjectsNotEqualToBooleanConveter.cs @@ -0,0 +1,30 @@ +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Data; + +namespace Tango.MachineStudio.Developer.Converters +{ + public class ObjectsNotEqualToBooleanConveter : IMultiValueConverter + { + public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) + { + try + { + return (values[0] != values[1]); + } + catch + { + return true; + } + } + + public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture) + { + throw new NotImplementedException(); + } + } +} diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Converters/SegmentLengthToWidthConverter.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Converters/SegmentLengthToWidthConverter.cs index 959fb6410..b632d9d12 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Converters/SegmentLengthToWidthConverter.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Converters/SegmentLengthToWidthConverter.cs @@ -19,21 +19,29 @@ namespace Tango.MachineStudio.Developer.Converters if (values.Length == 4) { Job job = values[0] as Job; - double jobLength = System.Convert.ToDouble(values[1]); - double elementWidth = System.Convert.ToDouble(values[2]); - double segmentLength = System.Convert.ToDouble(values[3]); - double totalLength = job.Length; - return (segmentLength / totalLength) * elementWidth; + if (job != null && values[1] is double) + { + double jobLength = System.Convert.ToDouble(values[1]); + double elementWidth = System.Convert.ToDouble(values[2]); + double segmentLength = System.Convert.ToDouble(values[3]); + double totalLength = job.Length; + + return (segmentLength / totalLength) * elementWidth; + } + else + { + return 0d; + } } else { - return 0; + return 0d; } } catch { - return 0; + return 0d; } } diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Tango.MachineStudio.Developer.csproj b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Tango.MachineStudio.Developer.csproj index b58908048..3b72c4971 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Tango.MachineStudio.Developer.csproj +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Tango.MachineStudio.Developer.csproj @@ -77,7 +77,9 @@ + + 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 85febd0f1..4f7447253 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 @@ -15,6 +15,7 @@ using Tango.MachineStudio.Common.Notifications; using Tango.MachineStudio.Common.StudioApplication; using Tango.SharedUI; using System.Runtime.CompilerServices; +using System.Windows.Threading; namespace Tango.MachineStudio.Developer.ViewModels { @@ -22,7 +23,7 @@ namespace Tango.MachineStudio.Developer.ViewModels /// Represents the developer module main view, view model. /// /// - public class MainViewVM : ViewModel + public class MainViewVM : ViewModel, IShutdownRequestBlocker { private INotificationProvider _notification; @@ -203,13 +204,35 @@ namespace Tango.MachineStudio.Developer.ViewModels } private bool _isJobRunning; - + /// + /// Gets or sets a value indicating whether a job is currently running. + /// public bool IsJobRunning { get { return _isJobRunning; } set { _isJobRunning = value; RaisePropertyChangedAuto(); } } + private Job _runningJob; + /// + /// Gets or sets the currently running job. + /// + public Job RunningJob + { + get { return _runningJob; } + set { _runningJob = value; RaisePropertyChangedAuto(); } + } + + private double _runningJobProgress; + /// + /// Gets or sets the running job current progress. + /// + public double RunningJobProgress + { + get { return _runningJobProgress; } + set { _runningJobProgress = value; RaisePropertyChangedAuto(); } + } + #endregion #region Commands @@ -279,6 +302,11 @@ namespace Tango.MachineStudio.Developer.ViewModels /// public RelayCommand StartJobCommand { get; set; } + /// + /// Gets or sets the stop job command. + /// + public RelayCommand StopJobCommand { get; set; } + #endregion #region Constructors @@ -324,6 +352,7 @@ namespace Tango.MachineStudio.Developer.ViewModels RemoveBrushStopCommand = new RelayCommand(RemoveBrushStop, () => SelectedBrushStop != null); SaveJobsCommand = new RelayCommand(SaveJobs, () => SelectedMachine != null); StartJobCommand = new RelayCommand(StartJob, () => SelectedJob != null && !IsJobRunning); + StopJobCommand = new RelayCommand(StopJob, () => IsJobRunning); } #endregion @@ -438,9 +467,32 @@ namespace Tango.MachineStudio.Developer.ViewModels #region Private Methods + private void StopJob() + { + RunningJobProgress = 0; + IsJobRunning = false; + RunningJob = null; + } + private void StartJob() { IsJobRunning = true; + RunningJob = SelectedJob; + + DispatcherTimer timer = new DispatcherTimer(); + timer.Interval = TimeSpan.FromSeconds(0.1); + timer.Tick += (x, y) => + { + if (RunningJob == null || RunningJobProgress >= RunningJob.Length) + { + timer.Stop(); + StopJob(); + return; + } + RunningJobProgress += 0.1; + }; + + timer.Start(); } private async void SaveJobs() @@ -739,5 +791,24 @@ namespace Tango.MachineStudio.Developer.ViewModels } #endregion + + #region IShutdownRequestBlocker + + public Task OnShutdownRequest() + { + if (IsJobRunning) + { + InvokeUI(() => + { + _notification.ShowWarning("Please stop the currently running job before closing the developer module."); + }); + + return Task.FromResult(false); + } + + return Task.FromResult(true); + } + + #endregion } } diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/MainView.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/MainView.xaml index a1b607b8b..5dbb8604b 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/MainView.xaml +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/MainView.xaml @@ -42,6 +42,8 @@ + + @@ -164,12 +166,12 @@ - + - - JOB RUNNING... + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + @@ -316,7 +425,7 @@