From b34d8641f72e7b92958ea17d10ff15c29d37c464 Mon Sep 17 00:00:00 2001 From: Victoria Plitt Date: Mon, 16 Sep 2019 11:40:14 +0300 Subject: Dropping Machine Studio ColorLab Module. Move to RML module. Related Work Items: #1168 --- .../Images/arrow-long-down.png | Bin 0 -> 2865 bytes .../Images/arrow-long-left.png | Bin 0 -> 2413 bytes .../Images/arrow-long-right.png | Bin 0 -> 2169 bytes .../Tango.MachineStudio.RML.csproj | 54 +- .../ViewModels/CalibrationDataPointVM.cs | 64 ++ .../ViewModels/CalibrationDataVM.cs | 83 +++ .../ViewModels/CalibrationDataViewVM.cs | 110 +++ .../ViewModels/ColorConversionViewVM.cs | 396 +++++++++++ .../ViewModels/LiquidVolumeVM.cs | 51 ++ .../ViewModels/MainViewVM.cs | 41 +- .../Tango.MachineStudio.RML/ViewModels/RgbVM.cs | 148 ++++ .../Views/CalibrationDataView.xaml | 72 ++ .../Views/CalibrationDataView.xaml.cs | 28 + .../Views/ColorConversionView.xaml | 772 +++++++++++++++++++++ .../Views/ColorConversionView.xaml.cs | 28 + .../Views/ProcessParametersView.xaml | 155 +++++ .../Views/ProcessParametersView.xaml.cs | 59 ++ .../Tango.MachineStudio.RML/Views/RmlView.xaml | 272 ++------ .../Tango.MachineStudio.RML/Views/RmlView.xaml.cs | 22 +- 19 files changed, 2134 insertions(+), 221 deletions(-) create mode 100644 Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Images/arrow-long-down.png create mode 100644 Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Images/arrow-long-left.png create mode 100644 Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Images/arrow-long-right.png create mode 100644 Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels/CalibrationDataPointVM.cs create mode 100644 Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels/CalibrationDataVM.cs create mode 100644 Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels/CalibrationDataViewVM.cs create mode 100644 Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels/ColorConversionViewVM.cs create mode 100644 Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels/LiquidVolumeVM.cs create mode 100644 Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels/RgbVM.cs create mode 100644 Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Views/CalibrationDataView.xaml create mode 100644 Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Views/CalibrationDataView.xaml.cs create mode 100644 Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Views/ColorConversionView.xaml create mode 100644 Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Views/ColorConversionView.xaml.cs create mode 100644 Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Views/ProcessParametersView.xaml create mode 100644 Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Views/ProcessParametersView.xaml.cs (limited to 'Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML') diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Images/arrow-long-down.png b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Images/arrow-long-down.png new file mode 100644 index 000000000..e3a862399 Binary files /dev/null and b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Images/arrow-long-down.png differ diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Images/arrow-long-left.png b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Images/arrow-long-left.png new file mode 100644 index 000000000..5845204d2 Binary files /dev/null and b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Images/arrow-long-left.png differ diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Images/arrow-long-right.png b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Images/arrow-long-right.png new file mode 100644 index 000000000..6c089d44e Binary files /dev/null and b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Images/arrow-long-right.png differ 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 fc05f3c16..6741a1dff 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 @@ -90,13 +90,28 @@ + + + + + + AddLiquidFactorView.xaml + + CalibrationDataView.xaml + + + ColorConversionView.xaml + MainView.xaml + + ProcessParametersView.xaml + RmlsView.xaml @@ -115,10 +130,22 @@ + + {37e4ceab-b54b-451f-b535-04cf7da9c459} + ColorMine + {f441feee-322a-4943-b566-110e12fd3b72} Tango.BL + + {40085232-aced-4cbe-945b-90ba8153c151} + Tango.BrushPicker + + + {b4fe6485-4161-4b36-bc08-67e0b53d01b7} + Tango.ColorConversion + {a34ee0f0-649d-41c8-8489-b6f1cc6924ee} Tango.Core @@ -135,6 +162,10 @@ {b112d89a-a106-41ae-a0c1-4abc84c477f5} Tango.DragAndDrop + + {942134ac-6ea2-4500-8f22-0f739b70a05f} + Tango.Hive + {bc932dbd-7cdb-488c-99e4-f02cf441f55e} Tango.Logging @@ -155,10 +186,6 @@ {cb0b0aa2-bb24-4bca-a720-45e397684e12} Tango.MachineStudio.Common - - {4d183aca-552b-4135-ae81-7c5a8e5fc3b1} - Tango.MachineStudio.ColorLab - @@ -168,10 +195,22 @@ Designer MSBuild:Compile + + MSBuild:Compile + Designer + + + Designer + MSBuild:Compile + Designer MSBuild:Compile + + Designer + MSBuild:Compile + Designer MSBuild:Compile @@ -190,6 +229,13 @@ + + + + + + + diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels/CalibrationDataPointVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels/CalibrationDataPointVM.cs new file mode 100644 index 000000000..4ad06c7ed --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels/CalibrationDataPointVM.cs @@ -0,0 +1,64 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.Core; +using Tango.PMR.ColorLab; +using Tango.SharedUI; + +namespace Tango.MachineStudio.RML.ViewModels +{ + public class CalibrationDataPointVM : ExtendedObject + { + private double _x; + + public double X + { + get { return _x; } + set { _x = value; RaisePropertyChangedAuto(); } + } + + private double _y; + + public double Y + { + get { return _y; } + set { _y = value; RaisePropertyChangedAuto(); } + } + + private int _index; + + public int Index + { + get { return _index; } + set { _index = value; RaisePropertyChangedAuto(); } + } + + + public CalibrationDataPointVM() + { + + } + + public CalibrationDataPointVM(double x, double y) + { + X = x; + Y = y; + } + + public CalibrationDataPointVM(CalibrationPoint calibrationPoint) : this(calibrationPoint.X, calibrationPoint.Y) + { + + } + + public CalibrationPoint ToPMR() + { + return new CalibrationPoint() + { + X = X, + Y = Y, + }; + } + } +} diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels/CalibrationDataVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels/CalibrationDataVM.cs new file mode 100644 index 000000000..403494a8e --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels/CalibrationDataVM.cs @@ -0,0 +1,83 @@ +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.SharedUI; + +namespace Tango.MachineStudio.RML.ViewModels +{ + public class CalibrationDataVM : ExtendedObject + { + private LiquidType _liquidType; + + public LiquidType LiquidType + { + get { return _liquidType; } + set { _liquidType = value; RaisePropertyChangedAuto(); } + } + + private IdsPack _idsPack; + + public IdsPack IdsPack + { + get { return _idsPack; } + set { _idsPack = value; RaisePropertyChangedAuto(); } + } + + private ObservableCollection _calibrationPoints; + + public ObservableCollection CalibrationPoints + { + get { return _calibrationPoints; } + set { _calibrationPoints = value; RaisePropertyChangedAuto(); OnCalibrationPointsChanged(); } + } + + private void OnCalibrationPointsChanged() + { + if (CalibrationPoints != null) + { + CalibrationPoints.CollectionChanged -= CalibrationPoints_CollectionChanged; + CalibrationPoints.CollectionChanged += CalibrationPoints_CollectionChanged; + + SetIndices(); + } + } + + private void CalibrationPoints_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) + { + SetIndices(); + } + + private void SetIndices() + { + if (CalibrationPoints != null) + { + int index = 1; + foreach (var p in CalibrationPoints) + { + p.Index = index++; + } + } + } + + private CalibrationDataVM() + { + CalibrationPoints = new ObservableCollection(); + } + + public CalibrationDataVM(IdsPack pack) : this() + { + IdsPack = pack; + LiquidType = pack.LiquidType; + } + + public CalibrationDataVM(LiquidType liquidType) : this() + { + LiquidType = liquidType; + } + } +} diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels/CalibrationDataViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels/CalibrationDataViewVM.cs new file mode 100644 index 000000000..b34ef83bc --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels/CalibrationDataViewVM.cs @@ -0,0 +1,110 @@ +using Microsoft.Win32; +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.BL.Calibration; +using Tango.Core.Commands; +using Tango.MachineStudio.Common; +using Tango.MachineStudio.Common.Notifications; +using Tango.SharedUI; + +namespace Tango.MachineStudio.RML.ViewModels +{ + public class CalibrationDataViewVM : ViewModel + { + private INotificationProvider _notification; + + private ObservableCollection _liquidsCalibrationData; + /// + /// Gets or sets the liquids calibration data. + /// + public ObservableCollection LiquidsCalibrationData + { + get { return _liquidsCalibrationData; } + set { _liquidsCalibrationData = value; RaisePropertyChangedAuto(); } + } + + /// + /// Gets or sets the import excel command. + /// + public RelayCommand ImportExcelCommand { get; set; } + + /// + /// Gets or sets the export excel command. + /// + public RelayCommand ExportExcelCommand { get; set; } + + /// + /// Initializes a new instance of the class. + /// + public CalibrationDataViewVM(INotificationProvider notificationProvider) + { + _notification = notificationProvider; + + LiquidsCalibrationData = new ObservableCollection(); + + ImportExcelCommand = new RelayCommand(ImportExcel); + ExportExcelCommand = new RelayCommand(ExportExcel); + } + + /// + /// Initializes a new instance of the class. + /// + /// The liquids calibration data. + public CalibrationDataViewVM(INotificationProvider notificationProvider, ObservableCollection liquidsCalibrationData) : this(notificationProvider) + { + LiquidsCalibrationData = liquidsCalibrationData; + } + + private void ImportExcel(CalibrationDataVM vm) + { + OpenFileDialog dlg = new OpenFileDialog(); + + try + { + dlg.Title = $"Import excel calibration file for {vm.LiquidType.Name}"; + dlg.Filter = "Excel Files|*.xlsx"; + if (dlg.ShowDialog().Value) + { + vm.CalibrationPoints.Clear(); + var points = CalibrationHelper.ImportCalibrationDataFromExcel(dlg.FileName); + + foreach (var p in points) + { + vm.CalibrationPoints.Add(new CalibrationDataPointVM(p)); + } + } + } + catch (Exception ex) + { + LogManager.Log(ex, "Error importing excel file " + dlg.FileName); + _notification.ShowError("An error occurred while trying to import the selected excel file. Please check the file format if valid and is available to read."); + } + } + + private void ExportExcel(CalibrationDataVM vm) + { + SaveFileDialog dlg = new SaveFileDialog(); + try + { + dlg.Title = $"Export excel calibration file for {vm.LiquidType.Name}"; + dlg.Filter = "Excel Files|*.xlsx"; + dlg.DefaultExt = ".xlsx"; + dlg.FileName = $"CData_{vm.LiquidType.Name}_v{vm.LiquidType.Version}.xlsx"; + if (dlg.ShowDialog().Value) + { + var points = vm.CalibrationPoints.Select(x => x.ToPMR()).ToList(); + CalibrationHelper.ExportCalibrationDataToExcel(points, dlg.FileName); + } + } + catch (Exception ex) + { + LogManager.Log(ex, "Error exporting excel file " + dlg.FileName); + _notification.ShowError("An error occurred while trying to export the calibration data."); + } + } + } +} diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels/ColorConversionViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels/ColorConversionViewVM.cs new file mode 100644 index 000000000..2624c9b7d --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels/ColorConversionViewVM.cs @@ -0,0 +1,396 @@ +using Google.Protobuf; +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Data.Entity; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Media; +using Tango.BL; +using Tango.BL.Entities; +using Tango.BL.Enumerations; +using Tango.ColorConversion; +using Tango.MachineStudio.Common; +using Tango.MachineStudio.Common.Notifications; +using Tango.MachineStudio.RML.Models; +using Tango.PMR.ColorLab; +using Tango.SharedUI; + +namespace Tango.MachineStudio.RML.ViewModels +{ + public class ColorConversionViewVM: ViewModel + { + #region properties + + private INotificationProvider _notification; + private bool _prevent_inverse_conversion; + + private bool _isVolumesOutOfRange; + /// + /// Gets or sets a value indicating whether the liquid volumes are out of range. + /// + public bool IsVolumesOutOfRange + { + get { return _isVolumesOutOfRange; } + set + { + if (_isVolumesOutOfRange != value) + { + _isVolumesOutOfRange = value; + RaisePropertyChangedAuto(); + } + } + } + + private bool _isOutOfGamut; + /// + /// Gets or sets a value indicating whether the source color is out of gamut. + /// + public bool IsOutOfGamut + { + get { return _isOutOfGamut; } + set { _isOutOfGamut = value; RaisePropertyChangedAuto(); } + } + + private Rml _rml; + public Rml RML + { + get { return _rml; } + set { _rml = value; RaisePropertyChangedAuto(); } + } + + private List _hiveSuggestions; + /// + /// Gets or sets the hive suggestions. + /// + public List HiveSuggestions + { + get { return _hiveSuggestions; } + set { _hiveSuggestions = value; RaisePropertyChangedAuto(); } + } + + private ColorConversionSuggestion _selectedSuggestion; + /// + /// Gets or sets the selected suggestion. + /// + public ColorConversionSuggestion SelectedSuggestion + { + get { return _selectedSuggestion; } + set { _selectedSuggestion = value; RaisePropertyChangedAuto(); OnSelectedSuggestionChanged(); } + } + + private ObservableCollection _liquidTypesRmls; + /// + /// Gets or sets the liquid types RMLS. + /// + public ObservableCollection LiquidTypesRmls + { + get { return _liquidTypesRmls; } + set { _liquidTypesRmls = value; RaisePropertyChangedAuto(); OnLiquidTypesRmlsChanged(); } + } + + private void OnLiquidTypesRmlsChanged() + { + if (LiquidTypesRmls != null) + { + LiquidTypesRmls.CollectionChanged += LiquidTypesRmls_CollectionChanged; + InvalidateLiquidVolumes(); + } + } + + private void LiquidTypesRmls_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) + { + InvalidateLiquidVolumes(); + } + + private void InvalidateLiquidVolumes() + { + LiquidVolumes = LiquidTypesRmls.Where(x => x.LiquidType.HasPigment).Select(x => new LiquidVolumeVM() + { + Color = x.LiquidType.Color, + Name = x.LiquidType.Name, + LiquidType = x.LiquidType, + }).ToObservableCollection(); + } + + private ObservableCollection _liquidVolumes; + /// + /// Gets or sets the liquid volumes. + /// + public ObservableCollection LiquidVolumes + { + get { return _liquidVolumes; } + set { _liquidVolumes = value; RaisePropertyChangedAuto(); OnLiquidsVolumesChanged(); } + } + + private ObservableCollection _liquidsCalibrationData; + /// + /// Gets or sets the liquids calibration data. + /// + public ObservableCollection LiquidsCalibrationData + { + get { return _liquidsCalibrationData; } + set { _liquidsCalibrationData = value; RaisePropertyChangedAuto(); } + } + + private CctModel _cct; + public CctModel CCT + { + get { return _cct; } + set + { + _cct = value; + RaisePropertyChangedAuto(); + InvalidateRelayCommands(); + } + } + + private RgbVM _sourceColor; + /// + /// Gets or sets the color of the source. + /// + public RgbVM SourceColor + { + get { return _sourceColor; } + set { _sourceColor = value; RaisePropertyChangedAuto(); } + } + + private RgbVM _targetColor; + /// + /// Gets or sets the color of the target. + /// + /// + /// The color of the target. + /// + public RgbVM TargetColor + { + get { return _targetColor; } + set { _targetColor = value; RaisePropertyChangedAuto(); } + } + + #endregion + + public ColorConversionViewVM(INotificationProvider notification) + { + _notification = notification; + + // CCT = new Cct(); + + SourceColor = new RgbVM(); + SourceColor.ColorChanged += SourceColor_ColorChanged; + } + + private void OnLiquidsVolumesChanged() + { + LiquidVolumes.EnableCrossThreadOperations(); + LiquidVolumes.ToList().ForEach(x => x.VolumeChanged += (s, e) => OnLiquidVolumeChanged()); + } + + private void SourceColor_ColorChanged(object sender, Color e) + { + GetHiveSuggestions(); + } + + private void GetHiveSuggestions() + { + Task.Factory.StartNew(() => + { + try + { + if (RML == null || LiquidsCalibrationData == null || CCT == null || CCT.Data == null) return; + + ConversionInput input = new ConversionInput(); + input.ColorSpace = SourceColor.IsLab ? PMR.ColorLab.ColorSpace.Lab : PMR.ColorLab.ColorSpace.Rgb; + //input.DeltaChroma = DeltaChroma; + //input.DeltaL = DeltaL; + input.ForwardData = ByteString.CopyFrom(CCT.Data); + + input.InputCoordinates = new InputCoordinates(); + input.InputCoordinates.Red = (int)SourceColor.Red; + input.InputCoordinates.Green = (int)SourceColor.Green; + input.InputCoordinates.Blue = (int)SourceColor.Blue; + + input.InputCoordinates.L = SourceColor.L; + input.InputCoordinates.A = SourceColor.A; + input.InputCoordinates.B = SourceColor.B; + + input.ThreadL = RML.WhitePointL; + input.ThreadA = RML.WhitePointA; + input.ThreadB = RML.WhitePointB; + + //Validate calibration data + foreach (var vm in LiquidsCalibrationData.Where(x => x.LiquidType.HasPigment)) + { + if (vm.CalibrationPoints.Count == 0) + { + InvokeUI(() => + { + _notification.ShowError($"No calibration data for liquid '{vm.LiquidType.Name}'. Could not convert source color."); + }); + return; + } + else if (!(vm.CalibrationPoints.First().X == 0 && vm.CalibrationPoints.First().Y == 0 && vm.CalibrationPoints.Last().X == 100 && vm.CalibrationPoints.Last().Y == 100)) + { + InvokeUI(() => + { + _notification.ShowError($"Invalid calibration data for liquid '{vm.LiquidType.Name}'. Could not convert source color."); + }); + return; + } + } + + foreach (var vm in LiquidsCalibrationData) + { + InputLiquid inputLiquid = new InputLiquid(); + + + CalibrationData calData = new CalibrationData(); + calData.LiquidType = (PMR.ColorLab.LiquidType)vm.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.LiquidType.Code; + inputLiquid.MaxNanoliterPerCentimeter = LiquidTypesRmls.SingleOrDefault(x => x.LiquidType.Code == vm.LiquidType.Code).MaxNlPerCm; + + input.InputCoordinates.InputLiquids.Add(inputLiquid); + } + + foreach (var process in RML.GetActiveProcessGroup().ProcessParametersTables) + { + input.ProcessRanges.Add(new ProcessRange() + { + MinInkUptake = process.MinInkUptake, + MaxInkUptake = process.MaxInkUptake, + }); + } + + IColorConverter converter = new DefaultColorConverter(); + + var output = converter.Convert(input); + + IsOutOfGamut = output.OutOfGamut; + + HiveSuggestions = output.CreateHiveSuggestions(); + } + catch (Exception ex) + { + LogManager.Log(ex, "An error occurred while trying to convert from source color to Volume."); + + InvokeUI(() => + { + _notification.ShowError($"An error occurred while trying to convert from source color to Volume.\n" + ex.Message); + }); + } + }); + } + + private void OnSelectedSuggestionChanged() + { + if (SelectedSuggestion != null) + { + _prevent_inverse_conversion = true; + + var coords = SelectedSuggestion.Coordinates; + + foreach (var liquid in coords.OutputLiquids) + { + var liquidVolume = LiquidVolumes.SingleOrDefault(x => x.LiquidType.Code == liquid.LiquidType.ToInt32()); + + if (liquidVolume != null) + { + liquidVolume.Volume = liquid.Volume; + } + } + + _prevent_inverse_conversion = false; + + OnLiquidVolumeChanged(); + } + } + + private void OnLiquidVolumeChanged() + { + try + { + if (LiquidsCalibrationData == null || _prevent_inverse_conversion) return; + + //TODO: This is temporary because of out of range volumes. + if (LiquidVolumes.Where(x => x.LiquidType.HasPigment).Sum(x => x.Volume) > 200) + { + IsVolumesOutOfRange = true; + return; + } + else + { + IsVolumesOutOfRange = false; + } + + ConversionInput input = new ConversionInput(); + input.ColorSpace = PMR.ColorLab.ColorSpace.Volume; + input.ForwardData = ByteString.CopyFrom(CCT.Data); + + input.InputCoordinates = new InputCoordinates(); + input.ThreadL = RML.WhitePointL; + input.ThreadA = RML.WhitePointA; + input.ThreadB = RML.WhitePointB; + + foreach (var vm in LiquidsCalibrationData.Where(x => x.LiquidType.HasPigment)) + { + InputLiquid inputLiquid = new InputLiquid(); + + CalibrationData calData = new CalibrationData(); + calData.LiquidType = (PMR.ColorLab.LiquidType)vm.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.LiquidType.Code; + inputLiquid.MaxNanoliterPerCentimeter = LiquidTypesRmls.SingleOrDefault(x => x.LiquidType.Code == vm.LiquidType.Code).MaxNlPerCm; + inputLiquid.Volume = LiquidVolumes.SingleOrDefault(x => x.LiquidType == vm.LiquidType).Volume; + + input.InputCoordinates.InputLiquids.Add(inputLiquid); + } + + foreach (var process in RML.ProcessParametersTablesGroups.Single().ProcessParametersTables) + { + input.ProcessRanges.Add(new ProcessRange() + { + MinInkUptake = process.MinInkUptake, + MaxInkUptake = process.MaxInkUptake, + }); + } + + IColorConverter converter = new DefaultColorConverter(); + + var output = converter.Convert(input); + + if (SourceColor.IsLab) + { + TargetColor = new RgbVM() + { + IsLab = true, + L = output.SingleCoordinates.L, + A = output.SingleCoordinates.A, + B = output.SingleCoordinates.B, + }; + } + else + { + TargetColor = new RgbVM() + { + Red = output.SingleCoordinates.Red, + Green = output.SingleCoordinates.Green, + Blue = output.SingleCoordinates.Blue, + }; + } + } + catch (Exception ex) + { + LogManager.Log(ex, "Error in inversed color conversion!"); + _notification.ShowError("An error occurred while trying to convert from Volume to RGB.\n" + ex.Message); + } + } + } +} diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels/LiquidVolumeVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels/LiquidVolumeVM.cs new file mode 100644 index 000000000..7399d62af --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels/LiquidVolumeVM.cs @@ -0,0 +1,51 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.BL.Entities; +using Tango.Core; +using Tango.SharedUI; + +namespace Tango.MachineStudio.RML.ViewModels +{ + public class LiquidVolumeVM : ExtendedObject + { + public event EventHandler VolumeChanged; + + private String _name; + + public String Name + { + get { return _name; } + set { _name = value; RaisePropertyChangedAuto(); } + } + + private double _volume; + + public double Volume + { + get { return _volume; } + set + { + _volume = value; RaisePropertyChangedAuto(); + VolumeChanged?.Invoke(this, _volume); + } + } + + private int _color; + + public int Color + { + get { return _color; } + set { _color = value; RaisePropertyChangedAuto(); } + } + + private LiquidType _liquidType; + public LiquidType LiquidType + { + get { return _liquidType; } + set { _liquidType = value; RaisePropertyChangedAuto(); } + } + } +} 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 aa84fb137..361608ef6 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 @@ -13,13 +13,13 @@ using Tango.BL.Builders; using Tango.BL.Calibration; using Tango.BL.Entities; using Tango.Core.Commands; -using Tango.MachineStudio.ColorLab.ViewModels; using Tango.MachineStudio.Common; using Tango.MachineStudio.Common.Notifications; using Tango.MachineStudio.RML.Contracts; using Tango.MachineStudio.RML.Models; using Tango.MachineStudio.RML.Views; using Tango.PMR.ColorLab; +using System.Data.Entity; namespace Tango.MachineStudio.RML.ViewModels { @@ -132,7 +132,14 @@ namespace Tango.MachineStudio.RML.ViewModels public CctModel SelectedCCT { get { return _selectedCCT; } - set { _selectedCCT = value; RaisePropertyChangedAuto(); InvalidateRelayCommands(); } + set { _selectedCCT = value; RaisePropertyChangedAuto(); OnSelectedCCTChanged(); InvalidateRelayCommands(); } + } + + private ColorConversionViewVM _colorConversionViewVM; + public ColorConversionViewVM ColorConversionViewVM + { + get { return _colorConversionViewVM; } + set { _colorConversionViewVM = value; RaisePropertyChangedAuto(); } } /// @@ -287,6 +294,13 @@ namespace Tango.MachineStudio.RML.ViewModels CalibrationDataViewVM.LiquidsCalibrationData.Add(catVM); } + ColorConversionViewVM = new ColorConversionViewVM(_notification) + { + RML = ActiveRML, + CCT = SelectedCCT, + LiquidsCalibrationData = CalibrationDataViewVM.LiquidsCalibrationData, + LiquidTypesRmls = LiquidTypesRmls, + }; View.NavigateTo(RmlNavigationView.RmlView); @@ -296,6 +310,27 @@ namespace Tango.MachineStudio.RML.ViewModels } } + private async void OnSelectedCCTChanged() + { + if (SelectedCCT != null && !SelectedCCT.IsNew) + { + using (_notification.PushTaskItem("Loading CCT data...")) + { + IsFree = false; + + var cct = await _active_context.Ccts.SingleOrDefaultAsync(x => x.Guid == SelectedCCT.Guid); + + if (cct != null) + { + SelectedCCT.Data = cct.Data; + ColorConversionViewVM.CCT = SelectedCCT; + } + + IsFree = true; + } + } + } + private void LoadRmlProperties() { Materials = _active_context.MediaMaterials.ToObservableCollection(); @@ -566,6 +601,8 @@ namespace Tango.MachineStudio.RML.ViewModels CCTS.Insert(0, cctModel); SelectedCCT = cctModel; + + ColorConversionViewVM.CCT = SelectedCCT; } } diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels/RgbVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels/RgbVM.cs new file mode 100644 index 000000000..e64592aae --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels/RgbVM.cs @@ -0,0 +1,148 @@ +using ColorMine.ColorSpaces; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Media; +using System.Windows.Threading; +using Tango.Core; +using Tango.SharedUI; + +namespace Tango.MachineStudio.RML.ViewModels +{ + public class RgbVM : ExtendedObject + { + private DispatcherTimer _color_change_timer; + + public event EventHandler ColorChanged; + + public RgbVM() + { + _color_change_timer = new DispatcherTimer(); + _color_change_timer.Interval = TimeSpan.FromMilliseconds(30); + _color_change_timer.Tick += _color_change_timer_Tick; + _color_change_timer.Stop(); + + Color = Colors.DimGray; + } + + private void _color_change_timer_Tick(object sender, EventArgs e) + { + _color_change_timer.Stop(); + ColorChanged?.Invoke(this, Color); + } + + private double _red; + public double Red + { + get { return _red; } + set { _red = value; SynchronizeColor(); RaisePropertyChangedAuto(); } + } + + private double _green; + public double Green + { + get { return _green; } + set { _green = value; SynchronizeColor(); RaisePropertyChangedAuto(); } + } + + private double _blue; + public double Blue + { + get { return _blue; } + set { _blue = value; SynchronizeColor(); RaisePropertyChangedAuto(); } + } + + private double _l; + public double L + { + get { return _l; } + set { _l = value; SynchronizeColor(); RaisePropertyChangedAuto(); } + } + + private double _a; + public double A + { + get { return _a; } + set { _a = value; SynchronizeColor(); RaisePropertyChangedAuto(); } + } + + private double _b; + public double B + { + get { return _b; } + set { _b = value; SynchronizeColor(); RaisePropertyChangedAuto(); } + } + + private Color _color; + public Color Color + { + get { return _color; } + set { _color = value; RaisePropertyChanged(nameof(Color)); SynchronizeComponents(); } + } + + private bool _isLab; + public bool IsLab + { + get { return _isLab; } + set { _isLab = value; RaisePropertyChangedAuto(); } + } + + + private void SynchronizeColor() + { + _color_change_timer.Stop(); + + if (!IsLab) + { + Rgb rgb = new Rgb(Red, Green, Blue); + Lab lab = rgb.To(); + _l = lab.L; + _a = lab.A; + _b = lab.B; + } + else + { + Lab lab = new Lab(L, A, B); + Rgb rgb = lab.To(); + _red = rgb.R; + _green = rgb.G; + _blue = rgb.B; + } + + _color = Color.FromRgb((byte)Red, (byte)Green, (byte)Blue); + RaisePropertyChanged(nameof(Color)); + + _color_change_timer.Start(); + } + + private void SynchronizeComponents() + { + _color_change_timer.Stop(); + + _red = Color.R; + _green = Color.G; + _blue = Color.B; + + if (IsLab) + { + Rgb rgb = new Rgb(Red, Green, Blue); + Lab lab = rgb.To(); + _l = lab.L; + _a = lab.A; + _b = lab.B; + } + + RaisePropertyChanged(nameof(Red)); + RaisePropertyChanged(nameof(Green)); + RaisePropertyChanged(nameof(Blue)); + RaisePropertyChanged(nameof(L)); + RaisePropertyChanged(nameof(A)); + RaisePropertyChanged(nameof(B)); + RaisePropertyChanged(nameof(Color)); + + _color_change_timer.Start(); + } + } +} diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Views/CalibrationDataView.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Views/CalibrationDataView.xaml new file mode 100644 index 000000000..54e96017c --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Views/CalibrationDataView.xaml @@ -0,0 +1,72 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Views/CalibrationDataView.xaml.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Views/CalibrationDataView.xaml.cs new file mode 100644 index 000000000..e23e343a4 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Views/CalibrationDataView.xaml.cs @@ -0,0 +1,28 @@ +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; + +namespace Tango.MachineStudio.RML.Views +{ + /// + /// Interaction logic for CalibrationDataView.xaml + /// + public partial class CalibrationDataView : UserControl + { + public CalibrationDataView() + { + InitializeComponent(); + } + } +} diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Views/ColorConversionView.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Views/ColorConversionView.xaml new file mode 100644 index 000000000..ed27c1760 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Views/ColorConversionView.xaml @@ -0,0 +1,772 @@ + + + + + + + + + + + + + + + + + + + COLOR CONVERSION + + + + + + + + + + + + + + + + + + + + + + + + RGB + LAB + + + + + + + Color is out of gamut + + + + + + + + + + + + + + + + + SOURCE / INVERSE + SUGGESTIONS + LIQUID VOLUMES + + + + + + + + + + + + , + + + + + + + + + + + + + + + + + + + R + + + + + + + + + + + + G + + + + + + + + + + + B + + + + + + + + + + + + + L + + + + + + + + A + + + + + + + + B + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + GAMUT REGION: + + + + + + + + + + Liquid volumes exceeds the maximum range + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + COMPOSITE + + + + + + + + + + + + + + R + + + + + + + + + + + + G + + + + + + + + + + + B + + + + + + + + + + + + + L + + + + + + + + A + + + + + + + + B + + + + + + + + + + + + + + + + diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Views/ColorConversionView.xaml.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Views/ColorConversionView.xaml.cs new file mode 100644 index 000000000..8b6955269 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Views/ColorConversionView.xaml.cs @@ -0,0 +1,28 @@ +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; + +namespace Tango.MachineStudio.RML.Views +{ + /// + /// Interaction logic for ColorConversionView.xaml + /// + public partial class ColorConversionView : UserControl + { + public ColorConversionView() + { + InitializeComponent(); + } + } +} diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Views/ProcessParametersView.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Views/ProcessParametersView.xaml new file mode 100644 index 000000000..b85fd2c12 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Views/ProcessParametersView.xaml @@ -0,0 +1,155 @@ + + + + + + + + + + + + + + + + + + ACTIVE PROCESS GROUP + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + LIQUID FACTORS + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Views/ProcessParametersView.xaml.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Views/ProcessParametersView.xaml.cs new file mode 100644 index 000000000..a6d03ca0e --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Views/ProcessParametersView.xaml.cs @@ -0,0 +1,59 @@ +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; +using Tango.BL.Entities; +using Tango.DragAndDrop; + +namespace Tango.MachineStudio.RML.Views +{ + /// + /// Interaction logic for ProcessParametersView.xaml + /// + public partial class ProcessParametersView : UserControl + { + private MainViewVM _vm; + public DraggingSurface DraggingSurface + { + get { return (DraggingSurface)GetValue(DraggingSurfaceProperty); } + set { SetValue(DraggingSurfaceProperty, value); } + } + public static readonly DependencyProperty DraggingSurfaceProperty = + DependencyProperty.Register("DraggingSurface", typeof(DraggingSurface), typeof(ProcessParametersView), new PropertyMetadata(null)); + + public double WidthLilquidFactors + { + get { return (double )GetValue(WidthLilquidFactorsProperty); } + set { SetValue(WidthLilquidFactorsProperty, value); } + } + + // Using a DependencyProperty as the backing store for WidthLilquidFactors. This enables animation, styling, binding, etc... + public static readonly DependencyProperty WidthLilquidFactorsProperty = + DependencyProperty.Register("WidthLilquidFactors", typeof(double ), typeof(ProcessParametersView), new PropertyMetadata(null)); + + + public ProcessParametersView() + { + InitializeComponent(); + DraggingSurface = draggingSurface; + Loaded += (_, __) => { _vm = DataContext as MainViewVM; }; + } + private void OnProcessTableDropped(object sender, DropEventArgs e) + { + ProcessParametersTable dragged = e.Draggable.DataContext as ProcessParametersTable; + ProcessParametersTable dropped = e.Droppable.DataContext as ProcessParametersTable; + _vm.OnProcessParametersTableDropped(dragged, dropped); + } + } +} 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 fa51a6bf5..628b9e402 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 @@ -9,7 +9,6 @@ xmlns:controls="clr-namespace:Tango.SharedUI.Controls;assembly=Tango.SharedUI" xmlns:editors="clr-namespace:Tango.SharedUI.Editors;assembly=Tango.SharedUI" xmlns:mahapps="http://metro.mahapps.com/winfx/xaml/controls" - xmlns:colorLabViews="clr-namespace:Tango.MachineStudio.ColorLab.Views;assembly=Tango.MachineStudio.ColorLab" xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes" xmlns:converters="clr-namespace:Tango.SharedUI.Converters;assembly=Tango.SharedUI" xmlns:dragAndDrop="clr-namespace:Tango.DragAndDrop;assembly=Tango.DragAndDrop" @@ -126,215 +125,94 @@ - - + + - - - - - - - - - - - - - - - ACTIVE PROCESS GROUP - - - + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + CCT + + + + + + + + + + + + + + + + + + + + - - - + + + + + + + - COLOR CONVERSION TABLE (CCT) + CALIBRATION DATA + - - - - - - - - - - - - - - - - - + + + - - - - - - - - - - - - - - - - - - - - - LIQUID FACTORS - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - CALIBRATION DATA - - - - - - - - - - - diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Views/RmlView.xaml.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Views/RmlView.xaml.cs index 2a5d317c6..aa4803bd0 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Views/RmlView.xaml.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Views/RmlView.xaml.cs @@ -25,32 +25,18 @@ namespace Tango.MachineStudio.RML.Views { private MainViewVM _vm; - public DraggingSurface DraggingSurface - { - get { return (DraggingSurface)GetValue(DraggingSurfaceProperty); } - set { SetValue(DraggingSurfaceProperty, value); } - } - public static readonly DependencyProperty DraggingSurfaceProperty = - DependencyProperty.Register("DraggingSurface", typeof(DraggingSurface), typeof(RmlView), new PropertyMetadata(null)); - - public RmlView() { InitializeComponent(); - DraggingSurface = draggingSurface; Loaded += (_, __) => { _vm = DataContext as MainViewVM; }; } - private void OnProcessTableDropped(object sender, DropEventArgs e) - { - ProcessParametersTable dragged = e.Draggable.DataContext as ProcessParametersTable; - ProcessParametersTable dropped = e.Droppable.DataContext as ProcessParametersTable; - _vm.OnProcessParametersTableDropped(dragged, dropped); - } - private void calibrationDataScrollViewer_ScrollChanged(object sender, ScrollChangedEventArgs e) { - liquidsFactorsScrollViewer.ScrollToHorizontalOffset(e.HorizontalOffset); + if(processParametersView.IsVisible) + { + processParametersView.liquidsFactorsScrollViewer.ScrollToHorizontalOffset(e.HorizontalOffset); + } } } } -- cgit v1.3.1