aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/PPC/Modules/Tango.PPC.JobsV2/Models/LiquidVolumesCollection.cs
blob: 704fc36b0e7208ba86178791a291ebb6c1fe2ac6 (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
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Tango.BL.Entities;
using Tango.BL.Enumerations;

namespace Tango.PPC.Jobs.Models
{
    public class LiquidVolumesCollection : ObservableCollection<LiquidVolumeModel>
    {

        public void RaiseMaxVolume()
        {
            this.ToList().ForEach(x => x.RaiseMaxVolume());
        }

        public void RaiseVolume()
        {
            this.ToList().ForEach(x => x.RaiseVolume());
        }

        public void ResetVolume()
        {
            this.ToList().ForEach(x => x.Volume = 0);
        }

        public void ResetVolumeSilent()
        {
            this.ToList().ForEach(x => x.SetVolumeSilent(0));
        }

        public LiquidVolumeModel GetLiquidVolume(LiquidTypes type)
        {
            return this.FirstOrDefault(x => x.IdsPack.LiquidType.Type == type);
        }

        public LiquidVolumeModel GetLiquidVolume(PMR.ColorLab.LiquidType type)
        {
            return this.FirstOrDefault(x => x.IdsPack.LiquidType.Type == (LiquidTypes)type);
        }

        public void Undo()
        {
            this.ToList().ForEach(x => x.Undo());
        }

        public void SaveState()
        {
            this.ToList().ForEach(x => x.SaveState());
        }

        public double GetMaxNanoliterPerCM()
        {
            return this.Sum(x => x.GetColorNLPerCm());
        }

        public void SetVolumesFromBrushStop(BrushStop stop)
        {
            foreach (var model in this)
            {
                model.Volume = 0;
                try
                {
                    var stopVolume = stop.GetVolume(model.IdsPack.PackIndex);
                    model.Volume = stopVolume;
                }
                catch
                {
                    Debug.WriteLine($"No volume found for {model.IdsPack.LiquidType.Name} at index {model.IdsPack.PackIndex}");
                }
            }
        }

        public void SetVolumesFromBrushStopSilent(BrushStop stop)
        {
            foreach (var model in this)
            {
                model.SetVolumeSilent(0);
                try
                {
                    var stopVolume = stop.GetVolume(model.IdsPack.PackIndex);
                    model.SetVolumeSilent(stopVolume);
                }
                catch
                {
                    Debug.WriteLine($"No volume found for {model.IdsPack.LiquidType.Name} at index {model.IdsPack.PackIndex}");
                }
            }
        }

        public void SetVolumesFromBrushStop(BrushStopModel brushStop)
        {
            foreach (var model in this)
            {
                model.Volume = 0;
                var b = brushStop.LiquidVolumes.GetLiquidVolume(model.IdsPack.LiquidType.Type);
                if (b != null)
                {
                    model.Volume = b.Volume;
                }
            }
        }

        public void SetVolumesOnBrushStop(BrushStop brushStop)
        {
            foreach (var model in this)
            {
                try
                {
                    brushStop.SetVolume(model.IdsPack.PackIndex, model.Volume);
                }
                catch
                {
                    Debug.WriteLine($"Could not set brush stop volume for {model.IdsPack.LiquidType.Name} at index {model.IdsPack.PackIndex}");
                }
            }
        }
    }
}