Skip to content
44 changes: 19 additions & 25 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,7 +94,6 @@ 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
Expand Down Expand Up @@ -133,6 +124,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 @@ -153,10 +146,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} PUBLIC SimpleIni::SimpleIni)

# setup the same API exports for imgui
target_compile_definitions(${PROJECT_NAME} PUBLIC IMGUI_API=SOFAIMGUI_API)
Expand Down
4 changes: 4 additions & 0 deletions SofaImGui/SofaImGuiConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
find_package(SofaGLFW REQUIRED)
find_package(Sofa.GL.Component.Rendering3D REQUIRED)

if(NOT TARGET SimpleIni::SimpleIni)
sofa_find_package(SimpleIni QUIET REQUIRED)
endif()

if(NOT TARGET @PROJECT_NAME@)
include("${CMAKE_CURRENT_LIST_DIR}/@[email protected]")
endif()
Expand Down
4 changes: 3 additions & 1 deletion 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 @@ -781,8 +782,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
5 changes: 3 additions & 2 deletions SofaImGui/src/SofaImGui/ImGuiGUIEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
#include "guis/AdditionalGUIRegistry.h"
#include "windows/WindowState.h"
#include <SimpleIni.h>
#include <imgui.h>

using windows::WindowState;

Expand Down Expand Up @@ -84,7 +83,9 @@ class ImGuiGUIEngine : public sofaglfw::BaseGUIEngine
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) ;

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
83 changes: 83 additions & 0 deletions SofaImGui/src/SofaImGui/widgets/RigidMass.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/******************************************************************************
* SOFA, Simulation Open-Framework Architecture *
* (c) 2006 INRIA, USTL, UJF, CNRS, MGH *
* *
* This program is free software; you can redistribute it and/or modify it *
* under the terms of the GNU General Public License as published by the Free *
* Software Foundation; either version 2 of the License, or (at your option) *
* any later version. *
* *
* This program is distributed in the hope that it will be useful, but WITHOUT *
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or *
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for *
* more details. *
* *
* You should have received a copy of the GNU General Public License along *
* with this program. If not, see <http://www.gnu.org/licenses/>. *
*******************************************************************************
* Authors: The SOFA Team and external contributors (see Authors.txt) *
* *
* Contact information: [email protected] *
******************************************************************************/
#pragma once

#include <SofaImGui/widgets/RigidMass.h>

#include <imgui.h>
#include <sofa/core/objectmodel/Base.h>

namespace sofaimgui
{

template<sofa::Size N, typename real>
inline void showRigidMass(const sofa::defaulttype::RigidMass<N,real>& rigidMass)
{
ImGui::Text("Mass: %f", rigidMass.mass);
ImGui::Text("Volume: %f", rigidMass.volume);

std::stringstream ss;
ss << rigidMass.inertiaMatrix;
ImGui::Text("Inertia Matrix: %s", ss.str().c_str());
}

template<sofa::Size N, typename real>
inline void showRigidMasses(const sofa::Data<sofa::type::vector<sofa::defaulttype::RigidMass<N, real>>>& data)
{
static ImGuiTableFlags flags = ImGuiTableFlags_SizingFixedFit | ImGuiTableFlags_Resizable | ImGuiTableFlags_BordersOuter | ImGuiTableFlags_BordersV | ImGuiTableFlags_ContextMenuInBody | ImGuiTableFlags_NoHostExtendX;
ImGui::Text("%d elements", data.getValue().size());
if (ImGui::BeginTable((data.getName() + data.getOwner()->getPathName()).c_str(), 4, flags))
{
ImGui::TableSetupColumn("");
ImGui::TableSetupColumn("Mass");
ImGui::TableSetupColumn("Volume");
ImGui::TableSetupColumn("Inertia Matrix");

ImGui::TableHeadersRow();

unsigned int counter {};
for (const auto& rigidMass : *sofa::helper::getReadAccessor(data))
{
ImGui::TableNextRow();
ImGui::TableNextColumn();
ImGui::Text("%d", counter++);
ImGui::TableNextColumn();
ImGui::Text("%f", rigidMass.mass);
ImGui::TableNextColumn();
ImGui::Text("%f", rigidMass.volume);

ImGui::TableNextColumn();
std::stringstream ss;
ss << rigidMass.inertiaMatrix;
ImGui::Text("Inertia Matrix: %s", ss.str().c_str());
}
ImGui::EndTable();
}
}

template void SOFAIMGUI_API showRigidMass<2, SReal>(const sofa::defaulttype::RigidMass<2, SReal>&);
template void SOFAIMGUI_API showRigidMass<3, SReal>(const sofa::defaulttype::RigidMass<3, SReal>&);

template void SOFAIMGUI_API showRigidMasses<2, SReal>(const sofa::Data<sofa::type::vector<sofa::defaulttype::RigidMass<2, SReal>>>&);
template void SOFAIMGUI_API showRigidMasses<3, SReal>(const sofa::Data<sofa::type::vector<sofa::defaulttype::RigidMass<3, SReal>>>&);

}
50 changes: 9 additions & 41 deletions SofaImGui/src/SofaImGui/widgets/RigidMass.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,55 +20,23 @@
* Contact information: [email protected] *
******************************************************************************/
#pragma once

