3. Import plug-ins
Prev | Chapter 6. Plug-ins development | Next

## 3. Import plug-ins

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

Following is a small description of the class ImportModule :

### Public members

Following is a list of all public members :

- `ImportModule (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");`

- `~ImportModule ()` :

  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 succeeds.

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 an ImportModule derived class

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

    using namespace std;
    using namespace tlp;

    /** Import module documentation */
    // MyImportModule is just an example
    /*@{*/

    class MyImportModule:public ImportModule {
    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");
      MyImportModule(AlgorithmContext context):ImportModule(context) {
      }

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

      // The import method is the starting point of your import module.
      // The returned value must be true if it succeeded.
      bool import(const string &name) {
        return true;
      }
    };
    /*@}*/

    // This line is very important because it's the only way to register your import module in tulip.
    // It automatically builds the plugin object that will embed the algorithm.
    IMPORTPLUGIN(MyImportModule, "My Import 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.
    // IMPORTPLUGINOFGROUP(MyImportModule, "My Import Module", "Authors", "07/07/07", "Comments", "1.0", "My algorithms");

Prev | Up | Next
2. The Algorithm class. | Home | 4. Export plug-ins