Tulip  5.1.0
Large graphs analysis and drawing
Graph.h
1 /*
2  *
3  * This file is part of Tulip (http://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 
20 #ifndef Tulip_SUPERGRAPH_H
21 #define Tulip_SUPERGRAPH_H
22 
23 #include <iostream>
24 #include <set>
25 #include <string>
26 #include <vector>
27 
28 #include <climits>
29 #include <tulip/tulipconf.h>
30 #include <tulip/DataSet.h>
31 #include <tulip/Node.h>
32 #include <tulip/Edge.h>
33 #include <tulip/Observable.h>
34 
35 namespace tlp {
36 
37 class PropertyInterface;
38 class BooleanProperty;
39 class PluginProgress;
40 template<class C>struct Iterator;
41 
42 /**
43  * @enum This Enum describes the possible types of an element of the graph.
44  *
45  * It is used in functions that can return an edge or a node, to distinguish between the two cases.
46  **/
48  /** This element describes a node **/
49  NODE = 0,
50  /** This element describes an edge **/
51  EDGE = 1
52 };
53 
54 /**
55  * @ingroup Graph
56  * @brief Loads a graph from a file (extension can be any of the Tulip supported input graph file format).
57  *
58  * This function loads a graph serialized in a file trough the available Tulip import plugins.
59  * Since Tulip 4.8, the selection of the import plugin is based on the provided filename extension.
60  * The import will fail if the selected import plugin is not loaded.
61  * The graph file formats that can currently be imported are : TLP (*.tlp, *.tlp.gz, *.tlpz), TLP Binary (*.tlpb, *.tlpb.gz, *.tlpbz), TLP JSON (*.json),
62  * Gephi (*.gexf), Pajek (*.net, *.paj), GML (*.gml), Graphviz (*.dot) and UCINET (*.txt)
63  *
64  * Before Tulip 4.8 and as a fallback, the function uses the "TLP Import" import plugin
65  * (always loaded as it is linked into the tulip-core library).
66  *
67  * If the import fails (no such file, parse error, ...) NULL is returned.
68  *
69  * @param filename the file in one of the supported formats to parse.
70  * @return Graph* the imported Graph, NULL if the import failed.
71  **/
72 TLP_SCOPE Graph * loadGraph(const std::string &filename, tlp::PluginProgress* progress = NULL);
73 
74 /**
75  * @ingroup Graph
76  * @brief Saves the corresponding graph to a file (extension can be any of the Tulip supported ouput graph file format)..
77  *
78  * This function serializes the corresponding graph and all its subgraphs (depending on the format) to a file
79  * through the available Tulip export plugins.
80  * Since Tulip 4.8, the selection of the export plugin is based on the provided filename extension.
81  * The export will fail if the selected export plugin is not loaded.
82  *
83  * Before Tulip 4.8 and as a fallback, this function uses the "TLP Export" export plugin
84  * (always loaded as it is linked into the tulip-core library).
85  *
86  * @param graph the graph to save.
87  * @param filename the file to save the graph to.
88  * @param progress PluginProgress to report the progress of the operation, as well as final state. Defaults to NULL.
89  * @param data Parameters to pass to the export plugin (e.g. additional data, options for the format)
90  * @return bool whether the export was successfull or not.
91  **/
92 TLP_SCOPE bool saveGraph(Graph* graph, const std::string &filename, tlp::PluginProgress* progress = NULL, tlp::DataSet *data = NULL);
93 
94 /**
95  * @ingroup Graph
96  * @brief Exports a graph using the specified export plugin with parameters stored in the DataSet.
97  *
98  * You determine the destination, whether by using a fstream, or by saving the contents of the stream to the destination of your choice.
99  *
100  * @param graph The graph to export.
101  * @param outputStream The stream to export to. Can be a standard ostream, an ofstream, or even a gzipped ostream.
102  * @param format The format to use to export the Graph.
103  * @param dataSet Parameters to pass to the export plugin (e.g. additional data, options for the format)
104  * @param progress A PluginProgress to report the progress of the operation, as well as final state. Defaults to NULL.
105  * @return bool Whether the export was successfull or not.
106  **/
107 TLP_SCOPE bool exportGraph(Graph *graph, std::ostream &outputStream, const std::string &format, DataSet &dataSet, PluginProgress *progress=NULL);
108 
109 /**
110  * @ingroup Graph
111  * @brief Imports a graph using the specified import plugin with the parameters stored in the DataSet.
112  *
113  * If no graph is passed, then a new graph will be created. You can pass a graph in order to import data into it.
114  * Returns the graph with imported data, or NULL if the import failed. In this case, the Pluginprogress should have an error that can be displayed.
115  *
116  * @param format The format to use to import the graph.
117  * @param dataSet The parameters to pass to the import plugin (file to read, ...)
118  * @param progress A PluginProgress to report the progress of the operation, as well as final state. Defaults to NULL.
119  * @param newGraph The graph to import the data into. This can be useful to import data into a subgraph. Defaults to NULL.
120  * @return :Graph* The graph containing the imported data, or NULL in case of failure.
121  **/
122 TLP_SCOPE Graph* importGraph(const std::string &format, DataSet &dataSet, PluginProgress *progress=NULL,Graph *newGraph=NULL);
123 
124 /**
125  * @ingroup Graph
126  * @brief Creates a new, empty graph.
127  *
128  * This is a simple method factory to create a Graph implementation (remember, Graph is only an interface).
129  *
130  * This is the recommended way to create a new Graph.
131  *
132  * @return :Graph* A new, empty graph.
133  **/
134 TLP_SCOPE Graph* newGraph();
135 
136 /**
137  * @ingroup Graph
138  * Appends the selected part of the graph inG (properties, nodes and edges) into the graph outG.
139  * If no selection is done (inSel=NULL), the whole inG graph is appended.
140  * The output selection is used to select the appended nodes & edges
141  * \warning The input selection is extended to all selected edge ends.
142  */
143 TLP_SCOPE void copyToGraph(Graph *outG, const Graph *inG, BooleanProperty* inSelection=NULL, BooleanProperty* outSelection=NULL );
144 
145 /**
146  * @ingroup Graph
147  * Removes the selected part of the graph ioG (properties values, nodes and edges).
148  * If no selection is done (inSel=NULL), the whole graph is reseted to default value.
149  * \warning The selection is extended to all selected edge ends.
150  */
151 TLP_SCOPE void removeFromGraph(Graph * ioG, BooleanProperty* inSelection=NULL);
152 
153 
154 /**
155  * @ingroup Graph
156  * Gets an iterator over the root graphs. That is all the currently existing graphs which have been created using the tlp::newGraph, tlp::loadGraph or tlp::importGraph functions and are the root graphs of an existing graph hierarchy.
157  * @return An iterator over all the root graphs. The caller of this function is responsible of the deletion of the returned iterator.
158  */
159 TLP_SCOPE Iterator<Graph*>* getRootGraphs();
160 
161 /**
162  * @ingroup Graph
163  * The class Graph is the interface of a Graph in the Tulip Library.
164  *
165  * There are a few principles to know when working with a Tulip Graph.
166  *
167  * @chapter Directed
168  * Every edge is directed in a Tulip Graph.
169  * You can choose to ignore this, but every edge has a source and destination.
170  *
171  * @chapter Inheritance
172  *
173  * Subgraphs inherit from their parent graph.
174  * This is true of nodes and edges; every node and edge in a subgraph also exists in each of its parent graphs.
175  * This is also true of properties; every property in a graph exist in all of its subgraphs, except if it has been replaced
176  * by a local property.
177  *
178  * For instance, if you have the following graph hierarchy:
179  * root
180  * / \
181  * A B
182  *
183  * Every node in A is in root, and every node in B is in root.
184  * Nodes can be in A and root but not B; or in B and root but not A.
185  *
186  * For instance, imagine a graph. You want to compare it to its Delaunay triangulation.
187  * You need to create a subgraph that is a clone of the original (say this is A) to keep the original graph,
188  * and another copy (say this one is B) on which you will perform the delaunay triangulation.
189  *
190  * B will have none of the original edges, and A will have only the original edges.
191  *
192  * As for properties; let's imagine the same graph hierarchy.
193  * You want to compare two different layouts on the same graph.
194  * You need to create two clone subgraphs, on each you make the 'viewLayout' property local.
195  * This results in A and B having different values for the layout, but everything else in common.
196  * You then can apply two different algorithms on A and B (e.g. Bubble Tree and Tree Radial).
197  *
198  * @chapter Meta Nodes
199  * A meta node is a node representing a subgraph of the current graph.
200  *
201  * @chapter Undo Redo
202  * The Tulip Graph object supports for undo and redo of modifications.
203  *The operations affect the whole graph hierarchy, and cannot be limited to a subgraph.
204  *
205  */
206 class TLP_SCOPE Graph : public Observable {
207 
208  friend class GraphAbstract;
209  friend class GraphUpdatesRecorder;
210  friend class GraphDecorator;
211  friend class PropertyManager;
212  friend class PropertyInterface;
213 
214 public:
215  Graph():id(0) {}
216  virtual ~Graph() {}
217 
218  /**
219  * @brief Applies an algorithm plugin, identified by its name.
220  * Algorithm plugins are subclasses of the tlp::Algorithm interface.
221  * Parameters are transmitted to the algorithm trough the DataSet.
222  * To determine a plugin's parameters, you can either:
223  *
224  * * refer to its documentation
225  *
226  * * use buildDefaultDataSet on the plugin object if you have an instance of it
227  *
228  * * call getPluginParameters() with the name of the plugin on the PluginLister
229  *
230  *
231  * If an error occurs, a message describing the error should be stored in errorMessage.
232  *
233  * @param algorithm The algorithm to apply.
234  * @param errorMessage A string that will be modified to contain an error message should an error occur.
235  * @param dataSet The parameters to the algorithm. Defaults to NULL.
236  * @param progress A PluginProgress to report the progress of the operation, as well as final state. Defaults to NULL.
237  * @return bool Whether the algorithm was successfully applied.
238  **/
239  bool applyAlgorithm(const std::string &algorithm, std::string &errorMessage, DataSet *dataSet=NULL, PluginProgress *progress=NULL);
240 
241  //=========================================================================
242  // Graph hierarchy access and building
243  //=========================================================================
244 
245  /**
246  * @brief Removes all nodes, edges and sub-graphs from this graph.
247  *
248  * Contrarily to creating a new Graph, this keeps attributes and properties.
249  *
250  * @return void
251  **/
252  virtual void clear()=0;
253 
254  /**
255  * @brief Creates and returns a new sub-graph of this graph.
256  *
257  * If a BooleanProperty is provided, only nodes and edges for which it is true will be added to the subgraph.
258  * If none is provided, then the subgraph will be empty.
259  *
260  * @param selection The elements to add to the new subgraph. Defaults to NULL.
261  * @param name The name of the newly created subgraph. Defaults to "unnamed".
262  * @return :Graph* The newly created subgraph.
263  **/
264  virtual Graph *addSubGraph(BooleanProperty *selection=NULL,
265  const std::string& name = "unnamed")=0;
266 
267  /**
268  * @brief Creates and returns a new named sub-graph of this graph.
269  *
270  * @param name The name of the newly created subgraph.
271  * @return :Graph* The newly created subgraph.
272  **/
273  Graph *addSubGraph(const std::string& name);
274 
275  /**
276  * @brief Creates and returns a subgraph that contains all the elements of this graph.
277  *
278  * @param name The name of the newly created subgraph. Defaults to "unnamed".
279  * @param addSibling if true the clone subgraph will be a sibling of this graph, if false (the default) it will be a subgraph of this graph
280  * @param addSiblingProperties if true the local properties will be cloned into the sibling of this graph, if false (the default) the local properties will not be cloned
281  * @return :Graph* The newly created clone subgraph. NULL will be returned if addSibling is set to true and this graph is a root graph.
282  **/
283  virtual Graph* addCloneSubGraph(const std::string& name = "unnamed", bool addSibling = false, bool addSiblingProperties = false);
284 
285  /**
286  * @brief Creates and returns a new sub-graph of the graph induced by a vector of nodes.
287  * @since Tulip 5.0
288  * Every node contained in the given vector is added to the subgraph.
289  * Every edge connecting any two nodes in the set of given nodes is also added.
290  * @param nodes The nodes to add to the subgraph. All the edges between these nodes are added too.
291  * @param parentSubGraph If provided, is used as parent graph for the newly created subgraph instead of the graph this method is called on.
292  * @param name The name of the newly created subgraph.
293  * @return The newly created subgraph.
294  */
295  Graph *inducedSubGraph(const std::vector<node>& nodes,
296  Graph* parentSubGraph = NULL,
297  const std::string& name = "unnamed");
298 
299  /**
300  * @brief deprecated, use inducedSubGraph(const std::set<node>&, Graph* = NULL, const std::string& = "unamed") instead
301  */
302  _DEPRECATED Graph *inducedSubGraph(const std::set<node>& nodeSet,
303  Graph* parentSubGraph = NULL,
304  const std::string& name = "unnamed");
305 
306  /**
307  * @brief Creates and returns a new sub-graph of the graph induced by a selection of nodes and edges.
308  * @since Tulip 4.10
309  * Every node contained in the selection is added to the subgraph.
310  * Every edge and its source and target node contained in the selection is added to the subgraph.
311  * Every edge connecting any two nodes in the resulting set of nodes is also added.
312  * @param selection a selection of nodes and edges.
313  * @param parentSubGraph If provided, is used as parent graph for the newly created subgraph instead of the graph this method is called on.
314  * @param name The name of the newly created subgraph.
315  * @return The newly created subgraph.
316  */
317  Graph *inducedSubGraph(BooleanProperty *selection,
318  Graph* parentSubGraph = NULL, const std::string& name = "unnamed");
319 
320  /**
321  * @brief Deletes a sub-graph of this graph.
322  * All subgraphs of the removed graph are re-parented to this graph.
323  * For instance, with a graph hierarchy as follows :
324  * root
325  * / \
326  * A B
327  * /|\
328  * C D E
329  *
330  * @code root->delSubGraph(B);
331  * would result in the following hierarchy:
332  * root
333  * / | \\
334  * A C D E
335  *
336  * @param graph The subgraph to delete.
337  *
338  * @see delAllSubGraphs() if you want to remove all descendants of a graph.
339  */
340  virtual void delSubGraph(Graph *graph)=0;
341 
342  /**
343  * @brief Deletes a sub-graph of this graph and all of its sub-graphs.
344  ** For instance, with a graph hierarchy as follows :
345  * root
346  * / \
347  * A B
348  * /|\
349  * C D E
350  *
351  * @codeline root->delSubGraph(B); @endcode
352  * would result in the following hierarchy:
353  * root
354  * |
355  * A
356  *
357  * @param graph The subgraph to delete.
358  * @see delSubGraph() if you want to keep the descendants of the subgraph to remove.
359  */
360  virtual void delAllSubGraphs(Graph *graph)=0;
361 
362  /**
363  * @brief Returns the parent of the graph. If called on the root graph, it returns itself.
364  * @return The parent of this graph (or itself if it is the root graph).
365  * @see getRoot() to directly retrieve the root graph.
366  */
367  virtual Graph* getSuperGraph()const =0;
368 
369  /**
370  * @brief Gets the root graph of the graph hierarchy.
371  * @return The root graph of the graph hierarchy.
372  */
373  virtual Graph* getRoot() const =0;
374 
375  /**
376  * @cond DOXYGEN_HIDDEN
377  * @brief Sets the parent of a graph.
378  * @warning ONLY USE IF YOU KNOW EXACTLY WHAT YOU ARE DOING.
379  * @endcond
380  */
381  virtual void setSuperGraph(Graph *)=0;
382 
383  /**
384  * @brief Gets an iterator over all the sub-graphs of the graph.
385  * For instance, in the following graph hierarchy:
386  ** root
387  * / \
388  * A B
389  * /|\
390  * C D E
391  *
392  * @codeline root->getSubGraphs(); @endcode
393  * Will return an iterator over A and B, but not C, D and E.
394  * @return An iterator over this graph's direct subgraphs.
395  */
396  virtual Iterator<Graph *> * getSubGraphs() const=0;
397 
398  /**
399  * @brief This method returns the nth subgraph.
400  * Since subgraphs order cannot be ensured in every implementation, this method should be equivalent to:
401  * @code
402  int i=0;
403  Iterator<Graph *> *it = g->getSubGraphs();
404  while (it->hasNext()) {
405  Graph *result = it->next();
406  if (i++ == n) {
407  delete it;
408  return result;
409  }
410  }
411  delete it;
412  return NULL;
413  * @endcode
414  * @param n the index of the subgraph to retrieve.
415  * @return The n-th subgraph.
416  */
417  virtual Graph *getNthSubGraph(unsigned int n) const;
418 
419  /**
420  * @brief Return the number of direct sub-graphs.
421  * For instance, in the following graph hierarchy:
422  * root
423  * / \
424  * A B
425  * /|\
426  * C D E
427  *
428  * @codeline root->numberOfSubGraphs(); @endcode
429  * Will return 2.
430  * @return The number of direct subgraphs.
431  * @see numberOfDescendantGraphs() to count in the whole hierarchy.
432  */
433  virtual unsigned int numberOfSubGraphs() const=0;
434 
435  /**
436  * @brief Return the number of descendant sub-graphs.
437  * For instance, in the following graph hierarchy:
438  * root
439  * / \
440  * A B
441  * /|\
442  * C D E
443  *
444  * @codeline root->numberOfSubGraphs(); @endcode
445  * Will return 5.
446  * @return The number of descendants subgraphs.
447  * @see numberOfSubGraphs() to count only direct subgraphs.
448  */
449  virtual unsigned int numberOfDescendantGraphs() const=0;
450 
451  /**
452  * @brief Indicates if the graph argument is a direct sub-graph.
453  * @param subGraph The graph to check is a subgraph of this graph.
454  * @return Whether subGraph is a direct subgraph of this graph.
455  * @see isDescendantGraph() to search in the whole hierarchy.
456  */
457  virtual bool isSubGraph(const Graph* subGraph) const=0;
458 
459  /**
460  * @brief Indicates if the graph argument is a descendant of this graph.
461  * @param subGraph The graph to check is a descendant of this graph.
462  * @return Whether subGraph is a descendant of this graph.
463  * @see isSubGraph to search only in direct subgraphs.
464  */
465  virtual bool isDescendantGraph(const Graph* subGraph) const=0;
466 
467  /**
468  * @brief Returns a pointer on the sub-graph with the corresponding id
469  * or NULL if there is no sub-graph with that id.
470  * @param id The id of the subgraph to retrieve.
471  * @return A subgraph of the given id, or null if no such subgraph exists on this graph.
472  * @see getDescendantGraph(unsigned int) to search in the whole hierarchy.
473  */
474  virtual Graph* getSubGraph(unsigned int id) const=0;
475 
476  /**
477  * @brief Returns a pointer on the sub-graph with the corresponding name
478  * or NULL if there is no sub-graph with that name.
479  * @param name The name of the subgraph to retrieve.
480  * @return A Graph named name, or NULL if no such subgraph exists on this graph.
481  * @see getDescendantGraph(const std::string &) to search in the whole hierarchy.
482  */
483  virtual Graph* getSubGraph(const std::string &name) const=0;
484 
485  /**
486  * @brief Returns a pointer on the descendant with the corresponding id
487  * or NULL if there is no descendant with that id.
488  * @param id The id of the descendant graph to retrieve.
489  * @return A graph with the given id, or NULL if no such graph exists in this graph's descendants.
490  * @see getSubGraph(unsigned int) to search only in direct subgraphs.
491  */
492  virtual Graph* getDescendantGraph(unsigned int id) const=0;
493 
494  /**
495  * @brief Returns a pointer on the first descendant graph with the corresponding name
496  * or NULL if there is no descendant graph with that name.
497  * @param name The name of the descendant graph to look for.
498  * @return A graph named name, or NULL if there is no such graph in this graph's descendants.
499  * @see getSubGraph(const std::string &) to search only in direct subgraphs.
500  */
501  virtual Graph* getDescendantGraph(const std::string &name) const=0;
502 
503  /**
504  * @brief Gets an iterator over all the descendant sub-graphs of the graph.
505  * For instance, in the following graph hierarchy:
506  ** root
507  * / \
508  * A B
509  * /|\
510  * C D E
511  *
512  * @codeline root->getSubGraphs(); @endcode
513  * Will return an iterator over A B, C, D and E.
514  * @return An iterator over this graph's descendant subgraphs.
515  */
516  Iterator<Graph *> * getDescendantGraphs() const;
517 
518  //==============================================================================
519  // Modification of the graph structure
520  //==============================================================================
521  /**
522  * @brief Adds a new node in the graph and returns it. This node is also added in all
523  * the ancestor graphs.
524  * @return The newly added node.
525  * @see addNodes() if you want to add more than one node.
526  */
527  virtual node addNode()=0;
528 
529  /**
530  * @brief Adds new nodes in the graph.
531  * The new nodes are also added in all the ancestor graphs.
532  *
533  * @param nbNodes The number of nodes to add.
534  * @see addNode() to add a single node.
535  */
536  virtual void addNodes(unsigned int nbNodes)=0;
537 
538  /**
539  * @brief Adds new nodes in the graph and returns them in the addedNodes vector.
540  * The new nodes are also added in all the ancestor graphs.
541  *
542  * @param nbNodes The number of nodes to add.
543  * @param addedNodes The newly added nodes. This vector is cleared before being filled.
544  * @see addNode() to add a single node.
545  */
546  virtual void addNodes(unsigned int nbNodes, std::vector<node>& addedNodes)=0;
547 
548  /**
549  * @brief Adds an existing node in the graph. This node is also added in all the ancestor graphs.
550  * This node must exists in the graph hierarchy (which means it must exist in the root graph).
551  * You cannot add a node to the root graph this way (as it must already be an element of the root graph).
552  * @warning Using this method on the root graph will display a warning on the console.
553  *
554  * @param n The node to add to a subgraph. This node must exist in the root graph.
555  * @see addNode() to add a new node to a graph.
556  */
557  virtual void addNode(const node n)=0;
558 
559  /**
560  * @brief Adds existing nodes in the graph. The nodes are also added in all the ancestor graphs.
561  * as with addNode(const tlp::node), the nodes must exist in the graph hierarchy and thus exist in the root graph,
562  * and node cannot be added this way to the root graph.
563 
564  * @warning Using this method on the root graph will display a warning on the console.
565  * @warning The graph does not take ownership of the Iterator.
566  *
567  * @param nodes An iterator over nodes to add to this subgraph. The graph does not takes ownership of this iterator.
568  */
569  virtual void addNodes(Iterator<node>* nodes)=0;
570 
571  /**
572  * @brief Adds existing nodes in the graph. The nodes are also added in all the ancestor graphs.
573  * as with addNode(const tlp::node), the nodes must exist in the graph hierarchy and thus exist in the root graph,
574  * and nodes cannot be added this way to the root graph.
575 
576  * @warning Using this method on the root graph will display a warning on the console.
577  *
578  * @param nodes a vector of nodes to add to this subgraph.
579  */
580  void addNodes(const std::vector<node>& nodes);
581 
582  /**
583  * @brief Deletes a node in the graph.
584  * This node is also removed in the sub-graphs hierarchy of the current graph.
585  * @param n The node to delete.
586  * @param deleteInAllGraphs Whether to delete in all its parent graphs or only in this graph. By default only removes in the current graph.
587  * @see delNodes() to remove multiple nodes.
588  */
589  virtual void delNode(const node n, bool deleteInAllGraphs = false)=0;
590 
591  /**
592  * @brief Deletes nodes in the graph.
593  * These nodes are also removed in the sub-graphs hierarchy of the current graph.
594  * @warning the graph does not take ownership of the Iterator.
595  * @param it The nodes to delete.
596  * @param deleteInAllGraphs Whether to delete in all its parent graphs or only in this graph. By default only removes in the current graph.
597  * @see delNode() to remove a single node.
598  */
599  virtual void delNodes(Iterator<node>* it, bool deleteInAllGraphs = false)=0;
600 
601  /**
602  * @brief Deletes nodes in the graph.
603  * These nodes are also removed in the sub-graphs hierarchy of the current graph.
604  * @warning the graph does not take ownership of the Iterator.
605  * @param nodes a vector of the nodes to delete.
606  * @param deleteInAllGraphs Whether to delete in all its parent graphs or only in this graph. By default only removes in the current graph.
607  * @see delNode() to remove a single node.
608  */
609  void delNodes(const std::vector<node>& nodes, bool deleteInAllGraphs = false);
610 
611  /**
612  * @brief Adds a new edge in the graph
613  * This edge is also added in all the super-graph of the graph.
614  * @param source The source of the edge.
615  * @param target The target of the edge.
616  * @return The newly added edge.
617  * @see addEdges() to add multiple edges at once.
618  */
619  virtual edge addEdge(const node source, const node target)=0;
620 
621  /**
622  * @brief Adds new edges in the graph.
623  * The new edges are also added in all graph ancestors.
624  *
625  * @warning If the edges vector contains a node that does not belong to this graph,
626  * undefined behavior will ensue.
627  * @param edges A vector describing between which nodes to add edges.
628  * The first element of the pair is the source, the second is the destination.
629  *
630  */
631  virtual void addEdges(const std::vector<std::pair<node, node> >& edges)=0;
632 
633  /**
634  * @brief Adds new edges in the graph and returns them in the addedEdges vector.
635  * The new edges are also added in all graph ancestors.
636  *
637  * @warning If the edges vector contains a node that does not belong to this graph,
638  * undefined behavior will ensue.
639  * @param edges A vector describing between which nodes to add edges.
640  * The first element of the pair is the source, the second is the destination.
641  * @param addedEdges The newly added edges. This vector is cleared before being filled.
642  *
643  */
644  virtual void addEdges(const std::vector<std::pair<node, node> >& edges,
645  std::vector<edge>& addedEdges)=0;
646 
647  /**
648  * @brief Adds an existing edge in the graph. This edge is also added in all
649  * the ancestor graphs.
650  * The edge must be an element of the graph hierarchy, thus it must be
651  * an element of the root graph.
652  * @warning Using this method on the root graph will display a warning on the console.
653  * @param e The edge to add to this subgraph.
654  * @see addEgdes() to add more than one edge at once.
655  * @see addNode() to add nodes.
656  */
657  virtual void addEdge(const edge e)=0;
658 
659  /**
660  * @brief Adds existing edges in the graph. The edges are also added in all
661  * the ancestor graphs.
662  * The added edges must be elements of the graph hierarchy,
663  * thus they must be elements of the root graph.
664  * @warning Using this method on the root graph will display a warning on the console.
665  * @warning The graph does not take ownership of the iterator.
666  * @param edges The edges to add on this subgraph.
667  */
668  virtual void addEdges(Iterator<edge>* edges)=0;
669 
670  /**
671  * @brief Adds existing edges in the graph. The edges are also added in all
672  * the ancestor graphs.
673  * The added edges must be elements of the graph hierarchy,
674  * thus they must be elements of the root graph.
675  * @warning Using this method on the root graph will display a warning on the console.
676  * @param edges a vector of the edges to add on this subgraph.
677  */
678  void addEdges(const std::vector<edge>& edges);
679 
680  /**
681  * @brief Deletes an edge in the graph. The edge is also removed in
682  * the sub-graphs hierarchy.
683  * The ordering of remaining edges is preserved.
684  * @param e The edge to delete.
685  * @param deleteInAllGraphs Whether to delete in all its parent graphs or only in this graph. By default only removes in the current graph.
686  */
687  virtual void delEdge(const edge e, bool deleteInAllGraphs = false)=0;
688 
689  /**
690  * @brief Deletes edges in the graph. These edges are also removed in the sub-graphs hierarchy.
691  * The ordering of remaining edges is preserved.
692  * @warning The graph does not take ownership of the Iterator.
693  * @param itE
694  * @param deleteInAllGraphs Whether to delete in all its parent graphs or only in this graph. By default only removes in the current graph.
695  */
696  virtual void delEdges(Iterator<edge>* itE, bool deleteInAllGraphs = false)=0;
697 
698  /**
699  * @brief Deletes edges in the graph. These edges are also removed in the sub-graphs hierarchy.
700  * The ordering of remaining edges is preserved.
701  * @warning The graph does not take ownership of the Iterator.
702  * @param edges a vector of the edges to delete
703  * @param deleteInAllGraphs Whether to delete in all its parent graphs or only in this graph. By default only removes in the current graph.
704  */
705  void delEdges(const std::vector<edge>& edges, bool deleteInAllGraphs = false);
706 
707  /**
708  * @brief Sets the order of the edges around a node.
709  * This operation ensures that adjacent edges of a node will
710  * be ordered as they are in the vector of edges given in parameter.
711  *
712  * This can be useful if you want to make sure you retrieve the edges in a specific order when iterating upon them.
713  * @param n The node whose edges to order.
714  * @param edges The edges, in the order you want them.
715  */
716  virtual void setEdgeOrder(const node n,const std::vector<edge> &edges)=0;
717 
718  /**
719  * @brief Swaps two edges in the adjacency list of a node.
720  * @param n The node on whoch to swap the edges order.
721  * @param e1 The first edge, that will take the second edge's position.
722  * @param e2 The second edge, that will take the first edge's position.
723  */
724  virtual void swapEdgeOrder(const node n,const edge e1, const edge e2)=0;
725 
726  /**
727  * @brief Sets the source of an edge to be the given node.
728  * @param e The edge to change the source of.
729  * @param source The new source of the edge.
730  */
731  virtual void setSource(const edge e, const node source) = 0;
732 
733  /**
734  * @brief Sets the target of an edge to be the given node.
735  * @param e The edge to change the target of.
736  * @param target The new target of the edge.
737  */
738  virtual void setTarget(const edge e, const node target) = 0;
739 
740  /**
741  * @brief Sets both the source and the target of an edge.
742  * @param e The edge to set the source and target of.
743  * @param source The new source of the edge.
744  * @param target The new target of the edge.
745  */
746  virtual void setEnds(const edge e, const node source, const node target) = 0;
747 
748  /**
749  * @brief Reverses the direction of an edge, the source becomes the target and the target
750  * becomes the source.
751  * @warning The ordering is global to the entire graph hierarchy. Thus, by changing
752  * the ordering of a graph you change the ordering of the hierarchy.
753  * @param e The edge top reverse.
754  */
755  virtual void reverse(const edge e)=0;
756  // Attempts to reserve enough space to store nodes.
757  // Only defined on root graph.
758  virtual void reserveNodes(unsigned int nbNodes) = 0;
759  // Attempts to reserve enough space to store edges.
760  // Only defined on root graph.
761  virtual void reserveEdges(unsigned int nbEdges) = 0;
762  //================================================================================
763  //Iterators on the graph structure.
764  //================================================================================
765  /**
766  * @brief Finds the first node whose input degree equals 0.
767  *
768  * @return tlp::node The first encountered node with input degree of 0, or an invalid node if none was found.
769  **/
770  virtual tlp::node getSource() const;
771 
772  /**
773  * @brief Finds the first node whose output degree equals 0.
774  *
775  * @return tlp::node The first encountered node with output degree of 0, or an invalid node if none was found.
776  **/
777  virtual tlp::node getSink() const;
778 
779  /**
780  * @brief Returns the first node in the graph.
781  *
782  */
783  virtual node getOneNode() const =0;
784 
785  /**
786  * @brief Returns a random node in the graph.
787  *
788  * @since Tulip 4.8
789  *
790  */
791  virtual node getRandomNode() const =0;
792 
793  /**
794  * @brief Return a const reference on the vector of nodes of the graph
795  * It is the fastest way to access to nodes, Iterators are 25% slower.
796  * @remark o(1)
797  */
798  virtual const std::vector<node>& nodes() const =0;
799 
800  /**
801  * @brief Return the position of a node in the vector of nodes of the graph
802  * @param n The node for which the position is requested
803  */
804  virtual unsigned int nodePos(const node n) const =0;
805 
806  /**
807  * @brief Gets an iterator over this graph's nodes.
808  * @return An iterator over all the nodes of this graph.
809  * @see getInNodes()
810  * @see getOutNodes()
811  * @see getInOutNodes()
812  * @see getEdges()
813  */
814  virtual Iterator<node>* getNodes() const =0;
815 
816  /**
817  * @brief Gets the i-th node in the input nodes of a given node.
818  * An input node 'in' of a node 'N' is the source of an edge going from
819  * 'in' to 'N'. e.g.
820  * @code
821  * node in = graph->addNode();
822  * node N = graph->addNode();
823  * graph->addEdge(in, N);
824  * //in == graph->getInNode(N, 1);
825  * @endcode
826  *
827  * If you have 5 input nodes on a node N, then
828  * @codeline graph->getInNode(2); @endcode
829  * will return the second of those nodes.
830  * It will ignore the output nodes of this node.
831  * @param n The node to get an input node of.
832  * @param i The index of the input node to get.
833  * @return The i-th input node of the given node.
834  * @see getInNodes()
835  * @see getInEdges()
836  */
837  virtual node getInNode(const node n,unsigned int i)const =0;
838 
839  /**
840  * @brief Gets an iterator over the input nodes of a node.
841  * @param n The node to get the input nodes of.
842  * @return An iterator over the input nodes of a node.
843  * @see getInNode()
844  * @see getInOutNodes()
845  * @see getInEdges()
846  */
847  virtual Iterator<node>* getInNodes(const node n) const =0;
848 
849  /**
850  * @brief Gets the i-th node in the output nodes of a given node.
851  * An output node 'out' of a node 'N' is the target of an edge going from
852  * 'N' to 'out'. e.g.
853  * @code
854  * node N = graph->addNode();
855  * node out = graph->addNode();
856  * graph->addEdge(N, out);
857  * //out == graph->getOutNode(N, 1);
858  * @endcode
859  *
860  * If you have 5 output nodes on a node N, then
861  * @codeline graph->getOutNode(2); @endcode
862  * will return the second of those nodes.
863  * It will ignore the input nodes of this node.
864  * @param n The node to get an output node of.
865  * @param i The index of the output node to get.
866  * @return The i-th output node of the given node.
867  * @see getOutNodes()
868  * @see getOutEdges()
869  */
870  virtual node getOutNode(const node n,unsigned int i) const =0;
871 
872  /**
873  * @brief Gets an iterator over the output nodes of a node.
874  * @param n The node to get the output nodes of.
875  * @return An iterator over the output nodes of a node.
876  * @see getOutNode()
877  * @see getInOutNodes()
878  * @see getOutEdges()
879  */
880  virtual Iterator<node>* getOutNodes(const node n) const =0;
881 
882  /**
883  * @brief Gets an iterator over the neighbors of a given node.
884  * @param n The node to retrieve the neighbors of.
885  * @return An iterator over the node's neighbors.
886  */
887  virtual Iterator<node>* getInOutNodes(const node n) const =0;
888 
889  /**
890  * @brief Gets an iterator performing a breadth-first search on the graph.
891  * @param root The node from whom to start the BFS. If not provided, the root
892  * node will be assigned to a source node in the graph (node with input degree equals to 0).
893  * If there is no source node in the graph, a random node will be picked.
894  * @return A stable iterator over the graph nodes in the BFS order.
895  */
896  virtual Iterator<node>* bfs(const node root = node()) const = 0;
897 
898  /**
899  * @brief Gets an iterator performing a depth-first search on the graph.
900  * @param root The node from whom to start the DFS. If not provided, the root
901  * node will be assigned to a source node in the graph (node with input degree equals to 0).
902  * If there is no source node in the graph, a random node will be picked.
903  * @return A stable iterator over the graph nodes in the DFS order.
904  */
905  virtual Iterator<node>* dfs(const node root = node()) const = 0;
906 
907  /**
908  * @brief Gets the underlying graph of a meta node.
909  * @param metaNode The metanode.
910  * @return The Graph pointed to by the metanode.
911  * @see getEdgeMetaInfo()
912  */
913  virtual Graph* getNodeMetaInfo(const node metaNode) const = 0;
914 
915  /**
916  * @brief Return a const reference on the vector of edges of the graph
917  * It is the fastest way to access to edges, Iterators are 25% slower.
918  * @remark o(1)
919  */
920  virtual const std::vector<edge>& edges() const =0;
921 
922  /**
923  * @brief Return the position of an edge in the vector of edges of the graph
924  * @param e The edge for which the position is requested
925  */
926  virtual unsigned int edgePos(const edge e) const =0;
927 
928  /**
929  * @brief Get an iterator over all the graph's edges.
930  * @return An iterator over all the graph's edges.
931  * @see getInEdges()
932  * @see getOutEdges()
933  * @see getInOutEdges()
934  */
935  virtual Iterator<edge>* getEdges() const =0;
936 
937  /**
938  * @brief Returns the first edge in the graph.
939  *
940  */
941  virtual edge getOneEdge() const =0;
942 
943  /**
944  * @brief Returns a random edge in the graph.
945  *
946  * @since Tulip 4.8
947  *
948  */
949  virtual edge getRandomEdge() const =0;
950 
951  /**
952  * @brief Gets an iterator over the output edges of a node.
953  * @param n The node to get the output edges from.
954  * @return An iterator over the node's output edges.
955  * @see getEdges()
956  * @see getOutEdges()
957  * @see getInOutEdges()
958  */
959  virtual Iterator<edge>* getOutEdges(const node n) const =0;
960 
961  /**
962  * @brief Gets an iterator over the edges of a node.
963  * @param n The node to get the edges from.
964  * @return An iterator over the node's edges.
965  * @see getEdges()
966  * @see getOutEdges()
967  * @see getInEdges()
968  */
969  virtual Iterator<edge>* getInOutEdges(const node n) const =0;
970 
971  /**
972  * @brief Gets an iterator over the input edges of a node.
973  * @param n The node to get the input edges from.
974  * @return An iterator over the node's input edges.
975  * @see getEdges()
976  * @see getOutEdges()
977  * @see getInOutEdges()
978  */
979  virtual Iterator<edge>* getInEdges(const node n) const =0;
980 
981  /**
982  * @brief Gets all input/output edges of a node existing in the root graph
983  * @warning If the current graph is not the root, the existence of the edge
984  * can be tested with isElement(edge) function.
985  * @param n The node to get the input/ouput edges from.
986  * @return a const reference to the vector of all edges of a node
987  */
988  virtual const std::vector<edge>& allEdges(const node n) const =0;
989 
990  /**
991  * @brief Gets an iterator over the edges composing a meta edge.
992  * @param metaEdge The metaEdge to get the real edges of.
993  * @return An Iterator over the edges composing the metaEdge.
994  * @see getNodeMetaInfo()
995  */
996  virtual Iterator<edge>* getEdgeMetaInfo(const edge metaEdge) const =0;
997 
998  /**
999  * @brief sort the graph elements in ascending order
1000  * @warning: That operation modify the vector of nodes and the vector of edges
1001  * and thus devalidate all iterators.
1002  */
1003  virtual void sortElts()=0;
1004 
1005  //================================================================================
1006  // Graph, nodes and edges information about the graph stucture
1007  //================================================================================
1008  /**
1009  * @brief Gets the unique identifier of the graph.
1010  * @return The unique identifier of this graph.
1011  */
1012  unsigned int getId() const {
1013  return id;
1014  }
1015 
1016  /**
1017  * @brief Gets the number of nodes in this graph.
1018  * @return The number of nodes in this graph.
1019  * @see numberOfEdges()
1020  */
1021  virtual unsigned int numberOfNodes()const =0;
1022 
1023  /**
1024  * @brief Gets the number of edges in this graph.
1025  * @return The number of edges in this graph.
1026  * @see numberOfNodes()
1027  */
1028  virtual unsigned int numberOfEdges()const =0;
1029 
1030  /**
1031  * @param n The node to get the degree of.
1032  * @return The degree of the given node.
1033  */
1034  virtual unsigned int deg(const node n)const =0;
1035 
1036  /**
1037  * @brief Get the input degree of a node.
1038  * @param n The node to get the input degree of.
1039  * @return The input degree of the given node.
1040  */
1041  virtual unsigned int indeg(const node n)const =0;
1042 
1043  /**
1044  * @brief Get the output degree of a node.
1045  * @param n The node to get the output degree of.
1046  * @return The output degree of the given node.
1047  */
1048  virtual unsigned int outdeg(const node n)const =0;
1049 
1050  /**
1051  * @brief Gets the source of an edge.
1052  * @param e The edge to get the source of.
1053  * @return The source of the given edge.
1054  */
1055  virtual node source(const edge e)const =0;
1056 
1057  /**
1058  * @brief Gets the target of an edge.
1059  * @param e The edge to get the target of.
1060  * @return The target of the given edge.
1061  */
1062  virtual node target(const edge e)const =0;
1063 
1064  /**
1065  * @brief Gets the source and the target of an edge.
1066  * @param e The edge to get the ends of.
1067  * @return A pair whose first element is the source, and second is the target.
1068  */
1069  virtual const std::pair<node, node>& ends(const edge e)const=0;
1070 
1071  /**
1072  * @brief Gets the opposite node of n through e.
1073  * @param e The edge linking the two nodes.
1074  * @param n The node at one end of e.
1075  * @return The node at the other end of e.
1076  */
1077  virtual node opposite(const edge e, const node n)const =0;
1078 
1079  /**
1080  * @brief Checks if an element belongs to this graph.
1081  * @param n The node to check if it is an element of the graph.
1082  * @return Whether or not the element belongs to the graph.
1083  */
1084  virtual bool isElement(const node n) const =0;
1085 
1086  /**
1087  * @brief Checks if a node is a meta node.
1088  * @param n The node to check if it is a meta node.
1089  * @return Whether or not the node is a meta node.
1090  */
1091  virtual bool isMetaNode(const node n) const =0;
1092 
1093  /**
1094  * @brief Checks if an element belongs to this graph.
1095  * @param e The edge to check if it is an element of the graph.
1096  * @return Whether or not the element belongs to the graph.
1097  */
1098  virtual bool isElement(const edge e) const =0;
1099 
1100  /**
1101  * @brief Checks if an edge is a meta edge.
1102  * @param e The edge to check if it is a meta edge.
1103  * @return Whether or not the edge is a meta edge.
1104  */
1105  virtual bool isMetaEdge(const edge e) const =0;
1106 
1107  /**
1108  * @brief Checks if an edge exists between two given nodes.
1109  * @param source The source of the hypothetical edge.
1110  * @param target The target of the hypothetical edge.
1111  * @param directed When set to false edges from target to source are also considered
1112  * @return true if such an edge exists
1113  */
1114  virtual bool hasEdge(const node source, const node target,
1115  bool directed = true) const {
1116  return existEdge(source, target, directed).isValid();
1117  }
1118 
1119 
1120  /**
1121  * @brief Returns all the edges between two nodes.
1122  * @param source The source of the hypothetical edges.
1123  * @param target The target of the hypothetical edges.
1124  * @param directed When set to false edges from target to source are also considered
1125  * @return a vector of existing edges
1126  */
1127  virtual std::vector<edge> getEdges(const node source, const node target,
1128  bool directed = true) const=0;
1129 
1130  /**
1131  * @brief Returns the first edge found between the two given nodes.
1132  * @warning This function always returns an edge,
1133  * you need to check if this edge is valid with edge::isValid().
1134  * @param source The source of the hypothetical edge.
1135  * @param target The target of the hypothetical edge.
1136  * @param directed When set to false
1137  * an edge from target to source may also be returned
1138  * @return An edge that is only valid if it exists.
1139  */
1140  virtual edge existEdge(const node source, const node target,
1141  bool directed = true) const=0;
1142 
1143  //================================================================================
1144  // Access to the graph attributes and to the node/edge property.
1145  //================================================================================
1146  /**
1147  * @brief Sets the name of the graph.
1148  * The name does not have to be unique, it is used for convenience.
1149  * @param name The new name of the graph.
1150  */
1151  virtual void setName(const std::string &name) = 0;
1152 
1153  /**
1154  * @brief Retrieves the name of the graph.
1155  * @return The name of the graph.
1156  */
1157  virtual std::string getName() const = 0;
1158 
1159  /**
1160  * @brief Gets the attributes of the graph.
1161  *
1162  * The attributes contains the name and any user-defined value.
1163  * @return The attributes of the graph.
1164  */
1165  const DataSet & getAttributes() const {
1166  return (const_cast<Graph *>(this))->getNonConstAttributes();
1167  }
1168 
1169  /**
1170  * @brief Gets an attribute on the graph.
1171  * @param name The name of the attribute to set.
1172  * @param value The value to set.
1173  * @return Whether the setting of the attribute was sucessful.
1174  */
1175  template<typename ATTRIBUTETYPE>
1176  bool getAttribute(const std::string &name, ATTRIBUTETYPE& value) const;
1177 
1178  /**
1179  * @brief Gets a copy of the attribute.
1180  * @param name The name of the attribute to retrieve.
1181  * @return A copy of the attribute to retrieve.
1182  */
1183  DataType* getAttribute(const std::string& name) const;
1184 
1185  /**
1186  * @brief Sets an attribute on the graph.
1187  * @param name The name of the attribute to set.
1188  * @param value The value to set on this attribute.
1189  */
1190  template<typename ATTRIBUTETYPE>
1191  void setAttribute(const std::string &name,const ATTRIBUTETYPE &value);
1192 
1193  /**
1194  * @brief Sets an attribute on the graph.
1195  * @param name The name of the attribute to set.
1196  * @param value The value to set.
1197  */
1198  void setAttribute(const std::string &name, const DataType* value);
1199 
1200  /**
1201  * @brief Removes an attribute on the graph.
1202  * @param name The name of the attribute to remove.
1203  */
1204  void removeAttribute(const std::string &name) {
1205  notifyRemoveAttribute(name);
1206  getNonConstAttributes().remove(name);
1207  }
1208 
1209  /**
1210  * @brief Checks if an attribute exists.
1211  * @param name The name of the attribute to check for.
1212  * @return Whether the attribute exists.
1213  */
1214  bool existAttribute(const std::string &name) const {
1215  return getAttributes().exist(name);
1216  }
1217 
1218  /**
1219  * @brief deprecated, use existAttribute instead.
1220  */
1221  _DEPRECATED bool attributeExist(const std::string &name) const {
1222  return existAttribute(name);
1223  }
1224 
1225  /**
1226  * @brief Adds a property to the graph.
1227  * The graph takes ownership of the property. If you want to delete it, use
1228  * Graph::delLocalProperty().
1229  * @param name The unique identifier of the property.
1230  * @param prop The property to add.
1231  */
1232  virtual void addLocalProperty(const std::string &name, PropertyInterface *prop)=0;
1233 
1234  /**
1235  * @brief Gets an existing property.
1236  * In DEBUG mode an assertion checks the existence of the property.
1237  *
1238  * The graph keeps ownership of the property, if you wish to remove it from the graph use
1239  * Graph::delLocalProperty().
1240  *
1241  * @param name The unique identifier of the property.
1242  * @return An existing property, or NULL if no property with the given name exists.
1243  */
1244  virtual PropertyInterface* getProperty(const std::string& name) const = 0;
1245 
1246  /**
1247  * @brief Gets a property on this graph.
1248  * The name of a property identifies it uniquely.
1249  * Either there already exists a property with the given name, in which case it is returned.
1250  * Either no such property exists and it is created.
1251  *
1252  * The graph keeps ownership of the property, if you wish to remove it from the graph use
1253  * Graph::delLocalProperty().
1254  * @warning using the wrong template parameter will cause a segmentation fault.
1255  * @param The unique identifier of the property.
1256  * @return The property of given name.
1257  */
1258  template<typename PropertyType>
1259  PropertyType* getLocalProperty(const std::string &name);
1260 
1261  /**
1262  * @brief Gets a property on this graph or one of its ancestors.
1263  * If the property already exists on the graph or in one of its ancestors, it is returned.
1264  * Otherwise a new property is created on this graph.
1265  *
1266  * The graph keeps ownership of the property, if you wish to remove it from the graph use
1267  * Graph::delLocalProperty().
1268  *
1269  * @warning using the wrong propertyType will result in a segmentation fault. Using an invalid property type will always return NULL.
1270  * @param name The unique identifier of the property.
1271  * @return An existing property, or a new one if none exists with the given name.
1272  */
1273  template<typename PropertyType>
1274  PropertyType* getProperty(const std::string &name);
1275 
1276  /**
1277  * @brief Gets a property on this graph, and this graph only.
1278  * This forwards the call to the template version of getLocalProperty(), with the correct template parameter deduced from the propertyType parameter.
1279  *
1280  * The graph keeps ownership of the property, if you wish to remove it from the graph use
1281  * Graph::delLocalProperty().
1282  *
1283  * @warning using the wrong propertyType will result in a segmentation fault. Using an invalid property type will always return NULL.
1284  * @param propertyName The unique identifier of the property.
1285  * @param propertyType A string describing the type of the property.
1286  * @return The property of given name.
1287  * @see getLocalProperty().
1288  */
1289  PropertyInterface *getLocalProperty(const std::string& propertyName, const std::string& propertyType);
1290 
1291  /**
1292  * @brief Gets a property on this graph or one of its ancestors.
1293  * This forwards the call to the template version of getProperty(), with the correct template parameter deduced from the propertyType parameter.
1294  *
1295  * The graph keeps ownership of the property, if you wish to remove it from the graph use
1296  * Graph::delLocalProperty().
1297  *
1298  * @warning using the wrong propertyType will result in a segmentation fault. Using an invalid property type will always return NULL.
1299  * @param propertyName The unique identifier of the property.
1300  * @param propertyType A string describing the type of the property.
1301  * @return The property of given name.
1302  * @see getProperty().
1303  */
1304  PropertyInterface *getProperty(const std::string& propertyName, const std::string& propertyType);
1305 
1306  /**
1307  * @brief Checks if a property exists in this graph or one of its ancestors.
1308  * @param The unique identifier of the property.
1309  * @return Whether a property with the given name exists.
1310  */
1311  virtual bool existProperty(const std::string& name) const = 0;
1312 
1313  /**
1314  * @brief Checks if a property exists in this graph.
1315  * @param The unique identifier of the property.
1316  * @return Whether a property with the given name exists.
1317  */
1318  virtual bool existLocalProperty(const std::string& name) const = 0;
1319 
1320  /**
1321  * @brief Removes and deletes a property from this graph.
1322  * The property is removed from the graph's property pool, meaning its name can now be used by another property.
1323  * The object is deleted and the memory freed.
1324  * @param name The unique identifier of the property.
1325  */
1326  virtual void delLocalProperty(const std::string& name)=0;
1327 
1328  /**
1329  * @brief Gets an iterator over the names of the local properties of this graph.
1330  * @return An iterator over this graph's properties names.
1331  */
1332  virtual Iterator<std::string>* getLocalProperties() const=0;
1333 
1334  /**
1335  * @brief Gets an iterator over the local properties of this graph.
1336  * @return An iterator over this graph's properties.
1337  */
1338  virtual Iterator<PropertyInterface*>* getLocalObjectProperties() const=0;
1339 
1340  /**
1341  * @brief Gets an iterator over the names of the properties inherited from this graph's ancestors,
1342  * excluding this graph's local properties.
1343  * @return An iterator over the names of the properties this graph inherited.
1344  */
1345  virtual Iterator<std::string>* getInheritedProperties() const=0;
1346 
1347  /**
1348  * @brief Gets an iterator over the properties inherited from this graph's ancestors,
1349  * excluding this graph's local properties.
1350  * @return An iterator over the properties this graph inherited.
1351  */
1352  virtual Iterator<PropertyInterface*>* getInheritedObjectProperties() const=0;
1353 
1354  /**
1355  * @brief Gets an iterator over the names of all the properties attached to this graph,
1356  * whether they are local or inherited.
1357  * @return An iterator over the names of all the properties attached to this graph.
1358  */
1359  virtual Iterator<std::string>* getProperties() const=0;
1360 
1361  /**
1362  * @brief Gets an iterator over the properties attached to this graph,
1363  * whether they are local or inherited.
1364  * @return An iterator over all of the properties attached to this graph.
1365  */
1366  virtual Iterator<PropertyInterface*>* getObjectProperties() const=0;
1367 
1368  /**
1369  * @brief Runs a plugin on the graph, whose result is a property.
1370  *
1371  * @param algorithm The name of the plugin to run.
1372  * @param result The property in which to put the results. All previous values will be erased.
1373  * @param errorMessage Stores the error message if the plugin fails.
1374  * @param progress A means of feedback during the plugin execution. Some plugins support being stopped or cancelled through this.
1375  * @param parameters The parameters of the algorithm. Some algorithms use this DataSet to output some additional information.
1376  * @return Whether the plugin executed successfully or not. If not, check the error message.
1377  *
1378  * @see PluginLister::getPluginParameters() to retrieve the list of default parameters for the pligin.
1379  */
1380  bool applyPropertyAlgorithm(const std::string &algorithm,
1381  PropertyInterface* result,
1382  std::string &errorMessage,
1383  PluginProgress *progress=NULL,
1384  DataSet *parameters=NULL);
1385 
1386  // updates management
1387  /**
1388  * @brief Saves the current state of the whole graph hierarchy and allows to revert to this state later on, using pop().
1389  * All modifications except those altering the ordering of the edges will be undone.
1390  *
1391  * This allows to undo/redo modifications on a graph.
1392  * This is mostly useful from a user interface point of view, but some algorithms use this mechanism to clean up before finishing.
1393  * For instance:
1394  * @code
1395  * Graph* graph = tlp::newGraph();
1396  * DoubleProperty* prop = graph->getProperty<DoubleProperty>("metric");
1397  * string errorMessage;
1398  *
1399  * //our super metric stuff we want to kee
1400  * DoubleProperty* superProperty = graph->getProperty<DoubleProperty>("superStuff");
1401  * vector<PropertyInterface*> propertiesToKeep;
1402  * propertiesToKeep.push_back(superProperty);
1403  *
1404  *
1405  * //apply some metric
1406  * graph->applyPropertyAlgorithm("Degree", prop, errorMessage);
1407  *
1408  * // save this state to be able to revert to it later
1409  * //however we do not want to allow to unpop(), which would go forward again to the state where prop contains 'Depth'.
1410  * //this saves some memory.
1411  * //Also we always want to keep the value of our super property, so we pass it in the collection of properties to leave unaffected by the pop().
1412  * graph->push(false, propertiesToKeep);
1413  *
1414  * //compute the quality of this metric, or whatever makes sense
1415  * int degreeQuality = prop->getMax();
1416  *
1417  * //compute another metric
1418  * graph->applyPropertyAlgorithm("Depth", prop, errorMessage);
1419  *
1420  * //compute our secret metric, that depends on depth
1421  * graph->applyPropertyAlgorithm("MySuperSecretAlgorithm", superProperty, errorMessage);
1422  *
1423  * //compute its quality
1424  * int depthQuality = prop->getMax();
1425  *
1426  * //if the degree was better, revert back to the state where its contents were in prop.
1427  * if(degreeQuality > depthQuality) {
1428  * //this does not affect superProperty, as we told the system not to consider it when recording modifications to potentially revert.
1429  * graph->pop();
1430  * }
1431  *
1432  * //do some stuff using our high quality metric
1433  * ColorProperty* color = graph->getProperty("viewColor");
1434  * graph->applyPropertyAlgorithm("Color Mapping", color, errorMessage);
1435  *
1436  * @endcode
1437  *
1438  * @param unpopAllowed Whether or not to allow to re-do the modifications once they are undone.
1439  * @param propertiesToPreserveOnPop A collection of properties whose state to preserve when using pop().
1440  * @see pop()
1441  * @see popIfNoUpdates()
1442  * @see unpop()
1443  * @see canPop()
1444  * @see canUnPop()
1445  * @see canPopThenUnPop()
1446  */
1447  virtual void push(bool unpopAllowed = true,
1448  std::vector<PropertyInterface*>* propertiesToPreserveOnPop= NULL)=0;
1449 
1450  /**
1451  * @brief Undoes modifications and reverts the whole graph hierarchy back to a previous state.
1452  *
1453  * @param unpopAllowed Whether or not it is possible to redo what will be undoe by this call.
1454  */
1455  virtual void pop(bool unpopAllowed = true)=0;
1456 
1457  /**
1458  * @brief abort last push if no updates have been recorded
1459  */
1460  virtual void popIfNoUpdates()=0;
1461 
1462 
1463  /**
1464  * @brief Re-perform actions that were undone using pop().
1465  *
1466  * For instance:
1467  * @code
1468  * DoubleProperty* prop = graph->getProperty<DoubleProperty>("metric");
1469  * string errorMessage;
1470  *
1471  * //apply some metric
1472  * graph->applyPropertyAlgorithm("Degree", prop, errorMessage);
1473  *
1474  * // save this state to be able to revert to it later
1475  * graph->push();
1476  *
1477  * //compute the quality of this metric, or whatever makes sense
1478  * int degreeQuality = prop->getMax();
1479  *
1480  * //compute another metric
1481  * graph->applyPropertyAlgorithm("Depth", prop, errorMessage);
1482  *
1483  * //compute its quality
1484  * int depthQuality = prop->getMax();
1485  *
1486  * //if the degree was better, revert back to the state where its contents were in prop.
1487  * if(degreeQuality > depthQuality) {
1488  * graph->pop();
1489  * }
1490  *
1491  * ...
1492  *
1493  * //revert back to the depth for some reason.
1494  * graph->unpop();
1495  * @endcode
1496  */
1497  virtual void unpop()=0;
1498 
1499  /**
1500  * @brief Checks if there is a state to revert to.
1501  * @return Whether there was a previous call to push() that was not yet pop()'ed.
1502  */
1503  virtual bool canPop()=0;
1504 
1505  /**
1506  * @brief Checks if the last undone modifications can be redone.
1507  * @return Whether it is possible to re-do modifications that have been undone by pop().
1508  */
1509  virtual bool canUnpop()=0;
1510 
1511  /**
1512  * @brief Checks if it is possible to call pop() and then unPop(), to undo then re-do modifications.
1513  * @return Whether it is possible to undo and then redo.
1514  */
1515  virtual bool canPopThenUnpop()=0;
1516 
1517  // meta nodes management
1518  /**
1519  * @brief Creates a meta-node from a vector of nodes.
1520  * Every edges from any node in the vector to another node of the graph will be replaced with meta edges
1521  * from the meta node to the other nodes.
1522  * @warning This method will fail when called on the root graph.
1523  *
1524  * @param nodes The vector of nodes to put into the meta node.
1525  * @param multiEdges Whether a meta edge should be created for each underlying edge.
1526  * @param delAllEdge Whether the underlying edges will be removed from the whole hierarchy.
1527  * @return The newly created meta node.
1528  */
1529  node createMetaNode(const std::vector<node> &nodes, bool multiEdges = true,
1530  bool delAllEdge = true);
1531 
1532  /**
1533  * @brief deprecated, use createMetaNode(const std::vector<node>&, bool multiEdges = true, bool delAllEdge = true) instead
1534  */
1535  _DEPRECATED node createMetaNode(const std::set<node> &nodeSet,
1536  bool multiEdges = true,
1537  bool delAllEdge = true);
1538 
1539  /**
1540  * @brief Populates a quotient graph with one meta node
1541  * for each iterated graph.
1542  *
1543  * @param itS a Graph iterator, (typically a subgraph iterator)
1544  * @param quotientGraph the graph that will contain the meta nodes
1545  * @param metaNodes will contains all the added meta nodes after the call
1546  *
1547  */
1548  void createMetaNodes(Iterator<Graph *> *itS, Graph *quotientGraph,
1549  std::vector<node>& metaNodes);
1550  /**
1551  * @brief Closes an existing subgraph into a metanode. Edges from nodes
1552  * in the subgraph to nodes outside the subgraph are replaced with
1553  * edges from the metanode to the nodes outside the subgraph.
1554  * @warning this method will fail when called on the root graph.
1555  *
1556  * @param subGraph an existing subgraph
1557  * @param multiEdges indicates if a meta edge will be created for each underlying edge
1558  * @param delAllEdge indicates if the underlying edges will be removed from the entire hierarchy
1559  */
1560  node createMetaNode(Graph* subGraph, bool multiEdges = true, bool delAllEdge = true);
1561 
1562  /**
1563  * @brief Opens a metanode and replaces all edges between that
1564  * meta node and other nodes in the graph.
1565  *
1566  * @warning this method will fail when called on the root graph.
1567  *
1568  * @param n The meta node to open.
1569  * @param updateProperties If set to true, open meta node will update inner nodes layout, color, size, etc
1570  */
1571  void openMetaNode(node n, bool updateProperties=true);
1572 
1573 ///@cond DOXYGEN_HIDDEN
1574 protected:
1575  virtual DataSet &getNonConstAttributes() = 0;
1576  // designed to reassign an id to a previously deleted elt
1577  // used by GraphUpdatesRecorder
1578  virtual void restoreNode(node)=0;
1579  virtual void restoreEdge(edge, node source, node target)=0;
1580  // designed to only update own structures
1581  // used by GraphUpdatesRecorder
1582  virtual void removeNode(const node)=0;
1583  virtual void removeEdge(const edge)=0;
1584 
1585  // to check if a property can be deleted
1586  // used by PropertyManager
1587  virtual bool canDeleteProperty(Graph* g, PropertyInterface *prop) {
1588  return getRoot()->canDeleteProperty(g, prop);
1589  }
1590 
1591  // local property renaming
1592  // can failed if a property with the same name already exists
1593  virtual bool renameLocalProperty(PropertyInterface* prop,
1594  const std::string& newName)=0;
1595 
1596  // internally used to deal with sub graph deletion
1597  virtual void removeSubGraph(Graph*)=0;
1598  virtual void clearSubGraphs()=0;
1599  virtual void restoreSubGraph(Graph*)=0;
1600  virtual void setSubGraphToKeep(Graph*)=0;
1601 
1602  // for notification of GraphObserver
1603  void notifyAddNode(const node n);
1604  void notifyAddNode(Graph*, const node n) {
1605  notifyAddNode(n);
1606  }
1607  void notifyAddEdge(const edge e);
1608  void notifyAddEdge(Graph*, const edge e) {
1609  notifyAddEdge(e);
1610  }
1611  void notifyBeforeSetEnds(const edge e);
1612  void notifyBeforeSetEnds(Graph*, const edge e) {
1613  notifyBeforeSetEnds(e);
1614  }
1615  void notifyAfterSetEnds(const edge e);
1616  void notifyAfterSetEnds(Graph*, const edge e) {
1617  notifyAfterSetEnds(e);
1618  }
1619  void notifyDelNode(const node n);
1620  void notifyDelNode(Graph*, const node n) {
1621  notifyDelNode(n);
1622  }
1623  void notifyDelEdge(const edge e);
1624  void notifyDelEdge(Graph*, const edge e) {
1625  notifyDelEdge(e);
1626  }
1627  void notifyReverseEdge(const edge e);
1628  void notifyReverseEdge(Graph*, const edge e) {
1629  notifyReverseEdge(e);
1630  }
1631  void notifyBeforeAddSubGraph(const Graph*);
1632  void notifyAfterAddSubGraph(const Graph*);
1633  void notifyBeforeAddSubGraph(Graph*, const Graph* sg) {
1634  notifyBeforeAddSubGraph(sg);
1635  }
1636  void notifyAfterAddSubGraph(Graph*, const Graph* sg) {
1637  notifyAfterAddSubGraph(sg);
1638  }
1639  void notifyBeforeDelSubGraph(const Graph*);
1640  void notifyAfterDelSubGraph(const Graph*);
1641  void notifyBeforeDelSubGraph(Graph*, const Graph* sg) {
1642  notifyBeforeDelSubGraph(sg);
1643  }
1644  void notifyAfterDelSubGraph(Graph*, const Graph* sg) {
1645  notifyAfterDelSubGraph(sg);
1646  }
1647 
1648  void notifyBeforeAddDescendantGraph(const Graph*);
1649  void notifyAfterAddDescendantGraph(const Graph*);
1650  void notifyBeforeDelDescendantGraph(const Graph*);
1651  void notifyAfterDelDescendantGraph(const Graph*);
1652 
1653  void notifyBeforeAddLocalProperty(const std::string&);
1654  void notifyAddLocalProperty(const std::string&);
1655  void notifyAddLocalProperty(Graph*, const std::string& name) {
1656  notifyAddLocalProperty(name);
1657  }
1658  void notifyBeforeDelLocalProperty(const std::string&);
1659  void notifyAfterDelLocalProperty(const std::string&);
1660  void notifyDelLocalProperty(Graph*, const std::string& name) {
1661  notifyBeforeDelLocalProperty(name);
1662  }
1663  void notifyBeforeSetAttribute(const std::string&);
1664  void notifyBeforeSetAttribute(Graph*, const std::string& name) {
1665  notifyBeforeSetAttribute(name);
1666  }
1667  void notifyAfterSetAttribute(const std::string&);
1668  void notifyAfterSetAttribute(Graph*, const std::string& name) {
1669  notifyAfterSetAttribute(name);
1670  }
1671  void notifyRemoveAttribute(const std::string&);
1672  void notifyRemoveAttribute(Graph*, const std::string& name) {
1673  notifyRemoveAttribute(name);
1674  }
1675  void notifyDestroy();
1676  void notifyDestroy(Graph*) {
1677  notifyDestroy();
1678  }
1679 
1680  unsigned int id;
1681  TLP_HASH_MAP<std::string, tlp::PropertyInterface*> circularCalls;
1682 ///@endcond
1683 };
1684 
1685 /**
1686  * @ingroup Observation
1687  * Event class for specific events on Graph
1688  **/
1689 class TLP_SCOPE GraphEvent :public Event {
1690 public:
1691  // be careful about the ordering of the constants
1692  // in the enum below because it is used in some assertions
1693  enum GraphEventType {
1694  TLP_ADD_NODE = 0,
1695  TLP_DEL_NODE = 1,
1696  TLP_ADD_EDGE = 2,
1697  TLP_DEL_EDGE = 3,
1698  TLP_REVERSE_EDGE = 4,
1699  TLP_BEFORE_SET_ENDS = 5,
1700  TLP_AFTER_SET_ENDS = 6,
1701  TLP_ADD_NODES = 7,
1702  TLP_ADD_EDGES = 8,
1703  TLP_BEFORE_ADD_DESCENDANTGRAPH = 9,
1704  TLP_AFTER_ADD_DESCENDANTGRAPH = 10,
1705  TLP_BEFORE_DEL_DESCENDANTGRAPH = 11,
1706  TLP_AFTER_DEL_DESCENDANTGRAPH = 12,
1707  TLP_BEFORE_ADD_SUBGRAPH = 13,
1708  TLP_AFTER_ADD_SUBGRAPH = 14,
1709  TLP_BEFORE_DEL_SUBGRAPH = 15,
1710  TLP_AFTER_DEL_SUBGRAPH = 16,
1711  TLP_ADD_LOCAL_PROPERTY = 17,
1712  TLP_BEFORE_DEL_LOCAL_PROPERTY = 18,
1713  TLP_AFTER_DEL_LOCAL_PROPERTY = 19,
1714  TLP_ADD_INHERITED_PROPERTY = 20,
1715  TLP_BEFORE_DEL_INHERITED_PROPERTY = 21,
1716  TLP_AFTER_DEL_INHERITED_PROPERTY = 22,
1717  TLP_BEFORE_RENAME_LOCAL_PROPERTY = 23,
1718  TLP_AFTER_RENAME_LOCAL_PROPERTY = 24,
1719  TLP_BEFORE_SET_ATTRIBUTE = 25,
1720  TLP_AFTER_SET_ATTRIBUTE = 26,
1721  TLP_REMOVE_ATTRIBUTE = 27,
1722  TLP_BEFORE_ADD_LOCAL_PROPERTY = 28,
1723  TLP_BEFORE_ADD_INHERITED_PROPERTY = 29
1724  };
1725 
1726  // constructor for node/edge/nodes/edges events
1727  GraphEvent(const Graph& g, GraphEventType graphEvtType, unsigned int id,
1728  Event::EventType evtType = Event::TLP_MODIFICATION)
1729  : Event(g, evtType), evtType(graphEvtType) {
1730  if (graphEvtType == TLP_ADD_NODES || graphEvtType == TLP_ADD_EDGES)
1731  info.nbElts = id;
1732  else
1733  info.eltId = id;
1734 
1735  vectInfos.addedNodes = NULL;
1736  }
1737  // constructor for subgraph events
1738  GraphEvent(const Graph& g, GraphEventType graphEvtType,
1739  const Graph* sg)
1740  : Event(g, Event::TLP_MODIFICATION), evtType(graphEvtType) {
1741  info.subGraph = sg;
1742  vectInfos.addedNodes = NULL;
1743  }
1744 
1745  // constructor for attribute/property events
1746  GraphEvent(const Graph& g, GraphEventType graphEvtType,
1747  const std::string& str,
1748  Event::EventType evtType = Event::TLP_MODIFICATION)
1749  : Event(g, evtType), evtType(graphEvtType) {
1750  info.name = new std::string(str);
1751  vectInfos.addedNodes = NULL;
1752  }
1753 
1754  // constructor for rename property events
1755  GraphEvent(const Graph& g, GraphEventType graphEvtType,
1756  PropertyInterface* prop,
1757  const std::string& newName)
1758  : Event(g, Event::TLP_MODIFICATION), evtType(graphEvtType) {
1759  info.renamedProp =
1760  new std::pair<PropertyInterface*,std::string>(prop, newName);
1761  vectInfos.addedNodes = NULL;
1762  }
1763 
1764  ~GraphEvent();
1765 
1766  Graph* getGraph() const {
1767  return static_cast<Graph *>(sender());
1768  }
1769 
1770  node getNode() const {
1771  assert(evtType < TLP_ADD_EDGE);
1772  return node(info.eltId);
1773  }
1774 
1775  edge getEdge() const {
1776  assert(evtType > TLP_DEL_NODE && evtType < TLP_ADD_NODES);
1777  return edge(info.eltId);
1778  }
1779 
1780  const std::vector<node>& getNodes() const;
1781 
1782  unsigned int getNumberOfNodes() const {
1783  assert(evtType == TLP_ADD_NODES);
1784  return info.nbElts;
1785  }
1786 
1787  const std::vector<edge>& getEdges() const;
1788 
1789  unsigned int getNumberOfEdges() const {
1790  assert(evtType == TLP_ADD_EDGES);
1791  return info.nbElts;
1792  }
1793 
1794  const Graph* getSubGraph() const {
1795  assert(evtType > TLP_ADD_EDGES && evtType < TLP_ADD_LOCAL_PROPERTY);
1796  return info.subGraph;
1797  }
1798 
1799  const std::string& getAttributeName() const {
1800  assert(evtType > TLP_AFTER_DEL_INHERITED_PROPERTY);
1801  return *(info.name);
1802  }
1803 
1804  const std::string& getPropertyName() const;
1805 
1806  PropertyInterface* getProperty() const {
1807  assert(evtType == TLP_BEFORE_RENAME_LOCAL_PROPERTY ||
1808  evtType == TLP_AFTER_RENAME_LOCAL_PROPERTY);
1809  return info.renamedProp->first;
1810  }
1811 
1812  const std::string& getPropertyNewName() const {
1813  assert(evtType == TLP_BEFORE_RENAME_LOCAL_PROPERTY);
1814  return info.renamedProp->second;
1815  }
1816 
1817  const std::string& getPropertyOldName() const {
1818  assert(evtType == TLP_AFTER_RENAME_LOCAL_PROPERTY);
1819  return info.renamedProp->second;
1820  }
1821 
1822  GraphEventType getType() const {
1823  return evtType;
1824  }
1825 
1826 protected:
1827  GraphEventType evtType;
1828  union {
1829  unsigned int eltId;
1830  const Graph* subGraph;
1831  std::string* name;
1832  unsigned int nbElts;
1833  std::pair<PropertyInterface*, std::string>* renamedProp;
1834  } info;
1835  union {
1836  std::vector<node>* addedNodes;
1837  std::vector<edge>* addedEdges;
1838  } vectInfos;
1839 };
1840 
1841 }
1842 
1843 ///Print the graph (only nodes and edges) in ostream, in the tulip format
1844 TLP_SCOPE std::ostream& operator<< (std::ostream &,const tlp::Graph *);
1845 
1846 //================================================================================
1847 // these functions allow to use tlp::Graph as a key in a hash-based data structure (e.g. hashmap).
1848 //================================================================================
1849 ///@cond DOXYGEN_HIDDEN
1850 TLP_BEGIN_HASH_NAMESPACE {
1851  template <>
1852  struct TLP_SCOPE hash<const tlp::Graph *> {
1853  size_t operator()(const tlp::Graph *s) const {return size_t(s->getId());}
1854  };
1855  template <>
1856  struct TLP_SCOPE hash<tlp::Graph *> {
1857  size_t operator()(tlp::Graph *s) const {return size_t(s->getId());}
1858  };
1859 } TLP_END_HASH_NAMESPACE
1860 ///@endcond
1861 
1862 #include "cxx/Graph.cxx"
1863 #endif
bool attributeExist(const std::string &name) const
deprecated, use existAttribute instead.
Definition: Graph.h:1221
A graph property that maps a boolean value to graph elements.
Graph * newGraph()
Creates a new, empty graph.
std::ostream & operator<<(std::ostream &os, const Array< Obj, SIZE > &array)
operator << stream operator to easily print an array, or save it to a file.
Definition: Array.cxx:34
PropertyInterface describes the interface of a graph property.
void copyToGraph(Graph *outG, const Graph *inG, BooleanProperty *inSelection=NULL, BooleanProperty *outSelection=NULL)
Interface for Tulip iterators. Allows basic iteration operations only.
Definition: Iterator.h:39
virtual bool hasEdge(const node source, const node target, bool directed=true) const
Checks if an edge exists between two given nodes.
Definition: Graph.h:1114
Describes a value of any type.
Definition: DataSet.h:57
bool saveGraph(Graph *graph, const std::string &filename, tlp::PluginProgress *progress=NULL, tlp::DataSet *data=NULL)
Saves the corresponding graph to a file (extension can be any of the Tulip supported ouput graph file...
A container that can store data from any type.
Definition: DataSet.h:190
bool existAttribute(const std::string &name) const
Checks if an attribute exists.
Definition: Graph.h:1214
ElementType
Definition: Graph.h:47
const DataSet & getAttributes() const
Gets the attributes of the graph.
Definition: Graph.h:1165
Graph * importGraph(const std::string &format, DataSet &dataSet, PluginProgress *progress=NULL, Graph *newGraph=NULL)
Imports a graph using the specified import plugin with the parameters stored in the DataSet...
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
Iterator< Graph * > * getRootGraphs()
Event is the base class for all events used in the Observation mechanism.
Definition: Observable.h:47
PluginProcess subclasses are meant to notify about the progress state of some process (typically a pl...
void removeAttribute(const std::string &name)
Removes an attribute on the graph.
Definition: Graph.h:1204
unsigned int getId() const
Gets the unique identifier of the graph.
Definition: Graph.h:1012
bool exportGraph(Graph *graph, std::ostream &outputStream, const std::string &format, DataSet &dataSet, PluginProgress *progress=NULL)
Exports a graph using the specified export plugin with parameters stored in the DataSet.
The Observable class is the base of Tulip&#39;s observation system.
Definition: Observable.h:123
void removeFromGraph(Graph *ioG, BooleanProperty *inSelection=NULL)
Graph * loadGraph(const std::string &filename, tlp::PluginProgress *progress=NULL)
Loads a graph from a file (extension can be any of the Tulip supported input graph file format)...