From acc42268e340f5c12710310702d38dd6bb96f475 Mon Sep 17 00:00:00 2001 From: Paul Baksic Date: Thu, 4 Jun 2026 09:02:25 +0200 Subject: [PATCH] factorize code to use in child class --- .../Common/src/sofa/gui/common/BaseViewer.cpp | 23 +++++++++++-------- .../Common/src/sofa/gui/common/BaseViewer.h | 1 + 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/Sofa/GUI/Common/src/sofa/gui/common/BaseViewer.cpp b/Sofa/GUI/Common/src/sofa/gui/common/BaseViewer.cpp index 22297b87293..3f9cf6381b1 100644 --- a/Sofa/GUI/Common/src/sofa/gui/common/BaseViewer.cpp +++ b/Sofa/GUI/Common/src/sofa/gui/common/BaseViewer.cpp @@ -270,15 +270,7 @@ bool BaseViewer::load() if (groot) { - groot->get(currentCamera, core::objectmodel::BaseContext::SearchDown); - if (!currentCamera) - { - currentCamera = sofa::core::objectmodel::New(); - currentCamera->setName(groot->getNameHelper().resolveName(currentCamera->getClassName(), sofa::core::ComponentNameHelper::Convention::python)); - groot->addObject(currentCamera); - currentCamera->bwdInit(); - msg_info("BaseViewer") << "There is no camera in this scene, I created one. To remove this error message, add a camera in your scene."; - } + addCameraIfRequired(); sofa::component::visual::VisualStyle::SPtr visualStyle = nullptr; groot->get(visualStyle); if (!visualStyle) @@ -304,6 +296,19 @@ bool BaseViewer::load() return false; } +void BaseViewer::addCameraIfRequired() +{ + groot->get(currentCamera, core::objectmodel::BaseContext::SearchDown); + if (!currentCamera) + { + currentCamera = sofa::core::objectmodel::New(); + currentCamera->setName(groot->getNameHelper().resolveName(currentCamera->getClassName(), sofa::core::ComponentNameHelper::Convention::python)); + groot->addObject(currentCamera); + currentCamera->bwdInit(); + msg_info("BaseViewer") << "There is no camera in this scene, I created one. To remove this error message, add a camera in your scene."; + } + +} bool BaseViewer::unload() { diff --git a/Sofa/GUI/Common/src/sofa/gui/common/BaseViewer.h b/Sofa/GUI/Common/src/sofa/gui/common/BaseViewer.h index 2e14241df36..5dd4122028f 100644 --- a/Sofa/GUI/Common/src/sofa/gui/common/BaseViewer.h +++ b/Sofa/GUI/Common/src/sofa/gui/common/BaseViewer.h @@ -64,6 +64,7 @@ class SOFA_GUI_COMMON_API BaseViewer virtual void setSceneFileName(const std::string &f); virtual void setScene(sofa::simulation::Node::SPtr scene, const char* filename = nullptr, bool /*keepParams*/= false); virtual void setCameraMode(core::visual::VisualParams::CameraType); + void addCameraIfRequired(); /// true when the viewer keep the hand on the render /// false when it's not in activity