diff --git a/SofaGLFW/SofaGLFWConfig.cmake.in b/SofaGLFW/SofaGLFWConfig.cmake.in index 535ac94c30..b788ebe788 100644 --- a/SofaGLFW/SofaGLFWConfig.cmake.in +++ b/SofaGLFW/SofaGLFWConfig.cmake.in @@ -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) diff --git a/SofaImGui/CMakeLists.txt b/SofaImGui/CMakeLists.txt index b7c0cc75a8..a35db2abef 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 @@ -110,7 +101,6 @@ set(HEADER_FILES ${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 @@ -118,8 +108,6 @@ set(HEADER_FILES ${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 @@ -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 @@ -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 "$") 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) diff --git a/SofaImGui/extensions/SofaImGui.Camera/CMakeLists.txt b/SofaImGui/extensions/SofaImGui.Camera/CMakeLists.txt index d287caab9c..8a7e6db83f 100644 --- a/SofaImGui/extensions/SofaImGui.Camera/CMakeLists.txt +++ b/SofaImGui/extensions/SofaImGui.Camera/CMakeLists.txt @@ -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 @@ -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 "$") target_link_libraries(${PROJECT_NAME} PUBLIC SofaImGui) sofa_create_package_with_targets( diff --git a/SofaImGui/src/SofaImGui/AppIniFile.cpp b/SofaImGui/src/SofaImGui/AppIniFile.cpp index 1838a928c0..d65d716136 100644 --- a/SofaImGui/src/SofaImGui/AppIniFile.cpp +++ b/SofaImGui/src/SofaImGui/AppIniFile.cpp @@ -23,7 +23,6 @@ #include #include #include -#include "windows/Performances.h" #include "AppIniFile.h" diff --git a/SofaImGui/src/SofaImGui/ImGuiGUIEngine.cpp b/SofaImGui/src/SofaImGui/ImGuiGUIEngine.cpp index dfaa8f2db2..14016975b3 100644 --- a/SofaImGui/src/SofaImGui/ImGuiGUIEngine.cpp +++ b/SofaImGui/src/SofaImGui/ImGuiGUIEngine.cpp @@ -24,6 +24,7 @@ #include #include #include +#include #include #include @@ -68,6 +69,7 @@ #include //imgui_internal.h is included in order to use the DockspaceBuilder API (which is still in development) #include #include +#include #include #include #include @@ -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"))) @@ -103,6 +110,9 @@ ImGuiGUIEngine::ImGuiGUIEngine() { } +ImGuiGUIEngine::~ImGuiGUIEngine() +{} + void ImGuiGUIEngine::init() { IMGUI_CHECKVERSION(); @@ -121,22 +131,21 @@ void ImGuiGUIEngine::init() io.ConfigFlags |= ImGuiConfigFlags_DockingEnable; io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable; - - - ini.SetUnicode(); + settings = std::make_unique(); + 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; @@ -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(ini.GetDoubleValue("Visualization", "globalScale", 1.0)); + const float globalScale = static_cast(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); @@ -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(windowSizeX), static_cast(windowSizeY)); @@ -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(); @@ -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); @@ -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 @@ -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 @@ -854,11 +864,11 @@ void ImGuiGUIEngine::terminate() const auto lastWindowSize = ImGui::GetMainViewport()->Size; // save latest window state - ini.SetLongValue("Window", "windowPosX", static_cast(lastWindowPos.x)); - ini.SetLongValue("Window", "windowPosY", static_cast(lastWindowPos.y)); - ini.SetLongValue("Window", "windowSizeX", static_cast(lastWindowSize.x)); - ini.SetLongValue("Window", "windowSizeY", static_cast(lastWindowSize.y)); - [[maybe_unused]] SI_Error rc = ini.SaveFile(sofaimgui::AppIniFile::getAppIniFile().c_str()); + settings->ini.SetLongValue("Window", "windowPosX", static_cast(lastWindowPos.x)); + settings->ini.SetLongValue("Window", "windowPosY", static_cast(lastWindowPos.y)); + settings->ini.SetLongValue("Window", "windowSizeX", static_cast(lastWindowSize.x)); + settings->ini.SetLongValue("Window", "windowSizeY", static_cast(lastWindowSize.y)); + [[maybe_unused]] SI_Error rc = settings->ini.SaveFile(sofaimgui::AppIniFile::getAppIniFile().c_str()); NFD_Quit(); diff --git a/SofaImGui/src/SofaImGui/ImGuiGUIEngine.h b/SofaImGui/src/SofaImGui/ImGuiGUIEngine.h index ada302fd89..83f2b826b5 100644 --- a/SofaImGui/src/SofaImGui/ImGuiGUIEngine.h +++ b/SofaImGui/src/SofaImGui/ImGuiGUIEngine.h @@ -28,8 +28,6 @@ #include "guis/AdditionalGUIRegistry.h" #include "windows/WindowState.h" -#include -#include using windows::WindowState; @@ -49,7 +47,7 @@ class ImGuiGUIEngine : public sofaglfw::BaseGUIEngine public: ImGuiGUIEngine() ; - ~ImGuiGUIEngine() = default; + ~ImGuiGUIEngine(); void init() override; void initBackend(GLFWwindow*) override; @@ -83,8 +81,12 @@ class ImGuiGUIEngine : public sofaglfw::BaseGUIEngine std::pair m_currentFBOSize; 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) ; + + struct Settings; + std::unique_ptr 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; 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 {