示例#1
0
        private IPKSimMacroCommand updateParameters(PathCache <IParameter> allParameters, ParameterVariationSet parameterVariationSet)
        {
            var macroCommand = new PKSimMacroCommand();

            foreach (var parameterValue in parameterVariationSet.ParameterValues)
            {
                var parameterPath = parameterValue.ParameterPath;

                var parameter = allParameters[parameterPath];
                if (parameter == null)
                {
                    //try with adding the name of the simulation at first
                    parameterPath = $"{Simulation.Name}{ObjectPath.PATH_DELIMITER}{parameterPath}";
                    parameter     = allParameters[parameterPath];
                    if (parameter == null)
                    {
                        _logger.AddWarning($"Parameter with path '{parameterValue.ParameterPath}' not found!");
                        continue;
                    }
                }

                _logger.AddDebug($"Parameter '{parameterValue.ParameterPath}' value set from '{parameter.Value} to '{parameterValue.Value}'.");
                macroCommand.Add(new SetParameterValueCommand(parameter, parameterValue.Value));
            }

            return(macroCommand.Run(_executionContext));
        }
示例#2
0
        private ICommand setParameterValue(IParameter sourceParameter, IParameter targetParameter, bool forceUpdate)
        {
            //Always update the default value of the target parameter
            targetParameter.DefaultValue = sourceParameter.DefaultValue;
            if (!forceUpdate && areValuesEqual(targetParameter, sourceParameter))
            {
                //same value but not same display unit, simply update the display unit
                if (sourceParameter.DisplayUnit == targetParameter.DisplayUnit)
                {
                    return(null);
                }

                return(_parameterTask.SetParameterDisplayUnit(targetParameter, sourceParameter.DisplayUnit));
            }

            var setValueCommand = _parameterTask.SetParameterValue(targetParameter, sourceParameter.Value);

            //Only value differs
            if (sourceParameter.DisplayUnit == targetParameter.DisplayUnit)
            {
                return(setValueCommand);
            }

            //in that case, we create a macro command that updates value and unit
            var setDisplayUnitCommand = _parameterTask.SetParameterDisplayUnit(targetParameter, sourceParameter.DisplayUnit);
            var macroCommand          = new PKSimMacroCommand {
                CommandType = setValueCommand.CommandType, ObjectType = setValueCommand.ObjectType, Description = PKSimConstants.Command.SetParameterValueAndDisplayUnitDescription
            };

            macroCommand.Add(setValueCommand);
            macroCommand.Add(setDisplayUnitCommand);
            return(macroCommand);
        }
示例#3
0
        public ICommand UpdateMoleculeName(ExpressionProfile expressionProfile, string newMoleculeName)
        {
            var command = new PKSimMacroCommand();

            var oldMoleculeName = expressionProfile.MoleculeName;

            //we are not renaming anything
            if (string.Equals(newMoleculeName, oldMoleculeName))
            {
                return(command);
            }

            var(_, individual) = expressionProfile;
            var mainCommand = renameMoleculeReferences(individual, oldMoleculeName, newMoleculeName);

            command.Add(mainCommand);
            command.UpdatePropertiesFrom(mainCommand);
            allSimulationSubjectsUsing(expressionProfile).Each(x =>
            {
                _lazyLoadTask.Load(x);
                command.Add(renameMoleculeReferences(x, oldMoleculeName, newMoleculeName));
            });


            return(command);
        }
