public void Clone(Simulation simulationToClone) { if (_buildingBlockInSimulationManager.StatusFor(simulationToClone) != BuildingBlockStatus.Green) { throw new PKSimException(PKSimConstants.Error.SimulationCloneOnlyAvailableWhenBuildingBlocksAreUptodate); } _buildingBlockTask.Load(simulationToClone); using (var presenter = _applicationController.Start <ICloneSimulationPresenter>()) { var cloneCommand = presenter.CloneSimulation(simulationToClone); //User cancel action. return if (cloneCommand.IsEmpty()) { return; } var clone = presenter.Simulation; _simulationResultsTask.CloneResults(simulationToClone, clone); clone.Creation.AsCloneOf(simulationToClone); _simulationSettingsRetriever.SynchronizeSettingsIn(clone); var addCommand = new AddBuildingBlockToProjectCommand(clone, _executionContext).Run(_executionContext); addCommand.Description = PKSimConstants.Command.CloneEntity(PKSimConstants.ObjectTypes.Simulation, simulationToClone.Name, clone.Name); _buildingBlockTask.AddCommandToHistory(addCommand); //after clone => we go in edit mode _buildingBlockTask.Edit(clone); } }
public IPKSimCommand AddToProject <TBuildingBlock>(TBuildingBlock buildingBlock, bool editBuildingBlock = false) where TBuildingBlock : class, IPKSimBuildingBlock { if (!RenameBuildingBlockIfAlreadyUsed(buildingBlock)) { return(new PKSimEmptyCommand()); } //add buildingblock to project var addToProjectCommand = new AddBuildingBlockToProjectCommand(buildingBlock, _executionContext).Run(_executionContext); addToProjectCommand.ExtendedDescription = _executionContext.ReportFor(buildingBlock); AddCommandToHistory(addToProjectCommand); if (editBuildingBlock) { Edit(buildingBlock); } return(addToProjectCommand); }
public void Clone <TBuildingBlock>(TBuildingBlock buildingBlockToClone) where TBuildingBlock : class, IPKSimBuildingBlock { Load(buildingBlockToClone); using (var clonePresenter = _applicationController.Start <ICloneBuildingBlockPresenter>()) { var clone = clonePresenter.CreateCloneFor(buildingBlockToClone); if (clone == null) { return; } clone.Creation.AsCloneOf(buildingBlockToClone); var addCommand = new AddBuildingBlockToProjectCommand(clone, _executionContext).Run(_executionContext); var entityType = _entityTask.TypeFor(buildingBlockToClone); addCommand.Description = PKSimConstants.Command.CloneEntity(entityType, buildingBlockToClone.Name, clone.Name); AddCommandToHistory(addCommand); } }
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); } }
protected override void Context() { base.Context(); _buildingBlock.Name = "AA"; _clonedBuildingBlock = A.Fake <IPKSimBuildingBlock>(); A.CallTo(() => _clonePresenter.CreateCloneFor(_buildingBlock)).Returns(_clonedBuildingBlock); A.CallTo(() => _executionContext.AddToHistory(A <IPKSimCommand> .Ignored)).Invokes(x => _command = x.GetArgument <AddBuildingBlockToProjectCommand>(0)); }