aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels
diff options
context:
space:
mode:
authorAvi Levkovich <avi@twine-s.com>2019-09-18 10:29:59 +0300
committerAvi Levkovich <avi@twine-s.com>2019-09-18 10:29:59 +0300
commit1aa9206775dbc3ffe196c58f6c6055f0aec96470 (patch)
treef2af3a50e63acc33b7cceb86103cab6498e5401b /Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels
parentbbc47180c532430835c90c043f5e313420b776a6 (diff)
parent22aea2d70ade546a64f2339e06ea1bcb7c10b699 (diff)
downloadTango-1aa9206775dbc3ffe196c58f6c6055f0aec96470.tar.gz
Tango-1aa9206775dbc3ffe196c58f6c6055f0aec96470.zip
Merge branch 'master' of https://twinetfs.visualstudio.com/_git/Tango
Diffstat (limited to 'Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels')
-rw-r--r--Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels/CalibrationDataPointVM.cs64
-rw-r--r--Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels/CalibrationDataVM.cs83
-rw-r--r--Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels/CalibrationDataViewVM.cs110
-rw-r--r--Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels/ColorConversionViewVM.cs396
-rw-r--r--Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels/LiquidVolumeVM.cs51
-rw-r--r--Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels/MainViewVM.cs41
-rw-r--r--Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels/RgbVM.cs148
7 files changed, 891 insertions, 2 deletions
diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels/CalibrationDataPointVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels/CalibrationDataPointVM.cs
new file mode 100644
index 000000000..4ad06c7ed
--- /dev/null
+++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels/CalibrationDataPointVM.cs
@@ -0,0 +1,64 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Tango.Core;
+using Tango.PMR.ColorLab;
+using Tango.SharedUI;
+
+namespace Tango.MachineStudio.RML.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,
+ };
+ }
+ }
+}
diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels/CalibrationDataVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels/CalibrationDataVM.cs
new file mode 100644
index 000000000..403494a8e
--- /dev/null
+++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels/CalibrationDataVM.cs
@@ -0,0 +1,83 @@
+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.SharedUI;
+
+namespace Tango.MachineStudio.RML.ViewModels
+{
+ public class CalibrationDataVM : ExtendedObject
+ {
+ private LiquidType _liquidType;
+
+ public 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(LiquidType liquidType) : this()
+ {
+ LiquidType = liquidType;
+ }
+ }
+}
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
new file mode 100644
index 000000000..b34ef83bc
--- /dev/null
+++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels/CalibrationDataViewVM.cs
@@ -0,0 +1,110 @@
+using Microsoft.Win32;
+using System;
+using System.Collections.Generic;
+using System.Collections.ObjectModel;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Tango.BL.Calibration;
+using Tango.Core.Commands;
+using Tango.MachineStudio.Common;
+using Tango.MachineStudio.Common.Notifications;
+using Tango.SharedUI;
+
+namespace Tango.MachineStudio.RML.ViewModels
+{
+ public class CalibrationDataViewVM : ViewModel
+ {
+ private INotificationProvider _notification;
+
+ private ObservableCollection<CalibrationDataVM> _liquidsCalibrationData;
+ /// <summary>
+ /// Gets or sets the liquids calibration data.
+ /// </summary>
+ public ObservableCollection<CalibrationDataVM> LiquidsCalibrationData
+ {
+ get { return _liquidsCalibrationData; }
+ set { _liquidsCalibrationData = value; RaisePropertyChangedAuto(); }
+ }
+
+ /// <summary>
+ /// Gets or sets the import excel command.
+ /// </summary>
+ public RelayCommand<CalibrationDataVM> ImportExcelCommand { get; set; }
+
+ /// <summary>
+ /// Gets or sets the export excel command.
+ /// </summary>
+ public RelayCommand<CalibrationDataVM> ExportExcelCommand { get; set; }
+
+ /// <summary>
+ /// Initializes a new instance of the <see cref="CalibrationDataViewVM"/> class.
+ /// </summary>
+ public CalibrationDataViewVM(INotificationProvider notificationProvider)
+ {
+ _notification = notificationProvider;
+
+ LiquidsCalibrationData = new ObservableCollection<CalibrationDataVM>();
+
+ ImportExcelCommand = new RelayCommand<CalibrationDataVM>(ImportExcel);
+ ExportExcelCommand = new RelayCommand<CalibrationDataVM>(ExportExcel);
+ }
+
+ /// <summary>
+ /// Initializes a new instance of the <see cref="CalibrationDataViewVM"/> class.
+ /// </summary>
+ /// <param name="liquidsCalibrationData">The liquids calibration data.</param>
+ public CalibrationDataViewVM(INotificationProvider notificationProvider, ObservableCollection<CalibrationDataVM> liquidsCalibrationData) : this(notificationProvider)
+ {
+ LiquidsCalibrationData = liquidsCalibrationData;
+ }
+
+ private void ImportExcel(CalibrationDataVM vm)
+ {
+ OpenFileDialog dlg = new OpenFileDialog();
+
+ try
+ {
+ dlg.Title = $"Import excel calibration file for {vm.LiquidType.Name}";
+ dlg.Filter = "Excel Files|*.xlsx";
+ if (dlg.ShowDialog().Value)
+ {
+ vm.CalibrationPoints.Clear();
+ var points = CalibrationHelper.ImportCalibrationDataFromExcel(dlg.FileName);
+
+ foreach (var p in points)
+ {
+ vm.CalibrationPoints.Add(new CalibrationDataPointVM(p));
+ }
+ }
+ }
+ 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.");
+ }
+ }
+
+ private void ExportExcel(CalibrationDataVM vm)
+ {
+ SaveFileDialog dlg = new SaveFileDialog();
+ try
+ {
+ dlg.Title = $"Export excel calibration file for {vm.LiquidType.Name}";
+ dlg.Filter = "Excel Files|*.xlsx";
+ dlg.DefaultExt = ".xlsx";
+ dlg.FileName = $"CData_{vm.LiquidType.Name}_v{vm.LiquidType.Version}.xlsx";
+ if (dlg.ShowDialog().Value)
+ {
+ var points = vm.CalibrationPoints.Select(x => x.ToPMR()).ToList();
+ 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.");
+ }
+ }
+ }
+}
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
new file mode 100644
index 000000000..2624c9b7d
--- /dev/null
+++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels/ColorConversionViewVM.cs
@@ -0,0 +1,396 @@
+using Google.Protobuf;
+using System;
+using System.Collections.Generic;
+using System.Collections.ObjectModel;
+using System.Data.Entity;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Media;
+using Tango.BL;
+using Tango.BL.Entities;
+using Tango.BL.Enumerations;
+using Tango.ColorConversion;
+using Tango.MachineStudio.Common;
+using Tango.MachineStudio.Common.Notifications;
+using Tango.MachineStudio.RML.Models;
+using Tango.PMR.ColorLab;
+using Tango.SharedUI;
+
+namespace Tango.MachineStudio.RML.ViewModels
+{
+ public class ColorConversionViewVM: ViewModel
+ {
+ #region properties
+
+ private INotificationProvider _notification;
+ private bool _prevent_inverse_conversion;
+
+ private bool _isVolumesOutOfRange;
+ /// <summary>
+ /// Gets or sets a value indicating whether the liquid volumes are out of range.
+ /// </summary>
+ public bool IsVolumesOutOfRange
+ {
+ get { return _isVolumesOutOfRange; }
+ set
+ {
+ if (_isVolumesOutOfRange != value)
+ {
+ _isVolumesOutOfRange = value;
+ RaisePropertyChangedAuto();
+ }
+ }
+ }
+
+ private bool _isOutOfGamut;
+ /// <summary>
+ /// Gets or sets a value indicating whether the source color is out of gamut.
+ /// </summary>
+ public bool IsOutOfGamut
+ {
+ get { return _isOutOfGamut; }
+ set { _isOutOfGamut = value; RaisePropertyChangedAuto(); }
+ }
+
+ private Rml _rml;
+ public Rml RML
+ {
+ get { return _rml; }
+ set { _rml = value; RaisePropertyChangedAuto(); }
+ }
+
+ private List<ColorConversionSuggestion> _hiveSuggestions;
+ /// <summary>
+ /// Gets or sets the hive suggestions.
+ /// </summary>
+ public List<ColorConversionSuggestion> HiveSuggestions
+ {
+ get { return _hiveSuggestions; }
+ set { _hiveSuggestions = value; RaisePropertyChangedAuto(); }
+ }
+
+ private ColorConversionSuggestion _selectedSuggestion;
+ /// <summary>
+ /// Gets or sets the selected suggestion.
+ /// </summary>
+ public ColorConversionSuggestion SelectedSuggestion
+ {
+ get { return _selectedSuggestion; }
+ set { _selectedSuggestion = value; RaisePropertyChangedAuto(); OnSelectedSuggestionChanged(); }
+ }
+
+ private ObservableCollection<LiquidTypesRml> _liquidTypesRmls;
+ /// <summary>
+ /// Gets or sets the liquid types RMLS.
+ /// </summary>
+ public ObservableCollection<LiquidTypesRml> LiquidTypesRmls
+ {
+ get { return _liquidTypesRmls; }
+ set { _liquidTypesRmls = value; RaisePropertyChangedAuto(); OnLiquidTypesRmlsChanged(); }
+ }
+
+ private void OnLiquidTypesRmlsChanged()
+ {
+ if (LiquidTypesRmls != null)
+ {
+ LiquidTypesRmls.CollectionChanged += LiquidTypesRmls_CollectionChanged;
+ InvalidateLiquidVolumes();
+ }
+ }
+
+ private void LiquidTypesRmls_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
+ {
+ InvalidateLiquidVolumes();
+ }
+
+ private void InvalidateLiquidVolumes()
+ {
+ LiquidVolumes = LiquidTypesRmls.Where(x => x.LiquidType.HasPigment).Select(x => new LiquidVolumeVM()
+ {
+ Color = x.LiquidType.Color,
+ Name = x.LiquidType.Name,
+ LiquidType = x.LiquidType,
+ }).ToObservableCollection();
+ }
+
+ private ObservableCollection<LiquidVolumeVM> _liquidVolumes;
+ /// <summary>
+ /// Gets or sets the liquid volumes.
+ /// </summary>
+ public ObservableCollection<LiquidVolumeVM> LiquidVolumes
+ {
+ get { return _liquidVolumes; }
+ set { _liquidVolumes = value; RaisePropertyChangedAuto(); OnLiquidsVolumesChanged(); }
+ }
+
+ private ObservableCollection<CalibrationDataVM> _liquidsCalibrationData;
+ /// <summary>
+ /// Gets or sets the liquids calibration data.
+ /// </summary>
+ public ObservableCollection<CalibrationDataVM> LiquidsCalibrationData
+ {
+ get { return _liquidsCalibrationData; }
+ set { _liquidsCalibrationData = value; RaisePropertyChangedAuto(); }
+ }
+
+ private CctModel _cct;
+ public CctModel CCT
+ {
+ get { return _cct; }
+ set
+ {
+ _cct = value;
+ RaisePropertyChangedAuto();
+ InvalidateRelayCommands();
+ }
+ }
+
+ private RgbVM _sourceColor;
+ /// <summary>
+ /// Gets or sets the color of the source.
+ /// </summary>
+ public RgbVM SourceColor
+ {
+ get { return _sourceColor; }
+ set { _sourceColor = value; RaisePropertyChangedAuto(); }
+ }
+
+ private RgbVM _targetColor;
+ /// <summary>
+ /// Gets or sets the color of the target.
+ /// </summary>
+ /// <value>
+ /// The color of the target.
+ /// </value>
+ public RgbVM TargetColor
+ {
+ get { return _targetColor; }
+ set { _targetColor = value; RaisePropertyChangedAuto(); }
+ }
+
+ #endregion
+
+ public ColorConversionViewVM(INotificationProvider notification)
+ {
+ _notification = notification;
+
+ // CCT = new Cct();
+
+ SourceColor = new RgbVM();
+ SourceColor.ColorChanged += SourceColor_ColorChanged;
+ }
+
+ private void OnLiquidsVolumesChanged()
+ {
+ LiquidVolumes.EnableCrossThreadOperations();
+ LiquidVolumes.ToList().ForEach(x => x.VolumeChanged += (s, e) => OnLiquidVolumeChanged());
+ }
+
+ private void SourceColor_ColorChanged(object sender, Color e)
+ {
+ GetHiveSuggestions();
+ }
+
+ private void GetHiveSuggestions()
+ {
+ Task.Factory.StartNew(() =>
+ {
+ try
+ {
+ if (RML == null || LiquidsCalibrationData == null || CCT == null || CCT.Data == null) return;
+
+ ConversionInput input = new ConversionInput();
+ input.ColorSpace = SourceColor.IsLab ? PMR.ColorLab.ColorSpace.Lab : PMR.ColorLab.ColorSpace.Rgb;
+ //input.DeltaChroma = DeltaChroma;
+ //input.DeltaL = DeltaL;
+ input.ForwardData = ByteString.CopyFrom(CCT.Data);
+
+ input.InputCoordinates = new InputCoordinates();
+ input.InputCoordinates.Red = (int)SourceColor.Red;
+ input.InputCoordinates.Green = (int)SourceColor.Green;
+ input.InputCoordinates.Blue = (int)SourceColor.Blue;
+
+ input.InputCoordinates.L = SourceColor.L;
+ input.InputCoordinates.A = SourceColor.A;
+ input.InputCoordinates.B = SourceColor.B;
+
+ input.ThreadL = RML.WhitePointL;
+ input.ThreadA = RML.WhitePointA;
+ input.ThreadB = RML.WhitePointB;
+
+ //Validate calibration data
+ foreach (var vm in LiquidsCalibrationData.Where(x => x.LiquidType.HasPigment))
+ {
+ if (vm.CalibrationPoints.Count == 0)
+ {
+ InvokeUI(() =>
+ {
+ _notification.ShowError($"No calibration data for liquid '{vm.LiquidType.Name}'. Could not convert source color.");
+ });
+ return;
+ }
+ else if (!(vm.CalibrationPoints.First().X == 0 && vm.CalibrationPoints.First().Y == 0 && vm.CalibrationPoints.Last().X == 100 && vm.CalibrationPoints.Last().Y == 100))
+ {
+ InvokeUI(() =>
+ {
+ _notification.ShowError($"Invalid calibration data for liquid '{vm.LiquidType.Name}'. Could not convert source color.");
+ });
+ return;
+ }
+ }
+
+ foreach (var vm in LiquidsCalibrationData)
+ {
+ InputLiquid inputLiquid = new InputLiquid();
+
+
+ CalibrationData calData = new CalibrationData();
+ calData.LiquidType = (PMR.ColorLab.LiquidType)vm.LiquidType.Code;
+ calData.CalibrationPoints.AddRange(vm.CalibrationPoints.Select(x => new CalibrationPoint() { X = x.X, Y = x.Y }));
+
+ inputLiquid.CalibrationData = calData;
+
+ inputLiquid.LiquidType = (PMR.ColorLab.LiquidType)vm.LiquidType.Code;
+ inputLiquid.MaxNanoliterPerCentimeter = LiquidTypesRmls.SingleOrDefault(x => x.LiquidType.Code == vm.LiquidType.Code).MaxNlPerCm;
+
+ input.InputCoordinates.InputLiquids.Add(inputLiquid);
+ }
+
+ foreach (var process in RML.GetActiveProcessGroup().ProcessParametersTables)
+ {
+ input.ProcessRanges.Add(new ProcessRange()
+ {
+ MinInkUptake = process.MinInkUptake,
+ MaxInkUptake = process.MaxInkUptake,
+ });
+ }
+
+ IColorConverter converter = new DefaultColorConverter();
+
+ var output = converter.Convert(input);
+
+ IsOutOfGamut = output.OutOfGamut;
+
+ HiveSuggestions = output.CreateHiveSuggestions();
+ }
+ catch (Exception ex)
+ {
+ LogManager.Log(ex, "An error occurred while trying to convert from source color to Volume.");
+
+ InvokeUI(() =>
+ {
+ _notification.ShowError($"An error occurred while trying to convert from source color to Volume.\n" + ex.Message);
+ });
+ }
+ });
+ }
+
+ private void OnSelectedSuggestionChanged()
+ {
+ if (SelectedSuggestion != null)
+ {
+ _prevent_inverse_conversion = true;
+
+ var coords = SelectedSuggestion.Coordinates;
+
+ foreach (var liquid in coords.OutputLiquids)
+ {
+ var liquidVolume = LiquidVolumes.SingleOrDefault(x => x.LiquidType.Code == liquid.LiquidType.ToInt32());
+
+ if (liquidVolume != null)
+ {
+ liquidVolume.Volume = liquid.Volume;
+ }
+ }
+
+ _prevent_inverse_conversion = false;
+
+ OnLiquidVolumeChanged();
+ }
+ }
+
+ private void OnLiquidVolumeChanged()
+ {
+ try
+ {
+ if (LiquidsCalibrationData == null || _prevent_inverse_conversion) return;
+
+ //TODO: This is temporary because of out of range volumes.
+ if (LiquidVolumes.Where(x => x.LiquidType.HasPigment).Sum(x => x.Volume) > 200)
+ {
+ IsVolumesOutOfRange = true;
+ return;
+ }
+ else
+ {
+ IsVolumesOutOfRange = false;
+ }
+
+ ConversionInput input = new ConversionInput();
+ input.ColorSpace = PMR.ColorLab.ColorSpace.Volume;
+ input.ForwardData = ByteString.CopyFrom(CCT.Data);
+
+ input.InputCoordinates = new InputCoordinates();
+ input.ThreadL = RML.WhitePointL;
+ input.ThreadA = RML.WhitePointA;
+ input.ThreadB = RML.WhitePointB;
+
+ foreach (var vm in LiquidsCalibrationData.Where(x => x.LiquidType.HasPigment))
+ {
+ InputLiquid inputLiquid = new InputLiquid();
+
+ CalibrationData calData = new CalibrationData();
+ calData.LiquidType = (PMR.ColorLab.LiquidType)vm.LiquidType.Code;
+ calData.CalibrationPoints.AddRange(vm.CalibrationPoints.Select(x => new CalibrationPoint() { X = x.X, Y = x.Y }));
+
+ inputLiquid.CalibrationData = calData;
+
+ inputLiquid.LiquidType = (PMR.ColorLab.LiquidType)vm.LiquidType.Code;
+ inputLiquid.MaxNanoliterPerCentimeter = LiquidTypesRmls.SingleOrDefault(x => x.LiquidType.Code == vm.LiquidType.Code).MaxNlPerCm;
+ inputLiquid.Volume = LiquidVolumes.SingleOrDefault(x => x.LiquidType == vm.LiquidType).Volume;
+
+ input.InputCoordinates.InputLiquids.Add(inputLiquid);
+ }
+
+ foreach (var process in RML.ProcessParametersTablesGroups.Single().ProcessParametersTables)
+ {
+ input.ProcessRanges.Add(new ProcessRange()
+ {
+ MinInkUptake = process.MinInkUptake,
+ MaxInkUptake = process.MaxInkUptake,
+ });
+ }
+
+ IColorConverter converter = new DefaultColorConverter();
+
+ var output = converter.Convert(input);
+
+ if (SourceColor.IsLab)
+ {
+ TargetColor = new RgbVM()
+ {
+ IsLab = true,
+ L = output.SingleCoordinates.L,
+ A = output.SingleCoordinates.A,
+ B = output.SingleCoordinates.B,
+ };
+ }
+ else
+ {
+ TargetColor = new RgbVM()
+ {
+ Red = output.SingleCoordinates.Red,
+ Green = output.SingleCoordinates.Green,
+ Blue = output.SingleCoordinates.Blue,
+ };
+ }
+ }
+ catch (Exception ex)
+ {
+ LogManager.Log(ex, "Error in inversed color conversion!");
+ _notification.ShowError("An error occurred while trying to convert from Volume to RGB.\n" + ex.Message);
+ }
+ }
+ }
+}
diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels/LiquidVolumeVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels/LiquidVolumeVM.cs
new file mode 100644
index 000000000..7399d62af
--- /dev/null
+++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels/LiquidVolumeVM.cs
@@ -0,0 +1,51 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Tango.BL.Entities;
+using Tango.Core;
+using Tango.SharedUI;
+
+namespace Tango.MachineStudio.RML.ViewModels
+{
+ public class LiquidVolumeVM : ExtendedObject
+ {
+ public event EventHandler<double> VolumeChanged;
+
+ private String _name;
+
+ public String Name
+ {
+ get { return _name; }
+ set { _name = value; RaisePropertyChangedAuto(); }
+ }
+
+ private double _volume;
+
+ public double Volume
+ {
+ get { return _volume; }
+ set
+ {
+ _volume = value; RaisePropertyChangedAuto();
+ VolumeChanged?.Invoke(this, _volume);
+ }
+ }
+
+ private int _color;
+
+ public int Color
+ {
+ get { return _color; }
+ set { _color = value; RaisePropertyChangedAuto(); }
+ }
+
+ private LiquidType _liquidType;
+ public LiquidType LiquidType
+ {
+ get { return _liquidType; }
+ set { _liquidType = value; RaisePropertyChangedAuto(); }
+ }
+ }
+}
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 aa84fb137..361608ef6 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
@@ -13,13 +13,13 @@ using Tango.BL.Builders;
using Tango.BL.Calibration;
using Tango.BL.Entities;
using Tango.Core.Commands;
-using Tango.MachineStudio.ColorLab.ViewModels;
using Tango.MachineStudio.Common;
using Tango.MachineStudio.Common.Notifications;
using Tango.MachineStudio.RML.Contracts;
using Tango.MachineStudio.RML.Models;
using Tango.MachineStudio.RML.Views;
using Tango.PMR.ColorLab;
+using System.Data.Entity;
namespace Tango.MachineStudio.RML.ViewModels
{
@@ -132,7 +132,14 @@ namespace Tango.MachineStudio.RML.ViewModels
public CctModel SelectedCCT
{
get { return _selectedCCT; }
- set { _selectedCCT = value; RaisePropertyChangedAuto(); InvalidateRelayCommands(); }
+ set { _selectedCCT = value; RaisePropertyChangedAuto(); OnSelectedCCTChanged(); InvalidateRelayCommands(); }
+ }
+
+ private ColorConversionViewVM _colorConversionViewVM;
+ public ColorConversionViewVM ColorConversionViewVM
+ {
+ get { return _colorConversionViewVM; }
+ set { _colorConversionViewVM = value; RaisePropertyChangedAuto(); }
}
/// <summary>
@@ -287,6 +294,13 @@ namespace Tango.MachineStudio.RML.ViewModels
CalibrationDataViewVM.LiquidsCalibrationData.Add(catVM);
}
+ ColorConversionViewVM = new ColorConversionViewVM(_notification)
+ {
+ RML = ActiveRML,
+ CCT = SelectedCCT,
+ LiquidsCalibrationData = CalibrationDataViewVM.LiquidsCalibrationData,
+ LiquidTypesRmls = LiquidTypesRmls,
+ };
View.NavigateTo(RmlNavigationView.RmlView);
@@ -296,6 +310,27 @@ namespace Tango.MachineStudio.RML.ViewModels
}
}
+ private async void OnSelectedCCTChanged()
+ {
+ if (SelectedCCT != null && !SelectedCCT.IsNew)
+ {
+ using (_notification.PushTaskItem("Loading CCT data..."))
+ {
+ IsFree = false;
+
+ var cct = await _active_context.Ccts.SingleOrDefaultAsync(x => x.Guid == SelectedCCT.Guid);
+
+ if (cct != null)
+ {
+ SelectedCCT.Data = cct.Data;
+ ColorConversionViewVM.CCT = SelectedCCT;
+ }
+
+ IsFree = true;
+ }
+ }
+ }
+
private void LoadRmlProperties()
{
Materials = _active_context.MediaMaterials.ToObservableCollection();
@@ -566,6 +601,8 @@ namespace Tango.MachineStudio.RML.ViewModels
CCTS.Insert(0, cctModel);
SelectedCCT = cctModel;
+
+ ColorConversionViewVM.CCT = SelectedCCT;
}
}
diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels/RgbVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels/RgbVM.cs
new file mode 100644
index 000000000..e64592aae
--- /dev/null
+++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels/RgbVM.cs
@@ -0,0 +1,148 @@
+using ColorMine.ColorSpaces;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Media;
+using System.Windows.Threading;
+using Tango.Core;
+using Tango.SharedUI;
+
+namespace Tango.MachineStudio.RML.ViewModels
+{
+ public class RgbVM : ExtendedObject
+ {
+ private DispatcherTimer _color_change_timer;
+
+ public event EventHandler<Color> ColorChanged;
+
+ public RgbVM()
+ {
+ _color_change_timer = new DispatcherTimer();
+ _color_change_timer.Interval = TimeSpan.FromMilliseconds(30);
+ _color_change_timer.Tick += _color_change_timer_Tick;
+ _color_change_timer.Stop();
+
+ Color = Colors.DimGray;
+ }
+
+ private void _color_change_timer_Tick(object sender, EventArgs e)
+ {
+ _color_change_timer.Stop();
+ ColorChanged?.Invoke(this, Color);
+ }
+
+ private double _red;
+ public double Red
+ {
+ get { return _red; }
+ set { _red = value; SynchronizeColor(); RaisePropertyChangedAuto(); }
+ }
+
+ private double _green;
+ public double Green
+ {
+ get { return _green; }
+ set { _green = value; SynchronizeColor(); RaisePropertyChangedAuto(); }
+ }
+
+ private double _blue;
+ public double Blue
+ {
+ get { return _blue; }
+ set { _blue = value; SynchronizeColor(); RaisePropertyChangedAuto(); }
+ }
+
+ private double _l;
+ public double L
+ {
+ get { return _l; }
+ set { _l = value; SynchronizeColor(); RaisePropertyChangedAuto(); }
+ }
+
+ private double _a;
+ public double A
+ {
+ get { return _a; }
+ set { _a = value; SynchronizeColor(); RaisePropertyChangedAuto(); }
+ }
+
+ private double _b;
+ public double B
+ {
+ get { return _b; }
+ set { _b = value; SynchronizeColor(); RaisePropertyChangedAuto(); }
+ }
+
+ private Color _color;
+ public Color Color
+ {
+ get { return _color; }
+ set { _color = value; RaisePropertyChanged(nameof(Color)); SynchronizeComponents(); }
+ }
+
+ private bool _isLab;
+ public bool IsLab
+ {
+ get { return _isLab; }
+ set { _isLab = value; RaisePropertyChangedAuto(); }
+ }
+
+
+ private void SynchronizeColor()
+ {
+ _color_change_timer.Stop();
+
+ if (!IsLab)
+ {
+ Rgb rgb = new Rgb(Red, Green, Blue);
+ Lab lab = rgb.To<Lab>();
+ _l = lab.L;
+ _a = lab.A;
+ _b = lab.B;
+ }
+ else
+ {
+ Lab lab = new Lab(L, A, B);
+ Rgb rgb = lab.To<Rgb>();
+ _red = rgb.R;
+ _green = rgb.G;
+ _blue = rgb.B;
+ }
+
+ _color = Color.FromRgb((byte)Red, (byte)Green, (byte)Blue);
+ RaisePropertyChanged(nameof(Color));
+
+ _color_change_timer.Start();
+ }
+
+ private void SynchronizeComponents()
+ {
+ _color_change_timer.Stop();
+
+ _red = Color.R;
+ _green = Color.G;
+ _blue = Color.B;
+
+ if (IsLab)
+ {
+ Rgb rgb = new Rgb(Red, Green, Blue);
+ Lab lab = rgb.To<Lab>();
+ _l = lab.L;
+ _a = lab.A;
+ _b = lab.B;
+ }
+
+ RaisePropertyChanged(nameof(Red));
+ RaisePropertyChanged(nameof(Green));
+ RaisePropertyChanged(nameof(Blue));
+ RaisePropertyChanged(nameof(L));
+ RaisePropertyChanged(nameof(A));
+ RaisePropertyChanged(nameof(B));
+ RaisePropertyChanged(nameof(Color));
+
+ _color_change_timer.Start();
+ }
+ }
+}