diff options
| author | Victoria Plitt <Victoria.Plitt@twine-s.com> | 2021-11-01 14:53:16 +0200 |
|---|---|---|
| committer | Victoria Plitt <Victoria.Plitt@twine-s.com> | 2021-11-01 14:53:16 +0200 |
| commit | 20f49c625cd32b95154db138ed7eeebbadd04bf7 (patch) | |
| tree | 951627b53972a48e77f9c3d11e9de5295e15fa45 /Software/Visual_Studio/PPC/Modules/Tango.PPC.JobsV2/ViewModels | |
| parent | b1049c0822b76939215225a617e143274abe2e8b (diff) | |
| download | Tango-20f49c625cd32b95154db138ed7eeebbadd04bf7.tar.gz Tango-20f49c625cd32b95154db138ed7eeebbadd04bf7.zip | |
Color selection and Job sequence package. Redesign list control, move Color Selection View to dialogs, implement save.
Diffstat (limited to 'Software/Visual_Studio/PPC/Modules/Tango.PPC.JobsV2/ViewModels')
3 files changed, 235 insertions, 669 deletions
diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.JobsV2/ViewModels/ColorSelectionToolViewVM.cs b/Software/Visual_Studio/PPC/Modules/Tango.PPC.JobsV2/ViewModels/ColorSelectionToolViewVM.cs deleted file mode 100644 index aeb42f98b..000000000 --- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.JobsV2/ViewModels/ColorSelectionToolViewVM.cs +++ /dev/null @@ -1,285 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Tango.BL.Enumerations; -using Tango.ColorConversion; -using Tango.Core.Commands; -using Tango.Core.Threading; -using Tango.PPC.Common; -using Tango.PPC.Common.Navigation; -using Tango.PPC.Jobs.Models; -using Tango.PPC.Jobs.NavigationObjects; -using Tango.PPC.Jobs.ViewContracts; - -namespace Tango.PPC.Jobs.ViewModels -{ - public class ColorSelectionToolViewVM : PPCViewModel<IJobView>, INavigationResultProvider<BrushStopModel, ColorSelectionNavigationObject> - { - public enum ColorTab - { - HSB, - CIELab, - RGB, - CMYK, - Catalogs - } - - private ActionTimer _volumeConversionTimer; - private IColorConverter _converter; - - - #region Properties - private bool _confirmed; - - private bool _isEditMode; - - public bool IsEditMode - { - get { return _isEditMode; } - set { _isEditMode = value; - RaisePropertyChangedAuto(); - } - } - - private int _selectedColorTabIndex; - /// <summary> - /// Gets or sets the index of the selected category. - /// </summary> - public int SelectedColorTabIndex - { - get { return _selectedColorTabIndex; } - set - { - _selectedColorTabIndex = value; - RaisePropertyChangedAuto(); - RaisePropertyChanged(nameof(SelectedColorTab)); - OnSelectedtabChanged(); - } - } - - /// <summary> - /// Gets or sets the selected category. - /// </summary> - public ColorTab SelectedColorTab - { - get { return (ColorTab)SelectedColorTabIndex; } - set - { - if (SelectedColorTabIndex != value.ToInt32()) - { - SelectedColorTabIndex = value.ToInt32(); - } - } - } - - private int _segmentIndex; - - public int SegmentIndex - { - get { return _segmentIndex; } - set { _segmentIndex = value; - RaisePropertyChangedAuto(); - } - } - - - private BrushStopModel _initialBrushStop; - /// <summary> - /// Gets or sets the initial brush stop. - /// </summary> - public BrushStopModel InitialBrushStop - { - get { return _initialBrushStop; } - set { - _initialBrushStop = value; - RaisePropertyChangedAuto(); } - } - - private BrushStopModel _selectedBrushStop; - /// <summary> - /// Gets or sets the edited brush stop. - /// </summary> - public BrushStopModel SelectedBrushStop - { - get { return _selectedBrushStop; } - set - { - _selectedBrushStop = value; - RaisePropertyChangedAuto(); - } - } - - public double MaxCyanValue - { - get - { - return GetMaxCMYKValueOrDefault( LiquidTypes.Cyan); - } - } - - public double MaxMagentaValue - { - get - { - return GetMaxCMYKValueOrDefault(LiquidTypes.Magenta); - } - } - - public double MaxYellowValue - { - get - { - return GetMaxCMYKValueOrDefault(LiquidTypes.Yellow); - } - } - - public double MaxBlackValue - { - get - { - return GetMaxCMYKValueOrDefault(LiquidTypes.Black); - } - } - - #endregion - - #region Command - /// <summary> - /// Gets or sets the OK command. - /// </summary> - public RelayCommand OKCommand { get; set; } - #endregion - - public ColorSelectionToolViewVM() - { - OKCommand = new RelayCommand(Confirm); - _volumeConversionTimer = new ActionTimer(TimeSpan.FromMilliseconds(50)); - _converter = new DefaultColorConverter(); - } - - #region Navigation - /// Confirms this instance. - /// </summary> - private void Confirm() - { - _confirmed = true; - - NavigationManager.NavigateBack(); - } - - public BrushStopModel GetNavigationResult() - { - if (_confirmed) - { - return SelectedBrushStop; - } - else - { - return null; - } - } - - public void OnNavigationObjectReceived(ColorSelectionNavigationObject obj) - { - SegmentIndex = obj.SelectedSegment.SegmentIndex; - IsEditMode = obj.IsEditingMode; - if (obj.IsEditingMode) - { - InitialBrushStop = obj.BrushStopForEdit; - // InitialBrushStop.ConvertColorToRGB(); - // InitialBrushStop.InitColor(); - SelectedBrushStop = InitialBrushStop.Clone(); - SelectedBrushStop.ColorSpace = InitialBrushStop.ColorSpace; - - if(SelectedBrushStop.ColorSpace == BL.Enumerations.ColorSpaces.RGB) - SelectedColorTab = ColorTab.RGB; - else if (SelectedBrushStop.ColorSpace == BL.Enumerations.ColorSpaces.LAB) - SelectedColorTab = ColorTab.CIELab; - else if (SelectedBrushStop.ColorSpace == BL.Enumerations.ColorSpaces.CMYK) - SelectedColorTab = ColorTab.CMYK; - else if (SelectedBrushStop.ColorSpace == BL.Enumerations.ColorSpaces.Catalog) - SelectedColorTab = ColorTab.Catalogs; - else SelectedColorTab = ColorTab.HSB; - } - else - { - SelectedBrushStop = obj.BrushStopForEdit; - SelectedColorTab = ColorTab.RGB; - } - UpdateCMYKMaxValues(); - _confirmed = false; - } - - private void OnSelectedtabChanged() - { - switch (SelectedColorTab) - { - case ColorTab.HSB: - { - if (SelectedBrushStop != null) - { - SelectedBrushStop.ConvertColorToHSB(); - } - - return; - } - case ColorTab.RGB: - { - if (SelectedBrushStop != null) - { - SelectedBrushStop.ConvertColorToRGB(); - } - return; - } - case ColorTab.CIELab: - { - if (SelectedBrushStop != null) - { - SelectedBrushStop.ConvertColorToLAB(); - } - return; - } - case ColorTab.CMYK: - { - - if (SelectedBrushStop != null) - { - SelectedBrushStop.ConvertColorToCMYK(); - } - return; - } - } - } - - #endregion - - #region Methods - - private double GetMaxCMYKValueOrDefault(LiquidTypes type) - { - if (SelectedBrushStop != null && SelectedBrushStop.SegmentModel != null && SelectedBrushStop.SegmentModel.Job != null && SelectedBrushStop.SegmentModel.Job.Rml != null) - { - var liquidTypesRml = SelectedBrushStop.SegmentModel.Job.Rml.LiquidTypesRmls.FirstOrDefault(x => x.LiquidType.Type == type); - if (liquidTypesRml != null) - { - //var test = liquidTypesRml.GetMaxCalibrationValue(); - - return liquidTypesRml.GetMaxCalibrationValue(); - } - - } - return 100; - } - - private void UpdateCMYKMaxValues() - { - RaisePropertyChanged(nameof(MaxCyanValue)); - RaisePropertyChanged(nameof(MaxMagentaValue)); - RaisePropertyChanged(nameof(MaxYellowValue)); - RaisePropertyChanged(nameof(MaxBlackValue)); - } - #endregion - } -} diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.JobsV2/ViewModels/JobViewVM.cs b/Software/Visual_Studio/PPC/Modules/Tango.PPC.JobsV2/ViewModels/JobViewVM.cs index 52c961876..990f210f4 100644 --- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.JobsV2/ViewModels/JobViewVM.cs +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.JobsV2/ViewModels/JobViewVM.cs @@ -48,11 +48,11 @@ namespace Tango.PPC.Jobs.ViewModels /// Represents the selected job view model. /// </summary> /// <seealso cref="Tango.PPC.Common.PPCViewModel" /> - public class JobViewVM : PPCViewModel<IJobView>, INavigationObjectReceiver<JobNavigationObject> + public class JobViewVM : PPCViewModel<IJobView>, INavigationObjectReceiver<JobNavigationObject>, INavigationBlocker { private ObservablesContext _db; private bool _can_navigate_back; - private Thread _check_gamut_thread; + //private Thread _check_gamut_thread; private Job _job_to_load; private JobNavigationIntent _job_to_load_intent; private static Dictionary<String, List<FineTuneItem>> _jobs_fine_tune_items; @@ -435,7 +435,7 @@ namespace Tango.PPC.Jobs.ViewModels // (e.Draggable as FrameworkElement).DataContext as Segment, // (e.Droppable as FrameworkElement).DataContext as Segment); //}); - + AddColorCommand = new RelayCommand<SegmentModel>(AddColor); EditColorCommand = new RelayCommand<BrushStopModel>(EditColor); @@ -453,8 +453,8 @@ namespace Tango.PPC.Jobs.ViewModels } }); - _check_gamut_thread = new Thread(CheckGamutThreadMethod); - _check_gamut_thread.IsBackground = true; + //_check_gamut_thread = new Thread(CheckGamutThreadMethod); + //_check_gamut_thread.IsBackground = true; StartSampleDyeCommand = new RelayCommand(StartSampleDye, CanStartJob); DyeCommand = new RelayCommand(StartJob, CanStartJob); @@ -479,8 +479,8 @@ namespace Tango.PPC.Jobs.ViewModels RepeateSegmentCommand = new RelayCommand(RepeateSegment); PasteCommand = new RelayCommand(Paste); CopyCommand = new RelayCommand(Copy); - UndoCommand = new RelayCommand(Undo); - RedoCommand = new RelayCommand(Redo); + UndoCommand = new RelayCommand(Undo,(x)=> { return false; }); + RedoCommand = new RelayCommand(Redo, (x) => { return false; }); IsFullMode = true; } @@ -498,10 +498,9 @@ namespace Tango.PPC.Jobs.ViewModels { if (!(_job_to_load == null || (_job_to_load != null && Job != null && _job_to_load.Guid == Job.Guid))) { - View.ScrollToTop(); + //View.ScrollToTop(); LogManager.Log($"Loading selected job '{_job_to_load.Name}'..."); - //NotificationProvider.SetGlobalBusyMessage("Loading job details..."); IsFree = false; @@ -541,9 +540,7 @@ namespace Tango.PPC.Jobs.ViewModels .WithSegments() .WithBrushStops() .BuildAsync(); - - //Job.RmlChanged += OnRmlChanged; Job.NameChanged -= Job_NameChanged; Job.NameChanged += Job_NameChanged; @@ -568,15 +565,7 @@ namespace Tango.PPC.Jobs.ViewModels await LoadRML(_selectedRML); - if (!_check_gamut_thread.IsAlive) - { - _check_gamut_thread.Start(); - } - - // SegmentsCollectionView = CollectionViewSource.GetDefaultView(Job.Segments); - // SegmentsCollectionView.SortDescriptions.Add(new SortDescription(nameof(Segment.SegmentIndex), ListSortDirection.Ascending)); - - //ResetFineTuning(); + ///NEW CODE Save to MODEL var jobModel = new JobModel(ColorSpaces) { @@ -594,7 +583,7 @@ namespace Tango.PPC.Jobs.ViewModels foreach( var segm in Job.Segments) { - SegmentModel segmentModel = new SegmentModel(jobModel) + SegmentModel segmentModel = new SegmentModel(jobModel, segm.Guid) { Name = segm.Name, Length = segm.Length, @@ -607,6 +596,7 @@ namespace Tango.PPC.Jobs.ViewModels { BrushStopModel brushStopModel = new BrushStopModel(segmentModel) { + SegmentModel = segmentModel, Cyan = brushStop.Cyan, Magenta = brushStop.Magenta, Yellow = brushStop.Yellow, @@ -618,14 +608,16 @@ namespace Tango.PPC.Jobs.ViewModels A = brushStop.A, B = brushStop.B, OffsetPercent = brushStop.OffsetPercent, - IsTransparent = brushStop.IsTransparent, Color = brushStop.Color, DisplayedColor = brushStop.Color, ColorSpace = brushStop.ColorSpace.Space, - ColorCatalogsItem = brushStop.ColorCatalogsItem + ColorCatalogsItem = brushStop.ColorCatalogsItem, + StopIndex = brushStop.StopIndex }; - AddBrushStop(segmentModel, brushStopModel); + segmentModel.BrushStops.Add(brushStopModel); + // AddBrushStop(segmentModel, brushStopModel); } + ArrangeBrushStopsPosition(segmentModel); jobModel.Segments.Add(segmentModel); } JobModel = jobModel; @@ -691,7 +683,7 @@ namespace Tango.PPC.Jobs.ViewModels base.OnBeforeNavigatedFrom(); //Save... } - + /// <summary> /// Saves the job. /// </summary> @@ -801,43 +793,37 @@ namespace Tango.PPC.Jobs.ViewModels try { LogManager.Log("Editing the job details."); - JobCreationViewVM vm = new JobCreationViewVM( - _spoolTypes.ToList(), - _rmls.ToList() - ); + JobCreationViewVM vm = new JobCreationViewVM( _spoolTypes.ToList(),_rmls.ToList(), JobModel.InterSegmentLength, true ); vm.JobName = JobModel.Name; vm.SelectedRML = JobModel.Rml; vm.SelectedSpoolType = JobModel.SpoolType; vm = await NotificationProvider.ShowDialog<JobCreationViewVM>(vm); if (!vm.DialogResult) return; - Job.Name = vm.JobName; - JobModel.Name = vm.JobName; - bool updateVolumes = JobModel.Rml != vm.SelectedRML; - JobModel. Rml = vm.SelectedRML; - SelectedRML = vm.SelectedRML; - JobModel.Rml = vm.SelectedRML; - Job.SpoolType = vm.SelectedSpoolType; - JobModel.SpoolType = vm.SelectedSpoolType; + if(vm.IsDuplicate) + { + //Duplicate new job + /* + * int index = Jobs.Max(x => x.JobIndex); - if(updateVolumes) + List<Job> clonedJobs = new List<Job>(); + + foreach (var job in SelectedJobs) { - NotificationProvider.SetGlobalBusyMessage("Updating job liquid volumes..."); - foreach (var stop in JobModel.Segments.SelectMany(x => x.BrushStops).Where(x => x.ColorSpace == BL.Enumerations.ColorSpaces.RGB || x.ColorSpace == BL.Enumerations.ColorSpaces.LAB).ToList()) - { - try - { - stop.OnBrushStopFieldValueChanged(); - //TODO ASK ROY!!!!!! - //output.ApplyOnBrushStopVolumesOnly(stop); - } - catch (Exception ex) - { - LogManager.Log(ex, $"Error updating stop volumes after changing thread on segment {stop.SegmentModel.SegmentIndex}, stop {stop.StopIndex}."); - } - } - NotificationProvider.ReleaseGlobalBusyMessage(); + var cloned = job.Clone(); + cloned.JobIndex = ++index; + _db.Jobs.Add(cloned); + clonedJobs.Add(cloned); } + + await _db.SaveChangesAsync(); + * */ + } + Job.Name = vm.JobName; + JobModel.Name = vm.JobName; + Job.SpoolType = vm.SelectedSpoolType; + JobModel.SpoolType = vm.SelectedSpoolType;//update length!!!! + SelectedRML = vm.SelectedRML; } catch (Exception ex) { @@ -845,9 +831,22 @@ namespace Tango.PPC.Jobs.ViewModels } } - private void RepeatUnits() + private async void RepeatUnits() { - //open dialog + var maxLength = Job.SpoolType.Length; + var maxRep = (maxLength == 0 ? 999 : (maxLength / JobModel.Length)); + + + var vm = await NotificationProvider.ShowDialog<RepeatJobViewVM>(new RepeatJobViewVM() + { + MaxRepeations = (int)maxRep, + Repeats = JobModel.NumberOfUnits + }); + + if (vm.DialogResult) + { + JobModel.NumberOfUnits = vm.Repeats; + } } #endregion @@ -865,7 +864,7 @@ namespace Tango.PPC.Jobs.ViewModels { if (Job.Rml != rml || rml.Cct == null) { - bool updateVolumes = Job.Rml != rml; + bool updateRML = Job.Rml != rml; Job.Rml = await new RmlBuilder(_db) .Set(rml.Guid) @@ -875,32 +874,50 @@ namespace Tango.PPC.Jobs.ViewModels .WithLiquidFactors() .WithSpools() .BuildAsync(); - - //foreach (var segment in Job.Segments) - //{ - // SetSegmentLiquidVolumes(segment); - //} - + if(JobModel != null) + JobModel.Rml = Job.Rml; + GetLubricationLevel(); await SetSpoolTension(rml); - if (updateVolumes) + if (updateRML && JobModel != null) { - NotificationProvider.SetGlobalBusyMessage("Updating job liquid volumes..."); - foreach (var stop in Job.Segments.SelectMany(x => x.BrushStops).Where(x => x.BrushColorSpace == BL.Enumerations.ColorSpaces.RGB || x.BrushColorSpace == BL.Enumerations.ColorSpaces.LAB).ToList()) + NotificationProvider.SetGlobalBusyMessage("Updating IsOutOfGammut due to the change RML..."); + foreach (var stop in JobModel.Segments.SelectMany(x => x.BrushStops).Where(x => x.ColorSpace == BL.Enumerations.ColorSpaces.RGB || x.ColorSpace == BL.Enumerations.ColorSpaces.LAB).ToList()) { try { - var output = await _converter.ConvertAsync(stop, false, false); - output.ApplyOnBrushStopVolumesOnly(stop); + stop.OnBrushStopFieldValueChanged(); + //TODO ASK ROY!!!!!! + //output.ApplyOnBrushStopVolumesOnly(stop); } catch (Exception ex) { - LogManager.Log(ex, $"Error updating stop volumes after changing thread on segment {stop.Segment.SegmentIndex}, stop {stop.StopIndex}."); + LogManager.Log(ex, $"Error updating stop volumes after changing thread on segment {stop.SegmentModel.SegmentIndex}, stop {stop.StopIndex}."); } } + DyeCommand.RaiseCanExecuteChanged(); + StartSampleDyeCommand.RaiseCanExecuteChanged(); + StartFineTuningCommand.RaiseCanExecuteChanged(); NotificationProvider.ReleaseGlobalBusyMessage(); } + //if (updateVolumes) + //{ + // NotificationProvider.SetGlobalBusyMessage("Updating job liquid volumes..."); + // foreach (var stop in Job.Segments.SelectMany(x => x.BrushStops).Where(x => x.BrushColorSpace == BL.Enumerations.ColorSpaces.RGB || x.BrushColorSpace == BL.Enumerations.ColorSpaces.LAB).ToList()) + // { + // try + // { + // var output = await _converter.ConvertAsync(stop, false, false); + // output.ApplyOnBrushStopVolumesOnly(stop); + // } + // catch (Exception ex) + // { + // LogManager.Log(ex, $"Error updating stop volumes after changing thread on segment {stop.Segment.SegmentIndex}, stop {stop.StopIndex}."); + // } + // } + // NotificationProvider.ReleaseGlobalBusyMessage(); + //} } } } @@ -1022,204 +1039,6 @@ namespace Tango.PPC.Jobs.ViewModels #region Brush Stops Management - //private void Stop_ColorCatalogChanged(object sender, ColorCatalog catalog) - //{ - // BrushStop stop = sender as BrushStop; - - // if (stop.ColorSpace != null && stop.BrushColorSpace == BL.Enumerations.ColorSpaces.Catalog) - // { - // if (stop.ColorCatalogsItem != null) - // { - // try - // { - // if (catalog != null && catalog.AllItemsOrdered.Count > 0) - // { - // stop.ColorCatalogsItem = catalog.GetClosestItem(stop.ColorCatalogsItem.Color); - // } - // else - // { - // stop.ColorCatalogsItem = null; - // } - // } - // catch (Exception ex) - // { - // LogManager.Log(ex, "Error getting closest catalog color."); - // stop.ColorCatalogsItem = null; - // } - // } - // } - //} - - - /// <summary> - /// Invokes the color adjustment for the specified brush stop. - /// </summary> - /// <param name="brushStop">The brush stop.</param> - private async void InvokeColorAdjustmentForBrushStop(BrushStop brushStop) - { - try - { - 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); - } - - BasicColorCorrectionViewVM vm = null; - List<ColorConversionSuggestion> suggestions = null; - - if (brushStop.IsOutOfGamut) - { - vm = await NotificationProvider.ShowDialog<BasicColorCorrectionViewVM>(new BasicColorCorrectionViewVM() - { - InvalidBrushStop = brushStop, - Suggestions = new List<ColorConversionSuggestion>() { new ColorConversionSuggestion(conversionOutput.SingleCoordinates, 0, 0) }, - }); - } - - if (vm == null || 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, - }); - } - - if (vm.Result == BasicColorCorrectionViewVM.ColorCorrectionDialogResult.Confirmed) - { - LogManager.Log($"Color suggestion selected: {vm.SelectedSuggestion.Color.ToString()}."); - - if (brushStop.BrushColorSpace == BL.Enumerations.ColorSpaces.RGB) - { - brushStop.Red = vm.SelectedSuggestion.Coordinates.Red; - brushStop.Green = vm.SelectedSuggestion.Coordinates.Green; - brushStop.Blue = vm.SelectedSuggestion.Coordinates.Blue; - } - else if (brushStop.BrushColorSpace == BL.Enumerations.ColorSpaces.LAB) - { - brushStop.L = vm.SelectedSuggestion.Coordinates.L; - brushStop.A = vm.SelectedSuggestion.Coordinates.A; - brushStop.B = vm.SelectedSuggestion.Coordinates.B; - } - else if (brushStop.BrushColorSpace == BL.Enumerations.ColorSpaces.Volume) - { - vm.SelectedSuggestion.ApplyOnBrushStop(brushStop); - } - - brushStop.Corrected = true; - brushStop.IsOutOfGamut = false; - brushStop.OutOfGamutChecked = true; - } - } - catch (Exception ex) - { - 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> - /// Called when the brush stop field value has been changed (This called from the view!). - /// </summary> - /// <param name="stop">The brush stop.</param> - [HandleProcessCorruptedStateExceptions] - public void OnBrushStopFieldValueChanged(BrushStop stop) - { - if (stop != null && stop.ColorSpace != null) - { - if (stop.BrushColorSpace == BL.Enumerations.ColorSpaces.Catalog) - { - DyeCommand.RaiseCanExecuteChanged(); - return; - } - - _volumeConversionTimer.ResetReplace(() => - { - - try - { - var output = _converter.Convert(stop, false); - - if (stop.BrushColorSpace == BL.Enumerations.ColorSpaces.Volume) - { - stop.Red = output.SingleCoordinates.Red; - stop.Green = output.SingleCoordinates.Green; - stop.Blue = output.SingleCoordinates.Blue; - stop.L = output.SingleCoordinates.L; - stop.A = output.SingleCoordinates.A; - stop.B = output.SingleCoordinates.B; - stop.Corrected = false; - stop.OutOfGamutChecked = false; - } - else if (stop.BrushColorSpace == BL.Enumerations.ColorSpaces.LAB) - { - output.ApplyOnBrushStopVolumesOnly(stop); - stop.Corrected = false; - stop.OutOfGamutChecked = false; - } - else if (stop.BrushColorSpace == BL.Enumerations.ColorSpaces.RGB) - { - output.ApplyOnBrushStopVolumesOnly(stop); - stop.Corrected = false; - stop.OutOfGamutChecked = false; - } - - try - { - var closestItem = AvailableCatalogs.SelectMany(x => x.AllItemsOrdered).GetClosestItem(stop.Color); - stop.ColorCatalog = closestItem.ColorCatalogsGroup.ColorCatalog; - stop.ColorCatalogsItem = closestItem; - } - catch { } - } - catch (Exception ex) - { - LogManager.Log(ex, "An error occurred while trying to get volume => RGB from conversion engine."); - } - finally - { - InvokeUI(() => DyeCommand.RaiseCanExecuteChanged()); - } - - }); - - } - } - /// <summary> /// Opens the twine catalog for the specified brush stop. /// </summary> @@ -1244,12 +1063,23 @@ namespace Tango.PPC.Jobs.ViewModels // } //} - private void ArrangeBrushStopsIndices(Segment segment) + private void ArrangeBrushStopsIndexes(SegmentModel segment) { for (int i = 0; i < segment.BrushStops.Count; i++) { segment.BrushStops[i].StopIndex = i + 1; } + ArrangeBrushStopsPosition(segment); + } + + private void ArrangeBrushStopsPosition(SegmentModel segment) + { + if(segment.BrushStops.Count == 1) + { + segment.BrushStops.FirstOrDefault().Position = BrushStopModel.PositionStatus.FirstColor; + } + else if (segment.BrushStops.Count > 1) + segment.BrushStops.ToList().ForEach(x => x.Position = (BrushStopModel.PositionStatus)x.StopIndex); } private bool ValidateBrushStops() @@ -1269,15 +1099,21 @@ namespace Tango.PPC.Jobs.ViewModels await NotificationProvider.ShowInfo("Color transitions are best visible with segment length of 5 meters and above."); } - var newBrushStop = await NavigationManager.NavigateForResult<JobsV2Module, ColorSelectionToolView, BrushStopModel, ColorSelectionNavigationObject>( - new ColorSelectionNavigationObject() + var vm = await NotificationProvider.ShowDialog<ColorSelectionViewVM>(new ColorSelectionViewVM() + { + DialogEditObject = new ColorSelectionViewVM.DialogObject() { SelectedSegment = segment, BrushStopForEdit = new BrushStopModel(segment), - IsEditingMode = false - }, true); - - AddBrushStop(segment, newBrushStop); + IsEditingMode = false, + } + }); + + if (vm.DialogResult) + { + AddBrushStop(segment, vm.SelectedBrushStop); + DyeCommand.RaiseCanExecuteChanged(); + } // SetSegmentLiquidVolumes(segment); //RegisterJobBrushStopsEvents(); } @@ -1289,18 +1125,22 @@ namespace Tango.PPC.Jobs.ViewModels { SegmentModel segment = brushStop.SegmentModel; LogManager.Log($"Edit brush stop."); - - var newBrushStop = await NavigationManager.NavigateForResult<JobsV2Module, ColorSelectionToolView, BrushStopModel, ColorSelectionNavigationObject>( - new ColorSelectionNavigationObject() + + var vm = await NotificationProvider.ShowDialog<ColorSelectionViewVM>(new ColorSelectionViewVM() + { + DialogEditObject = new ColorSelectionViewVM.DialogObject() { SelectedSegment = segment, BrushStopForEdit = brushStop, - IsEditingMode = true - }, true); + IsEditingMode = true, + } + }); - if(newBrushStop != null) + + if (vm.DialogResult) { - segment.SetNewColor(brushStop,newBrushStop); + segment.SetNewColor(brushStop, vm.SelectedBrushStop); + DyeCommand.RaiseCanExecuteChanged(); } } @@ -1310,29 +1150,23 @@ namespace Tango.PPC.Jobs.ViewModels public async void AddBrushStop(SegmentModel segment, BrushStopModel newBrushStop) { if (newBrushStop == null || segment == null) - return; - - JobModel job = segment.Job; - + return; + Segment s = new Segment(); //SolidColor - if(segment.BrushStops.Count == 0) + if (segment.BrushStops.Count == 0) { - newBrushStop.IsFirstColorBrush = true; + newBrushStop.Position = BrushStopModel.PositionStatus.FirstColor; segment.BrushStops.Add(newBrushStop); } - //Add SecondColor + //Add Second BrushStop else if(segment.BrushStops.Count == 1)// add gradient { BrushStopModel currentBrushStop = segment.BrushStops[0]; segment.CreateGradientBrushes(segment.BrushStops[0], newBrushStop); segment.RaiseSegmentBrushChanged(); } - else + else //Create new Segment and Add BrushStop { - if (segment.BrushStops.Count < 5) - { - return; - } await NotificationProvider.ShowInfo("Please note that gradient segment is now split into two gradients."); SegmentModel newSegmentModel = segment.Clone(); @@ -1347,12 +1181,14 @@ namespace Tango.PPC.Jobs.ViewModels segment.AddOrReplaceSecondBrush(newBrushStop); segment.UpdateMiddleColorBrush(); segment.RaiseSegmentBrushChanged(); + ArrangeBrushStopsIndexes(segment); + ArrangeBrushStopsIndexes(newSegmentModel); - if(job.Segments.Count == segment.SegmentIndex) - job.Segments.Add(newSegmentModel); + if (JobModel.Segments.Count == segment.SegmentIndex) + JobModel.Segments.Add(newSegmentModel); else { - job.Segments.Insert(segment.SegmentIndex, newSegmentModel); + JobModel.Segments.Insert(segment.SegmentIndex, newSegmentModel); } ArrangeSegmentsIndixes(); } @@ -1596,51 +1432,7 @@ namespace Tango.PPC.Jobs.ViewModels #region Out Of Gamut Check Thread - /// <summary> - /// Iterates over all brush stops and checks for out of gamut. - /// </summary> - [HandleProcessCorruptedStateExceptions] - private void CheckGamutThreadMethod() - { - while (true) - { - Thread.Sleep(500); - - if (Job != null && Job.Rml.Cct != null && IsVisible) - { - var brushStops = Job.Segments.SelectMany(x => x.BrushStops).Where(x => x.ColorSpace != null).Where(x => (x.BrushColorSpace == BL.Enumerations.ColorSpaces.LAB || x.BrushColorSpace == BL.Enumerations.ColorSpaces.RGB) && !x.Corrected && !x.OutOfGamutChecked).ToList(); - - foreach (var stop in brushStops) - { - try - { - stop.IsOutOfGamut = _converter.IsOutOfGamut(stop); - stop.OutOfGamutChecked = true; - } - catch (AccessViolationException) - { - LogManager.Log($"Out of gamut check failed for brush stop {stop.StopIndex} at segment {stop.Segment.SegmentIndex}.", LogCategory.Warning); - continue; - } - catch - { - LogManager.Log($"Out of gamut check failed for brush stop {stop.StopIndex} at segment {stop.Segment.SegmentIndex}.", LogCategory.Warning); - } - } - - if (brushStops.Count > 0) - { - InvokeUI(() => - { - DyeCommand.RaiseCanExecuteChanged(); - StartSampleDyeCommand.RaiseCanExecuteChanged(); - StartFineTuningCommand.RaiseCanExecuteChanged(); - }); - } - } - } - } - + #endregion #region Lubrication Level @@ -1755,6 +1547,11 @@ namespace Tango.PPC.Jobs.ViewModels _job_to_load_intent = JobNavigationIntent.Default; } + public override void OnNavigatedTo(PPCViewModel fromVM) + { + base.OnNavigatedTo(fromVM); + } + /// <summary> /// Called before the navigation system navigates back from this object. /// Return false to abort the navigation. @@ -1762,40 +1559,17 @@ namespace Tango.PPC.Jobs.ViewModels /// <returns></returns> public async override Task<bool> OnNavigateBackRequest() { - bool result = true; - - if (!IsFree) return false; - - if (!_can_navigate_back) + try { - bool jobChainged = false; - - if (Job != null) - { - string job_string = Job.ToJobFileWhenLoaded().ToString(); - jobChainged = job_string != _current_job_string; - } - - if (jobChainged) - { - if (await NotificationProvider.ShowQuestion("Are you sure you want to exit this job without saving changes?")) - { - Job = null; - SegmentsCollectionView = null; - } - else - { - result = false; - } - } - else - { - Job = null; - SegmentsCollectionView = null; - } + await Save(); + return true; + } + catch (Exception ex) + { + LogManager.Log(ex, "Error saving job to database."); + await NotificationProvider.ShowError("Error saving the current job."); + return false; } - - return result; } public override void OnApplicationReady() @@ -1832,16 +1606,21 @@ namespace Tango.PPC.Jobs.ViewModels { if (false == JobModel.Segments.ToList().Any(x => x.IsSelected)) return; - var firstIndex = JobModel.Segments.ToList().FindIndex(i => i.IsSelected == true); - var lastIndex = JobModel.Segments.ToList().FindLastIndex(i => i.IsSelected == true); - if(firstIndex < lastIndex) + + for (int firstIndex = 0, lastIndex = JobModel.Segments.Count - 1; firstIndex < lastIndex; firstIndex++) { - //TODO function! - //var copy = JobModel.Segments.ToList(); - //copy.Reverse(firstIndex, (lastIndex - firstIndex + 1)); - //JobModel.Segments = new SynchronizedObservableCollection<SegmentModel>(copy); - //ArrangeSegmentsIndixes(); + if (JobModel.Segments[firstIndex].IsSelected) + { + for (; lastIndex >= 0; lastIndex--) + { + if (JobModel.Segments[lastIndex].IsSelected) + { + JobModel.SwapSegments(firstIndex, lastIndex); + } + } + } } + ArrangeSegmentsIndixes(); } private async void DeleteSegment() @@ -1902,5 +1681,80 @@ namespace Tango.PPC.Jobs.ViewModels } #endregion + + private async Task Save() + { + if (JobModel == null) + return; + var colorSpaces = await _db.ColorSpaces.ToListAsync(); + + Job.ColorSpace = colorSpaces.FirstOrDefault(); + + var oldSegments = Job.Segments.ToList(); + + foreach (var segment in Job.Segments.ToList()) + { + foreach (var stop in segment.BrushStops.ToList()) + { + _db.BrushStops.Remove(stop); + } + + _db.Segments.Remove(segment); + } + + Job.Segments.Clear(); + + foreach (var segment in JobModel.Segments.OrderBy(x => x.SegmentIndex).ToList()) + { + var dbSegment = new Segment(); + dbSegment.Name = "Standard Segment"; + + dbSegment.Job = Job; + dbSegment.SegmentIndex = segment.SegmentIndex; + dbSegment.Length = segment.Length; + + _db.Segments.Add(dbSegment); + + foreach (var stop in segment.BrushStops.OrderBy(x => x.StopIndex).ToList()) + { + var dbStop = new BrushStop(); + dbStop.Segment = dbSegment; + _db.BrushStops.Add(dbStop); + + dbStop.ColorSpace = colorSpaces.FirstOrDefault(x => x.Code == (int)stop.ColorSpace); + dbStop.Red = stop.Red; + dbStop.Green = stop.Green; + dbStop.Blue = stop.Blue; + dbStop.L = stop.L; + dbStop.A = stop.A; + dbStop.B = stop.B; + dbStop.Cyan = stop.Cyan; + dbStop.Magenta = stop.Magenta; + dbStop.Yellow = stop.Yellow; + dbStop.Black = stop.Black; + dbStop.BestMatchR = stop.DisplayedColor.R; + dbStop.BestMatchG = stop.DisplayedColor.G; + dbStop.BestMatchB = stop.DisplayedColor.B; + + dbStop.OffsetPercent = stop.OffsetPercent; + dbStop.StopIndex = stop.StopIndex; + dbStop.IsOutOfGamut = stop.IsOutOfGamut; + + + dbStop.SetVolume(LiquidTypes.Cyan, stop.Cyan); + dbStop.SetVolume(LiquidTypes.Magenta, stop.Magenta); + dbStop.SetVolume(LiquidTypes.Yellow, stop.Yellow); + dbStop.SetVolume(LiquidTypes.Black, stop.Black); + } + } + Job.LastUpdated = DateTime.UtcNow; + Job.IsSynchronized = false; + Job.JobStatus = BL.Enumerations.JobStatuses.Draft; + //_current_job_string = Job.ToJobFileWhenLoaded().ToString(); + RaiseMessage(new JobSavedMessage() { Job = Job }); + + await _db.SaveChangesAsync(); + + } } } diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.JobsV2/ViewModels/JobsViewVM.cs b/Software/Visual_Studio/PPC/Modules/Tango.PPC.JobsV2/ViewModels/JobsViewVM.cs index 0a1ce7df7..1f7042b57 100644 --- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.JobsV2/ViewModels/JobsViewVM.cs +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.JobsV2/ViewModels/JobsViewVM.cs @@ -422,10 +422,7 @@ namespace Tango.PPC.Jobs.ViewModels { await Task.Delay(200); } - JobCreationViewVM vm = new JobCreationViewVM( - _spoolTypes.ToList(), - _rmls.ToList() - ); + JobCreationViewVM vm = new JobCreationViewVM( _spoolTypes.ToList(), _rmls.ToList(), 3, false ); string selectedRmlGuid = (Settings.DefaultRmlGuid != null && _rmls.Select(x => x.Guid).Contains(Settings.DefaultRmlGuid)) ? Settings.DefaultRmlGuid : _rmls.FirstOrDefault().Guid; string selectedSpoolTypeGuid = Settings.DefaultSpoolTypeGuid != null ? Settings.DefaultSpoolTypeGuid : Adapter.SpoolTypes.FirstOrDefault().Guid; ; |
