private void configure(Simulation simulationToConfigure, Func <IConfigureSimulationPresenter, IPKSimCommand> configureAction) { _buildingBlockTask.Load(simulationToConfigure); using (var presenter = _applicationController.Start <IConfigureSimulationPresenter>()) { var activeSubject = _activeSubjectRetriever.Active <IPKSimBuildingBlock>(); var configureCommand = configureAction(presenter); //User cancel action. return if (configureCommand.IsEmpty()) { return; } //Before swapping simulation=>update results and charts information from the original simulation var simulation = presenter.Simulation; _simulationResultsTask.CopyResults(simulationToConfigure, simulation); _simulationSettingsRetriever.SynchronizeSettingsIn(simulation); //We have the same simulation=> we should update the id simulation.Id = simulationToConfigure.Id; _parameterIdUpdater.UpdateSimulationId(simulation); //was the presenter open for the simulation? if yes var presenterWasOpen = _applicationController.HasPresenterOpenedFor(simulationToConfigure); simulation.Creation.CreationMode = CreationMode.Configure; var swapSimulationCommand = new SwapSimulationCommand(simulationToConfigure, simulation, _executionContext).Run(_executionContext); swapSimulationCommand.ReplaceNameTemplateWithName(simulation.Name); swapSimulationCommand.ReplaceTypeTemplateWithType(PKSimConstants.ObjectTypes.Simulation); _buildingBlockTask.AddCommandToHistory(swapSimulationCommand); //no active presenter: nothing to do if (activeSubject == null) { return; } //presenter was not open, nothing to do if (!presenterWasOpen) { return; } //edit the simulation back, since it was edited _buildingBlockTask.Edit(simulation); //now, was the simulation the active presenter? if no, we need to active the other presenter if (activeSubject != simulationToConfigure) { _buildingBlockTask.Edit(activeSubject); } } }
public void RenameSimulation(Simulation simulation, string newName) { _buildingBlockTask.Load(simulation); //rename model, all object path and results //was the presenter open for the simulation? if yes var presenterWasOpen = _applicationController.HasPresenterOpenedFor(simulation); _applicationController.Close(simulation); //Model and root string oldName = simulation.Name; simulation.Name = newName; simulation.Model.Name = simulation.Name; simulation.Model.Root.Name = simulation.Name; _renameAbsolutePathVisitor.RenameAllAbsolutePathIn(simulation, oldName); _buildingBlockInSimulationManager.UpdateBuildingBlockNamesUsedIn(simulation); _simulationPathUpdater.UpdatePathsForRenamedSimulation(simulation, oldName, newName); //presenter was not open, nothing to do if (!presenterWasOpen) { return; } //edit the simulation back, since it was edited _buildingBlockTask.Edit(simulation); }
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); } }
protected override void PerformExecute() { _buildingBlockTask.Edit(Subject); }
protected void EditBuildingBlock(IPKSimBuildingBlock buildingBlock) { _buildingBlockTask.Edit(buildingBlock); }