diff options
Diffstat (limited to 'Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels')
| -rw-r--r-- | Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MachineStatusViewVM.cs | 203 |
1 files changed, 174 insertions, 29 deletions
diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MachineStatusViewVM.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MachineStatusViewVM.cs index 07c5f77ed..2faee12ac 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MachineStatusViewVM.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MachineStatusViewVM.cs @@ -32,6 +32,7 @@ using Tango.Core.ExtensionMethods; using Tango.PPC.Common.Printing; using Tango.PPC.Common.RemoteJob; using Tango.PPC.UI.Dialogs; +using Tango.ColorConversion; namespace Tango.PPC.UI.ViewModels { @@ -76,6 +77,9 @@ namespace Tango.PPC.UI.ViewModels private DispatcherTimer _productiondata_timer; private bool startingJob = false; private bool _jerricanDialogShowing; + private List<ColorSpace> _colorSpaces; + private bool _conversion_Busy; + private bool _printingEnded; #region Properties @@ -180,14 +184,28 @@ namespace Tango.PPC.UI.ViewModels if (_currentBrushStop != value) { _currentBrushStop = value; - - OnUpdateCurrentBrush(); } } } - public JobBrushStop JobBrushStop { get; set; } + private JobBrushStop _jobBrushStop; + public JobBrushStop JobBrushStop + { + get { return _jobBrushStop; } + set + { + if (_jobBrushStop != value) + { + _jobBrushStop = value; + if (_jobBrushStop != null) + { + UpdateOutputLiquids(); + } + } + } + } + //public double TransparentInkOutput //{ @@ -392,7 +410,7 @@ namespace Tango.PPC.UI.ViewModels AbortCommand = new RelayCommand(AbortJob, () => CanStopped()); ResumeCommand = new RelayCommand(ResumeJob, () => MachineProvider.MachineOperator.CanPrint); - CaancelJobCommand = new RelayCommand(CaancelJob); + CaancelJobCommand = new RelayCommand(CancelJob); RestartJobCommand = new RelayCommand(RestartJob, () => MachineProvider.MachineOperator.CanPrint); ClearJobCommand = new RelayCommand(ClearJob); @@ -585,7 +603,7 @@ namespace Tango.PPC.UI.ViewModels #region printing - public override void OnApplicationStarted() + public override async void OnApplicationStarted() { MachineProvider.MachineOperator.PrintingStarted += MachineOperator_PrintingStarted; MachineProvider.MachineOperator.PrintingEnded += MachineOperator_PrintingEnded; @@ -595,6 +613,18 @@ namespace Tango.PPC.UI.ViewModels JobResumeManager.JobResumeUpdated += JobResumeManager_JobResumeUpdated; JobResumeManager.JobResumeDropped += JobResumeManager_JobResumeDropped; + + try + { + using (var db = ObservablesContext.CreateDefault()) + { + _colorSpaces = await db.ColorSpaces.ToListAsync(); + } + } + catch (Exception ex) + { + LogManager.Log(ex); + } } @@ -605,8 +635,11 @@ namespace Tango.PPC.UI.ViewModels private void MachineOperator_PrintingStarted(object sender, PrintingEventArgs e) { + _printingEnded = false; _handler = e.JobHandler; Job = e.Job; + CurrentBrushStop = null; + JobBrushStop = null; List<LiquidOutputModel> outputs = new List<LiquidOutputModel>(); @@ -647,8 +680,6 @@ namespace Tango.PPC.UI.ViewModels StopCommand.RaiseCanExecuteChanged(); AbortCommand.RaiseCanExecuteChanged(); }); - - } private void JobHandler_Stopped(object sender, EventArgs e) @@ -665,6 +696,14 @@ namespace Tango.PPC.UI.ViewModels private void MachineOperator_PrintingEnded(object sender, PrintingEventArgs e) { + _printingEnded = true; + + try + { + CurrentBrushStop = RunningJobStatus.CurrentSegment.BrushStops.OrderBy(x => x.StopIndex).Last(); + } + catch { } + LogManager.Log("Printing ended"); InvokeUI(() => { @@ -674,7 +713,7 @@ namespace Tango.PPC.UI.ViewModels }); } - private void JobHandler_StatusChanged(object sender, RunningJobStatus e) + private async void JobHandler_StatusChanged(object sender, RunningJobStatus e) { RunningJobStatus = e; if (RunningJobStatus != null && RunningJobStatus.IsFailed) @@ -689,41 +728,142 @@ namespace Tango.PPC.UI.ViewModels IsDyeingProcess = (RunningJobStatus != null && RunningJobStatus.CurrentSegment != null); if (RunningJobStatus != null && RunningJobStatus.CurrentSegment != null) { - if (_runningJobStatus.CurrentSegment.IsInterSegment) - { - CurrentBrushStop = _runningJobStatus.CurrentSegment.BrushStops.FirstOrDefault(); - JobBrushStop = null; - } - else + try { - var realsegmIndex = 1; - if (Job.EnableInterSegment && Job.InterSegmentLength > 0) + if (_runningJobStatus.CurrentSegment.IsInterSegment) + { + var stop = _runningJobStatus.CurrentSegment.BrushStops.FirstOrDefault(); + stop.ColorSpace = CurrentBrushStop.ColorSpace; + CurrentBrushStop = stop; + JobBrushStop = null; + } + else { - int segmentIndex = _runningJobStatus.CurrentSegment.SegmentIndex - (Job.EffectiveSegments.Count * RunningJobStatus.CurrentUnit); - if (RunningJobStatus.CurrentUnit > 0) + var realsegmIndex = 1; + if (Job.EnableInterSegment && Job.InterSegmentLength > 0) + { + int segmentIndex = _runningJobStatus.CurrentSegment.SegmentIndex - (Job.EffectiveSegments.Count * RunningJobStatus.CurrentUnit); + if (RunningJobStatus.CurrentUnit > 0) + { + segmentIndex -= RunningJobStatus.CurrentUnit;// inter segment between units + } + realsegmIndex = (int)(segmentIndex / 2) + 1; + } + else { - segmentIndex -= RunningJobStatus.CurrentUnit;// inter segment between units + realsegmIndex = Math.Max(_runningJobStatus.CurrentSegment.SegmentIndex - (Job.Segments.Count * RunningJobStatus.CurrentUnit), 0); + } + + var segment = Job.Segments.FirstOrDefault(x => x.SegmentIndex == realsegmIndex); + JobSegment jobSegment = null; + + if (segment != null) + { + if (_handler.JobTicket.Segments.Count > 0) + { + jobSegment = _handler.JobTicket.Segments[Job.OrderedSegments.IndexOf(segment)]; + if (jobSegment.BrushStops.Count == 1) + { + JobBrushStop = jobSegment.BrushStops.First(); + } + else if (jobSegment.BrushStops.Count > 1) + { + JobBrushStop = jobSegment.BrushStops.Last(x => x.OffsetMeters <= e.CurrentSegment.Progress); + } + else + { + JobBrushStop = null; + } + } + } + + + if (segment != null && jobSegment != null && jobSegment.BrushStops.Count > 1) + { + if (!_conversion_Busy) + { + var brushStop = RunningJobStatus.CurrentSegment.FirstBrushStop; + await ApplyJobBrushStopToBrushStop(JobBrushStop, brushStop); + + if (!_printingEnded) + { + _currentBrushStop = brushStop; + RaisePropertyChanged(nameof(CurrentBrushStop)); + } + } + } + else + { + CurrentBrushStop = RunningJobStatus.CurrentSegment.FirstBrushStop; } - realsegmIndex = (int)(segmentIndex / 2) + 1; } - else + } + catch (Exception ex) + { + LogManager.Log(ex, "Error displaying job progress input output."); + } + } + } + + private async Task ApplyJobBrushStopToBrushStop(JobBrushStop stop, BrushStop s) + { + _conversion_Busy = true; + + try + { + foreach (var dispenser in stop.Dispensers) + { + s.SetVolume(dispenser.Index, dispenser.Volume); + } + + s.SetLiquidVolumes(MachineProvider.Machine.Configuration, Job.Rml, MachineProvider.MachineOperator.CurrentProcessParameters); + + foreach (var liquidVolume in s.LiquidVolumes.Where(x => x.IdsPack.LiquidType.IsLightInk && x.Volume > 0).ToList()) + { + var darkInk = s.LiquidVolumes.FirstOrDefault(x => x.IdsPack.LiquidType.Code == liquidVolume.IdsPack.LiquidType.DarkInkCode); + if (darkInk != null) { - realsegmIndex = Math.Max(_runningJobStatus.CurrentSegment.SegmentIndex - (Job.Segments.Count * RunningJobStatus.CurrentUnit), 0); + darkInk.Volume = liquidVolume.Volume / 10d; + liquidVolume.Volume = 0; } + } - var segment = Job.Segments.FirstOrDefault(x => x.SegmentIndex == realsegmIndex); - if (segment != null) + if (_colorSpaces != null) + { + if ((s.BrushColorSpace == ColorSpaces.RGB || s.BrushColorSpace == ColorSpaces.LAB) && (!s.IsLast && !s.IsFirst)) { - if (_handler.JobTicket.Segments.Count > 0) + var converter = new DefaultColorConverter(); + + var previousSpace = s.ColorSpace; + s.SetColorSpaceSilent(_colorSpaces.First(x => x.Space == ColorSpaces.Volume)); + + try { - JobBrushStop = _handler.JobTicket.Segments[Job.OrderedSegments.IndexOf(segment)].BrushStops.First(); + var output = await converter.ConvertAsync(s, false, false); + s.SetColorSpaceSilent(previousSpace); + if (!_printingEnded) + { + output.ApplyOnBrushStop(s, MachineProvider.MachineOperator.CurrentProcessParameters); + } + } + catch (Exception ex) + { + s.SetColorSpaceSilent(previousSpace); + throw ex; } } - CurrentBrushStop = RunningJobStatus.CurrentSegment.FirstBrushStop; } + + _conversion_Busy = false; + } + catch (Exception ex) + { + _conversion_Busy = false; + throw ex; } } + private void JobHandler_CanCancelChanged(object sender, EventArgs e) { InvokeUI(() => @@ -874,7 +1014,7 @@ namespace Tango.PPC.UI.ViewModels } } - private void CaancelJob() + private void CancelJob() { ClearJob(); } @@ -908,10 +1048,15 @@ namespace Tango.PPC.UI.ViewModels protected void OnUpdateCurrentBrush() { - CurrentBrushStop.SetLiquidVolumes(MachineProvider.Machine.Configuration, Job.Rml, MachineProvider.MachineOperator.CurrentProcessParameters); + CurrentBrushStop?.SetLiquidVolumes(MachineProvider.Machine.Configuration, Job.Rml, MachineProvider.MachineOperator.CurrentProcessParameters); RaisePropertyChanged(nameof(CurrentBrushStop)); + UpdateOutputLiquids(); + } + + private void UpdateOutputLiquids() + { foreach (var output in LiquidOutputs) { output.Volume = GetVolumeLiquidType(output.LiquidType.Type); |
