From a561ed1999a14bd0f73406e2610a6d43d46baf5c Mon Sep 17 00:00:00 2001 From: Michael Sevestre Date: Tue, 21 Mar 2023 11:33:37 -0400 Subject: [PATCH] More work on #2569 to make test pass again: --- .../PKSim.Assets.Images.csproj | 4 +- src/PKSim.Assets/PKSim.Assets.csproj | 4 +- src/PKSim.BatchTool/PKSim.BatchTool.csproj | 4 +- src/PKSim.CLI.Core/PKSim.CLI.Core.csproj | 4 +- src/PKSim.CLI/PKSim.CLI.csproj | 6 +- ...eToExpressionProfileBuildingBlockMapper.cs | 6 +- ...dividualToIndividualBuildingBlockMapper.cs | 34 +++++----- .../PathAndValueBuildingBlockMapper.cs | 68 +++++++++++-------- .../Model/PKSimSpatialStructureFactory.cs | 5 +- src/PKSim.Core/PKSim.Core.csproj | 8 +-- src/PKSim.Core/Services/Cloner.cs | 2 +- ...butedParameterToTableParameterConverter.cs | 4 +- .../PKSim.Infrastructure.csproj | 18 ++--- .../Services/MoBiExportTask.cs | 21 +++--- src/PKSim.Matlab/PKSim.Matlab.csproj | 4 +- .../PKSim.Presentation.csproj | 6 +- src/PKSim.R/PKSim.R.csproj | 4 +- src/PKSim.UI.Starter/PKSim.UI.Starter.csproj | 10 +-- src/PKSim.UI/PKSim.UI.csproj | 8 +-- .../Individuals/ExpressionParametersView.cs | 2 +- .../Views/Parameters/ParameterSetView.cs | 4 +- src/PKSim/PKSim.csproj | 6 +- .../PKSim.Matlab.Tests.csproj | 4 +- tests/PKSim.R.Tests/PKSim.R.Tests.csproj | 4 +- ...pressionProfileBuildingBlockMapperSpecs.cs | 10 ++- .../CompressedSerializationManagerSpecs.cs | 4 +- .../PKSimParameterStartValuesCreatorSpecs.cs | 2 +- .../IntegrationTests/SimulationSpecs.cs | 2 +- tests/PKSim.Tests/PKSim.Tests.csproj | 2 +- ...ualToIndividualBuildingBlockMapperSpecs.cs | 42 ++++++++++-- tests/PKSim.UI.Tests/PKSim.UI.Tests.csproj | 6 +- 31 files changed, 179 insertions(+), 129 deletions(-) diff --git a/src/PKSim.Assets.Images/PKSim.Assets.Images.csproj b/src/PKSim.Assets.Images/PKSim.Assets.Images.csproj index 2071706d9..2ef0e2f23 100644 --- a/src/PKSim.Assets.Images/PKSim.Assets.Images.csproj +++ b/src/PKSim.Assets.Images/PKSim.Assets.Images.csproj @@ -26,8 +26,8 @@ - - + + diff --git a/src/PKSim.Assets/PKSim.Assets.csproj b/src/PKSim.Assets/PKSim.Assets.csproj index 2d8463f7d..c5fa737cf 100644 --- a/src/PKSim.Assets/PKSim.Assets.csproj +++ b/src/PKSim.Assets/PKSim.Assets.csproj @@ -26,8 +26,8 @@ - - + + diff --git a/src/PKSim.BatchTool/PKSim.BatchTool.csproj b/src/PKSim.BatchTool/PKSim.BatchTool.csproj index b2358b970..4775653fa 100644 --- a/src/PKSim.BatchTool/PKSim.BatchTool.csproj +++ b/src/PKSim.BatchTool/PKSim.BatchTool.csproj @@ -59,8 +59,8 @@ - - + + diff --git a/src/PKSim.CLI.Core/PKSim.CLI.Core.csproj b/src/PKSim.CLI.Core/PKSim.CLI.Core.csproj index 5e2d80ec8..1ce7609d5 100644 --- a/src/PKSim.CLI.Core/PKSim.CLI.Core.csproj +++ b/src/PKSim.CLI.Core/PKSim.CLI.Core.csproj @@ -27,9 +27,9 @@ - + - + diff --git a/src/PKSim.CLI/PKSim.CLI.csproj b/src/PKSim.CLI/PKSim.CLI.csproj index 317687a86..8acc32b5a 100644 --- a/src/PKSim.CLI/PKSim.CLI.csproj +++ b/src/PKSim.CLI/PKSim.CLI.csproj @@ -61,9 +61,9 @@ - - - + + + diff --git a/src/PKSim.Core/Mappers/ExpressionProfileToExpressionProfileBuildingBlockMapper.cs b/src/PKSim.Core/Mappers/ExpressionProfileToExpressionProfileBuildingBlockMapper.cs index 4f093f834..4da139005 100644 --- a/src/PKSim.Core/Mappers/ExpressionProfileToExpressionProfileBuildingBlockMapper.cs +++ b/src/PKSim.Core/Mappers/ExpressionProfileToExpressionProfileBuildingBlockMapper.cs @@ -5,6 +5,8 @@ using OSPSuite.Core.Domain.Services; using PKSim.Assets; using PKSim.Core.Model; +using PKSim.Core.Services; +using ILazyLoadTask = OSPSuite.Core.Domain.Services.ILazyLoadTask; namespace PKSim.Core.Mappers { @@ -14,8 +16,8 @@ public interface IExpressionProfileToExpressionProfileBuildingBlockMapper : IPat public class ExpressionProfileToExpressionProfileBuildingBlockMapper : PathAndValueBuildingBlockMapper, IExpressionProfileToExpressionProfileBuildingBlockMapper { - public ExpressionProfileToExpressionProfileBuildingBlockMapper(IObjectBaseFactory objectBaseFactory, IEntityPathResolver entityPathResolver, IApplicationConfiguration applicationConfiguration, ILazyLoadTask lazyLoadTask) : - base(objectBaseFactory, entityPathResolver, applicationConfiguration, lazyLoadTask) + public ExpressionProfileToExpressionProfileBuildingBlockMapper(IObjectBaseFactory objectBaseFactory, IEntityPathResolver entityPathResolver, IApplicationConfiguration applicationConfiguration, ILazyLoadTask lazyLoadTask, ICloner cloner) : + base(objectBaseFactory, entityPathResolver, applicationConfiguration, lazyLoadTask, cloner) { } diff --git a/src/PKSim.Core/Mappers/IndividualToIndividualBuildingBlockMapper.cs b/src/PKSim.Core/Mappers/IndividualToIndividualBuildingBlockMapper.cs index fbea43d15..3631be69c 100644 --- a/src/PKSim.Core/Mappers/IndividualToIndividualBuildingBlockMapper.cs +++ b/src/PKSim.Core/Mappers/IndividualToIndividualBuildingBlockMapper.cs @@ -8,6 +8,8 @@ using PKSim.Assets; using PKSim.Core.Model; using PKSim.Core.Repositories; +using PKSim.Core.Services; +using ILazyLoadTask = OSPSuite.Core.Domain.Services.ILazyLoadTask; namespace PKSim.Core.Mappers { @@ -21,7 +23,7 @@ public class IndividualToIndividualBuildingBlockMapper : PathAndValueBuildingBlo private readonly ICalculationMethodCategoryRepository _calculationMethodCategoryRepository; public IndividualToIndividualBuildingBlockMapper(IObjectBaseFactory objectBaseFactory, IEntityPathResolver entityPathResolver, IApplicationConfiguration applicationConfiguration, - ILazyLoadTask lazyLoadTask, IRepresentationInfoRepository representationInfoRepository, ICalculationMethodCategoryRepository calculationMethodCategoryRepository) : base(objectBaseFactory, entityPathResolver, applicationConfiguration, lazyLoadTask) + ILazyLoadTask lazyLoadTask, IRepresentationInfoRepository representationInfoRepository, ICalculationMethodCategoryRepository calculationMethodCategoryRepository, ICloner cloner) : base(objectBaseFactory, entityPathResolver, applicationConfiguration, lazyLoadTask, cloner) { _representationInfoRepository = representationInfoRepository; _calculationMethodCategoryRepository = calculationMethodCategoryRepository; @@ -32,25 +34,25 @@ protected override IReadOnlyList AllParametersFor(Individual individ return individual.GetAllChildren().Where(x => x.GroupName != CoreConstants.Groups.RELATIVE_EXPRESSION).ToList(); } - public override IndividualBuildingBlock MapFrom(Individual input) + public override IndividualBuildingBlock MapFrom(Individual individual) { - var buildingBlock = base.MapFrom(input); - buildingBlock.Icon = input.Icon; + var buildingBlock = base.MapFrom(individual); + buildingBlock.Icon = individual.Icon; - addOriginDataToBuildingBlock(buildingBlock, PKSimConstants.UI.DiseaseState, input.OriginData.DiseaseState?.DisplayName); - addOriginDataToBuildingBlock(buildingBlock, PKSimConstants.UI.Species, input.Species?.DisplayName); - addOriginDataToBuildingBlock(buildingBlock, PKSimConstants.UI.Gender, input.OriginData.Gender?.DisplayName); - addOriginDataToBuildingBlock(buildingBlock, PKSimConstants.UI.Age, input.OriginData.Age); - addOriginDataToBuildingBlock(buildingBlock, PKSimConstants.UI.GestationalAge, input.OriginData.GestationalAge); - addOriginDataToBuildingBlock(buildingBlock, PKSimConstants.UI.Height, input.OriginData.Height); - addOriginDataToBuildingBlock(buildingBlock, PKSimConstants.UI.BMI, input.OriginData.BMI); - addOriginDataToBuildingBlock(buildingBlock, PKSimConstants.UI.Weight, input.OriginData.Weight); - addOriginDataToBuildingBlock(buildingBlock, PKSimConstants.UI.Population, input.OriginData.Population?.DisplayName); + addOriginDataToBuildingBlock(buildingBlock, PKSimConstants.UI.DiseaseState, individual.OriginData.DiseaseState?.DisplayName); + addOriginDataToBuildingBlock(buildingBlock, PKSimConstants.UI.Species, individual.Species?.DisplayName); + addOriginDataToBuildingBlock(buildingBlock, PKSimConstants.UI.Gender, individual.OriginData.Gender?.DisplayName); + addOriginDataToBuildingBlock(buildingBlock, PKSimConstants.UI.Age, individual.OriginData.Age); + addOriginDataToBuildingBlock(buildingBlock, PKSimConstants.UI.GestationalAge, individual.OriginData.GestationalAge); + addOriginDataToBuildingBlock(buildingBlock, PKSimConstants.UI.Height, individual.OriginData.Height); + addOriginDataToBuildingBlock(buildingBlock, PKSimConstants.UI.BMI, individual.OriginData.BMI); + addOriginDataToBuildingBlock(buildingBlock, PKSimConstants.UI.Weight, individual.OriginData.Weight); + addOriginDataToBuildingBlock(buildingBlock, PKSimConstants.UI.Population, individual.OriginData.Population?.DisplayName); - input.OriginData.AllCalculationMethods().Where(cm => _calculationMethodCategoryRepository.HasMoreThanOneOption(cm, input.Species)) + individual.OriginData.AllCalculationMethods().Where(cm => _calculationMethodCategoryRepository.HasMoreThanOneOption(cm, individual.Species)) .Each(x => addCalculationMethodOriginDataToBuildingBlock(buildingBlock, x)); - buildingBlock.OriginData.ValueOrigin = input.OriginData.ValueOrigin.Clone(); + buildingBlock.OriginData.ValueOrigin = individual.OriginData.ValueOrigin.Clone(); return buildingBlock; } @@ -79,7 +81,7 @@ private void addOriginDataToBuildingBlock(IndividualBuildingBlock buildingBlock, if (string.IsNullOrEmpty(value)) return; - buildingBlock.OriginData.AddOriginDataItem(new OriginDataItem { Name = key, Value = value }); + buildingBlock.OriginData.AddOriginDataItem(new OriginDataItem {Name = key, Value = value}); } } } \ No newline at end of file diff --git a/src/PKSim.Core/Mappers/PathAndValueBuildingBlockMapper.cs b/src/PKSim.Core/Mappers/PathAndValueBuildingBlockMapper.cs index 9884c9b48..8356a4152 100644 --- a/src/PKSim.Core/Mappers/PathAndValueBuildingBlockMapper.cs +++ b/src/PKSim.Core/Mappers/PathAndValueBuildingBlockMapper.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using System.Linq; using OSPSuite.Core; using OSPSuite.Core.Domain; using OSPSuite.Core.Domain.Builder; @@ -6,31 +7,45 @@ using OSPSuite.Core.Domain.Services; using OSPSuite.Utility; using OSPSuite.Utility.Collections; +using OSPSuite.Utility.Extensions; using PKSim.Core.Model; +using PKSim.Core.Services; +using ILazyLoadTask = OSPSuite.Core.Domain.Services.ILazyLoadTask; namespace PKSim.Core.Mappers { - public interface IPathAndValueBuildingBlockMapper : IMapper + public interface IPathAndValueBuildingBlockMapper : IMapper { } - public abstract class PathAndValueBuildingBlockMapper : IPathAndValueBuildingBlockMapper where T : PKSimBuildingBlock where TBuildingBlock : PathAndValueEntityBuildingBlockFromPKSim where TBuilder : PathAndValueEntity + public abstract class PathAndValueBuildingBlockMapper : IPathAndValueBuildingBlockMapper where TPKSimBuildingBlock : PKSimBuildingBlock where TBuildingBlock : PathAndValueEntityBuildingBlockFromPKSim + where TBuilder : PathAndValueEntity { protected IObjectBaseFactory _objectBaseFactory; protected IEntityPathResolver _entityPathResolver; protected IApplicationConfiguration _applicationConfiguration; private readonly ILazyLoadTask _lazyLoadTask; + private readonly ICloner _cloner; + + //Cache used to store all formula that can be cached. This is required to avoid having the same formula defined multiple times in the building block + //note that a clone of the original formula is added to the cache so that it can be modified if required private readonly Cache _formulaCache = new Cache(x => x.Name); - protected PathAndValueBuildingBlockMapper(IObjectBaseFactory objectBaseFactory, IEntityPathResolver entityPathResolver, IApplicationConfiguration applicationConfiguration, ILazyLoadTask lazyLoadTask) + protected PathAndValueBuildingBlockMapper( + IObjectBaseFactory objectBaseFactory, + IEntityPathResolver entityPathResolver, + IApplicationConfiguration applicationConfiguration, + ILazyLoadTask lazyLoadTask, + ICloner cloner) { _objectBaseFactory = objectBaseFactory; _entityPathResolver = entityPathResolver; _applicationConfiguration = applicationConfiguration; _lazyLoadTask = lazyLoadTask; + _cloner = cloner; } - protected TBuildingBlock CreateBaseObject(T pkSimBuildingBlock) + protected TBuildingBlock CreateBaseObject(TPKSimBuildingBlock pkSimBuildingBlock) { var buildingBlock = _objectBaseFactory.Create(); @@ -43,12 +58,16 @@ protected TBuildingBlock CreateBaseObject(T pkSimBuildingBlock) private TBuilder mapBuilderParameter(IParameter parameter) { var builderParameter = _objectBaseFactory.Create(); + builderParameter.Name = parameter.Name; + builderParameter.Path = _entityPathResolver.ObjectPathFor(parameter); + builderParameter.Dimension = parameter.Dimension; + builderParameter.DisplayUnit = parameter.DisplayUnit; // Add the formula to the building block formula cache if the formula can be cached if (isFormulaCachable(parameter)) { if (!_formulaCache.Contains(parameter.Formula.Name)) - _formulaCache.Add(parameter.Formula); + _formulaCache.Add(cloneFormulaForExport(parameter)); // If the parameter value is different from the default value, set the value only and not the formula // If the parameter value is not different from the default, set the formula only and not the value @@ -63,14 +82,16 @@ private TBuilder mapBuilderParameter(IParameter parameter) builderParameter.Value = getParameterValue(parameter); } - builderParameter.Name = parameter.Name; - - builderParameter.Path = _entityPathResolver.ObjectPathFor(parameter); - builderParameter.Dimension = parameter.Dimension; - builderParameter.DisplayUnit = parameter.DisplayUnit; return builderParameter; } + private IFormula cloneFormulaForExport(IParameter parameter) + { + var cloneFormula = _cloner.Clone(parameter.Formula); + cloneFormula.ObjectPaths.Each(x => x.Remove(Constants.ROOT)); + return cloneFormula; + } + private static bool isFormulaCachable(IParameter parameter) { return parameter.Formula != null && parameter.Formula.IsCachable(); @@ -81,30 +102,23 @@ private static double getParameterValue(IParameter parameter) return parameter.TryGetValue().value; } - protected void MapAllParameters(T sourcePKSimBuildingBlock, TBuildingBlock buildingBlock) + protected void MapAllParameters(TPKSimBuildingBlock sourcePKSimBuildingBlock, TBuildingBlock buildingBlock) { - var allParameters = AllParametersFor(sourcePKSimBuildingBlock); + var allBuilderParameters = AllParametersFor(sourcePKSimBuildingBlock).Select(mapBuilderParameter); + allBuilderParameters.Each(buildingBlock.Add); - foreach (var parameter in allParameters) - { - var builderParameter = mapBuilderParameter(parameter); - buildingBlock.Add(builderParameter); - } - - foreach (var formula in _formulaCache) - { - buildingBlock.FormulaCache.Add(formula); - } + //Formula cache already contains a clone of all formula. We can add as is + _formulaCache.Each(buildingBlock.FormulaCache.Add); } - protected abstract IReadOnlyList AllParametersFor(T sourcePKSimBuildingBlock); + protected abstract IReadOnlyList AllParametersFor(TPKSimBuildingBlock sourcePKSimBuildingBlock); - public virtual TBuildingBlock MapFrom(T input) + public virtual TBuildingBlock MapFrom(TPKSimBuildingBlock pkSimBuildingBlock) { - _lazyLoadTask.Load(input); + _lazyLoadTask.Load(pkSimBuildingBlock); - var buildingBlock = CreateBaseObject(input); - MapAllParameters(input, buildingBlock); + var buildingBlock = CreateBaseObject(pkSimBuildingBlock); + MapAllParameters(pkSimBuildingBlock, buildingBlock); return buildingBlock; } } diff --git a/src/PKSim.Core/Model/PKSimSpatialStructureFactory.cs b/src/PKSim.Core/Model/PKSimSpatialStructureFactory.cs index 32d6f0248..12dac9512 100644 --- a/src/PKSim.Core/Model/PKSimSpatialStructureFactory.cs +++ b/src/PKSim.Core/Model/PKSimSpatialStructureFactory.cs @@ -138,9 +138,6 @@ private void addModelStructureTo(IContainer container, OriginData originData, Mo } } - protected override ISpatialStructure CreateSpatialStructure() - { - return _objectBaseFactory.Create(); - } + protected override ISpatialStructure CreateSpatialStructure() => _objectBaseFactory.Create(); } } \ No newline at end of file diff --git a/src/PKSim.Core/PKSim.Core.csproj b/src/PKSim.Core/PKSim.Core.csproj index 6d1fb98ee..8d07f3ba2 100644 --- a/src/PKSim.Core/PKSim.Core.csproj +++ b/src/PKSim.Core/PKSim.Core.csproj @@ -30,10 +30,10 @@ - - - - + + + + diff --git a/src/PKSim.Core/Services/Cloner.cs b/src/PKSim.Core/Services/Cloner.cs index 80f88c530..33e94bf63 100644 --- a/src/PKSim.Core/Services/Cloner.cs +++ b/src/PKSim.Core/Services/Cloner.cs @@ -43,7 +43,7 @@ public Cloner(ICloneManagerForModel cloneManagerForModel, ICloneManagerForBuildi public T Clone(T objectToClone) where T : class, IUpdatable { - //formula cache are never used in pksim explicitely. And if need, we access CloneManagerForBuildingBlock + //formula cache are never used in pksim explicitly. And if need, we access CloneManagerForBuildingBlock _cloneManagerForBuildingBlock.FormulaCache = new FormulaCache(); return createClone(objectToClone, _cloneManagerForBuildingBlock); } diff --git a/src/PKSim.Core/Services/DistributedParameterToTableParameterConverter.cs b/src/PKSim.Core/Services/DistributedParameterToTableParameterConverter.cs index 96522eb27..c4b55b126 100644 --- a/src/PKSim.Core/Services/DistributedParameterToTableParameterConverter.cs +++ b/src/PKSim.Core/Services/DistributedParameterToTableParameterConverter.cs @@ -119,7 +119,7 @@ private void updateAgeParameter(SimulationConfiguration simulationConfiguration) { var spatialStructure = simulationConfiguration.SpatialStructure; //We have only one in PK-Sim - var parameterStartValueBuildingBlock = simulationConfiguration.ParameterStartValuesCollection.First(); + var parameterStartValueBuildingBlock = simulationConfiguration.ParameterStartValues; var organism = spatialStructure.TopContainers.FindByName(Constants.ORGANISM); var ageParameter = organism.Parameter(CoreConstants.Parameters.AGE); var minToYearFactor = _timeDimension.BaseUnitValueToUnitValue(_yearUnit, 1); @@ -199,7 +199,7 @@ private void createSpatialStructureTableParameters(SimulationConfiguration simul private void createOntogenyTableParameters(SimulationConfiguration simulationConfiguration) { var simulationPopulation = _simulation as PopulationSimulation; - var parameterStartValueBuildingBlock = simulationConfiguration.ParameterStartValuesCollection.First(); + var parameterStartValueBuildingBlock = simulationConfiguration.ParameterStartValues; foreach (var molecule in _baseIndividual.AllMolecules().Where(m => m.Ontogeny.IsDefined())) { var ontogenyFactorPath = _entityPathResolver.ObjectPathFor(molecule.OntogenyFactorParameter); diff --git a/src/PKSim.Infrastructure/PKSim.Infrastructure.csproj b/src/PKSim.Infrastructure/PKSim.Infrastructure.csproj index db71b9dca..d5c5fa1c8 100644 --- a/src/PKSim.Infrastructure/PKSim.Infrastructure.csproj +++ b/src/PKSim.Infrastructure/PKSim.Infrastructure.csproj @@ -41,15 +41,15 @@ - - - - - - - - - + + + + + + + + + diff --git a/src/PKSim.Infrastructure/Services/MoBiExportTask.cs b/src/PKSim.Infrastructure/Services/MoBiExportTask.cs index b2d0e364e..a920c459f 100644 --- a/src/PKSim.Infrastructure/Services/MoBiExportTask.cs +++ b/src/PKSim.Infrastructure/Services/MoBiExportTask.cs @@ -35,9 +35,15 @@ public class MoBiExportTask : IMoBiExportTask, IVisitor private readonly IApplicationSettings _applicationSettings; private readonly IStartableProcessFactory _startableProcessFactory; - public MoBiExportTask(ISimulationConfigurationTask simulationConfigurationTask, ISimulationToModelCoreSimulationMapper simulationMapper, - IRepresentationInfoRepository representationInfoRepository, IPKSimConfiguration configuration, - ILazyLoadTask lazyLoadTask, IDialogCreator dialogCreator, ISimulationPersistor simulationPersistor, IProjectRetriever projectRetriever, + public MoBiExportTask( + ISimulationConfigurationTask simulationConfigurationTask, + ISimulationToModelCoreSimulationMapper simulationMapper, + IRepresentationInfoRepository representationInfoRepository, + IPKSimConfiguration configuration, + ILazyLoadTask lazyLoadTask, + IDialogCreator dialogCreator, + ISimulationPersistor simulationPersistor, + IProjectRetriever projectRetriever, IObjectIdResetter objectIdResetter, IJournalRetriever journalRetriever, IApplicationSettings applicationSettings, IStartableProcessFactory startableProcessFactory) { _simulationConfigurationTask = simulationConfigurationTask; @@ -163,14 +169,7 @@ public void ExportSimulationToPkmlFile(Simulation simulation, string fileName) private void updateRepresentationInfo(IModelCoreSimulation moBiSimulation) { - //TODO. That should be done better I think. Can we accept a global visitor? - //moBiSimulation.Configuration.AcceptVisitor(this)?; - moBiSimulation.Configuration.SpatialStructure.AcceptVisitor(this); - moBiSimulation.Configuration.Reactions.AcceptVisitor(this); - moBiSimulation.Configuration.Molecules.AcceptVisitor(this); - moBiSimulation.Configuration.PassiveTransports.AcceptVisitor(this); - moBiSimulation.Configuration.Observers.AcceptVisitor(this); - moBiSimulation.Configuration.EventGroups.AcceptVisitor(this); + moBiSimulation.Configuration.AcceptVisitor(this); moBiSimulation.Model.AcceptVisitor(this); } diff --git a/src/PKSim.Matlab/PKSim.Matlab.csproj b/src/PKSim.Matlab/PKSim.Matlab.csproj index d9fb0c939..ef170a301 100644 --- a/src/PKSim.Matlab/PKSim.Matlab.csproj +++ b/src/PKSim.Matlab/PKSim.Matlab.csproj @@ -26,9 +26,9 @@ - + - + diff --git a/src/PKSim.Presentation/PKSim.Presentation.csproj b/src/PKSim.Presentation/PKSim.Presentation.csproj index 4150a36cf..64ed741c4 100644 --- a/src/PKSim.Presentation/PKSim.Presentation.csproj +++ b/src/PKSim.Presentation/PKSim.Presentation.csproj @@ -27,11 +27,11 @@ - + - - + + diff --git a/src/PKSim.R/PKSim.R.csproj b/src/PKSim.R/PKSim.R.csproj index 42ed06d18..5723619b2 100644 --- a/src/PKSim.R/PKSim.R.csproj +++ b/src/PKSim.R/PKSim.R.csproj @@ -49,9 +49,9 @@ - + - + diff --git a/src/PKSim.UI.Starter/PKSim.UI.Starter.csproj b/src/PKSim.UI.Starter/PKSim.UI.Starter.csproj index c747e7b61..835db2ad3 100644 --- a/src/PKSim.UI.Starter/PKSim.UI.Starter.csproj +++ b/src/PKSim.UI.Starter/PKSim.UI.Starter.csproj @@ -1,4 +1,4 @@ - + net472 @@ -23,10 +23,10 @@ - - - - + + + + diff --git a/src/PKSim.UI/PKSim.UI.csproj b/src/PKSim.UI/PKSim.UI.csproj index 7a773533a..399fc21dc 100644 --- a/src/PKSim.UI/PKSim.UI.csproj +++ b/src/PKSim.UI/PKSim.UI.csproj @@ -60,14 +60,14 @@ - + - - - + + + diff --git a/src/PKSim.UI/Views/Individuals/ExpressionParametersView.cs b/src/PKSim.UI/Views/Individuals/ExpressionParametersView.cs index d8affd3ff..25ed2fe7c 100644 --- a/src/PKSim.UI/Views/Individuals/ExpressionParametersView.cs +++ b/src/PKSim.UI/Views/Individuals/ExpressionParametersView.cs @@ -350,7 +350,7 @@ protected virtual void UpdateExpressionParameterAppearance(TExpressionParameterD _gridView.AdjustAppearance(e, isEnabled: false); else if (_presenter.IsSetByUser(parameterDTO)) - _gridView.AdjustAppearance(e, PKSimColors.Changed, e.Appearance.ForeColor); + _gridView.AdjustAppearance(e, PKSimColors.Changed); else e.CombineAppearance(_gridView.Appearance.Row); diff --git a/src/PKSim.UI/Views/Parameters/ParameterSetView.cs b/src/PKSim.UI/Views/Parameters/ParameterSetView.cs index 91c13ec05..f95cf38f8 100644 --- a/src/PKSim.UI/Views/Parameters/ParameterSetView.cs +++ b/src/PKSim.UI/Views/Parameters/ParameterSetView.cs @@ -303,10 +303,10 @@ private void updateRowCellStyle(object sender, RowCellStyleEventArgs e) _gridView.AdjustAppearance(e, false); else if (_presenter.IsFormulaNotFixed(parameterDTO)) - _gridView.AdjustAppearance(e, PKSimColors.Formula, e.Appearance.ForeColor); + _gridView.AdjustAppearance(e, PKSimColors.Formula); else if (_presenter.IsSetByUser(parameterDTO)) - _gridView.AdjustAppearance(e, PKSimColors.Changed, e.Appearance.ForeColor); + _gridView.AdjustAppearance(e, PKSimColors.Changed); else e.CombineAppearance(_gridView.Appearance.Row); } diff --git a/src/PKSim/PKSim.csproj b/src/PKSim/PKSim.csproj index 965d37c92..d07667ad2 100644 --- a/src/PKSim/PKSim.csproj +++ b/src/PKSim/PKSim.csproj @@ -76,14 +76,14 @@ - - + + - + diff --git a/tests/PKSim.Matlab.Tests/PKSim.Matlab.Tests.csproj b/tests/PKSim.Matlab.Tests/PKSim.Matlab.Tests.csproj index 878197445..82ba4f2e6 100644 --- a/tests/PKSim.Matlab.Tests/PKSim.Matlab.Tests.csproj +++ b/tests/PKSim.Matlab.Tests/PKSim.Matlab.Tests.csproj @@ -22,9 +22,9 @@ runtime; build; native; contentfiles; analyzers; buildtransitive - + - + diff --git a/tests/PKSim.R.Tests/PKSim.R.Tests.csproj b/tests/PKSim.R.Tests/PKSim.R.Tests.csproj index 5f40ebbd6..00c3c0041 100644 --- a/tests/PKSim.R.Tests/PKSim.R.Tests.csproj +++ b/tests/PKSim.R.Tests/PKSim.R.Tests.csproj @@ -22,9 +22,9 @@ runtime; build; native; contentfiles; analyzers; buildtransitive - + - + diff --git a/tests/PKSim.Tests/Core/ExpressionProfileToExpressionProfileBuildingBlockMapperSpecs.cs b/tests/PKSim.Tests/Core/ExpressionProfileToExpressionProfileBuildingBlockMapperSpecs.cs index 91b7d6a98..98cfaa7b2 100644 --- a/tests/PKSim.Tests/Core/ExpressionProfileToExpressionProfileBuildingBlockMapperSpecs.cs +++ b/tests/PKSim.Tests/Core/ExpressionProfileToExpressionProfileBuildingBlockMapperSpecs.cs @@ -5,9 +5,12 @@ using OSPSuite.Core; using OSPSuite.Core.Domain; using OSPSuite.Core.Domain.Builder; +using OSPSuite.Core.Domain.Formulas; using OSPSuite.Core.Domain.Services; using PKSim.Core.Mappers; using PKSim.Core.Model; +using PKSim.Core.Services; +using ILazyLoadTask = OSPSuite.Core.Domain.Services.ILazyLoadTask; namespace PKSim.Core { @@ -20,6 +23,7 @@ public abstract class concern_for_ExpressionProfileToExpressionProfileBuildingBl protected ExpressionProfileBuildingBlock _result; private IApplicationConfiguration _applicationConfiguration; private ILazyLoadTask _lazyLoadTask; + private ICloner _cloner; protected override void Context() { @@ -27,10 +31,14 @@ protected override void Context() _objectBaseFactory = A.Fake(); _objectPathFactory = new EntityPathResolverForSpecs(); _lazyLoadTask = A.Fake(); + _cloner= A.Fake(); + //cloning formula always returns the same formula for testing + A.CallTo(() => _cloner.Clone(A._)).ReturnsLazily(x => x.GetArgument(0)); + A.CallTo(() => _objectBaseFactory.Create()).Returns(new ExpressionProfileBuildingBlock()); A.CallTo(() => _objectBaseFactory.Create()).ReturnsLazily(() => new ExpressionParameter()); - sut = new ExpressionProfileToExpressionProfileBuildingBlockMapper(_objectBaseFactory, _objectPathFactory, _applicationConfiguration, _lazyLoadTask); + sut = new ExpressionProfileToExpressionProfileBuildingBlockMapper(_objectBaseFactory, _objectPathFactory, _applicationConfiguration, _lazyLoadTask, _cloner); } } diff --git a/tests/PKSim.Tests/Infrastructure/CompressedSerializationManagerSpecs.cs b/tests/PKSim.Tests/Infrastructure/CompressedSerializationManagerSpecs.cs index d0ce22d01..9575becd1 100644 --- a/tests/PKSim.Tests/Infrastructure/CompressedSerializationManagerSpecs.cs +++ b/tests/PKSim.Tests/Infrastructure/CompressedSerializationManagerSpecs.cs @@ -32,7 +32,7 @@ protected override void Context() } - public class When_deserialzing_an_object_from_a_compressed_string : concern_for_CompressedSerializationManager + public class When_deserializing_an_object_from_a_compressed_string : concern_for_CompressedSerializationManager { [Observation] public void should_decompress_the_string_and_leverage_the_underlying_deserialize_the_object() @@ -42,7 +42,7 @@ public void should_decompress_the_string_and_leverage_the_underlying_deserialize } - public class When_serialzing_an_object_to_a_compressed_string : concern_for_CompressedSerializationManager + public class When_serializing_an_object_to_a_compressed_string : concern_for_CompressedSerializationManager { [Observation] public void should_decompress_the_string_and_leverage_the_underlying_deserialize_the_object() diff --git a/tests/PKSim.Tests/IntegrationTests/PKSimParameterStartValuesCreatorSpecs.cs b/tests/PKSim.Tests/IntegrationTests/PKSimParameterStartValuesCreatorSpecs.cs index 653b6e582..aba6c5b86 100644 --- a/tests/PKSim.Tests/IntegrationTests/PKSimParameterStartValuesCreatorSpecs.cs +++ b/tests/PKSim.Tests/IntegrationTests/PKSimParameterStartValuesCreatorSpecs.cs @@ -66,7 +66,7 @@ protected override void Because() parameter.Value = 10; _parameterPath = _entityPathResolver.ObjectPathFor(parameter); var simulationConfiguration = _simulationConfigurationTask.CreateFor(_simulation, shouldValidate: true, createAgingDataInSimulation: false); - _psv = simulationConfiguration.ParameterStartValuesCollection[0]; + _psv = simulationConfiguration.ParameterStartValues; } [Observation] diff --git a/tests/PKSim.Tests/IntegrationTests/SimulationSpecs.cs b/tests/PKSim.Tests/IntegrationTests/SimulationSpecs.cs index 70e3e1e89..d19937848 100644 --- a/tests/PKSim.Tests/IntegrationTests/SimulationSpecs.cs +++ b/tests/PKSim.Tests/IntegrationTests/SimulationSpecs.cs @@ -289,7 +289,7 @@ public override void GlobalContext() [Observation] public void should_set_negative_values_allowed_true_to_predefined_compartments_and_molecules() { - var msv = _simulationConfiguration.MoleculeStartValuesCollection[0]; + var msv = _simulationConfiguration.MoleculeStartValues; var moleculesWithAllowedNegativeValues = (from molecule in msv where molecule.NegativeValuesAllowed select molecule).ToList(); diff --git a/tests/PKSim.Tests/PKSim.Tests.csproj b/tests/PKSim.Tests/PKSim.Tests.csproj index 8e01af43f..0c6f64a14 100644 --- a/tests/PKSim.Tests/PKSim.Tests.csproj +++ b/tests/PKSim.Tests/PKSim.Tests.csproj @@ -21,7 +21,7 @@ - + diff --git a/tests/PKSim.Tests/Presentation/IndividualToIndividualBuildingBlockMapperSpecs.cs b/tests/PKSim.Tests/Presentation/IndividualToIndividualBuildingBlockMapperSpecs.cs index f7af2b89e..590d9ccf9 100644 --- a/tests/PKSim.Tests/Presentation/IndividualToIndividualBuildingBlockMapperSpecs.cs +++ b/tests/PKSim.Tests/Presentation/IndividualToIndividualBuildingBlockMapperSpecs.cs @@ -5,12 +5,15 @@ using OSPSuite.Core; using OSPSuite.Core.Domain; using OSPSuite.Core.Domain.Builder; -using OSPSuite.Core.Domain.Services; +using OSPSuite.Core.Domain.Formulas; +using OSPSuite.Core.Extensions; using PKSim.Core; using PKSim.Core.Mappers; using PKSim.Core.Model; using PKSim.Core.Repositories; +using PKSim.Core.Services; using PKSim.Infrastructure; +using ILazyLoadTask = OSPSuite.Core.Domain.Services.ILazyLoadTask; namespace PKSim.Presentation { @@ -23,6 +26,7 @@ public class concern_for_IndividualToIndividualBuildingBlockMapper : ContextSpec private EntityPathResolverForSpecs _objectPathFactory; private ICalculationMethodCategoryRepository _calculationMethodCategoryRepository; private static CalculationMethodCategory _category1; + private ICloner _cloner; protected override void Context() { @@ -31,19 +35,36 @@ protected override void Context() _applicationConfiguration = new PKSimConfiguration(); _objectPathFactory = new EntityPathResolverForSpecs(); _objectBaseFactory = A.Fake(); + _cloner = A.Fake(); + + //cloning formula always returns the same formula for testing + A.CallTo(() => _cloner.Clone(A._)).ReturnsLazily(x => x.GetArgument(0)); + var representationInfoRepository = A.Fake(); - A.CallTo(() => representationInfoRepository.InfoFor(A._, A._)).Returns(new RepresentationInfo { DisplayName = "displayName" }); + A.CallTo(representationInfoRepository).WithReturnType().Returns(new RepresentationInfo {DisplayName = "displayName"}); _calculationMethodCategoryRepository = A.Fake(); - updateOriginDataForTest(_individual.OriginData); + updateIndividualForTest(_individual); A.CallTo(() => _objectBaseFactory.Create()).Returns(new IndividualBuildingBlock()); A.CallTo(() => _objectBaseFactory.Create()).Returns(new IndividualParameter()); - sut = new IndividualToIndividualBuildingBlockMapper(_objectBaseFactory, _objectPathFactory, _applicationConfiguration, _lazyLoadTask, representationInfoRepository, _calculationMethodCategoryRepository); + sut = new IndividualToIndividualBuildingBlockMapper(_objectBaseFactory, _objectPathFactory, _applicationConfiguration, _lazyLoadTask, representationInfoRepository, _calculationMethodCategoryRepository, _cloner); } - private void updateOriginDataForTest(OriginData originData) - { + private void updateIndividualForTest(Individual individual) + { //add a parameter with a formula starting with ROOT so that we can test that this is being dealt with properly + var parameterWithFormula = DomainHelperForSpecs.ConstantParameterWithValue(0).WithName("FormulaParameter"); + parameterWithFormula.Formula = new ExplicitFormula("P2").WithName("FormulaParameterFormula"); + parameterWithFormula.Formula.AddObjectPath(new FormulaUsablePath("ROOT", "ORGANISM", "P2").WithAlias("P2")); + + //for this formula, we return a real one to make sure we have actually changed the ROOT + var cloneFormula = new ExplicitFormula("P2").WithName("FormulaParameterFormula"); + cloneFormula.AddObjectPath(new FormulaUsablePath("ROOT", "ORGANISM", "P2").WithAlias("P2")); + + A.CallTo(() => _cloner.Clone(parameterWithFormula.Formula)).Returns(cloneFormula); + individual.Organism.Add(parameterWithFormula); + + var originData = individual.OriginData; originData.Gender.DisplayName = originData.Gender.Name; originData.Population.DisplayName = originData.Population.Name; originData.Age = new OriginDataParameter(1, "year", "Age"); @@ -51,7 +72,6 @@ private void updateOriginDataForTest(OriginData originData) _category1 = new CalculationMethodCategory(); - var calculationMethod = new CalculationMethod { DisplayName = "method1", @@ -114,5 +134,13 @@ public void the_properties_of_the_building_block_should_match() _buildingBlock.OriginData.AllDataItems.Count(x => x.Name.Equals("displayName")).ShouldBeEqualTo(1); _buildingBlock.OriginData.AllDataItems.Count.ShouldBeEqualTo(8); } + + [Observation] + public void should_have_replaced_the_ROOT_key_element_path_in_all_formula() + { + var formula = _buildingBlock.FormulaCache.FindByName("FormulaParameterFormula"); + formula.ObjectPaths.Count.ShouldBeEqualTo(1); + formula.ObjectPaths[0].ToPathString().ShouldBeEqualTo("ORGANISM|P2"); + } } } \ No newline at end of file diff --git a/tests/PKSim.UI.Tests/PKSim.UI.Tests.csproj b/tests/PKSim.UI.Tests/PKSim.UI.Tests.csproj index 263d5e496..326440063 100644 --- a/tests/PKSim.UI.Tests/PKSim.UI.Tests.csproj +++ b/tests/PKSim.UI.Tests/PKSim.UI.Tests.csproj @@ -29,10 +29,10 @@ - + - - + +