Skip to content

Commit

Permalink
[SofaSimpleGUI] Fix calls to deprecated functions
Browse files Browse the repository at this point in the history
  • Loading branch information
alxbilger authored and fredroy committed Dec 21, 2023
1 parent 7a56c19 commit ef35c4f
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 29 deletions.
10 changes: 8 additions & 2 deletions applications/plugins/SofaSimpleGUI/SofaGL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <sofa/core/objectmodel/Tag.h>
#include <sofa/core/visual/VisualLoop.h>
#include <sofa/core/visual/VisualParams.h>
#include <sofa/helper/narrow_cast.h>

#include <sofa/simulation/mechanicalvisitor/MechanicalPickParticlesVisitor.h>
using sofa::simulation::mechanicalvisitor::MechanicalPickParticlesVisitor;
Expand Down Expand Up @@ -276,8 +277,13 @@ void SofaGL::getSceneBBox( float* xmin, float* ymin, float* zmin, float* xmax, f
{
SReal xm, xM, ym, yM, zm, zM;
_sofaScene->getBoundingBox(&xm,&xM,&ym,&yM,&zm,&zM);
// cerr << "SofaGL::getSceneBBox, xm=" << xm <<", xM=" << xM << endl;
*xmin=xm, *xmax=xM, *ymin=ym, *ymax=yM, *zmin=zm, *zmax=zM;

*xmin = helper::narrow_cast<float>(xm);
*xmax = helper::narrow_cast<float>(xM);
*ymin = helper::narrow_cast<float>(ym);
*ymax = helper::narrow_cast<float>(yM);
*zmin = helper::narrow_cast<float>(zm);
*zmax = helper::narrow_cast<float>(zM);
}


Expand Down
47 changes: 23 additions & 24 deletions applications/plugins/SofaSimpleGUI/SofaScene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ using std::endl;
typedef sofa::simulation::graph::DAGSimulation SofaSimulation;


namespace sofa {
namespace simplegui {
namespace sofa::simplegui
{


typedef sofa::type::Vec3 Vec3;
Expand All @@ -27,29 +27,29 @@ typedef sofa::component::statecontainer::MechanicalObject< defaulttype::Vec3Type

SofaScene::SofaScene()
{
_groot = _iroot = NULL;
_groot = _iroot = nullptr;
std::shared_ptr<sofa::core::ObjectFactory::ClassEntry> classVisualModel;// = NULL;
sofa::core::ObjectFactory::AddAlias("VisualModel", "OglModel", true, &classVisualModel);

sofaSimulation = sofa::simulation::getSimulation(); // creates one if it is not already created
sofa::component::init();
}

void SofaScene::step( SReal dt)
{
sofaSimulation->animate(_groot.get(),dt);
sofa::simulation::node::animate(_groot.get(),dt);
}

void SofaScene::printGraph()
{
sofaSimulation->print(_groot.get());
sofa::simulation::node::print(_groot.get());
}

void SofaScene::loadPlugins( std::vector<std::string> plugins )
void SofaScene::loadPlugins( const std::vector<std::string>& plugins )
{
for (unsigned int i=0; i<plugins.size(); i++){
cout<<"SofaScene::init, loading plugin " << plugins[i] << endl;
sofa::helper::system::PluginManager::getInstance().loadPlugin(plugins[i]);
for (const auto& plugin : plugins)
{
cout <<"SofaScene::init, loading plugin " << plugin << '\n';
sofa::helper::system::PluginManager::getInstance().loadPlugin(plugin);
}

sofa::helper::system::PluginManager::getInstance().init();
Expand All @@ -60,8 +60,8 @@ void SofaScene::open(const std::string& fileName )
// --- Create simulation graph ---
assert( !fileName.empty());

if(_groot) sofaSimulation->unload (_groot);
_groot = sofaSimulation->load( fileName.c_str() ).get();
if(_groot) sofa::simulation::node::unload (_groot);
_groot = sofa::simulation::node::load( fileName.c_str() ).get();
if(!_groot)
{
cerr << "loading failed" << endl;
Expand All @@ -72,7 +72,7 @@ void SofaScene::open(const std::string& fileName )

// _currentFileName = fileName;

sofaSimulation->init(_groot.get());
sofa::simulation::node::init(_groot.get());

printGraph();
SReal xm,xM,ym,yM,zm,zM;
Expand All @@ -83,16 +83,16 @@ void SofaScene::open(const std::string& fileName )

void SofaScene::setScene(simulation::Node *node )
{
if(_groot) sofaSimulation->unload (_groot);
_groot = sofaSimulation->createNewGraph("root").get();
if(_groot) sofa::simulation::node::unload (_groot);
_groot = sofa::simulation::getSimulation()->createNewGraph("root").get();
_groot->addChild(node);
_iroot = _groot->createChild("iroot").get();
sofaSimulation->init(_groot.get());
sofa::simulation::node::init(_groot.get());
}

void SofaScene::reset()
{
sofaSimulation->reset(_groot.get());
sofa::simulation::node::reset(_groot.get());
}

//void SofaScene::open(const char *filename)
Expand All @@ -110,15 +110,15 @@ void SofaScene::reset()

// _currentFileName = filename;

// sofaSimulation->::init(_groot);
// sofa::simulation::node::::init(_groot);
//// cout<<"SofaScene::init, scene loaded" << endl;
//// printGraph();
//}

void SofaScene::getBoundingBox( SReal* xmin, SReal* xmax, SReal* ymin, SReal* ymax, SReal* zmin, SReal* zmax )
{
SReal pmin[3], pmax[3];
sofaSimulation->computeBBox( _groot.get(), pmin, pmax );
sofa::simulation::node::computeBBox( _groot.get(), pmin, pmax );
*xmin = pmin[0]; *xmax = pmax[0];
*ymin = pmin[1]; *ymax = pmax[1];
*zmin = pmin[2]; *zmax = pmax[2];
Expand All @@ -133,12 +133,12 @@ void SofaScene::insertInteractor( Interactor * interactor )
simulation::Node* SofaScene::groot() { return _groot.get(); }

void SofaScene::initVisual(){
sofaSimulation->initTextures(_groot.get());
sofa::simulation::node::initTextures(_groot.get());
}

void SofaScene::updateVisual()
{
sofaSimulation->updateVisual(_groot.get()); // needed to update normals and VBOs ! (i think it should be better if updateVisual() was called from draw(), why it is not already the case ?)
sofa::simulation::node::updateVisual(_groot.get()); // needed to update normals and VBOs ! (i think it should be better if updateVisual() was called from draw(), why it is not already the case ?)
}

//void SofaScene::draw( sofa::core::visual::VisualParams* v)
Expand All @@ -147,9 +147,8 @@ void SofaScene::updateVisual()
// {
//
// }
// sofaSimulation->draw(_vparams, groot() );
// sofa::simulation::node::draw(_vparams, groot() );
//}


}// newgui
}// sofa
}
5 changes: 2 additions & 3 deletions applications/plugins/SofaSimpleGUI/SofaScene.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ class SOFA_SOFASIMPLEGUI_API SofaScene

/**
* @brief load the given plugin
* @param pluginName name of the plugin
* @param plugins names of the plugins
*/
void loadPlugins( std::vector<std::string> pluginName );
void loadPlugins( const std::vector<std::string>& plugins );
/**
* @brief Load a scene file. The previous scene graph, if any, is deleted.
* @param fileName Scene file to load
Expand Down Expand Up @@ -110,7 +110,6 @@ class SOFA_SOFASIMPLEGUI_API SofaScene
protected:
simulation::Node::SPtr _groot; ///< root of the scene
simulation::Node* _iroot; ///< root of the interactors, child of _groot
simulation::Simulation* sofaSimulation;

};

Expand Down

0 comments on commit ef35c4f

Please sign in to comment.