Tulip  4.4.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 1 and Inria Bordeaux - Sud Ouest
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 /*
23  Author: David Auber
24  Email : auber@labri.fr
25  Last modification : 20/08/2001
26  This program is free software; you can redistribute it and/or modify
27  it under the terms of the GNU General Public License as published by
28  the Free Software Foundation; either version 2 of the License, or
29  (at your option) any later version.
30 */
31 
32 #ifndef Tulip_SUPERGRAPHVIEW_H
33 #define Tulip_SUPERGRAPHVIEW_H
34 
35 #ifndef DOXYGEN_NOTFOR_USER
36 
37 #include <tulip/GraphAbstract.h>
38 #include <tulip/GraphImpl.h>
39 #include <tulip/MutableContainer.h>
40 
41 namespace tlp {
42 
43 /**
44  * This class is one the implementation of the Graph Interface
45  * It only filters the elements of its parents.
46  */
47 class GraphView:public GraphAbstract {
48 
49  friend class GraphImpl;
50 public:
51  GraphView(Graph *supergraph, BooleanProperty *filter, unsigned int id = 0);
52  ~GraphView();
53  //========================================================================
54  node addNode();
55  void addNodes(unsigned int nb, std::vector<node>& addedNodes);
56  void addNode(const node);
57  void addNodes(Iterator<node>* nodes);
58  edge addEdge(const node n1,const node n2);
59  void addEdges(const std::vector<std::pair<node, node> >& edges,
60  std::vector<edge>& addedEdges);
61  void addEdge(const edge);
62  void addEdges(Iterator<edge>* edges);
63  void delNode(const tlp::node n, bool deleteInAllGraphs = false);
64  void delEdge(const tlp::edge e, bool deleteInAllGraphs = false);
65  void setEdgeOrder(const node,const std::vector<edge> & );
66  void swapEdgeOrder(const node,const edge , const edge );
67  //=========================================================================
68  bool isElement(const node ) const;
69  bool isElement(const edge ) const;
70  edge existEdge(const node source, const node target,
71  bool directed) const;
72  unsigned int numberOfNodes() const;
73  unsigned int numberOfEdges() const;
74  //=========================================================================
75  unsigned int deg(const node) const;
76  unsigned int indeg(const node) const;
77  unsigned int outdeg(const node) const;
78  //=========================================================================
79  Iterator<node>* getNodes() const;
80  Iterator<node>* getInNodes(const node) const;
81  Iterator<node>* getOutNodes(const node) const;
82  Iterator<node>* getInOutNodes(const node) const;
83  Iterator<edge>* getEdges() const;
84  Iterator<edge>* getInEdges(const node) const;
85  Iterator<edge>* getOutEdges(const node) const;
86  Iterator<edge>* getInOutEdges(const node) const;
87  std::vector<edge> getEdges(const node source, const node target,
88  bool directed = true) const;
89  //=========================================================================
90  // only implemented on a root graph
91  virtual void reserveNodes(unsigned int nbNodes);
92  virtual void reserveEdges(unsigned int nbEdges);
93  //=========================================================================
94  // updates management
95  virtual void push(bool unpopAllowed = true,
96  std::vector<PropertyInterface*>* propertiesToPreserveOnPop= NULL);
97  virtual void pop(bool unpopAllowed = true);
98  virtual void unpop();
99  virtual bool canPop();
100  virtual bool canUnpop();
101  virtual bool canPopThenUnpop();
102 
103 protected:
104  // designed to reassign an id to a previously deleted elt
105  // used by GraphUpdatesRecorder
106  virtual node restoreNode(node);
107  virtual void restoreNodes(const std::vector<node>&);
108  virtual edge restoreEdge(edge, node source, node target);
109  virtual void restoreEdges(const std::vector<edge>& edges,
110  const std::vector<std::pair<node, node> >& ends);
111  // designed to only update own structures
112  // used by GraphUpdatesRecorder
113  virtual void removeNode(const node);
114  virtual void removeEdge(const edge);
115  void removeNode(const node n, const std::vector<edge>& edges);
116  void removeEdges(const std::vector<edge>& edges);
117 
118 private:
119  MutableContainer<bool> nodeAdaptativeFilter;
120  MutableContainer<bool> edgeAdaptativeFilter;
121  MutableContainer<unsigned int> outDegree;
122  MutableContainer<unsigned int> inDegree;
123  mutable int nNodes;
124  mutable int nEdges;
125  edge addEdgeInternal(edge);
126  void delEdgeInternal(const edge);
127  void delNodeInternal(const node);
128  void reverseInternal(const edge, const node src, const node tgt);
129  void setEndsInternal(const edge, const node src, const node tgt,
130  const node newSrc, const node newTgt);
131 };
132 
133 }
134 #endif
135 
136 #endif
137 
138 
139 
140 ///@endcond