From c435be14ccb975b5666da84a7324ec55c3575842 Mon Sep 17 00:00:00 2001 From: Roy Date: Wed, 7 Mar 2018 09:03:11 +0200 Subject: Add auto generation for ColorLab color space & liquid type. Started implementing native color query in colorlab module. --- .../ViewModels/CalibrationDataVM.cs | 9 ++ .../ViewModels/LiquidVolumeVM.cs | 9 ++ .../ViewModels/MainViewVM.cs | 162 +++++++++++++++++++-- .../Views/MainView.xaml | 4 +- .../Controls/HiveComboControl.xaml.cs | 3 +- 5 files changed, 173 insertions(+), 14 deletions(-) (limited to 'Software/Visual_Studio/MachineStudio') diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorLab/ViewModels/CalibrationDataVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorLab/ViewModels/CalibrationDataVM.cs index 1bcb29835..87bbacab5 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorLab/ViewModels/CalibrationDataVM.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorLab/ViewModels/CalibrationDataVM.cs @@ -4,6 +4,7 @@ using System.Collections.ObjectModel; using System.Linq; using System.Text; using System.Threading.Tasks; +using Tango.BL.Entities; using Tango.SharedUI; namespace Tango.MachineStudio.ColorLab.ViewModels @@ -26,6 +27,14 @@ namespace Tango.MachineStudio.ColorLab.ViewModels set { _color = value; RaisePropertyChangedAuto(); } } + private IdsPack _idsPack; + + public IdsPack IdsPack + { + get { return _idsPack; } + set { _idsPack = value; RaisePropertyChangedAuto(); } + } + private ObservableCollection _calibrationPoints; public ObservableCollection CalibrationPoints diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorLab/ViewModels/LiquidVolumeVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorLab/ViewModels/LiquidVolumeVM.cs index a804d628b..a9d46f142 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorLab/ViewModels/LiquidVolumeVM.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorLab/ViewModels/LiquidVolumeVM.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using Tango.BL.Entities; using Tango.SharedUI; namespace Tango.MachineStudio.ColorLab.ViewModels @@ -32,5 +33,13 @@ namespace Tango.MachineStudio.ColorLab.ViewModels get { return _color; } set { _color = value; RaisePropertyChangedAuto(); } } + + private IdsPack _idsPack; + + public IdsPack IdsPack + { + get { return _idsPack; } + set { _idsPack = value; RaisePropertyChangedAuto(); } + } } } diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorLab/ViewModels/MainViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorLab/ViewModels/MainViewVM.cs index c6cc95930..70419c1a9 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorLab/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorLab/ViewModels/MainViewVM.cs @@ -1,14 +1,21 @@ -using System; +using Google.Protobuf; +using Microsoft.Win32; +using System; using System.Collections.Generic; using System.Collections.ObjectModel; +using System.IO; using System.Linq; using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; using System.Text; using System.Threading.Tasks; using System.Windows.Media; using Tango.BL; using Tango.BL.Entities; +using Tango.Core.Commands; using Tango.MachineStudio.Common.Controls; +using Tango.PMR; +using Tango.PMR.ColorLab; using Tango.SharedUI; using Tango.SharedUI.Controls; @@ -16,6 +23,9 @@ namespace Tango.MachineStudio.ColorLab.ViewModels { public class MainViewVM : ViewModel { + [DllImport("Tango.ColorLib.dll", CallingConvention = CallingConvention.Cdecl, EntryPoint = "Convert")] + public static extern int GetColorAdjust(IntPtr data, int size, ref IntPtr output); + private ObservablesContext _dbContext; private HiveComboControl _hiveCombo; @@ -31,11 +41,11 @@ namespace Tango.MachineStudio.ColorLab.ViewModels set { _machines = value; RaisePropertyChangedAuto(); } } - private ObservableCollection _colorSpaces; + private ObservableCollection _colorSpaces; /// /// Gets or sets the color spaces. /// - public ObservableCollection ColorSpaces + public ObservableCollection ColorSpaces { get { return _colorSpaces; } set { _colorSpaces = value; RaisePropertyChangedAuto(); } @@ -75,7 +85,7 @@ namespace Tango.MachineStudio.ColorLab.ViewModels set { _selectedRML = value; - InvalidateLiquidFactorsAndProcessTables(); + InvalidateLiquidFactorsCalibrationData(); RaisePropertyChangedAuto(); } } @@ -130,23 +140,68 @@ namespace Tango.MachineStudio.ColorLab.ViewModels set { _selectedHexagon = value; RaisePropertyChangedAuto(); } } + private Cct _cct; + /// + /// Gets or sets the CCT. + /// + public Cct CCT + { + get { return _cct; } + set { _cct = value; RaisePropertyChangedAuto(); } + } + + private int _deltaChroma; + /// + /// Gets or sets the delta chroma. + /// + public int DeltaChroma + { + get { return _deltaChroma; } + set { _deltaChroma = value; RaisePropertyChangedAuto(); } + } + + private int _deltaL; + /// + /// Gets or sets the delta l. + /// + public int DeltaL + { + get { return _deltaL; } + set { _deltaL = value; RaisePropertyChangedAuto(); } + } + + + #endregion + + #region Commands + + public RelayCommand ImportForwardDataCommand { get; set; } + + public RelayCommand ImportInverseDataCommand { get; set; } + #endregion public MainViewVM() : base() { _dbContext = ObservablesContext.CreateDefault(); + CCT = new Cct(); + SourceColor = new RgbVM(); SourceColor.ColorChanged += SourceColor_ColorChanged; Machines = _dbContext.Machines.ToObservableCollection(); ColorSpaces = _dbContext.ColorSpaces.ToObservableCollection(); Rmls = _dbContext.Rmls.ToObservableCollection(); + + ImportForwardDataCommand = new RelayCommand(ImportForwardData, () => SelectedRML != null); + ImportInverseDataCommand = new RelayCommand(ImportInverseData, () => SelectedRML != null); } private void SourceColor_ColorChanged(object sender, Color color) { if (_hiveCombo != null) { + GetHiveSuggestions(); _hiveCombo.GenerateDemoModeHiveColors(color); _hiveCombo.SelectHeagon(_hiveCombo.CenterHexagon); } @@ -157,13 +212,92 @@ namespace Tango.MachineStudio.ColorLab.ViewModels _hiveCombo = hiveCombo; } + #region ColorLab + + private void GetHiveSuggestions() + { + ConversionInput input = new ConversionInput(); + input.ColorSpace = PMR.ColorLab.ColorSpace.Rgb; + input.DeltaChroma = DeltaChroma; + input.DeltaL = DeltaL; + input.ForwardData = ByteString.CopyFrom(CCT.ForwardData); + input.InverseData = ByteString.CopyFrom(CCT.InverseData); + input.InputCoordinates.Red = (int)SourceColor.Red; + input.InputCoordinates.Green = (int)SourceColor.Green; + input.InputCoordinates.Blue = (int)SourceColor.Blue; + + foreach (var vm in LiquidsCalibrationData) + { + InputLiquid inputLiquid = new InputLiquid(); + + CalibrationData calData = new CalibrationData(); + calData.LiquidType = (PMR.ColorLab.LiquidType)vm.IdsPack.LiquidType.Code; + calData.CalibrationPoints.AddRange(vm.CalibrationPoints.Select(x => new CalibrationPoint() { X = x.X, Y = x.Y })); + inputLiquid.CalibrationData = calData; + + inputLiquid.LiquidType = (PMR.ColorLab.LiquidType)vm.IdsPack.LiquidType.Code; + inputLiquid.MaxNanoliterPerCentimeter = LiquidTypesRmls.SingleOrDefault(x => x.LiquidType.Code == vm.IdsPack.LiquidType.Code).MaxNlPerCm; + + input.InputCoordinates.InputLiquids.Add(inputLiquid); + } + + NativePMR nativePMR = new NativePMR(GetColorAdjust); + ConversionOutput output = nativePMR.Invoke(input); + + //Fill Hive ! + } + + #endregion + + #region Import / Export Color Adjustment Data + + private void ImportForwardData() + { + String file = GetCCTFile(); + if (file != null) + { + CCT.ForwardFileName = Path.GetFileName(file); + CCT.ForwardData = File.ReadAllBytes(file); + } + } + + private void ImportInverseData() + { + String file = GetCCTFile(); + if (file != null) + { + CCT.InverseFileName = Path.GetFileName(file); + CCT.InverseData = File.ReadAllBytes(file); + } + } + + private String GetCCTFile() + { + OpenFileDialog dlg = new OpenFileDialog(); + dlg.Title = "Select color adjustment file"; + dlg.Filter = "Color Conversion Table|*.cct"; + if (dlg.ShowDialogCenter()) + { + return dlg.FileName; + } + + return null; + } + + #endregion + #region Liquid Volumes private void OnSelectedMachineChanged() { if (SelectedMachine != null) { - LiquidVolumes = SelectedMachine.Configuration.IdsPacks.OrderBy(x => x.PackIndex).Select(x => new LiquidVolumeVM() { Color = x.LiquidType.Color, Name = x.LiquidType.Name }).ToObservableCollection(); + LiquidVolumes = SelectedMachine.Configuration.IdsPacks.OrderBy(x => x.PackIndex).Select(x => new LiquidVolumeVM() + { + Color = x.LiquidType.Color, + Name = x.LiquidType.Name, + IdsPack = x, + }).ToObservableCollection(); } } @@ -171,7 +305,7 @@ namespace Tango.MachineStudio.ColorLab.ViewModels #region RML - private void InvalidateLiquidFactorsAndProcessTables() + private void InvalidateLiquidFactorsCalibrationData() { if (SelectedRML != null && SelectedMachine != null) { @@ -180,13 +314,14 @@ namespace Tango.MachineStudio.ColorLab.ViewModels LiquidsCalibrationData = new ObservableCollection(); - foreach (var liquidType in SelectedMachine.Configuration.IdsPacks.OrderBy(x => x.PackIndex).Select(x => x.LiquidType)) + foreach (var idsPack in SelectedMachine.Configuration.IdsPacks.OrderBy(x => x.PackIndex)) { CalibrationDataVM vm = new CalibrationDataVM(); - vm.Name = liquidType.Name; - vm.Color = liquidType.Color; + vm.Name = idsPack.LiquidType.Name; + vm.Color = idsPack.LiquidType.Color; + vm.IdsPack = idsPack; - var cat = liquidType.Cats.FirstOrDefault(x => x.Machine == SelectedMachine); + var cat = idsPack.LiquidType.Cats.FirstOrDefault(x => x.Machine == SelectedMachine); if (cat != null) { @@ -196,6 +331,13 @@ namespace Tango.MachineStudio.ColorLab.ViewModels LiquidsCalibrationData.Add(vm); } + + CCT = SelectedRML.Ccts.FirstOrDefault(); + + if (CCT == null) + { + CCT = new Cct(); + } } } diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorLab/Views/MainView.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorLab/Views/MainView.xaml index 72a1bdd4e..c0f2912f3 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorLab/Views/MainView.xaml +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorLab/Views/MainView.xaml @@ -206,7 +206,7 @@ - + @@ -345,7 +345,7 @@ - +