diff options
| author | Victoria Plitt <Victoria.Plitt@twine-s.com> | 2019-09-09 10:11:20 +0300 |
|---|---|---|
| committer | Victoria Plitt <Victoria.Plitt@twine-s.com> | 2019-09-09 10:11:20 +0300 |
| commit | 50e86d29ec671997f599560202ff7eb84440393b (patch) | |
| tree | 288b144ce83757496727226a462cddc573d37f15 /Software/Visual_Studio/MachineStudio | |
| parent | 333a1e44ac878c6de96bc398e0fa49d3adabc4c1 (diff) | |
| download | Tango-50e86d29ec671997f599560202ff7eb84440393b.tar.gz Tango-50e86d29ec671997f599560202ff7eb84440393b.zip | |
Refactoring ColorLab module CCT association.
Diffstat (limited to 'Software/Visual_Studio/MachineStudio')
5 files changed, 173 insertions, 39 deletions
diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorLab/Models/CctModel.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorLab/Models/CctModel.cs new file mode 100644 index 000000000..bb5525ffb --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorLab/Models/CctModel.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.MachineStudio.ColorLab.Models +{ + public class CctModel + { + public String Guid { get; set; } + public String FileName { get; set; } + public bool IsNew { get; set; } + public byte[] Data { get; set; } + } +} diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorLab/Tango.MachineStudio.ColorLab.csproj b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorLab/Tango.MachineStudio.ColorLab.csproj index 367657cdc..ef01ae5f9 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorLab/Tango.MachineStudio.ColorLab.csproj +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorLab/Tango.MachineStudio.ColorLab.csproj @@ -73,6 +73,7 @@ <Link>GlobalVersionInfo.cs</Link> </Compile> <Compile Include="ColorLabModuleSettings.cs" /> + <Compile Include="Models\CctModel.cs" /> <Compile Include="ViewModelLocator.cs" /> <Compile Include="ViewModels\CalibrationDataPointVM.cs" /> <Compile Include="ViewModels\CalibrationDataViewVM.cs" /> @@ -196,7 +197,7 @@ <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <ProjectExtensions> <VisualStudio> - <UserProperties BuildVersion_AssemblyInfoFilename="Properties\AssemblyInfo.cs" BuildVersion_UpdateAssemblyVersion="True" BuildVersion_BuildVersioningStyle="None.None.Increment.TimeStamp" BuildVersion_UseGlobalSettings="False" BuildVersion_StartDate="2000/1/1" /> + <UserProperties BuildVersion_StartDate="2000/1/1" BuildVersion_UseGlobalSettings="False" BuildVersion_BuildVersioningStyle="None.None.Increment.TimeStamp" BuildVersion_UpdateAssemblyVersion="True" BuildVersion_AssemblyInfoFilename="Properties\AssemblyInfo.cs" /> </VisualStudio> </ProjectExtensions> </Project>
\ No newline at end of file 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 71929b72b..a521127e1 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 @@ -17,6 +17,7 @@ using Tango.BL.Entities; using Tango.BL.Enumerations; using Tango.ColorConversion; using Tango.Core.Commands; +using Tango.MachineStudio.ColorLab.Models; using Tango.MachineStudio.Common; using Tango.MachineStudio.Common.Controls; using Tango.MachineStudio.Common.Notifications; @@ -25,6 +26,7 @@ using Tango.PMR.ColorLab; using Tango.Settings; using Tango.SharedUI; using Tango.SharedUI.Controls; +using System.Data.Entity; namespace Tango.MachineStudio.ColorLab.ViewModels { @@ -32,7 +34,6 @@ namespace Tango.MachineStudio.ColorLab.ViewModels { private ObservablesContext _dbContext; private INotificationProvider _notification; - private bool _isNewCCT; private bool _prevent_inverse_conversion; #region Properties @@ -183,16 +184,40 @@ namespace Tango.MachineStudio.ColorLab.ViewModels set { _targetColor = value; RaisePropertyChangedAuto(); } } - private Cct _cct; - /// <summary> - /// Gets or sets the CCT. - /// </summary> - public Cct CCT + private ObservableCollection<CctModel> _ccts; + public ObservableCollection<CctModel> CCTS + { + get { return _ccts; } + set + { + _ccts = value; + RaisePropertyChangedAuto(); + } + } + + private CctModel _selectedCCT; + public CctModel SelectedCCT { - get { return _cct; } - set { _cct = value; RaisePropertyChangedAuto(); } + get { return _selectedCCT; } + set + { + _selectedCCT = value; + RaisePropertyChangedAuto(); + InvalidateRelayCommands(); + OnSelectedCCTChanged(); + } } + //private Cct _cct; + ///// <summary> + ///// Gets or sets the CCT. + ///// </summary> + //public Cct CCT + //{ + // get { return _cct; } + // set { _cct = value; RaisePropertyChangedAuto(); } + //} + private int _deltaChroma; /// <summary> /// Gets or sets the delta chroma. @@ -265,14 +290,14 @@ namespace Tango.MachineStudio.ColorLab.ViewModels { _notification = notification; - CCT = new Cct(); + // CCT = new Cct(); SourceColor = new RgbVM(); SourceColor.ColorChanged += SourceColor_ColorChanged; ImportForwardDataCommand = new RelayCommand(ImportForwardData, () => SelectedRML != null && IsFree); - ExportForwardDataCommand = new RelayCommand(ExportForwardData, () => SelectedRML != null && CCT != null && CCT.FileName != null && IsFree); + ExportForwardDataCommand = new RelayCommand(ExportForwardData, () => SelectedRML != null && SelectedCCT != null && IsFree); SaveCommand = new RelayCommand(Save, () => SelectedRML != null && IsFree); } @@ -299,6 +324,15 @@ namespace Tango.MachineStudio.ColorLab.ViewModels Machines = _dbContext.Machines.ToObservableCollection(); ColorSpaces = _dbContext.ColorSpaces.ToObservableCollection(); Rmls = _dbContext.Rmls.ToObservableCollection(); + + CCTS = _dbContext.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); }); var settings = SettingsManager.Default.GetOrCreate<ColorLabModuleSettings>(); @@ -331,13 +365,13 @@ namespace Tango.MachineStudio.ColorLab.ViewModels { try { - if (LiquidsCalibrationData == null || CCT.Data == null) return; + if (LiquidsCalibrationData == null || SelectedCCT == null || SelectedCCT.Data == null) return; ConversionInput input = new ConversionInput(); input.ColorSpace = SourceColor.IsLab ? PMR.ColorLab.ColorSpace.Lab : PMR.ColorLab.ColorSpace.Rgb; input.DeltaChroma = DeltaChroma; input.DeltaL = DeltaL; - input.ForwardData = ByteString.CopyFrom(CCT.Data); + input.ForwardData = ByteString.CopyFrom(SelectedCCT.Data); input.InputCoordinates = new InputCoordinates(); input.InputCoordinates.Red = (int)SourceColor.Red; @@ -452,17 +486,57 @@ namespace Tango.MachineStudio.ColorLab.ViewModels String file = GetCCTFileOpen(); if (file != null) { - CCT.FileName = Path.GetFileName(file); - CCT.Data = File.ReadAllBytes(file); + 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; } } private void ExportForwardData() { - String file = GetCCTFileSave(CCT.FileName); - if (file != null) + + if (SelectedCCT != null) { - File.WriteAllBytes(file, CCT.Data); + String file = GetCCTFileSave(SelectedCCT.FileName); + if (file != null) + { + using (_notification.PushTaskItem("Exporting CCT file...")) + { + try + { + IsFree = false; + + if (SelectedCCT.IsNew) + { + File.WriteAllBytes(file, SelectedCCT.Data); + } + else + { + var cct = _dbContext.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; + } + } + } } } @@ -497,6 +571,25 @@ namespace Tango.MachineStudio.ColorLab.ViewModels #endregion #region Liquid Volumes + private async void OnSelectedCCTChanged() + { + if (SelectedCCT != null && !SelectedCCT.IsNew) + { + using (_notification.PushTaskItem("Loading CCT data...")) + { + IsFree = false; + + var cct = await _dbContext.Ccts.SingleOrDefaultAsync(x => x.Guid == SelectedCCT.Guid); + + if (cct != null) + { + SelectedCCT.Data = cct.Data; + } + + IsFree = true; + } + } + } private void OnSelectedMachineChanged() { @@ -551,7 +644,7 @@ namespace Tango.MachineStudio.ColorLab.ViewModels input.ColorSpace = PMR.ColorLab.ColorSpace.Volume; input.DeltaChroma = DeltaChroma; input.DeltaL = DeltaL; - input.ForwardData = ByteString.CopyFrom(CCT.Data); + input.ForwardData = ByteString.CopyFrom(SelectedCCT.Data); input.InputCoordinates = new InputCoordinates(); input.ThreadL = SelectedRML.WhitePointL; @@ -636,12 +729,33 @@ namespace Tango.MachineStudio.ColorLab.ViewModels _dbContext.Adapter.GetConfiguration(x => x.Guid == SelectedMachine.ConfigurationGuid); } - _selectedRML = new RmlBuilder(_dbContext) + var builder = new RmlBuilder(_dbContext) .Set(_selectedRML.Guid) .WithActiveParametersGroup() .WithCAT(SelectedMachine.Guid) - .WithCCT() - .WithLiquidFactors().Build(); + .WithLiquidFactors(); + + if (IsHosted) + { + builder.WithCCT(); + } + + _selectedRML = builder.Build(); + + if (IsHosted) + { + if(SelectedRML.Cct != null){ + + SelectedCCT = new CctModel() + { + Data = SelectedRML.Cct.Data + }; + } + } + else + { + SelectedCCT = CCTS.SingleOrDefault(x => x.Guid == SelectedRML.CctGuid); + } LiquidVolumes = SelectedMachine.Configuration.GetSupportedIdsPacks(_selectedRML).Select(x => new LiquidVolumeVM() { @@ -685,16 +799,6 @@ namespace Tango.MachineStudio.ColorLab.ViewModels } } - _isNewCCT = false; - CCT = SelectedRML.Cct; - - if (CCT == null) - { - CCT = new Cct(); - SelectedRML.Cct = CCT; - _isNewCCT = true; - } - var settings = SettingsManager.Default.GetOrCreate<ColorLabModuleSettings>(); settings.LastMachineSerialNumber = SelectedMachine.SerialNumber; settings.LastRmlGuid = SelectedRML.Guid; @@ -750,11 +854,6 @@ namespace Tango.MachineStudio.ColorLab.ViewModels public async Task SaveChanges() { - if (_isNewCCT) - { - _dbContext.Ccts.Add(CCT); - } - foreach (var calDataVM in LiquidsCalibrationData) { var cat = calDataVM.IdsPack.LiquidType.Cats.FirstOrDefault(x => x.Machine == SelectedMachine && x.Rml == SelectedRML); @@ -777,6 +876,23 @@ namespace Tango.MachineStudio.ColorLab.ViewModels cat.PutCalibrationData(calData); } + if (SelectedCCT != null && !IsHosted) + { + if (SelectedCCT.IsNew) + { + Cct cct = new Cct(); + cct.Guid = SelectedCCT.Guid; + cct.FileName = SelectedCCT.FileName; + cct.Data = SelectedCCT.Data; + SelectedRML.Cct = cct; + SelectedCCT.IsNew = false; + } + else + { + SelectedRML.CctGuid = SelectedCCT.Guid; + } + } + await _dbContext.SaveChangesAsync(); InvalidateLiquidFactorsCalibrationData(); diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorLab/Views/MainView.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorLab/Views/MainView.xaml index 49966bad2..37f5f70be 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorLab/Views/MainView.xaml +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorLab/Views/MainView.xaml @@ -148,8 +148,7 @@ <materialDesign:PackIcon Kind="ArrowLeftBoldHexagonOutline" VerticalAlignment="Center" Width="40" Height="40" /> <Image Source="../Images/data-table.png" Height="80" Opacity="0.8"></Image> <StackPanel VerticalAlignment="Center" Width="300" Margin="10 0 0 0"> - - <TextBox IsReadOnly="False" Margin="0 5 0 0" Text="{Binding CCT.FileName}" HorizontalContentAlignment="Center"></TextBox> + <ComboBox materialDesign:HintAssist.Hint="No CCT Defined" Margin="0 5 0 0" HorizontalContentAlignment="Center" ItemsSource="{Binding CCTS}" SelectedItem="{Binding SelectedCCT}" DisplayMemberPath="FileName" Style="{StaticResource TransparentComboBoxStyle}"></ComboBox> <UniformGrid Columns="2" Margin="0 5 0 0" HorizontalAlignment="Right"> <Button Style="{StaticResource MaterialDesignFlatButton}" Padding="0" Command="{Binding ImportForwardDataCommand}"> <StackPanel Orientation="Horizontal" Margin="0 0 20 0"> 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 cb79dd043..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 @@ -518,9 +518,11 @@ namespace Tango.MachineStudio.RML.ViewModels 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 { |
