From 92b1cd2bd7f4f42d7613ba424ef568a3a476bd89 Mon Sep 17 00:00:00 2001 From: Victoria Plitt Date: Sun, 6 Sep 2020 14:38:46 +0300 Subject: Color Calibration. Added Error notification to Linearization process. Clear graphs on start new process. Memory testing C++ code in debug. --- .../Models/ColorLinearizationModel.cs | 4 +- .../ViewModels/ColorCalibrationViewVM.cs | 65 +++++++++++++++------- 2 files changed, 47 insertions(+), 22 deletions(-) (limited to 'Software/Visual_Studio/MachineStudio') diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Models/ColorLinearizationModel.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Models/ColorLinearizationModel.cs index f82c04bbc..23179b3f2 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Models/ColorLinearizationModel.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Models/ColorLinearizationModel.cs @@ -23,7 +23,7 @@ namespace Tango.MachineStudio.RML.Models } - public void GetDataFromFile(string fileName, out List items) + public void GetDataFromFile(string fileName, out List items, ref string errors) { items = null; try @@ -35,7 +35,7 @@ namespace Tango.MachineStudio.RML.Models } catch (Exception ex) { - Console.WriteLine($" Error in GetDataFromFile {fileName} exception: {ex.Message}" + Environment.NewLine); + errors = ex.Message; } } 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 index 31d89005e..8daa1b085 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels/ColorCalibrationViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels/ColorCalibrationViewVM.cs @@ -253,6 +253,15 @@ namespace Tango.MachineStudio.RML.ViewModels } + public void ClearResults() + { + Points.Clear(); + TargetPoints.Clear(); + ErrorMessage = ""; + HasError = false; + Factor = 0.0; + } + private double GetLiquidFactor() { try @@ -295,11 +304,17 @@ namespace Tango.MachineStudio.RML.ViewModels dlg.Filter = "Excel Files|*.xlsx"; if (dlg.ShowDialog().Value) { + ClearResults(); + List items;//List items ColorLinearizationModel model = new ColorLinearizationModel(); - model.GetDataFromFile(dlg.FileName, out items); - if (items == null || items.Count == 0) + string error = ""; + model.GetDataFromFile(dlg.FileName, out items, ref error); + if (false == String.IsNullOrEmpty(error) || items == null || items.Count == 0) + { + _notification.ShowError("An error occurred while trying to import data form the selected excel file. Please check the file format if valid and is available to read."); return; + } Measurements.Clear(); items.ForEach(x => Measurements.Add(new CalibrationMeasurementModel(x))); } @@ -316,7 +331,7 @@ namespace Tango.MachineStudio.RML.ViewModels { if (_liquidType == null) return; - + ClearResults(); string labType = ColorCalibrationExt.DisplayLiquidTypeToLABType[_liquidType.Type]; await Task.Factory.StartNew(() => { @@ -324,8 +339,6 @@ namespace Tango.MachineStudio.RML.ViewModels }); DataPoint targetPoint = GetTargetPoint(); - Points.Clear(); - TargetPoints.Clear(); To = 0; From = 0; @@ -387,23 +400,30 @@ namespace Tango.MachineStudio.RML.ViewModels if (fileName == null) return; + LinearizationPoints.Clear(); + LinearizationPlotControl.InvalidatePlot(true); + LPoints.Clear(); + APoints.Clear(); + BPoints.Clear(); + LabMinVal = LabMaxVal = 0; + LABLinearizationPlotControl.InvalidatePlot(true); + List items; - model.GetDataFromFile(fileName, out items); - if (items == null || items.Count == 0) + string errors = ""; + model.GetDataFromFile(fileName, out items, ref errors); + if(false == String.IsNullOrEmpty(errors) || items == null || items.Count == 0) + { + _notification.ShowError("An error occurred while trying to import data form the selected excel file. Please check the file format if valid and is available to read."); return; + } - List outputPoints = new List(); + List outputPoints = new List(); + await Task.Factory.StartNew(() => { outputPoints = GetLinearizationMeasurements(items); }); - LinearizationPoints.Clear(); - LPoints.Clear(); - APoints.Clear(); - BPoints.Clear(); - LabMinVal = LabMaxVal = 0; - LabMinVal = items.Min(x => Math.Min(x.L, Math.Min(x.A, x.B))); LabMaxVal = items.Max(x => Math.Max(x.L, Math.Max(x.A, x.B))); foreach (var labItem in items) @@ -450,6 +470,17 @@ namespace Tango.MachineStudio.RML.ViewModels items.ForEach(x => linearizationInput.Measurements.Add(new LinearizationMeasurement { L = x.L, A = x.A, B = x.B, InkPercentage = x.InkPercentage })); linearizationInput.LiquidType = PMR.ColorLab.LiquidType.TryParse(_liquidType.Type.ToString(), out PMR.ColorLab.LiquidType outValue) ? outValue : PMR.ColorLab.LiquidType.Black; + LinearizationOutput result = _linearizationMeasurementscalibrator.GetLinearizationMeasurements(linearizationInput); + + if(!String.IsNullOrEmpty(result.ErrorMessage)) + { + LogManager.Log(result.ErrorMessage, "GetLinearizationMeasurements returns error." + result.ErrorMessage); + InvokeUI(() => + { + _notification.ShowError("Linearization failed. " + result.ErrorMessage); + }); + } + LAB lab; if (ColorCalibrationExt.TargetLiquidTypeToLAB.TryGetValue(_liquidType.Type, out lab)) { @@ -457,12 +488,6 @@ namespace Tango.MachineStudio.RML.ViewModels linearizationInput.TargetA = lab.A; linearizationInput.TargetB = lab.B; } - LinearizationOutput result = _linearizationMeasurementscalibrator.GetLinearizationMeasurements(linearizationInput); - - if(!String.IsNullOrEmpty(result.ErrorMessage)) - { - //LogManager.Log(result.ErrorMessage, "Error occurred while trying to call GetLinearizationMeasurements."); - } return result.InkPercentage.ToList(); } catch (Exception ex) -- cgit v1.3.1