Open3D (C++ API)
Application.h
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - Open3D: www.open3d.org -
3 // ----------------------------------------------------------------------------
4 // The MIT License (MIT)
5 //
6 // Copyright (c) 2018 www.open3d.org
7 //
8 // Permission is hereby granted, free of charge, to any person obtaining a copy
9 // of this software and associated documentation files (the "Software"), to deal
10 // in the Software without restriction, including without limitation the rights
11 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 // copies of the Software, and to permit persons to whom the Software is
13 // furnished to do so, subject to the following conditions:
14 //
15 // The above copyright notice and this permission notice shall be included in
16 // all copies or substantial portions of the Software.
17 //
18 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
24 // IN THE SOFTWARE.
25 // ----------------------------------------------------------------------------
26 
27 #pragma once
28 
29 #include <functional>
30 #include <memory>
31 
32 #include "Open3D/GUI/Menu.h"
33 
34 namespace open3d {
35 namespace gui {
36 
37 struct Theme;
38 class Window;
39 
40 class Application {
41 public:
42  static Application &GetInstance();
43 
44  virtual ~Application();
45 
49  void Initialize();
53  void Initialize(int argc, const char *argv[]);
54 
57  void Run();
58  bool RunOneTick(); // internal use
60  void Quit();
61 
62  std::shared_ptr<Menu> GetMenubar() const;
63  void SetMenubar(std::shared_ptr<Menu> menubar);
64 
66  void AddWindow(std::shared_ptr<Window> window);
68  void RemoveWindow(Window *window);
69 
78  void ShowMessageBox(const char *title, const char *message);
79 
80  // (std::string not good in interfaces for ABI reasons)
81  const char *GetResourcePath() const;
82 
87  const Theme &GetTheme() const;
88 
91  double Now() const;
92 
94  void OnMenuItemSelected(Menu::ItemId itemId);
95 
100  void OnTerminate();
101 
102 private:
103  Application();
104 
105  enum class RunStatus { CONTINUE, DONE };
106  RunStatus ProcessQueuedEvents();
107 
108 private:
109  struct Impl;
110  std::unique_ptr<Impl> impl_;
111 };
112 
113 } // namespace gui
114 } // namespace open3d
void OnTerminate()
Definition: Application.cpp:259
std::shared_ptr< Menu > GetMenubar() const
Definition: Application.cpp:210
Definition: Window.h:49
void Quit()
Closes all the windows, which exits as a result.
Definition: Application.cpp:253
void AddWindow(std::shared_ptr< Window > window)
Must be called on the same thread that calls Run()
Definition: Application.cpp:233
void OnMenuItemSelected(Menu::ItemId itemId)
Delivers the itemId to the active window. Used internally.
Definition: Application.cpp:264
const Theme & GetTheme() const
Definition: Application.cpp:361
Definition: Application.cpp:93
bool RunOneTick()
Definition: Application.cpp:286
void SetMenubar(std::shared_ptr< Menu > menubar)
Definition: Application.cpp:214
void ShowMessageBox(const char *title, const char *message)
Definition: Application.cpp:123
double Now() const
Definition: Application.cpp:208
Definition: Open3DViewer.h:29
static Application & GetInstance()
Definition: Application.cpp:118
Definition: Application.h:40
int ItemId
Definition: Menu.h:45
virtual ~Application()
Definition: Application.cpp:188
void Initialize()
Definition: Application.cpp:190
void Run()
Definition: Application.cpp:281
void RemoveWindow(Window *window)
Must be called on the same thread that calls Run()
Definition: Application.cpp:239
const char * GetResourcePath() const
Definition: Application.cpp:357
Definition: Theme.h:38