// ---------------------------------------------------------------------------- // - Open3D: www.open3d.org - // ---------------------------------------------------------------------------- // The MIT License (MIT) // // Copyright (c) 2018 www.open3d.org // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal // in the Software without restriction, including without limitation the rights // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS // IN THE SOFTWARE. // ---------------------------------------------------------------------------- #include "Open3D/GUI/Application.h" #include #include #include #include #include "Open3D/GUI/Button.h" #include "Open3D/GUI/Events.h" #include "Open3D/GUI/Label.h" #include "Open3D/GUI/Layout.h" #include "Open3D/GUI/Native.h" #include "Open3D/GUI/Theme.h" #include "Open3D/GUI/Window.h" #include "Open3D/Utility/Console.h" #include "Open3D/Utility/FileSystem.h" #include "Open3D/Visualization/Rendering/Filament/FilamentEngine.h" namespace { const double RUNLOOP_DELAY_SEC = 0.010; std::string FindResourcePath(int argc, const char *argv[]) { std::string argv0; if (argc != 0 && argv) { argv0 = argv[0]; } // Convert backslash (Windows) to forward slash for (auto &c : argv0) { if (c == '\\') { c = '/'; } } // Chop off the process name auto last_slash = argv0.rfind("/"); auto path = argv0.substr(0, last_slash); if (argv0[0] == '/' || (argv0.size() > 3 && argv0[1] == ':' && argv0[2] == '/')) { // is absolute path, we're done } else { // relative path: prepend working directory auto cwd = open3d::utility::filesystem::GetWorkingDirectory(); path = cwd + "/" + path; } #ifdef __APPLE__ if (path.rfind("MacOS") == path.size() - 5) { // path is in a bundle return path.substr(0, path.size() - 5) + "Resources"; } #endif // __APPLE__ auto resource_path = path + "/resources"; if (!open3d::utility::filesystem::DirectoryExists(resource_path)) { return path + "/../resources"; // building with Xcode } return resource_path; } } // namespace namespace open3d { namespace gui { struct Application::Impl { std::string resource_path_; Theme theme_; double last_time_ = 0.0; bool is_GLFW_initalized_ = false; bool is_running_ = false; bool should_quit_ = false; std::shared_ptr menubar_; std::unordered_set> windows_; std::unordered_set> windows_to_be_destroyed_; void InitGFLW() { if (this->is_GLFW_initalized_) { return; } #if __APPLE__ glfwInitHint(GLFW_COCOA_MENUBAR, GLFW_FALSE); // no auto-create menubar #endif glfwInit(); this->is_GLFW_initalized_ = true; } }; Application &Application::GetInstance() { static Application g_app; return g_app; } void Application::ShowMessageBox(const char *title, const char *message) { utility::LogInfo("{}", message); auto alert = std::make_shared((title ? title : "Alert"), Window::FLAG_TOPMOST); auto em = alert->GetTheme().font_size; auto layout = std::make_shared(em, Margins(em)); auto msg = std::make_shared