diff options
| author | Victoria Plitt <Victoria.Plitt@twine-s.com> | 2019-09-08 14:56:38 +0300 |
|---|---|---|
| committer | Victoria Plitt <Victoria.Plitt@twine-s.com> | 2019-09-08 14:56:38 +0300 |
| commit | 333a1e44ac878c6de96bc398e0fa49d3adabc4c1 (patch) | |
| tree | f1f10bd187877c87fbfa22976038940fd8710248 /Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels | |
| parent | a8945386c7a9b5e18f02e5136ee5fa8f71b164b0 (diff) | |
| download | Tango-333a1e44ac878c6de96bc398e0fa49d3adabc4c1.tar.gz Tango-333a1e44ac878c6de96bc398e0fa49d3adabc4c1.zip | |
Refactored RML module CCT association.
Diffstat (limited to 'Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels')
| -rw-r--r-- | Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels/MainViewVM.cs | 106 |
1 files changed, 92 insertions, 14 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 7218ef5ea..cb79dd043 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 @@ -17,6 +17,7 @@ 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; @@ -120,6 +121,20 @@ 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(); InvalidateRelayCommands(); } + } + /// <summary> /// Gets or sets the manage RML command. /// </summary> @@ -170,9 +185,9 @@ namespace Tango.MachineStudio.RML.ViewModels CreateCalibrationDataExcelTemplateCommand = new RelayCommand(CreateCalibrationDataExcelTemplate); SaveCommand = new RelayCommand(Save, () => IsFree); - ImportForwardDataCommand = new RelayCommand(ImportForwardData, () => ActiveRML != null && IsFree); + ImportForwardDataCommand = new RelayCommand(ImportCCTData, () => ActiveRML != null && IsFree); - ExportForwardDataCommand = new RelayCommand(ExportForwardData, () => ActiveRML != null && ActiveRML.Cct != null && IsFree); + ExportForwardDataCommand = new RelayCommand(ExportCCTData, () => ActiveRML != null && SelectedCCT != null && IsFree); } public override void OnApplicationReady() @@ -201,6 +216,16 @@ 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) @@ -210,6 +235,11 @@ namespace Tango.MachineStudio.RML.ViewModels .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?")) @@ -483,6 +513,21 @@ namespace Tango.MachineStudio.RML.ViewModels ActiveRML.LastUpdated = DateTime.UtcNow; + if (SelectedCCT != null) + { + if (SelectedCCT.IsNew) + { + Cct cct = new Cct(); + cct.FileName = SelectedCCT.FileName; + cct.Data = SelectedCCT.Data; + ActiveRML.Cct = cct; + } + else + { + ActiveRML.CctGuid = SelectedCCT.Guid; + } + } + await _active_context.SaveChangesAsync(); } } @@ -505,28 +550,61 @@ namespace Tango.MachineStudio.RML.ViewModels #region Import / Export Color Conversion Data - private void ImportForwardData() + private void ImportCCTData() { String file = GetCCTFileOpen(); if (file != null) { - if (ActiveRML.Cct == null) - { - Cct cct = new Cct(); - ActiveRML.Cct = cct; - } + CctModel cctModel = new CctModel(); + cctModel.Guid = Guid.NewGuid().ToString(); + cctModel.IsNew = true; - ActiveRML.Cct.FileName = Path.GetFileName(file); - ActiveRML.Cct.Data = File.ReadAllBytes(file); + cctModel.FileName = Path.GetFileName(file); + cctModel.Data = File.ReadAllBytes(file); + + CCTS.Insert(0, cctModel); + SelectedCCT = cctModel; } } - private void ExportForwardData() + private void ExportCCTData() { - String file = GetCCTFileSave(ActiveRML.Cct.FileName); - if (file != null) + if (SelectedCCT != null) { - File.WriteAllBytes(file, ActiveRML.Cct.Data); + 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; + } + } + } } } |