示例#4
0
        public ICommand ExtractIndividualsFromPopulationCommand(Population population, IndividualExtractionOptions individualExtractionOptions)
        {
            if (population.IsAnImplementationOf <MoBiPopulation>())
            {
                throw new PKSimException(PKSimConstants.Error.CannotExtractIndividualFrom(_executionContext.TypeFor(population)));
            }

            var allPopulationParameters = population.AllVectorialParameters(_entityPathResolver).ToList();

            var allDistributedParameters = allPopulationParameters.Where(x => x.Formula.IsDistributed()).ToList();
            var allConstantParameters    = allPopulationParameters.Where(x => x.Formula.IsConstant()).ToList();
            var allRemainingParameters   = allPopulationParameters.Except(allConstantParameters).Except(allDistributedParameters);

            //Update constant parameters first, then distributed and last all others. This ensures that formula parameters in the extracted individuals are not updated with a constant value
            var allParametersOrderedByFormulaType = allConstantParameters.Union(allDistributedParameters).Union(allRemainingParameters).ToList();

            var addCommands = individualExtractionOptions.IndividualIds.Distinct()
                              .Select(individualId => extractIndividualFrom(population, individualId, allParametersOrderedByFormulaType, individualExtractionOptions))
                              .ToList();

            var overallCommand = new PKSimMacroCommand
            {
                CommandType       = PKSimConstants.Command.CommandTypeAdd,
                ObjectType        = PKSimConstants.ObjectTypes.Population,
                Description       = PKSimConstants.Command.ExtractingIndividualsDescription(population.Name),
                BuildingBlockName = population.Name,
                BuildingBlockType = PKSimConstants.ObjectTypes.Population
            };

            overallCommand.AddRange(addCommands);

            return(overallCommand);
        }
示例#5
0
        private IOSPSuiteCommand withUpdatedDefaultStateAndValue(IOSPSuiteCommand executedCommand, IParameter parameter, bool shouldChangeVersion = true, bool shouldUpdateDefaultStateAndValueOriginForDefaultParameter = true)
        {
            if (!shouldUpdateDefaultStateAndValueOriginForDefaultParameter)
            {
                return(executedCommand);
            }

            if (!parameter.IsDefault)
            {
                return(executedCommand);
            }

            if (executedCommand.IsEmpty())
            {
                return(executedCommand);
            }

            var macroCommand = new PKSimMacroCommand().WithHistoryEntriesFrom(executedCommand);

            macroCommand.Add(executedCommand);
            macroCommand.Add(new SetParameterDefaultStateCommand(parameter, isDefault: false)
            {
                ShouldChangeVersion = shouldChangeVersion
            }.Run(_executionContext).AsHidden());

            var setValueOriginCommand = setParameterValueOrigin(parameter, ValueOrigin.Unknown, shouldChangeVersion).AsHidden();

            macroCommand.Add(setValueOriginCommand);
            return(macroCommand);
        }
        protected override void Context()
        {
            _macroCommand                     = new PKSimMacroCommand();
            _macroCommand.Description         = "my name is " + CoreConstants.ContainerName.NameTemplate;
            _macroCommand.ExtendedDescription = "my extended is " + CoreConstants.ContainerName.NameTemplate;

            _subCommand                     = A.Fake <IPKSimCommand>();
            _subCommand.Description         = null;
            _subCommand.ExtendedDescription = "extended is " + CoreConstants.ContainerName.NameTemplate;

            _macroCommand.Add(_subCommand);
        }
