diff options
Diffstat (limited to 'Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ThreadExtensions/Models/CalibrationPlotModel.cs')
| -rw-r--r-- | Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ThreadExtensions/Models/CalibrationPlotModel.cs | 205 |
1 files changed, 205 insertions, 0 deletions
diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ThreadExtensions/Models/CalibrationPlotModel.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ThreadExtensions/Models/CalibrationPlotModel.cs new file mode 100644 index 000000000..d6a7212c0 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ThreadExtensions/Models/CalibrationPlotModel.cs @@ -0,0 +1,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 (DataPlotControl == null) + { + Debug.WriteLine("ERROR!!! CreateGraph. Plot Control is NULL."); + return; + } + + if (items == null || items.Count == 0) + return; + + ClearResults(); + DataPlotControl.InvalidatePlot(true); + 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)))); + + DataPlotControl.InvalidatePlot(true); + } + + public void InitLinearizationGraph(List<ColorLinearizationModel.LinearizationDataItem> items, List<double> outputPoints) + { + + if (outputPoints == null) + return; + + 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)); + + LinearizationPlotControl.InvalidatePlot(true); + } + } +} |
