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 | 321 |
1 files changed, 303 insertions, 18 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 deb162687..bb6a3c467 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 @@ -152,20 +152,49 @@ namespace Tango.MachineStudio.RML.ViewModels set { _activeProcessParametersTableView = value; RaisePropertyChangedAuto(); } } - private ObservableCollection<CctModel> _ccts; - public ObservableCollection<CctModel> CCTS + private ObservableCollection<DataFileModel> _ccts; + public ObservableCollection<DataFileModel> CCTS { get { return _ccts; } set { _ccts = value; RaisePropertyChangedAuto(); } } - private CctModel _selectedCCT; - public CctModel SelectedCCT + private DataFileModel _selectedCCT; + public DataFileModel SelectedCCT { get { return _selectedCCT; } set { _selectedCCT = value; RaisePropertyChangedAuto(); OnSelectedCCTChanged(); InvalidateRelayCommands(); } } + private ObservableCollection<DataFileModel> _gbds; + public ObservableCollection<DataFileModel> GBDS + { + get { return _gbds; } + set { _gbds = value; RaisePropertyChangedAuto(); } + } + + private DataFileModel _selectedGBD; + public DataFileModel SelectedGBD + { + get { return _selectedGBD; } + set { _selectedGBD = value; RaisePropertyChangedAuto(); OnSelectedGBDChanged(); InvalidateRelayCommands(); } + } + + + private ObservableCollection<DataFileModel> _lubs; + public ObservableCollection<DataFileModel> LUBS + { + get { return _lubs; } + set { _lubs = value; RaisePropertyChangedAuto(); } + } + + private DataFileModel _selectedLUB; + public DataFileModel SelectedLUB + { + get { return _selectedLUB; } + set { _selectedLUB = value; RaisePropertyChangedAuto(); OnSelectedLUBChanged(); InvalidateRelayCommands(); } + } + private ColorConversionViewVM _colorConversionViewVM; public ColorConversionViewVM ColorConversionViewVM { @@ -227,6 +256,14 @@ namespace Tango.MachineStudio.RML.ViewModels public RelayCommand ExportForwardDataCommand { get; set; } + public RelayCommand ImportGBDCommand { get; set; } + + public RelayCommand ExportGBDCommand { get; set; } + + public RelayCommand ImportLUBCommand { get; set; } + + public RelayCommand ExportLUBCommand { get; set; } + public RelayCommand AddProcessParametersTableCommand { get; set; } public RelayCommand<ProcessParametersTable> RemoveProcessParametersTableCommand { get; set; } @@ -283,6 +320,14 @@ namespace Tango.MachineStudio.RML.ViewModels ExportForwardDataCommand = new RelayCommand(ExportCCTData, () => ActiveRML != null && SelectedCCT != null && IsFree); + ImportGBDCommand = new RelayCommand(ImportGBDData, () => ActiveRML != null && IsFree); + + ExportGBDCommand = new RelayCommand(ExportGBDData, () => ActiveRML != null && SelectedGBD != null && IsFree); + + ImportLUBCommand = new RelayCommand(ImportLUBData, () => ActiveRML != null && IsFree); + + ExportLUBCommand = new RelayCommand(ExportLUBData, () => ActiveRML != null && SelectedLUB != null && IsFree); + ExportRMLFileCommand = new RelayCommand(ExportRmlFile, () => SelectedRML != null && IsFree); ImportRMLFileCommand = new RelayCommand(ImportRmlFile, () => IsFree); @@ -363,7 +408,7 @@ namespace Tango.MachineStudio.RML.ViewModels _active_context = ObservablesContext.CreateDefault(); CCTS = _active_context.Ccts - .Select(x => new CctModel() + .Select(x => new DataFileModel() { Guid = x.Guid, FileName = x.FileName, @@ -372,6 +417,22 @@ namespace Tango.MachineStudio.RML.ViewModels CCTS.Where(x => String.IsNullOrWhiteSpace(x.FileName)).ToList().ForEach(x => x.FileName = x.Guid); + GBDS = _active_context.Gbds + .Select(x => new DataFileModel() + { + Guid = x.Guid, + FileName = x.FileName, + + }).ToObservableCollection(); + + LUBS = _active_context.Lubs + .Select(x => new DataFileModel() + { + Guid = x.Guid, + FileName = x.FileName, + + }).ToObservableCollection(); + LoadRmlProperties(); ActiveRML = await new RmlBuilder(_active_context) @@ -379,12 +440,26 @@ namespace Tango.MachineStudio.RML.ViewModels .WithActiveParametersGroup() .WithLiquidFactors() .WithCCT() + .WithGbdAndLub() .WithSpools() .BuildAsync(); if (ActiveRML.Cct != null) { - SelectedCCT = CCTS.SingleOrDefault(x => x.Guid == ActiveRML.Cct.Guid); + _selectedCCT = CCTS.SingleOrDefault(x => x.Guid == ActiveRML.Cct.Guid); + RaisePropertyChanged(nameof(SelectedCCT)); + } + + if (ActiveRML.Gbd != null) + { + _selectedGBD = GBDS.SingleOrDefault(x => x.Guid == ActiveRML.Gbd.Guid); + RaisePropertyChanged(nameof(SelectedGBD)); + } + + if (ActiveRML.Lub != null) + { + _selectedLUB = LUBS.SingleOrDefault(x => x.Guid == ActiveRML.Lub.Guid); + RaisePropertyChanged(nameof(SelectedLUB)); } if (ActiveRML.ProcessParametersTablesGroups.ToList().Count == 0) @@ -445,6 +520,8 @@ namespace Tango.MachineStudio.RML.ViewModels { RML = ActiveRML, CCT = SelectedCCT, + GBD = SelectedGBD, + LUB = SelectedLUB, LiquidsCalibrationData = CalibrationDataViewVM.LiquidsCalibrationData, LiquidTypesRmls = LiquidTypesRmls, }; @@ -475,7 +552,7 @@ namespace Tango.MachineStudio.RML.ViewModels } } - private async void OnSelectedCCTChanged() + private async Task OnSelectedCCTChanged() { if (SelectedCCT != null && !SelectedCCT.IsNew) { @@ -496,6 +573,48 @@ namespace Tango.MachineStudio.RML.ViewModels } } + private async Task OnSelectedGBDChanged() + { + if (SelectedGBD != null && !SelectedGBD.IsNew) + { + using (_notification.PushTaskItem("Loading GBD data...")) + { + IsFree = false; + + var gbd = await _active_context.Gbds.SingleOrDefaultAsync(x => x.Guid == SelectedGBD.Guid); + + if (gbd != null) + { + SelectedGBD.Data = gbd.Data; + ColorConversionViewVM.GBD = SelectedGBD; + } + + IsFree = true; + } + } + } + + private async Task OnSelectedLUBChanged() + { + if (SelectedLUB != null && !SelectedLUB.IsNew) + { + using (_notification.PushTaskItem("Loading LUB data...")) + { + IsFree = false; + + var lub = await _active_context.Lubs.SingleOrDefaultAsync(x => x.Guid == SelectedLUB.Guid); + + if (lub != null) + { + SelectedLUB.Data = lub.Data; + ColorConversionViewVM.LUB = SelectedLUB; + } + + IsFree = true; + } + } + } + private void LoadRmlProperties() { Materials = _active_context.MediaMaterials.ToObservableCollection(); @@ -895,6 +1014,40 @@ namespace Tango.MachineStudio.RML.ViewModels } } + if (SelectedGBD != null) + { + if (SelectedGBD.IsNew) + { + Gbd gbd = new Gbd(); + gbd.Guid = SelectedGBD.Guid; + gbd.FileName = SelectedGBD.FileName; + gbd.Data = SelectedGBD.Data; + ActiveRML.Gbd = gbd; + SelectedGBD.IsNew = false; + } + else + { + ActiveRML.GbdGuid = SelectedGBD.Guid; + } + } + + if (SelectedLUB != null) + { + if (SelectedLUB.IsNew) + { + Lub lub = new Lub(); + lub.Guid = SelectedLUB.Guid; + lub.FileName = SelectedLUB.FileName; + lub.Data = SelectedLUB.Data; + ActiveRML.Lub = lub; + SelectedLUB.IsNew = false; + } + else + { + ActiveRML.LubGuid = SelectedLUB.Guid; + } + } + var rmlAfter = RmlDTO.FromObservable(ActiveRML); await _active_context.SaveChangesAsync(); @@ -1016,7 +1169,7 @@ namespace Tango.MachineStudio.RML.ViewModels input.InputCoordinates.B = lab.B; input.ColorSpace = PMR.ColorLab.ColorSpace.Lab; var output = converter.Convert(input, ActiveRML.ColorConversionVersion); - + BatchConversionCsvModelOut result = new BatchConversionCsvModelOut(); result.Index = lab.Index; @@ -1100,7 +1253,7 @@ namespace Tango.MachineStudio.RML.ViewModels item.Volume = result.LightCyan; break; case PMR.ColorLab.LiquidType.LightMagenta: - item.Volume= result.LightMagenta; + item.Volume = result.LightMagenta; break; case PMR.ColorLab.LiquidType.LightYellow: item.Volume = result.LightYellow; @@ -1156,7 +1309,7 @@ namespace Tango.MachineStudio.RML.ViewModels private void ImportCCTData() { - String file = GetCCTFileOpen(); + String file = GetDataFileOpen("Select color adjustment file", "Color Conversion Table|*.cct"); if (file != null) { if (CCTS.ToList().Exists(x => x.FileName == Path.GetFileName(file))) @@ -1165,7 +1318,7 @@ namespace Tango.MachineStudio.RML.ViewModels return; } - CctModel cctModel = new CctModel(); + DataFileModel cctModel = new DataFileModel(); cctModel.Guid = Guid.NewGuid().ToString(); cctModel.IsNew = true; @@ -1183,7 +1336,7 @@ namespace Tango.MachineStudio.RML.ViewModels { if (SelectedCCT != null) { - String file = GetCCTFileSave(ActiveRML.Cct.FileName); + String file = GetDataFileSave("Select color adjustment file", "Color Conversion Table|*.cct", ActiveRML.Cct.FileName); if (file != null) { using (_notification.PushTaskItem("Exporting CCT file...")) @@ -1220,11 +1373,143 @@ namespace Tango.MachineStudio.RML.ViewModels } } - private String GetCCTFileOpen() + private void ExportLUBData() + { + if (SelectedLUB != null) + { + String file = GetDataFileSave("Select lubrication transformation file", "Lubrication Transformation File|*.lub", ActiveRML.Lub.FileName); + if (file != null) + { + using (_notification.PushTaskItem("Exporting LUB file...")) + { + try + { + IsFree = false; + + if (SelectedLUB.IsNew) + { + File.WriteAllBytes(file, SelectedLUB.Data); + } + else + { + var lub = _active_context.Lubs.SingleOrDefault(x => x.Guid == SelectedLUB.Guid); + + if (lub != null) + { + File.WriteAllBytes(file, lub.Data); + } + } + } + catch (Exception ex) + { + LogManager.Log(ex, "Error exporting LUB file."); + _notification.ShowError($"An error occurred while trying to export the LUB file.\n{ex.Message}"); + } + finally + { + IsFree = true; + } + } + } + } + } + + private void ImportLUBData() + { + String file = GetDataFileOpen("Select lubrication transformation file", "Lubrication Transformation File|*.lub"); + if (file != null) + { + if (LUBS.ToList().Exists(x => x.FileName == Path.GetFileName(file))) + { + _notification.ShowError("The selected LUB file already exists on the database. Please select the LUB file from the dropdown box."); + return; + } + + DataFileModel lubModel = new DataFileModel(); + lubModel.Guid = Guid.NewGuid().ToString(); + lubModel.IsNew = true; + + lubModel.FileName = Path.GetFileName(file); + lubModel.Data = File.ReadAllBytes(file); + + LUBS.Insert(0, lubModel); + SelectedLUB = lubModel; + + ColorConversionViewVM.LUB = SelectedLUB; + } + } + + private void ExportGBDData() + { + if (SelectedGBD != null) + { + String file = GetDataFileSave("Select gamut boundary descriptor file", "Gamut Boundary Descriptor File|*.gbd", ActiveRML.Gbd.FileName); + if (file != null) + { + using (_notification.PushTaskItem("Exporting GBD file...")) + { + try + { + IsFree = false; + + if (SelectedGBD.IsNew) + { + File.WriteAllBytes(file, SelectedGBD.Data); + } + else + { + var gbd = _active_context.Gbds.SingleOrDefault(x => x.Guid == SelectedGBD.Guid); + + if (gbd != null) + { + File.WriteAllBytes(file, gbd.Data); + } + } + } + catch (Exception ex) + { + LogManager.Log(ex, "Error exporting GBD file."); + _notification.ShowError($"An error occurred while trying to export the GBD file.\n{ex.Message}"); + } + finally + { + IsFree = true; + } + } + } + } + } + + private void ImportGBDData() + { + String file = GetDataFileOpen("Select gamut boundary description file", "Gamut Boundary Description File|*.gbd"); + if (file != null) + { + if (GBDS.ToList().Exists(x => x.FileName == Path.GetFileName(file))) + { + _notification.ShowError("The selected GBD file already exists on the database. Please select the GBD file from the dropdown box."); + return; + } + + DataFileModel gbdModel = new DataFileModel(); + gbdModel.Guid = Guid.NewGuid().ToString(); + gbdModel.IsNew = true; + + gbdModel.FileName = Path.GetFileName(file); + gbdModel.Data = File.ReadAllBytes(file); + + GBDS.Insert(0, gbdModel); + SelectedGBD = gbdModel; + + ColorConversionViewVM.GBD = SelectedGBD; + } + } + + private String GetDataFileOpen(String title, String filter) { OpenFileDialog dlg = new OpenFileDialog(); - dlg.Title = "Select color adjustment file"; - dlg.Filter = "Color Conversion Table|*.cct"; + dlg.Title = title; + dlg.Filter = filter; if (dlg.ShowDialogCenter()) { return dlg.FileName; @@ -1233,11 +1518,11 @@ namespace Tango.MachineStudio.RML.ViewModels return null; } - private String GetCCTFileSave(String fileName) + private String GetDataFileSave(String title, String filter, String fileName) { SaveFileDialog dlg = new SaveFileDialog(); - dlg.Title = "Select color adjustment file"; - dlg.Filter = "Color Conversion Table|*.cct"; + dlg.Title = title; + dlg.Filter = filter; dlg.FileName = fileName; dlg.DefaultExt = ".cct"; if (dlg.ShowDialogCenter()) |