示例#7
0
        private ICommand macroCommandFrom(Population population, ICommand baseCommand, IEnumerable <ICommand> commands)
        {
            var macroCommand = new PKSimMacroCommand
            {
                ObjectType  = baseCommand.ObjectType,
                Description = baseCommand.Description,
                CommandType = baseCommand.CommandType
            };

            macroCommand.AddRange(commands);
            _executionContext.UpdateBuildingBlockPropertiesInCommand(macroCommand, population);
            return(macroCommand);
        }
 public ICommand AddMoleculeVariability(IndividualMolecule molecule, Population population, bool usePredefinedMeanVariability)
 {
    var macroCommand = new PKSimMacroCommand(new[]
    {
       addParameterVariability(molecule, molecule.ReferenceConcentration, population, usePredefinedMeanVariability),
       addParameterVariability(molecule, molecule.HalfLifeLiver, population, usePredefinedMeanVariability),
       addParameterVariability(molecule, molecule.HalfLifeIntestine, population, usePredefinedMeanVariability)
    })
    {
       CommandType = PKSimConstants.Command.CommandTypeAdd,
       ObjectType = PKSimConstants.ObjectTypes.Population,
       Description = PKSimConstants.Command.AddDefaultVariabilityToPopulation(population.Name)
    };
    _executionContext.UpdateBuildingBlockPropertiesInCommand(macroCommand, population);
    return macroCommand;
 }
        private IPKSimCommand createProcessFor <TCompoundProcess, TCreateProcessPresenter>(Compound compound, IEnumerable <TCompoundProcess> templates, string defaultMoleculeName)
            where TCompoundProcess : CompoundProcess
            where TCreateProcessPresenter : ICreateProcessPresenter
        {
            using (var editPresenter = _applicationController.Start <TCreateProcessPresenter>())
            {
                var partialPresenter = editPresenter as ICreatePartialProcessPresenter;
                if (partialPresenter != null)
                {
                    partialPresenter.DefaultMoleculeName = defaultMoleculeName;
                }

                var editCommands = editPresenter.CreateProcess(compound, templates);

                //Canceled by user
                if (editCommands.IsEmpty())
                {
                    return(editCommands);
                }

                var process = editPresenter.Process;

                //create + add command are added as one action into the history
                var overallCommand = new PKSimMacroCommand {
                    CommandType = PKSimConstants.Command.CommandTypeAdd
                };
                _executionContext.UpdateBuildingBlockPropertiesInCommand(overallCommand, compound);

                //First add process to compound so that it will be available for later rollbacks
                var addProcessToCompound = new AddProcessToCompoundCommand(process, compound, _executionContext).Run(_executionContext);
                overallCommand.Add(addProcessToCompound);
                overallCommand.Description = addProcessToCompound.Description;
                overallCommand.ObjectType  = addProcessToCompound.ObjectType;

                _executionContext.UpdateBuildingBlockPropertiesInCommand(editCommands, compound);

                var macroCommand = editCommands as IPKSimMacroCommand;
                if (macroCommand != null)
                {
                    macroCommand.ReplaceNameTemplateWithName(compound.Name);
                    macroCommand.ReplaceTypeTemplateWithType(_executionContext.TypeFor(compound));
                    macroCommand.All().Each(overallCommand.Add);
                }

                return(overallCommand);
            }
        }
示例#10
0
        public ICommand UpdateParametersFromSimulationInBuildingBlock(Simulation simulation, IPKSimBuildingBlock templateBuildingBlock)
        {
            //Update the building block in the simulation based on the same template
            var usedBuildingBlock = simulation.UsedBuildingBlockByTemplateId(templateBuildingBlock.Id);

            //Template was not used in the simulation...return
            if (usedBuildingBlock == null)
            {
                return(null);
            }

            var buildingBlockType           = _executionContext.TypeFor(templateBuildingBlock);
            var templateParameters          = parametersToUpdateFrom(templateBuildingBlock);
            var usedBuildingBlockParameters = parametersToUpdateFrom(usedBuildingBlock.BuildingBlock);
            var updateCommands = new PKSimMacroCommand
            {
                ObjectType        = buildingBlockType,
                BuildingBlockType = buildingBlockType,
                BuildingBlockName = templateBuildingBlock.Name,
                CommandType       = PKSimConstants.Command.CommandTypeUpdate,
                Description       = PKSimConstants.Command.UpdateTemplateBuildingBlockCommandDescription(buildingBlockType, templateBuildingBlock.Name, simulation.Name)
            };

            _executionContext.UpdateBuildingBlockPropertiesInCommand(updateCommands, templateBuildingBlock);

            //First Update the parameters in the template building block (the parameter in the used building block are synchronized with the one used in the simulation)
            var updateTemplateParametersCommand = updateParameterValues(usedBuildingBlockParameters, templateParameters);

            updateTemplateParametersCommand.Description = PKSimConstants.Command.UpdateTemplateParameterCommandDescription(templateBuildingBlock.Name, buildingBlockType, simulation.Name);
            _executionContext.UpdateBuildingBlockPropertiesInCommand(updateTemplateParametersCommand, templateBuildingBlock);

            updateCommands.Add(updateTemplateParametersCommand);

            //Last, see if we have some special cases to handle
            var synchronizeCommand = synchronizeBuildingBlocks(templateBuildingBlock, updateTemplateParametersCommand);

            updateCommands.Add(synchronizeCommand);

            //now make sure that the used building block is updated with the template building block info
            updateCommands.Add(new UpdateUsedBuildingBlockInfoCommand(simulation, usedBuildingBlock, templateBuildingBlock, _executionContext).Run(_executionContext));

            _executionContext.PublishEvent(new BuildingBlockUpdatedEvent(templateBuildingBlock));
            return(updateCommands);
        }
