Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions SofaGLFW/SofaGLFWConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ find_package(Sofa.Simulation.Graph QUIET REQUIRED)
find_package(Sofa.GL QUIET REQUIRED)
find_package(Sofa.Component.Visual QUIET REQUIRED)

if(NOT TARGET glfw)
sofa_find_package(glfw3 QUIET REQUIRED)
endif()

set(SOFAGLFW_HAVE_SOFA_GUI_COMMON @SOFAGLFW_HAVE_SOFA_GUI_COMMON@)
if(SOFAGLFW_HAVE_SOFA_GUI_COMMON)
find_package(Sofa.GUI.Common QUIET REQUIRED)
Expand Down
47 changes: 19 additions & 28 deletions SofaImGui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ sofa_fetch_dependency(imgui
DONT_BUILD
)

# nfd (nativefiledialog-extended)
find_package(nfd CONFIG QUIET)

if(TARGET nfd::nfd)
Expand All @@ -42,43 +43,34 @@ elseif( (DEFINED SOFA_ALLOW_FETCH_DEPENDENCIES AND SOFA_ALLOW_FETCH_DEPENDENCIES
add_library(nfd::nfd ALIAS nfd) # introduced in nfd >= v1.2.1
endif()


# ImPlot
sofa_fetch_dependency(ImPlot
GIT_REPOSITORY https://github.com/epezent/implot
GIT_TAG 18c72431f8265e2b0b5378a3a73d8a883b2175ff # v0.16
DONT_BUILD
)

# IconFontCppHeaders
sofa_fetch_dependency(IconFontCppHeaders
GIT_REPOSITORY https://github.com/juliettef/IconFontCppHeaders
GIT_TAG bf610efb2e5d4361df799d0dfb5ae3977d7bba2e
DONT_BUILD
)

sofa_fetch_dependency(simpleini
GIT_REPOSITORY https://github.com/brofield/simpleini
GIT_TAG 09c21bda1dc1b578fa55f4a005d79b0afd481296 # v4.22
# SimpleIni
find_package(SimpleIni QUIET)

)
if(NOT TARGET SimpleIni::SimpleIni AND ((DEFINED SOFA_ALLOW_FETCH_DEPENDENCIES AND SOFA_ALLOW_FETCH_DEPENDENCIES) OR (NOT DEFINED SOFA_ALLOW_FETCH_DEPENDENCIES)))
message("${PROJECT_NAME}: SimpleIni not found and SOFA_ALLOW_FETCH_DEPENDENCIES is ON, fetching source code...")

sofa_fetch_dependency(simpleini
GIT_REPOSITORY https://github.com/brofield/simpleini
GIT_TAG 09c21bda1dc1b578fa55f4a005d79b0afd481296 # v4.22
)
elseif(NOT TARGET SimpleIni::SimpleIni)
message(FATAL_ERROR "{PROJECT_NAME}: SimpleIni not found and SOFA_ALLOW_FETCH_DEPENDENCIES is OFF and thus cannot be fetched. Install SimpleIni, or enable SOFA_ALLOW_FETCH_DEPENDENCIES to fix this issue.")
endif()

set(IMGUI_HEADER_FILES
${imgui_SOURCE_DIR}/backends/imgui_impl_glfw.h
${imgui_SOURCE_DIR}/backends/imgui_impl_opengl3.h
${imgui_SOURCE_DIR}/backends/imgui_impl_opengl2.h
${imgui_SOURCE_DIR}/imconfig.h
${imgui_SOURCE_DIR}/imgui.h
${imgui_SOURCE_DIR}/imgui_internal.h
${imgui_SOURCE_DIR}/misc/cpp/imgui_stdlib.h
${ImPlot_SOURCE_DIR}/implot.h
${ImPlot_SOURCE_DIR}/implot_internal.h
${IconFontCppHeaders_SOURCE_DIR}/IconsFontAwesome4.h
${IconFontCppHeaders_SOURCE_DIR}/IconsFontAwesome6.h
${simpleini_SOURCE_DIR}/SimpleIni.h
resources/fa-regular-400.h
resources/fa-solid-900.h
resources/Roboto-Medium.h
resources/Style.h
)
set(IMGUI_SOURCE_FILES
${imgui_SOURCE_DIR}/backends/imgui_impl_glfw.cpp
${imgui_SOURCE_DIR}/backends/imgui_impl_opengl3.cpp
Expand All @@ -102,24 +94,20 @@ set(HEADER_FILES
${SOFAIMGUI_SOURCE_DIR}/ImGuiDataWidget.h
${SOFAIMGUI_SOURCE_DIR}/ImGuiGUI.h
${SOFAIMGUI_SOURCE_DIR}/ImGuiGUIEngine.h
${SOFAIMGUI_SOURCE_DIR}/ObjectColor.h
${SOFAIMGUI_SOURCE_DIR}/UIStrings.h
${SOFAIMGUI_SOURCE_DIR}/widgets/DisplayFlagsWidget.h
${SOFAIMGUI_SOURCE_DIR}/widgets/LinearSpringWidget.h
${SOFAIMGUI_SOURCE_DIR}/widgets/MaterialWidget.h
${SOFAIMGUI_SOURCE_DIR}/widgets/RigidMass.h
${SOFAIMGUI_SOURCE_DIR}/widgets/ScalarWidget.h
${SOFAIMGUI_SOURCE_DIR}/widgets/VecVectorWidget.h
${SOFAIMGUI_SOURCE_DIR}/windows/Performances.h
${SOFAIMGUI_SOURCE_DIR}/windows/Log.h
${SOFAIMGUI_SOURCE_DIR}/windows/MouseManager.h
${SOFAIMGUI_SOURCE_DIR}/windows/Profiler.h
${SOFAIMGUI_SOURCE_DIR}/windows/SceneGraph.h
${SOFAIMGUI_SOURCE_DIR}/windows/DisplayFlags.h
${SOFAIMGUI_SOURCE_DIR}/windows/Plugins.h
${SOFAIMGUI_SOURCE_DIR}/windows/Components.h
${SOFAIMGUI_SOURCE_DIR}/windows/Settings.h
${SOFAIMGUI_SOURCE_DIR}/windows/ViewPort.h
${SOFAIMGUI_SOURCE_DIR}/AppIniFile.h
${SOFAIMGUI_SOURCE_DIR}/windows/WindowState.h
${SOFAIMGUI_SOURCE_DIR}/guis/BaseAdditionalGUI.h
Expand All @@ -134,6 +122,8 @@ set(SOURCE_FILES
${SOFAIMGUI_SOURCE_DIR}/initSofaImGui.cpp
${SOFAIMGUI_SOURCE_DIR}/widgets/DisplayFlagsWidget.cpp
${SOFAIMGUI_SOURCE_DIR}/widgets/MaterialWidget.cpp
${SOFAIMGUI_SOURCE_DIR}/widgets/RigidMass.cpp
${SOFAIMGUI_SOURCE_DIR}/widgets/ScalarWidget.cpp
${SOFAIMGUI_SOURCE_DIR}/windows/Performances.cpp
${SOFAIMGUI_SOURCE_DIR}/windows/Log.cpp
${SOFAIMGUI_SOURCE_DIR}/windows/MouseManager.cpp
Expand All @@ -154,10 +144,11 @@ set(SOURCE_FILES

set(IMGUI_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/resources ${imgui_SOURCE_DIR} ${ImPlot_SOURCE_DIR} ${IconFontCppHeaders_SOURCE_DIR} ${simpleini_SOURCE_DIR})

add_library(${PROJECT_NAME} SHARED ${HEADER_FILES} ${SOURCE_FILES} ${IMGUI_HEADER_FILES} ${IMGUI_SOURCE_FILES})
add_library(${PROJECT_NAME} SHARED ${HEADER_FILES} ${SOURCE_FILES} ${IMGUI_SOURCE_FILES})
target_include_directories(${PROJECT_NAME} PUBLIC "$<BUILD_INTERFACE:${IMGUI_SOURCE_DIR}>")
target_link_libraries(${PROJECT_NAME} PUBLIC SofaGLFW Sofa.GL.Component.Rendering3D ${CMAKE_DL_LIBS})
target_link_libraries(${PROJECT_NAME} PRIVATE nfd)
target_link_libraries(${PROJECT_NAME} PRIVATE SimpleIni::SimpleIni)

# setup the same API exports for imgui
target_compile_definitions(${PROJECT_NAME} PUBLIC IMGUI_API=SOFAIMGUI_API)
Expand Down
9 changes: 9 additions & 0 deletions SofaImGui/extensions/SofaImGui.Camera/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ project(SofaImGui.Camera VERSION 1.0 LANGUAGES CXX)
find_package(Sofa.Config REQUIRED)
sofa_find_package(SofaImGui REQUIRED)

sofa_fetch_dependency(imgui
GIT_REPOSITORY https://github.com/ocornut/imgui
GIT_TAG 11b3a7c8ca23201294464c7f368614a9106af2a1 # v1.91.8-docking
DONT_BUILD
)

set(HEADER_FILES
src/SofaImGui.Camera/config.h.in
src/SofaImGui.Camera/init.h
Expand All @@ -18,7 +24,10 @@ set(SOURCE_FILES
src/SofaImGui.Camera/CameraGUI.cpp
)

set(IMGUI_SOURCE_DIR ${imgui_SOURCE_DIR})

add_library(${PROJECT_NAME} SHARED ${HEADER_FILES} ${SOURCE_FILES})
target_include_directories(${PROJECT_NAME} PUBLIC "$<BUILD_INTERFACE:${IMGUI_SOURCE_DIR}>")
target_link_libraries(${PROJECT_NAME} PUBLIC SofaImGui)

sofa_create_package_with_targets(
Expand Down
1 change: 0 additions & 1 deletion SofaImGui/src/SofaImGui/AppIniFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
#include <sofa/helper/Utils.h>
#include <sofa/helper/system/FileSystem.h>
#include <sofa/gui/common/BaseGUI.h>
#include "windows/Performances.h"
#include "AppIniFile.h"


Expand Down
60 changes: 35 additions & 25 deletions SofaImGui/src/SofaImGui/ImGuiGUIEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <iomanip>
#include <ostream>
#include <unordered_set>
#include <type_traits>
#include <SofaGLFW/SofaGLFWBaseGUI.h>

#include <sofa/core/CategoryLibrary.h>
Expand Down Expand Up @@ -68,6 +69,7 @@
#include <imgui_internal.h> //imgui_internal.h is included in order to use the DockspaceBuilder API (which is still in development)
#include <implot.h>
#include <nfd.h>
#include <SimpleIni.h>
#include <sofa/component/visual/VisualStyle.h>
#include <sofa/core/ObjectFactory.h>
#include <sofa/core/visual/VisualParams.h>
Expand All @@ -86,6 +88,11 @@ using namespace sofa;
namespace sofaimgui
{

struct ImGuiGUIEngine::Settings
{
CSimpleIniA ini;
};

ImGuiGUIEngine::ImGuiGUIEngine()
: winManagerProfiler(helper::system::FileSystem::append(sofaimgui::getConfigurationFolderPath(), std::string("profiler.txt")))
, winManagerSceneGraph(helper::system::FileSystem::append(sofaimgui::getConfigurationFolderPath(), std::string("scenegraph.txt")))
Expand All @@ -103,6 +110,9 @@ ImGuiGUIEngine::ImGuiGUIEngine()
{
}

ImGuiGUIEngine::~ImGuiGUIEngine()
{}

void ImGuiGUIEngine::init()
{
IMGUI_CHECKVERSION();
Expand All @@ -121,22 +131,21 @@ void ImGuiGUIEngine::init()
io.ConfigFlags |= ImGuiConfigFlags_DockingEnable;
io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable;



ini.SetUnicode();
settings = std::make_unique<Settings>();
settings->ini.SetUnicode();
if (sofa::helper::system::FileSystem::exists(sofaimgui::AppIniFile::getAppIniFile()))
{
[[maybe_unused]] SI_Error rc = ini.LoadFile(sofaimgui::AppIniFile::getAppIniFile().c_str());
[[maybe_unused]] SI_Error rc = settings->ini.LoadFile(sofaimgui::AppIniFile::getAppIniFile().c_str());
assert(rc == SI_OK);
msg_info("ImGuiGUIEngine") << "Fetching settings from " << sofaimgui::AppIniFile::getAppIniFile();
}

const char* pv;
pv = ini.GetValue("Style", "theme");
pv = settings->ini.GetValue("Style", "theme");
if (!pv)
{
ini.SetValue("Style", "theme", sofaimgui::defaultStyle.c_str(), ini::styleDescription);
SI_Error rc = ini.SaveFile(sofaimgui::AppIniFile::getAppIniFile().c_str());
settings->ini.SetValue("Style", "theme", sofaimgui::defaultStyle.c_str(), ini::styleDescription);
SI_Error rc = settings->ini.SaveFile(sofaimgui::AppIniFile::getAppIniFile().c_str());
if (rc != SI_OK)
{
msg_error("ImGuiGUIEngine") << "Saving file '" << sofaimgui::AppIniFile::getAppIniFile() << "' failed. " << std::strerror(errno) << ". Error code " << rc;
Expand Down Expand Up @@ -188,18 +197,18 @@ void ImGuiGUIEngine::initBackend(GLFWwindow* glfwWindow)
io.Fonts->AddFontFromMemoryCompressedTTF(FA_SOLID_900_compressed_data, FA_SOLID_900_compressed_size, 16 * yscale, &config, icon_ranges);

// restore the global scale stored in the Settings ini file
const float globalScale = static_cast<float>(ini.GetDoubleValue("Visualization", "globalScale", 1.0));
const float globalScale = static_cast<float>(settings->ini.GetDoubleValue("Visualization", "globalScale", 1.0));
this->setScale(globalScale, windowMonitor);
}

// restore window settings if set
const bool rememberWindowPosition = ini.GetBoolValue("Window", "rememberWindowPosition", true);
const bool rememberWindowPosition = settings->ini.GetBoolValue("Window", "rememberWindowPosition", true);
if(rememberWindowPosition)
{
if(ini.KeyExists("Window", "windowPosX") && ini.KeyExists("Window", "windowPosY"))
if(settings->ini.KeyExists("Window", "windowPosX") && settings->ini.KeyExists("Window", "windowPosY"))
{
const long windowPosX = ini.GetLongValue("Window", "windowPosX");
const long windowPosY = ini.GetLongValue("Window", "windowPosY");
const long windowPosX = settings->ini.GetLongValue("Window", "windowPosX");
const long windowPosY = settings->ini.GetLongValue("Window", "windowPosY");

int monitorCount;
GLFWmonitor** monitors = glfwGetMonitors(&monitorCount);
Expand Down Expand Up @@ -246,13 +255,13 @@ void ImGuiGUIEngine::initBackend(GLFWwindow* glfwWindow)

}

const bool rememberWindowSize = ini.GetBoolValue("Window", "rememberWindowSize", true);
const bool rememberWindowSize = settings->ini.GetBoolValue("Window", "rememberWindowSize", true);
if(rememberWindowSize)
{
if(ini.KeyExists("Window", "windowSizeX") && ini.KeyExists("Window", "windowSizeY"))
if(settings->ini.KeyExists("Window", "windowSizeX") && settings->ini.KeyExists("Window", "windowSizeY"))
{
const long windowSizeX = ini.GetLongValue("Window", "windowSizeX");
const long windowSizeY = ini.GetLongValue("Window", "windowSizeY");
const long windowSizeX = settings->ini.GetLongValue("Window", "windowSizeX");
const long windowSizeY = settings->ini.GetLongValue("Window", "windowSizeY");
if(windowSizeX > 0 && windowSizeY > 0)
{
glfwSetWindowSize(glfwWindow, static_cast<int>(windowSizeX), static_cast<int>(windowSizeY));
Expand Down Expand Up @@ -398,7 +407,7 @@ void ImGuiGUIEngine::startFrame(sofaglfw::SofaGLFWBaseGUI* baseGUI)

auto groot = baseGUI->getRootNode();

bool alwaysShowFrame = ini.GetBoolValue("Visualization", "alwaysShowFrame", true);
bool alwaysShowFrame = settings->ini.GetBoolValue("Visualization", "alwaysShowFrame", true);
if (alwaysShowFrame)
{
auto sceneFrame = groot->get<sofa::gl::component::rendering3d::OglSceneFrame>();
Expand Down Expand Up @@ -682,7 +691,7 @@ void ImGuiGUIEngine::startFrame(sofaglfw::SofaGLFWBaseGUI* baseGUI)
/***************************************
* Viewport window
**************************************/
windows::showViewPort(groot, windowNameViewport, ini, m_fbo, m_viewportWindowSize,
windows::showViewPort(groot, windowNameViewport, settings->ini, m_fbo, m_viewportWindowSize,
isMouseOnViewport, winManagerViewPort, baseGUI,
isViewportDisplayedForTheFirstTime, lastViewPortPos);

Expand Down Expand Up @@ -756,7 +765,7 @@ void ImGuiGUIEngine::startFrame(sofaglfw::SofaGLFWBaseGUI* baseGUI)
/***************************************
* Settings window
**************************************/
windows::showSettings(windowNameSettings,ini, winManagerSettings, this);
windows::showSettings(windowNameSettings, settings->ini, winManagerSettings, this);

ImGui::Render();
#if SOFAIMGUI_FORCE_OPENGL2 == 1
Expand All @@ -782,8 +791,9 @@ void ImGuiGUIEngine::endFrame()
std::setlocale(LC_NUMERIC, m_localeBackup.c_str());
}

void ImGuiGUIEngine::resetView(ImGuiID dockspace_id, const char* windowNameSceneGraph, const char* winNameSelectionDescription, const char *windowNameLog, const char *windowNameViewport)
void ImGuiGUIEngine::resetView(_ImGuiID dockspace_id, const char* windowNameSceneGraph, const char* winNameSelectionDescription, const char *windowNameLog, const char *windowNameViewport)
{
static_assert(std::is_same<_ImGuiID, ImGuiID>::value, "_ImGuiID and ImGuiID types must be identical. _ImGuiID must be adjusted.");
ImGuiViewport* viewport = ImGui::GetMainViewport();

ImGui::DockBuilderRemoveNode(dockspace_id); // clear any previous layout
Expand Down Expand Up @@ -854,11 +864,11 @@ void ImGuiGUIEngine::terminate()
const auto lastWindowSize = ImGui::GetMainViewport()->Size;

// save latest window state
ini.SetLongValue("Window", "windowPosX", static_cast<long>(lastWindowPos.x));
ini.SetLongValue("Window", "windowPosY", static_cast<long>(lastWindowPos.y));
ini.SetLongValue("Window", "windowSizeX", static_cast<long>(lastWindowSize.x));
ini.SetLongValue("Window", "windowSizeY", static_cast<long>(lastWindowSize.y));
[[maybe_unused]] SI_Error rc = ini.SaveFile(sofaimgui::AppIniFile::getAppIniFile().c_str());
settings->ini.SetLongValue("Window", "windowPosX", static_cast<long>(lastWindowPos.x));
settings->ini.SetLongValue("Window", "windowPosY", static_cast<long>(lastWindowPos.y));
settings->ini.SetLongValue("Window", "windowSizeX", static_cast<long>(lastWindowSize.x));
settings->ini.SetLongValue("Window", "windowSizeY", static_cast<long>(lastWindowSize.y));
[[maybe_unused]] SI_Error rc = settings->ini.SaveFile(sofaimgui::AppIniFile::getAppIniFile().c_str());

NFD_Quit();

Expand Down
12 changes: 7 additions & 5 deletions SofaImGui/src/SofaImGui/ImGuiGUIEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@

#include "guis/AdditionalGUIRegistry.h"
#include "windows/WindowState.h"
#include <SimpleIni.h>
#include <imgui.h>

using windows::WindowState;

Expand All @@ -49,7 +47,7 @@ class ImGuiGUIEngine : public sofaglfw::BaseGUIEngine
public:

ImGuiGUIEngine() ;
~ImGuiGUIEngine() = default;
~ImGuiGUIEngine();

void init() override;
void initBackend(GLFWwindow*) override;
Expand Down Expand Up @@ -83,8 +81,12 @@ class ImGuiGUIEngine : public sofaglfw::BaseGUIEngine
std::pair<unsigned int, unsigned int> m_currentFBOSize;
std::pair<float, float> m_viewportWindowSize;
bool isMouseOnViewport { false };
CSimpleIniA ini;
void resetView(ImGuiID dockspace_id, const char *windowNameSceneGraph, const char *winNameSelectionDescription, const char *windowNameLog, const char *windowNameViewport) ;

struct Settings;
std::unique_ptr<Settings> settings;

using _ImGuiID = unsigned int;
void resetView(_ImGuiID dockspace_id, const char *windowNameSceneGraph, const char *winNameSelectionDescription, const char *windowNameLog, const char *windowNameViewport) ;

// WindowState members
windows::WindowState winManagerProfiler;
Expand Down
Loading
Loading