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