Tulip
4.6.0
Better Visualization Through Research
|
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 COMPOSITE_H 00021 #define COMPOSITE_H 00022 00023 #include <map> 00024 #include <list> 00025 #include <string> 00026 00027 #include <tulip/GlSimpleEntity.h> 00028 #include <tulip/tulipconf.h> 00029 00030 namespace tlp { 00031 00032 /** 00033 * @ingroup OpenGL 00034 * \brief GlSimpleEntity used to agregate other GlEntity 00035 * 00036 * This class provide basic container to manage other GlEntity 00037 * @see GlSimpleEntity 00038 */ 00039 class TLP_GL_SCOPE GlComposite : public GlSimpleEntity { 00040 00041 00042 public: 00043 00044 /** 00045 * @brief Constructor 00046 * @param deleteComponentsInDestructor if true : call delete on components when the GlComposite is delete 00047 */ 00048 GlComposite(bool deleteComponentsInDestructor=true); 00049 00050 /** 00051 * @brief Destructor 00052 */ 00053 ~GlComposite(); 00054 00055 /** 00056 * @brief Clear the composite 00057 * 00058 * If deleteElems is true, composite's entities are delete 00059 */ 00060 void reset(bool deleteElems); 00061 /** 00062 * @brief Add new entity with name : key. 00063 * 00064 * The composite does not takes the entity's ownership, i.e. it is not its responsibility to delete it. 00065 */ 00066 void addGlEntity(GlSimpleEntity *entity, const std::string &key); 00067 /** 00068 * @brief Remove entity with name : key 00069 * 00070 * The entity is not deleted 00071 */ 00072 void deleteGlEntity(const std::string &key,bool informTheEntity=true); 00073 /** 00074 * @brief Remove given entity 00075 * 00076 * The entity is not deleted 00077 */ 00078 void deleteGlEntity(GlSimpleEntity *entity,bool informTheEntity=true); 00079 /** 00080 * @brief Find name of given entity 00081 */ 00082 std::string findKey(GlSimpleEntity *entity); 00083 /** 00084 * @brief Find entity with name : key 00085 */ 00086 GlSimpleEntity* findGlEntity(const std::string &key); 00087 /** 00088 * @brief Return map of entities in composite 00089 */ 00090 const std::map<std::string, GlSimpleEntity*> & 00091 getGlEntities () const { 00092 return elements; 00093 } 00094 00095 /** 00096 * @brief Set stencil number for all composite's children 00097 * 00098 * For more information on stencil : 00099 * @see GlSimpleEntity 00100 */ 00101 virtual void setStencil(int stencil) { 00102 this->stencil=stencil; 00103 00104 for(std::list<GlSimpleEntity*>::iterator it=_sortedElements.begin(); it!=_sortedElements.end(); ++it) { 00105 (*it)->setStencil(stencil); 00106 } 00107 } 00108 00109 /** 00110 * @brief Set if at the destruction of composite, components well be deleted 00111 */ 00112 void setDeleteComponentsInDestructor(bool deleteComponentsInDestructor) { 00113 this->deleteComponentsInDestructor=deleteComponentsInDestructor; 00114 } 00115 00116 /** 00117 * @brief translate the composite with children 00118 */ 00119 virtual void translate(const Coord &mouvement); 00120 00121 /** 00122 * @brief Function to export data in outString (in XML format) 00123 */ 00124 virtual void getXML(std::string &outString); 00125 00126 /** 00127 * @brief Function to set data with inString (in XML format) 00128 */ 00129 virtual void setWithXML(const std::string &inString, unsigned int ¤tPosition); 00130 00131 ///@cond DOXYGEN_HIDDEN 00132 00133 /** 00134 * Function used to visit composite's children 00135 */ 00136 virtual void acceptVisitor(GlSceneVisitor *visitor) { 00137 //visitor->visit(this); 00138 for(std::list<GlSimpleEntity*>::iterator it=_sortedElements.begin(); it!=_sortedElements.end(); ++it) { 00139 if((*it)->isVisible()) { 00140 00141 #ifndef NDEBUG 00142 GlComposite *composite=dynamic_cast<GlComposite*>(*it); 00143 00144 if(!composite && !(*it)->getBoundingBox().isValid()) { 00145 for(std::map<std::string, GlSimpleEntity*>::iterator itE=elements.begin(); itE!=elements.end(); ++itE) { 00146 if((*itE).second==(*it)) { 00147 tlp::warning() << "Invalid bounding box for entity : " << (*itE).first << std::endl; 00148 assert(false); 00149 } 00150 } 00151 } 00152 00153 #endif 00154 00155 (*it)->acceptVisitor(visitor); 00156 } 00157 } 00158 } 00159 00160 /** 00161 * Add a layer parent to this entity 00162 */ 00163 virtual void addLayerParent(GlLayer *layer); 00164 00165 /** 00166 * Remove a layer parent to this entity 00167 */ 00168 virtual void removeLayerParent(GlLayer *layer); 00169 00170 /** 00171 * Call when a child of the composite is modified 00172 */ 00173 void notifyModified(GlSimpleEntity *entity); 00174 00175 /** 00176 * \attention This function do nothing, GlComposite is a GlSimpleEntity so draw function must be define 00177 */ 00178 virtual void draw(float,Camera *) {} 00179 00180 ///@endcond 00181 00182 protected: 00183 00184 std::map<std::string, GlSimpleEntity*> elements; 00185 std::list<GlSimpleEntity *> _sortedElements; //necessary to enable ordering of elements (for alpha blending) 00186 std::vector<GlLayer *> layerParents; 00187 bool deleteComponentsInDestructor; 00188 }; 00189 00190 } 00191 #endif