app_selector.cpp 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #include "app_selector.h"
  2. #include "impl/apps/debug/app_debug.h"
  3. #include "impl/apps/endo_guide/endo_guide.h"
  4. #include "impl/apps/depth_guide/depth_guide.h"
  5. #include "impl/apps/remote_ar/remote_ar.h"
  6. #include "impl/apps/tiny_player/tiny_player.h"
  7. #include <GLFW/glfw3.h>
  8. #include <ImGuiFileDialog.h>
  9. #include <boost/asio/post.hpp>
  10. using boost::asio::post;
  11. app_selector::app_selector(const create_config &_conf) {
  12. conf = _conf;
  13. auto dialog_conf = IGFD::FileDialogConfig();
  14. dialog_conf.flags |= ImGuiFileDialogFlags_DisableCreateDirectoryButton;
  15. dialog_conf.flags |= ImGuiFileDialogFlags_HideColumnType;
  16. dialog_conf.flags |= ImGuiFileDialogFlags_ReadOnlyFileNameField;
  17. dialog_conf.flags |= ImGuiFileDialogFlags_CaseInsensitiveExtention;
  18. dialog_conf.path = "/home/tpx/project/DepthGuide/data"; // TODO: remember last value
  19. dialog->OpenDialog(dialog_name, "Choose YAML file",
  20. "YAML files{.yaml,.yml}", dialog_conf);
  21. }
  22. app_selector::~app_selector() {
  23. dialog->Close();
  24. }
  25. void app_selector::show_ui() {
  26. if (dialog->Display(dialog_name)) {
  27. if (dialog->IsOk()) {
  28. load_app(dialog->GetFilePathName());
  29. }
  30. }
  31. }
  32. void app_selector::load_app(const std::string &conf_path) {
  33. auto app_conf = YAML::LoadFile(conf_path);
  34. SPDLOG_INFO("Load application from {}", conf_path);
  35. auto app_name = app_conf["app_name"].as<std::string>();
  36. auto create_conf = base_config{
  37. .asio_ctx = conf.asio_ctx,
  38. .cuda_ctx = conf.cuda_ctx,
  39. .ext_conf = app_conf,
  40. };
  41. auto app = std::unique_ptr<app_base>();
  42. if (app_name == "depth_guide") {
  43. app = std::make_unique<app_depth_guide>(create_conf);
  44. } else if (app_name == "remote_ar") {
  45. app = std::make_unique<app_remote_ar>(create_conf);
  46. } else if (app_name == "tiny_player") {
  47. app = std::make_unique<app_tiny_player>(create_conf);
  48. } else if (app_name == "endo_guide") {
  49. app = std::make_unique<app_endo_guide>(create_conf);
  50. } else if (app_name == "debug") {
  51. app = std::make_unique<app_debug>(create_conf);
  52. }
  53. // change window title
  54. auto window = glfwGetCurrentContext();
  55. glfwSetWindowTitle(window, app->window_name());
  56. // replace application
  57. assert(app != nullptr);
  58. auto app_ptr = conf.app_ptr;
  59. post(*conf.asio_ctx, [=, app = std::move(app)]() mutable {
  60. *app_ptr = std::move(app);
  61. });
  62. }