diff options
| author | Shlomo Hecht <shlomo@twine-s.com> | 2019-04-23 22:25:54 +0300 |
|---|---|---|
| committer | Shlomo Hecht <shlomo@twine-s.com> | 2019-04-23 22:25:54 +0300 |
| commit | ebcb9ce27131e4bbd14c96b5f897a67bc752aaeb (patch) | |
| tree | 293aee8b1751ce7fce542645722c0f1a96b73097 /Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/JobViewVM.cs | |
| parent | 52967e858bd52621208f6360e84f4c47ec435816 (diff) | |
| parent | 636ad730569dfef1a4ee04c8d716d510bcc47ee1 (diff) | |
| download | Tango-ebcb9ce27131e4bbd14c96b5f897a67bc752aaeb.tar.gz Tango-ebcb9ce27131e4bbd14c96b5f897a67bc752aaeb.zip | |
merge alarm handling from remote
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 | 106 |
1 files changed, 81 insertions, 25 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 f0cf87079..713dfce42 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 @@ -31,6 +31,9 @@ using Tango.Logging; using Tango.PPC.Common.Messages; using Tango.BL.Builders; using Tango.PPC.Jobs.AppButtons; +using Tango.Core.Threading; +using System.Diagnostics; +using System.Runtime.ExceptionServices; namespace Tango.PPC.Jobs.ViewModels { @@ -47,6 +50,7 @@ namespace Tango.PPC.Jobs.ViewModels private JobNavigationIntent _job_to_load_intent; private static Dictionary<String, List<FineTuneItem>> _jobs_fine_tune_items; private StartPrintingButton _start_printing_btn; + private ActionTimer _volumeConversionTimer; #region Properties @@ -319,6 +323,8 @@ namespace Tango.PPC.Jobs.ViewModels /// </summary> public JobViewVM() { + _volumeConversionTimer = new ActionTimer(TimeSpan.FromMilliseconds(50)); + RegisterForMessage<JobSelectedMessage>(HandleJobSelectedMessage); FineTuneItems = new ObservableCollection<FineTuneItem>(); @@ -396,7 +402,8 @@ namespace Tango.PPC.Jobs.ViewModels { LogManager.Log($"Loading selected job '{_job_to_load.Name}'..."); - NotificationProvider.SetGlobalBusyMessage("Loading job details..."); + //NotificationProvider.SetGlobalBusyMessage("Loading job details..."); + IsFree = false; _can_navigate_back = false; @@ -425,6 +432,11 @@ namespace Tango.PPC.Jobs.ViewModels Customers = await _db.Customers.Where(x => x.OrganizationGuid == MachineProvider.Machine.OrganizationGuid).ToListAsync(); TwineCatalogItems = await _db.ColorCatalogs.Where(x => x.RmlGuid == Job.Rml.Guid && x.ColorSpace.Code == (int)BL.Enumerations.ColorSpaces.Twine).OrderBy(x => x.Name).ToListAsync(); + foreach (var segment in Job.Segments) + { + SetSegmentLiquidVolumesIfVolume(segment); + } + if (!_check_gamut_thread.IsAlive) { _check_gamut_thread.Start(); @@ -433,10 +445,6 @@ namespace Tango.PPC.Jobs.ViewModels SegmentsCollectionView = CollectionViewSource.GetDefaultView(Job.Segments); SegmentsCollectionView.SortDescriptions.Add(new SortDescription(nameof(Segment.SegmentIndex), ListSortDirection.Ascending)); - InvokeUIOnIdle(() => - { - NotificationProvider.ReleaseGlobalBusyMessage(); - }); _job_to_load = null; } @@ -471,10 +479,16 @@ namespace Tango.PPC.Jobs.ViewModels LogManager.Log(ex, $"Error loading job '{_job_to_load.Name}'"); await NotificationProvider.ShowError("An error occurred while trying to load the selected job."); } + finally + { + InvokeUIOnIdle(() => + { + IsFree = true; + //NotificationProvider.ReleaseGlobalBusyMessage(); + }); + } } - - /// <summary> /// Saves the job. /// </summary> @@ -545,18 +559,18 @@ namespace Tango.PPC.Jobs.ViewModels /// <summary> /// Starts the job. /// </summary> - private void StartJob() + private async void StartJob() { try { LogManager.Log("Start job command pressed. Starting job and navigating to job progress view..."); - PrintingManager.Print(Job, _db); - NavigationManager.NavigateTo<JobsModule>(nameof(JobProgressView)); + await PrintingManager.Print(Job, _db); + await NavigationManager.NavigateTo<JobsModule>(nameof(JobProgressView)); } catch (Exception ex) { LogManager.Log(ex, "Could not start the current job."); - NotificationProvider.ShowError($"Cannot start job.\n{ex.Message}."); + await NotificationProvider.ShowError($"Cannot start job.\n{ex.Message}."); } } @@ -598,7 +612,9 @@ namespace Tango.PPC.Jobs.ViewModels try { LogManager.Log("Adding new solid segment..."); - return Job.AddSolidSegment(MachineProvider.Machine.DefaultSegmentLength > 0 ? MachineProvider.Machine.DefaultSegmentLength : 10); + var s = Job.AddSolidSegment(MachineProvider.Machine.DefaultSegmentLength > 0 ? MachineProvider.Machine.DefaultSegmentLength : 10); + SetSegmentLiquidVolumesIfVolume(s); + return s; } catch (Exception ex) { @@ -616,7 +632,9 @@ namespace Tango.PPC.Jobs.ViewModels try { LogManager.Log("Adding new gradient segment..."); - return Job.AddGradientSegment(MachineProvider.Machine.DefaultSegmentLength > 0 ? MachineProvider.Machine.DefaultSegmentLength : 10); + var s = Job.AddGradientSegment(MachineProvider.Machine.DefaultSegmentLength > 0 ? MachineProvider.Machine.DefaultSegmentLength : 10); + SetSegmentLiquidVolumesIfVolume(s); + return s; } catch (Exception ex) { @@ -680,6 +698,18 @@ namespace Tango.PPC.Jobs.ViewModels } } + /// <summary> + /// Sets the segment liquid volumes. + /// </summary> + /// <param name="segment">The segment.</param> + private void SetSegmentLiquidVolumesIfVolume(Segment segment) + { + if (Job.ColorSpace.Code == BL.Enumerations.ColorSpaces.Volume.ToInt32()) + { + segment.BrushStops.ToList().ForEach(x => x.SetLiquidVolumes(Job.Machine.Configuration, Job.Rml, Job.Rml.GetActiveProcessGroup().ProcessParametersTables.FirstOrDefault())); + } + } + #endregion #region Brush Stops Management @@ -692,6 +722,7 @@ namespace Tango.PPC.Jobs.ViewModels { LogManager.Log($"Adding new brush stop to segment {segment.SegmentIndex}."); segment.AddBrushStop(); + SetSegmentLiquidVolumesIfVolume(segment); } /// <summary> @@ -761,11 +792,36 @@ namespace Tango.PPC.Jobs.ViewModels /// <summary> /// Called when the brush stop field value has been changed (This called from the view!). /// </summary> - /// <param name="brushStop">The brush stop.</param> - public void OnBrushStopFieldValueChanged(BrushStop brushStop) + /// <param name="stop">The brush stop.</param> + [HandleProcessCorruptedStateExceptions] + public void OnBrushStopFieldValueChanged(BrushStop stop) { - brushStop.Corrected = false; - brushStop.OutOfGamutChecked = false; + if (stop != null) + { + stop.Corrected = false; + stop.OutOfGamutChecked = false; + + if (stop.BrushColorSpace == BL.Enumerations.ColorSpaces.Volume) + { + _volumeConversionTimer.ResetReplace(() => + { + try + { + var output = TangoColorConverter.GetSuggestions(stop); + + stop.Red = output.SingleCoordinates.Red; + stop.Green = output.SingleCoordinates.Green; + stop.Blue = output.SingleCoordinates.Blue; + stop.Corrected = true; + stop.IsOutOfGamut = false; + } + catch (Exception ex) + { + LogManager.Log(ex, "An error occurred while trying to get volume => RGB from conversion engine."); + } + }); + } + } } /// <summary> @@ -802,20 +858,20 @@ namespace Tango.PPC.Jobs.ViewModels /// <summary> /// Starts a sample dye. /// </summary> - private void StartSampleDye() + private async void StartSampleDye() { try { LogManager.Log("Sample dye command pressed..."); - PrintingManager.PrintSample(Job, _db); + await PrintingManager.PrintSample(Job, _db); - NavigationManager.NavigateTo<JobsModule>(nameof(JobProgressView)); + await NavigationManager.NavigateTo<JobsModule>(nameof(JobProgressView)); } catch (Exception ex) { LogManager.Log(ex, $"Error executing sample dye for job {Job.Name}."); - NotificationProvider.ShowError("An error occurred while trying to execute the sample dye."); + await NotificationProvider.ShowError("An error occurred while trying to execute the sample dye."); } } @@ -940,7 +996,7 @@ namespace Tango.PPC.Jobs.ViewModels /// <summary> /// Starts the fine tuning. /// </summary> - private void StartFineTuning() + private async void StartFineTuning() { try { @@ -948,14 +1004,14 @@ namespace Tango.PPC.Jobs.ViewModels _jobs_fine_tune_items[Job.Guid] = FineTuneItems.ToList(); - PrintingManager.PrintFineTuning(Job, _db, FineTuneItems); + await PrintingManager.PrintFineTuning(Job, _db, FineTuneItems); - NavigationManager.NavigateTo<JobsModule>(nameof(JobProgressView)); + await NavigationManager.NavigateTo<JobsModule>(nameof(JobProgressView)); } catch (Exception ex) { LogManager.Log(ex, "Error executing fine tuning job."); - NotificationProvider.ShowError("An error occurred while trying to start the fine tuning job."); + await NotificationProvider.ShowError("An error occurred while trying to start the fine tuning job."); } } |
