Commit 55f98c65 authored by sarrazij's avatar sarrazij
Browse files

FIXED sofa plugins in stable version v15.03 work in camiTK (also cuda plugin ?)

git-svn-id: svn+ssh://scm.forge.imag.fr/var/lib/gforge/chroot/scmrepos/svn/camitk/trunk/camitk@2084 ec899d31-69d1-42ba-9299-647d76f65fb3
parent 5d390a88
......@@ -37,7 +37,8 @@ if (SOFA_SUPPORT)
# specific flags needed (C++ code)
add_definitions(-DSOFA_SUPPORT)
add_definitions(-DSOFA_PATH="${SOFA_BUILD_DIR}")
add_definitions(-DSOFA_BUILD_DIR="${SOFA_BUILD_DIR}")
add_definitions(-DSOFA_SOURCE_DIR="${SOFA_SOURCE_DIR}")
add_definitions(-DSOFA_STABLE)
endif()
......
......@@ -30,6 +30,8 @@
#include <sofa/simulation/common/xml/initXml.h>
#include <sofa/component/init.h>
#include <sofa/helper/Utils.h>
#include <sofa/helper/system/PluginManager.h>
#ifdef SOFA_1_0_RC1
#include <sofa/simulation/common/xml/initXml.h>
......@@ -290,15 +292,53 @@ SofaSimulator::~SofaSimulator() {
void SofaSimulator::build() {
#if defined(SOFA_1_0_RC1) || defined(SOFA_SVN) || defined(SOFA_STABLE)
sofa::helper::system::DataRepository.addFirstPath( string( SOFA_PATH ) + "/share" );
sofa::helper::system::DataRepository.addFirstPath( string( SOFA_PATH ) + "/examples" );
// retrieve plugins
sofa::component::init();
sofa::simulation::xml::initXml();
// mimicking sofa set/get path methods using local variable names
const std::string sofaPathPrefix = string( SOFA_BUILD_DIR );
#ifdef WIN32
const std::string pluginDir = sofaPathPrefix;
#else
const std::string pluginDir = sofaPathPrefix + "/lib";
#endif
sofa::helper::system::PluginRepository.addFirstPath( pluginDir );
// Initialise paths
const std::string configDirectoryPath = sofaPathPrefix + "/config";
const std::string screenshotDirectoryPath = sofaPathPrefix + "/screenshots";
// manage plugins from plugin file loadedPlugins.ini
// This file can be found in the build path.
// Beware that this file can only be setup/initialized/populated by runSofa application (in Edit -> Plugin Manager menu)
// or sofa modeler.
// Simulate the initialization of m_pluginMap by a Sofa GUI application
// Next line is extracted from SofaPluginManager::loadPluginsFromIniFile()
std::string path = configDirectoryPath + "/loadedPlugins.ini";
sofa::helper::system::PluginManager::getInstance().readFromIniFile( path);
sofa::helper::system::PluginManager::getInstance().init();
// -- from GUIManager::Init
// double init!
sofa::component::init();
sofa::simulation::xml::initXml();
// from SOFA_SOURCE_DIR find the directory to share and examples files (do not use the etc/sofa.ini file
sofa::helper::system::DataRepository.addFirstPath( string( SOFA_SOURCE_DIR ) + "/share" );
sofa::helper::system::DataRepository.addFirstPath( string( SOFA_SOURCE_DIR ) + "/examples" );
// look for the scn file
QFileInfo scnFileInfo( scnFile.c_str() );
/*TODO CLEANUP
std::string fileName = sofa::helper::system::DataRepository.getFile(scnFileInfo.absoluteDir().canonicalPath().toStdString());
*/
sofa::helper::system::DataRepository.addFirstPath( scnFileInfo.absoluteDir().canonicalPath().toStdString() );
/* std::cout << "DataRepository is now: " << std::endl;
/* TODO CLEANUP std::cout << "DataRepository is now: " << std::endl;
const std::vector< std::string > paths = sofa::helper::system::DataRepository.getPaths();
std::copy( &paths[0], &paths[paths.size()], ostream_iterator<string>(cout, " "));
*/
*/
#endif
#ifdef MML_SOFA_1_0_BETA4
......@@ -312,9 +352,9 @@ void SofaSimulator::build() {
//-- load the SOFA scn
#if defined(SOFA_1_0_RC1) || defined(SOFA_SVN) || defined(SOFA_STABLE)
//preRC1 (svn)
groot = sofa::core::objectmodel::SPtr_dynamic_cast<sofa::simulation::Node>( sofa::simulation::tree::getSimulation()->load( scnFile.c_str() ) );
//RC1 groot = sofa::core::objectmodel::SPtr_dynamic_cast<sofa::simulation::Node>(sofa::simulation::getSimulation()->load(scnFile.c_str()));
// strong hypothesis: we don't use SOFA DAG, but sofa tree architecture
//groot = sofa::core::objectmodel::SPtr_dynamic_cast<sofa::simulation::Node>( sofa::simulation::tree::getSimulation()->load( fileName.c_str() ) );
groot = sofa::core::objectmodel::SPtr_dynamic_cast<sofa::simulation::Node>( sofa::simulation::tree::getSimulation()->load( scnFile.c_str() ) );
#endif
#ifdef MML_SOFA_1_0_BETA4
......@@ -335,6 +375,11 @@ void SofaSimulator::build() {
// init root
sofa::simulation::tree::getSimulation()->init( getGNode() );
// calling sofa::simulation::tree::getSimulation()->reset ( getGNode() ) is not needed as
// it is done in runSofa main (sse RealGUI::setScene -> RealGUI::resetScene )
// as it will be done automatically when the sofa simulator will be initialized
// (see SofaSimulator::init)
// sofa scn dt prevails
monitoringManager->setDt( getGNode()->getDt() );
......@@ -401,7 +446,12 @@ void SofaSimulator::doMove( double dt ) {
getGNode()->getContext()->setDt( dt );
//-- animate one step
#ifdef SOFA_STABLE
// Warning animate method does not need any dt. 0.0 is always at least used in Sofa v15_03
sofa::simulation::tree::getSimulation()->animate( getGNode(), /*dt*/0.0 );
#else
sofa::simulation::tree::getSimulation()->animate( getGNode(), dt );
#endif
}
// --------------- getPosition -------------------
......
......@@ -88,13 +88,13 @@ void SofaWidget::runSofa() {
} else {
folder=".";
}
p->setWorkingDirectory( tr(SOFA_PATH) + tr("/bin/") );
p->setWorkingDirectory( tr(SOFA_BUILD_DIR) + tr("/bin/") );
connect(p, SIGNAL(finished(int)), this, SLOT(sofaExited()));
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
env.insert("LD_LIBRARY_PATH", env.value("LD_LIBRARY_PATH") + ":" + SOFA_PATH + "/lib/linux/"); //TODO if win32...
env.insert("LD_LIBRARY_PATH", env.value("LD_LIBRARY_PATH") + ":" + SOFA_BUILD_DIR + "/lib/linux/"); //TODO if win32...
p->setProcessEnvironment(env);
p->start(tr(SOFA_PATH) + tr("/bin/runSofa"),QStringList() << temp);
p->start(tr(SOFA_BUILD_DIR) + tr("/bin/runSofa"),QStringList() << temp);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment