Tulip  4.1.0
Better Visualization Through Research
 All Classes 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  unsigned int numberOfNodes() const;
71  unsigned int numberOfEdges() const;
72  //=========================================================================
73  unsigned int deg(const node) const;
74  unsigned int indeg(const node) const;
75  unsigned int outdeg(const node) const;
76  //=========================================================================
77  Iterator<node>* getNodes() const;
78  Iterator<node>* getInNodes(const node) const;
79  Iterator<node>* getOutNodes(const node) const;
80  Iterator<node>* getInOutNodes(const node) const;
81  Iterator<edge>* getEdges() const;
82  Iterator<edge>* getInEdges(const node) const;
83  Iterator<edge>* getOutEdges(const node) const;
84  Iterator<edge>* getInOutEdges(const node) const;
85  //=========================================================================
86  // only implemented on a root graph
87  virtual void reserveNodes(unsigned int nbNodes);
88  virtual void reserveEdges(unsigned int nbEdges);
89  //=========================================================================
90  // updates management
91  virtual void push(bool unpopAllowed = true,
92  std::vector<PropertyInterface*>* propertiesToPreserveOnPop= NULL);
93  virtual void pop(bool unpopAllowed = true);
94  virtual void unpop();
95  virtual bool canPop();
96  virtual bool canUnpop();
97  virtual bool canPopThenUnpop();
98 
99 protected:
100  // designed to reassign an id to a previously deleted elt
101  // used by GraphUpdatesRecorder
102  virtual node restoreNode(node);
103  virtual void restoreNodes(const std::vector<node>&);
104  virtual edge restoreEdge(edge, node source, node target);
105  virtual void restoreEdges(const std::vector<edge>& edges,
106  const std::vector<std::pair<node, node> >& ends);
107  // designed to only update own structures
108  // used by GraphUpdatesRecorder
109  virtual void removeNode(const node);
110  virtual void removeEdge(const edge);
111  void removeNode(const node n, const std::vector<edge>& edges);
112  void removeEdges(const std::vector<edge>& edges);
113 
114 private:
115  MutableContainer<bool> nodeAdaptativeFilter;
116  MutableContainer<bool> edgeAdaptativeFilter;
117  MutableContainer<unsigned int> outDegree;
118  MutableContainer<unsigned int> inDegree;
119  mutable int nNodes;
120  mutable int nEdges;
121  edge addEdgeInternal(edge);
122  void delEdgeInternal(const edge);
123  void delNodeInternal(const node);
124  void reverse(const edge, const node src, const node tgt);
125  void setEnds(const edge, const node src, const node tgt,
126  const node newSrc, const node newTgt);
127 };
128 
129 }
130 #endif
131 
132 #endif
133 
134 
135 
136 ///@endcond