#include <SofaImGui/config.h>

#include <sofa/core/objectmodel/Data.h>
#include <imgui.h>

namespace sofaimgui
{

template<sofa::Size N, typename real>
inline void showRigidMass(const sofa::defaulttype::RigidMass<N,real>& rigidMass)
{
ImGui::Text("Mass: %f", rigidMass.mass);
ImGui::Text("Volume: %f", rigidMass.volume);

std::stringstream ss;
ss << rigidMass.inertiaMatrix;
ImGui::Text("Inertia Matrix: %s", ss.str().c_str());
}
inline void showRigidMass(const sofa::defaulttype::RigidMass<N,real>& rigidMass);

template<sofa::Size N, typename real>
inline void showRigidMasses(const sofa::Data<sofa::type::vector<sofa::defaulttype::RigidMass<N, real>>>& data)
{
static ImGuiTableFlags flags = ImGuiTableFlags_SizingFixedFit | ImGuiTableFlags_Resizable | ImGuiTableFlags_BordersOuter | ImGuiTableFlags_BordersV | ImGuiTableFlags_ContextMenuInBody | ImGuiTableFlags_NoHostExtendX;
ImGui::Text("%d elements", data.getValue().size());
if (ImGui::BeginTable((data.getName() + data.getOwner()->getPathName()).c_str(), 4, flags))
{
ImGui::TableSetupColumn("");
ImGui::TableSetupColumn("Mass");
ImGui::TableSetupColumn("Volume");
ImGui::TableSetupColumn("Inertia Matrix");

ImGui::TableHeadersRow();
inline void showRigidMasses(const sofa::Data<sofa::type::vector<sofa::defaulttype::RigidMass<N, real>>>& data);

unsigned int counter {};
for (const auto& rigidMass : *sofa::helper::getReadAccessor(data))
{
ImGui::TableNextRow();
ImGui::TableNextColumn();
ImGui::Text("%d", counter++);
ImGui::TableNextColumn();
ImGui::Text("%f", rigidMass.mass);
ImGui::TableNextColumn();
ImGui::Text("%f", rigidMass.volume);

ImGui::TableNextColumn();
std::stringstream ss;
ss << rigidMass.inertiaMatrix;
ImGui::Text("Inertia Matrix: %s", ss.str().c_str());
}
ImGui::EndTable();
}
}
extern template void SOFAIMGUI_API showRigidMass<2, SReal>(const sofa::defaulttype::RigidMass<2, SReal>&);
extern template void SOFAIMGUI_API showRigidMass<3, SReal>(const sofa::defaulttype::RigidMass<3, SReal>&);

extern template void SOFAIMGUI_API showRigidMasses<2, SReal>(const sofa::Data<sofa::type::vector<sofa::defaulttype::RigidMass<2, SReal>>>&);
extern template void SOFAIMGUI_API showRigidMasses<3, SReal>(const sofa::Data<sofa::type::vector<sofa::defaulttype::RigidMass<3, SReal>>>&);
}
39 changes: 39 additions & 0 deletions SofaImGui/src/SofaImGui/widgets/ScalarWidget.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/******************************************************************************
* SOFA, Simulation Open-Framework Architecture *
* (c) 2006 INRIA, USTL, UJF, CNRS, MGH *
* *
* This program is free software; you can redistribute it and/or modify it *
* under the terms of the GNU General Public License as published by the Free *
* Software Foundation; either version 2 of the License, or (at your option) *
* any later version. *
* *
* This program is distributed in the hope that it will be useful, but WITHOUT *
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or *
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for *
* more details. *
* *
* You should have received a copy of the GNU General Public License along *
* with this program. If not, see <http://www.gnu.org/licenses/>. *
*******************************************************************************
* Authors: The SOFA Team and external contributors (see Authors.txt) *
* *
* Contact information: [email protected] *
******************************************************************************/
#pragma once
#include <sofa/core/objectmodel/Data.h>
#include <imgui.h>

