Difference between revisions of "MITK Plugin Style Guide"

From mitk.org
Jump to navigation Jump to search
m (JasminMetzger moved page PluginStyleGuide to MITK Plugin Style Guide)
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
__NOTOC__
 
= The MITK Plugin Style Guide =
 
 
'''Attention:''' This article describes legacy [[BlueBerry]] bundles. MITK switched to using the CTK plugin framework. Although many things remain the same, this article needs to be revised.
 
'''Attention:''' This article describes legacy [[BlueBerry]] bundles. MITK switched to using the CTK plugin framework. Although many things remain the same, this article needs to be revised.
  
Line 8: Line 6:
  
 
[[File:PluginStyleGuide$plugin_folder.png]]
 
[[File:PluginStyleGuide$plugin_folder.png]]
 +
__TOC__
  
 
=== Meta files ===
 
=== Meta files ===
Line 15: Line 14:
 
* [http://makalu/doxygen/ExtensionPoints.html plugin.xml] (optional): You need this file if you want to use extension-points or declare your own. If you don't know what this means, you won't need that file. Must be located under the plugins root directory.
 
* [http://makalu/doxygen/ExtensionPoints.html plugin.xml] (optional): You need this file if you want to use extension-points or declare your own. If you don't know what this means, you won't need that file. Must be located under the plugins root directory.
 
* [http://makalu/doxygen/ManifestCpp.html manifest.cpp] (optional): This file contains code which makes your classes known to the platforms dynamic class loader. You need this file if you are using extension-points.
 
* [http://makalu/doxygen/ManifestCpp.html manifest.cpp] (optional): This file contains code which makes your classes known to the platforms dynamic class loader. You need this file if you are using extension-points.
 +
  
 
=== Build files ===
 
=== Build files ===
Line 22: Line 22:
 
* files.cmake (optional): List your source and resource files here.
 
* files.cmake (optional): List your source and resource files here.
 
* includes.cmake (optional, not in screenshot): Inside this file, you can set the CMake variable ''ADDITIONAL_INCLUDE_DIRECTORIES'' to a list of directories which are added as include paths to dependent plugins.
 
* includes.cmake (optional, not in screenshot): Inside this file, you can set the CMake variable ''ADDITIONAL_INCLUDE_DIRECTORIES'' to a list of directories which are added as include paths to dependent plugins.
 +
  
 
=== Documentation files ===
 
=== Documentation files ===
Line 27: Line 28:
 
* documentation/doxygen/modules.dox (required): This file is required if your plugin contains source code. It must define two doxygen groups for your plugin, see below:
 
* documentation/doxygen/modules.dox (required): This file is required if your plugin contains source code. It must define two doxygen groups for your plugin, see below:
  
 
+
<syntaxhighlight lang="cpp">
<pre><nowiki>
 
 
/**
 
/**
 
   \defgroup org_mitk_gui_qt_isosurface org.mitk.gui.qt.isosurface Plugin
 
   \defgroup org_mitk_gui_qt_isosurface org.mitk.gui.qt.isosurface Plugin
Line 45: Line 45:
 
   may change at any time. We mean it.
 
   may change at any time. We mean it.
 
*/
 
*/
</nowiki></pre>
+
</syntaxhighlight>
 +
 
  
 
=== Resource files ===
 
=== Resource files ===
Line 51: Line 52:
  
 
* resources.qrc (optional): if you use Qt, you may want to list your resource files here.
 
* resources.qrc (optional): if you use Qt, you may want to list your resource files here.
 +
  
 
=== Source files ===
 
=== Source files ===
 
* src/IsosurfaceDll.h (required): Required if your plugin contains source code. This file (the name depends on your plugin name) defines a macro containing Windows DLL export/import specifiers. You must use this macro in your class declaration (if you want your class to be accessible across DLL boundaries).
 
* src/IsosurfaceDll.h (required): Required if your plugin contains source code. This file (the name depends on your plugin name) defines a macro containing Windows DLL export/import specifiers. You must use this macro in your class declaration (if you want your class to be accessible across DLL boundaries).
  
 
+
<syntaxhighlight lang="cpp">
<pre><nowiki>#!cplusplus
 
 
class ISOSURFACE_EXPORTS QmitkIsoSurface
 
class ISOSURFACE_EXPORTS QmitkIsoSurface
 
{
 
{
 
...
 
...
 
};
 
};
</nowiki></pre>
+
</syntaxhighlight>
  
 
Source files should be logically grouped into two categories: Internal and External. In the beginning, usually every source and header file is internal, meaning that it is not intended to be used by other plugins/dlls/whatever. Hence it must be placed into ''src/internal''. This has nothing to do with Windows DLL export/import specifications but rather says that you do not see any benefit for others in making your classes accessible, or your code is not mature enough to be part of your plugins public API. Placing code directly under ''src'' essentially means: This code is public API, and safe for others to use (i.e. the class interfaces won't change much).
 
Source files should be logically grouped into two categories: Internal and External. In the beginning, usually every source and header file is internal, meaning that it is not intended to be used by other plugins/dlls/whatever. Hence it must be placed into ''src/internal''. This has nothing to do with Windows DLL export/import specifications but rather says that you do not see any benefit for others in making your classes accessible, or your code is not mature enough to be part of your plugins public API. Placing code directly under ''src'' essentially means: This code is public API, and safe for others to use (i.e. the class interfaces won't change much).
Line 72: Line 73:
 
Furthermore, you must put every class inside the appropriate doxygen group. For internal classes, this looks like
 
Furthermore, you must put every class inside the appropriate doxygen group. For internal classes, this looks like
  
 
+
<syntaxhighlight lang="cpp">
<pre><nowiki>#!cplusplus
 
 
/*!
 
/*!
 
   \ingroup org_mitk_gui_qt_isosurface_internal
 
   \ingroup org_mitk_gui_qt_isosurface_internal
Line 81: Line 81:
 
...
 
...
 
};
 
};
</nowiki></pre>
+
</syntaxhighlight>
  
 
and for external classes
 
and for external classes
  
 
+
<syntaxhighlight lang="cpp">
<pre><nowiki>#!cplusplus
 
 
/*!
 
/*!
 
   \ingroup org_mitk_gui_qt_isosurface
 
   \ingroup org_mitk_gui_qt_isosurface
Line 94: Line 93:
 
...
 
...
 
};
 
};
</nowiki></pre>
+
</syntaxhighlight>

Latest revision as of 15:57, 4 December 2014

Attention: This article describes legacy BlueBerry bundles. MITK switched to using the CTK plugin framework. Although many things remain the same, this article needs to be revised.

This is a style guide for writing new MITK plugins. Although you could organize your files inside your plugin directory nearly arbitrarily, it is strongly advised (a nice word for mandatory) to follow this guide.

Your plugin directory should look like this (individual folders are discussed below):

PluginStyleGuide$plugin folder.png

Meta files

These are files containing information about your plugin (id, name, version, extensions, ...). Click on the names of the files to get more information.

  • META-INF/MANIFEST.MF (required): This file is required to have exactly this name and to be located in this folder.
  • plugin.xml (optional): You need this file if you want to use extension-points or declare your own. If you don't know what this means, you won't need that file. Must be located under the plugins root directory.
  • manifest.cpp (optional): This file contains code which makes your classes known to the platforms dynamic class loader. You need this file if you are using extension-points.


Build files

Used to control build specific aspects of your plugin.

  • CMakeLists.txt (required): This is the entry-point for CMake. You only need to change this file if you have dependencies on external libraries (not included in plugins).
  • files.cmake (optional): List your source and resource files here.
  • includes.cmake (optional, not in screenshot): Inside this file, you can set the CMake variable ADDITIONAL_INCLUDE_DIRECTORIES to a list of directories which are added as include paths to dependent plugins.


Documentation files

  • documentation/UserManual (optional): This is the place for your user manual.
  • documentation/doxygen/modules.dox (required): This file is required if your plugin contains source code. It must define two doxygen groups for your plugin, see below:

<syntaxhighlight lang="cpp"> /**

 \defgroup org_mitk_gui_qt_isosurface org.mitk.gui.qt.isosurface Plugin
 \ingroup MITKPlugins
 \brief This is the isosurface plugin.
  • /

/**

 \defgroup org_mitk_gui_qt_isosurface_internal Internal
 \ingroup org_mitk_gui_qt_isosurface
 \brief This subcategory includes the internal classes of the org.mitk.gui.qt.isosurface plugin. Other
 plugins must not rely on these classes. They contain implementation details and their interface
 may change at any time. We mean it.
  • /

</syntaxhighlight>


Resource files

Resource files are usually all files which are not source-code files but are necessary for your code at runtime. They belong into the resources folder.

  • resources.qrc (optional): if you use Qt, you may want to list your resource files here.


Source files

  • src/IsosurfaceDll.h (required): Required if your plugin contains source code. This file (the name depends on your plugin name) defines a macro containing Windows DLL export/import specifiers. You must use this macro in your class declaration (if you want your class to be accessible across DLL boundaries).

<syntaxhighlight lang="cpp"> class ISOSURFACE_EXPORTS QmitkIsoSurface { ... }; </syntaxhighlight>

Source files should be logically grouped into two categories: Internal and External. In the beginning, usually every source and header file is internal, meaning that it is not intended to be used by other plugins/dlls/whatever. Hence it must be placed into src/internal. This has nothing to do with Windows DLL export/import specifications but rather says that you do not see any benefit for others in making your classes accessible, or your code is not mature enough to be part of your plugins public API. Placing code directly under src essentially means: This code is public API, and safe for others to use (i.e. the class interfaces won't change much).

Summary:

  • src: Code intended to be used by others (for example in order to extend your plugin). Every class declaration must contain the DLL export/import macro.
  • src/internal: Internal implementation code not to be used by others. Class declarations may contain the DLL export/import macro.

Furthermore, you must put every class inside the appropriate doxygen group. For internal classes, this looks like

<syntaxhighlight lang="cpp"> /*!

 \ingroup org_mitk_gui_qt_isosurface_internal
 */

class MyInternalClass { ... }; </syntaxhighlight>

and for external classes

<syntaxhighlight lang="cpp"> /*!

 \ingroup org_mitk_gui_qt_isosurface
 */

class ISOSURFACE_EXPORTS MyExternalClass { ... }; </syntaxhighlight>