using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Tango.BL.Dispensing; using Tango.BL.Entities; using Tango.BL.Enumerations; using Tango.Core; namespace Tango.PPC.Jobs.Models { public class LiquidVolumeModel : ExtendedObject { public event EventHandler VolumeChanged; public BrushStopModel BrushStopModel { get; set; } private double _volume; public double Volume { get { return _volume; } set { if (_volume != value) { _volume = value; RaisePropertyChangedAuto(); VolumeChanged?.Invoke(this, this); } } } public void SetVolumeSilent(double volume) { _volume = volume; } private IdsPack _idsPack; public IdsPack IdsPack { get { return _idsPack; } set { _idsPack = value; RaisePropertyChangedAuto(); } } public double MaxVolume { get { return GetMaxCMYKValueOrDefault(); } } public double VolumeBeforeChange { get; set; } public void RaiseMaxVolume() { RaisePropertyChanged(nameof(MaxVolume)); } public void SaveState() { VolumeBeforeChange = Volume; } public void RaiseVolume() { RaisePropertyChanged(nameof(Volume)); } public LiquidVolumeModel(BrushStopModel brushStopModel, IdsPack idsPack) { BrushStopModel = brushStopModel; IdsPack = idsPack; } public void Undo() { Volume = VolumeBeforeChange; VolumeBeforeChange = Volume; } private double GetMaxCMYKValueOrDefault() { if (BrushStopModel != null && BrushStopModel.SegmentModel != null && BrushStopModel.SegmentModel.Job != null && BrushStopModel.SegmentModel.Job.Rml != null && BrushStopModel.SegmentModel.Job.Rml.ProcessParametersTablesGroups.Count > 0) { var liquidTypesRml = BrushStopModel.SegmentModel.Job.Rml.LiquidTypesRmls.FirstOrDefault(x => x.LiquidType.Type == IdsPack.LiquidType.Type); var processParametersTable = BrushStopModel.SegmentModel.Job.Rml.ProcessParametersTablesGroups.Single().ProcessParametersTables.OrderBy(y => y.TableIndex).LastOrDefault(); if (liquidTypesRml != null && processParametersTable != null && liquidTypesRml.MaxNlPerCm != 0) { return (processParametersTable.MaxInkUptake / (liquidTypesRml.MaxNlPerCm) * 100); } } return 100; } public double GetColorNLPerCm() { StandardColorDispensingCalc calc = new StandardColorDispensingCalc(); Rml rml = BrushStopModel.SegmentModel.Job.Rml; LiquidTypesRml liquidType = rml.LiquidTypesRmls.FirstOrDefault(x => x.LiquidType.Type == IdsPack.LiquidType.Type); if (liquidType != null) { double maxNlPerCm = liquidType.MaxNlPerCm; return calc.CalculateNanoliterPerCentimeter(Volume, maxNlPerCm); } return 0.0; } public double GetMinLimit() { try { var tables = BrushStopModel.SegmentModel.Job.Rml.GetActiveProcessGroup().ProcessParametersTables.OrderBy(x => x.TableIndex).ToList(); LiquidTypesRml liquidType = BrushStopModel.SegmentModel.Job.Rml.LiquidTypesRmls.FirstOrDefault(x => x.LiquidType.Type == IdsPack.LiquidType.Type); if (tables.Count > 0 && liquidType != null && liquidType.MaxNlPerCm != 0) { var vmax = Math.Max(BrushStopModel.SegmentModel.Job.Rml.VMax / 10d, 0); if (IdsPack.LiquidType.Type == LiquidTypes.Black) { vmax = Math.Max(BrushStopModel.SegmentModel.Job.Rml.VMax, 0); } return (vmax * tables[0].MinInkUptake) / liquidType.MaxNlPerCm; } else { return 0; } } catch { return 0; } } } }