aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels
diff options
context:
space:
mode:
Diffstat (limited to 'Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels')
-rw-r--r--Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels/ColorCalibrationViewVM.cs156
-rw-r--r--Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels/ColorConversionViewVM.cs4
2 files changed, 122 insertions, 38 deletions
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 f118ce77a..7d05897d5 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
@@ -17,12 +17,14 @@ using Tango.PMR.ColorLab;
using Tango.Logging;
using Tango.MachineStudio.Common.Notifications;
using System.Text.RegularExpressions;
+using Microsoft.Win32;
namespace Tango.MachineStudio.RML.ViewModels
{
public class ColorCalibrationViewVM : ExtendedObject
{
private IColorCalibrator _calibrator;
+ private ILinearizationMeasurements _linearizationMeasurementscalibrator;
private INotificationProvider _notification;
#region Properties
@@ -41,15 +43,7 @@ namespace Tango.MachineStudio.RML.ViewModels
get { return _liquidType; }
set { _liquidType = value; RaisePropertyChangedAuto(); }
}
-
- private BL.Entities.LiquidType _selectedLinearizationliquidType;
-
- public BL.Entities.LiquidType SelectedLinearizationLiquidType
- {
- get { return _selectedLinearizationliquidType; }
- set { _selectedLinearizationliquidType = value; RaisePropertyChangedAuto(); }
- }
-
+
private List<BL.Entities.LiquidType> _liquidTypes;
public List<BL.Entities.LiquidType> LiquidTypes
@@ -98,18 +92,14 @@ namespace Tango.MachineStudio.RML.ViewModels
public RelayCommand CreateGraphCommand { get; set; }
public RelayCommand CreateLinearizationGraphCommand { get; set; }
+ public RelayCommand ExportGraphCommand { get; set; }
- public string CalibrationLiquidTypeName
+ public string LiquidTypeName
{
get { return LiquidType == null ?"" : LiquidType.Name; }
}
-
- public string LinearizationLiquidTypeName
- {
- get { return SelectedLinearizationLiquidType == null ? "" : SelectedLinearizationLiquidType.Name; }
- }
-
+
public Plot PlotControl { get; set; }
private IList<DataPoint> _points;
/// <summary>
@@ -201,14 +191,17 @@ namespace Tango.MachineStudio.RML.ViewModels
HasError = false;
CreateGraphCommand = new RelayCommand(CreateGraph);
CreateLinearizationGraphCommand = new RelayCommand(CreateLinearizationGraph);
+ ExportGraphCommand = new RelayCommand(ExportGraph);
this.Points = new List<DataPoint>();
TargetPoints = new List<DataPoint>();
+ LinearizationPoints = new List<DataPoint>();
}
public void Loading()
{
LiquidType = LiquidTypes.Count > 0 ? LiquidTypes[0] : null;
_calibrator = new DefaultColorCalibrator();
+ _linearizationMeasurementscalibrator = new DefaultColorCalibrator();
}
@@ -229,10 +222,10 @@ namespace Tango.MachineStudio.RML.ViewModels
conversionInput.TargetB = lab.B;
}
CalibrationOutput result = _calibrator.GetLiquidFactor(conversionInput);
-
- ErrorMessage = Regex.Replace(result.ErrorMessage, "[^A-Za-z0-9_., ]+", "");
-
+
+ ErrorMessage = result.ErrorMessage;
HasError = false == String.IsNullOrEmpty(ErrorMessage);
+
return result.LiquidFactor;
}
catch (Exception ex )
@@ -281,33 +274,124 @@ namespace Tango.MachineStudio.RML.ViewModels
#endregion
#region CreateLinearizationGraph
- private void CreateLinearizationGraph(object obj)
+ private async void CreateLinearizationGraph(object obj)
{
- if (_selectedLinearizationliquidType == null)
+ if (_liquidType == null )
return;
- string labType = ColorCalibrationExt.DisplayLiquidTypeToLABType[_selectedLinearizationliquidType.Type];
+ string labType = ColorCalibrationExt.DisplayLiquidTypeToLABType[_liquidType.Type];
ColorLinearizationModel model = new ColorLinearizationModel();
- string fileName = @"C:\Test\Test Input Lineration.xlsx";
- model.GetDataFromFile(fileName);
- //await Task.Factory.StartNew(() =>
- //{
- // Factor = GetLiquidFactor();
- //});
+ string fileName = GetInkDataFileOpen();// @"C:\Test\Test Input Lineration.xlsx";//dialog to open file
+ if (fileName == null)
+ return;
- LinearizationPoints.Clear();
-
- Measurements.ToList().ForEach(x => {
- LinearizationPoints.Add(new DataPoint(x.Ink, x.L));
+ List<ColorLinearizationModel.LinearizationDataItem> items;
+ model.GetDataFromFile(fileName, out items);
+ if (items.Count == 0)
+ return;
+
+ List<double> outputPoints = new List<double>();
+ await Task.Factory.StartNew(() =>
+ {
+ outputPoints = GetLinearizationMeasurements(items);
});
- RaisePropertyChanged("To");
- RaisePropertyChanged("From");
- XStep = (int)(Points.Count / 6);
+ LinearizationPoints.Clear();
+
+ if (outputPoints == null || outputPoints.Count != items.Count)
+ return;
+
+ foreach (var nw in items.Zip(outputPoints, Tuple.Create))
+ {
+ LinearizationPoints.Add(new DataPoint(nw.Item1.InkPercentage, nw.Item2));
+ }
+
LinearizationPlotControl.InvalidatePlot(true);
}
+
+ /// <summary>
+ /// Open file dialog and get name of file
+ /// </summary>
+ /// <returns></returns>
+ private String GetInkDataFileOpen()
+ {
+ OpenFileDialog dlg = new OpenFileDialog();
+ dlg.Title = "Select Ink data file";
+ dlg.Filter = "Excel |*.xlsx";
+ if (dlg.ShowDialogCenter())
+ {
+ return dlg.FileName;
+ }
+
+ return null;
+ }
+
+ private List<double> GetLinearizationMeasurements(List<ColorLinearizationModel.LinearizationDataItem> items)
+ {
+ try
+ {
+ LinearizationInput linearizationInput = new LinearizationInput();
+ 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;
+
+ LAB lab;
+ if (ColorCalibrationExt.TargetLiquidTypeToLAB.TryGetValue(_liquidType.Type, out lab))
+ {
+ linearizationInput.TargetL = lab.L;
+ 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)
+ {
+ LogManager.Log(ex, "Error occurred while trying to call GetLinearizationMeasurements.");
+ }
+ return null;
+ }
+ #endregion
+
+ #region Export graph
+ /// <summary>
+ /// Exports the graph point to Excel file.
+ /// </summary>
+ protected void ExportGraph()
+ {
+ SaveFileDialog dlg = new SaveFileDialog();
+ try
+ {
+ dlg.Title = $"Export excel calibration file for {LiquidType.Name}";
+ dlg.Filter = "Excel Files|*.xlsx";
+ dlg.DefaultExt = ".xlsx";
+ dlg.FileName = $"CData_{LiquidType.Name}_v{LiquidType.Version}.xlsx";
+ if (dlg.ShowDialog().Value)
+ {
+ List<CalibrationPoint> points = new List<CalibrationPoint>();
+ LinearizationPoints.ToList().ForEach(x=> points.Add(ToCalibrationPoint(x)));
+ BL.Calibration.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.");
+ }
+ }
+ public CalibrationPoint ToCalibrationPoint(DataPoint point)
+ {
+ return new CalibrationPoint()
+ {
+ X = point.X,
+ Y = point.Y,
+ };
+ }
#endregion
-
}
}
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
index f583fa15e..d9ba419e0 100644
--- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels/ColorConversionViewVM.cs
+++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels/ColorConversionViewVM.cs
@@ -314,11 +314,11 @@ namespace Tango.MachineStudio.RML.ViewModels
try
{
var tables = RML.GetActiveProcessGroup().ProcessParametersTables.OrderBy(x => x.TableIndex).ToList();
- return (tables[1].MaxInkUptake / tables[0].MaxInkUptake) * 100;
+ return tables.Max(x => x.MaxInkUptake);
}
catch
{
- return BrushStop.MAX_TOTAL_LIQUID_VOLUME;
+ return BrushStop.MAX_INK_UPTAKE;
}
}