From 5483268f8f9a1236207457f7187a8dddd35be90a Mon Sep 17 00:00:00 2001 From: AlexandreRouma Date: Thu, 16 Dec 2021 16:49:19 +0100 Subject: [PATCH] Added error dialog to module manager and fixed typo --- core/src/gui/dialogs/dialog_box.h | 3 +++ core/src/gui/menus/module_manager.cpp | 17 ++++++++++++--- core/src/module.cpp | 27 ++++++++++++++---------- core/src/module.h | 10 ++++----- decoder_modules/radio/src/radio_module.h | 2 +- 5 files changed, 39 insertions(+), 20 deletions(-) diff --git a/core/src/gui/dialogs/dialog_box.h b/core/src/gui/dialogs/dialog_box.h index 8134810..d06615f 100644 --- a/core/src/gui/dialogs/dialog_box.h +++ b/core/src/gui/dialogs/dialog_box.h @@ -4,9 +4,12 @@ #include #include +#define GENERIC_DIALOG_BUTTONS_OK "Ok\0" #define GENERIC_DIALOG_BUTTONS_YES_NO "Yes\0No\0" #define GENERIC_DIALOG_BUTTONS_APPLY_CANCEL "Apply\0Cancel\0" +#define GENERIC_DIALOG_BUTTONS_OK_CANCEL "Ok\0Cancel\0" +#define GENERIC_DIALOG_BUTTON_OK 0 #define GENERIC_DIALOG_BUTTON_YES 0 #define GENERIC_DIALOG_BUTTON_NO 1 #define GENERIC_DIALOG_BUTTON_APPLY 0 diff --git a/core/src/gui/menus/module_manager.cpp b/core/src/gui/menus/module_manager.cpp index 9e38294..ec0583c 100644 --- a/core/src/gui/menus/module_manager.cpp +++ b/core/src/gui/menus/module_manager.cpp @@ -10,8 +10,10 @@ namespace module_manager_menu { std::vector modTypes; std::string toBeRemoved; std::string modTypesTxt; + std::string errorMessage; int modTypeId; bool confirmOpened = false; + bool errorOpen = false; void init() { modName[0] = 0; @@ -66,6 +68,10 @@ namespace module_manager_menu { modified = true; } + ImGui::GenericDialog("module_mgr_error_", errorOpen, GENERIC_DIALOG_BUTTONS_OK, [](){ + ImGui::Text(errorMessage.c_str()); + }); + // Add module row with slightly different settings ImGui::BeginTable("Module Manager Add Table", 3); ImGui::TableSetupColumn("Name"); @@ -84,9 +90,14 @@ namespace module_manager_menu { ImGui::TableSetColumnIndex(2); if (strlen(modName) == 0) { style::beginDisabled(); } if (ImGui::Button("+##module_mgr_add_btn", ImVec2(16,0))) { - core::moduleManager.createInstance(modName, modTypes[modTypeId]); - core::moduleManager.postInit(modName); - modified = true; + if (!core::moduleManager.createInstance(modName, modTypes[modTypeId])) { + core::moduleManager.postInit(modName); + modified = true; + } + else { + errorMessage = "Could not create new instance of " + modTypes[modTypeId]; + errorOpen = true; + } } if (strlen(modName) == 0) { style::endDisabled(); } ImGui::EndTable(); diff --git a/core/src/module.cpp b/core/src/module.cpp index 255593a..7d93240 100644 --- a/core/src/module.cpp +++ b/core/src/module.cpp @@ -79,57 +79,62 @@ ModuleManager::Module_t ModuleManager::loadModule(std::string path) { return mod; } -void ModuleManager::createInstance(std::string name, std::string module) { +int ModuleManager::createInstance(std::string name, std::string module) { if (modules.find(module) == modules.end()) { spdlog::error("Module '{0}' doesn't exist", module); - return; + return -1; } if (instances.find(name) != instances.end()) { spdlog::error("A module instance with the name '{0}' already exists", name); - return; + return -1; } int maxCount = modules[module].info->maxInstances; if (countModuleInstances(module) >= maxCount && maxCount > 0) { spdlog::error("Maximum number of instances reached for '{0}'", module); - return; + return -1; } Instance_t inst; inst.module = modules[module]; inst.instance = inst.module.createInstance(name); instances[name] = inst; onInstanceCreated.emit(name); + return 0; } -void ModuleManager::deleteInstance(std::string name) { +int ModuleManager::deleteInstance(std::string name) { if (instances.find(name) == instances.end()) { spdlog::error("Tried to remove non-existent instance '{0}'", name); - return; + return -1; } onInstanceDelete.emit(name); Instance_t inst = instances[name]; inst.module.deleteInstance(inst.instance); instances.erase(name); onInstanceDeleted.emit(name); + return 0; } -void ModuleManager::deleteInstance(ModuleManager::Instance* instance) { +int ModuleManager::deleteInstance(ModuleManager::Instance* instance) { spdlog::error("Delete instance not implemented"); + return -1; } -void ModuleManager::enableInstance(std::string name) { +int ModuleManager::enableInstance(std::string name) { if (instances.find(name) == instances.end()) { spdlog::error("Cannot enable '{0}', instance doesn't exist", name); - return; + return -1; } instances[name].instance->enable(); + return 0; } -void ModuleManager::disableInstance(std::string name) { +int ModuleManager::disableInstance(std::string name) { if (instances.find(name) == instances.end()) { spdlog::error("Cannot disable '{0}', instance doesn't exist", name); - return; + return -1; } instances[name].instance->disable(); + return 0; } bool ModuleManager::instanceEnabled(std::string name) { diff --git a/core/src/module.h b/core/src/module.h index db6d97c..710a021 100644 --- a/core/src/module.h +++ b/core/src/module.h @@ -78,12 +78,12 @@ public: ModuleManager::Module_t loadModule(std::string path); - void createInstance(std::string name, std::string module); - void deleteInstance(std::string name); - void deleteInstance(ModuleManager::Instance* instance); + int createInstance(std::string name, std::string module); + int deleteInstance(std::string name); + int deleteInstance(ModuleManager::Instance* instance); - void enableInstance(std::string name); - void disableInstance(std::string name); + int enableInstance(std::string name); + int disableInstance(std::string name); bool instanceEnabled(std::string name); void postInit(std::string name); std::string getInstanceModuleName(std::string name); diff --git a/decoder_modules/radio/src/radio_module.h b/decoder_modules/radio/src/radio_module.h index edc1626..41b7c9c 100644 --- a/decoder_modules/radio/src/radio_module.h +++ b/decoder_modules/radio/src/radio_module.h @@ -20,7 +20,7 @@ const double DeemphasisModes[] { 75e-6 }; -const char* DeemhasisModesTxt = "50µS\00075µS\000None\000"; +const char* DeemhasisModesTxt = "50µs\00075µs\000None\000"; class RadioModule : public ModuleManager::Instance { public: