| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- #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 <GLFW/glfw3.h>
- #include <ImGuiFileDialog.h>
- #include <boost/asio/post.hpp>
- 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<std::string>();
- auto create_conf = base_config{
- .asio_ctx = conf.asio_ctx,
- .cuda_ctx = conf.cuda_ctx,
- .ext_conf = app_conf,
- };
- auto app = std::unique_ptr<app_base>();
- if (app_name == "depth_guide") {
- app = std::make_unique<app_depth_guide>(create_conf);
- } else if (app_name == "remote_ar") {
- app = std::make_unique<app_remote_ar>(create_conf);
- } else if (app_name == "tiny_player") {
- app = std::make_unique<app_tiny_player>(create_conf);
- } else if (app_name == "endo_guide") {
- app = std::make_unique<app_endo_guide>(create_conf);
- } else if (app_name == "debug") {
- app = std::make_unique<app_debug>(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);
- });
- }
|