aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Tango.AnimatedGif/Decoding/GifGraphicControlExtension.cs
blob: a3782c01117729502afba10299016283a3b027c8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
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<LiquidVolumeModel> 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;
            }
        }
    }
}