diff --git a/CHANGELOG.md b/CHANGELOG.md index e192ce692e5..8d9d0c88065 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -39,6 +39,7 @@ - Fix segmentation fault (infinite recursion) of DetectPlanarPatches if multiple points have same coordinates (PR #6794) - Fix build with fmt v10.2.0 (#6783) - Fix segmentation fault (lambda reference capture) of VisualizerWithCustomAnimation::Play (PR #6804) +- Add O3DVisualizer API to enable collapse control of verts in the side panel (PR #6865) ## 0.13 diff --git a/cpp/open3d/visualization/gui/Layout.cpp b/cpp/open3d/visualization/gui/Layout.cpp index f61c26eafe6..8da97bc899f 100644 --- a/cpp/open3d/visualization/gui/Layout.cpp +++ b/cpp/open3d/visualization/gui/Layout.cpp @@ -386,10 +386,7 @@ CollapsableVert::CollapsableVert(const char* text, int spacing, const Margins& margins /*= Margins()*/) : Vert(spacing, margins), impl_(new CollapsableVert::Impl()) { - static int g_next_id = 1; - - impl_->text_ = text; - impl_->id_ = impl_->text_ + "##collapsing_" + std::to_string(g_next_id++); + SetText(text); } CollapsableVert::~CollapsableVert() {} @@ -398,6 +395,15 @@ void CollapsableVert::SetIsOpen(bool is_open) { impl_->is_open_ = is_open; } bool CollapsableVert::GetIsOpen() { return impl_->is_open_; } +void CollapsableVert::SetText(const char* text) { + static int g_next_id = 1; + + impl_->text_ = text; + impl_->id_ = impl_->text_ + "##collapsing_" + std::to_string(g_next_id++); +} + +std::string CollapsableVert::GetText() const { return impl_->text_; }; + FontId CollapsableVert::GetFontId() const { return impl_->font_id_; } void CollapsableVert::SetFontId(FontId font_id) { impl_->font_id_ = font_id; } diff --git a/cpp/open3d/visualization/gui/Layout.h b/cpp/open3d/visualization/gui/Layout.h index 8d069e49273..7421c6522cb 100644 --- a/cpp/open3d/visualization/gui/Layout.h +++ b/cpp/open3d/visualization/gui/Layout.h @@ -7,6 +7,8 @@ #pragma once +#include + #include "open3d/visualization/gui/Widget.h" namespace open3d { @@ -148,6 +150,9 @@ class CollapsableVert : public Vert { /// Returns true if open and false if collapsed. bool GetIsOpen(); + void SetText(const char* text); + std::string GetText() const; + FontId GetFontId() const; void SetFontId(FontId font_id); diff --git a/cpp/open3d/visualization/visualizer/O3DVisualizer.cpp b/cpp/open3d/visualization/visualizer/O3DVisualizer.cpp index 554d38b2466..69dbcbadb61 100644 --- a/cpp/open3d/visualization/visualizer/O3DVisualizer.cpp +++ b/cpp/open3d/visualization/visualizer/O3DVisualizer.cpp @@ -1706,6 +1706,18 @@ Ctrl-alt-click to polygon select)"; } } + void SetPanelOpen(const std::string &name, bool open) { + if (name == settings.mouse_panel->GetText()) { + settings.mouse_panel->SetIsOpen(open); + } else if (name == settings.scene_panel->GetText()) { + settings.scene_panel->SetIsOpen(open); + } else if (name == settings.light_panel->GetText()) { + settings.light_panel->SetIsOpen(open); + } else if (name == settings.geometries_panel->GetText()) { + settings.geometries_panel->SetIsOpen(open); + } + } + void SetPicking() { if (selections_->GetNumberOfSets() == 0) { NewSelectionSet(); @@ -2446,6 +2458,10 @@ void O3DVisualizer::SetMouseMode(SceneWidget::Controls mode) { impl_->SetMouseMode(mode); } +void O3DVisualizer::SetPanelOpen(const std::string &name, bool open) { + impl_->SetPanelOpen(name, open); +} + void O3DVisualizer::EnableGroup(const std::string &group, bool enable) { impl_->EnableGroup(group, enable); } diff --git a/cpp/open3d/visualization/visualizer/O3DVisualizer.h b/cpp/open3d/visualization/visualizer/O3DVisualizer.h index 4ceec56de76..af0ced3d6ba 100644 --- a/cpp/open3d/visualization/visualizer/O3DVisualizer.h +++ b/cpp/open3d/visualization/visualizer/O3DVisualizer.h @@ -175,6 +175,7 @@ class O3DVisualizer : public gui::Window { void SetLineWidth(int line_width); void EnableGroup(const std::string& group, bool enable); void SetMouseMode(gui::SceneWidget::Controls mode); + void SetPanelOpen(const std::string& name, bool open); std::vector GetSelectionSets() const; diff --git a/cpp/pybind/visualization/gui/gui.cpp b/cpp/pybind/visualization/gui/gui.cpp index a211d233a05..9f086e50ef5 100644 --- a/cpp/pybind/visualization/gui/gui.cpp +++ b/cpp/pybind/visualization/gui/gui.cpp @@ -1772,6 +1772,10 @@ void pybind_gui_classes(py::module &m) { "window is visible") .def("get_is_open", &CollapsableVert::GetIsOpen, "Check if widget is open.") + .def("set_text", &CollapsableVert::SetText, "text"_a, + "Sets the text for the CollapsableVert") + .def("get_text", &CollapsableVert::GetText, + "Gets the text for the CollapsableVert") .def_property("font_id", &CollapsableVert::GetFontId, &CollapsableVert::SetFontId, "Set the font using the FontId returned from " diff --git a/cpp/pybind/visualization/o3dvisualizer.cpp b/cpp/pybind/visualization/o3dvisualizer.cpp index a97d108f918..0859658a081 100644 --- a/cpp/pybind/visualization/o3dvisualizer.cpp +++ b/cpp/pybind/visualization/o3dvisualizer.cpp @@ -344,6 +344,9 @@ void pybind_o3dvisualizer(py::module& m) { "enable"_a) .def("show_skybox", &O3DVisualizer::ShowSkybox, "Show/Hide the skybox", "show"_a) + .def("set_panel_open", &O3DVisualizer::SetPanelOpen, + "Expand/Collapse verts(panels) within the settings panel", + "name"_a, "open"_a) .def_property( "show_settings", [](const O3DVisualizer& dv) {