diff --git a/source/Gui/AlienWindow.h b/source/Gui/AlienWindow.h index c779d63ed..b96b3928c 100644 --- a/source/Gui/AlienWindow.h +++ b/source/Gui/AlienWindow.h @@ -14,7 +14,7 @@ class AlienWindow : public ShutdownInterface void setOn(bool value); protected: - virtual void shutdownIntern() {}; + virtual void shutdownIntern() {} virtual void processIntern() = 0; virtual void processBackground() {} virtual void processActivated() {} diff --git a/source/Gui/AutosaveWindow.cpp b/source/Gui/AutosaveWindow.cpp index 34ecd5855..8448b52c2 100644 --- a/source/Gui/AutosaveWindow.cpp +++ b/source/Gui/AutosaveWindow.cpp @@ -16,11 +16,10 @@ namespace auto constexpr AutosaveSenderId = "Autosave"; } -_AutosaveWindow::_AutosaveWindow(SimulationFacade const& simulationFacade, PersisterFacade const& persisterFacade) - : AlienWindow("Autosave (work in progress)", "windows.autosave", false) - , _simulationFacade(simulationFacade) - , _persisterFacade(persisterFacade) +void AutosaveWindow::init(SimulationFacade const& simulationFacade, PersisterFacade const& persisterFacade) { + _simulationFacade = simulationFacade; + _persisterFacade = persisterFacade; _settingsOpen = GlobalSettings::get().getBool("windows.autosave.settings.open", _settingsOpen); _settingsHeight = GlobalSettings::get().getFloat("windows.autosave.settings.height", _settingsHeight); _autosaveEnabled = GlobalSettings::get().getBool("windows.autosave.enabled", _autosaveEnabled); @@ -31,7 +30,11 @@ _AutosaveWindow::_AutosaveWindow(SimulationFacade const& simulationFacade, Persi _numberOfFiles = GlobalSettings::get().getInt("windows.autosave.number of files", _origNumberOfFiles); } -_AutosaveWindow::~_AutosaveWindow() +AutosaveWindow::AutosaveWindow() + : AlienWindow("Autosave (work in progress)", "windows.autosave", false) +{} + +void AutosaveWindow::shutdownIntern() { GlobalSettings::get().setBool("windows.autosave.settings.open", _settingsOpen); GlobalSettings::get().setFloat("windows.autosave.settings.height", _settingsHeight); @@ -41,7 +44,7 @@ _AutosaveWindow::~_AutosaveWindow() GlobalSettings::get().setInt("windows.autosave.number of files", _numberOfFiles); } -void _AutosaveWindow::processIntern() +void AutosaveWindow::processIntern() { processToolbar(); @@ -58,7 +61,7 @@ void _AutosaveWindow::processIntern() validationAndCorrection(); } -void _AutosaveWindow::processToolbar() +void AutosaveWindow::processToolbar() { ImGui::SameLine(); if (AlienImGui::ToolbarButton(ICON_FA_SAVE)) { @@ -83,7 +86,7 @@ void _AutosaveWindow::processToolbar() AlienImGui::Separator(); } -void _AutosaveWindow::processHeader() +void AutosaveWindow::processHeader() { AlienImGui::InputInt( AlienImGui::InputIntParameters().name("Autosave interval (min)").textWidth(RightColumnWidth).defaultValue(_origAutosaveInterval), @@ -91,7 +94,7 @@ void _AutosaveWindow::processHeader() &_autosaveEnabled); } -void _AutosaveWindow::processTable() +void AutosaveWindow::processTable() { static ImGuiTableFlags flags = ImGuiTableFlags_Resizable | ImGuiTableFlags_Reorderable | ImGuiTableFlags_Hideable | ImGuiTableFlags_RowBg | ImGuiTableFlags_BordersOuter | ImGuiTableFlags_BordersV | ImGuiTableFlags_NoBordersInBody | ImGuiTableFlags_ScrollY | ImGuiTableFlags_ScrollX; @@ -148,7 +151,7 @@ void _AutosaveWindow::processTable() } } -void _AutosaveWindow::processSettings() +void AutosaveWindow::processSettings() { if (_settingsOpen) { ImGui::Spacing(); @@ -179,7 +182,7 @@ void _AutosaveWindow::processSettings() } } -void _AutosaveWindow::createSavepoint() +void AutosaveWindow::createSavepoint() { printOverlayMessage("Creating save point ..."); static int i = 0; @@ -190,7 +193,7 @@ void _AutosaveWindow::createSavepoint() _savePoints.emplace_front(SavepointState::InQueue, jobId.value, "", "", 0); } -void _AutosaveWindow::updateSavepoint(SavepointEntry& savepoint) +void AutosaveWindow::updateSavepoint(SavepointEntry& savepoint) { if (savepoint.state != SavepointState::Persisted) { auto requestState = _persisterFacade->getRequestState(PersisterRequestId(savepoint.id)); @@ -210,7 +213,7 @@ void _AutosaveWindow::updateSavepoint(SavepointEntry& savepoint) } } -void _AutosaveWindow::validationAndCorrection() +void AutosaveWindow::validationAndCorrection() { _numberOfFiles = std::max(1, _numberOfFiles); } diff --git a/source/Gui/AutosaveWindow.h b/source/Gui/AutosaveWindow.h index a14abcb70..44563ab28 100644 --- a/source/Gui/AutosaveWindow.h +++ b/source/Gui/AutosaveWindow.h @@ -23,13 +23,18 @@ struct SavepointEntry uint64_t timestep; }; -class _AutosaveWindow : public AlienWindow +class AutosaveWindow : public AlienWindow { + MAKE_SINGLETON_NO_DEFAULT_CONSTRUCTION(AutosaveWindow); + public: - _AutosaveWindow(SimulationFacade const& simulationFacade, PersisterFacade const& persisterFacade); - ~_AutosaveWindow() override; + void init(SimulationFacade const& simulationFacade, PersisterFacade const& persisterFacade); private: + AutosaveWindow(); + + void shutdownIntern() override; + void processIntern() override; void processToolbar(); diff --git a/source/Gui/Definitions.h b/source/Gui/Definitions.h index b83787cd0..cc8c9925e 100644 --- a/source/Gui/Definitions.h +++ b/source/Gui/Definitions.h @@ -31,8 +31,7 @@ class SimulationInteractionController; class GpuSettingsDialog; -class _NewSimulationDialog; -using NewSimulationDialog = std::shared_ptr<_NewSimulationDialog>; +class NewSimulationDialog; class StartupController; @@ -53,8 +52,7 @@ class AutosaveController; class GettingStartedWindow; -class _DisplaySettingsDialog; -using DisplaySettingsDialog = std::shared_ptr<_DisplaySettingsDialog>; +class DisplaySettingsDialog; class _EditorModel; using EditorModel = std::shared_ptr<_EditorModel>; @@ -84,15 +82,13 @@ using CreatorWindow = std::shared_ptr<_CreatorWindow>; class _MultiplierWindow; using MultiplierWindow = std::shared_ptr<_MultiplierWindow>; -class _PatternAnalysisDialog; -using PatternAnalysisDialog = std::shared_ptr<_PatternAnalysisDialog>; +class PatternAnalysisDialog; class FpsController; class BrowserWindow; -class _ShaderWindow; -using ShaderWindow = std::shared_ptr<_ShaderWindow>; +class ShaderWindow; class LoginDialog; @@ -104,20 +100,15 @@ class CreateUserDialog; class ActivateUserDialog; -class _DeleteUserDialog; -using DeleteUserDialog = std::shared_ptr<_DeleteUserDialog>; +class DeleteUserDialog; -class _NetworkSettingsDialog; -using NetworkSettingsDialog = std::shared_ptr<_NetworkSettingsDialog>; +class NetworkSettingsDialog; -class _ResetPasswordDialog; -using ResetPasswordDialog = std::shared_ptr<_ResetPasswordDialog>; +class ResetPasswordDialog; -class _NewPasswordDialog; -using NewPasswordDialog = std::shared_ptr<_NewPasswordDialog>; +class NewPasswordDialog; -class _ImageToPatternDialog; -using ImageToPatternDialog = std::shared_ptr<_ImageToPatternDialog>; +class ImageToPatternDialog; class _GenomeEditorWindow; using GenomeEditorWindow = std::shared_ptr<_GenomeEditorWindow>; @@ -127,8 +118,7 @@ class RadiationSourcesWindow; class _ChangeColorDialog; using ChangeColorDialog = std::shared_ptr<_ChangeColorDialog>; -class _AutosaveWindow; -using AutosaveWindow = std::shared_ptr<_AutosaveWindow>; +class AutosaveWindow; class FileTransferController; diff --git a/source/Gui/DeleteUserDialog.cpp b/source/Gui/DeleteUserDialog.cpp index 811e77a76..a0edef2ec 100644 --- a/source/Gui/DeleteUserDialog.cpp +++ b/source/Gui/DeleteUserDialog.cpp @@ -9,11 +9,11 @@ #include "CreateUserDialog.h" #include "MessageDialog.h" -_DeleteUserDialog::_DeleteUserDialog() +DeleteUserDialog::DeleteUserDialog() : AlienDialog("Delete user") {} -void _DeleteUserDialog::processIntern() +void DeleteUserDialog::processIntern() { AlienImGui::Text( "Warning: All the data of the user '" + *NetworkService::get().getLoggedInUserName() @@ -43,7 +43,7 @@ void _DeleteUserDialog::processIntern() } } -void _DeleteUserDialog::onDelete() +void DeleteUserDialog::onDelete() { auto userName = *NetworkService::get().getLoggedInUserName(); if (NetworkService::get().deleteUser()) { diff --git a/source/Gui/DeleteUserDialog.h b/source/Gui/DeleteUserDialog.h index 2e86117ce..5b208f8c1 100644 --- a/source/Gui/DeleteUserDialog.h +++ b/source/Gui/DeleteUserDialog.h @@ -1,16 +1,18 @@ #pragma once +#include "Base/Singleton.h" #include "Network/Definitions.h" #include "AlienDialog.h" #include "Definitions.h" -class _DeleteUserDialog : public AlienDialog +class DeleteUserDialog : public AlienDialog { -public: - _DeleteUserDialog(); + MAKE_SINGLETON_NO_DEFAULT_CONSTRUCTION(DeleteUserDialog); private: + DeleteUserDialog(); + void processIntern(); void onDelete(); diff --git a/source/Gui/DisplaySettingsDialog.cpp b/source/Gui/DisplaySettingsDialog.cpp index 6a67e5ad6..2e7b0cd6a 100644 --- a/source/Gui/DisplaySettingsDialog.cpp +++ b/source/Gui/DisplaySettingsDialog.cpp @@ -16,15 +16,18 @@ namespace auto const RightColumnWidth = 185.0f; } -_DisplaySettingsDialog::_DisplaySettingsDialog() - : AlienDialog("Display settings") +void DisplaySettingsDialog::init() { auto primaryMonitor = glfwGetPrimaryMonitor(); _videoModes = glfwGetVideoModes(primaryMonitor, &_videoModesCount); _videoModeStrings = createVideoModeStrings(); } -void _DisplaySettingsDialog::processIntern() +DisplaySettingsDialog::DisplaySettingsDialog() + : AlienDialog("Display settings") +{} + +void DisplaySettingsDialog::processIntern() { auto isFullscreen = !WindowController::get().isWindowedMode(); @@ -77,7 +80,7 @@ void _DisplaySettingsDialog::processIntern() } } -void _DisplaySettingsDialog::openIntern() +void DisplaySettingsDialog::openIntern() { _selectionIndex = getSelectionIndex(); _origSelectionIndex = _selectionIndex; @@ -85,7 +88,7 @@ void _DisplaySettingsDialog::openIntern() _origFps = WindowController::get().getFps(); } -void _DisplaySettingsDialog::setFullscreen(int selectionIndex) +void DisplaySettingsDialog::setFullscreen(int selectionIndex) { if (0 == selectionIndex) { WindowController::get().setDesktopMode(); @@ -103,7 +106,7 @@ namespace } } -int _DisplaySettingsDialog::getSelectionIndex() const +int DisplaySettingsDialog::getSelectionIndex() const { auto result = 0; if (!WindowController::get().isWindowedMode() && !WindowController::get().isDesktopMode()) { @@ -127,7 +130,7 @@ namespace } } -std::vector _DisplaySettingsDialog::createVideoModeStrings() const +std::vector DisplaySettingsDialog::createVideoModeStrings() const { std::vector result; result.emplace_back("Desktop"); diff --git a/source/Gui/DisplaySettingsDialog.h b/source/Gui/DisplaySettingsDialog.h index c3d0d07f1..45f27fb89 100644 --- a/source/Gui/DisplaySettingsDialog.h +++ b/source/Gui/DisplaySettingsDialog.h @@ -1,15 +1,21 @@ #pragma once -#include "AlienDialog.h" +#include "Base/Singleton.h" #include "EngineInterface/Definitions.h" + #include "Definitions.h" +#include "AlienDialog.h" -class _DisplaySettingsDialog : public AlienDialog +class DisplaySettingsDialog : public AlienDialog { + MAKE_SINGLETON_NO_DEFAULT_CONSTRUCTION(DisplaySettingsDialog); + public: - _DisplaySettingsDialog(); + void init(); private: + DisplaySettingsDialog(); + void processIntern(); void openIntern(); @@ -18,9 +24,9 @@ class _DisplaySettingsDialog : public AlienDialog std::vector createVideoModeStrings() const; std::string _origMode; - int _origSelectionIndex; - int _selectionIndex; - int _origFps; + int _origSelectionIndex = 0; + int _selectionIndex = 0; + int _origFps = 33; int _videoModesCount = 0; GLFWvidmode const* _videoModes; diff --git a/source/Gui/ImageToPatternDialog.cpp b/source/Gui/ImageToPatternDialog.cpp index 8a992ec13..c736d4086 100644 --- a/source/Gui/ImageToPatternDialog.cpp +++ b/source/Gui/ImageToPatternDialog.cpp @@ -18,9 +18,10 @@ #include "GenericFileDialogs.h" -_ImageToPatternDialog::_ImageToPatternDialog(SimulationFacade const& simulationFacade) - : _simulationFacade(simulationFacade) +void ImageToPatternDialog::init(SimulationFacade const& simulationFacade) { + _simulationFacade = simulationFacade; + auto path = std::filesystem::current_path(); if (path.has_parent_path()) { path = path.parent_path(); @@ -28,7 +29,7 @@ _ImageToPatternDialog::_ImageToPatternDialog(SimulationFacade const& simulationF _startingPath = GlobalSettings::get().getString("dialogs.open image.starting path", path.string()); } -_ImageToPatternDialog::~_ImageToPatternDialog() +void ImageToPatternDialog::shutdown() { GlobalSettings::get().setString("dialogs.open image.starting path", _startingPath); } @@ -76,7 +77,7 @@ namespace } } -void _ImageToPatternDialog::show() +void ImageToPatternDialog::show() { GenericFileDialogs::get().showOpenFileDialog( "Open image", "Image (*.png){.png},.*", _startingPath, [&](std::filesystem::path const& path) { diff --git a/source/Gui/ImageToPatternDialog.h b/source/Gui/ImageToPatternDialog.h index bb185382e..a29560ab2 100644 --- a/source/Gui/ImageToPatternDialog.h +++ b/source/Gui/ImageToPatternDialog.h @@ -1,19 +1,24 @@ #pragma once +#include "Base/Singleton.h" #include "EngineInterface/Definitions.h" #include "Definitions.h" +#include "ShutdownInterface.h" -class _ImageToPatternDialog +class ImageToPatternDialog : public ShutdownInterface { -public: + MAKE_SINGLETON(ImageToPatternDialog); - _ImageToPatternDialog(SimulationFacade const& simulationFacade); - ~_ImageToPatternDialog(); +public: + void init(SimulationFacade const& simulationFacade); + void show(); private: + void shutdown() override; + SimulationFacade _simulationFacade; std::string _startingPath; diff --git a/source/Gui/LoginDialog.cpp b/source/Gui/LoginDialog.cpp index 9de6dfef6..343d02c1c 100644 --- a/source/Gui/LoginDialog.cpp +++ b/source/Gui/LoginDialog.cpp @@ -16,11 +16,10 @@ #include "HelpStrings.h" #include "LoginController.h" -void LoginDialog::init(SimulationFacade const& simulationFacade, PersisterFacade const& persisterFacade, ResetPasswordDialog const& resetPasswordDialog) +void LoginDialog::init(SimulationFacade const& simulationFacade, PersisterFacade const& persisterFacade) { _simulationFacade = simulationFacade; _persisterFacade = persisterFacade; - _resetPasswordDialog = resetPasswordDialog; } LoginDialog::LoginDialog() @@ -90,7 +89,7 @@ void LoginDialog::processIntern() ImGui::BeginDisabled(userName.empty()); if (AlienImGui::Button("Reset password")) { close(); - _resetPasswordDialog->open(userName, LoginController::get().getUserInfo()); + ResetPasswordDialog::get().open(userName, LoginController::get().getUserInfo()); } ImGui::EndDisabled(); diff --git a/source/Gui/LoginDialog.h b/source/Gui/LoginDialog.h index f681bf965..6a8b7c216 100644 --- a/source/Gui/LoginDialog.h +++ b/source/Gui/LoginDialog.h @@ -11,7 +11,7 @@ class LoginDialog : public AlienDialog MAKE_SINGLETON_NO_DEFAULT_CONSTRUCTION(LoginDialog); public: - void init(SimulationFacade const& simulationFacade, PersisterFacade const& persisterFacade, ResetPasswordDialog const& resetPasswordDialog); + void init(SimulationFacade const& simulationFacade, PersisterFacade const& persisterFacade); private: LoginDialog(); @@ -20,5 +20,4 @@ class LoginDialog : public AlienDialog SimulationFacade _simulationFacade; PersisterFacade _persisterFacade; - ResetPasswordDialog _resetPasswordDialog; }; diff --git a/source/Gui/MainWindow.cpp b/source/Gui/MainWindow.cpp index 179dce08b..b083794d2 100644 --- a/source/Gui/MainWindow.cpp +++ b/source/Gui/MainWindow.cpp @@ -132,20 +132,16 @@ _MainWindow::_MainWindow(SimulationFacade const& simulationFacade, PersisterFaca MassOperationsDialog::get().init(_simulationFacade); LogWindow::get().init(_logger); GettingStartedWindow::get().init(); - _newSimulationDialog = std::make_shared<_NewSimulationDialog>(_simulationFacade); - _displaySettingsDialog = std::make_shared<_DisplaySettingsDialog>(); - _patternAnalysisDialog = std::make_shared<_PatternAnalysisDialog>(_simulationFacade); + NewSimulationDialog::get().init(_simulationFacade); + DisplaySettingsDialog::get().init(); + PatternAnalysisDialog::get().init(_simulationFacade); BrowserWindow::get().init(_simulationFacade, _persisterFacade); ActivateUserDialog::get().init(_simulationFacade); - _newPasswordDialog = std::make_shared<_NewPasswordDialog>(_simulationFacade); - _resetPasswordDialog = std::make_shared<_ResetPasswordDialog>(_newPasswordDialog); - LoginDialog::get().init(_simulationFacade, _persisterFacade, _resetPasswordDialog); + NewPasswordDialog::get().init(_simulationFacade); + LoginDialog::get().init(_simulationFacade, _persisterFacade); UploadSimulationDialog::get().init(_simulationFacade); - _deleteUserDialog = std::make_shared<_DeleteUserDialog>(); - _networkSettingsDialog = std::make_shared<_NetworkSettingsDialog>(); - _imageToPatternDialog = std::make_shared<_ImageToPatternDialog>(_simulationFacade); - _shaderWindow = std::make_shared<_ShaderWindow>(); - _autosaveWindow = std::make_shared<_AutosaveWindow>(_simulationFacade, _persisterFacade); + ImageToPatternDialog::get().init(_simulationFacade); + AutosaveWindow::get().init(_simulationFacade, _persisterFacade); OverlayMessageController::get().init(_persisterFacade); FileTransferController::get().init(_persisterFacade, _simulationFacade); NetworkTransferController::get().init(_simulationFacade, _persisterFacade); @@ -215,6 +211,7 @@ void _MainWindow::shutdown() ShutdownController::get().shutdown(); GpuSettingsDialog::get().shutdown(); + NewSimulationDialog::get().shutdown(); ImGui_ImplOpenGL3_Shutdown(); ImGui_ImplGlfw_Shutdown(); @@ -377,7 +374,7 @@ void _MainWindow::processMenubar() ImGui::Dummy(ImVec2(10.0f, 0.0f)); if (AlienImGui::BeginMenuButton(" " ICON_FA_GAMEPAD " Simulation ", _simulationMenuToggled, "Simulation")) { if (ImGui::MenuItem("New", "CTRL+N")) { - _newSimulationDialog->open(); + NewSimulationDialog::get().open(); _simulationMenuToggled = false; } if (ImGui::MenuItem("Open", "CTRL+O")) { @@ -432,7 +429,7 @@ void _MainWindow::processMenubar() ImGui::Separator(); ImGui::BeginDisabled(!NetworkService::get().getLoggedInUserName()); if (ImGui::MenuItem("Delete user", "ALT+J")) { - _deleteUserDialog->open(); + DeleteUserDialog::get().open(); } ImGui::EndDisabled(); AlienImGui::EndMenuButton(); @@ -454,11 +451,11 @@ void _MainWindow::processMenubar() if (ImGui::MenuItem("Radiation sources", "ALT+5", RadiationSourcesWindow::get().isOn())) { RadiationSourcesWindow::get().setOn(!RadiationSourcesWindow::get().isOn()); } - if (ImGui::MenuItem("Shader parameters", "ALT+6", _shaderWindow->isOn())) { - _shaderWindow->setOn(!_shaderWindow->isOn()); + if (ImGui::MenuItem("Shader parameters", "ALT+6", ShaderWindow::get().isOn())) { + ShaderWindow::get().setOn(!ShaderWindow::get().isOn()); } - if (ImGui::MenuItem("Autosave", "ALT+7", _autosaveWindow->isOn())) { - _autosaveWindow->setOn(!_autosaveWindow->isOn()); + if (ImGui::MenuItem("Autosave", "ALT+7", AutosaveWindow::get().isOn())) { + AutosaveWindow::get().setOn(!AutosaveWindow::get().isOn()); } if (ImGui::MenuItem("Log", "ALT+8", LogWindow::get().isOn())) { LogWindow::get().setOn(!LogWindow::get().isOn()); @@ -537,11 +534,11 @@ void _MainWindow::processMenubar() _toolsMenuToggled = false; } if (ImGui::MenuItem("Pattern analysis", "ALT+P")) { - _patternAnalysisDialog->show(); + PatternAnalysisDialog::get().show(); _toolsMenuToggled = false; } if (ImGui::MenuItem("Image converter", "ALT+G")) { - _imageToPatternDialog->show(); + ImageToPatternDialog::get().show(); _toolsMenuToggled = false; } AlienImGui::EndMenuButton(); @@ -555,10 +552,10 @@ void _MainWindow::processMenubar() GpuSettingsDialog::get().open(); } if (ImGui::MenuItem("Display settings", "ALT+V")) { - _displaySettingsDialog->open(); + DisplaySettingsDialog::get().open(); } if (ImGui::MenuItem("Network settings", "ALT+K")) { - _networkSettingsDialog->open(); + NetworkSettingsDialog::get().open(); } AlienImGui::EndMenuButton(); } @@ -580,7 +577,7 @@ void _MainWindow::processMenubar() auto& io = ImGui::GetIO(); if (!io.WantCaptureKeyboard) { if (io.KeyCtrl && ImGui::IsKeyPressed(ImGuiKey_N)) { - _newSimulationDialog->open(); + NewSimulationDialog::get().open(); } if (io.KeyCtrl && ImGui::IsKeyPressed(ImGuiKey_O)) { FileTransferController::get().onOpenSimulation(); @@ -614,7 +611,7 @@ void _MainWindow::processMenubar() UploadSimulationDialog::get().open(NetworkResourceType_Genome); } if (io.KeyAlt && ImGui::IsKeyPressed(ImGuiKey_J) && NetworkService::get().getLoggedInUserName()) { - _deleteUserDialog->open(); + DeleteUserDialog::get().open(); } if (io.KeyAlt && ImGui::IsKeyPressed(ImGuiKey_1)) { @@ -633,10 +630,10 @@ void _MainWindow::processMenubar() RadiationSourcesWindow::get().setOn(!RadiationSourcesWindow::get().isOn()); } if (io.KeyAlt && ImGui::IsKeyPressed(ImGuiKey_6)) { - _shaderWindow->setOn(!_shaderWindow->isOn()); + ShaderWindow::get().setOn(!ShaderWindow::get().isOn()); } if (io.KeyAlt && ImGui::IsKeyPressed(ImGuiKey_7)) { - _autosaveWindow->setOn(!_autosaveWindow->isOn()); + AutosaveWindow::get().setOn(!AutosaveWindow::get().isOn()); } if (io.KeyAlt && ImGui::IsKeyPressed(ImGuiKey_8)) { LogWindow::get().setOn(!LogWindow::get().isOn()); @@ -683,7 +680,7 @@ void _MainWindow::processMenubar() GpuSettingsDialog::get().open(); } if (io.KeyAlt && ImGui::IsKeyPressed(ImGuiKey_V)) { - _displaySettingsDialog->open(); + DisplaySettingsDialog::get().open(); } if (ImGui::IsKeyPressed(ImGuiKey_F7)) { if (WindowController::get().isDesktopMode()) { @@ -693,7 +690,7 @@ void _MainWindow::processMenubar() } } if (io.KeyAlt && ImGui::IsKeyPressed(ImGuiKey_K)) { - _networkSettingsDialog->open(); + NetworkSettingsDialog::get().open(); } if (io.KeyAlt && ImGui::IsKeyPressed(ImGuiKey_O)) { @@ -710,31 +707,31 @@ void _MainWindow::processMenubar() MassOperationsDialog::get().show(); } if (io.KeyAlt && ImGui::IsKeyPressed(ImGuiKey_P)) { - _patternAnalysisDialog->show(); + PatternAnalysisDialog::get().show(); } if (io.KeyAlt && ImGui::IsKeyPressed(ImGuiKey_G)) { - _imageToPatternDialog->show(); + ImageToPatternDialog::get().show(); } } } void _MainWindow::processDialogs() { - _newSimulationDialog->process(); + NewSimulationDialog::get().process(); AboutDialog::get().process(); MassOperationsDialog::get().process(); GpuSettingsDialog::get().process(); - _displaySettingsDialog->process(); - _patternAnalysisDialog->process(); + DisplaySettingsDialog::get().process(); + PatternAnalysisDialog::get().process(); LoginDialog::get().process(); CreateUserDialog::get().process(); ActivateUserDialog::get().process(); UploadSimulationDialog::get().process(); EditSimulationDialog::get().process(); - _deleteUserDialog->process(); - _networkSettingsDialog->process(); - _resetPasswordDialog->process(); - _newPasswordDialog->process(); + DeleteUserDialog::get().process(); + NetworkSettingsDialog::get().process(); + ResetPasswordDialog::get().process(); + NewPasswordDialog::get().process(); ExitDialog::get().process(); MessageDialog::get().process(); @@ -750,9 +747,9 @@ void _MainWindow::processWindows() LogWindow::get().process(); BrowserWindow::get().process(); GettingStartedWindow::get().process(); - _shaderWindow->process(); + ShaderWindow::get().process(); RadiationSourcesWindow::get().process(); - _autosaveWindow->process(); + AutosaveWindow::get().process(); } void _MainWindow::processControllers() diff --git a/source/Gui/MainWindow.h b/source/Gui/MainWindow.h index 110d9548b..6881827fd 100644 --- a/source/Gui/MainWindow.h +++ b/source/Gui/MainWindow.h @@ -41,18 +41,6 @@ class _MainWindow GuiLogger _logger; - ShaderWindow _shaderWindow; - AutosaveWindow _autosaveWindow; - - NewSimulationDialog _newSimulationDialog; - DisplaySettingsDialog _displaySettingsDialog; - PatternAnalysisDialog _patternAnalysisDialog; - DeleteUserDialog _deleteUserDialog; - NetworkSettingsDialog _networkSettingsDialog; - ResetPasswordDialog _resetPasswordDialog; - NewPasswordDialog _newPasswordDialog; - ImageToPatternDialog _imageToPatternDialog; - PersisterFacade _persisterFacade; SimulationFacade _simulationFacade; diff --git a/source/Gui/NetworkSettingsDialog.cpp b/source/Gui/NetworkSettingsDialog.cpp index 2d5e35f15..1db9a5b2b 100644 --- a/source/Gui/NetworkSettingsDialog.cpp +++ b/source/Gui/NetworkSettingsDialog.cpp @@ -13,11 +13,11 @@ namespace auto const RightColumnWidth = 150.0f; } -_NetworkSettingsDialog::_NetworkSettingsDialog() +NetworkSettingsDialog::NetworkSettingsDialog() : AlienDialog("Network settings") {} -void _NetworkSettingsDialog::processIntern() +void NetworkSettingsDialog::processIntern() { AlienImGui::InputText( AlienImGui::InputTextParameters().name("Blocks").defaultValue(_origServerAddress).name("Server address").textWidth(RightColumnWidth), _serverAddress); @@ -37,13 +37,13 @@ void _NetworkSettingsDialog::processIntern() } } -void _NetworkSettingsDialog::openIntern() +void NetworkSettingsDialog::openIntern() { _origServerAddress = NetworkService::get().getServerAddress(); _serverAddress = _origServerAddress; } -void _NetworkSettingsDialog::onChangeSettings() +void NetworkSettingsDialog::onChangeSettings() { NetworkService::get().setServerAddress(_serverAddress); BrowserWindow::get().onRefresh(); diff --git a/source/Gui/NetworkSettingsDialog.h b/source/Gui/NetworkSettingsDialog.h index 15b1178a8..4ee665254 100644 --- a/source/Gui/NetworkSettingsDialog.h +++ b/source/Gui/NetworkSettingsDialog.h @@ -1,16 +1,18 @@ #pragma once +#include "Base/Singleton.h" #include "Network/Definitions.h" #include "AlienDialog.h" #include "Definitions.h" -class _NetworkSettingsDialog : public AlienDialog +class NetworkSettingsDialog : public AlienDialog { -public: - _NetworkSettingsDialog(); + MAKE_SINGLETON_NO_DEFAULT_CONSTRUCTION(NetworkSettingsDialog); private: + NetworkSettingsDialog(); + void processIntern(); void openIntern(); diff --git a/source/Gui/NewPasswordDialog.cpp b/source/Gui/NewPasswordDialog.cpp index d0ca3d601..36623a072 100644 --- a/source/Gui/NewPasswordDialog.cpp +++ b/source/Gui/NewPasswordDialog.cpp @@ -9,12 +9,12 @@ #include "BrowserWindow.h" #include "MessageDialog.h" -_NewPasswordDialog::_NewPasswordDialog(SimulationFacade const& simulationFacade) - : AlienDialog("New password") - , _simulationFacade(simulationFacade) -{} +void NewPasswordDialog::init(SimulationFacade const& simulationFacade) +{ + _simulationFacade = simulationFacade; +} -void _NewPasswordDialog::open(std::string const& userName, UserInfo const& userInfo) +void NewPasswordDialog::open(std::string const& userName, UserInfo const& userInfo) { AlienDialog::open(); _userName = userName; @@ -23,7 +23,11 @@ void _NewPasswordDialog::open(std::string const& userName, UserInfo const& userI _userInfo = userInfo; } -void _NewPasswordDialog::processIntern() +NewPasswordDialog::NewPasswordDialog() + : AlienDialog("New password") +{} + +void NewPasswordDialog::processIntern() { AlienImGui::Text("Security information"); AlienImGui::HelpMarker( @@ -53,7 +57,7 @@ void _NewPasswordDialog::processIntern() } } -void _NewPasswordDialog::onNewPassword() +void NewPasswordDialog::onNewPassword() { auto result = NetworkService::get().setNewPassword(_userName, _newPassword, _confirmationCode); if (result) { diff --git a/source/Gui/NewPasswordDialog.h b/source/Gui/NewPasswordDialog.h index 4a52ff316..3afc59ff3 100644 --- a/source/Gui/NewPasswordDialog.h +++ b/source/Gui/NewPasswordDialog.h @@ -5,14 +5,17 @@ #include "AlienDialog.h" #include "Definitions.h" -class _NewPasswordDialog : public AlienDialog +class NewPasswordDialog : public AlienDialog { + MAKE_SINGLETON_NO_DEFAULT_CONSTRUCTION(NewPasswordDialog); public: - _NewPasswordDialog(SimulationFacade const& simulationFacade); + void init(SimulationFacade const& simulationFacade); void open(std::string const& userName, UserInfo const& userInfo); private: + NewPasswordDialog(); + void processIntern(); void onNewPassword(); diff --git a/source/Gui/NewSimulationDialog.cpp b/source/Gui/NewSimulationDialog.cpp index 768db6215..00ee61faf 100644 --- a/source/Gui/NewSimulationDialog.cpp +++ b/source/Gui/NewSimulationDialog.cpp @@ -16,19 +16,23 @@ namespace auto const ContentTextInputWidth = 60.0f; } -_NewSimulationDialog::_NewSimulationDialog(SimulationFacade const& simulationFacade) - : AlienDialog("New simulation") - , _simulationFacade(simulationFacade) +void NewSimulationDialog::init(SimulationFacade const& simulationFacade) { - _adoptSimulationParameters = GlobalSettings::get().getBool("dialogs.new simulation.adopt simulation parameters", true); + _simulationFacade = simulationFacade; + _adoptSimulationParameters = + GlobalSettings::get().getBool("dialogs.new simulation.adopt simulation parameters", true); } -_NewSimulationDialog::~_NewSimulationDialog() +void NewSimulationDialog::shutdown() { GlobalSettings::get().setBool("dialogs.new simulation.adopt simulation parameters", _adoptSimulationParameters); } -void _NewSimulationDialog::processIntern() +NewSimulationDialog::NewSimulationDialog() + : AlienDialog("New simulation") +{} + +void NewSimulationDialog::processIntern() { AlienImGui::InputInt(AlienImGui::InputIntParameters().name("Width").textWidth(ContentTextInputWidth), _width); AlienImGui::InputInt(AlienImGui::InputIntParameters().name("Height").textWidth(ContentTextInputWidth), _height); @@ -54,14 +58,14 @@ void _NewSimulationDialog::processIntern() _height = std::max(1, _height); } -void _NewSimulationDialog::openIntern() +void NewSimulationDialog::openIntern() { auto worldSize = _simulationFacade->getWorldSize(); _width = worldSize.x; _height = worldSize.y; } -void _NewSimulationDialog::onNewSimulation() +void NewSimulationDialog::onNewSimulation() { SimulationParameters parameters; if (_adoptSimulationParameters) { diff --git a/source/Gui/NewSimulationDialog.h b/source/Gui/NewSimulationDialog.h index 9133ecad2..cc4690371 100644 --- a/source/Gui/NewSimulationDialog.h +++ b/source/Gui/NewSimulationDialog.h @@ -1,17 +1,21 @@ #pragma once +#include "Base/Singleton.h" #include "EngineInterface/Definitions.h" #include "EngineInterface/Descriptions.h" #include "Definitions.h" #include "AlienDialog.h" -class _NewSimulationDialog : public AlienDialog +class NewSimulationDialog : public AlienDialog { + MAKE_SINGLETON_NO_DEFAULT_CONSTRUCTION(NewSimulationDialog); + public: - _NewSimulationDialog(SimulationFacade const& simulationFacade); - ~_NewSimulationDialog() override; + void init(SimulationFacade const& simulationFacade); + void shutdown(); private: + NewSimulationDialog(); void processIntern() override; void openIntern() override; diff --git a/source/Gui/PatternAnalysisDialog.cpp b/source/Gui/PatternAnalysisDialog.cpp index 3d0d4ecbc..c4a960413 100644 --- a/source/Gui/PatternAnalysisDialog.cpp +++ b/source/Gui/PatternAnalysisDialog.cpp @@ -13,24 +13,28 @@ #include "EngineInterface/SimulationFacade.h" #include "MessageDialog.h" +#include "ShutdownController.h" -_PatternAnalysisDialog::_PatternAnalysisDialog(SimulationFacade const& simulationFacade) - : _simulationFacade(simulationFacade) +void PatternAnalysisDialog::init(SimulationFacade const& simulationFacade) { + _simulationFacade = simulationFacade; + auto path = std::filesystem::current_path(); if (path.has_parent_path()) { path = path.parent_path(); } _startingPath = GlobalSettings::get().getString("dialogs.pattern analysis.starting path", path.string()); + + ShutdownController::get().registerObject(this); } -_PatternAnalysisDialog::~_PatternAnalysisDialog() +void PatternAnalysisDialog::shutdown() { GlobalSettings::get().setString("dialogs.pattern analysis.starting path", _startingPath); } -void _PatternAnalysisDialog::process() +void PatternAnalysisDialog::process() { if (!ifd::FileDialog::Instance().IsDone("PatternAnalysisDialog")) { return; @@ -45,12 +49,12 @@ void _PatternAnalysisDialog::process() ifd::FileDialog::Instance().Close(); } -void _PatternAnalysisDialog::show() +void PatternAnalysisDialog::show() { ifd::FileDialog::Instance().Save("PatternAnalysisDialog", "Save pattern analysis result", "Analysis result (*.txt){.txt},.*", _startingPath); } -void _PatternAnalysisDialog::saveRepetitiveActiveClustersToFiles(std::string const& filename) +void PatternAnalysisDialog::saveRepetitiveActiveClustersToFiles(std::string const& filename) { auto const partitionClassDataByDescription = calcPartitionData(); @@ -98,7 +102,7 @@ void _PatternAnalysisDialog::saveRepetitiveActiveClustersToFiles(std::string con MessageDialog::get().information("Analysis result", messageStream.str()); } -auto _PatternAnalysisDialog::calcPartitionData() const -> std::map +auto PatternAnalysisDialog::calcPartitionData() const -> std::map { auto data = _simulationFacade->getClusteredSimulationData(); @@ -114,7 +118,7 @@ auto _PatternAnalysisDialog::calcPartitionData() const -> std::map ClusterAnalysisDescription +auto PatternAnalysisDialog::getAnalysisDescription(ClusterDescription const& cluster) const -> ClusterAnalysisDescription { ClusterAnalysisDescription result; std::map cellAnalysisDescById; diff --git a/source/Gui/PatternAnalysisDialog.h b/source/Gui/PatternAnalysisDialog.h index a7759705c..16d97a5a7 100644 --- a/source/Gui/PatternAnalysisDialog.h +++ b/source/Gui/PatternAnalysisDialog.h @@ -1,18 +1,23 @@ #pragma once +#include "Base/Singleton.h" #include "EngineInterface/Descriptions.h" + #include "Definitions.h" +#include "ShutdownInterface.h" -class _PatternAnalysisDialog +class PatternAnalysisDialog : public ShutdownInterface { + MAKE_SINGLETON(PatternAnalysisDialog); + public: - _PatternAnalysisDialog(SimulationFacade const& simulationFacade); - ~_PatternAnalysisDialog(); + void init(SimulationFacade const& simulationFacade); void process(); void show(); private: + void shutdown() override; void saveRepetitiveActiveClustersToFiles(std::string const& filename); struct CellAnalysisDescription diff --git a/source/Gui/ResetPasswordDialog.cpp b/source/Gui/ResetPasswordDialog.cpp index 7ee2bae0f..1c9783d99 100644 --- a/source/Gui/ResetPasswordDialog.cpp +++ b/source/Gui/ResetPasswordDialog.cpp @@ -6,12 +6,11 @@ #include "MessageDialog.h" #include "NewPasswordDialog.h" -_ResetPasswordDialog::_ResetPasswordDialog(NewPasswordDialog const& newPasswordDialog) +ResetPasswordDialog::ResetPasswordDialog() : AlienDialog("Reset password") - , _newPasswordDialog(newPasswordDialog) {} -void _ResetPasswordDialog::open(std::string const& userName, UserInfo const& userInfo) +void ResetPasswordDialog::open(std::string const& userName, UserInfo const& userInfo) { AlienDialog::open(); _userName = userName; @@ -19,7 +18,7 @@ void _ResetPasswordDialog::open(std::string const& userName, UserInfo const& use _userInfo = userInfo; } -void _ResetPasswordDialog::processIntern() +void ResetPasswordDialog::processIntern() { AlienImGui::Text("Security information"); AlienImGui::HelpMarker("The data transfer to the server is encrypted via https. On the server side, the email address is not stored in cleartext, but " @@ -50,10 +49,10 @@ void _ResetPasswordDialog::processIntern() } } -void _ResetPasswordDialog::onResetPassword() +void ResetPasswordDialog::onResetPassword() { if (NetworkService::get().resetPassword(_userName, _email)) { - _newPasswordDialog->open(_userName, _userInfo); + NewPasswordDialog::get().open(_userName, _userInfo); } else { MessageDialog::get().information( "Error", "An error occurred on the server. This could be related to the fact that the\nemail address is wrong."); diff --git a/source/Gui/ResetPasswordDialog.h b/source/Gui/ResetPasswordDialog.h index 1ccb86ece..9c9d522a2 100644 --- a/source/Gui/ResetPasswordDialog.h +++ b/source/Gui/ResetPasswordDialog.h @@ -5,20 +5,20 @@ #include "AlienDialog.h" #include "Definitions.h" -class _ResetPasswordDialog : public AlienDialog +class ResetPasswordDialog : public AlienDialog { -public: - _ResetPasswordDialog(NewPasswordDialog const& newPasswordDialog); + MAKE_SINGLETON_NO_DEFAULT_CONSTRUCTION(ResetPasswordDialog); +public: void open(std::string const& userName, UserInfo const& userInfo); private: + ResetPasswordDialog(); + void processIntern(); void onResetPassword(); - NewPasswordDialog _newPasswordDialog; - std::string _userName; std::string _email; UserInfo _userInfo; diff --git a/source/Gui/ShaderWindow.cpp b/source/Gui/ShaderWindow.cpp index ebee072b8..09dcc0cc3 100644 --- a/source/Gui/ShaderWindow.cpp +++ b/source/Gui/ShaderWindow.cpp @@ -1,7 +1,5 @@ #include "ShaderWindow.h" -#include "Base/GlobalSettings.h" - #include "AlienImGui.h" #include "SimulationView.h" @@ -10,16 +8,12 @@ namespace auto const RightColumnWidth = 140.0f; } -_ShaderWindow::_ShaderWindow() +ShaderWindow::ShaderWindow() : AlienWindow("Shader parameters", "windows.shader", false) { } -_ShaderWindow::~_ShaderWindow() -{ -} - -void _ShaderWindow::processIntern() +void ShaderWindow::processIntern() { auto const defaultBrightness = SimulationView::DefaultBrightness; auto const defaultContrast = SimulationView::DefaultContrast; diff --git a/source/Gui/ShaderWindow.h b/source/Gui/ShaderWindow.h index a80a47500..598761074 100644 --- a/source/Gui/ShaderWindow.h +++ b/source/Gui/ShaderWindow.h @@ -1,14 +1,16 @@ #pragma once +#include "Base/Singleton.h" + #include "AlienWindow.h" #include "Definitions.h" -class _ShaderWindow : public AlienWindow +class ShaderWindow : public AlienWindow { -public: - _ShaderWindow(); - ~_ShaderWindow() override; + MAKE_SINGLETON_NO_DEFAULT_CONSTRUCTION(ShaderWindow); private: + ShaderWindow(); + void processIntern() override; }; \ No newline at end of file