diff options
| author | Roy Ben-Shabat <Roy@Twine-s.com> | 2020-09-10 13:32:00 +0300 |
|---|---|---|
| committer | Roy Ben-Shabat <Roy@Twine-s.com> | 2020-09-10 13:32:00 +0300 |
| commit | eee2ca563c712da4d8ef976238642b5247330740 (patch) | |
| tree | c8a8a8a06cbcb118b3e71e43338cee67d7d9316e /Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels | |
| parent | c794c0c66533fc6d02563444d329b8af3d0fe482 (diff) | |
| parent | 6e127075e212e66a890fe130c9b9b90953c70bbd (diff) | |
| download | Tango-eee2ca563c712da4d8ef976238642b5247330740.tar.gz Tango-eee2ca563c712da4d8ef976238642b5247330740.zip | |
Merge branch 'master' of https://twinetfs.visualstudio.com/_git/Tango
Diffstat (limited to 'Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels')
3 files changed, 159 insertions, 17 deletions
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 index b34ef83bc..fd69fef35 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels/CalibrationDataViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels/CalibrationDataViewVM.cs @@ -6,6 +6,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using Tango.BL.Calibration; +using Tango.BL.Entities; using Tango.Core.Commands; using Tango.MachineStudio.Common; using Tango.MachineStudio.Common.Notifications; @@ -106,5 +107,14 @@ namespace Tango.MachineStudio.RML.ViewModels _notification.ShowError("An error occurred while trying to export the calibration data."); } } + + public void ApplyCalibrationData(LiquidType liquidType, List<CalibrationDataPointVM> newpoints) + { + CalibrationDataVM vm = LiquidsCalibrationData.FirstOrDefault(x => x.LiquidType == liquidType); + if(vm != null) + { + newpoints.ForEach(x => vm.CalibrationPoints.Add(x)); + } + } } } 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 4a6895df3..f04eccd90 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 @@ -41,7 +41,7 @@ namespace Tango.MachineStudio.RML.ViewModels public BL.Entities.LiquidType LiquidType { get { return _liquidType; } - set { _liquidType = value; RaisePropertyChangedAuto(); } + set { _liquidType = value; RaisePropertyChangedAuto(); RaisePropertyChanged("LiquidTypeName"); } } private List<BL.Entities.LiquidType> _liquidTypes; @@ -89,15 +89,17 @@ namespace Tango.MachineStudio.RML.ViewModels get { return _hasError; } set { _hasError = value; RaisePropertyChangedAuto(); } } - + + public RelayCommand ImportDataCommand { get; set; } public RelayCommand CreateGraphCommand { get; set; } public RelayCommand CreateLinearizationGraphCommand { get; set; } public RelayCommand ExportGraphCommand { get; set; } + public RelayCommand ApplyCalibrationDataCommand { get; set; } public string LiquidTypeName { - get { return LiquidType == null ?"" : LiquidType.Name; } + get { return LiquidType == null ?"" : LiquidType.Name; } } public Plot PlotControl { get; set; } @@ -160,7 +162,23 @@ namespace Tango.MachineStudio.RML.ViewModels } } - + private double _LabMinVal; + + public double LabMinVal + { + get { return _LabMinVal; } + set { _LabMinVal = value; RaisePropertyChangedAuto(); } + } + + private double _LabMaxVal; + + public double LabMaxVal + { + get { return _LabMaxVal; } + set { _LabMaxVal = value; RaisePropertyChangedAuto(); } + } + + public Plot LABLinearizationPlotControl { get; set; } public Plot LinearizationPlotControl { get; set; } private IList<DataPoint> _linearizationPoints; /// <summary> @@ -176,6 +194,31 @@ namespace Tango.MachineStudio.RML.ViewModels } } + private IList<DataPoint> _LPoints; + + public IList<DataPoint> LPoints + { + get { return _LPoints; } + set { _LPoints = value; } + } + + private IList<DataPoint> _APoints; + + public IList<DataPoint> APoints + { + get { return _APoints; } + set { _APoints = value; } + } + + private IList<DataPoint> _BPoints; + + public IList<DataPoint> BPoints + { + get { return _BPoints; } + set { _BPoints = value; } + } + + #endregion public ColorCalibrationViewVM(INotificationProvider notification) @@ -189,12 +232,17 @@ namespace Tango.MachineStudio.RML.ViewModels }; Factor = 0; HasError = false; + ImportDataCommand = new RelayCommand(ImportDataForCalcFactorExcel); CreateGraphCommand = new RelayCommand(CreateGraph); CreateLinearizationGraphCommand = new RelayCommand(CreateLinearizationGraph); ExportGraphCommand = new RelayCommand(ExportGraph); + ApplyCalibrationDataCommand = new RelayCommand(ApplyCalibrationData); this.Points = new List<DataPoint>(); TargetPoints = new List<DataPoint>(); LinearizationPoints = new List<DataPoint>(); + LPoints = new List<DataPoint>(); + APoints = new List<DataPoint>(); + BPoints = new List<DataPoint>(); } public void Loading() @@ -205,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 @@ -236,14 +293,46 @@ namespace Tango.MachineStudio.RML.ViewModels } return 0.0; } + + private void ImportDataForCalcFactorExcel() + { + OpenFileDialog dlg = new OpenFileDialog(); + + try + { + dlg.Title = $"Import excel file for calculate Factor"; + dlg.Filter = "Excel Files|*.xlsx"; + if (dlg.ShowDialog().Value) + { + ClearResults(); + List<ColorLinearizationModel.LinearizationDataItem> items;//List<LinearizationDataItem> items + ColorLinearizationModel model = new ColorLinearizationModel(); + 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))); + } + } + 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."); + } + } #region CreateGraph private async void CreateGraph(object obj) { if (_liquidType == null) return; - + ClearResults(); + PlotControl.InvalidatePlot(true); string labType = ColorCalibrationExt.DisplayLiquidTypeToLABType[_liquidType.Type]; await Task.Factory.StartNew(() => { @@ -251,8 +340,6 @@ namespace Tango.MachineStudio.RML.ViewModels }); DataPoint targetPoint = GetTargetPoint(); - Points.Clear(); - TargetPoints.Clear(); To = 0; From = 0; @@ -314,18 +401,39 @@ 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<ColorLinearizationModel.LinearizationDataItem> items; - model.GetDataFromFile(fileName, out items); - if (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<double> outputPoints = new List<double>(); + List<double> outputPoints = new List<double>(); + await Task.Factory.StartNew(() => { outputPoints = GetLinearizationMeasurements(items); }); - LinearizationPoints.Clear(); + 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) + { + LPoints.Add(new DataPoint(labItem.InkPercentage, labItem.L)); + APoints.Add(new DataPoint(labItem.InkPercentage, labItem.A)); + BPoints.Add(new DataPoint(labItem.InkPercentage, labItem.B)); + } + LABLinearizationPlotControl.InvalidatePlot(true); if (outputPoints == null || outputPoints.Count != items.Count) return; @@ -363,6 +471,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)) { @@ -370,12 +489,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) @@ -420,6 +533,19 @@ namespace Tango.MachineStudio.RML.ViewModels Y = point.Y, }; } + + /// <summary> + /// Applies the calibration data. + /// </summary> + protected void ApplyCalibrationData() + { + if (LinearizationPoints.Count == 0) + return; + + List<CalibrationDataPointVM> points = new List<CalibrationDataPointVM>(); + LinearizationPoints.ToList().ForEach(x => points.Add(new CalibrationDataPointVM(x.X, x.Y))); + ViewModelLocator.MainViewVM.CalibrationDataViewVM.ApplyCalibrationData(LiquidType, points); + } #endregion } } 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 548ea7d8c..cadd1fb95 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 @@ -883,6 +883,12 @@ namespace Tango.MachineStudio.RML.ViewModels String file = GetCCTFileOpen(); if (file != null) { + if (CCTS.ToList().Exists(x => x.FileName == Path.GetFileName(file))) + { + _notification.ShowError("The selected CCT file already exists on the database. Please select the CCT file from the dropdown box."); + return; + } + CctModel cctModel = new CctModel(); cctModel.Guid = Guid.NewGuid().ToString(); cctModel.IsNew = true; |
