Tulip  5.1.0
Large graphs analysis and drawing
GlComposite.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 COMPOSITE_H
21 #define COMPOSITE_H
22 
23 #include <map>
24 #include <list>
25 #include <string>
26 
27 #include <tulip/GlSimpleEntity.h>
28 #include <tulip/tulipconf.h>
29 
30 namespace tlp {
31 
32 /**
33  * @ingroup OpenGL
34  * \brief GlSimpleEntity used to agregate other GlEntity
35  *
36  * This class provide basic container to manage other GlEntity
37  * @see GlSimpleEntity
38  */
39 class TLP_GL_SCOPE GlComposite : public GlSimpleEntity {
40 
41 
42 public:
43 
44  /**
45  * @brief Constructor
46  * @param deleteComponentsInDestructor if true : call delete on components when the GlComposite is delete
47  */
48  GlComposite(bool deleteComponentsInDestructor=true);
49 
50  /**
51  * @brief Destructor
52  */
53  ~GlComposite();
54 
55  /**
56  * @brief Clear the composite
57  *
58  * If deleteElems is true, composite's entities are delete
59  */
60  void reset(bool deleteElems);
61  /**
62  * @brief Add new entity with name : key.
63  *
64  * The composite does not takes the entity's ownership, i.e. it is not its responsibility to delete it.
65  */
66  void addGlEntity(GlSimpleEntity *entity, const std::string &key);
67  /**
68  * @brief Remove entity with name : key
69  *
70  * The entity is not deleted
71  */
72  void deleteGlEntity(const std::string &key,bool informTheEntity=true);
73  /**
74  * @brief Remove given entity
75  *
76  * The entity is not deleted
77  */
78  void deleteGlEntity(GlSimpleEntity *entity,bool informTheEntity=true);
79  /**
80  * @brief Find name of given entity
81  */
82  std::string findKey(GlSimpleEntity *entity);
83  /**
84  * @brief Find entity with name : key
85  */
86  GlSimpleEntity* findGlEntity(const std::string &key);
87  /**
88  * @brief Return map of entities in composite
89  */
90  const std::map<std::string, GlSimpleEntity*> &
91  getGlEntities () const {
92  return elements;
93  }
94 
95  /**
96  * @brief Set stencil number for all composite's children
97  *
98  * For more information on stencil :
99  * @see GlSimpleEntity
100  */
101  virtual void setStencil(int stencil) {
102  this->stencil=stencil;
103 
104  for(std::list<GlSimpleEntity*>::iterator it=_sortedElements.begin(); it!=_sortedElements.end(); ++it) {
105  (*it)->setStencil(stencil);
106  }
107  }
108 
109  /**
110  * @brief Set if at the destruction of composite, components well be deleted
111  */
112  void setDeleteComponentsInDestructor(bool deleteComponentsInDestructor) {
113  this->deleteComponentsInDestructor=deleteComponentsInDestructor;
114  }
115 
116  /**
117  * @brief translate the composite with children
118  */
119  virtual void translate(const Coord &mouvement);
120 
121  /**
122  * @brief Function to export data in outString (in XML format)
123  */
124  virtual void getXML(std::string &outString);
125 
126  /**
127  * @brief Function to set data with inString (in XML format)
128  */
129  virtual void setWithXML(const std::string &inString, unsigned int &currentPosition);
130 
131 ///@cond DOXYGEN_HIDDEN
132 
133  /**
134  * Function used to visit composite's children
135  */
136  virtual void acceptVisitor(GlSceneVisitor *visitor) {
137  //visitor->visit(this);
138  for(std::list<GlSimpleEntity*>::iterator it=_sortedElements.begin(); it!=_sortedElements.end(); ++it) {
139  if((*it)->isVisible()) {
140 
141 #ifndef NDEBUG
142  GlComposite *composite=dynamic_cast<GlComposite*>(*it);
143 
144  if(!composite && !(*it)->getBoundingBox().isValid()) {
145  for(std::map<std::string, GlSimpleEntity*>::iterator itE=elements.begin(); itE!=elements.end(); ++itE) {
146  if(itE->second==(*it)) {
147  tlp::warning() << "Invalid bounding box for entity: " << itE->first << std::endl;
148  assert(false);
149  }
150  }
151  }
152 
153 #endif
154 
155  (*it)->acceptVisitor(visitor);
156  }
157  }
158  }
159 
160  /**
161  * Add a layer parent to this entity
162  */
163  virtual void addLayerParent(GlLayer *layer);
164 
165  /**
166  * Remove a layer parent to this entity
167  */
168  virtual void removeLayerParent(GlLayer *layer);
169 
170  /**
171  * Call when a child of the composite is modified
172  */
173  void notifyModified(GlSimpleEntity *entity);
174 
175  /**
176  * \attention This function do nothing, GlComposite is a GlSimpleEntity so draw function must be define
177  */
178  virtual void draw(float,Camera *) {}
179 
180 ///@endcond
181 
182 protected:
183 
184  std::map<std::string, GlSimpleEntity*> elements;
185  std::list<GlSimpleEntity *> _sortedElements; //necessary to enable ordering of elements (for alpha blending)
186  std::vector<GlLayer *> layerParents;
187  bool deleteComponentsInDestructor;
188 };
189 
190 }
191 #endif
bool isValid() const
Checks whether the bounding box&#39;s lowest point is less than it&#39;s highest point. "Less Than" means axi...
Base class for all Tulip OpenGL entities.
virtual BoundingBox getBoundingBox()
Return the entity boundingbox.
Tulip OpenGL camera object.
Definition: Camera.h:45
void setDeleteComponentsInDestructor(bool deleteComponentsInDestructor)
Set if at the destruction of composite, components well be deleted.
Definition: GlComposite.h:112
GlSimpleEntity used to agregate other GlEntity.
Definition: GlComposite.h:39
virtual void setStencil(int stencil)
Set stencil number for all composite&#39;s children.
Definition: GlComposite.h:101
const std::map< std::string, GlSimpleEntity * > & getGlEntities() const
Return map of entities in composite.
Definition: GlComposite.h:91
A GlLayer is like an 2D drawing software layer system.
Definition: GlLayer.h:51