diff options
| author | Roy Ben-Shabat <Roy@Twine-s.com> | 2019-07-01 17:56:49 +0300 |
|---|---|---|
| committer | Roy Ben-Shabat <Roy@Twine-s.com> | 2019-07-01 17:56:49 +0300 |
| commit | 8a1e772f025eaf3bfdf17905d9e33c460993e559 (patch) | |
| tree | b6d705cca71033cd6c5f814596ceb9abc849bf50 /Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/JobViewVM.cs | |
| parent | c0fd8dcc53e45aa5aa0095cc2c8c5f39a34f7886 (diff) | |
| download | Tango-8a1e772f025eaf3bfdf17905d9e33c460993e559.tar.gz Tango-8a1e772f025eaf3bfdf17905d9e33c460993e559.zip | |
Many bug fixes !!!
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 | 47 |
1 files changed, 38 insertions, 9 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 3a777e142..0d1d2f3cb 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 @@ -407,7 +407,7 @@ namespace Tango.PPC.Jobs.ViewModels _check_gamut_thread = new Thread(CheckGamutThreadMethod); _check_gamut_thread.IsBackground = true; - StartSampleDyeCommand = new RelayCommand(StartSampleDye); + StartSampleDyeCommand = new RelayCommand(StartSampleDye, CanStartJob); DyeCommand = new RelayCommand(StartJob, CanStartJob); ApproveSampleCommand = new RelayCommand(ApproveSampleDye); @@ -415,7 +415,7 @@ namespace Tango.PPC.Jobs.ViewModels AnotherSampleCommand = new RelayCommand(DyeAnotherSample); InvokeFineTuningPaletteCommand = new RelayCommand<FineTuneItem>(InvokeFineTuningPalette); ResetFineTuningCommand = new RelayCommand(ResetFineTuning); - StartFineTuningCommand = new RelayCommand(StartFineTuning, () => FineTuneItems.Any(x => x.IsSelected)); + StartFineTuningCommand = new RelayCommand(StartFineTuning, () => FineTuneItems.Any(x => x.IsSelected) && CanStartJob()); RepeatFineTuningCommand = new RelayCommand(RepeatFineTuning); ApproveFineTuningCommand = new RelayCommand(ApproveFineTuning); OpenTwineCatalogCommand = new RelayCommand<BrushStop>(OpenTwineCatalog); @@ -463,6 +463,8 @@ namespace Tango.PPC.Jobs.ViewModels Job.RmlChanged -= OnRmlChanged; Job.RmlChanged += OnRmlChanged; + Job.NameChanged -= Job_NameChanged; + Job.NameChanged += Job_NameChanged; Job.ValidateOnPropertyChanged = true; @@ -490,6 +492,7 @@ namespace Tango.PPC.Jobs.ViewModels SegmentsCollectionView = CollectionViewSource.GetDefaultView(Job.Segments); SegmentsCollectionView.SortDescriptions.Add(new SortDescription(nameof(Segment.SegmentIndex), ListSortDirection.Ascending)); + ResetFineTuning(); _job_to_load = null; } @@ -517,7 +520,11 @@ namespace Tango.PPC.Jobs.ViewModels View.DisplayFineTuning(); } + ValidateBrushStops(); + DyeCommand.RaiseCanExecuteChanged(); + StartSampleDyeCommand.RaiseCanExecuteChanged(); + StartFineTuningCommand.RaiseCanExecuteChanged(); } catch (Exception ex) { @@ -534,6 +541,11 @@ namespace Tango.PPC.Jobs.ViewModels } } + private void Job_NameChanged(object sender, string e) + { + DyeCommand.RaiseCanExecuteChanged(); + } + /// <summary> /// Saves the job. /// </summary> @@ -564,12 +576,17 @@ namespace Tango.PPC.Jobs.ViewModels Job.LastUpdated = DateTime.UtcNow; Job.JobStatus = BL.Enumerations.JobStatuses.Draft; await _db.SaveChangesAsync(); - RaiseMessage(new JobSavedMessage() { Job = Job }); if (displayNotification) { await NotificationProvider.ShowInfo(String.Format("Job '{0}' saved successfully.", Job.Name)); } + + RaiseMessage(new JobSavedMessage() { Job = Job }); + } + else + { + await NotificationProvider.ShowError($"Error saving job. {Job.ValidationErrors.FirstOrDefault()}"); } } catch (Exception ex) @@ -617,7 +634,7 @@ namespace Tango.PPC.Jobs.ViewModels catch (Exception ex) { LogManager.Log(ex, "Could not start the current job."); - await NotificationProvider.ShowError($"Cannot start job.\n{ex.Message}."); + await NotificationProvider.ShowError($"{ex.Message}."); } } @@ -627,7 +644,7 @@ namespace Tango.PPC.Jobs.ViewModels private bool CanStartJob() { return - Job != null && + Job != null && Job.Validate(_db) && !Job.Segments.SelectMany(x => x.BrushStops).ToList().Exists(x => x.IsOutOfGamut); } @@ -653,6 +670,8 @@ namespace Tango.PPC.Jobs.ViewModels var replacement = CoatsCatalogItems.SingleOrDefault(x => x.Name == stop.ColorCatalog.Name); stop.ColorCatalog = replacement; } + + ResetFineTuning(); } #endregion @@ -748,6 +767,8 @@ namespace Tango.PPC.Jobs.ViewModels _db.Segments.Remove(segment); ArrangeSegmentsIndices(); + + DyeCommand.RaiseCanExecuteChanged(); } } catch (Exception ex) @@ -815,8 +836,9 @@ namespace Tango.PPC.Jobs.ViewModels if (brushStop.Segment.BrushStops.Count > 2) { LogManager.Log($"removing brush stop {brushStop.StopIndex} from segment {brushStop.Segment.SegmentIndex}."); + var segment = brushStop.Segment; _db.BrushStops.Remove(brushStop); - ArrangeBrushStopsIndices(brushStop.Segment); + ArrangeBrushStopsIndices(segment); } else { @@ -946,6 +968,11 @@ namespace Tango.PPC.Jobs.ViewModels } } + private bool ValidateBrushStops() + { + return Job.Segments.SelectMany(x => x.BrushStops).ToList().All(x => x.Validate(_db)); + } + #endregion #region Job Selection Message @@ -979,7 +1006,7 @@ namespace Tango.PPC.Jobs.ViewModels catch (Exception ex) { LogManager.Log(ex, $"Error executing sample dye for job {Job.Name}."); - await NotificationProvider.ShowError("An error occurred while trying to execute the sample dye."); + await NotificationProvider.ShowError(ex.Message); } } @@ -1119,7 +1146,7 @@ namespace Tango.PPC.Jobs.ViewModels catch (Exception ex) { LogManager.Log(ex, "Error executing fine tuning job."); - await NotificationProvider.ShowError("An error occurred while trying to start the fine tuning job."); + await NotificationProvider.ShowError(ex.Message); } } @@ -1177,7 +1204,7 @@ namespace Tango.PPC.Jobs.ViewModels { Thread.Sleep(500); - if (Job != null && IsVisible && (Job.ColorSpace != null && (Job.ColorSpace.Code == BL.Enumerations.ColorSpaces.RGB.ToInt32() || Job.ColorSpace.Code == BL.Enumerations.ColorSpaces.LAB.ToInt32()))) + if (Job != null && Job.Rml.Ccts.Count > 0 && IsVisible && (Job.ColorSpace != null && (Job.ColorSpace.Code == BL.Enumerations.ColorSpaces.RGB.ToInt32() || Job.ColorSpace.Code == BL.Enumerations.ColorSpaces.LAB.ToInt32()))) { var brushStops = Job.Segments.SelectMany(x => x.BrushStops).Where(x => !x.Corrected && !x.OutOfGamutChecked).ToList(); @@ -1199,6 +1226,8 @@ namespace Tango.PPC.Jobs.ViewModels InvokeUI(() => { DyeCommand.RaiseCanExecuteChanged(); + StartSampleDyeCommand.RaiseCanExecuteChanged(); + StartFineTuningCommand.RaiseCanExecuteChanged(); }); } } |
