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