![]() |
GeMA
The GeMA main application
|
This tutorial presents a step by step guide for creating a new physics plugin. On the first part, it will present how to create the skeleton for a new plugin based on a copy of an existing one. For those already familiar with updating and changing existing physics plugins, this part will provide the needed base for continuing on your own. The second part explains the needed structure and methods for a physics plugin.
This step will estabilish a base to begin with. The best way is to choose a simple physics as the 'source template'. In this example we will choose the temperature physics as our base and we will call our new physics diffusionFemPhysics. If you are creating a coupled physics, or a physics inheriting from another existing physics, other options might work best.
To make this copy, go to the plugins\physics directory and make a copy of the temperature physics directory, calling it diffusionFemPhysics. Please keep in mind that under the GeMA package distribution there are two 'plugins' directories. The one with the source code resides under the root directory. The other one, with plugin binaries is located under the gema application directory. Make sure to make your copy from the source code one.
If your copy was not done from a clean distribution, make sure to discard any files that are not version controled (those are in general the debug, release, generated, lib and doxygen\html directories plus *.vcxproj.*, doxygenlog.txt and doxygen\*.tag files).
While on the plugins\physics directory, make sure to edit both the DoxygenBuild.bat and vc_build_physics.bat files. Just follow the existing pattern adding new entries in both files for the new diffusionFemPhysics directory.
Now get into the diffusionFemPhysics directory and rename the .pro file to diffusionFemPhysics.pro. Open this file in a text editor to adjust the new project building options. The following changes should be done:
Now go inside the inc and src subdirectories and rename those files according to the names given in the diffusionFemPhysics.pro file. At this step we won't bother with those files contents, since for now we just want to be able to generate the new Visual Studio project. Files should now be named gmpDiffusionConfig.h, gmpDiffusionVersion.h, gmpDiffusionFemPhysics.cpp, gmpDiffusionFemPhysics.h and gmpDiffusionFemPhysicsFactory.h.
Now go inside the luaScripts directory and do the following changes:
Gema.FemProcessPlugin.CheckFemPhysics(physDef)
.Going back to the physics main directory, rename the plugin .lua definition file to diffusionFemPhysics.lua. Edit this file making the following changes:
Although this step can be done later on, lets do it now so that we do not forget how important documentation is. First open the file Doxyfile in a text editor and change the following tags:
Go into the doxygen folder and edit the doxygenMainPage.h contents. Make sure to adjust the subpage name reference to the plugin options page. Now go into the doxygenPluginOptions.h file and update its tag name + the file contents to document the new plugin available options. Keep in min that several of the default options are common to all physics plugins.
To link your new plugin documentation to the global documentation, the files doxygenPluginReferenceIndex.h and doxygenClassDocumentationIndex.h, both located in the gema\doxygen directory should be updated with links to the new plugin. Just follow the existing pattern in both files (and do not forget to later rebuild the documentation following the instructions in the documentation tutorial, but don't do it now - wait until we finish with this part of the tutorial). The Doxyfile in the gema directory should also be updated by adding an entry in the TAGFILES list corresponding to the new plugin.
Go back to the root gema directory and open the versionList.lua file. Add a new line for your plugin specifying its path (plugins/physics/diffusionFemPhysics), version number, the name of the version header file (gmpDiffusionVersion.h), the prefix used for the auto-generated version functions (GmpDiffusionFemPhysics) and the list of libraries and other plugins that this plugin depends on. This list is used for dependency version check when loading a plugin.
Execute the standard vc_build.bat on the project root directory as you regularly do after a project update or adding files to the project. After this the plugin .vcxproj files should have been created. Take special care to look if any warnings or errors where written to the console.
Open the gema.sln in the Visual Studio application. On the solution explorer, select the Physics folder under the Plugins folder. With a right click, select the "Add Existing Project" option. On the file selection dialog, choose the newly created vcxproj file for your plugin. This will add your new plugin to the solution.
On the solution explorer, right click on the root "Solution" entry and select the "Project Dependencies" option. On the dialog shown, mark that the gema application depends on the new physics. Select your new physics on the Projects combo box and mark bellow the projects that it depends upon. Use the base physics as a template. In general a physics plugin will depend at least on femProcess, gemaCoreLib, luautils and unit projects.
Edit the GmpDiffusionFemPhysics class definition and implementation on files gmpDiffusionFemPhysics.h and gmpDiffusionFemPhysics.cpp. The contents of a minimum physics class that compiles, but does nothing, is given below. We are going to fill that class with meaningfull code on Part II of this tutorial. While editing the files, please remember to update file names and #ifdefs accordingly.
In the class definition, please notice that the value returned by the pluginName() method should match the pluginName given in the plugin definition file (step 5). Also, the pluginType should match one of the names given in the objectTypes table of that same file. If the physics supports several object types, there should either be a class for each type or the type should be received as an object constructor parameter and used in this function return value.
Edit the GmpDiffusionFemPhysicsFactory class implementation on file gmpDiffusionFemPhysicsFactory.h. The contents of a minimum physics factory class is given below. We are going to explore that class further on Part II of this tutorial. While editing the files, please remember to update file names and #ifdefs accordingly.
In the class implementation, please notice that the string passed to the GmPluginObjectFactory() inherited constructor is the base name for the plugin logger and should be equal to the plugin name. The functions used to return the plugin version information are automatically created from the version information filled on step 7.
If the steps above where followed correctly, your code should compile. Check that the plugin DLL + static library where created on the lib directory and also on the gema application equivalent plugin directory.
Now that your plugin is compiling, add the new files to the SVN source control. Remeber that generated files (such as those on the debug, release, generated, lib and doxygen\html directories plus *.vcxproj.*, doxygenlog.txt and doxygen\*.tag files) should not be added to the repository and should be marked as ignored.