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