diff options
| author | Roy <roy.mail.net@gmail.com> | 2022-05-30 17:11:19 +0300 |
|---|---|---|
| committer | Roy <roy.mail.net@gmail.com> | 2022-05-30 17:11:19 +0300 |
| commit | e645e84144f312c8b26832f0a356a006bd8c0c2a (patch) | |
| tree | 3b35c305790eb6807301a5b9b5d9ddfd4a48b8da /Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels | |
| parent | 10eb841cf1535f7bbab097e7cf0a3fd0cf2282fa (diff) | |
| download | Tango-e645e84144f312c8b26832f0a356a006bd8c0c2a.tar.gz Tango-e645e84144f312c8b26832f0a356a006bd8c0c2a.zip | |
Merged MS batch conversion branch.
Diffstat (limited to 'Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels')
| -rw-r--r-- | Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels/MainViewVM.cs | 236 |
1 files changed, 236 insertions, 0 deletions
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 bde174f07..deb162687 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 @@ -25,6 +25,9 @@ using Tango.MachineStudio.Common.Authentication; using Tango.BL.ActionLogs; using Tango.BL.DTO; using Tango.BL.Enumerations; +using Google.Protobuf; +using Tango.ColorConversion; +using Tango.CSV; namespace Tango.MachineStudio.RML.ViewModels { @@ -257,6 +260,8 @@ namespace Tango.MachineStudio.RML.ViewModels /// </summary> public RelayCommand RemoveSpoolCommand { get; set; } + public RelayCommand BatchConversionCommand { get; set; } + public MainViewVM(INotificationProvider notificationProvider, IAuthenticationProvider authentication, IActionLogManager actionLogManager) { _notification = notificationProvider; @@ -283,6 +288,8 @@ namespace Tango.MachineStudio.RML.ViewModels AddSpoolCommand = new RelayCommand(AddNewSpool); RemoveSpoolCommand = new RelayCommand(RemoveSpool, () => SelectedSpool != null); + + BatchConversionCommand = new RelayCommand(BatchConversion); } public override void OnApplicationReady() @@ -916,6 +923,235 @@ namespace Tango.MachineStudio.RML.ViewModels LoadRmls(); } + #region Batch Conversion + + private void BatchConversion() + { + OpenFileDialog dlg = new OpenFileDialog(); + dlg.Title = "Select CSV file with LAB data"; + dlg.Filter = "CSV Files|*.csv"; + if (!dlg.ShowDialogCenter()) + { + return; + } + + String fileName = dlg.FileName; + + try + { + ConversionInput input = new ConversionInput(); + input.ColorSpace = PMR.ColorLab.ColorSpace.Lab; + input.ForwardData = ByteString.CopyFrom(SelectedCCT.Data); + + input.InputCoordinates = new InputCoordinates(); + + input.ThreadL = ActiveRML.WhitePointL; + input.ThreadA = ActiveRML.WhitePointA; + input.ThreadB = ActiveRML.WhitePointB; + + input.UseLightInks = ActiveRML.UseLightInks; + input.VMax = ActiveRML.VMax; + + //Validate calibration data + foreach (var vm in CalibrationDataViewVM.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 CalibrationDataViewVM.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 ActiveRML.GetActiveProcessGroup().ProcessParametersTables) + { + input.ProcessRanges.Add(new ProcessRange() + { + MinInkUptake = process.MinInkUptake, + MaxInkUptake = process.MaxInkUptake, + }); + } + + input.GenerateHive = false; + + IColorConverter converter = new DefaultColorConverter(); + + List<BatchConversionCsvModelIn> labList = CsvFile.Read<BatchConversionCsvModelIn>(new CsvSource(fileName)).ToList(); + + List<BatchConversionCsvModelOut> resultsList = new List<BatchConversionCsvModelOut>(); + + using (_notification.PushTaskItem("Converting...")) + { + foreach (var lab in labList) + { + input.InputCoordinates.L = lab.L; + input.InputCoordinates.A = lab.A; + input.InputCoordinates.B = lab.B; + input.ColorSpace = PMR.ColorLab.ColorSpace.Lab; + var output = converter.Convert(input, ActiveRML.ColorConversionVersion); + + BatchConversionCsvModelOut result = new BatchConversionCsvModelOut(); + + result.Index = lab.Index; + result.L = lab.L; + result.A = lab.A; + result.B = lab.B; + result.SuggestionL = output.CreateSingleSuggestion().Coordinates.L; + result.SuggestionA = output.CreateSingleSuggestion().Coordinates.A; + result.SuggestionB = output.CreateSingleSuggestion().Coordinates.B; + var cyanVolume = output.CreateSingleSuggestion().Coordinates.OutputLiquids.FirstOrDefault(x => x.LiquidType == PMR.ColorLab.LiquidType.Cyan); + + if (cyanVolume != null) + { + result.Cyan = cyanVolume.Volume; + } + + var magentaVolume = output.CreateSingleSuggestion().Coordinates.OutputLiquids.FirstOrDefault(x => x.LiquidType == PMR.ColorLab.LiquidType.Magenta); + + if (magentaVolume != null) + { + result.Magenta = magentaVolume.Volume; + } + + var yellowVolume = output.CreateSingleSuggestion().Coordinates.OutputLiquids.FirstOrDefault(x => x.LiquidType == PMR.ColorLab.LiquidType.Yellow); + + if (yellowVolume != null) + { + result.Yellow = yellowVolume.Volume; + } + + var blackVolume = output.CreateSingleSuggestion().Coordinates.OutputLiquids.FirstOrDefault(x => x.LiquidType == PMR.ColorLab.LiquidType.Black); + + if (blackVolume != null) + { + result.Black = blackVolume.Volume; + } + + var lightCyanVolume = output.CreateSingleSuggestion().Coordinates.OutputLiquids.FirstOrDefault(x => x.LiquidType == PMR.ColorLab.LiquidType.LightCyan); + + if (lightCyanVolume != null) + { + result.LightCyan = lightCyanVolume.Volume; + } + + var lightMagentaVolume = output.CreateSingleSuggestion().Coordinates.OutputLiquids.FirstOrDefault(x => x.LiquidType == PMR.ColorLab.LiquidType.LightMagenta); + + if (lightMagentaVolume != null) + { + result.LightMagenta = lightMagentaVolume.Volume; + } + + var lightYellowVolume = output.CreateSingleSuggestion().Coordinates.OutputLiquids.FirstOrDefault(x => x.LiquidType == PMR.ColorLab.LiquidType.LightYellow); + + if (lightYellowVolume != null) + { + result.LightYellow = lightYellowVolume.Volume; + } + foreach (var item in input.InputCoordinates.InputLiquids) + { + switch (item.LiquidType) + { + case PMR.ColorLab.LiquidType.Cyan: + item.Volume = result.Cyan; + break; + case PMR.ColorLab.LiquidType.Magenta: + item.Volume = result.Magenta; + break; + case PMR.ColorLab.LiquidType.Yellow: + item.Volume = result.Yellow; + break; + case PMR.ColorLab.LiquidType.Black: + item.Volume = result.Black; + break; + case PMR.ColorLab.LiquidType.TransparentInk: + break; + case PMR.ColorLab.LiquidType.Lubricant: + break; + case PMR.ColorLab.LiquidType.Cleaner: + break; + case PMR.ColorLab.LiquidType.LightCyan: + item.Volume = result.LightCyan; + break; + case PMR.ColorLab.LiquidType.LightMagenta: + item.Volume= result.LightMagenta; + break; + case PMR.ColorLab.LiquidType.LightYellow: + item.Volume = result.LightYellow; + break; + default: + break; + } + } + + result.OutOfGamut = output.OutOfGamut; + input.ColorSpace = PMR.ColorLab.ColorSpace.Volume; + output = converter.Convert(input, ActiveRML.ColorConversionVersion); + result.OutputL = output.CreateSingleSuggestion().Coordinates.L; + result.OutputA = output.CreateSingleSuggestion().Coordinates.A; + result.OutputB = output.CreateSingleSuggestion().Coordinates.B; + result.SuggestionDeltaE = BatchConversionCsvModelOut.MirtaDeltaE(result.L, result.A, result.B, result.SuggestionL, result.SuggestionA, result.SuggestionB); + result.OutputDeltaE = BatchConversionCsvModelOut.MirtaDeltaE(result.L, result.A, result.B, result.OutputL, result.OutputA, result.OutputB); + + + resultsList.Add(result); + } + } + + SaveFileDialog dlgOut = new SaveFileDialog(); + dlgOut.Title = "Select results CSV file"; + dlgOut.Filter = "CSV Files|*.csv"; + dlgOut.FileName = Path.GetFileNameWithoutExtension(fileName) + " - Results"; + dlgOut.DefaultExt = ".csv"; + if (!dlgOut.ShowDialogCenter()) + { + return; + } + + using (CsvFile<BatchConversionCsvModelOut> outFile = new CsvFile<BatchConversionCsvModelOut>(new CsvDestination(dlgOut.FileName))) + { + foreach (var result in resultsList) + { + outFile.Append(result); + } + } + } + catch (Exception ex) + { + _notification.ShowError($"Error converting the selected file. Please check all data is valid.\n{ex.FlattenMessage()}"); + } + + _notification.ShowInfo("Batch Conversion Completed."); + } + + #endregion + #region Import / Export Color Conversion Data private void ImportCCTData() |
