Tulip  5.5.1
Large graphs analysis and drawing
clique_import/cliqueimport.cpp

This example shows a simple graph import plug-in.It details the different functions and possibilities of a Graph import plug-in.

#include <string>
#include <tulip/TulipPluginHeaders.h>
using namespace tlp;
using namespace std;
class CliqueImport : public tlp::ImportModule {
public:
PLUGININFORMATION("Clique", "Tulip Team", "05/10/2012", "Clique Import Plugin", "1.0", "Graph")
CliqueImport(tlp::PluginContext *context);
~CliqueImport();
bool importGraph();
};
PLUGIN(CliqueImport)
// a description of the parameter, that will appear in the GUI to explain how the parameter
// influences the plugin.
const char *nodeCountDescription = "How many nodes the clique will contain";
CliqueImport::CliqueImport(tlp::PluginContext *context) : ImportModule(context) {
// how many nodes we want in our clique
addInParameter<unsigned int>("nodeCount", nodeCountDescription, "5");
// depend on the circular layout, as it is the most obvious choice to draw a clique
addDependency("Circular", "1.1");
}
CliqueImport::~CliqueImport() {}
// retrieve the number of nodes we need to create
unsigned int nodeCount = 5;
dataSet->get("nodeCount", nodeCount);
// create the nodes
for (unsigned int i = 0; i < nodeCount; ++i) {
graph->addNode();
}
/*
* This could be done more efficiently by using a vector of nodes and iterating over the indices,
* but we don't really care about performances in this case, do we ?
*/
// double iteration over the graph's nodes.
for (auto current : graph->nodes()) {
for (auto other : graph->nodes()) {
if (current != other) {
graph->addEdge(current, other);
}
}
}
// apply the circular algorithm on the clique to make it look good (at least better than 'Random')
LayoutProperty *layout = graph->getProperty<LayoutProperty>("viewLayout");
string message;
graph->applyPropertyAlgorithm("Circular", layout, message);
// no way in hell this can fail.
return true;
}
tlp::LayoutProperty
A graph property that maps a tlp::Coord value to graph nodes and std::vector<tlp::Coord> for edges.
Definition: LayoutProperty.h:50
tlp::PluginContext
Contains runtime parameters for a plugin.
Definition: PluginContext.h:42
PLUGININFORMATION
#define PLUGININFORMATION(NAME, AUTHOR, DATE, INFO, RELEASE, GROUP)
Declare meta-information for a plugin This is an helper macro that defines every function related to ...
Definition: Plugin.h:233
PLUGIN
#define PLUGIN(C)
Register a plugin into the plugin system. This macro is mandatory in order to register a plugin into ...
Definition: Plugin.h:296
tlp::importGraph
Graph * importGraph(const std::string &format, DataSet &dataSet, PluginProgress *progress=nullptr, Graph *newGraph=nullptr)
Imports a graph using the specified import plugin with the parameters stored in the DataSet.
tlp
Definition: AbstractProperty.h:34
tlp::Graph::addNode
virtual node addNode()=0
Adds a new node in the graph and returns it. This node is also added in all the ancestor graphs.