diff --git a/SofaImGui/CMakeLists.txt b/SofaImGui/CMakeLists.txt index c666a684e7..fb86e73562 100644 --- a/SofaImGui/CMakeLists.txt +++ b/SofaImGui/CMakeLists.txt @@ -95,6 +95,7 @@ set(HEADER_FILES ${SOFAIMGUI_SOURCE_DIR}/ImGuiGUI.h ${SOFAIMGUI_SOURCE_DIR}/ImGuiGUIEngine.h ${SOFAIMGUI_SOURCE_DIR}/UIStrings.h + ${SOFAIMGUI_SOURCE_DIR}/widgets/BoundingBoxWidget.h ${SOFAIMGUI_SOURCE_DIR}/widgets/BoolWidget.h ${SOFAIMGUI_SOURCE_DIR}/widgets/DisplayFlagsWidget.h ${SOFAIMGUI_SOURCE_DIR}/widgets/LinearSpringWidget.h diff --git a/SofaImGui/src/SofaImGui/ImGuiDataWidget.cpp b/SofaImGui/src/SofaImGui/ImGuiDataWidget.cpp index bf39ff3642..8d5b40cfb5 100644 --- a/SofaImGui/src/SofaImGui/ImGuiDataWidget.cpp +++ b/SofaImGui/src/SofaImGui/ImGuiDataWidget.cpp @@ -32,6 +32,7 @@ #include #include #include +#include #include namespace sofaimgui @@ -651,6 +652,16 @@ void DataWidget>::showWidget(M showRigidMasses(data); } +/*********************************************************************************************************************** + * Bounding Box + **********************************************************************************************************************/ + +template<> +void DataWidget::showWidget(MyData& data) +{ + showBoundingBoxWidget(data); +} + /*********************************************************************************************************************** * Factory **********************************************************************************************************************/ @@ -742,4 +753,6 @@ const bool dw_rigid2mass = DataWidgetFactory::Add const bool dw_vector_rigid2mass = DataWidgetFactory::Add>(); const bool dw_rigid3mass = DataWidgetFactory::Add(); const bool dw_vector_rigid3mass = DataWidgetFactory::Add>(); + +const bool dw_boundingbox = DataWidgetFactory::Add(); } diff --git a/SofaImGui/src/SofaImGui/widgets/BoundingBoxWidget.h b/SofaImGui/src/SofaImGui/widgets/BoundingBoxWidget.h new file mode 100644 index 0000000000..c8780c52dc --- /dev/null +++ b/SofaImGui/src/SofaImGui/widgets/BoundingBoxWidget.h @@ -0,0 +1,63 @@ +/****************************************************************************** +* 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 +{ + +inline void showBoundingBoxWidget(sofa::Data& data) +{ + const auto box = data.getValue(); + + static ImGuiTableFlags flags = ImGuiTableFlags_SizingFixedFit | ImGuiTableFlags_Resizable | ImGuiTableFlags_BordersOuter | ImGuiTableFlags_BordersV | ImGuiTableFlags_ContextMenuInBody | ImGuiTableFlags_NoHostExtendX; + + if (ImGui::BeginTable("bbox_table", 4, flags)) + { + ImGui::TableSetupColumn(""); + ImGui::TableSetupColumn("X", ImGuiTableColumnFlags_WidthStretch); + ImGui::TableSetupColumn("Y", ImGuiTableColumnFlags_WidthStretch); + ImGui::TableSetupColumn("Z", ImGuiTableColumnFlags_WidthStretch); + + ImGui::TableHeadersRow(); + + // Second row: ["min", min.x, min.y, min.z] + ImGui::TableNextRow(); + ImGui::TableSetColumnIndex(0); ImGui::Text("min"); + ImGui::TableSetColumnIndex(1); ImGui::Text("%.2f", box.minBBox().x()); + ImGui::TableSetColumnIndex(2); ImGui::Text("%.2f", box.minBBox().y()); + ImGui::TableSetColumnIndex(3); ImGui::Text("%.2f", box.minBBox().z()); + + // Third row: ["max", max.x, max.y, max.z] + ImGui::TableNextRow(); + ImGui::TableSetColumnIndex(0); ImGui::Text("max"); + ImGui::TableSetColumnIndex(1); ImGui::Text("%.2f", box.maxBBox().x()); + ImGui::TableSetColumnIndex(2); ImGui::Text("%.2f", box.maxBBox().y()); + ImGui::TableSetColumnIndex(3); ImGui::Text("%.2f", box.maxBBox().z()); + + ImGui::EndTable(); + } +} + +}