diff options
Diffstat (limited to 'Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels/MainViewVM.cs')
| -rw-r--r-- | Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels/MainViewVM.cs | 187 |
1 files changed, 186 insertions, 1 deletions
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 ebcfe72fd..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 @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.ComponentModel; +using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -12,12 +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 { @@ -119,6 +121,26 @@ namespace Tango.MachineStudio.RML.ViewModels set { _activeProcessParametersTableView = value; RaisePropertyChangedAuto(); } } + private ObservableCollection<CctModel> _ccts; + public ObservableCollection<CctModel> CCTS + { + get { return _ccts; } + set { _ccts = value; RaisePropertyChangedAuto(); } + } + + private CctModel _selectedCCT; + public CctModel SelectedCCT + { + get { return _selectedCCT; } + set { _selectedCCT = value; RaisePropertyChangedAuto(); OnSelectedCCTChanged(); InvalidateRelayCommands(); } + } + + private ColorConversionViewVM _colorConversionViewVM; + public ColorConversionViewVM ColorConversionViewVM + { + get { return _colorConversionViewVM; } + set { _colorConversionViewVM = value; RaisePropertyChangedAuto(); } + } /// <summary> /// Gets or sets the manage RML command. @@ -135,6 +157,10 @@ namespace Tango.MachineStudio.RML.ViewModels /// </summary> public RelayCommand RemoveRmlCommand { get; set; } + public RelayCommand ImportForwardDataCommand { get; set; } + + public RelayCommand ExportForwardDataCommand { get; set; } + public RelayCommand AddProcessParametersTableCommand { get; set; } public RelayCommand<ProcessParametersTable> RemoveProcessParametersTableCommand { get; set; } @@ -165,6 +191,10 @@ namespace Tango.MachineStudio.RML.ViewModels RemoveLiquidFactorCommand = new RelayCommand<LiquidTypesRml>(RemoveLiquidFactor, () => IsFree); CreateCalibrationDataExcelTemplateCommand = new RelayCommand(CreateCalibrationDataExcelTemplate); SaveCommand = new RelayCommand(Save, () => IsFree); + + ImportForwardDataCommand = new RelayCommand(ImportCCTData, () => ActiveRML != null && IsFree); + + ExportForwardDataCommand = new RelayCommand(ExportCCTData, () => ActiveRML != null && SelectedCCT != null && IsFree); } public override void OnApplicationReady() @@ -193,14 +223,30 @@ namespace Tango.MachineStudio.RML.ViewModels _active_context = ObservablesContext.CreateDefault(); + CCTS = _active_context.Ccts + .Select(x => new CctModel() + { + Guid = x.Guid, + FileName = x.FileName, + + }).ToObservableCollection(); + + CCTS.Where(x => String.IsNullOrWhiteSpace(x.FileName)).ToList().ForEach(x => x.FileName = x.Guid); + LoadRmlProperties(); ActiveRML = await new RmlBuilder(_active_context) .Set(guid) .WithActiveParametersGroup() .WithLiquidFactors() + .WithCCT() .BuildAsync(); + if (ActiveRML.Cct != null) + { + SelectedCCT = CCTS.SingleOrDefault(x => x.Guid == ActiveRML.Cct.Guid); + } + if (ActiveRML.ProcessParametersTablesGroups.ToList().Count == 0) { if (!_notification.ShowQuestion("Could not find any process group for the selected RML. Would you like to create one?")) @@ -248,13 +294,43 @@ 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); + InvalidateRelayCommands(); + IsFree = true; } } + 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(); @@ -472,6 +548,23 @@ namespace Tango.MachineStudio.RML.ViewModels ActiveRML.LastUpdated = DateTime.UtcNow; + if (SelectedCCT != null) + { + if (SelectedCCT.IsNew) + { + Cct cct = new Cct(); + cct.Guid = SelectedCCT.Guid; + cct.FileName = SelectedCCT.FileName; + cct.Data = SelectedCCT.Data; + ActiveRML.Cct = cct; + SelectedCCT.IsNew = false; + } + else + { + ActiveRML.CctGuid = SelectedCCT.Guid; + } + } + await _active_context.SaveChangesAsync(); } } @@ -491,5 +584,97 @@ namespace Tango.MachineStudio.RML.ViewModels View.NavigateTo(RmlNavigationView.RmlsView); LoadRmls(); } + + #region Import / Export Color Conversion Data + + private void ImportCCTData() + { + String file = GetCCTFileOpen(); + if (file != null) + { + CctModel cctModel = new CctModel(); + cctModel.Guid = Guid.NewGuid().ToString(); + cctModel.IsNew = true; + + cctModel.FileName = Path.GetFileName(file); + cctModel.Data = File.ReadAllBytes(file); + + CCTS.Insert(0, cctModel); + SelectedCCT = cctModel; + + ColorConversionViewVM.CCT = SelectedCCT; + } + } + + private void ExportCCTData() + { + if (SelectedCCT != null) + { + String file = GetCCTFileSave(ActiveRML.Cct.FileName); + if (file != null) + { + using (_notification.PushTaskItem("Exporting CCT file...")) + { + try + { + IsFree = false; + + if (SelectedCCT.IsNew) + { + File.WriteAllBytes(file, SelectedCCT.Data); + } + else + { + var cct = _active_context.Ccts.SingleOrDefault(x => x.Guid == SelectedCCT.Guid); + + if (cct != null) + { + File.WriteAllBytes(file, cct.Data); + } + } + } + catch (Exception ex) + { + LogManager.Log(ex, "Error exporting CCT file."); + _notification.ShowError($"An error occurred while trying to export the CCT file.\n{ex.Message}"); + } + finally + { + IsFree = true; + } + } + } + } + } + + private String GetCCTFileOpen() + { + OpenFileDialog dlg = new OpenFileDialog(); + dlg.Title = "Select color adjustment file"; + dlg.Filter = "Color Conversion Table|*.cct"; + if (dlg.ShowDialogCenter()) + { + return dlg.FileName; + } + + return null; + } + + private String GetCCTFileSave(String fileName) + { + SaveFileDialog dlg = new SaveFileDialog(); + dlg.Title = "Select color adjustment file"; + dlg.Filter = "Color Conversion Table|*.cct"; + dlg.FileName = fileName; + dlg.DefaultExt = ".cct"; + if (dlg.ShowDialogCenter()) + { + return dlg.FileName; + } + + return null; + } + + #endregion } } |
