Tulip  4.10.0
Better Visualization Through Research
GraphView.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 Tulip_SUPERGRAPHVIEW_H
22 #define Tulip_SUPERGRAPHVIEW_H
23 
24 #include <tulip/GraphAbstract.h>
25 #include <tulip/GraphImpl.h>
26 #include <tulip/MutableContainer.h>
27 
28 namespace tlp {
29 
30 /**
31  * This class is one the implementation of the Graph Interface
32  * It only filters the elements of its parents.
33  */
34 class GraphView:public GraphAbstract {
35 
36  friend class GraphImpl;
37 public:
38  GraphView(Graph *supergraph, BooleanProperty *filter, unsigned int id = 0);
39  ~GraphView();
40  //========================================================================
41  node addNode();
42  void addNodes(unsigned int nb, std::vector<node>& addedNodes);
43  void addNode(const node);
44  void addNodes(Iterator<node>* nodes);
45  edge addEdge(const node n1,const node n2);
46  void addEdges(const std::vector<std::pair<node, node> >& edges,
47  std::vector<edge>& addedEdges);
48  void addEdge(const edge);
49  void addEdges(Iterator<edge>* edges);
50  void delNode(const tlp::node n, bool deleteInAllGraphs = false);
51  void delEdge(const tlp::edge e, bool deleteInAllGraphs = false);
52  void setEdgeOrder(const node,const std::vector<edge> & );
53  void swapEdgeOrder(const node,const edge , const edge );
54  //=========================================================================
55  bool isElement(const node ) const;
56  bool isElement(const edge ) const;
57  edge existEdge(const node source, const node target,
58  bool directed) const;
59  unsigned int numberOfNodes() const;
60  unsigned int numberOfEdges() const;
61  //=========================================================================
62  unsigned int deg(const node) const;
63  unsigned int indeg(const node) const;
64  unsigned int outdeg(const node) const;
65  //=========================================================================
66  Iterator<node>* getNodes() const;
67  Iterator<node>* getInNodes(const node) const;
68  Iterator<node>* getOutNodes(const node) const;
69  Iterator<node>* getInOutNodes(const node) const;
70  Iterator<edge>* getEdges() const;
71  Iterator<edge>* getInEdges(const node) const;
72  Iterator<edge>* getOutEdges(const node) const;
73  Iterator<edge>* getInOutEdges(const node) const;
74  std::vector<edge> getEdges(const node source, const node target,
75  bool directed = true) const;
76  //=========================================================================
77  // only implemented on a root graph
78  virtual void reserveNodes(unsigned int nbNodes);
79  virtual void reserveEdges(unsigned int nbEdges);
80  //=========================================================================
81  // updates management
82  virtual void push(bool unpopAllowed = true,
83  std::vector<PropertyInterface*>* propertiesToPreserveOnPop= NULL);
84  virtual void pop(bool unpopAllowed = true);
85  virtual void unpop();
86  virtual bool canPop();
87  virtual bool canUnpop();
88  virtual bool canPopThenUnpop();
89 
90 protected:
91  // designed to reassign an id to a previously deleted elt
92  // used by GraphUpdatesRecorder
93  virtual node restoreNode(node);
94  virtual void restoreNodes(const std::vector<node>&);
95  virtual edge restoreEdge(edge, node source, node target);
96  virtual void restoreEdges(const std::vector<edge>& edges,
97  const std::vector<std::pair<node, node> >& ends);
98  // designed to only update own structures
99  // used by GraphUpdatesRecorder
100  virtual void removeNode(const node);
101  virtual void removeEdge(const edge);
102  void removeNode(const node n, const std::vector<edge>& edges);
103  void removeEdges(const std::vector<edge>& edges);
104 
105 private:
106  MutableContainer<bool> nodeAdaptativeFilter;
107  MutableContainer<bool> edgeAdaptativeFilter;
108  MutableContainer<unsigned int> outDegree;
109  MutableContainer<unsigned int> inDegree;
110  mutable int nNodes;
111  mutable int nEdges;
112  edge addEdgeInternal(edge);
113  void reverseInternal(const edge, const node src, const node tgt);
114  void setEndsInternal(const edge, const node src, const node tgt,
115  const node newSrc, const node newTgt);
116 };
117 
118 }
119 #endif
120 
121 ///@endcond
Interface for Tulip iterators. Allows basic iteration operations only.
Definition: Iterator.h:39
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