Tulip  4.3.0
Better Visualization Through Research
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Properties Groups Pages
GlSimpleEntity.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_GLSIMPLEENTITY_H
21 #define Tulip_GLSIMPLEENTITY_H
22 
23 #include <vector>
24 
25 #include <tulip/GlEntity.h>
26 #include <tulip/Coord.h>
27 #include <tulip/GlSceneVisitor.h>
28 #include <tulip/BoundingBox.h>
29 
30 #include <QStringList>
31 #include <QVariantList>
32 
33 namespace tlp {
34 
35 class GlComposite;
36 class Camera;
37 
38 /**
39  * @ingroup OpenGL
40  * @brief Base class for all Tulip OpenGL entities
41  *
42  * Other Tulip entities inherit for this class.
43  *
44  * You don't have to create a GlSimpleEntity, you have to use GlLine, GlRect or GlSphere for example
45  * @see Gl2DRect
46  * @see GlPolygon
47  * @see GlAxis
48  * @see GlBezierCurve
49  * @see GlBox
50  * @see GlCatmullRomCurve
51  * @see GlCircle
52  * @see GlComplexPolygon
53  * @see GlGrid
54  * @see GlHexagon
55  * @see GlLabel
56  * @see GlSphere
57  * @see GlPentagon
58  * @see GlTriangle
59  * @see GlOpenUniformCubicBSpline
60  *
61  * To GlSimpleEntity manipulation :
62  * @see GlLayer
63  * @see GlScene
64  */
65 class TLP_GL_SCOPE GlSimpleEntity : public GlEntity {
66 
67 public:
68 
69  /**
70  * @brief Constructor
71  */
72  GlSimpleEntity():visible(true),stencil(0xFFFF) {}
73 
74  /**
75  * @brief Destructor
76  */
77  virtual ~GlSimpleEntity();
78 
79  /**
80  * @brief Set if entity is visible
81  */
82  virtual void setVisible(bool visible);
83  /**
84  * @brief Return if entity is visible
85  */
86  bool isVisible() const {
87  return visible;
88  }
89  /**
90  * @brief Set stencil number of the entity
91  *
92  * Stencil is an OpenGl system to ensure that other entity can't be displayed above this entity; it's a "guaranted visibility" system.
93  * A small number causes a guaranted visibility
94  * Default value in Tulip is 0xFFFF (greater integer)
95  * And when we have stencil on entity value is 0x2
96  */
97  virtual void setStencil(int stencil) {
98  this->stencil=stencil;
99  }
100  /**
101  * @brief Return stencil number of entity
102  *
103  * @see setStencil()
104  */
105  int getStencil() {
106  return stencil;
107  }
108 
109  /**
110  * @brief Draw function
111  *
112  * @warning You don't have to call this function, the Tulip OpenGL engine call it.
113  */
114  virtual void draw(float lod,Camera* camera) = 0;
115 
116  /**
117  * @brief Return the entity boundingbox
118  *
119  * @warning You don't have to call this function, the Tulip OpenGL engine call it.
120  */
122  return boundingBox;
123  }
124 
125  /**
126  * @brief Save the entity in outString (in XML format)
127  *
128  * @warning You don't have to call this function, the Tulip OpenGL engine call it.
129  */
130  virtual void getXML(std::string &outString) =0;
131 
132  /**
133  * @brief Load entity with inString (in XML format)
134  *
135  * @warning You don't have to call this function, the Tulip OpenGL engine call it.
136  */
137  virtual void setWithXML(const std::string &inString, unsigned int &currentPosition) =0;
138 
139 ///@cond DOXYGEN_HIDDEN
140 
141  /**
142  * @brief Accept visitor function
143  */
144  virtual void acceptVisitor(GlSceneVisitor *visitor) {
145  visitor->visit(this);
146  }
147 
148  /**
149  * Add a parent to this entity
150  */
151  void addParent(GlComposite *composite);
152 
153  /**
154  * remove a parent to this entity
155  */
156  void removeParent(GlComposite *composite);
157 
158  /**
159  * @brief Return properties names for this entity
160  * These properties names are used to dynamically configure the entity
161  * for example these function can be used by Mouse information interactor
162  * If you create a class that inherits of GlSimpleEntity : you can reimplement this function to return your properties names
163  * for example : return QStringList() << "fillColor" << "outlineColor";
164  * @return QList of properties names
165  */
166  virtual QStringList propertiesNames() const;
167 
168  /**
169  * @brief Return properties (in QVariant format) for this entity
170  * These properties QVariant are used to dynamically configure the entity
171  * for example these function can be used by Mouse information interactor
172  * If you create a class that inherits of GlSimpleEntity : you can reimplement this function to return your properties
173  * for example : return QVariantList() << QVariant::fromValue<Color>(getFillColor()) << QVariant::fromValue<Color>(getOutlineColor());
174  * @return QList of properties (in QVariant format)
175  */
176  virtual QVariantList propertiesQVariant() const;
177 
178  /**
179  * @brief Set value for a property previously returned by propertiesNames() and properties() functions
180  * This function is call when we want to set value of a property
181  * this parameter is returned in list by propertiesNames() and properties funtions
182  * If you create a class that inherits of GlSimpleEntity : you can reimplement this function to set your properties
183  * For example :
184  * if(name=="fillColor")
185  * setFillColor(value.value<Color>());
186  * else if(name=="outlineColor")
187  * setOutlineColor(value.value<Color>());
188  */
189  virtual void setProperty(const QString &name, const QVariant &value);
190 
191  /**
192  * virtual fucntion : Translate entity of vector translation
193  */
194  virtual void translate(const Coord &) {}
195 
196  GlComposite* getParent() const {
197  if (parents.empty())
198  return NULL;
199 
200  return parents[0];
201  }
202 
203 ///@endcond
204 
205 protected:
206 
207  bool visible;
208  int stencil;
209 
210  BoundingBox boundingBox;
211 
212  std::vector<GlComposite*> parents;
213 
214 };
215 
216 }
217 
218 #endif // Tulip_GLSIMPLEENTITY_H
219