示例#11
0
        public IOSPSuiteCommand UpdateValues(PathCache <IParameter> sourceParameters, PathCache <IParameter> targetParameters, bool updateParameterOriginId = true)
        {
            var updateCommands = new PKSimMacroCommand {
                CommandType = PKSimConstants.Command.CommandTypeEdit, ObjectType = PKSimConstants.ObjectTypes.Parameter
            };

            //should update non distributed parameter first and then distributed parameter
            foreach (var sourceParameter in sourceParameters.KeyValues.OrderBy(x => x.Value.IsDistributed()))
            {
                var targetParameter = targetParameters[sourceParameter.Key];
                if (targetParameter == null)
                {
                    continue;
                }

                updateCommands.Add(UpdateValue(sourceParameter.Value, targetParameter, updateParameterOriginId));
            }
            return(updateCommands);
        }
示例#12
0
        private ICommand removeAdvancedParametersForMolecule(IndividualMolecule molecule, Population population)
        {
            var macroCommand = new PKSimMacroCommand
            {
                CommandType = PKSimConstants.Command.CommandTypeDelete,
                Description = PKSimConstants.Command.RemoveAdvancedParametersForMoleculeInPopulation(molecule.Name, population.Name)
            };

            foreach (var parameter in molecule.GetAllChildren <IParameter>())
            {
                var advancedParameter = population.AdvancedParameterFor(_entityPathResolver, parameter);
                if (advancedParameter != null)
                {
                    macroCommand.AddCommand(new RemoveAdvancedParameterFromContainerCommand(advancedParameter, population, _executionContext).Run(_executionContext));
                }
            }

            _executionContext.UpdateBuildingBlockPropertiesInCommand(macroCommand, population);
            return(macroCommand);
        }
示例#13
0
        public bool Delete <TBuildingBlock>(IReadOnlyList <TBuildingBlock> buildingBlocksToDelete) where TBuildingBlock : class, IPKSimBuildingBlock
        {
            if (!buildingBlocksToDelete.Any())
            {
                return(true);
            }

            var buildingBlockType = _entityTask.TypeFor(buildingBlocksToDelete.First());

            foreach (var buildingBlockToDelete in buildingBlocksToDelete)
            {
                var simulationsUsingBuildingBlockToDelete = _buildingBlockInSimulationManager.SimulationsUsing(buildingBlockToDelete).ToList();
                if (simulationsUsingBuildingBlockToDelete.Any())
                {
                    throw new CannotDeleteBuildingBlockException(buildingBlockToDelete.Name, buildingBlockType, simulationsUsingBuildingBlockToDelete);
                }
            }

            var viewResult = _dialogCreator.MessageBoxYesNo(PKSimConstants.UI.ReallyDeleteObjectOfType(buildingBlockType, buildingBlocksToDelete.AllNames().ToArray()));

            if (viewResult == ViewResult.No)
            {
                return(false);
            }

            buildingBlocksToDelete.OfType <Simulation>().Each(simulation => _simulationReferenceUpdater.RemoveSimulationFromParameterIdentificationsAndSensitivityAnalyses(simulation));

            var macoCommand = new PKSimMacroCommand
            {
                CommandType       = PKSimConstants.Command.CommandTypeDelete,
                ObjectType        = buildingBlockType,
                BuildingBlockType = buildingBlockType,
                Description       = PKSimConstants.Command.ObjectsDeletedFromProject(buildingBlockType),
            };

            buildingBlocksToDelete.Each(x => macoCommand.Add(DeleteCommand(x)));
            AddCommandToHistory(macoCommand.Run(_executionContext));
            buildingBlocksToDelete.Each(RemovePresenterSettings);

            return(true);
        }
