Tulip 5.7.1
Large graphs analysis and drawing
Loading...
Searching...
No Matches
GraphAbstract.h
1/*
2 *
3 * This file is part of Tulip (https://tulip.labri.fr)
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_SUPERGRAPHABSTRACT_H
22#define TULIP_SUPERGRAPHABSTRACT_H
23
24#include <set>
25#include <vector>
26#include <tulip/Graph.h>
27#include <tulip/DataSet.h>
28
29namespace tlp {
30
31template <class C>
32struct Iterator;
33class PropertyManager;
34class GraphProperty;
35
36/// Abstract class for default graph operations.
37class TLP_SCOPE GraphAbstract : public Graph {
38 friend class PropertyManager;
39 DataSet attributes;
40 Graph *supergraph;
41 Graph *const root;
42 std::vector<Graph *> subgraphs;
43 Graph *subGraphToKeep;
44 // pointer to root viewMetaGraph property
45 GraphProperty *metaGraphProperty;
46
47protected:
48 GraphAbstract(Graph *supergraph, unsigned int id = 0);
49
50public:
51 ~GraphAbstract() override;
52 void clear() override;
53 // use to enforce subgraph id
54 Graph *addSubGraph(unsigned int id, BooleanProperty *selection = nullptr,
55 const std::string &name = "unnamed");
56 Graph *addSubGraph(BooleanProperty *selection = nullptr,
57 const std::string &name = "unnamed") override {
58 return addSubGraph(0, selection, name);
59 }
60 void delSubGraph(Graph *) override;
61 void delAllSubGraphs(Graph *) override;
62 inline Graph *getSuperGraph() const override {
63 return supergraph;
64 }
65 inline Graph *getRoot() const override {
66 return root;
67 }
68 Iterator<Graph *> *getSubGraphs() const override;
69 inline const std::vector<Graph *> &subGraphs() const override {
70 return subgraphs;
71 }
72 bool isSubGraph(const Graph *sg) const override;
73 bool isDescendantGraph(const Graph *sg) const override;
74 Graph *getSubGraph(unsigned int id) const override;
75 Graph *getSubGraph(const std::string &name) const override;
76 Graph *getDescendantGraph(unsigned int id) const override;
77 Graph *getDescendantGraph(const std::string &name) const override;
78 Graph *getNthSubGraph(unsigned int n) const override;
79 inline unsigned int numberOfSubGraphs() const override {
80 return subgraphs.size();
81 }
82 unsigned int numberOfDescendantGraphs() const override;
83
84 //=======================================
85 bool isMetaNode(const node) const override;
86 Graph *getNodeMetaInfo(const node) const override;
87 void delNodes(Iterator<node> *itN, bool deleteInAllGraphs) override;
88 bool isMetaEdge(const edge) const override;
89 Iterator<edge> *getEdgeMetaInfo(const edge) const override;
90 void delEdges(Iterator<edge> *itE, bool deleteInAllGraphs = false) override;
91 //=======================================
92 node getOneNode() const override;
93 node getRandomNode() const override;
94 node getInNode(const node, unsigned int) const override;
95 node getOutNode(const node, unsigned int) const override;
96 edge getOneEdge() const override;
97 edge getRandomEdge() const override;
98 //========================================
99 bool existProperty(const std::string &) const override;
100 bool existLocalProperty(const std::string &) const override;
101 void delLocalProperty(const std::string &) override;
102 void addLocalProperty(const std::string &name, PropertyInterface *prop) override;
103 Iterator<std::string> *getLocalProperties() const override;
104 Iterator<std::string> *getInheritedProperties() const override;
105 Iterator<std::string> *getProperties() const override;
106 Iterator<PropertyInterface *> *getLocalObjectProperties() const override;
107 Iterator<PropertyInterface *> *getInheritedObjectProperties() const override;
108 Iterator<PropertyInterface *> *getObjectProperties() const override;
109 PropertyInterface *getProperty(const std::string &) const override;
110
111 // to get viewMetaGraph property
112 GraphProperty *getMetaGraphProperty();
113
114 void setName(const std::string &name) override;
115 std::string getName() const override;
116
117 Iterator<node> *bfs(const node root = node()) const override;
118 Iterator<node> *dfs(const node root = node()) const override;
119
120protected:
121 DataSet &getNonConstAttributes() override {
122 return attributes;
123 }
124 void setSuperGraph(Graph *) override;
125 PropertyManager *propertyContainer;
126 const std::set<edge> &getReferencedEdges(const edge) const;
127
128 bool renameLocalProperty(PropertyInterface *prop, const std::string &newName) override;
129
130 // internally used to deal with sub graph deletion
131 void clearSubGraphs() override;
132 void removeSubGraph(Graph *) override;
133 void restoreSubGraph(Graph *) override;
134 void setSubGraphToKeep(Graph *) override;
135
136private:
137 void delAllSubGraphs();
138 // notification of addition/deletion of inherited properties
139 void notifyBeforeAddInheritedProperty(const std::string &prop);
140 void notifyAddInheritedProperty(const std::string &prop);
141 void notifyBeforeDelInheritedProperty(const std::string &prop);
142 void notifyAfterDelInheritedProperty(const std::string &prop);
143 // notification of property renaming
144 void notifyBeforeRenameLocalProperty(PropertyInterface *prop, const std::string &newName);
145 void notifyAfterRenameLocalProperty(PropertyInterface *prop, const std::string &oldName);
146};
147} // namespace tlp
148#endif
149
150///@endcond