Tulip  6.0.0
Large graphs analysis and drawing
ImportModule.h
1 /*
2  *
3  * This file is part of Tulip (https://tulip.labri.fr)
4  *
5  * Authors: David Auber and the Tulip development Team
6  * from LaBRI, University of Bordeaux
7  *
8  * Tulip is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU Lesser General Public License
10  * as published by the Free Software Foundation, either version 3
11  * of the License, or (at your option) any later version.
12  *
13  * Tulip is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16  * See the GNU General Public License for more details.
17  *
18  */
19 ///@cond DOXYGEN_HIDDEN
20 
21 #ifndef _IMPORTMODULE_H
22 #define _IMPORTMODULE_H
23 
24 #include <tulip/Plugin.h>
25 
26 #include <list>
27 #include <string>
28 
29 namespace tlp {
30 
31 static const std::string IMPORT_CATEGORY = "Import";
32 
33 class PluginProgress;
34 class Graph;
35 class DataSet;
36 
37 /**
38  * @addtogroup Plugins
39  * @brief Base class for import plugins.
40  **/
41 class TLP_SCOPE ImportModule : public tlp::Plugin {
42 public:
43  ImportModule(const tlp::PluginContext *context);
44  /**
45  * @brief Gets the extensions of the file formats the plugin can import.
46  * e.g. a TLP import would return 'tlp'.
47  *
48  * @return the list of file extensions the plugin can import.
49  **/
50  virtual std::list<std::string> fileExtensions() const {
51  return std::list<std::string>();
52  }
53 
54  std::string category() const override {
55  return IMPORT_CATEGORY;
56  }
57 
58  std::string icon() const override {
59  return ":/tulip/gui/icons/64/document-import.png";
60  }
61 
62  /**
63  * @brief The import operations should take place here.
64  *
65  * @return bool Whether the import was successful or not.
66  **/
67  virtual bool importGraph() = 0;
68 
69  /**
70  * @brief The Graph in which to write the data to import.
71  **/
72  Graph *graph;
73 
74  /**
75  * @brief A means to report progress to the user.
76  **/
77  PluginProgress *pluginProgress;
78 
79  /**
80  * @brief A container for the parameters of this import plug-in.
81  **/
82  DataSet *dataSet;
83 };
84 
85 /**
86  * @addtogroup Plugins
87  * @brief Base class for plugins importing from a file.
88  **/
89 class TLP_SCOPE ImportFileModule : public ImportModule {
90 protected:
91  /**
92  * @brief The pathname of the file to import
93  **/
94  std::string filename;
95 
96  /**
97  * @brief The supported file extensions
98  **/
99  std::list<std::string> extensions;
100 
101 public:
102  ImportFileModule(const tlp::PluginContext *context, std::list<std::string> exts = {});
103 
104  /**
105  * @brief override the inherited method
106  **/
107  std::list<std::string> fileExtensions() const override {
108  return extensions;
109  }
110 
111  /**
112  * @brief check plugin parameters
113  **/
114  virtual bool check();
115 
116  /**
117  * @brief create the graph contents from the file data
118  **/
119  virtual bool importFile() = 0;
120 
121  /**
122  * @brief override the inherited method
123  **/
124  bool importGraph() override;
125 };
126 
127 } // namespace tlp
128 #endif
129 ///@endcond
Contains runtime parameters for a plugin.
Definition: PluginContext.h:42
Top-level interface for plug-ins.
Definition: Plugin.h:86
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.