示例#14
0
        public ICommand UpdateValuesByName(IEnumerable <IParameter> sourceParameters, IEnumerable <IParameter> targetParameters)
        {
            var updateCommands = new PKSimMacroCommand {
                CommandType = PKSimConstants.Command.CommandTypeEdit, ObjectType = PKSimConstants.ObjectTypes.Parameter
            };
            var targetParameterCache = new Cache <string, IParameter>(p => p.Name, key => null);

            targetParameterCache.AddRange(targetParameters);

            foreach (var sourceParameter in sourceParameters)
            {
                var targetParameter = targetParameterCache[sourceParameter.Name];
                if (targetParameter == null)
                {
                    continue;
                }

                updateCommands.Add(UpdateValue(sourceParameter, targetParameter));
            }
            return(updateCommands);
        }
示例#15
0
        public void ScaleIndividual(Individual individualToScale)
        {
            _buildingBlockTask.Load(individualToScale);

            using (var presenter = _applicationController.Start <IScaleIndividualPresenter>())
            {
                var scaleCommand = presenter.ScaleIndividual(individualToScale);

                //User cancel action. return
                if (scaleCommand.IsEmpty())
                {
                    return;
                }

                var scaledIndividual = presenter.Individual;
                var overallCommand   = new PKSimMacroCommand
                {
                    CommandType       = PKSimConstants.Command.CommandTypeScale,
                    ObjectType        = PKSimConstants.ObjectTypes.Individual,
                    Description       = PKSimConstants.Command.ScaleIndividualDescription(individualToScale.Name, scaledIndividual.Name),
                    BuildingBlockName = scaledIndividual.Name,
                    BuildingBlockType = PKSimConstants.ObjectTypes.Individual
                };

                //indvidual was not scaled but cloned. Create a new individual
                var addToProjectCommand = new AddBuildingBlockToProjectCommand(scaledIndividual, _executionContext).Run(_executionContext);
                overallCommand.Add(addToProjectCommand);

                //these needs to be done afterwards in order to be able to undo the scaling action
                var macroCommand = scaleCommand as IPKSimMacroCommand;
                if (macroCommand != null)
                {
                    macroCommand.All().Each(overallCommand.Add);
                }
                overallCommand.ReplaceNameTemplateWithName(scaledIndividual.Name);
                overallCommand.ReplaceTypeTemplateWithType(PKSimConstants.ObjectTypes.Individual);

                _buildingBlockTask.AddCommandToHistory(overallCommand);
            }
        }
示例#16
0
        private ICommand withUpdatedValueOrigin(ICommand command, IParameter sourceParameter, IParameter targetParameter)
        {
            if (Equals(sourceParameter.ValueOrigin, targetParameter.ValueOrigin))
            {
                return(command);
            }

            var updateValueOriginCommand = _parameterTask.SetParameterValueOrigin(targetParameter, sourceParameter.ValueOrigin);

            if (command == null)
            {
                return(updateValueOriginCommand);
            }

            var macroCommand = new PKSimMacroCommand {
                CommandType = command.CommandType, ObjectType = command.ObjectType, Description = command.Description
            };

            macroCommand.Add(command);
            macroCommand.Add(updateValueOriginCommand);
            return(macroCommand);
        }
