In this post, we are going to explore two tricks around plugins: auto-loading and application private plugins.
auto-loading
dtk plugins path is usually set in a .config/inria/dtk-LAYER-NAME.ini file (in linux) in order to be loaded at runtime. Let’s take the layer dtk-discrete-geometry for demonstration. For this layer, my dtk-discrete-geometry.ini file is:
[discrete-geometry] plugins=/home/tcabel/Devel/dtk-plugins-discrete-geometry/build/lib64
the default action when you initialize a layer is to scan all files in the plugins directory define in this .ini file and load them if they are plugins of the layer being initialized.
However, you may have some plugins that cannot work together (for example two plugins compiled with different versions of VTK). In this situation, you can choose to only load the plugins you need. Here is how you do these two options:
- default way:
// dtk-discrete-geometry dtkDiscreteGeometry::pluginManager::initialize(); mesh_view = dtkDiscreteGeometry::meshView::pluginFactory().create("dtkMeshViewVTKCatalyst");
- no auto-load
//dtk-discrete-geometry dtkDiscreteGeometry::pluginManager::setAutoLoading(false); dtkDiscreteGeometry::pluginManager::initialize(); dtkDiscreteGeometry::meshView::pluginManager().loadFromName("dtkMeshViewVTKCatalyst"); mesh_view = dtkDiscreteGeometry::meshView::pluginFactory().create("dtkMeshViewVTKCatalyst");
private plugins
Another usefull functionality that you may need is to use plugins specific for your application: private plugins. In order to use this kind of plugins do the three following steps.
- First add a new file dtkTracesPluginsConfig.in in your application plugins source directory as this:
#pragma once #define DTKTRACES_PLUGINS_PATH "@CMAKE_BINARY_DIR@/lib"
As you guessed “@CMAKE_BINARY_DIR@/lib” is the directory where the plugins will be compiled.
- Then, edit your CMakeLists.txt to include this config file
configure_file(plugins/dtkTracesPluginsConfig.in dtkTracesPluginsConfig.h)
- To finish, when you initialize your plugins, use this pre-processing variable:
#include "dtkTracesPluginsConfig.h" [...] dtkDiscreteGeometry::pluginManager::initialize(); dtkDiscreteGeometry::mesher::pluginManager().initialize(DTKTRACES_PLUGINS_PATH); dtkDiscreteGeometry::meshPartitionner::pluginManager().initialize(DTKTRACES_PLUGINS_PATH);