SEARCH
TOOLBOX
LANGUAGES
ComponentCreation

ComponentCreation

From SOFAWiki

Jump to: navigation, search
Basic instructions to create a new Component

A SOFA Component is a class deriving, directly or not, from sofa::core::objectmodel::BaseObject.

Contents

Where to put your files

  • The best way to write new components is to integrate them in a new Plugin
  • Conversely you can to place your files next to other existing components, located in Sofa/modules/sofa/components/, in the subdirectory corresponding to the type of your component (forcefield, constraint, linearsolver, ...).


Creating a new component

  • Your components must derive from the sofa::core::objectmodel::BaseObject class or an existing component (e.g: sofa::core::visual::VisualModel ).

In your header file :

#include <sofa/core/objectmodel/BaseObject.h>
 
class MyComponent : public sofa::core::objectmodel::BaseObject
{
public:
SOFA_CLASS(MyComponent ,BaseObject);
 
    MyComponent ();
    virtual ~MyComponent ();
};


Modifications of the .pro file

  • If you chose to put your components directly inside sofa directories (fast and dirty), open the .pro file in the same directory as your component
  • If you have a separated project, then you should already have a .pro file (take example on one of our projects), open this .pro file
  • Modify the opened .pro file by
    • Adding in the HEADERS section, the list of the new .h and .inl files
    • Adding in the SOURCES section, the list of the new .cpp files

Recreate the project

  1. For windows users, you have to run projectVC8.bat or projectVC9.bat depending on your version of Microsoft Visual Studio C++.
  2. For the others, simply run qmake at the Sofa main directory

Build Sofa

Launch the compilation. A good way to verify that your component's creation went well, is to launch the Modeler, and try to find it in the Library. If it doesn't appear, it means probably that you failed to register your component properly

Documentation

A scene has to be created, with the same name as your component, and placed inside Sofa/examples/Components and its good subdirectory. Finally, you can write a small paragraph for the sofa documentation placed in Sofa/doc, and a link to a publication, if any exists.