示例#17
0
        public IPKSimCommand SetTargetOrgan(ISchemaItem schemaItem, string targetOrgan, string targetCompartment)
        {
            var organCommand = new SetSchemaItemTargetOrganCommand(schemaItem, targetOrgan, _executionContext);

            if (schemaItem.TargetCompartment == targetCompartment)
            {
                return(organCommand.Run(_executionContext));
            }

            var macroCommand = new PKSimMacroCommand {
                CommandType = organCommand.CommandType, Description = organCommand.Description, ObjectType = organCommand.ObjectType
            };

            organCommand.Visible = false;
            var compartmentCommand = new SetSchemaItemTargetCompartmentCommand(schemaItem, targetCompartment, _executionContext)
            {
                Visible = false
            };

            macroCommand.Add(organCommand, compartmentCommand);
            return(macroCommand.Run(_executionContext));
        }
        public ICommand UpdateParametersFromBuildingBlockInSimulation(IPKSimBuildingBlock templateBuildingBlock, Simulation simulation)
        {
            //Update the building block in the simulation based on the same template
            var usedBuildingBlock = simulation.UsedBuildingBlockByTemplateId(templateBuildingBlock.Id);

            //Template was not used in the simulation...return
            if (usedBuildingBlock == null)
            {
                return(null);
            }

            string buildingBlockType           = _executionContext.TypeFor(templateBuildingBlock);
            var    templateParameters          = parametersToUpdateFrom(templateBuildingBlock);
            var    usedBuildingBlockParameters = parametersToUpdateFrom(usedBuildingBlock.BuildingBlock);
            var    updateCommands = new PKSimMacroCommand();

            //First Update the parameters in the used building block (internal command, should be visible = false)
            var updateUsedBuildingBlockParameterCommand = updateParameterValues(templateParameters, usedBuildingBlockParameters);

            updateUsedBuildingBlockParameterCommand.Visible     = false;
            updateUsedBuildingBlockParameterCommand.Description = PKSimConstants.Command.UpdateUsedBuildingBlockParameterCommandDescription(templateBuildingBlock.Name, buildingBlockType, simulation.Name);
            updateCommands.Add(updateUsedBuildingBlockParameterCommand);

            //then update the values in the simulation from the used building block
            foreach (var command in updateParameterValues(usedBuildingBlockParameters, simulation, usedBuildingBlock.BuildingBlockType))
            {
                updateCommands.Add(command);
            }

            //now make sure that the used building block is updated with the template building block info
            updateCommands.Add(new UpdateUsedBuildingBlockInfoCommand(simulation, usedBuildingBlock, templateBuildingBlock, _executionContext).Run(_executionContext));

            updateCommands.ObjectType  = PKSimConstants.ObjectTypes.Simulation;
            updateCommands.CommandType = PKSimConstants.Command.CommandTypeUpdate;
            updateCommands.Description = PKSimConstants.Command.UpdateBuildingBlockCommandDescription(buildingBlockType, templateBuildingBlock.Name, simulation.Name);
            _executionContext.UpdateBuildinBlockPropertiesInCommand(updateCommands, simulation);
            return(updateCommands);
        }
        public ICommand UpdateParametersFromSimulationInBuildingBlock(Simulation simulation, IPKSimBuildingBlock templateBuildingBlock)
        {
            //Update the building block in the simulation based on the same template
            var usedBuildingBlock = simulation.UsedBuildingBlockByTemplateId(templateBuildingBlock.Id);

            //Template was not used in the simulation...return
            if (usedBuildingBlock == null)
            {
                return(null);
            }

            var buildingBlockType           = _executionContext.TypeFor(templateBuildingBlock);
            var templateParameters          = _containerTask.CacheAllChildren <IParameter>(templateBuildingBlock);
            var usedBuildingBlockParameters = _containerTask.CacheAllChildren <IParameter>(usedBuildingBlock.BuildingBlock);
            var updateCommands = new PKSimMacroCommand();

            //First Update the parameters in the template building block (the parameter in the used building block are synchronized with the one used in the simulation)
            var updateTemplateParametersCommand = updateParameterValues(usedBuildingBlockParameters, templateParameters);

            updateTemplateParametersCommand.Description = PKSimConstants.Command.UpdateTemplateParameterCommandDescription(templateBuildingBlock.Name, buildingBlockType, simulation.Name);
            _executionContext.UpdateBuildinBlockPropertiesInCommand(updateTemplateParametersCommand, templateBuildingBlock);

            updateCommands.Add(updateTemplateParametersCommand);

            //now make sure that the used building block is updated with the template building block info
            updateCommands.Add(new UpdateUsedBuildingBlockInfoCommand(simulation, usedBuildingBlock, templateBuildingBlock, _executionContext).Run(_executionContext));

            updateCommands.ObjectType        = buildingBlockType;
            updateCommands.BuildingBlockType = buildingBlockType;
            updateCommands.BuildingBlockName = templateBuildingBlock.Name;
            updateCommands.CommandType       = PKSimConstants.Command.CommandTypeUpdate;
            updateCommands.Description       = PKSimConstants.Command.UpdateTemplateBuildingBlockCommandDescription(buildingBlockType, templateBuildingBlock.Name, simulation.Name);
            _executionContext.UpdateBuildinBlockPropertiesInCommand(updateCommands, templateBuildingBlock);

            _executionContext.PublishEvent(new BuildingBlockUpdatedEvent(templateBuildingBlock));
            return(updateCommands);
        }
