Tulip  5.3.1
Large graphs analysis and drawing
GlLayer.h
1 /*
2  *
3  * This file is part of Tulip (http://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 
20 #ifndef Tulip_GLLAYER_H
21 #define Tulip_GLLAYER_H
22 
23 #include <tulip/tulipconf.h>
24 #include <tulip/GlComposite.h>
25 
26 namespace tlp {
27 
28 class Graph;
29 class GlScene;
30 class GlSceneVisitor;
31 class GlGraphComposite;
32 
33 /**
34  * @ingroup OpenGL
35  * @brief A GlLayer is like an 2D drawing software layer system
36  *
37  * A layer is an entity with a Camera and a GlComposite to store GlEntity
38  * Layers are used with GlScene : you can add a layer to a scene and a scene can have many layers
39  * @see Camera
40  * @see GlComposite
41  * @see GlSimpleEntity
42  * @see GlScene
43  *
44  *
45  * You have two constructor for GlLayer : one with a camera pointer and one without
46  * The constructor without camera pointer create a layer with a new camera and delete this camera at
47  * the destruction
48  * The constructor with camera pointer create a layer and use the camera pointer but you have the
49  * responsibility of camera destruction
50  *
51  * After you have created a layer, you can populate the layer with GlEntity and addGlEntity()
52  * functions
53  */
54 class TLP_GL_SCOPE GlLayer {
55 
56 public:
57  /**
58  * @brief Layer constructor : construct a layer with his name
59  * A new camera is created for this layer and this camera will be deleted in the GlLayer
60  * destructor
61  * @param name layer name
62  * @param workingLayer a working layer is not displayed on overview
63  */
64  GlLayer(const std::string &name, bool workingLayer = false);
65 
66  /**
67  * @brief Layer constructor : construct a layer with his name and use the camera : camera
68  * You have the responsibility of camera destruction
69  * @param name layer name
70  * @param camera camera to use in this layer
71  * @param workingLayer a working layer is not displayed on overview
72  */
73  GlLayer(const std::string &name, Camera *camera, bool workingLayer = false);
74 
75  /**
76  * @brief Destructor
77  */
78  ~GlLayer();
79 
80  /**
81  * @brief Return the scene where the layer is
82  */
84  return scene;
85  }
86 
87  /**
88  * @brief Return the layer's name
89  */
90  std::string getName() {
91  return name;
92  }
93 
94  /**
95  * @brief Set the layer's camera
96  * GlLayer now use a copy of the camera parameters
97  */
98  void setCamera(Camera *camera);
99 
100  /**
101  * Set the layer's camera
102  * GlLayer now use camera parameters and you have the resposibility of camera destruction
103  */
104  void setSharedCamera(Camera *camera);
105 
106  /**
107  * @brief Replace the layer's camera with a new 2D one
108  */
109  void set2DMode();
110 
111  /**
112  * @brief Return the layer's camera
113  */
115  return *camera;
116  }
117 
118  /**
119  * @brief Set if the layer is visible
120  */
121  void setVisible(bool visible);
122 
123  /**
124  * @brief Return if the layer is visible
125  */
126  bool isVisible() {
127  return composite.isVisible();
128  }
129 
130  /**
131  * @brief Add an entity to GlComposite of the layer
132  */
133  void addGlEntity(GlSimpleEntity *entity, const std::string &name);
134 
135  /**
136  * @brief A Convienience function that adds a graph to the layer
137  *
138  * This method will automatically create a GlGraphComposite entity and add it to the layer.
139  */
140  void addGraph(tlp::Graph *graph, const std::string &name);
141 
142  /**
143  * @brief Remove entity with name : key
144  * This entity is not deleted
145  */
146  void deleteGlEntity(const std::string &key);
147 
148  /**
149  * @brief Remove entity
150  * This entity is not deleted
151  */
152  void deleteGlEntity(GlSimpleEntity *entity);
153 
154  /**
155  * @brief Return entity with name : key
156  */
157  GlSimpleEntity *findGlEntity(const std::string &key);
158 
159  /**
160  * @brief Return the map of layer's entities
161  */
162  const std::map<std::string, GlSimpleEntity *> &getGlEntities() const;
163 
164  /**
165  * @brief Return the GlComposite used by the layer
166  * A GlLayer is only a container of a camera and a composite, so to manipulate GlEntity on this
167  * layer you can get the GlComposite and add/remove entities on this composite
168  */
170  return &composite;
171  }
172 
173  /**
174  * @brief Remove all entities of the layer
175  * Entities are not deleted so before call this function you have to get the entities list and you
176  * have the responsibility of entities destruction
177  */
178  void clear() {
179  composite.reset(false);
180  }
181 
182  /**
183  * @brief Return if this layer is a working layer
184  * A working layer is not displayed on overview
185  */
187  return workingLayer;
188  }
189 
190  /**
191  * @brief Return if this layer use a shared camera
192  * A shared camera is a camera used by more than one Layer, so if this layer use a shared camera
193  * we don't have to delete it when the layer is destroyed
194  */
196  return sharedCamera;
197  }
198 
199  /**
200  * Get XML description of the layer and children and store it in out string
201  */
202  void getXML(std::string &outString);
203 
204  /**
205  * @brief Get XML description of cameras of the layer and store it in out string
206  */
207  void getXMLOnlyForCameras(std::string &outString);
208 
209  /**
210  * @brief Function to set data with inString (in XML format)
211  */
212  void setWithXML(const std::string &inString, unsigned int &currentPosition);
213 
214  ///@cond DOXYGEN_HIDDEN
215 
216  /**
217  * This function is automaticaly call when a GlGraphComposite is added in this layer
218  * You don't have to call this function
219  */
220  void glGraphCompositeAdded(GlGraphComposite *composite);
221 
222  /**
223  * This function is automaticaly call when a GlGraphComposite is removed in this layer
224  * You don't have to call this function
225  */
226  void glGraphCompositeRemoved(GlGraphComposite *composite);
227 
228  /**
229  * function used by visitors to visit this layer
230  */
231  void acceptVisitor(GlSceneVisitor *visitor);
232 
233  ///@endcond
234 
235 protected:
236  /**
237  * Set the scene where the layer is
238  */
239  void setScene(GlScene *scene);
240 
241 private:
242  std::string name;
243 
244  GlComposite composite;
245  GlScene *scene;
246 
247  Camera *camera;
248  bool sharedCamera;
249 
250  bool workingLayer;
251 
252  friend class GlScene;
253 };
254 } // namespace tlp
255 
256 #endif // Tulip_GLLAYER_H
std::string getName()
Return the layer&#39;s name.
Definition: GlLayer.h:90
Base class for all Tulip OpenGL entities.
bool isAWorkingLayer()
Return if this layer is a working layer A working layer is not displayed on overview.
Definition: GlLayer.h:186
GlComposite * getComposite()
Return the GlComposite used by the layer A GlLayer is only a container of a camera and a composite...
Definition: GlLayer.h:169
bool isVisible()
Return if the layer is visible.
Definition: GlLayer.h:126
Camera & getCamera()
Return the layer&#39;s camera.
Definition: GlLayer.h:114
Tulip scene class.
Definition: GlScene.h:160
void clear()
Remove all entities of the layer Entities are not deleted so before call this function you have to ge...
Definition: GlLayer.h:178
Tulip OpenGL camera object.
Definition: Camera.h:47
bool useSharedCamera()
Return if this layer use a shared camera A shared camera is a camera used by more than one Layer...
Definition: GlLayer.h:195
Class use to visualize graph in OpenGL Tulip engine.
GlSimpleEntity used to agregate other GlEntity.
Definition: GlComposite.h:39
A GlLayer is like an 2D drawing software layer system.
Definition: GlLayer.h:54
GlScene * getScene()
Return the scene where the layer is.
Definition: GlLayer.h:83