4. Export plug-ins

In this section, we will learn how to create export plug-ins. Those plug-ins will inherit from ExportModule.

Following is a small description of the class ExportModule :

Public members

Following is a list of all public members :

  • ExportModule (AlgorithmContext context) :

    The constructor is the right place to declare the parameters needed by the algorithm.

    addParameter<DoubleProperty>("metric", paramHelp[0], 0, false);

    And to declare the algorithm dependencies.

    addDependency<Algorithm>("Quotient Clustering", "1.0");

  • ~ExportModule () :

    Destructor of the class.

  • bool import (const std::string name) :

    This is the main method, the starting point of your algorithm.

    The returned value must be true if your algorithm succeeded.

The methods below, will be redefined in our plugin (See section plug-in skeleton).

Protected members

Following is a list of all protected members :

  • Graph* graph :

    This graph is the one given in parameters, the one on which the algorithm will be applied.

  • PluginProgress* pluginProgress :

    The class PluginProgress can be used to have an interaction between the user and our algorithm. See the section called “The PluginProgress class.” for more details.

  • DataSet* dataSet :

    This member contains all the parameters needed to run the Algorithm. The class DataSet is a container which allows insertion of values of different types. The inserted data must have a copy-constructor well done. See the section called DataSet for more details.

Skeleton of an ExportModule derived class

 

#include <tulip/TulipPlugin.h>
#include <string>
#include <iostream>

using namespace std;
using namespace tlp;

/** Export module documentation */
// MyExportModule is just an example
/*@{*/


class MyExportModule:public ExportModule { 
public:

  // The constructor below has to be defined,
  // it is the right place to declare the parameters
  // needed by the algorithm,
  // addParameter<DoubleProperty>("metric", paramHelp[0], 0, false);
  // and declare the algorithm dependencies too.
  // addDependency<Algorithm>("Quotient Clustering", "1.0");
  MyExportModule(AlgorithmContext context):ExportModule(context) {
  }

  // Define the destructor only if needed 
  // ~MyExportModule() {
  // }

  // The exportGraph method is the starting point of your export module.
  // The returned value must be true if it succeeded.
  bool exportGraph(ostream &os,Graph *graph) {
    return true;
  }
};
/*@}*/

// This line is very important because it's the only way to register your export module in tulip.
// It automatically builds the plugin object that will embed the algorithm.
EXPORTPLUGIN(MyExportModule, "My Export Module", "Authors", "07/07/07", "Comments", "1.0")
// If you want to present your algorithm in a dedicated submenu of the Tulip GUI,
// use the declaration below where the last parameter specified the name of submenu.
// EXPORTPLUGINOFGROUP(MyExportModule, "My Export Module", "Authors", "07/07/07", "Comments", "1.0", "My algorithms");