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.cs190
1 files changed, 95 insertions, 95 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 dd0c66c58..f118ce77a 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
@@ -16,6 +16,7 @@ using Tango.ColorCalibration;
using Tango.PMR.ColorLab;
using Tango.Logging;
using Tango.MachineStudio.Common.Notifications;
+using System.Text.RegularExpressions;
namespace Tango.MachineStudio.RML.ViewModels
{
@@ -41,6 +42,14 @@ namespace Tango.MachineStudio.RML.ViewModels
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
@@ -69,17 +78,38 @@ namespace Tango.MachineStudio.RML.ViewModels
public double Factor
{
get { return _factor; }
- set { _factor = value; }
+ set { _factor = value; RaisePropertyChangedAuto(); }
}
- public RelayCommand CreateGraphCommand { get; set; }
+ private string _errorMessage;
+ public string ErrorMessage
+ {
+ get { return _errorMessage; }
+ set { _errorMessage = value; RaisePropertyChangedAuto(); }
+ }
+ private bool _hasError;
+
+ public bool HasError
+ {
+ get { return _hasError; }
+ set { _hasError = value; RaisePropertyChangedAuto(); }
+ }
- public string CalibrationType
+ public RelayCommand CreateGraphCommand { get; set; }
+ public RelayCommand CreateLinearizationGraphCommand { get; set; }
+
+
+ public string CalibrationLiquidTypeName
{
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>
@@ -140,6 +170,22 @@ namespace Tango.MachineStudio.RML.ViewModels
}
}
+
+ public Plot LinearizationPlotControl { get; set; }
+ private IList<DataPoint> _linearizationPoints;
+ /// <summary>
+ /// Binding to ItemsSource of line chart.
+ /// </summary>
+ public IList<DataPoint> LinearizationPoints
+ {
+ get { return _linearizationPoints; }
+ set
+ {
+ _linearizationPoints = value;
+ RaisePropertyChangedAuto();
+ }
+ }
+
#endregion
public ColorCalibrationViewVM(INotificationProvider notification)
@@ -152,7 +198,9 @@ namespace Tango.MachineStudio.RML.ViewModels
new CalibrationMeasurementModel(),
};
Factor = 0;
+ HasError = false;
CreateGraphCommand = new RelayCommand(CreateGraph);
+ CreateLinearizationGraphCommand = new RelayCommand(CreateLinearizationGraph);
this.Points = new List<DataPoint>();
TargetPoints = new List<DataPoint>();
}
@@ -166,24 +214,31 @@ namespace Tango.MachineStudio.RML.ViewModels
private double GetLiquidFactor()
{
- try{
- CalibrationInput conversionInput = new CalibrationInput();
- Measurements.ToList().ForEach(x => conversionInput.Measurements.Add(new CalibrationMeasurement{ L = x.L, A = x.A, B = x.B, NanoliterPerCentimeter = x.Ink }));
- conversionInput.LiquidType = PMR.ColorLab.LiquidType.TryParse(_liquidType.Type.ToString(), out PMR.ColorLab.LiquidType outValue) ? outValue : PMR.ColorLab.LiquidType.Black;
-
+ try
+ {
+ CalibrationInput conversionInput = new CalibrationInput();
+ Measurements.ToList().ForEach(x => conversionInput.Measurements.Add(new CalibrationMeasurement { L = x.L, A = x.A, B = x.B, NanoliterPerCentimeter = x.Ink }));
+ conversionInput.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))
- {
- conversionInput.TargetL = lab.L;
- conversionInput.TargetA = lab.A;
- conversionInput.TargetB = lab.B;
- }
- CalibrationOutput result = _calibrator.GetLiquidFactor(conversionInput);
- return result.LiquidFactor;
+
+ LAB lab;
+ if (ColorCalibrationExt.TargetLiquidTypeToLAB.TryGetValue(_liquidType.Type, out lab))
+ {
+ conversionInput.TargetL = lab.L;
+ conversionInput.TargetA = lab.A;
+ conversionInput.TargetB = lab.B;
+ }
+ CalibrationOutput result = _calibrator.GetLiquidFactor(conversionInput);
+
+ ErrorMessage = Regex.Replace(result.ErrorMessage, "[^A-Za-z0-9_., ]+", "");
+
+ HasError = false == String.IsNullOrEmpty(ErrorMessage);
+ return result.LiquidFactor;
}
catch (Exception ex )
{
+ HasError = true;
+ ErrorMessage = "Error occurred while trying to call GetLiquidFactor.";
LogManager.Log(ex, "Error occurred while trying to call GetLiquidFactor.");
}
return 0.0;
@@ -196,11 +251,10 @@ namespace Tango.MachineStudio.RML.ViewModels
if (_liquidType == null)
return;
- LAB lab;
string labType = ColorCalibrationExt.DisplayLiquidTypeToLABType[_liquidType.Type];
await Task.Factory.StartNew(() =>
{
- Factor = GetLiquidFactor();
+ Factor = GetLiquidFactor( );
});
Points.Clear();
@@ -222,92 +276,38 @@ namespace Tango.MachineStudio.RML.ViewModels
RaisePropertyChanged("CalibrationType");
PlotControl.InvalidatePlot(true);
- //await Task.Factory.StartNew(() =>
- //{
- // DataPoint ? intersectionpoints = FindIntersection(Points.ToArray(), TargetPoints.ToArray());
- // if(intersectionpoints == null)
- // {
- // InvokeUI(() =>
- // {
- // _notification.ShowWarning(LogManager.Log($"No intersect target value with input values", LogCategory.Warning));
- // });
- // }
- //});
-
}
#endregion
+ #region CreateLinearizationGraph
- #region Intersect
-
- public DataPoint? FindIntersection(DataPoint[] line1, DataPoint[] line2)
+ private void CreateLinearizationGraph(object obj)
{
- for (int i = 0; i < line1.Length; i++)
- {
- int nextI = i;
- nextI++;
- if (nextI == line1.Length) break;
-
- for (int j = 0; j < line2.Length; j++)
- {
- int nextJ = j;
- nextJ++;
- if (nextJ == line2.Length) break;
- DataPoint? d = CheckIntersecting(line1[i], line1[nextI], line2[j], line2[nextJ]);
- return d;
-
- }
- }
- return null;
- }
-
- public DataPoint? CheckIntersecting(DataPoint A, DataPoint B, DataPoint C, DataPoint D)
- {
- // Line AB represented as a1x + b1y = c1
- double a1 = B.Y - A.Y;
- double b1 = A.X - B.X;
- double c1 = a1 * (A.X) + b1 * (A.Y);
+ if (_selectedLinearizationliquidType == null)
+ return;
- // Line CD represented as a2x + b2y = c2
- double a2 = D.Y - C.Y;
- double b2 = C.X - D.X;
- double c2 = a2 * (C.X) + b2 * (C.Y);
+ string labType = ColorCalibrationExt.DisplayLiquidTypeToLABType[_selectedLinearizationliquidType.Type];
- double determinant = a1 * b2 - a2 * b1;
+ ColorLinearizationModel model = new ColorLinearizationModel();
+ string fileName = @"C:\Test\Test Input Lineration.xlsx";
+ model.GetDataFromFile(fileName);
+ //await Task.Factory.StartNew(() =>
+ //{
+ // Factor = GetLiquidFactor();
+ //});
- if (determinant == 0)
- {
- // The lines are parallel. This is simplified
- }
- else
- {
- double x = (b2 * c1 - b1 * c2) / determinant;
- double y = (a1 * c2 - a2 * c1) / determinant;
+ LinearizationPoints.Clear();
+
+ Measurements.ToList().ForEach(x => {
+ LinearizationPoints.Add(new DataPoint(x.Ink, x.L));
+ });
- // check if the point lies on given line segment
- /* To check if "x" is between "a" and "b";
- int m = (a+b)/2;
- if(Math.abs(x-m) <= (Math.abs(a-m)))
- {
- }
- */
- double mx1 = (A.X + B.X) / 2;
- double mx2 = (C.X + D.X) / 2;
- double my1 = (A.Y + B.Y) / 2;
- double my2 = (C.Y + D.Y) / 2;
- if (Math.Abs(x - mx1) <= Math.Abs(A.X - mx1)
- && Math.Abs(x - mx2) <= Math.Abs(C.X - mx2)
- && Math.Abs(y - my1) <= Math.Abs(A.Y - my1)
- && Math.Abs(y - my2) <= Math.Abs(C.Y - my2))
- {
- return new DataPoint(x, y);
- }
-
- }
- return null;
+ RaisePropertyChanged("To");
+ RaisePropertyChanged("From");
+ XStep = (int)(Points.Count / 6);
+ LinearizationPlotControl.InvalidatePlot(true);
}
-
#endregion
-
+
}
}