#include "app_selector.h" #include "impl/apps/debug/app_debug.h" #include "impl/apps/endo_guide/endo_guide.h" #include "impl/apps/depth_guide/depth_guide.h" #include "impl/apps/remote_ar/remote_ar.h" #include "impl/apps/tiny_player/tiny_player.h" #include #include #include using boost::asio::post; app_selector::app_selector(const create_config &_conf) { conf = _conf; auto dialog_conf = IGFD::FileDialogConfig(); dialog_conf.flags |= ImGuiFileDialogFlags_DisableCreateDirectoryButton; dialog_conf.flags |= ImGuiFileDialogFlags_HideColumnType; dialog_conf.flags |= ImGuiFileDialogFlags_ReadOnlyFileNameField; dialog_conf.flags |= ImGuiFileDialogFlags_CaseInsensitiveExtention; dialog_conf.path = "/home/tpx/project/DepthGuide/data"; // TODO: remember last value dialog->OpenDialog(dialog_name, "Choose YAML file", "YAML files{.yaml,.yml}", dialog_conf); } app_selector::~app_selector() { dialog->Close(); } void app_selector::show_ui() { if (dialog->Display(dialog_name)) { if (dialog->IsOk()) { load_app(dialog->GetFilePathName()); } } } void app_selector::load_app(const std::string &conf_path) { auto app_conf = YAML::LoadFile(conf_path); SPDLOG_INFO("Load application from {}", conf_path); auto app_name = app_conf["app_name"].as(); auto create_conf = base_config{ .asio_ctx = conf.asio_ctx, .cuda_ctx = conf.cuda_ctx, .ext_conf = app_conf, }; auto app = std::unique_ptr(); if (app_name == "depth_guide") { app = std::make_unique(create_conf); } else if (app_name == "remote_ar") { app = std::make_unique(create_conf); } else if (app_name == "tiny_player") { app = std::make_unique(create_conf); } else if (app_name == "endo_guide") { app = std::make_unique(create_conf); } else if (app_name == "debug") { app = std::make_unique(create_conf); } // change window title auto window = glfwGetCurrentContext(); glfwSetWindowTitle(window, app->window_name()); // replace application assert(app != nullptr); auto app_ptr = conf.app_ptr; post(*conf.asio_ctx, [=, app = std::move(app)]() mutable { *app_ptr = std::move(app); }); }