Tulip  5.2.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 public:
42  /**
43  * @brief Constructor
44  * @param deleteComponentsInDestructor if true : call delete on components when the GlComposite is
45  * delete
46  */
47  GlComposite(bool deleteComponentsInDestructor = true);
48 
49  /**
50  * @brief Destructor
51  */
52  ~GlComposite() override;
53 
54  /**
55  * @brief Clear the composite
56  *
57  * If deleteElems is true, composite's entities are delete
58  */
59  void reset(bool deleteElems);
60  /**
61  * @brief Add new entity with name : key.
62  *
63  * The composite does not takes the entity's ownership, i.e. it is not its responsibility to
64  * 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 *> &getGlEntities() const {
91  return elements;
92  }
93 
94  /**
95  * @brief Set stencil number for all composite's children
96  *
97  * For more information on stencil :
98  * @see GlSimpleEntity
99  */
100  void setStencil(int stencil) override {
101  this->stencil = stencil;
102 
103  for (std::list<GlSimpleEntity *>::iterator it = _sortedElements.begin();
104  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  void translate(const Coord &mouvement) override;
120 
121  /**
122  * @brief Function to export data in outString (in XML format)
123  */
124  void getXML(std::string &outString) override;
125 
126  /**
127  * @brief Function to set data with inString (in XML format)
128  */
129  void setWithXML(const std::string &inString, unsigned int &currentPosition) override;
130 
131  ///@cond DOXYGEN_HIDDEN
132 
133  /**
134  * Function used to visit composite's children
135  */
136  void acceptVisitor(GlSceneVisitor *visitor) override {
137  // visitor->visit(this);
138  for (std::list<GlSimpleEntity *>::iterator it = _sortedElements.begin();
139  it != _sortedElements.end(); ++it) {
140  if ((*it)->isVisible()) {
141 
142 #ifndef NDEBUG
143  GlComposite *composite = dynamic_cast<GlComposite *>(*it);
144 
145  if (!composite && !(*it)->getBoundingBox().isValid()) {
146  for (std::map<std::string, GlSimpleEntity *>::iterator itE = elements.begin();
147  itE != elements.end(); ++itE) {
148  if (itE->second == (*it)) {
149  tlp::warning() << "Invalid bounding box for entity: " << itE->first << std::endl;
150  assert(false);
151  }
152  }
153  }
154 
155 #endif
156 
157  (*it)->acceptVisitor(visitor);
158  }
159  }
160  }
161 
162  /**
163  * Add a layer parent to this entity
164  */
165  virtual void addLayerParent(GlLayer *layer);
166 
167  /**
168  * Remove a layer parent to this entity
169  */
170  virtual void removeLayerParent(GlLayer *layer);
171 
172  /**
173  * Call when a child of the composite is modified
174  */
175  void notifyModified(GlSimpleEntity *entity);
176 
177  /**
178  * \attention This function do nothing, GlComposite is a GlSimpleEntity so draw function must be
179  * define
180  */
181  void draw(float, Camera *) override {}
182 
183  ///@endcond
184 
185 protected:
186  std::map<std::string, GlSimpleEntity *> elements;
187  std::list<GlSimpleEntity *>
188  _sortedElements; // necessary to enable ordering of elements (for alpha blending)
189  std::vector<GlLayer *> layerParents;
190  bool deleteComponentsInDestructor;
191 };
192 }
193 #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.
void setStencil(int stencil) override
Set stencil number for all composite&#39;s children.
Definition: GlComposite.h:100
Tulip OpenGL camera object.
Definition: Camera.h:47
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
A GlLayer is like an 2D drawing software layer system.
Definition: GlLayer.h:54
const std::map< std::string, GlSimpleEntity * > & getGlEntities() const
Return map of entities in composite.
Definition: GlComposite.h:90