Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        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);
                }
            }
        }
Ejemplo n.º 3
0
        public void ConfigurePopulationSimulationComparison(PopulationSimulationComparison simulationComparison)
        {
            _executionContext.Load(simulationComparison);
            using (var presenter = _applicationController.Start <ISimulationSelectionForComparisonPresenter>())
            {
                if (!presenter.Edit(simulationComparison))
                {
                    return;
                }

                _executionContext.ProjectChanged();
                var presenterWasOpen = _applicationController.HasPresenterOpenedFor(simulationComparison);

                //presenter was not open, nothing to do
                if (!presenterWasOpen)
                {
                    return;
                }

                _applicationController.Close(simulationComparison);
                _singleStartPresenterTask.StartForSubject(simulationComparison);
            }
        }