diff options
Diffstat (limited to 'Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/JobViewVM.cs')
| -rw-r--r-- | Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/JobViewVM.cs | 149 |
1 files changed, 38 insertions, 111 deletions
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 5e90d3b5b..4e1e58dba 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 @@ -56,7 +56,6 @@ namespace Tango.PPC.Jobs.ViewModels private ActionTimer _volumeConversionTimer; private IColorConverter _converter; private string _current_job_string; - private bool startingJob = false; #region Properties @@ -413,7 +412,7 @@ namespace Tango.PPC.Jobs.ViewModels RepeatSampleDyeCommand = new RelayCommand(RepeatSampleDye); AnotherSampleCommand = new RelayCommand(DyeAnotherSample); InvokeFineTuningPaletteCommand = new RelayCommand<FineTuneItem>(InvokeFineTuningPalette); - ResetFineTuningCommand = new RelayCommand(() => ResetFineTuning(true)); + ResetFineTuningCommand = new RelayCommand(ResetFineTuning); StartFineTuningCommand = new RelayCommand(StartFineTuning, () => FineTuneItems.Any(x => x.IsSelected) && CanStartJob()); RepeatFineTuningCommand = new RelayCommand(RepeatFineTuning); ApproveFineTuningCommand = new RelayCommand(ApproveFineTuning); @@ -469,7 +468,7 @@ namespace Tango.PPC.Jobs.ViewModels Job.ValidateOnPropertyChanged = true; LogManager.Log("Loading RMLS..."); - Rmls = (await new RmlsCollectionBuilder(_db).SetAll().WithActiveParametersGroup().WithCAT(Job.MachineGuid).WithCCT().WithLiquidFactors().WithSpools().ForHeadType(MachineProvider.Machine.MachineHeadType).ForSite(MachineProvider.Machine.SiteGuid).BuildAsync()).ToList(); + Rmls = (await new RmlsCollectionBuilder(_db).SetAll().WithActiveParametersGroup().WithCAT(Job.MachineGuid).WithCCT().WithLiquidFactors().BuildAsync()).ToList(); LogManager.Log("Loading Color Spaces..."); ColorSpaces = await _db.ColorSpaces.ToListAsync(); LogManager.Log("Loading Spool Types..."); @@ -479,7 +478,7 @@ namespace Tango.PPC.Jobs.ViewModels if (Job.ColorSpace.Space == BL.Enumerations.ColorSpaces.Catalog) { - SelectedCatalog = await new CatalogBuilder(_db).Set(Job.ColorCatalogGuid).WithGroups().WithItems().BuildAsync(); + SelectedCatalog = await new ColorCatalogBuilder(_db).Set(Job.ColorCatalogGuid).WithGroups().WithItems().BuildAsync(); if (SelectedCatalog != null) { @@ -546,15 +545,18 @@ namespace Tango.PPC.Jobs.ViewModels } catch (Exception ex) { - IsFree = true; - LogManager.Log(ex, $"Error loading job '{(_job_to_load != null ? _job_to_load.Name : "null")}'"); + LogManager.Log(ex, $"Error loading job '{_job_to_load.Name}'"); await NotificationProvider.ShowError("An error occurred while trying to load the selected job."); _can_navigate_back = true; await NavigationManager.NavigateBack(); } finally { - IsFree = true; + InvokeUI(() => + { + IsFree = true; + //NotificationProvider.ReleaseGlobalBusyMessage(); + }); } } @@ -591,9 +593,7 @@ namespace Tango.PPC.Jobs.ViewModels } Job.LastUpdated = DateTime.UtcNow; - Job.IsSynchronized = false; Job.JobStatus = BL.Enumerations.JobStatuses.Draft; - Job.MarkModified(_db); await _db.SaveChangesAsync(); _current_job_string = Job.ToJobFileWhenLoaded().ToString(); @@ -645,16 +645,11 @@ namespace Tango.PPC.Jobs.ViewModels /// </summary> private async void StartJob() { - if (startingJob) return; - try { - Debug.WriteLine("Job Starting..."); - startingJob = true; LogManager.Log("Start job command pressed. Starting job and navigating to job progress view..."); - var handler = await PrintingManager.Print(Job, _db); + await PrintingManager.Print(Job, _db); await NavigationManager.NavigateTo<JobsModule>(nameof(JobProgressView)); - startingJob = false; } catch (InsufficientLiquidQuantityException) { @@ -665,10 +660,6 @@ namespace Tango.PPC.Jobs.ViewModels LogManager.Log(ex, "Could not start the current job."); await NotificationProvider.ShowError($"{ex.Message}."); } - finally - { - startingJob = false; - } } /// <summary> @@ -677,7 +668,8 @@ namespace Tango.PPC.Jobs.ViewModels private bool CanStartJob() { return - Job != null && Job.Validate(_db) && !Job.Segments.SelectMany(x => x.BrushStops).Where(x => !x.IsTransparent && !x.IsWhite).ToList().Exists(x => x.IsOutOfGamut || x.IsLiquidVolumesOutOfRange); + Job != null && Job.Validate(_db) && + !Job.Segments.SelectMany(x => x.BrushStops).ToList().Exists(x => x.IsOutOfGamut); } #endregion @@ -717,7 +709,7 @@ namespace Tango.PPC.Jobs.ViewModels try { LogManager.Log("Adding new solid segment..."); - var s = Job.AddSolidSegment(Settings.DefaultSegmentLength > 0 ? Settings.DefaultSegmentLength : 10); + var s = Job.AddSolidSegment(MachineProvider.Machine.DefaultSegmentLength > 0 ? MachineProvider.Machine.DefaultSegmentLength : 10); SetSegmentLiquidVolumesIfVolume(s); return s; } @@ -737,7 +729,7 @@ namespace Tango.PPC.Jobs.ViewModels try { LogManager.Log("Adding new gradient segment..."); - var s = Job.AddGradientSegment(Settings.DefaultSegmentLength > 0 ? Settings.DefaultSegmentLength : 10); + var s = Job.AddGradientSegment(MachineProvider.Machine.DefaultSegmentLength > 0 ? MachineProvider.Machine.DefaultSegmentLength : 10); SetSegmentLiquidVolumesIfVolume(s); return s; } @@ -767,7 +759,14 @@ namespace Tango.PPC.Jobs.ViewModels draggedSegment.SegmentIndex = droppedSegment.SegmentIndex + 1; } - ArrangeSegmentsIndices(); + int index = 1; + + foreach (var segment in Job.Segments.OrderBy(x => x.SegmentIndex)) + { + segment.SegmentIndex = index++; + } + + SegmentsCollectionView.Refresh(); } /// <summary> @@ -830,14 +829,10 @@ namespace Tango.PPC.Jobs.ViewModels private void ArrangeSegmentsIndices() { - int index = 1; - - foreach (var segment in Job.Segments.OrderBy(x => x.SegmentIndex)) + for (int i = 0; i < Job.Segments.Count; i++) { - segment.SegmentIndex = index++; + Job.Segments[i].SegmentIndex = i + 1; } - - SegmentsCollectionView.Refresh(); } #endregion @@ -885,55 +880,23 @@ namespace Tango.PPC.Jobs.ViewModels LogManager.Log($"Invoking triplet color adjustment dialog for brush stop {brushStop.StopIndex} at segment {brushStop.Segment.SegmentIndex}."); LogManager.Log("Retrieving color conversion suggestions for brush stop..."); - PMR.ColorLab.ConversionOutput conversionOutput = null; - - if (brushStop.IsOutOfGamut) - { - conversionOutput = _converter.Convert(brushStop, false); - } + var conversionOutput = _converter.Convert(brushStop, true); BasicColorCorrectionViewVM vm = null; - List<ColorConversionSuggestion> suggestions = null; - if (brushStop.IsOutOfGamut) + vm = await NotificationProvider.ShowDialog<BasicColorCorrectionViewVM>(new BasicColorCorrectionViewVM() { - vm = await NotificationProvider.ShowDialog<BasicColorCorrectionViewVM>(new BasicColorCorrectionViewVM() - { - InvalidBrushStop = brushStop, - Suggestions = new List<ColorConversionSuggestion>() { new ColorConversionSuggestion(conversionOutput.SingleCoordinates, 0, 0) }, - }); - } + InvalidBrushStop = brushStop, + Suggestions = conversionOutput.CreateTrippletSuggestions(), + }); - if (vm == null || vm.Result == BasicColorCorrectionViewVM.ColorCorrectionDialogResult.MoreOptions) + if (vm.Result == BasicColorCorrectionViewVM.ColorCorrectionDialogResult.MoreOptions) { - NotificationProvider.SetGlobalBusyMessage("Generating color hive..."); - - await Task.Factory.StartNew(() => - { - conversionOutput = _converter.Convert(brushStop, true); - - suggestions = conversionOutput.CreateHiveSuggestions(); - - if (vm == null) - { - var center = suggestions.GetCenterSuggestion(); - center.Coordinates.Red = brushStop.Red; - center.Coordinates.Green = brushStop.Green; - center.Coordinates.Blue = brushStop.Blue; - - center.Coordinates.L = brushStop.L; - center.Coordinates.A = brushStop.A; - center.Coordinates.B = brushStop.B; - } - }); - - NotificationProvider.ReleaseGlobalBusyMessage(); LogManager.Log("Invoking hive color conversion dialog..."); vm = await NotificationProvider.ShowDialog<AdvancedColorCorrectionViewVM>(new AdvancedColorCorrectionViewVM() { InvalidBrushStop = brushStop, - Suggestions = suggestions, - IsOutOfGamut = brushStop.IsOutOfGamut, + Suggestions = conversionOutput.CreateHiveSuggestions(), }); } @@ -953,13 +916,6 @@ namespace Tango.PPC.Jobs.ViewModels brushStop.A = vm.SelectedSuggestion.Coordinates.A; brushStop.B = vm.SelectedSuggestion.Coordinates.B; } - else if (brushStop.BrushColorSpace == BL.Enumerations.ColorSpaces.Volume) - { - if (vm.SelectedSuggestion != suggestions.GetCenterSuggestion()) - { - vm.SelectedSuggestion.ApplyOnBrushStop(brushStop); - } - } brushStop.Corrected = true; brushStop.IsOutOfGamut = false; @@ -971,11 +927,6 @@ namespace Tango.PPC.Jobs.ViewModels LogManager.Log(ex, "Error while invoking color adjustment dialog."); await NotificationProvider.ShowError("An error occurred while trying to convert the selected color."); } - finally - { - NotificationProvider.ReleaseGlobalBusyMessage(); - DyeCommand.RaiseCanExecuteChanged(); - } } /// <summary> @@ -985,7 +936,7 @@ namespace Tango.PPC.Jobs.ViewModels [HandleProcessCorruptedStateExceptions] public void OnBrushStopFieldValueChanged(BrushStop stop) { - if (stop != null && stop.ColorSpace != null) + if (stop != null) { stop.Corrected = false; stop.OutOfGamutChecked = false; @@ -1003,11 +954,6 @@ namespace Tango.PPC.Jobs.ViewModels stop.Blue = output.SingleCoordinates.Blue; stop.Corrected = true; stop.IsOutOfGamut = false; - - InvokeUI(() => - { - DyeCommand.RaiseCanExecuteChanged(); - }); } catch (Exception ex) { @@ -1128,7 +1074,7 @@ namespace Tango.PPC.Jobs.ViewModels /// <summary> /// Synchronizes the fine tune items to brush stops. /// </summary> - private async void SyncFineTuneItemsToBrushStops(bool displayBusy = false) + private void SyncFineTuneItemsToBrushStops() { try { @@ -1140,27 +1086,18 @@ namespace Tango.PPC.Jobs.ViewModels } else { - if (displayBusy) - { - NotificationProvider.SetGlobalBusyMessage("Generating suggestions..."); - } - FineTuneItems.Clear(); - foreach (var stop in Job.Segments.SelectMany(x => x.BrushStops).Where(x => !x.IsTransparent).Where(x => x.ColorSpace.Space == BL.Enumerations.ColorSpaces.RGB || x.ColorSpace.Space == BL.Enumerations.ColorSpaces.LAB).DistinctBy(x => x.Color)) + foreach (var stop in Job.Segments.SelectMany(x => x.BrushStops).Where(x => x.ColorSpace.Space == BL.Enumerations.ColorSpaces.RGB || x.ColorSpace.Space == BL.Enumerations.ColorSpaces.LAB).DistinctBy(x => x.Color)) { - var conversionoutput = await _converter.ConvertAsync(stop, true); - FineTuneItem item = new FineTuneItem(conversionoutput); - item.BrushStop = stop; + FineTuneItem item = new FineTuneItem(_converter.Convert(stop, true)); item.BrushStops = Job.Segments.SelectMany(x => x.BrushStops).Where(x => x.Color == stop.Color).ToList(); - item.SelectedSuggestion = item.Suggestions.GetCenterSuggestion(); + item.SelectedSuggestion = item.Suggestions[item.Suggestions.Count / 2]; item.SelectedChanged += () => StartFineTuningCommand.RaiseCanExecuteChanged(); FineTuneItems.Add(item); } _jobs_fine_tune_items[Job.Guid] = FineTuneItems.ToList(); - - NotificationProvider.ReleaseGlobalBusyMessage(); } ApprovalFineTuneItems = FineTuneItems.Where(x => x.IsSelected).ToObservableCollection(); @@ -1172,10 +1109,6 @@ namespace Tango.PPC.Jobs.ViewModels { LogManager.Log(ex, "Error while trying to synchronize fine tuning items with brush stops."); } - finally - { - NotificationProvider.ReleaseGlobalBusyMessage(); - } } /// <summary> @@ -1202,23 +1135,19 @@ namespace Tango.PPC.Jobs.ViewModels LogManager.Log(ex, "Error invoking the fine tunning palette"); await NotificationProvider.ShowError("An error occurred while trying to display the fine tunning palette."); } - finally - { - NotificationProvider.ReleaseGlobalBusyMessage(); - } } /// <summary> /// Resets the fine tuning. /// </summary> - private void ResetFineTuning(bool displayBusy = false) + private void ResetFineTuning() { if (Job != null && _jobs_fine_tune_items.ContainsKey(Job.Guid)) { _jobs_fine_tune_items.Remove(Job.Guid); } - SyncFineTuneItemsToBrushStops(displayBusy); + SyncFineTuneItemsToBrushStops(); } /// <summary> @@ -1428,8 +1357,6 @@ namespace Tango.PPC.Jobs.ViewModels { bool result = true; - if (!IsFree) return false; - if (!_can_navigate_back) { bool jobChainged = false; |
