1212#include " application/ProjectPersistence.h"
1313#include " application/ProjectNavigatorWidget.h"
1414#include " application/ScenarioAuthoringWidget.h"
15+ #include " application/ScenarioBatchResultWidget.h"
1516#include " application/ScenarioResultWidget.h"
1617#include " application/ScenarioRunWidget.h"
1718#include " domain/DemoFixtureService.h"
@@ -73,12 +74,17 @@ ProjectWorkspaceState makeEvacuationScenarioDemoWorkspace() {
7374 workspace.activeView = ProjectWorkspaceView::ScenarioResult;
7475 workspace.authoring = std::move (authoring);
7576 workspace.runningScenario = fixture.alternativeScenario ;
77+ workspace.runningScenarios = {fixture.baselineScenario , fixture.alternativeScenario };
7678 workspace.result = SavedScenarioResultState{
77- .scenario = std::move ( fixture.alternativeScenario ) ,
79+ .scenario = fixture.alternativeScenario ,
7880 .frame = std::move (fixture.frame ),
7981 .risk = std::move (fixture.risk ),
8082 .artifacts = std::move (fixture.artifacts ),
8183 };
84+ workspace.batchResult = SavedScenarioBatchResultState{
85+ .results = {*workspace.result },
86+ .currentResultIndex = 0 ,
87+ };
8288 return workspace;
8389}
8490
@@ -410,6 +416,15 @@ void MainWindow::openProject(const ProjectMetadata& metadata) {
410416 }
411417 break ;
412418 case ProjectWorkspaceView::ScenarioRun:
419+ if (!workspace.runningScenarios .empty ()) {
420+ showScenarioRun (
421+ *importResult.layout ,
422+ std::move (workspace.runningScenarios ),
423+ workspace.authoring .has_value ()
424+ ? std::make_optional (initialStateFromSaved (*workspace.authoring , *importResult.layout ))
425+ : std::nullopt );
426+ return ;
427+ }
413428 if (workspace.runningScenario .has_value ()) {
414429 showScenarioRun (
415430 *importResult.layout ,
@@ -421,6 +436,16 @@ void MainWindow::openProject(const ProjectMetadata& metadata) {
421436 }
422437 break ;
423438 case ProjectWorkspaceView::ScenarioResult:
439+ if (workspace.batchResult .has_value () && workspace.batchResult ->results .size () > 1 ) {
440+ showScenarioBatchResult (
441+ *importResult.layout ,
442+ workspace.batchResult ->results ,
443+ workspace.batchResult ->currentResultIndex ,
444+ workspace.authoring .has_value ()
445+ ? std::make_optional (initialStateFromSaved (*workspace.authoring , *importResult.layout ))
446+ : std::nullopt );
447+ return ;
448+ }
424449 if (workspace.result .has_value ()) {
425450 showScenarioResult (
426451 *importResult.layout ,
@@ -477,6 +502,22 @@ void MainWindow::saveCurrentProject() {
477502 if (auto * authoringWidget = visibleChild<ScenarioAuthoringWidget>(centralWidget ())) {
478503 workspace.activeView = ProjectWorkspaceView::ScenarioAuthoring;
479504 workspace.authoring = authoringWidget->currentSavedState ();
505+ } else if (auto * batchResultWidget = visibleChild<ScenarioBatchResultWidget>(centralWidget ())) {
506+ workspace.activeView = ProjectWorkspaceView::ScenarioResult;
507+ if (auto authoring = batchResultWidget->returnAuthoringState (); authoring.has_value ()) {
508+ workspace.authoring = savedStateFromInitial (*authoring);
509+ }
510+ workspace.batchResult = SavedScenarioBatchResultState{
511+ .results = batchResultWidget->results (),
512+ .currentResultIndex = batchResultWidget->currentResultIndex (),
513+ };
514+ if (!workspace.batchResult ->results .empty ()) {
515+ const auto index = std::clamp (
516+ workspace.batchResult ->currentResultIndex ,
517+ 0 ,
518+ static_cast <int >(workspace.batchResult ->results .size ()) - 1 );
519+ workspace.result = workspace.batchResult ->results [static_cast <std::size_t >(index)];
520+ }
480521 } else if (auto * resultWidget = visibleChild<ScenarioResultWidget>(centralWidget ())) {
481522 workspace.activeView = ProjectWorkspaceView::ScenarioResult;
482523 if (resultWidget->returnAuthoringState ().has_value ()) {
@@ -494,6 +535,7 @@ void MainWindow::saveCurrentProject() {
494535 workspace.authoring = savedStateFromInitial (*runWidget->returnAuthoringState ());
495536 }
496537 workspace.runningScenario = runWidget->scenario ();
538+ workspace.runningScenarios = runWidget->scenarios ();
497539 }
498540
499541 if (!ProjectPersistence::saveProjectWorkspace (currentProject_, workspace, &errorMessage)) {
@@ -603,10 +645,20 @@ void MainWindow::showScenarioRun(
603645 const safecrowd::domain::FacilityLayout2D& layout,
604646 const safecrowd::domain::ScenarioDraft& scenario,
605647 std::optional<ScenarioAuthoringWidget::InitialState> returnAuthoringState) {
648+ showScenarioRun (
649+ layout,
650+ std::vector<safecrowd::domain::ScenarioDraft>{scenario},
651+ std::move (returnAuthoringState));
652+ }
653+
654+ void MainWindow::showScenarioRun (
655+ const safecrowd::domain::FacilityLayout2D& layout,
656+ std::vector<safecrowd::domain::ScenarioDraft> scenarios,
657+ std::optional<ScenarioAuthoringWidget::InitialState> returnAuthoringState) {
606658 setCentralWidget (new ScenarioRunWidget (
607659 currentProject_.name ,
608660 layout,
609- scenario ,
661+ std::move (scenarios) ,
610662 [this ]() {
611663 saveCurrentProject ();
612664 },
@@ -622,8 +674,37 @@ void MainWindow::showScenarioRun(
622674 showLayoutReview (currentProject_);
623675 }
624676 },
625- this ,
626- std::move (returnAuthoringState)));
677+ std::move (returnAuthoringState),
678+ this ));
679+ }
680+
681+ void MainWindow::showScenarioBatchResult (
682+ const safecrowd::domain::FacilityLayout2D& layout,
683+ std::vector<SavedScenarioResultState> results,
684+ int currentResultIndex,
685+ std::optional<ScenarioAuthoringWidget::InitialState> returnAuthoringState) {
686+ setCentralWidget (new ScenarioBatchResultWidget (
687+ currentProject_.name ,
688+ layout,
689+ std::move (results),
690+ [this ]() {
691+ saveCurrentProject ();
692+ },
693+ [this ]() {
694+ hasCurrentProject_ = false ;
695+ currentProject_ = {};
696+ showProjectNavigator ();
697+ },
698+ [this ]() {
699+ if (lastApprovedImportResult_.has_value ()) {
700+ showLayoutReview (currentProject_, *lastApprovedImportResult_);
701+ } else {
702+ showLayoutReview (currentProject_);
703+ }
704+ },
705+ std::move (returnAuthoringState),
706+ currentResultIndex,
707+ this ));
627708}
628709
629710void MainWindow::showScenarioResult (
0 commit comments