Added error dialog to module manager and fixed typo

This commit is contained in:
AlexandreRouma 2021-12-16 16:49:19 +01:00
parent 6c7e952be3
commit 5483268f8f
5 changed files with 39 additions and 20 deletions

View File

@ -4,9 +4,12 @@
#include <string> #include <string>
#include <gui/gui.h> #include <gui/gui.h>
#define GENERIC_DIALOG_BUTTONS_OK "Ok\0"
#define GENERIC_DIALOG_BUTTONS_YES_NO "Yes\0No\0" #define GENERIC_DIALOG_BUTTONS_YES_NO "Yes\0No\0"
#define GENERIC_DIALOG_BUTTONS_APPLY_CANCEL "Apply\0Cancel\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_YES 0
#define GENERIC_DIALOG_BUTTON_NO 1 #define GENERIC_DIALOG_BUTTON_NO 1
#define GENERIC_DIALOG_BUTTON_APPLY 0 #define GENERIC_DIALOG_BUTTON_APPLY 0

View File

@ -10,8 +10,10 @@ namespace module_manager_menu {
std::vector<std::string> modTypes; std::vector<std::string> modTypes;
std::string toBeRemoved; std::string toBeRemoved;
std::string modTypesTxt; std::string modTypesTxt;
std::string errorMessage;
int modTypeId; int modTypeId;
bool confirmOpened = false; bool confirmOpened = false;
bool errorOpen = false;
void init() { void init() {
modName[0] = 0; modName[0] = 0;
@ -66,6 +68,10 @@ namespace module_manager_menu {
modified = true; modified = true;
} }
ImGui::GenericDialog("module_mgr_error_", errorOpen, GENERIC_DIALOG_BUTTONS_OK, [](){
ImGui::Text(errorMessage.c_str());
});
// Add module row with slightly different settings // Add module row with slightly different settings
ImGui::BeginTable("Module Manager Add Table", 3); ImGui::BeginTable("Module Manager Add Table", 3);
ImGui::TableSetupColumn("Name"); ImGui::TableSetupColumn("Name");
@ -84,10 +90,15 @@ namespace module_manager_menu {
ImGui::TableSetColumnIndex(2); ImGui::TableSetColumnIndex(2);
if (strlen(modName) == 0) { style::beginDisabled(); } if (strlen(modName) == 0) { style::beginDisabled(); }
if (ImGui::Button("+##module_mgr_add_btn", ImVec2(16,0))) { if (ImGui::Button("+##module_mgr_add_btn", ImVec2(16,0))) {
core::moduleManager.createInstance(modName, modTypes[modTypeId]); if (!core::moduleManager.createInstance(modName, modTypes[modTypeId])) {
core::moduleManager.postInit(modName); core::moduleManager.postInit(modName);
modified = true; modified = true;
} }
else {
errorMessage = "Could not create new instance of " + modTypes[modTypeId];
errorOpen = true;
}
}
if (strlen(modName) == 0) { style::endDisabled(); } if (strlen(modName) == 0) { style::endDisabled(); }
ImGui::EndTable(); ImGui::EndTable();

View File

@ -79,57 +79,62 @@ ModuleManager::Module_t ModuleManager::loadModule(std::string path) {
return mod; 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()) { if (modules.find(module) == modules.end()) {
spdlog::error("Module '{0}' doesn't exist", module); spdlog::error("Module '{0}' doesn't exist", module);
return; return -1;
} }
if (instances.find(name) != instances.end()) { if (instances.find(name) != instances.end()) {
spdlog::error("A module instance with the name '{0}' already exists", name); spdlog::error("A module instance with the name '{0}' already exists", name);
return; return -1;
} }
int maxCount = modules[module].info->maxInstances; int maxCount = modules[module].info->maxInstances;
if (countModuleInstances(module) >= maxCount && maxCount > 0) { if (countModuleInstances(module) >= maxCount && maxCount > 0) {
spdlog::error("Maximum number of instances reached for '{0}'", module); spdlog::error("Maximum number of instances reached for '{0}'", module);
return; return -1;
} }
Instance_t inst; Instance_t inst;
inst.module = modules[module]; inst.module = modules[module];
inst.instance = inst.module.createInstance(name); inst.instance = inst.module.createInstance(name);
instances[name] = inst; instances[name] = inst;
onInstanceCreated.emit(name); onInstanceCreated.emit(name);
return 0;
} }
void ModuleManager::deleteInstance(std::string name) { int ModuleManager::deleteInstance(std::string name) {
if (instances.find(name) == instances.end()) { if (instances.find(name) == instances.end()) {
spdlog::error("Tried to remove non-existent instance '{0}'", name); spdlog::error("Tried to remove non-existent instance '{0}'", name);
return; return -1;
} }
onInstanceDelete.emit(name); onInstanceDelete.emit(name);
Instance_t inst = instances[name]; Instance_t inst = instances[name];
inst.module.deleteInstance(inst.instance); inst.module.deleteInstance(inst.instance);
instances.erase(name); instances.erase(name);
onInstanceDeleted.emit(name); onInstanceDeleted.emit(name);
return 0;
} }
void ModuleManager::deleteInstance(ModuleManager::Instance* instance) { int ModuleManager::deleteInstance(ModuleManager::Instance* instance) {
spdlog::error("Delete instance not implemented"); 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()) { if (instances.find(name) == instances.end()) {
spdlog::error("Cannot enable '{0}', instance doesn't exist", name); spdlog::error("Cannot enable '{0}', instance doesn't exist", name);
return; return -1;
} }
instances[name].instance->enable(); instances[name].instance->enable();
return 0;
} }
void ModuleManager::disableInstance(std::string name) { int ModuleManager::disableInstance(std::string name) {
if (instances.find(name) == instances.end()) { if (instances.find(name) == instances.end()) {
spdlog::error("Cannot disable '{0}', instance doesn't exist", name); spdlog::error("Cannot disable '{0}', instance doesn't exist", name);
return; return -1;
} }
instances[name].instance->disable(); instances[name].instance->disable();
return 0;
} }
bool ModuleManager::instanceEnabled(std::string name) { bool ModuleManager::instanceEnabled(std::string name) {

View File

@ -78,12 +78,12 @@ public:
ModuleManager::Module_t loadModule(std::string path); ModuleManager::Module_t loadModule(std::string path);
void createInstance(std::string name, std::string module); int createInstance(std::string name, std::string module);
void deleteInstance(std::string name); int deleteInstance(std::string name);
void deleteInstance(ModuleManager::Instance* instance); int deleteInstance(ModuleManager::Instance* instance);
void enableInstance(std::string name); int enableInstance(std::string name);
void disableInstance(std::string name); int disableInstance(std::string name);
bool instanceEnabled(std::string name); bool instanceEnabled(std::string name);
void postInit(std::string name); void postInit(std::string name);
std::string getInstanceModuleName(std::string name); std::string getInstanceModuleName(std::string name);

View File

@ -20,7 +20,7 @@ const double DeemphasisModes[] {
75e-6 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 { class RadioModule : public ModuleManager::Instance {
public: public: