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