示例#20
0
        public void ScaleIndividual(Individual individualToScale)
        {
            _buildingBlockTask.Load(individualToScale);

            using (var presenter = _applicationController.Start <IScaleIndividualPresenter>())
            {
                var scaleCommand = presenter.ScaleIndividual(individualToScale);

                //User cancel action. return
                if (scaleCommand.IsEmpty())
                {
                    return;
                }

                var scaledIndividual = presenter.Individual;
                var overallCommand   = new PKSimMacroCommand
                {
                    CommandType       = PKSimConstants.Command.CommandTypeScale,
                    ObjectType        = PKSimConstants.ObjectTypes.Individual,
                    Description       = PKSimConstants.Command.ScaleIndividualDescription(individualToScale.Name, scaledIndividual.Name),
                    BuildingBlockName = scaledIndividual.Name,
                    BuildingBlockType = PKSimConstants.ObjectTypes.Individual
                };

                //Do not add to history as the add action should be part of the overall command
                var addToProjectCommand = _buildingBlockTask.AddToProject(scaledIndividual, addToHistory: false);
                overallCommand.Add(addToProjectCommand);

                //these needs to be done afterwards in order to be able to undo the scaling action
                var macroCommand = scaleCommand as IPKSimMacroCommand;
                macroCommand?.All().Each(overallCommand.Add);
                overallCommand.ReplaceNameTemplateWithName(scaledIndividual.Name);
                overallCommand.ReplaceTypeTemplateWithType(PKSimConstants.ObjectTypes.Individual);

                _buildingBlockTask.AddCommandToHistory(overallCommand);
            }
        }
        private ICommand setParameterValue(IParameter sourceParameter, IParameter targetParameter, bool forceUpdate)
        {
            //If the parameter we are updating from is a default parameter, the target parameter should either remain as is (default or not default)
            bool shouldUpdateDefaultState = !sourceParameter.IsDefault;

            //Always update the default value of the target parameter
            targetParameter.DefaultValue = sourceParameter.DefaultValue;
            if (!forceUpdate && areValuesEqual(targetParameter, sourceParameter))
            {
                //same value but not same display unit, simply update the display unit
                if (areDisplayUnitsEqual(targetParameter, sourceParameter))
                {
                    return(null);
                }

                return(_parameterTask.SetParameterDisplayUnit(targetParameter, sourceParameter.DisplayUnit, shouldUpdateDefaultState));
            }

            var setValueCommand = _parameterTask.SetParameterValue(targetParameter, sourceParameter.Value, shouldUpdateDefaultState);

            //Only value differs
            if (areDisplayUnitsEqual(targetParameter, sourceParameter))
            {
                return(setValueCommand);
            }

            //in that case, we create a macro command that updates value and unit
            var setDisplayUnitCommand = _parameterTask.SetParameterDisplayUnit(targetParameter, sourceParameter.DisplayUnit, shouldUpdateDefaultState);
            var macroCommand          = new PKSimMacroCommand {
                CommandType = setValueCommand.CommandType, ObjectType = setValueCommand.ObjectType, Description = PKSimConstants.Command.SetParameterValueAndDisplayUnitDescription
            };

            macroCommand.Add(setValueCommand);
            macroCommand.Add(setDisplayUnitCommand);
            return(macroCommand);
        }
