aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels/MainViewVM.cs
diff options
context:
space:
mode:
authorVictoria Plitt <Victoria.Plitt@twine-s.com>2022-05-31 12:27:47 +0300
committerVictoria Plitt <Victoria.Plitt@twine-s.com>2022-05-31 12:27:47 +0300
commit209d0f0c99d0244fb4678e975141d0f602fe3ced (patch)
tree873814fde05f74de4c93cfc2699bade052593c1f /Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels/MainViewVM.cs
parent714d734a19da58c49baecdc064b408e05dec1259 (diff)
parentb4242c696553510865ac25d6ccfd05f25adc0195 (diff)
downloadTango-209d0f0c99d0244fb4678e975141d0f602fe3ced.tar.gz
Tango-209d0f0c99d0244fb4678e975141d0f602fe3ced.zip
Merge branch 'software' of https://twinetfs.visualstudio.com/Tango/_git/Tango into software
Diffstat (limited to 'Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels/MainViewVM.cs')
-rw-r--r--Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels/MainViewVM.cs236
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()