diff --git a/SofaImGui/CMakeLists.txt b/SofaImGui/CMakeLists.txt index 2a6e9985b1..bc2ebeff62 100644 --- a/SofaImGui/CMakeLists.txt +++ b/SofaImGui/CMakeLists.txt @@ -20,6 +20,7 @@ sofa_fetch_dependency(imgui DONT_BUILD ) +# nfd (nativefiledialog-extended) find_package(nfd CONFIG QUIET) if(TARGET nfd::nfd) @@ -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 @@ -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 @@ -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 @@ -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 "$") 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) diff --git a/SofaImGui/SofaImGuiConfig.cmake.in b/SofaImGui/SofaImGuiConfig.cmake.in index cfc50d5c69..11e228d3d2 100644 --- a/SofaImGui/SofaImGuiConfig.cmake.in +++ b/SofaImGui/SofaImGuiConfig.cmake.in @@ -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}/@PROJECT_NAME@Targets.cmake") endif() diff --git a/SofaImGui/src/SofaImGui/ImGuiGUIEngine.cpp b/SofaImGui/src/SofaImGui/ImGuiGUIEngine.cpp index a3883e9ad8..22e52946a0 100644 --- a/SofaImGui/src/SofaImGui/ImGuiGUIEngine.cpp +++ b/SofaImGui/src/SofaImGui/ImGuiGUIEngine.cpp @@ -24,6 +24,7 @@ #include #include #include +#include #include #include @@ -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 diff --git a/SofaImGui/src/SofaImGui/ImGuiGUIEngine.h b/SofaImGui/src/SofaImGui/ImGuiGUIEngine.h index ec7a7b3a7c..6c2f48d8eb 100644 --- a/SofaImGui/src/SofaImGui/ImGuiGUIEngine.h +++ b/SofaImGui/src/SofaImGui/ImGuiGUIEngine.h @@ -29,7 +29,6 @@ #include "guis/AdditionalGUIRegistry.h" #include "windows/WindowState.h" #include -#include using windows::WindowState; @@ -84,7 +83,9 @@ class ImGuiGUIEngine : public sofaglfw::BaseGUIEngine std::pair 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; diff --git a/SofaImGui/src/SofaImGui/widgets/RigidMass.cpp b/SofaImGui/src/SofaImGui/widgets/RigidMass.cpp new file mode 100644 index 0000000000..b82eae264d --- /dev/null +++ b/SofaImGui/src/SofaImGui/widgets/RigidMass.cpp @@ -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 . * +******************************************************************************* +* Authors: The SOFA Team and external contributors (see Authors.txt) * +* * +* Contact information: contact@sofa-framework.org * +******************************************************************************/ +#pragma once + +#include + +#include +#include + +namespace sofaimgui +{ + +template +inline void showRigidMass(const sofa::defaulttype::RigidMass& 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 +inline void showRigidMasses(const sofa::Data>>& 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>>&); +template void SOFAIMGUI_API showRigidMasses<3, SReal>(const sofa::Data>>&); + +} diff --git a/SofaImGui/src/SofaImGui/widgets/RigidMass.h b/SofaImGui/src/SofaImGui/widgets/RigidMass.h index 32afd2a616..974ef6b03d 100644 --- a/SofaImGui/src/SofaImGui/widgets/RigidMass.h +++ b/SofaImGui/src/SofaImGui/widgets/RigidMass.h @@ -20,55 +20,23 @@ * Contact information: contact@sofa-framework.org * ******************************************************************************/ #pragma once + +#include + #include -#include namespace sofaimgui { template -inline void showRigidMass(const sofa::defaulttype::RigidMass& 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& rigidMass); template -inline void showRigidMasses(const sofa::Data>>& 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>>& 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>>&); +extern template void SOFAIMGUI_API showRigidMasses<3, SReal>(const sofa::Data>>&); } diff --git a/SofaImGui/src/SofaImGui/widgets/ScalarWidget.cpp b/SofaImGui/src/SofaImGui/widgets/ScalarWidget.cpp new file mode 100644 index 0000000000..9362260a86 --- /dev/null +++ b/SofaImGui/src/SofaImGui/widgets/ScalarWidget.cpp @@ -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 . * +******************************************************************************* +* Authors: The SOFA Team and external contributors (see Authors.txt) * +* * +* Contact information: contact@sofa-framework.org * +******************************************************************************/ +#pragma once +#include +#include + +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); +} + +} diff --git a/SofaImGui/src/SofaImGui/widgets/ScalarWidget.h b/SofaImGui/src/SofaImGui/widgets/ScalarWidget.h index e7b4e9ea6d..bb1c63af38 100644 --- a/SofaImGui/src/SofaImGui/widgets/ScalarWidget.h +++ b/SofaImGui/src/SofaImGui/widgets/ScalarWidget.h @@ -21,20 +21,13 @@ ******************************************************************************/ #pragma once #include -#include 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 void showScalarWidget(sofa::Data& data) diff --git a/SofaImGui/src/SofaImGui/windows/Log.h b/SofaImGui/src/SofaImGui/windows/Log.h index 0a70b65c49..77a75af105 100644 --- a/SofaImGui/src/SofaImGui/windows/Log.h +++ b/SofaImGui/src/SofaImGui/windows/Log.h @@ -27,9 +27,7 @@ #include #include -#include #include -#include #include "WindowState.h" diff --git a/SofaImGui/src/SofaImGui/windows/Performances.h b/SofaImGui/src/SofaImGui/windows/Performances.h index b320c4ea8d..1d0e499198 100644 --- a/SofaImGui/src/SofaImGui/windows/Performances.h +++ b/SofaImGui/src/SofaImGui/windows/Performances.h @@ -30,7 +30,6 @@ #include #include -#include #include "WindowState.h" diff --git a/SofaImGui/src/SofaImGui/windows/Profiler.h b/SofaImGui/src/SofaImGui/windows/Profiler.h index ac843b6414..7ee088a7b7 100644 --- a/SofaImGui/src/SofaImGui/windows/Profiler.h +++ b/SofaImGui/src/SofaImGui/windows/Profiler.h @@ -28,9 +28,7 @@ #include #include -#include #include -#include #include "WindowState.h" diff --git a/SofaImGui/src/SofaImGui/windows/Settings.h b/SofaImGui/src/SofaImGui/windows/Settings.h index 5a8e039539..cb52c2e3a2 100644 --- a/SofaImGui/src/SofaImGui/windows/Settings.h +++ b/SofaImGui/src/SofaImGui/windows/Settings.h @@ -23,6 +23,7 @@ #include #include "WindowState.h" +#include namespace sofaimgui { diff --git a/SofaImGui/src/SofaImGui/windows/ViewPort.h b/SofaImGui/src/SofaImGui/windows/ViewPort.h index 6eb08cc04c..743035a5b4 100644 --- a/SofaImGui/src/SofaImGui/windows/ViewPort.h +++ b/SofaImGui/src/SofaImGui/windows/ViewPort.h @@ -23,6 +23,7 @@ #include #include "WindowState.h" +#include namespace windows {