SDFormat Editor
Loading...
Searching...
No Matches
gui.h
1/*
2* sdformat-editor
3* Copyright 2025 sdformat-editor
4*
5* Licensed under the Apache License, Version 2.0 (the "License");
6* you may not use this file except in compliance with the License.
7* You may obtain a copy of the License at
8*
9* http://www.apache.org/licenses/LICENSE-2.0
10*
11* Unless required by applicable law or agreed to in writing, software
12* distributed under the License is distributed on an "AS IS" BASIS,
13* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14* See the License for the specific language governing permissions and
15* limitations under the License.
16*
17* Developer: Zaid Duraid, Ean Wheeler, Evan Vokey
18*/
19
20#ifndef SDFORMAT_EDITOR_GUI_HH_
21#define SDFORMAT_EDITOR_GUI_HH_
22
23// IMGUI dependencies
24#include <stdio.h>
25#include "imgui.h"
26#include "imgui_impl_glfw.h"
27#include "imgui_impl_opengl3.h"
28#include <GLFW/glfw3.h>
29
30#include <interfaces/gui_interface.h>
31#include "command_factory.h"
32
34class GUI : public GUII
35{
36
41 public: GUI(const std::string &window_name, std::shared_ptr<SDFormatParserI> sdformat_parser, bool &success);
42
44 public: ~GUI();
45
50 private: void Initialize(const std::string &window_name, std::shared_ptr<SDFormatParserI> sdformat_parser, bool &success) override;
51
53 private: bool ShouldClose() override;
54
58 private: std::unique_ptr<CommandI> Update(std::shared_ptr<CommandFactoryI> command_factory) override;
59
62 private: void SetPreventInputFlag(bool set) override;
63
67 private: void OpenChoiceDialog(DialogMessage dialogMessage, std::vector<std::pair<std::string, bool>>& choices) override;
68
72 private: static void GLFWErrorCallback(int error, const char *description);
73
78 private: void DisplaySDFRootElement(std::unique_ptr<CommandI> &command, std::shared_ptr<SDFormatParserI> sdformat_parser,
79 std::shared_ptr<CommandFactoryI> command_factory);
80
83 private: bool SetupNewFrame();
84
88 private: void DrawCoreFrame(std::unique_ptr<CommandI>& command, std::shared_ptr<CommandFactoryI> command_factory);
89
95 private: void CreateModifyAttributeDropdown(sdf::ParamPtr attribute, std::unique_ptr<CommandI> &command,
96 std::shared_ptr<CommandFactoryI> command_factory, int& unique_id);
97
103 private: void CreateModifyElementDropdown(sdf::ElementPtr element, std::unique_ptr<CommandI> &command,
104 std::shared_ptr<CommandFactoryI> command_factory, int& unique_id);
105
111 private: void CreateAppendElementDropdown(sdf::ElementPtr element, std::unique_ptr<CommandI> &command,
112 std::shared_ptr<CommandFactoryI> command_factory, int& unique_id);
113
119 private: void CreateDropdown(const std::vector<std::string>& items, const std::vector<std::string>& item_descriptions, int& selected_item, int& unique_id);
120
122 private: std::unique_lock<std::mutex> LockMutex() override;
123
124 private: std::shared_ptr<CommandFactory> command_factory;
125
127 private: std::atomic<bool> prevent_input_flag = false;
128
130 private: bool model_viewer_running = false;
131
134
136 private: GLFWwindow *window = nullptr;
137
139 private: ImGuiIO *io = nullptr;
140
142 private: std::shared_ptr<SDFormatParserI> sdformat_parser;
143
145 private: sdf::ElementPtr element_to_append_to;
146
148 private: ImVec4 background_colour;
149
151 private: std::mutex gui_mutex;
152
155
157 private: sdf::ParamPtr attribute_to_edit;
158
160 private: sdf::ElementPtr element_to_edit;
161
163 private: bool use_dropdown_for_editing_element = false;
164
165};
166
167#endif
Interface for the SDFormat Editor's Graphical User Interface Note that this class also inherits from ...
Definition gui_interface.h:39
Implementation of GUII.
Definition gui.h:35
bool use_dropdown_for_editing_element
Indicates if a dropdown is used for editing attributes.
Definition gui.h:163
bool model_viewer_running
Flag to indicate if the model viewer is currently running.
Definition gui.h:130
void CreateAppendElementDropdown(sdf::ElementPtr element, std::unique_ptr< CommandI > &command, std::shared_ptr< CommandFactoryI > command_factory, int &unique_id)
Create a dropdown list for an element.
Definition gui.cpp:652
std::atomic< bool > prevent_input_flag
Flag which can be set to prevent the GUI from taking user input.
Definition gui.h:127
void DrawCoreFrame(std::unique_ptr< CommandI > &command, std::shared_ptr< CommandFactoryI > command_factory)
Draw the core part of the ImGUI frame.
Definition gui.cpp:148
void DisplaySDFRootElement(std::unique_ptr< CommandI > &command, std::shared_ptr< SDFormatParserI > sdformat_parser, std::shared_ptr< CommandFactoryI > command_factory)
Function to display the SDF root element in the GUI in a tree format.
Definition gui.cpp:314
GLFWwindow * window
Pointer to the GLFW window object, used to manage for rendering and handling window events.
Definition gui.h:136
bool use_dropdown_for_editing_attribute
Indicates if a dropdown is used for editing attributes.
Definition gui.h:154
std::mutex gui_mutex
Mutex to protect shared resources.
Definition gui.h:151
ImVec4 background_colour
The background color used in the GUI.
Definition gui.h:148
void OpenChoiceDialog(DialogMessage dialogMessage, std::vector< std::pair< std::string, bool > > &choices) override
Implementation of interface method.
Definition gui.cpp:733
void SetPreventInputFlag(bool set) override
Implementation of flag setting method.
Definition gui.cpp:39
sdf::ParamPtr attribute_to_edit
Holds a reference to the attribute the user is currently editing.
Definition gui.h:157
void Initialize(const std::string &window_name, std::shared_ptr< SDFormatParserI > sdformat_parser, bool &success) override
Implementation of interface method, wrapped by constructor.
Definition gui.cpp:49
std::unique_lock< std::mutex > LockMutex() override
Implementation of lock method.
Definition gui.cpp:44
bool SetupNewFrame()
Sets up a new ImGUI frame.
Definition gui.cpp:131
void CreateModifyElementDropdown(sdf::ElementPtr element, std::unique_ptr< CommandI > &command, std::shared_ptr< CommandFactoryI > command_factory, int &unique_id)
Create a dropdown list.
Definition gui.cpp:619
void CreateDropdown(const std::vector< std::string > &items, const std::vector< std::string > &item_descriptions, int &selected_item, int &unique_id)
Create a dropdown list.
Definition gui.cpp:692
bool ShouldClose() override
Implementation of interface method.
Definition gui.cpp:34
std::unique_ptr< CommandI > Update(std::shared_ptr< CommandFactoryI > command_factory) override
Implementation of interface method.
Definition gui.cpp:299
void CreateModifyAttributeDropdown(sdf::ParamPtr attribute, std::unique_ptr< CommandI > &command, std::shared_ptr< CommandFactoryI > command_factory, int &unique_id)
Create a dropdown list.
Definition gui.cpp:586
sdf::ElementPtr element_to_edit
Holds a reference to the element the user is currently editing.
Definition gui.h:160
sdf::ElementPtr element_to_append_to
An element for which we want to show the "append_to" dropdown.
Definition gui.h:145
std::shared_ptr< SDFormatParserI > sdformat_parser
Pointer to the sdformat_parser object.
Definition gui.h:142
ImGuiIO * io
Reference to the ImGuiIO structure, which handles input/output operations for ImGui.
Definition gui.h:139
~GUI()
Destructor.
Definition gui.cpp:785
static void GLFWErrorCallback(int error, const char *description)
Function for handling GLFW Error (required to be static by GLFW)
Definition gui.cpp:29
bool render_collisions_in_model_viewer
Flag to indicate if collisions should be loaded in the model viewer.
Definition gui.h:133
Struct representing a dialog message. This struct encapsulates the components of a dialog message.
Definition gui_interface.h:61