aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ThreadExtensions/ViewModels
diff options
context:
space:
mode:
authorVictoria Plitt <Victoria.Plitt@twine-s.com>2022-01-09 16:17:15 +0200
committerVictoria Plitt <Victoria.Plitt@twine-s.com>2022-01-09 16:17:15 +0200
commitb6b16143304b50744e974ddaa9c71c49766be4dc (patch)
treed773bd1c50b4241669a07cc6cb2e7f4cf936f86b /Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ThreadExtensions/ViewModels
parent506b18058821a3791b28c0296e54ef3bc5a3391a (diff)
downloadTango-b6b16143304b50744e974ddaa9c71c49766be4dc.tar.gz
Tango-b6b16143304b50744e974ddaa9c71c49766be4dc.zip
#5821 RML extension - Color calibration window
Diffstat (limited to 'Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ThreadExtensions/ViewModels')
-rw-r--r--Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ThreadExtensions/ViewModels/CalibrationDataVM.cs138
-rw-r--r--Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ThreadExtensions/ViewModels/ColorCalibrationTabVM.cs323
-rw-r--r--Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ThreadExtensions/ViewModels/ColorCalibrationViewVM.cs467
-rw-r--r--Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ThreadExtensions/ViewModels/MainViewVM.cs73
4 files changed, 976 insertions, 25 deletions
diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ThreadExtensions/ViewModels/CalibrationDataVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ThreadExtensions/ViewModels/CalibrationDataVM.cs
new file mode 100644
index 000000000..b8fab210c
--- /dev/null
+++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ThreadExtensions/ViewModels/CalibrationDataVM.cs
@@ -0,0 +1,138 @@
+using System;
+using System.Collections.Generic;
+using System.Collections.ObjectModel;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Tango.BL.Entities;
+using Tango.Core;
+using Tango.PMR.ColorLab;
+
+namespace Tango.MachineStudio.ThreadExtensions.ViewModels
+{
+ public class CalibrationDataPointVM : ExtendedObject
+ {
+ private double _x;
+
+ public double X
+ {
+ get { return _x; }
+ set { _x = value; RaisePropertyChangedAuto(); }
+ }
+
+ private double _y;
+
+ public double Y
+ {
+ get { return _y; }
+ set { _y = value; RaisePropertyChangedAuto(); }
+ }
+
+ private int _index;
+
+ public int Index
+ {
+ get { return _index; }
+ set { _index = value; RaisePropertyChangedAuto(); }
+ }
+
+
+ public CalibrationDataPointVM()
+ {
+
+ }
+
+ public CalibrationDataPointVM(double x, double y)
+ {
+ X = x;
+ Y = y;
+ }
+
+ public CalibrationDataPointVM(CalibrationPoint calibrationPoint) : this(calibrationPoint.X, calibrationPoint.Y)
+ {
+
+ }
+
+ public CalibrationPoint ToPMR()
+ {
+ return new CalibrationPoint()
+ {
+ X = X,
+ Y = Y,
+ };
+ }
+ }
+
+ public class CalibrationDataVM : ExtendedObject
+ {
+ private BL.Entities.LiquidType _liquidType;
+
+ public BL.Entities.LiquidType LiquidType
+ {
+ get { return _liquidType; }
+ set { _liquidType = value; RaisePropertyChangedAuto(); }
+ }
+
+ private IdsPack _idsPack;
+
+ public IdsPack IdsPack
+ {
+ get { return _idsPack; }
+ set { _idsPack = value; RaisePropertyChangedAuto(); }
+ }
+
+ private ObservableCollection<CalibrationDataPointVM> _calibrationPoints;
+
+ public ObservableCollection<CalibrationDataPointVM> CalibrationPoints
+ {
+ get { return _calibrationPoints; }
+ set { _calibrationPoints = value; RaisePropertyChangedAuto(); OnCalibrationPointsChanged(); }
+ }
+
+ private void OnCalibrationPointsChanged()
+ {
+ if (CalibrationPoints != null)
+ {
+ CalibrationPoints.CollectionChanged -= CalibrationPoints_CollectionChanged;
+ CalibrationPoints.CollectionChanged += CalibrationPoints_CollectionChanged;
+
+ SetIndices();
+ }
+ }
+
+ private void CalibrationPoints_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
+ {
+ SetIndices();
+ }
+
+ private void SetIndices()
+ {
+ if (CalibrationPoints != null)
+ {
+ int index = 1;
+ foreach (var p in CalibrationPoints)
+ {
+ p.Index = index++;
+ }
+ }
+ }
+
+ private CalibrationDataVM()
+ {
+ CalibrationPoints = new ObservableCollection<CalibrationDataPointVM>();
+ }
+
+ public CalibrationDataVM(IdsPack pack) : this()
+ {
+ IdsPack = pack;
+ LiquidType = pack.LiquidType;
+ }
+
+ public CalibrationDataVM(BL.Entities.LiquidType liquidType) : this()
+ {
+ LiquidType = liquidType;
+ CalibrationPoints = new ObservableCollection<CalibrationDataPointVM>();
+ //CalibrationPoints.Add(new CalibrationDataPointVM() { Index = 1, X = 2, Y = 22 });
+ }
+ }
+} \ No newline at end of file
diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ThreadExtensions/ViewModels/ColorCalibrationTabVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ThreadExtensions/ViewModels/ColorCalibrationTabVM.cs
new file mode 100644
index 000000000..103052b52
--- /dev/null
+++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ThreadExtensions/ViewModels/ColorCalibrationTabVM.cs
@@ -0,0 +1,323 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Tango.SharedUI;
+using Tango.MachineStudio.ThreadExtensions.Models;
+using Tango.BL.Enumerations;
+using Tango.Core.Commands;
+using Microsoft.Win32;
+using Tango.MachineStudio.Common.Notifications;
+using Tango.PMR.ColorLab;
+using Tango.ColorCalibration;
+using Tango.BL.ActionLogs;
+
+namespace Tango.MachineStudio.ThreadExtensions.ViewModels
+{
+ public class ColorCalibrationTabVM : ViewModel
+ {
+ private INotificationProvider _notification;
+ private IActionLogManager _actionLogManager;
+ private ILinearizationMeasurements _linearizationMeasurementscalibrator;
+
+ #region Properties
+
+ private string _name;
+ /// <summary>
+ /// Gets or sets the name of the thread. Using in print
+ /// </summary>
+ public string Name
+ {
+ get { return _name; }
+ set
+ {
+ _name = value;
+ RaisePropertyChangedAuto();
+ }
+ }
+
+ private int _tabIndex;
+
+ public int TabIndex
+ {
+ get { return _tabIndex; }
+ set { _tabIndex = value; }
+ }
+
+
+ private bool _isSelected;
+ /// <summary>
+ /// Gets or sets a value indicating whether this instance is selected.
+ /// </summary>
+ public bool IsSelected
+ {
+ get { return _isSelected; }
+ set { _isSelected = value; RaisePropertyChangedAuto(); }
+ }
+
+ private CalibrationPlotModel _cyanPlot;
+
+ public CalibrationPlotModel CyanPlot
+ {
+ get { return _cyanPlot; }
+ set
+ {
+ _cyanPlot = value;
+ RaisePropertyChangedAuto();
+ }
+ }
+
+ private CalibrationPlotModel _magentaPlot;
+
+ public CalibrationPlotModel MagentaPlot
+ {
+ get { return _magentaPlot; }
+ set { _magentaPlot = value; }
+ }
+
+ private CalibrationPlotModel _yellowPlot;
+
+ public CalibrationPlotModel YellowPlot
+ {
+ get { return _yellowPlot; }
+ set { _yellowPlot = value; }
+ }
+
+ private CalibrationPlotModel _blackPlot;
+
+ public CalibrationPlotModel BlackPlot
+ {
+ get { return _blackPlot; }
+ set { _blackPlot = value; }
+ }
+
+ private CalibrationDataVM _cyanCalibrationData;
+
+ public CalibrationDataVM CyanCalibrationData
+ {
+ get { return _cyanCalibrationData; }
+ set { _cyanCalibrationData = value; }
+ }
+
+ private CalibrationDataVM _magentaCalibrationData;
+
+ public CalibrationDataVM MagentaCalibrationData
+ {
+ get { return _magentaCalibrationData; }
+ set { _magentaCalibrationData = value; }
+ }
+
+ private CalibrationDataVM _yellowCalibrationData;
+
+ public CalibrationDataVM YellowCalibrationData
+ {
+ get { return _yellowCalibrationData; }
+ set { _yellowCalibrationData = value; }
+ }
+
+ private CalibrationDataVM _blackCalibrationData;
+
+ public CalibrationDataVM BlackCalibrationData
+ {
+ get { return _blackCalibrationData; }
+ set { _blackCalibrationData = value; RaisePropertyChangedAuto(); }
+ }
+
+
+ #endregion
+
+ #region Commands
+
+ public RelayCommand ImportCyanDataCommand { get; set; }
+ public RelayCommand ImportMagentaDataCommand { get; set; }
+ public RelayCommand ImportYellowDataCommand { get; set; }
+ public RelayCommand ImportBlackDataCommand { get; set; }
+
+ #endregion
+
+ public ColorCalibrationTabVM(INotificationProvider notification, IActionLogManager actionLogManager)
+ {
+ _notification = notification;
+ _actionLogManager = actionLogManager;
+ _linearizationMeasurementscalibrator = new DefaultColorCalibrator();
+
+ CyanPlot = new CalibrationPlotModel(FactorColors.CYAN, "Cyan");
+ YellowPlot = new CalibrationPlotModel(FactorColors.YELLOW, "Yellow");
+ MagentaPlot = new CalibrationPlotModel(FactorColors.MAGENTA, "Magenta");
+ BlackPlot = new CalibrationPlotModel(FactorColors.BLACK, "Black");
+
+ CyanCalibrationData = new CalibrationDataVM(new Tango.BL.Entities.LiquidType() { Code = (int)LiquidTypes.Cyan });
+ MagentaCalibrationData = new CalibrationDataVM(new Tango.BL.Entities.LiquidType() { Code = (int)LiquidTypes.Magenta });
+ YellowCalibrationData = new CalibrationDataVM(new Tango.BL.Entities.LiquidType() { Code = (int)LiquidTypes.Yellow });
+ BlackCalibrationData = new CalibrationDataVM(new Tango.BL.Entities.LiquidType() { Code = (int)LiquidTypes.Black });
+
+ ImportCyanDataCommand = new RelayCommand(ImportCyanData);
+ ImportMagentaDataCommand = new RelayCommand(ImportMagentaData);
+ ImportYellowDataCommand = new RelayCommand(ImportYellowData);
+ ImportBlackDataCommand = new RelayCommand(ImportBlackData);
+ }
+
+ #region Methods
+ private async void ImportCyanData(object obj)
+ {
+
+ List<ColorLinearizationModel.LinearizationDataItem> items;
+ if (ImportDataFromFile(out items) && items.Count > 0)
+ {
+ CyanPlot.InitDataGraph(items);
+
+ List<double> outputPoints = new List<double>();
+
+ await Task.Factory.StartNew(() =>
+ {
+ outputPoints = GetLinearizationMeasurements(items, PMR.ColorLab.LiquidType.Cyan);
+ });
+
+ CyanPlot.InitLinearizationGraph(items, outputPoints);
+ CyanCalibrationData.CalibrationPoints.Clear();
+ var index = 1;
+ foreach (var nw in items.Zip(outputPoints, Tuple.Create))
+ {
+ CyanCalibrationData.CalibrationPoints.Add(new CalibrationDataPointVM() { Index = index++, X = nw.Item1.InkPercentage, Y = nw.Item2 });
+ }
+ }
+
+ }
+
+ private async void ImportMagentaData(object obj)
+ {
+
+ List<ColorLinearizationModel.LinearizationDataItem> items;
+ if (ImportDataFromFile(out items) && items.Count > 0)
+ {
+ MagentaPlot.InitDataGraph(items);
+
+ List<double> outputPoints = new List<double>();
+
+ await Task.Factory.StartNew(() =>
+ {
+ outputPoints = GetLinearizationMeasurements(items, PMR.ColorLab.LiquidType.Magenta);
+ });
+
+ MagentaPlot.InitLinearizationGraph(items, outputPoints);
+ MagentaCalibrationData.CalibrationPoints.Clear();
+ var index = 1;
+ foreach (var nw in items.Zip(outputPoints, Tuple.Create))
+ {
+ MagentaCalibrationData.CalibrationPoints.Add(new CalibrationDataPointVM() { Index = index++, X = nw.Item1.InkPercentage, Y = nw.Item2});
+ }
+ }
+ }
+
+ private async void ImportYellowData(object obj)
+ {
+
+ List<ColorLinearizationModel.LinearizationDataItem> items;
+ if (ImportDataFromFile(out items) && items.Count > 0)
+ {
+ YellowPlot.InitDataGraph(items);
+
+ List<double> outputPoints = new List<double>();
+
+ await Task.Factory.StartNew(() =>
+ {
+ outputPoints = GetLinearizationMeasurements(items, PMR.ColorLab.LiquidType.Yellow);
+ });
+ YellowPlot.InitLinearizationGraph(items, outputPoints);
+ YellowCalibrationData.CalibrationPoints.Clear();
+ var index = 1;
+ foreach (var nw in items.Zip(outputPoints, Tuple.Create))
+ {
+ YellowCalibrationData.CalibrationPoints.Add(new CalibrationDataPointVM() { Index = index++, X = nw.Item1.InkPercentage, Y = nw.Item2 });
+ }
+ }
+ }
+
+
+ private async void ImportBlackData(object obj)
+ {
+
+ List<ColorLinearizationModel.LinearizationDataItem> items;
+ if (ImportDataFromFile(out items) && items.Count > 0)
+ {
+ BlackPlot.InitDataGraph(items);
+
+ List<double> outputPoints = new List<double>();
+
+ await Task.Factory.StartNew(() =>
+ {
+ outputPoints = GetLinearizationMeasurements(items, PMR.ColorLab.LiquidType.Black);
+ });
+ BlackPlot.InitLinearizationGraph(items, outputPoints);
+ BlackCalibrationData.CalibrationPoints.Clear();
+ var index = 1;
+ foreach (var nw in items.Zip(outputPoints, Tuple.Create))
+ {
+ BlackCalibrationData.CalibrationPoints.Add(new CalibrationDataPointVM() { Index = index++, X = nw.Item1.InkPercentage, Y = nw.Item2 });
+ }
+ }
+
+ }
+
+ /// <summary>
+ /// Open file dialog and get name of file
+ /// </summary>
+ /// <returns></returns>
+ private bool ImportDataFromFile(out List<ColorLinearizationModel.LinearizationDataItem> items)
+ {
+ OpenFileDialog dlg = new OpenFileDialog();
+ dlg.Title = "Select data file";
+ dlg.Filter = "Excel |*.xlsx";
+ items = null;
+ if (dlg.ShowDialogCenter() && dlg.FileName.IsNotNullOrEmpty())
+ {
+ ColorLinearizationModel model = new ColorLinearizationModel();
+ string errors = "";
+ model.GetDataFromFile(dlg.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 false;
+ }
+ return true;
+ }
+
+ return false;
+ }
+
+ #endregion
+
+ #region CreateLinearizationGraph
+
+ private List<double> GetLinearizationMeasurements(List<ColorLinearizationModel.LinearizationDataItem> items, PMR.ColorLab.LiquidType liquidType)
+ {
+ 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 = liquidType;
+
+ LinearizationOutput result = _linearizationMeasurementscalibrator.GetLinearizationMeasurements(linearizationInput);
+
+ if (!String.IsNullOrEmpty(result.ErrorMessage))
+ {
+ LogManager.Log(result.ErrorMessage, "GetLinearizationMeasurements returns error." + result.ErrorMessage);
+ InvokeUI(() =>
+ {
+ _notification.ShowError("Linearizion process failed. " + result.ErrorMessage);
+ });
+ }
+
+ return result.InkPercentage.ToList();
+ }
+ catch (Exception ex)
+ {
+ LogManager.Log(ex, "Error occurred while trying to call GetLinearizationMeasurements.");
+ }
+ return null;
+ }
+
+ #endregion
+ }
+}
diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ThreadExtensions/ViewModels/ColorCalibrationViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ThreadExtensions/ViewModels/ColorCalibrationViewVM.cs
new file mode 100644
index 000000000..99bb896d7
--- /dev/null
+++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ThreadExtensions/ViewModels/ColorCalibrationViewVM.cs
@@ -0,0 +1,467 @@
+
+using System;
+using System.Collections.Generic;
+using System.Collections.ObjectModel;
+using System.Collections.Specialized;
+using System.ComponentModel;
+using System.Linq;
+using System.Threading.Tasks;
+using Tango.BL;
+using Tango.BL.ActionLogs;
+using Tango.BL.Builders;
+using Tango.BL.Entities;
+using Tango.Core;
+using Tango.MachineStudio.Common.Notifications;
+using Tango.SharedUI;
+using Tango.AutoComplete.Editors;
+using Tango.MachineStudio.ThreadExtensions.Models;
+using Tango.Core.Commands;
+using Microsoft.Win32;
+using Tango.Logging;
+using Tango.BL.Enumerations;
+using Tango.PMR.ColorLab;
+using Tango.BL.Calibration;
+
+
+namespace Tango.MachineStudio.ThreadExtensions.ViewModels
+{
+ public class ColorCalibrationViewVM : ViewModel
+ {
+ private INotificationProvider _notification;
+ private IActionLogManager _actionLogManager;
+
+ private ObservablesContext _active_context;
+
+ public event EventHandler SaveColorCalibration;
+
+
+ #region Properties
+
+ private ObservableCollection<ColorCalibrationTabVM> _calibrationTabs;
+
+ public ObservableCollection<ColorCalibrationTabVM> CalibrationTabs
+ {
+ get { return _calibrationTabs; }
+ set { _calibrationTabs = value; }
+ }
+
+ private ColorCalibrationTabVM _selectedTab;
+
+ public ColorCalibrationTabVM SelectedTab
+ {
+ get { return _selectedTab; }
+ set
+ {
+ _selectedTab = value;
+ RaisePropertyChangedAuto();
+
+ foreach (var tab in _calibrationTabs.Where(x => x != _selectedTab))
+ {
+ tab.IsSelected = false;
+ }
+
+ if (_selectedTab != null)
+ {
+ _selectedTab.IsSelected = true;
+ }
+ }
+ }
+
+ private string _RMLExtentionGUID;
+
+ public string RMLExtemtionGUID
+ {
+ get { return _RMLExtentionGUID; }
+ set
+ {
+ _RMLExtentionGUID = value;
+ OnRMLExtensionGUIDChanged();
+ }
+ }
+
+ private string _RMLGUID;
+
+ public string RMLGUID
+ {
+ get { return _RMLGUID; }
+ set
+ {
+ _RMLGUID = value;
+ OnRMLExtensionGUIDChanged();
+ }
+ }
+
+ private Rml _activeRML;
+ public Rml ActiveRML
+ {
+ get { return _activeRML; }
+ set
+ {
+ _activeRML = value;
+ RaisePropertyChangedAuto();
+ }
+ }
+
+ private MachineModel _machine;
+ public MachineModel Machine
+ {
+ get { return _machine; }
+ set { _machine = value;
+ SelectedMachineChanged();
+ RaisePropertyChangedAuto();
+ InvalidateRelayCommands();
+ }
+ }
+
+
+ private bool _isViewLoaded;
+ /// <summary>
+ /// Gets or sets a value indicating whether this instance is view loaded. Used to update charts.
+ /// </summary>
+ public bool IsViewLoaded
+ {
+ get { return _isViewLoaded; }
+ set
+ {
+ if (_isViewLoaded != value)
+ {
+ _isViewLoaded = value;
+ }
+ }
+ }
+
+
+ #endregion
+
+ #region commands
+ public RelayCommand CreateColorDataImportExcelTemplateCommand { get; set; }
+ public RelayCommand ApplyToRMLCommand { get; set; }
+ public RelayCommand ApplyToMachineCalibrationCommand { get; set; }
+
+ public RelayCommand SaveCommand { get; set; }
+
+ public RelayCommand AddTabCommand { get; set; }
+
+ public RelayCommand<ColorCalibrationTabVM> RemoveTabCommand { get; set; }
+
+ public RelayCommand RenameTabCommand { get; set; }
+
+ #endregion
+
+ public ColorCalibrationViewVM(INotificationProvider notification, IActionLogManager actionLogManager)
+ {
+ _notification = notification;
+ _actionLogManager = actionLogManager;
+ CalibrationTabs = new ObservableCollection<ColorCalibrationTabVM>();
+
+ ApplyToRMLCommand = new RelayCommand(ApplyToRML);
+ ApplyToMachineCalibrationCommand = new RelayCommand(ApplyToMachineCalibration);
+ SaveCommand = new RelayCommand(Save, () => IsFree);
+
+ AddTabCommand = new RelayCommand(() => AddNewTab());
+ RemoveTabCommand = new RelayCommand<ColorCalibrationTabVM>(RemoveTab);
+ RenameTabCommand = new RelayCommand(RenameTab);
+
+ CreateColorDataImportExcelTemplateCommand = new RelayCommand(CreateColorDataImportExcelTemplate);
+ }
+
+
+
+ #region Methods
+
+ private void OnRMLExtensionGUIDChanged()
+ {
+ }
+
+ private void SelectedMachineChanged()
+ {
+ LoadColorCalibrations();
+ }
+
+ private void CreateColorDataImportExcelTemplate()
+ {
+ SaveFileDialog dlg = new SaveFileDialog();
+ try
+ {
+ dlg.Title = $"Create excel template file";
+ dlg.Filter = "Excel Files|*.xlsx";
+ dlg.DefaultExt = ".xlsx";
+ dlg.FileName = "Color Data File Template";
+ if (dlg.ShowDialog().Value)
+ {
+ CalibrationHelper.CreateColorDataInputExcelTemplate(dlg.FileName);
+ }
+ }
+ catch (Exception ex)
+ {
+ LogManager.Log(ex, "Error generating excel calibration template file " + dlg.FileName);
+ _notification.ShowError("An error occurred while trying to generate the calibration file.");
+ }
+ }
+ /// <summary>
+ /// Applies calibration points to RML.
+ /// </summary>
+ private void ApplyToRML(object obj)
+ {
+ if(SelectedTab != null && ActiveRML != null)
+ {
+ var liquidTypesRmls = ActiveRML.LiquidTypesRmls;
+ var calibrationDataVM = SelectedTab.CyanCalibrationData;
+ ApplayCalibrationDataToliquidTypesRml(liquidTypesRmls, LiquidTypes.Cyan, SelectedTab.CyanCalibrationData);
+ ApplayCalibrationDataToliquidTypesRml(liquidTypesRmls, LiquidTypes.Magenta, SelectedTab.MagentaCalibrationData);
+ ApplayCalibrationDataToliquidTypesRml(liquidTypesRmls, LiquidTypes.Yellow, SelectedTab.YellowCalibrationData);
+ ApplayCalibrationDataToliquidTypesRml(liquidTypesRmls, LiquidTypes.Black, SelectedTab.BlackCalibrationData);
+ Save();
+ }
+ }
+
+ private void ApplayCalibrationDataToliquidTypesRml(SynchronizedObservableCollection<LiquidTypesRml> liquidTypesRmls, LiquidTypes type, CalibrationDataVM calibrationDataVM)
+ {
+ if (calibrationDataVM.CalibrationPoints.Count == 0)
+ return;
+
+ var liquidTypeRml = liquidTypesRmls.SingleOrDefault(x => x.LiquidType.Type == type);
+ CalibrationData calData = new CalibrationData();
+ calData.LiquidType = (PMR.ColorLab.LiquidType)liquidTypeRml.LiquidType.Code;
+ calData.CalibrationPoints.Clear();
+ calData.CalibrationPoints.AddRange(calibrationDataVM.CalibrationPoints.Select(x => new CalibrationPoint() { X = x.X, Y = x.Y }));
+ liquidTypeRml.PutCalibrationData(calData);
+ }
+ /// <summary>
+ /// Applies calibration points to machine calibration.
+ /// </summary>
+ private void ApplyToMachineCalibration(object obj)
+ {
+ if (SelectedTab != null)
+ {
+ var idsPack = Machine.IdsPacks.
+ Where(x => ActiveRML.LiquidTypesRmls.ToList().Exists(y => x.LiquidType != null && y.LiquidType.Guid == x.LiquidType.Guid))
+ .OrderBy(x => x.PackIndex).ToList();
+
+ ApplayCalibrationDataToToMachineRml(idsPack, LiquidTypes.Cyan, SelectedTab.CyanCalibrationData);
+ ApplayCalibrationDataToToMachineRml(idsPack, LiquidTypes.Magenta, SelectedTab.MagentaCalibrationData);
+ ApplayCalibrationDataToToMachineRml(idsPack, LiquidTypes.Yellow, SelectedTab.YellowCalibrationData);
+ ApplayCalibrationDataToToMachineRml(idsPack, LiquidTypes.Black, SelectedTab.BlackCalibrationData);
+ Save();
+ }
+ }
+
+ private void ApplayCalibrationDataToToMachineRml(List<IdsPack> idsPacks, LiquidTypes type, CalibrationDataVM calibrationDataVM)
+ {
+ if (calibrationDataVM.CalibrationPoints.Count == 0)
+ return;
+
+ var idsPack = idsPacks.FirstOrDefault(x => x.LiquidType.Type == type);
+
+ if (idsPack != null)
+ {
+ var cat = idsPack.LiquidType.Cats.FirstOrDefault(x => x.MachineGuid == Machine.Guid && x.RmlGuid == ActiveRML.Guid); ;
+
+ if (cat == null)
+ {
+ cat = new Cat();
+ cat.Name = "untitled";
+ _active_context.Cats.Add(cat);
+ }
+
+ cat.RmlGuid = ActiveRML.Guid;
+ cat.MachineGuid = Machine.Guid;
+ cat.LiquidType = idsPack.LiquidType;
+
+ CalibrationData calData = new CalibrationData();
+ calData.LiquidType = (PMR.ColorLab.LiquidType)idsPack.LiquidType.Code;
+ calData.CalibrationPoints.AddRange(calibrationDataVM.CalibrationPoints.Select(x => new CalibrationPoint() { X = x.X, Y = x.Y }));
+
+ cat.PutCalibrationData(calData);
+ }
+ }
+
+ #endregion
+
+ #region Loading
+
+ public async void LoadColorCalibrations()
+ {
+ if (Machine == null)
+ {
+ _notification.ShowWarning(LogManager.Log($"Please, select machine.", LogCategory.Warning));
+ IsFree = false;
+ return;
+ }
+ if (ActiveRML == null)
+ {
+ IsFree = false;
+ return;
+ }
+ IsFree = false;
+ if (_active_context != null)
+ {
+ _active_context.Dispose();
+ }
+
+ _active_context = ObservablesContext.CreateDefault();
+
+ await Task.Factory.StartNew(() =>
+ {
+ using (_notification.PushTaskItem("Loading Color Calibrations Tests ..."))
+ {
+ }
+ });
+ if (CalibrationTabs.Count == 0)
+ {
+ SelectedTab = CreateNewColorCalibrationTabVM("Untitled", 1);
+ CalibrationTabs.Add(SelectedTab);
+ //_active_context.RmlExtensionCalibrationTests.Add(SelectedTab.TestResult);
+ // await _active_context.SaveChangesAsync();
+ }
+ //LoadColorCalibarions();
+ IsFree = true;
+ }
+
+ public void UpdatePlots()
+ {
+ if (IsViewLoaded)
+ {
+ //CyanPlot.CreateGraph(CyanProcessData.ToList(), true);
+ //MagentaPlot.CreateGraph(MagentaProcessData.ToList(), true);
+ //YellowPlot.CreateGraph(YellowProcessData.ToList(), false);
+ //BlackPlot.CreateGraph(BlackProcessData.ToList(), true);
+ }
+ }
+
+ private ColorCalibrationTabVM CreateNewColorCalibrationTabVM(string name, int index)
+ {
+ ColorCalibrationTabVM newtab = new ColorCalibrationTabVM(_notification, _actionLogManager) { Name = name , TabIndex = index};
+
+ return newtab;
+ }
+
+ #endregion
+
+ #region Tabs modification
+
+ /// <summary>
+ /// Removes the specified tab.
+ /// </summary>
+ /// <param name="tab">The tab.</param>
+ private void RemoveTab(ColorCalibrationTabVM tab)
+ {
+ if (CalibrationTabs.Count == 1)
+ return;
+ if (_notification.ShowQuestion("Are you sure you want to delete the selected tab?"))
+ {
+ // _active_context.RmlExtensionTestResults.Remove(tab.TestResult);
+
+ CalibrationTabs.Remove(tab);
+ SelectedTab = CalibrationTabs.LastOrDefault();
+ _active_context.SaveChanges();
+ }
+ }
+
+ /// <summary>
+ /// Adds a new tab.
+ /// </summary>
+ private bool AddNewTab(String name = null)
+ {
+ if (CalibrationTabs.Count > 7)
+ {
+ //_notification.ShowError("Cannot exceed the maximum number of 8 tabs. You can remove a tab, or create a new project.");
+ return false;
+ }
+
+ if (name == null)
+ {
+ name = _notification.ShowTextInput("Enter tab name", "Tab Name", "Test");
+ }
+
+ if (!String.IsNullOrWhiteSpace(name))
+ {
+ var tab = CreateNewColorCalibrationTabVM(name, (CalibrationTabs.Count + 1));
+ CalibrationTabs.Add(tab);
+ //_active_context.RmlExtensionTestResults.Add(tab.TestResult);
+ SelectedTab = tab;
+ return true;
+ }
+ else
+ {
+ return false;
+ }
+ }
+
+ /// <summary>
+ /// Renames the tab.
+ /// </summary>
+ /// <param name="tab">The tab.</param>
+ private void RenameTab()
+ {
+ if (SelectedTab != null)
+ {
+ var name = _notification.ShowTextInput("Enter tab name", "Tab Name", SelectedTab.Name);
+
+ if (!String.IsNullOrWhiteSpace(name))
+ {
+ SelectedTab.Name = name;
+ }
+ }
+ }
+
+ #endregion
+
+ #region Save
+
+ public async void Save()
+ {
+ if (Machine == null)
+ {
+ _notification.ShowWarning(LogManager.Log($"Could not save Color Calibrations. Please, select machine before save.", LogCategory.Warning));
+ return;
+ }
+
+ try
+ {
+ IsFree = false;
+
+ //SelectedColorProcessParameter.LastUpdated = DateTime.UtcNow;
+
+ //foreach (var item in RemovedColorProcessDataBeforeSave)
+ //{
+ // var existingColorProcessData = await _active_context.ColorProcessData.FirstOrDefaultAsync(y => y.Guid == item);
+ // if (existingColorProcessData != null)
+ // {
+ // _active_context.ColorProcessData.Remove(existingColorProcessData);
+ // }
+ //}
+ //foreach (var colordata in SelectedColorProcessParameter.ColorProcessData)
+ //{
+ // colordata.LastUpdated = DateTime.UtcNow;
+ //}
+ //foreach (var factordata in SelectedColorProcessParameter.ColorProcessFactors)
+ //{
+ // factordata.LastUpdated = DateTime.UtcNow;
+ //}
+ //foreach (var inkdata in SelectedColorProcessParameter.ColorProcessInkUptake)
+ //{
+ // inkdata.LastUpdated = DateTime.UtcNow;
+ //}
+
+ await _active_context.SaveChangesAsync();
+
+ // LoadColorParameters();
+ }
+ catch (Exception ex)
+ {
+ LogManager.Log(ex, "Could not update color calibrations.");
+ _notification.ShowError($"An error occurred while trying to save color calibrations.\n{ex.Message}");
+ }
+ finally
+ {
+ IsFree = true;
+ EventHandler handler = SaveColorCalibration;
+ handler?.Invoke(this, new EventArgs());
+ }
+ }
+
+ #endregion
+
+ }
+}
diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ThreadExtensions/ViewModels/MainViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ThreadExtensions/ViewModels/MainViewVM.cs
index 4802e0af1..e8aafca9d 100644
--- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ThreadExtensions/ViewModels/MainViewVM.cs
+++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ThreadExtensions/ViewModels/MainViewVM.cs
@@ -257,6 +257,13 @@ namespace Tango.MachineStudio.ThreadExtensions.ViewModels
set { _testResultsViewVM = value; RaisePropertyChangedAuto(); }
}
+ private ColorCalibrationViewVM _colorCalibrationViewVM;
+ public ColorCalibrationViewVM ColorCalibrationViewVM
+ {
+ get { return _colorCalibrationViewVM; }
+ set { _colorCalibrationViewVM = value; RaisePropertyChangedAuto(); }
+ }
+
protected MachineModel _selectedMachine;
/// <summary>
/// Gets or sets the selected machine.
@@ -294,20 +301,20 @@ namespace Tango.MachineStudio.ThreadExtensions.ViewModels
}
- private MachineTestResultsTabs PreviosSelectedTab { get; set; }
+ //private MachineTestResultsTabs PreviosSelectedTab { get; set; }
- private MachineTestResultsTabs _selectedTab;
+ //private MachineTestResultsTabs _selectedTab;
- public MachineTestResultsTabs SelectedTab
- {
- get { return _selectedTab; }
- set {
- PreviosSelectedTab = _selectedTab;
- _selectedTab = value;
- OnSelectedMachineTestResultsTabChanged();
- RaisePropertyChangedAuto();
- }
- }
+ //public MachineTestResultsTabs SelectedTab
+ //{
+ // get { return _selectedTab; }
+ // set {
+ // PreviosSelectedTab = _selectedTab;
+ // _selectedTab = value;
+ // OnSelectedMachineTestResultsTabChanged();
+ // RaisePropertyChangedAuto();
+ // }
+ //}
#endregion
@@ -922,7 +929,8 @@ namespace Tango.MachineStudio.ThreadExtensions.ViewModels
{
Guid = x.Guid,
Name = x.Name,
- SerialNumber = x.SerialNumber
+ SerialNumber = x.SerialNumber,
+ IdsPacks = x.Configuration.IdsPacks.Where(z => !z.IsEmpty)
}).ToObservableCollection();
}
@@ -994,9 +1002,7 @@ namespace Tango.MachineStudio.ThreadExtensions.ViewModels
.WithUser()
.BuildAsync();
- ActiveRML = new RmlBuilder(_active_context)
- .Set(SelectedRMLExtension.RMLGuid)
- .Build();
+ ActiveRML = new RmlBuilder(_active_context).Set(SelectedRMLExtension.RMLGuid).WithLiquidFactors().Build();
if (!String.IsNullOrEmpty(ActiveRML.Manufacturer) && false == Manufacturers.Any(x => x == ActiveRML.Manufacturer))
{
@@ -1040,12 +1046,23 @@ namespace Tango.MachineStudio.ThreadExtensions.ViewModels
TestResultsViewVM.SelectedMachineGUID = SelectedMachine != null ? SelectedMachine.Guid : null;
TestResultsViewVM.ThreadName = ActiveRML.Manufacturer;
+ ColorCalibrationViewVM = new ColorCalibrationViewVM(_notification, _actionLogManager);
+ ColorCalibrationViewVM.RMLExtemtionGUID = guid;
+ ColorCalibrationViewVM.ActiveRML = ActiveRML;
+ ColorCalibrationViewVM.RMLGUID = ActiveRML.Guid;
+ ColorCalibrationViewVM.Machine = SelectedMachine;
+
+
+
+
if (ActiveRMLExtension.RMLStatus == RMLExtensionStatus.New)
{
ColorParametersVewVM.SaveColorParameters -= UpdateStatus;
ColorParametersVewVM.SaveColorParameters += UpdateStatus;
TestResultsViewVM.SaveTestResults -= UpdateStatus;
TestResultsViewVM.SaveTestResults += UpdateStatus;
+ ColorCalibrationViewVM.SaveColorCalibration -= UpdateStatus;
+ ColorCalibrationViewVM.SaveColorCalibration += UpdateStatus;
}
View.NavigateTo(RMLExtensionNavigationView.RMLExtentionView);
@@ -1108,6 +1125,7 @@ namespace Tango.MachineStudio.ThreadExtensions.ViewModels
{
ColorParametersVewVM.SaveColorParameters -= UpdateStatus;
TestResultsViewVM.SaveTestResults -= UpdateStatus;
+ ColorCalibrationViewVM.SaveColorCalibration -= UpdateStatus;
ActiveRMLExtension.RMLStatus = RMLExtensionStatus.InProgress;
ActiveRMLExtension.LastUpdated = DateTime.UtcNow;
@@ -1134,6 +1152,10 @@ namespace Tango.MachineStudio.ThreadExtensions.ViewModels
{
TestResultsViewVM.SelectedMachineGUID = SelectedMachine.Guid;
}
+ if(ColorCalibrationViewVM != null)
+ {
+ ColorCalibrationViewVM.Machine = SelectedMachine;
+ }
}
#endregion
@@ -1183,10 +1205,10 @@ namespace Tango.MachineStudio.ThreadExtensions.ViewModels
#region selections
- private void OnSelectedMachineTestResultsTabChanged()
- {
- if(SelectedTab == MachineTestResultsTabs.ColorParameters)
- {
+ //private void OnSelectedMachineTestResultsTabChanged()
+ // {
+ //if(SelectedTab == MachineTestResultsTabs.ColorParameters)
+ // {
//if(PreviosSelectedTab == MachineTestResultsTabs.TestResults && TestResultsViewVM != null)
//{
// TestResultsViewVM.Save();
@@ -1194,15 +1216,15 @@ namespace Tango.MachineStudio.ThreadExtensions.ViewModels
//save
//if (_notification.ShowQuestion("Are you sure you want to exit this page without saving changes?"))
- }
- else if(SelectedTab == MachineTestResultsTabs.TestResults)
- {
+ // }
+ // else if(SelectedTab == MachineTestResultsTabs.TestResults)
+ // {
//if (PreviosSelectedTab == MachineTestResultsTabs.ColorParameters && ColorParametersVewVM != null)
//{
// ColorParametersVewVM.Save();
//}
- }
- }
+ //}
+ // }
#endregion
@@ -1304,6 +1326,7 @@ namespace Tango.MachineStudio.ThreadExtensions.ViewModels
colorParametrsExcelList.Add(colorParametrsExcelModel);
TestResultsViewVM.LoadTestResultsExcel(testResultsExcelModelList, machine.Guid, machine.SerialNumber);
+ //ColorCalibrationViewVM.WritetoExcel
}
}