Plugin Example
This plugin is a simple example of plugin. It aims to help you understand:
You may use it as a starting point to create your own plugin, and replace this page with your documentation.
Components
- MyBehaviorModel is one of
the simple possible components. It contains two attributes and does
basically nothing (Tode: make it do something).
- MyProjectiveConstraintSet is templated
on the type of degrees of fredom it processes. Note that the generic
implementations are defined in a .inl file, registered as a header in
the .pro file. The .cpp contains the instantiations of the class on
different types, which generate binary code.
- MyMappingPendulumInPlane is a real example of mapping. It shows examples of how to access the state vectors in the member methods.
- MyDataWidgetUnsigned shows how to create a custom data widget in the Qt GUI.
Create your own plugin
Suppose you want to create a plugin called YourPlugin. The easiest way is to apply the following steps:
- copy and rename the PluginExample example directory to YourPlugin
- rename PluginExample.pro to YourPlugin.pro, and PluginExample.txt to YourPlugin.txt
- replace PluginExample with YourPlugin in the following files:
- YourPlugin.pro
- YourPlugin.txt
- initPlugin.h
- initPlugin.cpp
- compile the plugin
- Linux
- The simplest way is to use Qt Creator. An example of execution parameters is given here.
- Windows, mac: TODO
- run the plugin.
- Do not forget to load it in Sofa (in the Qt GUI, use Edit > Plugin Manager > add…)
- You can adapt the example scene : PluginExampleTest.scn
Add, rename, remove component classes
To add a class
- create the .h and .cpp files (as well as a .inl if the class is template)
- add them to the project in the .pro file
- declare the class in the initPlugin.cpp file
To rename a class
- change the file names, the project file and the initPlugin.cpp file
- alternatively, the Unix shell script changeClassName.sh allows you to easily change a class Name:
./changeClassName.sh OldClassName NewClassName
This script replaces string OldClassName with string NewClassName in
all files (including .pro), and in the file names, of the current
directory.
It can also be used to rename the plugin.
To remove a class
- do not forget to remove it from the project file and the initPlugin file.
Document the code using Doxygen
Doxygen can automatically create code documentation. Run doxygen using the above Doxyfile if the previous link was broken.