Tulip  4.6.1
Better Visualization Through Research
 All Classes Namespaces 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 
20 /**
21  *
22  * This file is part of Tulip (www.tulip-software.org)
23  *
24  * Authors: David Auber and the Tulip development Team
25  * from LaBRI, University of Bordeaux
26  *
27  * Tulip is free software; you can redistribute it and/or modify
28  * it under the terms of the GNU Lesser General Public License
29  * as published by the Free Software Foundation, either version 3
30  * of the License, or (at your option) any later version.
31  *
32  * Tulip is distributed in the hope that it will be useful,
33  * but WITHOUT ANY WARRANTY; without even the implied warranty of
34  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
35  * See the GNU General Public License for more details.
36  *
37  */
38 #ifndef TLPBIMPORTEXPORT_H
39 #define TLPBIMPORTEXPORT_H
40 
41 #include <iostream>
42 #include <tulip/TulipPluginHeaders.h>
43 #include <tulip/ExportModule.h>
44 #include <tulip/ImportModule.h>
45 
46 // some compilation environments define major and minor as preprocessor macros
47 // undefine them in that case
48 #ifdef major
49 #undef major
50 #endif
51 
52 #ifdef minor
53 #undef minor
54 #endif
55 
56 /**
57  * The plugins below export/import a Tulip graph
58  * using the following binary format:
59  * format header = <magic_number, major, minor> (uint16 + uint8 +uint8)
60  * nb_nodes = uint32
61  * nb_edges = uint32
62  * edges = nb_edges * <source, target> (uint32+uint32)
63  * nb_subgraphs = uint32
64  * subgraphs = nb_subgraphs * <subgraph_id, parent_graph_id, nodes_desc, edges_desc>
65  * nodes_desc = nb_nodes_intervals * <first_node, last_node>
66  * edges_desc = nb_edges_intervals *<first_edge, last_edge>
67  * nb_properties = uint32
68  * properties = <prop_name, graph_id, type, default_node_val, default_edge_val, nodes_val, edges_val>
69  * prop_name = length + utf8 text
70  * graph_id = uint32
71  * type = length + utf8 text
72  * default_node_val = type dependant (method readb)
73  * default_edge_val = type dependant (method readb)
74  * nb_nodes_val = uint32
75  * nodes_val = nb_nodes_val * <node, node_val> (uint32 + type dependant)
76  * nb_edges_val = uint32
77  * edges_val = nb_edges_val * <edge, edge_val> (uint32 + type dependant)
78  * graph_attributes = (nb_subgraphs + 1) * <graph_id, graph_attributes_list>*
79  */
80 
81 /*@{*/
82 /// Export plugin for TLPB format
83 /**
84  *
85  * \brief This plugin saves a Tulip graph using a binary format
86  *
87  */
88 class TLPBExport: public tlp::ExportModule {
89 public:
90 
91  PLUGININFORMATION("TLPB Export", "David Auber, Patrick Mary","13/07/2012","Saves a graph in Tulip binary format","1.0","File")
92 
93  std::string fileExtension() const {
94  return "tlpb";
95  }
96 
97  TLPBExport(const tlp::PluginContext *context) :ExportModule(context) {}
98  ~TLPBExport() {}
99 
100  bool exportGraph(std::ostream &);
101 
102  std::string icon() const {
103  return ":/tulip/gui/icons/tlpb32x32.png";
104  }
105 
106  tlp::MutableContainer<tlp::node> nodeIndex;
107  tlp::MutableContainer<tlp::edge> edgeIndex;
108 
109  tlp::node getNode(tlp::node n) {
110  return nodeIndex.get(n.id);
111  }
112 
113  tlp::edge getEdge(tlp::edge e) {
114  return edgeIndex.get(e.id);
115  }
116 
117  void getSubGraphs(tlp::Graph*, std::vector<tlp::Graph*>&);
118 
119  void writeAttributes(std::ostream&, tlp::Graph*);
120 };
121 
122 /// Import plugin for TLPB format
123 /**
124  *
125  * \brief This plugin reads a Tulip graph using a binary format
126  *
127  */
128 class TLPBImport:public tlp::ImportModule {
129 public:
130  PLUGININFORMATION("TLPB Import", "David Auber, Patrick Mary", "13/07/2012",
131  "Reads a graph in Tulip binary format", "1.0", "File")
132 
133  TLPBImport(tlp::PluginContext* context);
134  ~TLPBImport() {}
135 
136  std::string icon() const {
137  return ":/tulip/gui/icons/tlpb32x32.png";
138  }
139 
140  std::list<std::string> fileExtensions() const {
141  return std::list<std::string>(1, "tlpb");
142  }
143 
144  bool importGraph();
145 };
146 
147 /*@}*/
148 
149 //Don't ask why it is David favorite 9 digit number.
150 #define TLPB_MAGIC_NUMBER 578374683
151 #define TLPB_MAJOR 1
152 #define TLPB_MINOR 0
153 
154 // structures used in both tlpb import/export plugins
155 struct TLPBHeader {
156  unsigned int magicNumber;
157  unsigned char major;
158  unsigned char minor;
159  unsigned int numNodes;
160  unsigned int numEdges;
161 
162  TLPBHeader(unsigned int nbN = 0, unsigned int nbE = 0)
163  : magicNumber(TLPB_MAGIC_NUMBER), major(TLPB_MAJOR), minor(TLPB_MINOR), numNodes(nbN), numEdges(nbE) {}
164 
165  bool checkCompatibility() {
166  return ((magicNumber == TLPB_MAGIC_NUMBER) &&
167  (major == TLPB_MAJOR) &&
168  (minor <= TLPB_MINOR));
169  }
170 };
171 
172 #define MAX_EDGES_TO_WRITE 64000
173 #define MAX_EDGES_TO_READ MAX_EDGES_TO_WRITE
174 #define MAX_RANGES_TO_WRITE MAX_EDGES_TO_WRITE
175 #define MAX_RANGES_TO_READ MAX_RANGES_TO_WRITE
176 #define MAX_VALUES_TO_WRITE MAX_EDGES_TO_WRITE
177 #define MAX_VALUES_TO_READ MAX_VALUES_TO_WRITE
178 
179 #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