aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ThreadExtensions/Models/CalibrationPlotModel.cs
blob: 0f844097d314d4db160af1785cb200b5043daf30 (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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
using OxyPlot;
using OxyPlot.Wpf;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using Tango.BL.Entities;
using Tango.BL.Enumerations;
using Tango.Core;

namespace Tango.MachineStudio.ThreadExtensions.Models
{
   
    public class CalibrationPlotModel : ExtendedObject
    {
        #region Properties

        public Plot DataPlotControl { get; set; }
        public Plot LinearizationPlotControl { get; set; }

        private string _title;

        public string Title
        {
            get { return _title; }
            set { _title = value; RaisePropertyChangedAuto(); }
        }
        
        private FactorColors _color;
        
        private IList<DataPoint> _LPoints;

        public IList<DataPoint> LPoints
        {
            get { return _LPoints; }
            set { _LPoints = value; }
        }

        private IList<DataPoint> _APoints;

        public IList<DataPoint> APoints
        {
            get { return _APoints; }
            set { _APoints = value; }
        }

        private IList<DataPoint> _BPoints;

        public IList<DataPoint> BPoints
        {
            get { return _BPoints; }
            set { _BPoints = value; }
        }

        private IList<DataPoint> _points;
        /// <summary>
        /// Binding to ItemsSource  of line chart.
        /// </summary>
        public IList<DataPoint> LinearizationPoints
        {
            get { return _points; }
            set
            {
                _points = value;
                RaisePropertyChangedAuto();
            }
        }
        
        private int _step;
        public int XStep
        {
            get { return _step; }
            set { _step = value; RaisePropertyChangedAuto(); }
        }

        private double _minY;
        /// <summary>
        /// From use to binding to left axis min value
        /// </summary>
        public double MinY
        {
            get { return _minY; }
            set
            {
                _minY = value; RaisePropertyChangedAuto();
            }
        }

        private double _maxY;
        /// <summary>
        /// To use to binding to left axis max value
        /// </summary>
        public double MaxY
        {
            get { return _maxY; }
            set
            {
                _maxY = value; RaisePropertyChangedAuto();
            }
        }
        private int _maxX;
        /// <summary>
        /// Gets or sets the maximum lab plot X values for LinearizationGraph left part
        /// </summary>
        public int MaxX
        {
            get { return _maxX; }
            set
            {
                _maxX = value;
                RaisePropertyChangedAuto();
            }
        }

        private double _linearizationMaxX;

        public double LinearizationMaxX
        {
            get { return _linearizationMaxX; }
            set
            {
                _linearizationMaxX = value;
                RaisePropertyChangedAuto();
            }
        }

        private double _linearizationMaxY;

        public double LinearizationMaxY
        {
            get { return _linearizationMaxY; }
            set
            {
                _linearizationMaxY = value;
                RaisePropertyChangedAuto();
            }
        }
        #endregion

        public CalibrationPlotModel(FactorColors color, string title)
        {
            LinearizationPoints = new List<DataPoint>();
            LPoints = new List<DataPoint>();
            APoints = new List<DataPoint>();
            BPoints = new List<DataPoint>();
            _color = color;
            _title = title;

        }
        public void ClearResults()
        {
            LPoints.Clear();
            APoints.Clear();
            BPoints.Clear();
            LinearizationPoints.Clear();
        }

        public void InitDataGraph(List<ColorLinearizationModel.LinearizationDataItem> items)
        {
            if (items == null || items.Count == 0)
                return;

            ClearResults();
            if (DataPlotControl != null)
                DataPlotControl.InvalidatePlot(true);
            if (LinearizationPlotControl != null)
                LinearizationPlotControl.InvalidatePlot(true);
            
            foreach (var labItem in items)
            {
                LPoints.Add(new DataPoint(labItem.InkPercentage, labItem.L));
                APoints.Add(new DataPoint(labItem.InkPercentage, labItem.A));
                BPoints.Add(new DataPoint(labItem.InkPercentage, labItem.B));
            }
            int maxValue = (int)(items.Max(x => x.InkPercentage));
            MaxX = Math.Max(100, maxValue);
            
            MinY = Math.Min(0, items.Min(x => Math.Min(x.L, Math.Min(x.A, x.B))));
            MaxY = Math.Max( 100, items.Max(x => Math.Max(x.L, Math.Max(x.A, x.B))));

            if (DataPlotControl != null)
                DataPlotControl.InvalidatePlot(true);
        }
        
        public void InitLinearizationGraph(List<ColorLinearizationModel.LinearizationDataItem> items, List<double> outputPoints)
        {
            if (outputPoints == null)
                return;

            LinearizationPoints.Clear();
            foreach (var nw in items.Zip(outputPoints, Tuple.Create))
            {
                LinearizationPoints.Add(new DataPoint(nw.Item1.InkPercentage, nw.Item2));
            }

            LinearizationMaxX = Math.Max(100, LinearizationPoints.Max(x => x.X));
            LinearizationMaxY = Math.Max(100, LinearizationPoints.Max(x => x.Y));

            if (LinearizationPlotControl != null)
            {
                LinearizationPlotControl.InvalidatePlot(true);
            }
        }
    }
}