diff options
Diffstat (limited to 'Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels')
3 files changed, 157 insertions, 31 deletions
diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/JobProgressViewVM.cs b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/JobProgressViewVM.cs index 387b3e6a0..264f41131 100644 --- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/JobProgressViewVM.cs +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/JobProgressViewVM.cs @@ -8,6 +8,8 @@ using Tango.Integration.Operation; using Tango.PPC.Common; using Tango.PPC.Common.Navigation; using Tango.PPC.Jobs.AppBarItems; +using Tango.PPC.Jobs.AppButtons; +using Tango.PPC.Jobs.Dialogs; using Tango.PPC.Jobs.Views; namespace Tango.PPC.Jobs.ViewModels @@ -18,6 +20,9 @@ namespace Tango.PPC.Jobs.ViewModels /// <seealso cref="Tango.PPC.Common.PPCViewModel" /> public class JobProgressViewVM : PPCViewModel { + private StopPrintingButton _stop_job_btn; + private JobHandler _handler; + #region Properties private Job _job; @@ -42,6 +47,20 @@ namespace Tango.PPC.Jobs.ViewModels #endregion + public JobProgressViewVM() + { + _stop_job_btn = new StopPrintingButton(); + _stop_job_btn.Pressed += _stop_job_btn_Pressed; + } + + private void _stop_job_btn_Pressed() + { + if (_handler != null) + { + _handler.Cancel(); + } + } + #region Override Methods /// <summary> @@ -80,6 +99,8 @@ namespace Tango.PPC.Jobs.ViewModels { NotificationProvider.CurrentAppBarItem.Close(); } + + _stop_job_btn.Push(); } #endregion @@ -93,12 +114,34 @@ namespace Tango.PPC.Jobs.ViewModels /// <param name="e">The <see cref="PrintingEventArgs"/> instance containing the event data.</param> private void MachineOperator_PrintingStarted(object sender, PrintingEventArgs e) { + _handler = e.JobHandler; Job = e.Job; e.JobHandler.StatusChanged += JobHandler_StatusChanged; + e.JobHandler.SpoolChangeRequired += JobHandler_SpoolChangeRequired; e.JobHandler.Stopped += JobHandler_Stopped; } /// <summary> + /// Handles the SpoolChangeRequired event of the JobHandler. + /// </summary> + /// <param name="sender">The source of the event.</param> + /// <param name="e">The <see cref="SpoolChangeRequiredEventArgs"/> instance containing the event data.</param> + private void JobHandler_SpoolChangeRequired(object sender, SpoolChangeRequiredEventArgs e) + { + InvokeUI(async () => + { + if ((await NotificationProvider.ShowDialog(new SpoolChangeViewVM(e))).DialogResult) + { + e.Confirm(); + } + else + { + e.Abort(); + } + }); + } + + /// <summary> /// Handles the Stopped event of the JobHandler. /// </summary> /// <param name="sender">The source of the event.</param> @@ -109,6 +152,8 @@ namespace Tango.PPC.Jobs.ViewModels { NotificationProvider.CurrentAppBarItem.Close(); } + + _stop_job_btn.Pop(); } /// <summary> diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/JobViewVM.cs b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/JobViewVM.cs index b009762b4..6a05eee12 100644 --- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/JobViewVM.cs +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/JobViewVM.cs @@ -30,6 +30,7 @@ using Tango.PPC.Common.Models; using Tango.Logging; using Tango.PPC.Common.Messages; using Tango.BL.Builders; +using Tango.PPC.Jobs.AppButtons; namespace Tango.PPC.Jobs.ViewModels { @@ -45,6 +46,7 @@ namespace Tango.PPC.Jobs.ViewModels private Job _job_to_load; private JobNavigationIntent _job_to_load_intent; private static Dictionary<String, List<FineTuneItem>> _jobs_fine_tune_items; + private StartPrintingButton _start_printing_btn; #region Properties @@ -458,6 +460,8 @@ namespace Tango.PPC.Jobs.ViewModels LogManager.Log("Directing view to display fine tuning region."); View.DisplayFineTuning(); } + + DyeCommand.RaiseCanExecuteChanged(); } catch (Exception ex) { @@ -888,6 +892,11 @@ namespace Tango.PPC.Jobs.ViewModels /// </summary> private void ResetFineTuning() { + if (Job != null && _jobs_fine_tune_items.ContainsKey(Job.Guid)) + { + _jobs_fine_tune_items.Remove(Job.Guid); + } + SyncFineTuneItemsToBrushStops(); } @@ -1012,6 +1021,8 @@ namespace Tango.PPC.Jobs.ViewModels /// </summary> public override void OnNavigatedTo() { + _start_printing_btn.Push(); + base.OnNavigatedTo(); LoadJob(); } @@ -1021,6 +1032,8 @@ namespace Tango.PPC.Jobs.ViewModels /// </summary> public override void OnNavigatedFrom() { + _start_printing_btn.Pop(); + base.OnNavigatedFrom(); _job_to_load_intent = JobNavigationIntent.Default; } @@ -1050,6 +1063,12 @@ namespace Tango.PPC.Jobs.ViewModels return result; } + public override void OnApplicationReady() + { + base.OnApplicationReady(); + + _start_printing_btn = new StartPrintingButton(DyeCommand, MachineProvider.MachineOperator); + } #endregion #region INavigationObjectReceiver diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/JobsViewVM.cs b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/JobsViewVM.cs index 8c1466c26..a2927660f 100644 --- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/JobsViewVM.cs +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/JobsViewVM.cs @@ -27,6 +27,7 @@ using Tango.Explorer; using System.IO; using Google.Protobuf; using Tango.PMR.Exports; +using Tango.Settings; namespace Tango.PPC.Jobs.ViewModels { @@ -38,6 +39,12 @@ namespace Tango.PPC.Jobs.ViewModels { private ObservablesContext _db; //Holds the db context for the job list. + public enum JobsCategory + { + Draft, + History + } + #region Properties private ObservableCollection<Job> _jobs; @@ -50,16 +57,30 @@ namespace Tango.PPC.Jobs.ViewModels set { _jobs = value; RaisePropertyChangedAuto(); } } - private ICollectionView _jobsCollectionView; + private ICollectionView _draftJobsCollectionView; + /// <summary> + /// Gets or sets the jobs collection view. + /// </summary> + public ICollectionView DraftJobsCollectionView + { + get { return _draftJobsCollectionView; } + set + { + _draftJobsCollectionView = value; + RaisePropertyChangedAuto(); + } + } + + private ICollectionView _historyJobsCollectionView; /// <summary> /// Gets or sets the jobs collection view. /// </summary> - public ICollectionView JobsCollectionView + public ICollectionView HistoryJobsCollectionView { - get { return _jobsCollectionView; } + get { return _historyJobsCollectionView; } set { - _jobsCollectionView = value; + _historyJobsCollectionView = value; RaisePropertyChangedAuto(); } } @@ -94,17 +115,30 @@ namespace Tango.PPC.Jobs.ViewModels set { _isMultiSelecting = value; RaisePropertyChangedAuto(); } } - private JobCategories _filterCategory; + private int _selectedCategoryIndex; + /// <summary> + /// Gets or sets the index of the selected category. + /// </summary> + public int SelectedCategoryIndex + { + get { return _selectedCategoryIndex; } + set + { + _selectedCategoryIndex = value; + RaisePropertyChangedAuto(); + RaisePropertyChanged(nameof(SelectedCategory)); + } + } + /// <summary> - /// Gets or sets the filter category. + /// Gets or sets the selected category. /// </summary> - public JobCategories FilterCategory + public JobsCategory SelectedCategory { - get { return _filterCategory; } + get { return (JobsCategory)SelectedCategoryIndex; } set { - _filterCategory = value; RaisePropertyChangedAuto(); - FilterJobCategory(value); + SelectedCategoryIndex = value.ToInt32(); } } @@ -207,7 +241,7 @@ namespace Tango.PPC.Jobs.ViewModels job.JobIndex = index++; } - JobsCollectionView.Refresh(); + DraftJobsCollectionView.Refresh(); } #endregion @@ -255,9 +289,15 @@ namespace Tango.PPC.Jobs.ViewModels InvokeUI(() => { Jobs = jobs; - JobsCollectionView = CollectionViewSource.GetDefaultView(Jobs); - JobsCollectionView.SortDescriptions.Add(new SortDescription(nameof(Job.LastUpdated), ListSortDirection.Descending)); - FilterJobCategory(FilterCategory); + DraftJobsCollectionView = new ListCollectionView(Jobs); + DraftJobsCollectionView.SortDescriptions.Add(new SortDescription(nameof(Job.LastUpdated), ListSortDirection.Descending)); + DraftJobsCollectionView.Filter = new Predicate<object>(x => (x as Job).JobStatus == JobStatuses.Draft); + + + HistoryJobsCollectionView = new ListCollectionView(Jobs); + HistoryJobsCollectionView.SortDescriptions.Add(new SortDescription(nameof(Job.LastUpdated), ListSortDirection.Descending)); + HistoryJobsCollectionView.Filter = new Predicate<object>(x => (x as Job).JobStatus != JobStatuses.Draft); + IsLoadingJobs = false; LogManager.Log("Machine jobs loaded!"); onCompleted?.Invoke(); @@ -281,18 +321,6 @@ namespace Tango.PPC.Jobs.ViewModels } /// <summary> - /// Filters the jobs list by the specified <see cref="JobCategories">job category</see>. - /// </summary> - /// <param name="jobCategory">The job category.</param> - public void FilterJobCategory(JobCategories jobCategory) - { - JobsCollectionView.Filter = (job) => - { - return (job as Job).JobCategories.Contains(jobCategory); - }; - } - - /// <summary> /// Adds a new job. /// </summary> private async void AddNewJob() @@ -303,18 +331,47 @@ namespace Tango.PPC.Jobs.ViewModels var machine = MachineProvider.Machine; - JobTypePickerViewVM vm = new JobTypePickerViewVM(machine.SupportedJobTypes.Count > 0 ? machine.SupportedJobTypes : Enum.GetValues(typeof(JobTypes)).Cast<JobTypes>().ToList()); + JobCreationViewVM vm = new JobCreationViewVM( + machine.SupportedJobTypes.Count > 0 ? machine.SupportedJobTypes : Enum.GetValues(typeof(JobTypes)).Cast<JobTypes>().ToList(), + machine.SupportedColorSpaces.Count > 0 ? machine.SupportedColorSpaces : Enum.GetValues(typeof(ColorSpaces)).Cast<ColorSpaces>().Where(x => x.IsUserSpace()).ToList() + ); + + var settings = SettingsManager.Default.GetOrCreate<JobsModuleSettings>(); - if (machine.SupportedJobTypes.Count != 1) + if (settings.LastJobType != null) + { + vm.SelectedJobType = settings.LastJobType.Value; + } + else { - vm = await NotificationProvider.ShowDialog<JobTypePickerViewVM>(vm); + vm.SelectedJobType = machine.SupportedJobTypes.FirstOrDefault(); + } + + if (settings.LastJobColorSpace != null) + { + vm.SelectedColorSpace = settings.LastJobColorSpace.Value; + } + else + { + var space = machine.SupportedColorSpaces.FirstOrDefault(); + vm.SelectedColorSpace = space.IsUserSpace() ? space : ColorSpaces.Twine; + } + + if (machine.SupportedJobTypes.Count != 1 && machine.SupportedColorSpaces.Count != 1) + { + vm = await NotificationProvider.ShowDialog<JobCreationViewVM>(vm); if (!vm.DialogResult) return; } else { vm.SelectedJobType = machine.SupportedJobTypes.First(); + vm.SelectedColorSpace = machine.SupportedColorSpaces.First(); } + settings.LastJobType = vm.SelectedJobType; + settings.LastJobColorSpace = vm.SelectedColorSpace; + settings.Save(); + Job job = new Job(); job.Name = "untitled"; job.NumberOfHeads = 1; @@ -322,13 +379,18 @@ namespace Tango.PPC.Jobs.ViewModels job.SampleUnitsOrMeters = 1; job.CreationDate = DateTime.UtcNow; job.JobStatus = JobStatuses.Draft; - job.JobType = vm.SelectedJobType.Value; - job.ColorSpaceGuid = machine.DefaultColorSpace != null ? machine.DefaultColorSpaceGuid : Adapter.ColorSpaces.FirstOrDefault(x => x.Code == ColorSpaces.RGB.ToInt32()).Guid; + job.JobType = vm.SelectedJobType; + job.ColorSpaceGuid = Adapter.ColorSpaces.FirstOrDefault(x => x.Code == vm.SelectedColorSpace.ToInt32()).Guid; job.MachineGuid = MachineProvider.Machine.Guid; job.UserGuid = AuthenticationProvider.CurrentUser.Guid; job.RmlGuid = machine.DefaultRml != null ? machine.DefaultRmlGuid : Adapter.Rmls.FirstOrDefault().Guid; job.WindingMethodGuid = Adapter.WindingMethods.FirstOrDefault().Guid; job.SpoolTypeGuid = machine.DefaultSpoolType != null ? machine.DefaultSpoolTypeGuid : Adapter.SpoolTypes.FirstOrDefault().Guid; + + if (Jobs.Count > 0) + { + job.JobIndex = Jobs.Max(x => x.JobIndex) + 1; + } job.AddSolidSegment(machine.DefaultSegmentLength > 0 ? machine.DefaultSegmentLength : 10); |
