コード例 #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
ファイル: BuildingBlockTask.cs プロジェクト: valdiman/PK-Sim
        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);
        }
コード例 #3
0
ファイル: ProtocolTask.cs プロジェクト: valdiman/PK-Sim
        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));
        }
コード例 #4
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);
        }