Tulip  4.6.0
Better Visualization Through Research
library/tulip-ogl/include/tulip/GlLayer.h
00001 /*
00002  *
00003  * This file is part of Tulip (www.tulip-software.org)
00004  *
00005  * Authors: David Auber and the Tulip development Team
00006  * from LaBRI, University of Bordeaux
00007  *
00008  * Tulip is free software; you can redistribute it and/or modify
00009  * it under the terms of the GNU Lesser General Public License
00010  * as published by the Free Software Foundation, either version 3
00011  * of the License, or (at your option) any later version.
00012  *
00013  * Tulip is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00016  * See the GNU General Public License for more details.
00017  *
00018  */
00019 
00020 #ifndef Tulip_GLLAYER_H
00021 #define Tulip_GLLAYER_H
00022 
00023 #include <tulip/tulipconf.h>
00024 #include <tulip/GlComposite.h>
00025 
00026 namespace tlp {
00027 
00028 class Graph;
00029 class GlScene;
00030 class GlSceneVisitor;
00031 class GlGraphComposite;
00032 
00033 /**
00034  * @ingroup OpenGL
00035  * @brief A GlLayer is like an 2D drawing software layer system
00036  *
00037  * A layer is an entity with a Camera and a GlComposite to store GlEntity
00038  * Layers are used with GlScene : you can add a layer to a scene and a scene can have many layers
00039  * @see Camera
00040  * @see GlComposite
00041  * @see GlSimpleEntity
00042  * @see GlScene
00043  *
00044  *
00045  * You have two constructor for GlLayer : one with a camera pointer and one without
00046  * The constructor without camera pointer create a layer with a new camera and delete this camera at the destruction
00047  * The constructor with camera pointer create a layer and use the camera pointer but you have the responsibility of camera destruction
00048  *
00049  * After you have created a layer, you can populate the layer with GlEntity and addGlEntity() functions
00050  */
00051 class TLP_GL_SCOPE GlLayer {
00052 
00053 public:
00054 
00055   /**
00056    * @brief Layer constructor : construct a layer with his name
00057    * A new camera is created for this layer and this camera will be deleted in the GlLayer destructor
00058    * @param name layer name
00059    * @param workingLayer a working layer is not displayed on overview
00060    */
00061   GlLayer(const std::string& name,bool workingLayer=false);
00062 
00063   /**
00064    * @brief Layer constructor : construct a layer with his name and use the camera : camera
00065    * You have the responsibility of camera destruction
00066    * @param name layer name
00067    * @param camera camera to use in this layer
00068    * @param workingLayer a working layer is not displayed on overview
00069    */
00070   GlLayer(const std::string& name,Camera *camera,bool workingLayer=false);
00071 
00072   /**
00073    * @brief Destructor
00074    */
00075   ~GlLayer();
00076 
00077   /**
00078    * @brief Return the scene where the layer is
00079    */
00080   GlScene *getScene() {
00081     return scene;
00082   }
00083 
00084   /**
00085    * @brief Return the layer's name
00086    */
00087   std::string getName() {
00088     return name;
00089   }
00090 
00091   /**
00092    * @brief Set the layer's camera
00093    * GlLayer now use a copy of the camera parameters
00094    */
00095   void setCamera(Camera* camera);
00096 
00097   /**
00098    * Set the layer's camera
00099    * GlLayer now use camera parameters and you have the resposibility of camera destruction
00100    */
00101   void setSharedCamera(Camera *camera);
00102 
00103   /**
00104    * @brief Replace the layer's camera with a new 2D one
00105    */
00106   void set2DMode();
00107 
00108   /**
00109    * @brief Return the layer's camera
00110    */
00111   Camera &getCamera() {
00112     return *camera;
00113   }
00114 
00115   /**
00116    * @brief Set if the layer is visible
00117    */
00118   void setVisible(bool visible);
00119 
00120   /**
00121    * @brief Return if the layer is visible
00122    */
00123   bool isVisible() {
00124     return composite.isVisible();
00125   }
00126 
00127   /**
00128    * @brief Add an entity to GlComposite of the layer
00129    */
00130   void addGlEntity(GlSimpleEntity *entity,const std::string& name);
00131 
00132   /**
00133    * @brief A Convienience function that adds a graph to the layer
00134    *
00135    * This method will automatically create a GlGraphComposite entity and add it to the layer.
00136    */
00137   void addGraph(tlp::Graph* graph, const std::string& name);
00138 
00139   /**
00140    * @brief Remove entity with name : key
00141    * This entity is not deleted
00142    */
00143   void deleteGlEntity(const std::string &key);
00144 
00145   /**
00146    * @brief Remove entity
00147    * This entity is not deleted
00148    */
00149   void deleteGlEntity(GlSimpleEntity *entity);
00150 
00151   /**
00152    * @brief Return entity with name : key
00153    */
00154   GlSimpleEntity* findGlEntity(const std::string &key);
00155 
00156   /**
00157    * @brief Return the map of layer's entities
00158    */
00159   const std::map<std::string, GlSimpleEntity*> &getGlEntities() const;
00160 
00161   /**
00162    * @brief Return the GlComposite used by the layer
00163    * 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
00164    */
00165   GlComposite *getComposite() {
00166     return &composite;
00167   }
00168 
00169   /**
00170    * @brief Remove all entities of the layer
00171    * Entities are not deleted so before call this function you have to get the entities list and you have the responsibility of entities destruction
00172    */
00173   void clear() {
00174     composite.reset(false);
00175   }
00176 
00177   /**
00178    * @brief Return if this layer is a working layer
00179    * A working layer is not displayed on overview
00180    */
00181   bool isAWorkingLayer() {
00182     return workingLayer;
00183   }
00184 
00185   /**
00186    * @brief Return if this layer use a shared camera
00187    * 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
00188    */
00189   bool useSharedCamera() {
00190     return sharedCamera;
00191   }
00192 
00193   /**
00194    * Get XML description of the layer and children and store it in out string
00195    */
00196   void getXML(std::string &outString);
00197 
00198   /**
00199    * @brief Get XML description of cameras of the layer and store it in out string
00200    */
00201   void getXMLOnlyForCameras(std::string &outString);
00202 
00203   /**
00204    * @brief Function to set data with inString (in XML format)
00205    */
00206   void setWithXML(const std::string &inString, unsigned int &currentPosition);
00207 
00208 ///@cond DOXYGEN_HIDDEN
00209 
00210   /**
00211    * This function is automaticaly call when a GlGraphComposite is added in this layer
00212    * You don't have to call this function
00213    */
00214   void glGraphCompositeAdded(GlGraphComposite *composite);
00215 
00216   /**
00217    * This function is automaticaly call when a GlGraphComposite is removed in this layer
00218    * You don't have to call this function
00219    */
00220   void glGraphCompositeRemoved(GlGraphComposite *composite);
00221 
00222   /**
00223    * function used by visitors to visit this layer
00224    */
00225   void acceptVisitor(GlSceneVisitor *visitor);
00226 
00227 ///@endcond
00228 
00229 protected :
00230 
00231   /**
00232    * Set the scene where the layer is
00233    */
00234   void setScene(GlScene *scene);
00235 
00236 private:
00237 
00238   std::string name;
00239 
00240   GlComposite composite;
00241   GlScene *scene;
00242 
00243   Camera *camera;
00244   bool sharedCamera;
00245 
00246   bool workingLayer;
00247 
00248   friend class GlScene;
00249 
00250 };
00251 
00252 }
00253 
00254 #endif // Tulip_GLLAYER_H
 All Classes Files Functions Variables Enumerations Enumerator Properties