From 86339c9b8e383b92e183ee443c5bfbebd05808e7 Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Wed, 22 Aug 2018 16:30:00 +0300 Subject: ColorLab Module seems to be working ok... --- .../ViewModels/MainViewVM.cs | 94 ++++++++++++++-------- 1 file changed, 62 insertions(+), 32 deletions(-) (limited to 'Software/Visual_Studio/MachineStudio/Modules') diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorLab/ViewModels/MainViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorLab/ViewModels/MainViewVM.cs index 5b317e6d2..3764e00de 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorLab/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorLab/ViewModels/MainViewVM.cs @@ -243,15 +243,10 @@ namespace Tango.MachineStudio.ColorLab.ViewModels { _notification = notification; - _dbContext = ObservablesContext.CreateDefault(); - CCT = new Cct(); SourceColor = new RgbVM(); SourceColor.ColorChanged += SourceColor_ColorChanged; - Machines = _dbContext.Machines.ToObservableCollection(); - ColorSpaces = _dbContext.ColorSpaces.ToObservableCollection(); - Rmls = _dbContext.Rmls.ToObservableCollection(); ImportForwardDataCommand = new RelayCommand(ImportForwardData, () => SelectedRML != null); ImportInverseDataCommand = new RelayCommand(ImportInverseData, () => SelectedRML != null); @@ -267,6 +262,21 @@ namespace Tango.MachineStudio.ColorLab.ViewModels GetHiveSuggestions(); } + public override void OnApplicationReady() + { + base.OnApplicationReady(); + + Task.Factory.StartNew(() => + { + _dbContext = ObservablesContext.CreateDefault(); + _dbContext.Configuration.LazyLoadingEnabled = false; + + Machines = _dbContext.Machines.ToObservableCollection(); + ColorSpaces = _dbContext.ColorSpaces.ToObservableCollection(); + Rmls = _dbContext.Rmls.ToObservableCollection(); + }); + } + #region ColorLab private void GetHiveSuggestions() @@ -417,6 +427,8 @@ namespace Tango.MachineStudio.ColorLab.ViewModels { if (SelectedMachine != null) { + _dbContext.GetConfiguration(x => x.Guid == SelectedMachine.ConfigurationGuid); + LiquidVolumes = SelectedMachine.Configuration.NoneEmptyIdsPacks.OrderBy(x => x.PackIndex).Select(x => new LiquidVolumeVM() { Color = x.LiquidType.Color, @@ -424,6 +436,9 @@ namespace Tango.MachineStudio.ColorLab.ViewModels IdsPack = x, }).ToObservableCollection(); + + LiquidVolumes.EnableCrossThreadOperations(); + LiquidVolumes.ToList().ForEach(x => x.VolumeChanged += (s, e) => OnLiquidVolumeChanged()); InvalidateLiquidFactorsCalibrationData(); @@ -515,42 +530,57 @@ namespace Tango.MachineStudio.ColorLab.ViewModels #region RML - private void InvalidateLiquidFactorsCalibrationData() + private async void InvalidateLiquidFactorsCalibrationData() { if (SelectedRML != null && SelectedMachine != null) { - LiquidTypesRmls = SelectedMachine.Configuration.NoneEmptyIdsPacks.OrderBy(x => x.PackIndex).Select(x => x.LiquidType).SelectMany(x => x.LiquidTypesRmls).Where(x => x.Rml.Guid == SelectedRML.Guid).ToList(); - //RmlProcessParametersTableGroup = SelectedRML.ProcessParametersTablesGroups.ToList().SingleOrDefault(x => x.Active); - - LiquidsCalibrationData = new ObservableCollection(); - - foreach (var idsPack in SelectedMachine.Configuration.NoneEmptyIdsPacks.OrderBy(x => x.PackIndex)) + await Task.Factory.StartNew(() => { - CalibrationDataVM vm = new CalibrationDataVM(); - vm.Name = idsPack.LiquidType.Name; - vm.Color = idsPack.LiquidType.Color; - vm.IdsPack = idsPack; + using (_notification.PushTaskItem("Loading RML data...")) + { + _dbContext.GetConfiguration(x => x.Guid == SelectedMachine.ConfigurationGuid); + _dbContext.GetRmlCCTs(SelectedRML.Guid); + _dbContext.GetRmlCATs(SelectedRML.Guid, SelectedMachine.Guid); + _dbContext.GetRmlLiquidTypes(SelectedRML.Guid); - var cat = idsPack.LiquidType.Cats.FirstOrDefault(x => x.Machine == SelectedMachine && x.Rml == SelectedRML); + LiquidTypesRmls = SelectedMachine.Configuration.NoneEmptyIdsPacks.OrderBy(x => x.PackIndex).Select(x => x.LiquidType).SelectMany(x => x.LiquidTypesRmls).Where(x => x.Rml.Guid == SelectedRML.Guid).ToList(); + //RmlProcessParametersTableGroup = SelectedRML.ProcessParametersTablesGroups.ToList().SingleOrDefault(x => x.Active); - if (cat != null) - { - var calData = cat.GetCalibrationData(); - vm.CalibrationPoints = calData.CalibrationPoints.Select(x => new CalibrationDataPointVM(x.X, x.Y)).ToObservableCollection(); - } + LiquidsCalibrationData = new ObservableCollection(); + LiquidsCalibrationData.EnableCrossThreadOperations(); - LiquidsCalibrationData.Add(vm); - } + foreach (var idsPack in SelectedMachine.Configuration.NoneEmptyIdsPacks.OrderBy(x => x.PackIndex)) + { + CalibrationDataVM vm = new CalibrationDataVM(); + vm.Name = idsPack.LiquidType.Name; + vm.Color = idsPack.LiquidType.Color; + vm.IdsPack = idsPack; + + var cat = idsPack.LiquidType.Cats.FirstOrDefault(x => x.Machine == SelectedMachine && x.Rml == SelectedRML); + + if (cat != null) + { + var calData = cat.GetCalibrationData(); + vm.CalibrationPoints = calData.CalibrationPoints.Select(x => new CalibrationDataPointVM(x.X, x.Y)).ToObservableCollection(); + } + + InvokeUINow(() => + { + LiquidsCalibrationData.Add(vm); + }); + } - _isNewCCT = false; - CCT = SelectedRML.Ccts.FirstOrDefault(); + _isNewCCT = false; + CCT = SelectedRML.Ccts.FirstOrDefault(); - if (CCT == null) - { - CCT = new Cct(); - CCT.Rml = SelectedRML; - _isNewCCT = true; - } + if (CCT == null) + { + CCT = new Cct(); + CCT.Rml = SelectedRML; + _isNewCCT = true; + } + } + }); } } -- cgit v1.3.1