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); }
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); }
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); }
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)); }
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); }
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); }
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); }
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); }
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); }
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); } }
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); }
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); }
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); }
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); } }
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 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 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); }