Tulip 5.7.1
Large graphs analysis and drawing
Loading...
Searching...
No Matches
TLPBExportImport.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 TLPBIMPORTEXPORT_H
22#define TLPBIMPORTEXPORT_H
23
24#include <iostream>
25#include <list>
26#include <vector>
27
28#include <tulip/Graph.h>
29#include <tulip/ExportModule.h>
30#include <tulip/ImportModule.h>
31
32// some compilation environments define major and minor as preprocessor macros
33// undefine them in that case
34#ifdef major
35#undef major
36#endif
37
38#ifdef minor
39#undef minor
40#endif
41
42/**
43 * The plugins below export/import a Tulip graph
44 * using the following binary format:
45 * format header = <magic_number, major, minor> (uint16 + uint8 +uint8)
46 * nb_nodes = uint32
47 * nb_edges = uint32
48 * edges = nb_edges * <source, target> (uint32+uint32)
49 * nb_subgraphs = uint32
50 * subgraphs = nb_subgraphs * <subgraph_id, parent_graph_id, nodes_desc, edges_desc>
51 * nodes_desc = nb_nodes_intervals * <first_node, last_node>
52 * edges_desc = nb_edges_intervals *<first_edge, last_edge>
53 * nb_properties = uint32
54 * properties = <prop_name, graph_id, type, default_node_val, default_edge_val, nodes_val,
55 * edges_val>
56 * prop_name = length + utf8 text
57 * graph_id = uint32
58 * type = length + utf8 text
59 * default_node_val = type dependent (method readb)
60 * default_edge_val = type dependent (method readb)
61 * nb_nodes_val = uint32
62 * nodes_val = nb_nodes_val * <node, node_val> (uint32 + type dependent)
63 * nb_edges_val = uint32
64 * edges_val = nb_edges_val * <edge, edge_val> (uint32 + type dependent)
65 * graph_attributes = (nb_subgraphs + 1) * <graph_id, graph_attributes_list>*
66 */
67
68/*@{*/
69/// Export plugin for TLPB format
70/**
71 *
72 * \brief This plugin saves a Tulip graph using a binary format
73 *
74 */
75class TLPBExport : public tlp::ExportModule {
76public:
77 PLUGININFORMATION("TLPB Export", "David Auber, Patrick Mary", "13/07/2012",
78 "<p>Supported extensions: tlpb, tlpbz (compressed), tlpb.gz "
79 "(compressed)</p><p>Exports a graph in a file using the Tulip binary format.",
80 "1.2", "File")
81
82 std::string fileExtension() const override {
83 return "tlpb";
84 }
85
86 std::list<std::string> gzipFileExtensions() const override {
87 std::list<std::string> ext;
88 ext.push_back("tlpb.gz");
89 ext.push_back("tlpbz");
90 return ext;
91 }
92
93 TLPBExport(const tlp::PluginContext *context) : ExportModule(context) {}
94 ~TLPBExport() override {}
95
96 bool exportGraph(std::ostream &) override;
97
98 std::string icon() const override {
99 return ":/tulip/gui/icons/tlpb32x32.png";
100 }
101
102 inline tlp::node getNode(tlp::node n) {
103 assert(graph->isElement(n));
104 return tlp::node(graph->nodePos(n));
105 }
106
107 inline tlp::edge getEdge(tlp::edge e) {
108 assert(graph->isElement(e));
109 return tlp::edge(graph->edgePos(e));
110 }
111
112 void getSubGraphs(tlp::Graph *, std::vector<tlp::Graph *> &);
113
114 void writeAttributes(std::ostream &, tlp::Graph *);
115};
116
117/// Import plugin for TLPB format
118/**
119 *
120 * \brief This plugin reads a Tulip graph using a binary format
121 *
122 */
123class TLPBImport : public tlp::ImportModule {
124public:
125 PLUGININFORMATION("TLPB Import", "David Auber, Patrick Mary", "13/07/2012",
126 "<p>Supported extensions: tlpb, tlpb.gz (compressed), tlpbz "
127 "(compressed)</p><p>Imports a graph recorded in a file using the Tulip binary "
128 "format.</p>",
129 "1.2", "File")
130
131 TLPBImport(tlp::PluginContext *context);
132 ~TLPBImport() override {}
133
134 std::string icon() const override {
135 return ":/tulip/gui/icons/tlpb32x32.png";
136 }
137
138 std::list<std::string> fileExtensions() const override {
139 std::list<std::string> l;
140 l.push_back("tlpb");
141 return l;
142 }
143
144 std::list<std::string> gzipFileExtensions() const override {
145 std::list<std::string> ext;
146 ext.push_back("tlpb.gz");
147 ext.push_back("tlpbz");
148 return ext;
149 }
150
151 bool importGraph() override;
152};
153
154/*@}*/
155
156// Don't ask why it is David favorite 9 digit number.
157#define TLPB_MAGIC_NUMBER 578374683
158#define TLPB_MAJOR 1
159#define TLPB_MINOR 2
160
161// structures used in both tlpb import/export plugins
162struct TLPBHeader {
163 unsigned int magicNumber;
164 unsigned char major;
165 unsigned char minor;
166 unsigned int numNodes;
167 unsigned int numEdges;
168
169 TLPBHeader(unsigned int nbN = 0, unsigned int nbE = 0)
170 : magicNumber(TLPB_MAGIC_NUMBER), major(TLPB_MAJOR), minor(TLPB_MINOR), numNodes(nbN),
171 numEdges(nbE) {}
172
173 bool checkCompatibility() {
174 return ((magicNumber == TLPB_MAGIC_NUMBER) && (major == TLPB_MAJOR) && (minor <= TLPB_MINOR));
175 }
176};
177
178#define MAX_EDGES_TO_WRITE 64000
179#define MAX_EDGES_TO_READ MAX_EDGES_TO_WRITE
180#define MAX_RANGES_TO_WRITE MAX_EDGES_TO_WRITE
181#define MAX_RANGES_TO_READ MAX_RANGES_TO_WRITE
182#define MAX_VALUES_TO_WRITE MAX_EDGES_TO_WRITE
183#define MAX_VALUES_TO_READ MAX_VALUES_TO_WRITE
184
185#endif // TLPBIMPORTEXPORT_H
186///@endcond
Contains runtime parameters for a plugin.
Definition: PluginContext.h:42
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.
bool exportGraph(Graph *graph, std::ostream &outputStream, const std::string &format, DataSet &dataSet, PluginProgress *progress=nullptr)
Exports a graph using the specified export plugin with parameters stored in the DataSet.
#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
The edge struct represents an edge in a Graph object.
Definition: Edge.h:40
The node struct represents a node in a Graph object.
Definition: Node.h:40