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