Tulip  4.8.0
Better Visualization Through Research
 All Classes Files Functions Variables Enumerations Enumerator Properties Groups Pages
GraphDecorator.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 ///@cond DOXYGEN_HIDDEN
20 
21 #ifndef DOXYGEN_NOTFOR_DEVEL
22 
23 #ifndef Tulip_GraphDecorator_H
24 #define Tulip_GraphDecorator_H
25 
26 #include <tulip/Graph.h>
27 
28 namespace tlp {
29 
30 class TLP_SCOPE GraphDecorator : public Graph {
31 public:
32  GraphDecorator(Graph* s);
33  virtual ~GraphDecorator();
34 
35  virtual void clear();
36  virtual Graph *addSubGraph(BooleanProperty *selection=0,
37  const std::string& name = "unnamed");
38  virtual void delSubGraph(Graph * s);
39  virtual void delAllSubGraphs(Graph *s);
40  virtual Graph* getSuperGraph()const;
41  virtual void setSuperGraph(Graph* s);
42  virtual Graph* getRoot() const;
43  virtual Iterator<Graph *> * getSubGraphs() const;
44  virtual bool isSubGraph(const Graph* sg) const;
45  virtual bool isDescendantGraph(const Graph* sg) const;
46  virtual Graph* getSubGraph(unsigned int id) const;
47  virtual Graph* getSubGraph(const std::string &name) const;
48  virtual Graph* getDescendantGraph(unsigned int id) const;
49  virtual Graph* getDescendantGraph(const std::string &name) const;
50  virtual unsigned int numberOfSubGraphs() const;
51  virtual unsigned int numberOfDescendantGraphs() const;
52 
53  //============================================================
54  virtual node source(const edge e)const;
55  virtual void setSource(const edge, const node);
56  virtual node target(const edge e)const;
57  virtual void setTarget(const edge, const node);
58  virtual node opposite(const edge e, const node n)const;
59  virtual edge existEdge(const node n, const node m, bool directed = true)const;
60  virtual bool hasEdge(const node source, const node target,
61  bool directed = true) const;
62  virtual std::vector<edge> getEdges(const node source, const node target,
63  bool directed = true) const;
64  virtual const std::pair<node, node>& ends(const edge e) const;
65  virtual void setEnds(const edge, const node, const node);
66  virtual void reverse(const edge e);
67  virtual unsigned int deg(const node n)const;
68  virtual unsigned int indeg(const node n)const;
69  virtual unsigned int outdeg(const node n)const;
70  virtual Graph* getNodeMetaInfo(const node n)const;
71 
72  //============================================================
73  virtual node createMetaNode(const std::set<node> &nodeSet, bool multiEdges = true, bool delAllEdge = true);
74  virtual void createMetaNodes(Iterator<Graph *> *itS, Graph *quotientGraph, std::vector<node>& metaNodes);
75  virtual node createMetaNode(Graph* subGraph, bool multiEdges = true, bool delAllEdge = true);
76 
77  //============================================================
78  virtual node getOneNode() const;
79  virtual node getRandomNode() const;
80  virtual node getInNode(const node n,unsigned int i)const;
81  virtual node getOutNode(const node n,unsigned int i) const;
82  virtual edge getOneEdge() const;
83  virtual edge getRandomEdge() const;
84 
85  virtual unsigned int numberOfNodes()const;
86  virtual unsigned int numberOfEdges()const;
87 
88  //=========================================================================
89 
90  virtual void reserveNodes(unsigned int nbNodes);
91  virtual void reserveEdges(unsigned int nbEdges);
92 
93  //============================================================
94  virtual bool isElement(const node n) const;
95  virtual bool isMetaNode(const node n) const;
96  virtual bool isElement(const edge e) const;
97  virtual bool isMetaEdge(const edge e) const;
98  virtual node addNode();
99  virtual void addNodes(unsigned int nb, std::vector<node>& addedNodes);
100  virtual void addNode(const node);
101  virtual void addNodes(Iterator<node>* nodes);
102  virtual edge addEdge(const node n1, const node n2);
103  virtual void addEdges(const std::vector<std::pair<node, node> >& edges,
104  std::vector<edge>& addedEdges);
105  virtual void addEdge(const edge);
106  virtual void addEdges(Iterator<edge>* edges);
107  virtual void delNode(const tlp::node n, bool deleteInAllGraphs = false);
108  virtual void delNodes(Iterator<node>* itN, bool deleteInAllGraphs);
109  virtual void delEdge(const tlp::edge e, bool deleteInAllGraphs = false);
110  virtual void delEdges(Iterator<edge>* itE, bool deleteInAllGraphs = false);
111  virtual void setEdgeOrder(const node n,const std::vector<edge> & s);
112  virtual void swapEdgeOrder(const node n ,const edge e1, const edge e2);
113 
114  virtual Iterator<node>* getNodes() const;
115  virtual Iterator<node>* getInNodes(const node n) const;
116  virtual Iterator<node>* getOutNodes(const node n) const;
117  virtual Iterator<node>* getInOutNodes(const node n) const;
118  virtual Iterator<node>* bfs(const node root = node()) const;
119  virtual Iterator<node>* dfs(const node root = node()) const;
120  virtual Iterator<edge>* getEdges() const;
121  virtual Iterator<edge>* getOutEdges(const node n) const;
122  virtual Iterator<edge>* getInOutEdges(const node n) const;
123  virtual Iterator<edge>* getInEdges(const node n) const;
124  virtual Iterator<edge>* getEdgeMetaInfo(const edge) const;
125  //============================================================
126  template<typename PropertyType>
127  PropertyType* getProperty(const std::string &name);
128  virtual PropertyInterface* getProperty(const std::string &name) const;
129  virtual bool existProperty(const std::string&name) const;
130  virtual bool existLocalProperty(const std::string&name) const;
131  virtual void delLocalProperty(const std::string&name);
132  virtual void addLocalProperty(const std::string &name, PropertyInterface *prop);
133  virtual Iterator<std::string>* getLocalProperties() const;
134  virtual Iterator<std::string>* getInheritedProperties() const;
135  virtual Iterator<std::string>* getProperties() const;
136  virtual Iterator<PropertyInterface*>* getLocalObjectProperties() const;
137  virtual Iterator<PropertyInterface*>* getInheritedObjectProperties() const;
138  virtual Iterator<PropertyInterface*>* getObjectProperties() const;
139  // updates management
140  virtual void push(bool unpopAllowed = true,
141  std::vector<PropertyInterface*>* propertiesToPreserveOnPop= NULL);
142  virtual void pop(bool unpopAllowed = true);
143  virtual void unpop();
144  virtual bool canPop();
145  virtual bool canUnpop();
146  virtual bool canPopThenUnpop();
147  //============================================================
148 
149  virtual void setName(const std::string &name);
150  virtual std::string getName() const;
151 
152 protected:
153  virtual DataSet & getNonConstAttributes();
154  Graph* graph_component;
155  // designed to reassign an id to a previously deleted elt
156  // called by GraphUpdatesRecorder
157  virtual node restoreNode(node);
158  virtual edge restoreEdge(edge, node source, node target);
159  virtual void restoreNodes(const std::vector<node>&);
160  virtual void restoreEdges(const std::vector<edge>& edges,
161  const std::vector<std::pair<node, node> >& ends);
162  // designed to only update own structures
163  // used by GraphUpdatesRecorder
164  virtual void removeNode(const node);
165  virtual void removeEdge(const edge);
166  // internally used to deal with sub graph deletion
167  virtual void removeSubGraph(Graph*);
168  virtual void clearSubGraphs();
169  virtual void restoreSubGraph(Graph*);
170  virtual void setSubGraphToKeep(Graph*);
171  // internally used for property renaming
172  virtual bool renameLocalProperty(PropertyInterface* prop,
173  const std::string& newName);
174 };
175 
176 //====================================================================================
177 template<typename PropertyType>
178 PropertyType* GraphDecorator::getProperty(const std::string &name) {
179  if (graph_component->existProperty(name)) {
180  tlp::PropertyInterface* prop = graph_component->getProperty(name);
181  assert (dynamic_cast<PropertyType *>(prop)!=NULL);
182  return dynamic_cast<PropertyType *>(prop);
183  }
184  else {
185  return graph_component->getLocalProperty<PropertyType>(name);
186  }
187 }
188 
189 }
190 
191 #endif
192 
193 #endif //DOXYGEN_NOTFOR_DEVEL
194 ///@endcond
PropertyInterface describes the interface of a graph property.
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