From 487fc03281c2dfde034e73ad99bd74ec4f63f69a Mon Sep 17 00:00:00 2001 From: Victoria Plitt Date: Wed, 17 Jun 2020 14:43:46 +0300 Subject: RML color calibration. --- .../Models/CalibrationMeasurementModel.cs | 86 +++++++++ .../Tango.MachineStudio.RML.csproj | 15 ++ .../ViewModels/ColorCalibrationViewVM.cs | 199 +++++++++++++++++++++ .../ViewModels/MainViewVM.cs | 12 ++ .../Views/ColorCalibrationView.xaml | 121 +++++++++++++ .../Views/ColorCalibrationView.xaml.cs | 40 +++++ .../Tango.MachineStudio.RML/Views/RmlView.xaml | 5 +- 7 files changed, 477 insertions(+), 1 deletion(-) create mode 100644 Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Models/CalibrationMeasurementModel.cs create mode 100644 Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels/ColorCalibrationViewVM.cs create mode 100644 Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Views/ColorCalibrationView.xaml create mode 100644 Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Views/ColorCalibrationView.xaml.cs (limited to 'Software/Visual_Studio') diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Models/CalibrationMeasurementModel.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Models/CalibrationMeasurementModel.cs new file mode 100644 index 000000000..74c6bba3e --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Models/CalibrationMeasurementModel.cs @@ -0,0 +1,86 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.Core; +using Tango.BL.Enumerations; +using Tango.PMR.Printing; + +namespace Tango.MachineStudio.RML.Models +{ + public static class ColorCalibrationExt + { + public static Dictionary TargetLiquidTypeToLAB = new Dictionary + { + {LiquidTypes.Cyan, new LAB(51.94591,-18.3438,-39.0577)}, + {LiquidTypes.Magenta, new LAB(47.46248, 65.84478, 3.922838)}, + {LiquidTypes.Yellow, new LAB(84.41956,-0.27005, 94.05445)}, + {LiquidTypes.Black, new LAB(26.57986, -0.13567, 0.948574)}, + }; + public static Dictionary DisplayLiquidTypeToLABType = new Dictionary + { + {LiquidTypes.Cyan, "L"}, + {LiquidTypes.Magenta, "L"}, + {LiquidTypes.Yellow, "B"}, + {LiquidTypes.Black, "L"}, + }; + }; + + public class LAB + { + public double L { get; set; } + public double A { get; set; } + public double B { get; set; } + + public LAB( double l, double a, double b) + { + L = l; B = b; A = a; + } + }; + + public class CalibrationMeasurementModel : ExtendedObject + { + #region properties + private int _l; + + public int L + { + get { return _l; } + set { _l = value; RaisePropertyChangedAuto(); } + } + + private int _a; + + public int A + { + get { return _a; } + set { _a = value; RaisePropertyChangedAuto(); } + } + + private int _b; + + public int B + { + get { return _b; } + set { _b = value; RaisePropertyChangedAuto(); } + } + + private int _ink; + + public int Ink + { + get { return _ink; } + set { _ink = value; RaisePropertyChangedAuto(); } + } + #endregion + + public CalibrationMeasurementModel() + { + _ink = 0; + L = 0; + A = 0; + B = 0; + } + } +} diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Tango.MachineStudio.RML.csproj b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Tango.MachineStudio.RML.csproj index a413223c3..3e2dcc67c 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Tango.MachineStudio.RML.csproj +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Tango.MachineStudio.RML.csproj @@ -49,6 +49,12 @@ ..\..\..\packages\MaterialDesignThemes.2.3.1.953\lib\net45\MaterialDesignThemes.Wpf.dll + + ..\..\..\packages\OxyPlot.Core.2.0.0\lib\net45\OxyPlot.dll + + + ..\..\..\packages\OxyPlot.Wpf.2.0.0\lib\net45\OxyPlot.Wpf.dll + @@ -73,6 +79,7 @@ GlobalVersionInfo.cs + @@ -93,6 +100,7 @@ + @@ -103,6 +111,9 @@ CalibrationDataView.xaml + + ColorCalibrationView.xaml + ColorConversionView.xaml @@ -212,6 +223,10 @@ MSBuild:Compile Designer + + Designer + MSBuild:Compile + Designer MSBuild:Compile diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels/ColorCalibrationViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels/ColorCalibrationViewVM.cs new file mode 100644 index 000000000..a6a2b3f7b --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels/ColorCalibrationViewVM.cs @@ -0,0 +1,199 @@ +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.BL.Entities; +using Tango.Core; +using Tango.Core.Commands; +using Tango.MachineStudio.RML.Models; +using Tango.SharedUI; +using OxyPlot; +using OxyPlot.Wpf; +using OxyPlot.Annotations; + + +namespace Tango.MachineStudio.RML.ViewModels +{ + public class ColorCalibrationViewVM : ExtendedObject + { + + #region Properties + + private Rml _rml; + public Rml RML + { + get { return _rml; } + set { _rml = value; RaisePropertyChangedAuto(); } + } + + private LiquidType _liquidType; + + public LiquidType LiquidType + { + get { return _liquidType; } + set { _liquidType = value; RaisePropertyChangedAuto(); } + } + + private List _liquidTypes; + + public List LiquidTypes + { + get { return _liquidTypes; } + set { _liquidTypes = value; } + } + + + private ObservableCollection _measurements; + public ObservableCollection Measurements + { + get + { + return _measurements; + } + set + { + _measurements = value; RaisePropertyChangedAuto(); + } + } + + + private double _factor; + + public double Factor + { + get { return _factor; } + set { _factor = value; } + } + + public RelayCommand CreateGraphCommand { get; set; } + + + public string CalibrationType + { + get { return LiquidType == null ?"" : LiquidType.Name; } + } + + public Plot PlotControl { get; set; } + private IList _points; + /// + /// Binding to ItemsSource of line chart. + /// + public IList Points + { + get { return _points; } + set + { + _points = value; + RaisePropertyChangedAuto(); + } + } + private IList _targetPoints; + /// + /// Binding to ItemsSource of line chart. + /// + public IList TargetPoints + { + get { return _targetPoints; } + set + { + _targetPoints = value; + RaisePropertyChangedAuto(); + } + } + private int _step; + public int XStep + { + get { return _step; } + set { _step = value; RaisePropertyChangedAuto(); } + } + + private double _from; + /// + /// From use to binding to bottom axis min value + /// + public double From + { + get { return _from; } + set + { + _from = value; RaisePropertyChangedAuto(); + } + } + + private double _to; + /// + /// To use to binding to bottom axis max value + /// + public double To + { + get { return _to; } + set + { + _to = value; RaisePropertyChangedAuto(); + } + } + + #endregion + + public ColorCalibrationViewVM() + { + Measurements = new ObservableCollection() + { + new CalibrationMeasurementModel(), + new CalibrationMeasurementModel(), + new CalibrationMeasurementModel(), + }; + Factor = 0; + CreateGraphCommand = new RelayCommand(CreateGraph); + this.Points = new List(); + TargetPoints = new List(); + } + + public void Loading() + { + LiquidType = LiquidTypes.Count > 0 ? LiquidTypes[0] : null; + } + + private void CreateGraph(object obj) + { + if (_liquidType == null) + return; + + LAB lab; + string color = ColorCalibrationExt.DisplayLiquidTypeToLABType[_liquidType.Type]; + if( ColorCalibrationExt.TargetLiquidTypeToLAB.TryGetValue(_liquidType.Type, out lab)) + { + var value = lab.GetType().GetProperty(color)?.GetValue(lab, null); + Factor = (double)value; + } + + + + //call color calibration function + //////////////////////// + /// + + + Points.Clear(); + TargetPoints.Clear(); + + To = 0; + From = 0; + + Measurements.ToList().ForEach(x =>{ + Points.Add(new DataPoint(x.Ink, x.L)); + TargetPoints.Add(new DataPoint(x.Ink,Factor)); }); + + _to = color == "L"? 100 : 128; + _from = color == "L" ? 0 : -127; + + RaisePropertyChanged("To"); + RaisePropertyChanged("From"); + XStep = (int)(Points.Count / 6); + RaisePropertyChanged("CalibrationType"); + PlotControl.InvalidatePlot(true); + } + } +} diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels/MainViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels/MainViewVM.cs index 1ceaf07df..4939cbb48 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels/MainViewVM.cs @@ -164,6 +164,12 @@ namespace Tango.MachineStudio.RML.ViewModels set { _selectedSpool = value; RaisePropertyChangedAuto(); InvalidateRelayCommands(); } } + private ColorCalibrationViewVM _colorCalibrationVM; + public ColorCalibrationViewVM ColorCalibrationVM + { + get { return _colorCalibrationVM; } + set { _colorCalibrationVM = value; RaisePropertyChangedAuto(); } + } /// /// Gets or sets the manage RML command. @@ -374,6 +380,12 @@ namespace Tango.MachineStudio.RML.ViewModels LiquidTypesRmls = LiquidTypesRmls, }; + ColorCalibrationVM = new ColorCalibrationViewVM() + { + RML = ActiveRML, + LiquidTypes = LiquidTypesRmls.Where(x => x.LiquidType.HasPigment).ToList().Select(y => y.LiquidType).ToList(), + }; + _rmlBeforeSave = RmlDTO.FromObservable(ActiveRML); View.NavigateTo(RmlNavigationView.RmlView); diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Views/ColorCalibrationView.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Views/ColorCalibrationView.xaml new file mode 100644 index 000000000..815e7a5f9 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Views/ColorCalibrationView.xaml @@ -0,0 +1,121 @@ + + + + + + + + + + + + + + + Color Calibrations + + + + + + + + + + + + + + + + + + Liquid Type + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Views/ColorCalibrationView.xaml.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Views/ColorCalibrationView.xaml.cs new file mode 100644 index 000000000..4c456c12d --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Views/ColorCalibrationView.xaml.cs @@ -0,0 +1,40 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; +using Tango.MachineStudio.RML.ViewModels; + +namespace Tango.MachineStudio.RML.Views +{ + /// + /// Interaction logic for ColorCalibrationView.xaml + /// + public partial class ColorCalibrationView : UserControl + { + public ColorCalibrationView() + { + InitializeComponent(); + this.Loaded += ColorCalibrationView_Loaded; + } + + private void ColorCalibrationView_Loaded(object sender, RoutedEventArgs e) + { + if(DataContext is ColorCalibrationViewVM) + { + ColorCalibrationViewVM vm = (ColorCalibrationViewVM)DataContext; + vm.PlotControl = CalibrationPlot; + vm.Loading(); + } + } + } +} diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Views/RmlView.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Views/RmlView.xaml index cd3ed2fe4..7d050a29a 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Views/RmlView.xaml +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Views/RmlView.xaml @@ -30,7 +30,7 @@ - +