Line |
Branch |
Exec |
Source |
1 |
|
|
// This file is part of INSTINCT, the INS Toolkit for Integrated |
2 |
|
|
// Navigation Concepts and Training by the Institute of Navigation of |
3 |
|
|
// the University of Stuttgart, Germany. |
4 |
|
|
// |
5 |
|
|
// This Source Code Form is subject to the terms of the Mozilla Public |
6 |
|
|
// License, v. 2.0. If a copy of the MPL was not distributed with this |
7 |
|
|
// file, You can obtain one at https://mozilla.org/MPL/2.0/. |
8 |
|
|
|
9 |
|
|
/// @file NodeEditorApplication.hpp |
10 |
|
|
/// @brief GUI callbacks |
11 |
|
|
/// @author T. Topp (topp@ins.uni-stuttgart.de) |
12 |
|
|
/// @date 2020-12-14 |
13 |
|
|
|
14 |
|
|
#pragma once |
15 |
|
|
|
16 |
|
|
#include <array> |
17 |
|
|
#include <cstdint> |
18 |
|
|
#include <vector> |
19 |
|
|
|
20 |
|
|
#include <application.h> |
21 |
|
|
#include <imgui.h> |
22 |
|
|
#include <implot.h> |
23 |
|
|
|
24 |
|
|
#include "internal/gui/GlobalActions.hpp" |
25 |
|
|
#include "internal/gui/windows/FontSizeEditor.hpp" |
26 |
|
|
|
27 |
|
|
namespace NAV |
28 |
|
|
{ |
29 |
|
|
class Node; |
30 |
|
|
class Pin; |
31 |
|
|
|
32 |
|
|
namespace gui |
33 |
|
|
{ |
34 |
|
|
/// @brief Application class providing all relevant GUI callbacks |
35 |
|
|
class NodeEditorApplication : public Application |
36 |
|
|
{ |
37 |
|
|
private: |
38 |
|
|
constexpr static float BOTTOM_VIEW_COLLAPSED_MIN_HEIGHT = 23.0F; ///< Minimal height of the bottom view if it is collapsed |
39 |
|
|
constexpr static float BOTTOM_VIEW_UNCOLLAPSED_MIN_HEIGHT = 200.0F; ///< Minimal height of the bottom view if it is not collapsed |
40 |
|
|
|
41 |
|
|
public: |
42 |
|
|
/// @brief Default constructor |
43 |
|
|
NodeEditorApplication() = delete; |
44 |
|
|
/// @brief Destructor |
45 |
|
✗ |
~NodeEditorApplication() override = default; |
46 |
|
|
/// @brief Copy constructor |
47 |
|
|
NodeEditorApplication(const NodeEditorApplication&) = delete; |
48 |
|
|
/// @brief Move constructor |
49 |
|
|
NodeEditorApplication(NodeEditorApplication&&) = delete; |
50 |
|
|
/// @brief Copy assignment operator |
51 |
|
|
NodeEditorApplication& operator=(const NodeEditorApplication&) = delete; |
52 |
|
|
/// @brief Move assignment operator |
53 |
|
|
NodeEditorApplication& operator=(NodeEditorApplication&&) = delete; |
54 |
|
|
|
55 |
|
|
/// Bring the Application Constructors into this class (NOLINTNEXTLINE) |
56 |
|
|
using Application::Application; |
57 |
|
|
|
58 |
|
|
// static Node* SpawnInputActionNode(); |
59 |
|
|
|
60 |
|
|
// static Node* SpawnLessNode(); |
61 |
|
|
|
62 |
|
|
// static Node* SpawnGroupBox(); |
63 |
|
|
|
64 |
|
|
/// @brief Called when the application is started |
65 |
|
|
void OnStart() override; |
66 |
|
|
|
67 |
|
|
/// @brief Called when the application is stopped |
68 |
|
|
void OnStop() override; |
69 |
|
|
|
70 |
|
|
/// @brief Called when the user request the application to close |
71 |
|
|
/// |
72 |
|
|
/// Checks whether there are unsaved changes and then prompts the user to save them before quit |
73 |
|
|
/// @return True if no unsaved changes |
74 |
|
|
bool OnQuitRequest() override; |
75 |
|
|
|
76 |
|
|
/// @brief Called on every frame |
77 |
|
|
/// @param[in] deltaTime Time since last frame |
78 |
|
|
void OnFrame(float deltaTime) override; |
79 |
|
|
|
80 |
|
|
/// @brief Shows a PopupModal asking the user if he wants to quit with unsaved changes |
81 |
|
|
void ShowQuitRequested(); |
82 |
|
|
/// @brief Shows a PopupModel where the user can select a path to save his flow to |
83 |
|
|
void ShowSaveAsRequested(); |
84 |
|
|
/// @brief Shows a PopupModel to clear the current flow |
85 |
|
|
void ShowClearNodesRequested(); |
86 |
|
|
/// @brief Shows a PopupModel loading a new flow |
87 |
|
|
void ShowLoadRequested(); |
88 |
|
|
/// @brief Shows a PopupModal where the user can rename the node |
89 |
|
|
/// @param[in, out] renameNode Pointer to the node to rename. Pointer gets nulled when finished. |
90 |
|
|
static void ShowRenameNodeRequest(Node*& renameNode); |
91 |
|
|
/// @brief Shows a PopupModal where the user can rename the pin |
92 |
|
|
/// @param[in, out] renamePin Pointer to the pin to rename. Pointer gets nulled when finished. |
93 |
|
|
static void ShowRenamePinRequest(Pin*& renamePin); |
94 |
|
|
|
95 |
|
|
/// @brief Frame counter to block the navigate to content function till nodes are correctly loaded |
96 |
|
|
int frameCountNavigate = 0; |
97 |
|
|
|
98 |
|
|
/// Shows the queue size on the pins (every frame the queue mutex will be locked) |
99 |
|
|
static inline bool _showQueueSizeOnPins = false; |
100 |
|
|
|
101 |
|
|
/// @brief Pointer to the texture for the instinct logo |
102 |
|
|
static inline std::array<ImTextureID, 2> m_InstinctLogo{ nullptr, nullptr }; |
103 |
|
|
|
104 |
|
|
/// @brief Pointer to the texture for the INS logo |
105 |
|
|
static inline std::array<ImTextureID, 2> m_InsLogo{ nullptr, nullptr }; |
106 |
|
|
|
107 |
|
|
/// @brief Pointer to the texture for the save button |
108 |
|
|
static inline ImTextureID m_SaveButtonImage = nullptr; |
109 |
|
|
|
110 |
|
|
/// @brief Pointer to the texture for the rose figure (ImuSimulator node) |
111 |
|
|
static inline ImTextureID m_RoseFigure = nullptr; |
112 |
|
|
|
113 |
|
|
/// @brief Default style of the ImPlot library to compare changes against |
114 |
|
|
static inline ImPlotStyle imPlotReferenceStyle; |
115 |
|
|
|
116 |
|
|
static inline bool hideLeftPane = false; ///< Hide left pane |
117 |
|
|
static inline bool hideFPS = false; ///< Hide FPS counter |
118 |
|
|
inline static float leftPaneWidth = 350.0F; ///< Width of the left pane |
119 |
|
|
inline static float rightPaneWidth = 850.0F; ///< Width of the right pane |
120 |
|
|
inline static float menuBarHeight = 20; ///< Height of the menu bar on top |
121 |
|
|
constexpr static float SPLITTER_THICKNESS = 4.0F; ///< Thickness of the splitter between left and right pane |
122 |
|
|
inline static float bottomViewHeight = BOTTOM_VIEW_COLLAPSED_MIN_HEIGHT; ///< Height of the log viewer |
123 |
|
|
|
124 |
|
|
/// Ratio to multiply for default GUI elements |
125 |
|
|
static float defaultFontRatio(); |
126 |
|
|
/// Ratio to multiply for GUI window elements |
127 |
|
|
static float windowFontRatio(); |
128 |
|
|
/// Ratio to multiply for GUI editor elements |
129 |
|
|
static float panelFontRatio(); |
130 |
|
|
/// Ratio to multiply for log output GUI elements |
131 |
|
|
static float monoFontRatio(); |
132 |
|
|
/// Ratio to multiply for node header elements |
133 |
|
|
static float headerFontRatio(); |
134 |
|
|
|
135 |
|
|
/// Available color settings |
136 |
|
|
enum Colors : uint8_t |
137 |
|
|
{ |
138 |
|
|
COLOR_GROUP_HEADER_TEXT, ///< Color of the group header text |
139 |
|
|
COLOR_GROUP_HEADER_BG, ///< Color of the group header background |
140 |
|
|
COLOR_GROUP_OUTER_BORDER, ///< Color of the group outer border |
141 |
|
|
}; |
142 |
|
|
|
143 |
|
|
/// Color settings |
144 |
|
|
static inline std::vector<ImVec4> m_colors = { |
145 |
|
|
{ 1.0, 1.0, 1.0, 1.0 }, // GROUP_HEADER_TEXT |
146 |
|
|
{ 1.0, 1.0, 1.0, 0.25 }, // GROUP_HEADER_BG |
147 |
|
|
{ 1.0, 1.0, 1.0, 0.25 }, // GROUP_OUTER_BORDER |
148 |
|
|
}; |
149 |
|
|
/// Color names |
150 |
|
|
static inline std::vector<const char*> m_colorsNames = { |
151 |
|
|
"GroupHeaderText", // GROUP_HEADER_TEXT |
152 |
|
|
"GroupHeaderBg", // GROUP_HEADER_BG |
153 |
|
|
"GroupOuterBorder", // GROUP_OUTER_BORDER |
154 |
|
|
}; |
155 |
|
|
|
156 |
|
|
private: |
157 |
|
|
/// @brief Tabs displayed in the bottom view |
158 |
|
|
enum class BottomViewTabItem : uint8_t |
159 |
|
|
{ |
160 |
|
|
None, ///< The cross item is selected |
161 |
|
|
LogOutput, ///< The log output item is selected |
162 |
|
|
}; |
163 |
|
|
|
164 |
|
|
BottomViewTabItem bottomViewSelectedTab = BottomViewTabItem::None; ///< Selected Tab item in the bottom view |
165 |
|
|
|
166 |
|
|
/// @brief Pointer to the texture for the node headers |
167 |
|
|
ImTextureID m_HeaderBackground = nullptr; |
168 |
|
|
|
169 |
|
|
/// @brief Global action to execute |
170 |
|
|
GlobalActions globalAction = GlobalActions::None; // TODO: Move to the GlobalAction.cpp as a global variable |
171 |
|
|
|
172 |
|
|
/// @brief Shows a window for choosing the font size |
173 |
|
|
/// @param[in, out] show Flag which indicates whether the window is shown |
174 |
|
|
friend void windows::ShowFontSizeEditor(bool* show); |
175 |
|
|
}; |
176 |
|
|
|
177 |
|
|
} // namespace gui |
178 |
|
|
} // namespace NAV |
179 |
|
|
|