示例#22
0
 public override void Initialize()
 {
     _macroCommand = new PKSimMacroCommand();
     InitializeWith(_macroCommand);
 }
示例#23
0
        private ICommand synchronizeBuildingBlocks(IPKSimBuildingBlock templateBuildingBlock, IPKSimMacroCommand updateTemplateParametersCommand)
        {
            var simulationSubject = templateBuildingBlock as ISimulationSubject;

            //For now, deal with update from Individual or Population into Expression Profile
            if (simulationSubject == null)
            {
                return(new PKSimEmptyCommand());
            }

            var allExpressionProfileParameterValueCommand = updateTemplateParametersCommand.All()
                                                            .OfType <SetExpressionProfileValueCommand>()
                                                            .ToList();

            if (!allExpressionProfileParameterValueCommand.Any())
            {
                return(new PKSimEmptyCommand());
            }


            var expressionProfilesToUpdate = new HashSet <ExpressionProfile>();
            var macroCommand = new PKSimMacroCommand();

            //We have some commands related to expression profile. We need to update the expression profile
            foreach (var parameterCommand in allExpressionProfileParameterValueCommand)
            {
                var simulationSubjectParameter = _executionContext.Get <IParameter>(parameterCommand.ParameterId);
                if (simulationSubjectParameter == null)
                {
                    continue;
                }

                //This should be the id of the parameter in the expression profile
                var expressionProfileParameterId = simulationSubjectParameter.Origin.ParameterId;
                var expressionProfileParameter   = _executionContext.Get <IParameter>(expressionProfileParameterId);
                if (expressionProfileParameter == null)
                {
                    continue;
                }

                var expressionProfile = _executionContext.BuildingBlockContaining(expressionProfileParameter) as ExpressionProfile;
                if (expressionProfile == null)
                {
                    continue;
                }

                expressionProfilesToUpdate.Add(expressionProfile);

                //We do not update the simulation subject. It will be done at the end of the loop
                var command = new SetExpressionProfileValueCommand(expressionProfileParameter, simulationSubjectParameter.Value, updateSimulationSubjects: false);
                macroCommand.Add(command);
            }

            macroCommand.Run(_executionContext);
            _executionContext.UpdateBuildingBlockPropertiesInCommand(macroCommand, templateBuildingBlock);

            //Now that our expression profile are updated, we need to trigger the synchronization in all building blocks
            expressionProfilesToUpdate.Each(x => _expressionProfileUpdater.SynchronizeAllSimulationSubjectsWithExpressionProfile(x));

            return(macroCommand);
        }
示例#24
0
 protected override void Because()
 {
     _result = sut.AddMoleculeVariability(_molecule1, _randomPopulation, true) as PKSimMacroCommand;
 }
示例#25
0
 protected override void Because()
 {
     _result = sut.RemoveMoleculeFrom(_molecule, _population) as PKSimMacroCommand;
 }
示例#26
0
 protected override void Because()
 {
     _result = sut.AddMoleculeTo(_molecule, _population) as PKSimMacroCommand;
 }
示例#27
0
 protected override void Because()
 {
     _setCommand = sut.SetParameterValue(_parameter, 10) as PKSimMacroCommand;
 }
 protected override void Because()
 {
     _command = sut.UpdateValueOrigin(_parameterAlternative, _newValueOrigin) as PKSimMacroCommand;
 }