diff options
| author | Shlomo Hecht <shlomo@twine-s.com> | 2019-09-10 13:26:09 +0300 |
|---|---|---|
| committer | Shlomo Hecht <shlomo@twine-s.com> | 2019-09-10 13:26:09 +0300 |
| commit | b681849bf2a14421435f1b0ce328bea6f0152925 (patch) | |
| tree | c87565b7373553ebbda3ee92bc9fab1c8cb0de52 /Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels/MainViewVM.cs | |
| parent | ddb9e22c3005bcbd4a2b6b327d606d3c4fb14ff2 (diff) | |
| parent | 536c0c613e538e62ab8905f8e096e739a40cb2b7 (diff) | |
| download | Tango-b681849bf2a14421435f1b0ce328bea6f0152925.tar.gz Tango-b681849bf2a14421435f1b0ce328bea6f0152925.zip | |
merge
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 | 108 |
1 files changed, 94 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..aa84fb137 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,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(); } } @@ -505,28 +552,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; + } + } + } } } |
