Skip to content

Commit

Permalink
[sofaInfo] Fix compilation and behavior (#4422)
Browse files Browse the repository at this point in the history
Co-authored-by: Paul Baksic <30337881+bakpaul@users.noreply.github.com>
  • Loading branch information
alxbilger and bakpaul committed Jan 10, 2024
1 parent 44ad519 commit 4abcbe6
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 37 deletions.
1 change: 1 addition & 0 deletions applications/projects/CMakeLists.txt
Expand Up @@ -16,3 +16,4 @@ sofa_add_subdirectory(application sofaOPENCL sofaOPENCL OFF)
sofa_add_subdirectory(directory Regression Regression EXTERNAL)
sofa_add_subdirectory(directory SofaGLFW SofaGLFW EXTERNAL)
sofa_add_subdirectory(application sofaProjectExample sofaProjectExample)
sofa_add_subdirectory(application sofaInfo sofaInfo)
9 changes: 4 additions & 5 deletions applications/projects/sofaInfo/CMakeLists.txt
@@ -1,10 +1,9 @@
cmake_minimum_required(VERSION 3.12)
project(sofaInfo)

find_package(SofaGeneral)
find_package(SofaMisc)
find_package(SofaBase)
find_package(SofaCommon)
find_package(Sofa.Config)
sofa_find_package(Sofa.Component)
sofa_find_package(Sofa.Simulation.Graph)

add_executable(${PROJECT_NAME} sofaInfo.cpp)
target_link_libraries(${PROJECT_NAME} SofaGeneral SofaBase SofaCommon SofaMisc)
target_link_libraries(${PROJECT_NAME} Sofa.Component Sofa.Simulation.Graph)
54 changes: 22 additions & 32 deletions applications/projects/sofaInfo/sofaInfo.cpp
Expand Up @@ -19,32 +19,31 @@
* *
* Contact information: contact@sofa-framework.org *
******************************************************************************/
#include <SofaBase/initSofaBase.h>
#include <SofaCommon/initSofaCommon.h>
#include <SofaGeneral/initSofaGeneral.h>
#include <sofa/core/ObjectFactory.h>
#include <sofa/component/init.h>
#include <sofa/simulation/Node.h>
#include <sofa/simulation/Simulation.h>
#include <sofa/simulation/common/init.h>
#include <sofa/simulation/graph/init.h>

// ---------------------------------------------------------------------
// ---
// ---------------------------------------------------------------------
int main(int /*argc*/, char** argv)
{
sofa::simulation::tree::init();
sofa::component::initSofaBase();
sofa::component::initSofaCommon();
sofa::component::initSofaGeneral();
sofa::simulation::common::init();
sofa::simulation::graph::init();
sofa::component::init();

if (argv[1] == NULL)
if (argv[1] == nullptr)
{
std::cout << "Usage: sofaInfo FILE" << std::endl;
return -1;
}

sofa::simulation::setSimulation(new sofa::simulation::tree::TreeSimulation());
sofa::simulation::Node::SPtr groot = sofa::simulation::node::load(argv[1]);

sofa::simulation::Node::SPtr groot = sofa::core::objectmodel::SPtr_dynamic_cast<sofa::simulation::Node>( sofa::simulation::getSimulation()->load(argv[1]));

if (groot==NULL)
if (groot == nullptr)
{
groot = sofa::simulation::getSimulation()->createNewGraph("");
}
Expand All @@ -56,42 +55,33 @@ int main(int /*argc*/, char** argv)
groot->getTreeObjects<sofa::core::objectmodel::Base>(&objects);

// get the classes and targets of the scene
for (unsigned int i=0; i<objects.size(); i++)
for (const auto& object : objects)
{
sofa::core::ObjectFactory::ClassEntry& entry = sofa::core::ObjectFactory::getInstance()->getEntry(objects[i]->getClassName());
if (entry.creatorMap.empty())
sofa::core::ObjectFactory::ClassEntry& entry = sofa::core::ObjectFactory::getInstance()->getEntry(object->getClassName());
if (!entry.creatorMap.empty())
{
classNames.insert(entry.className);

sofa::core::ObjectFactory::CreatorMap::iterator it = entry.creatorMap.find(objects[i]->getTemplateName());
const auto it = entry.creatorMap.find(object->getTemplateName());
if (it != entry.creatorMap.end() && *it->second->getTarget())
{
targets.insert(it->second->getTarget());
}
}
}

std::set<std::string>::const_iterator it = classNames.begin();
std::set<std::string>::const_iterator end = classNames.end();
std::cout << "=== CLASSES ===" << std::endl;
while (it != end)
{
std::cout << (*it) << std::endl;
it++;
}
std::cout << sofa::helper::join(classNames, "\n");

it = targets.begin();
end = targets.end();
std::cout << std::endl << "=== TARGETS ===" << std::endl;
while (it != end)
std::cout << sofa::helper::join(targets, "\n");

if (groot != nullptr)
{
std::cout << (*it) << std::endl;
it++;
sofa::simulation::node::unload(groot);
}

if (groot!=NULL)
sofa::simulation::getSimulation()->unload(groot);

sofa::simulation::tree::cleanup();
sofa::simulation::common::cleanup();
sofa::simulation::graph::cleanup();
return 0;
}

0 comments on commit 4abcbe6

Please sign in to comment.