namespace sofaimgui
{

bool showScalarWidget(const std::string& label, const std::string& id, float& value)
{
return ImGui::InputFloat((label + "##" + id).c_str(), &value, 0.0f, 0.0f, "%.8f", ImGuiInputTextFlags_None);
}

bool showScalarWidget(const std::string& label, const std::string& id, double& value)
{
return ImGui::InputDouble((label + "##" + id).c_str(), &value, 0.0f, 0.0f, "%.8f", ImGuiInputTextFlags_None);
}

}
11 changes: 2 additions & 9 deletions SofaImGui/src/SofaImGui/widgets/ScalarWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,13 @@
******************************************************************************/
#pragma once
#include <sofa/core/objectmodel/Data.h>
#include <imgui.h>

namespace sofaimgui
{

inline bool showScalarWidget(const std::string& label, const std::string& id, float& value)
{
return ImGui::InputFloat((label + "##" + id).c_str(), &value, 0.0f, 0.0f, "%.8f", ImGuiInputTextFlags_None);
}
inline bool showScalarWidget(const std::string& label, const std::string& id, float& value);

inline bool showScalarWidget(const std::string& label, const std::string& id, double& value)
{
return ImGui::InputDouble((label + "##" + id).c_str(), &value, 0.0f, 0.0f, "%.8f", ImGuiInputTextFlags_None);
}
inline bool showScalarWidget(const std::string& label, const std::string& id, double& value);

template<typename Scalar>
void showScalarWidget(sofa::Data<Scalar>& data)
Expand Down
2 changes: 0 additions & 2 deletions SofaImGui/src/SofaImGui/windows/Log.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@
#include <memory>
#include <SofaGLFW/BaseGUIEngine.h>

#include <imgui.h>
#include <sofa/simulation/Node.h>
#include <SimpleIni.h>
#include "WindowState.h"


Expand Down
1 change: 0 additions & 1 deletion SofaImGui/src/SofaImGui/windows/Performances.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@

#include <imgui.h>
#include <sofa/simulation/Node.h>
#include <SimpleIni.h>
#include "WindowState.h"


Expand Down
2 changes: 0 additions & 2 deletions SofaImGui/src/SofaImGui/windows/Profiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@
#include <SofaGLFW/BaseGUIEngine.h>
#include <sofa/gl/FrameBufferObject.h>

#include <imgui.h>
#include <sofa/simulation/Node.h>
#include <SimpleIni.h>
#include "WindowState.h"


Expand Down
1 change: 1 addition & 0 deletions SofaImGui/src/SofaImGui/windows/Settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

#include <sofa/simulation/Node.h>
#include "WindowState.h"
#include <SimpleIni.h>

namespace sofaimgui
{
Expand Down
Loading
Loading