aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/PPC/Modules/Tango.PPC.JobsV2/Models/LiquidVolumeModel.cs
blob: d36a8f297a0cf254ec0a08f6e8ba1fd7edebad88 (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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
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;
            }
        }
    }
}