Code_TYMPAN  4.2.0
Industrial site acoustic simulation
TYElementGraphic.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) <2012> <EDF-R&D> <FRANCE>
3  * This program is free software; you can redistribute it and/or modify
4  * it under the terms of the GNU General Public License as published by
5  * the Free Software Foundation; either version 2 of the License, or
6  * (at your option) any later version.
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10  * See the GNU General Public License for more details.
11  * You should have received a copy of the GNU General Public License along
12  * with this program; if not, write to the Free Software Foundation, Inc.,
13  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
14 */
15 
34 
35 #include "TYElementGraphic.h"
36 
37 #define IMG(id) OLocalizator::getPicture("TYElementGraphic", (id))
38 
40 
43 
44 
46 {
47  _pElement = pElt;
48 
49  _modified = true;
50  _visible = true;
51  _highlight = false;
52  _texture = false;
53  _bFirstDisp = true;
54 
55  // Highlight
56  _viewOnlyHighlight = false;
57 }
58 
60 {
61 }
62 
64 {
65  _pElement = pElt;
66 }
67 
69 {
70  TYElement* pParent = _pElement->getParent();
71 
72  if (getModified() && pParent && pParent->getGraphicObject())
73  {
74  // On force la mise a jour du parent
75  pParent->setIsGeometryModified(true);
76  // On remonte l'arbre
77  pParent->getGraphicObject()->updateTree();
78  }
79  else
80  {
81  // On appelle la methode update surchargee par les objets graphiques
82  update();
83  }
84 }
85 
86 void TYElementGraphic::update(bool force /*=false*/)
87 {
89 
90  if (_pElement)
91  {
93  {
95  }
96  else
97  {
98  _visible = false;
99  }
100  }
101 
102  // Update highlight seulement si actif
104 
105  // On repositionne le flag modified
106  setModified(false);
107 
108 #if TY_USE_IHM
109  // Emission du signal de notification de mise a jour
110  activateSignal();
111 #endif // TY_USE_IHM
112 }
113 
114 bool TYElementGraphic::getModified(bool andReset /*=false*/)
115 {
116  bool ret = _modified;
117 
118  if (andReset)
119  {
120  setModified(false);
121  }
122 
123  return ret;
124 }
125 
126 void TYElementGraphic::highlight(bool state /*=true*/)
127 {
128  // Update
129  _highlight = state;
130 }
131 
133 {
134  OVector3D n = normal; //getElement()->_normale;
135  OPoint3D p2;
136  p2._x = p1._x + n._x;
137  p2._y = p1._y + n._y;
138  p2._z = p1._z + n._z;
139  glColor3f(1.0f, 0.5f, 0.0f);
140  glLineWidth(2);
141  glPointSize(4);
142 
143  glBegin(GL_LINE_STRIP);
144  glVertex3f(p1._x, p1._y, p1._z);
145  glVertex3f(p2._x, p2._y, p2._z);
146  glEnd();
147 }
148 
150 {
151  float org[3];
152  org[0] = (_boundingBox._min._x + _boundingBox._max._x) / 2;
153  org[1] = (_boundingBox._min._y + _boundingBox._max._y) / 2;
154  org[2] = (_boundingBox._min._z + _boundingBox._max._z) / 2;
155 
156  //Ajout de 0.1 contre bug faces coplanaires
157  // CLM-NT33 : agrandit la bb avec un % de la taille
158  //double x = 5 + (_boundingBox._max._x - _boundingBox._min._x)/2;
159  //double y = 5 + (_boundingBox._max._y - _boundingBox._min._y)/2;
160  //double z = 5 + (_boundingBox._max._z - _boundingBox._min._z)/2;
161  //OPoint3D d = _boundingBox._max - _boundingBox._min;
162  double x = (_boundingBox._max._x - _boundingBox._min._x) * 1.1f / 2;
163  double y = (_boundingBox._max._y - _boundingBox._min._y) * 1.1f / 2;
164  double z = (_boundingBox._max._z - _boundingBox._min._z) * 1.1f / 2;
165 
166  glColor3f(1.0f, 1.0f, 0.5f);
167  glLineWidth(2);
168  glPointSize(4);
169 
170  glBegin(GL_LINE_LOOP);
171  glVertex3f(org[0] + x, org[1] - y, org[2] - z);
172  glVertex3f(org[0] - x, org[1] - y, org[2] - z);
173  glVertex3f(org[0] - x, org[1] + y, org[2] - z);
174  glVertex3f(org[0] + x, org[1] + y, org[2] - z);
175  glEnd();
176  glBegin(GL_LINE_LOOP);
177  glVertex3f(org[0] + x, org[1] - y, org[2] + z);
178  glVertex3f(org[0] - x, org[1] - y, org[2] + z);
179  glVertex3f(org[0] - x, org[1] + y, org[2] + z);
180  glVertex3f(org[0] + x, org[1] + y, org[2] + z);
181  glEnd();
182  glBegin(GL_LINE_STRIP);
183  glVertex3f(org[0] + x, org[1] - y, org[2] - z);
184  glVertex3f(org[0] + x, org[1] - y, org[2] + z);
185  glEnd();
186  glBegin(GL_LINE_STRIP);
187  glVertex3f(org[0] - x, org[1] - y, org[2] - z);
188  glVertex3f(org[0] - x, org[1] - y, org[2] + z);
189  glEnd();
190  glBegin(GL_LINE_STRIP);
191  glVertex3f(org[0] - x, org[1] + y, org[2] - z);
192  glVertex3f(org[0] - x, org[1] + y, org[2] + z);
193  glEnd();
194  glBegin(GL_LINE_STRIP);
195  glVertex3f(org[0] + x, org[1] + y, org[2] - z);
196  glVertex3f(org[0] + x, org[1] + y, org[2] + z);
197  glEnd();
198  glBegin(GL_POINTS);
199  glVertex3f(org[0] + x, org[1] - y, org[2] - z);
200  glVertex3f(org[0] - x, org[1] - y, org[2] - z);
201  glVertex3f(org[0] - x, org[1] + y, org[2] - z);
202  glVertex3f(org[0] + x, org[1] + y, org[2] - z);
203  glVertex3f(org[0] + x, org[1] - y, org[2] + z);
204  glVertex3f(org[0] - x, org[1] - y, org[2] + z);
205  glVertex3f(org[0] - x, org[1] + y, org[2] + z);
206  glVertex3f(org[0] + x, org[1] + y, org[2] + z);
207  glEnd();
208 }
209 
211 {
213 
214  //pour determiner la position du texte, il faut le centre de la boundingbox dans le repere global
215  NxVec3 origin;
216  float org[3];
217  org[0] = (_boundingBox._min._x + _boundingBox._max._x) / 2;
218  org[1] = (_boundingBox._min._y + _boundingBox._max._y) / 2;
219  org[2] = (_boundingBox._min._z + _boundingBox._max._z) / 2;
220  if (pThisGeoNode)
221  {
222  OMatrix mat = pThisGeoNode->localToGlobal();
223  origin = NxVec3(mat._m[0][3] + org[0], mat._m[2][3] + org[2], -mat._m[1][3] - org[1]);
224  }
225  else
226  {
227  origin = NxVec3(org[0], org[2], -org[1]);
228  }
229  NxVec3 ret = OGLCamera::worldToDisplay(origin);
230 
231  //ajouter une etiquette avec le nom
232  OGLTextElement oOGLTextElement;
233  oOGLTextElement.setFont(IMG("id_font"));
234  oOGLTextElement.setVisibility(true);
235  if (_pElement)
236  {
237  oOGLTextElement.setTextToDisplay(_pElement->getName());
238  }
239  oOGLTextElement.setColor(OColor::BLACK);
240  oOGLTextElement.setDisplayPosition(ret.x + 22, ret.y + 40);
241  oOGLTextElement.render();
242 
243  OGLLineElement oglLineElement;
244  oglLineElement.setColor(OColor::BLACK);
245  oglLineElement.setLineWidth(2.0f);
246  oglLineElement.setPoint1(OPoint3D(ret.x, ret.y, 0));
247  oglLineElement.setPoint2(OPoint3D(ret.x + 20, ret.y + 40, 0));
248  oglLineElement.setVisibility(true);
249  oglLineElement.render();
250 }
251 
253 {
254  float org[3];
255  org[0] = (_boundingBox._min._x + _boundingBox._max._x) / 2;
256  org[1] = (_boundingBox._min._y + _boundingBox._max._y) / 2;
257  org[2] = (_boundingBox._min._z + _boundingBox._max._z) / 2;
258 
259  //Ajout de 0.1 contre bug faces coplanaires
260  double x = 0.1 + (_boundingBox._max._x - _boundingBox._min._x) / 2;
261  double y = 0.1 + (_boundingBox._max._y - _boundingBox._min._y) / 2;
262  double z = 0.1 + (_boundingBox._max._z - _boundingBox._min._z) / 2;
263 
264  glColor4f(1.0f, 1.0f, 0.0f, 0.1f);
265 
266  glBegin(GL_QUADS);
267 
268  glVertex3d(org[0] + x, org[1] + y, org[2] - z);
269  glVertex3d(org[0] - x, org[1] + y, org[2] - z);
270  glVertex3d(org[0] - x, org[1] + y, org[2] + z);
271  glVertex3d(org[0] + x, org[1] + y, org[2] + z);
272 
273  glVertex3f(org[0] + x, org[1] - y, org[2] + z);
274  glVertex3f(org[0] - x, org[1] - y, org[2] + z);
275  glVertex3f(org[0] - x, org[1] - y, org[2] - z);
276  glVertex3f(org[0] + x, org[1] - y, org[2] - z);
277 
278  glVertex3f(org[0] + x, org[1] + y, org[2] + z);
279  glVertex3f(org[0] - x, org[1] + y, org[2] + z);
280  glVertex3f(org[0] - x, org[1] - y, org[2] + z);
281  glVertex3f(org[0] + x, org[1] - y, org[2] + z);
282 
283  glVertex3f(org[0] + x, org[1] - y, org[2] - z);
284  glVertex3f(org[0] - x, org[1] - y, org[2] - z);
285  glVertex3f(org[0] - x, org[1] + y, org[2] - z);
286  glVertex3f(org[0] + x, org[1] + y, org[2] - z);
287 
288  glVertex3f(org[0] - x, org[1] + y, org[2] + z);
289  glVertex3f(org[0] - x, org[1] + y, org[2] - z);
290  glVertex3f(org[0] - x, org[1] - y, org[2] - z);
291  glVertex3f(org[0] - x, org[1] - y, org[2] + z);
292 
293  glVertex3f(org[0] + x, org[1] + y, org[2] - z);
294  glVertex3f(org[0] + x, org[1] + y, org[2] + z);
295  glVertex3f(org[0] + x, org[1] - y, org[2] + z);
296  glVertex3f(org[0] + x, org[1] - y, org[2] - z);
297 
298  glEnd();
299 }
300 void TYElementGraphic::glVertex3fAndEnlargeBB(GLfloat x, GLfloat y, GLfloat z)
301 {
302  glVertex3f(x, y, z);
303  _boundingBox.Enlarge((float)x, (float)y, (float)z);
304 }
305 
306 void TYElementGraphic::glVertex3dAndEnlargeBB(GLdouble x, GLdouble y, GLdouble z)
307 {
308  glVertex3d(x, y, z);
309  _boundingBox.Enlarge((float)x, (float)y, (float)z);
310 }
311 
313  GLUquadric* qobj,
314  GLdouble innerRadius,
315  GLdouble outerRadius,
316  GLint slices,
317  GLint loops)
318 {
319  gluDisk(qobj, innerRadius, outerRadius, slices, loops);
320 }
321 
323  GLUquadric* qobj,
324  GLdouble baseRadius,
325  GLdouble topRadius,
326  GLdouble height,
327  GLint slices,
328  GLint stacks)
329 {
330  gluCylinder(qobj, baseRadius, topRadius, height, slices, stacks);
331 }
332 
334  GLUquadric* qobj,
335  GLdouble innerRadius,
336  GLdouble outerRadius,
337  GLint slices,
338  GLint loops,
339  GLdouble startAngle,
340  GLdouble sweepAngle)
341 {
342  gluPartialDisk(qobj, innerRadius, outerRadius, slices, loops, startAngle, sweepAngle);
343 }
344 
345 
347 {
348  return _highlight;
349 }
350 
351 void TYElementGraphic::viewOnlyHighlight(bool state /*=true*/)
352 {
353  _viewOnlyHighlight = state;
354 
355  // Active le highlight
357 }
358 
359 void TYElementGraphic::display(GLenum mode /*= GL_RENDER*/)
360 {
361  OBox reset;
362  _boundingBox = reset;
363 #if TY_USE_IHM
364  // Emission du signal de notification de mise a jour
365  activateSignal();
366 
367 #endif // TY_USE_IHM
368 }
369 
370 void TYElementGraphic::setRecursiveVisible(bool visible /*=true*/)
371 {
372  LPTYElementArray childs;
373 
374  _pElement->getChilds(childs);
375 
376  for (int i = 0; i < childs.size(); i++)
377  {
378  childs[i]->getGraphicObject()->setVisible(visible);
379  }
380 }
381 
382 
384 {
385  OBox reset;
386  _boundingBox = reset;
387 
389  getChilds(childs, false);
390  TYListPtrTYElementGraphic::iterator ite;
391  OBox boundingBox;
392  TYElementGraphic* pChild = NULL;
393  for (ite = childs.begin(); ite != childs.end(); ite++)
394  {
395  pChild = (*ite);
396  if (pChild != NULL)
397  {
398  pChild->computeBoundingBox();
399  boundingBox = pChild->GetBox();
400  }
401  _boundingBox.Enlarge(boundingBox);
402  }
403 }
static const OColor BLACK
Definition: color.h:86
The 3D vector class.
Definition: 3d.h:296
NxReal y
Definition: NxVec3.h:80
Definition: NxVec3.h:22
OPoint3D _max
Maximal coordinates of the OBox.
Definition: 3d.h:1368
static bool _gDrawNormals
Indique si les normals doivent etre visible.
virtual void setIsGeometryModified(bool isModified)
Definition: TYElement.cpp:274
virtual void getChilds(LPTYElementArray &childs, bool recursif=true)
Definition: TYElement.h:517
std::vector< LPTYElement > LPTYElementArray
Definition: TYElement.h:338
void setPoint2(const OPoint3D &point2)
list< TYElementGraphic * > TYListPtrTYElementGraphic
List de pointeur de TYElement.
bool _visible
Inique si l&#39;element est visible.
void setFont(const QString &qsFontPath)
virtual bool isInCurrentCalcul()
Definition: TYElement.h:526
static NxVec3 worldToDisplay(NxVec3 world)
Definition: OGLCamera.cpp:709
bool _viewOnlyHighlight
Inique si on affiche la bounding box seule.
void setTextToDisplay(const QString &qsText)
void gluCylinderAndEnlargeBB(GLUquadric *qobj, GLdouble baseRadius, GLdouble topRadius, GLdouble height, GLint slices, GLint stacks)
void glVertex3dAndEnlargeBB(GLdouble x, GLdouble y, GLdouble z)
void viewOnlyHighlight(bool state=true)
The box class.
Definition: 3d.h:1292
virtual ~TYElementGraphic()
bool getModified(bool andReset=false)
virtual void getChilds(TYListPtrTYElementGraphic &childs, bool recursif=true)
TYElement * getParent() const
Definition: TYElement.h:656
static OBox _globalBoundingBox
double _y
y coordinate of OCoord3D
Definition: 3d.h:281
double _x
x coordinate of OCoord3D
Definition: 3d.h:280
bool _highlight
Indique si le highlight est active pour cet element.
OPoint3D _min
Minimal coordinates of the OBox.
Definition: 3d.h:1367
virtual int render()
OMatrix localToGlobal() const
TYElementGraphic(TYElement *pElt)
virtual void Enlarge(const OPoint3D &pt)
Enlarge the box with the point if the point is outside the box.
Definition: 3d.cpp:1531
bool _modified
Indique si l&#39;element associe a ete modifie.
NxReal x
Definition: NxVec3.h:80
void setColor(const OColor &oColor)
void setLineWidth(float lineWidth)
virtual void update(bool force=false)
void setColor(const OColor &oColor)
void displayNormal(OVector3D normal, OPoint3D p1)
void gluDiskAndEnlargeBB(GLUquadric *qobj, GLdouble innerRadius, GLdouble outerRadius, GLint slices, GLint loops)
void glVertex3fAndEnlargeBB(GLfloat x, GLfloat y, GLfloat z)
static TYGeometryNode * GetGeoNode(TYElement *pElement)
void setRecursiveVisible(bool visible=true)
The 4x4 matrix class.
Definition: 3d.h:625
void gluPartialDiskAndEnlargeBB(GLUquadric *qobj, GLdouble innerRadius, GLdouble outerRadius, GLint slices, GLint loops, GLdouble startAngle, GLdouble sweepAngle)
void setDisplayPosition(double displayPositionX, double displayPositionY)
Definition: OGLElement.h:43
#define IMG(id)
classe graphique pour un element de base
Representation graphique d&#39;un element de base (fichier header)
static bool _gDrawPlafond
Indique si les plafonds doivent etre visible.
virtual void computeBoundingBox()
The 3D point class.
Definition: 3d.h:484
double _z
z coordinate of OCoord3D
Definition: 3d.h:282
void setElement(TYElement *pElt)
void setModified(bool modified=true)
void setPoint1(const OPoint3D &point1)
virtual QString getName() const
Definition: TYElement.h:647
TYElement * _pElement
L&#39;element metier auquel cet element graphique metier est associe.
virtual int render()
bool _texture
Indique si le texturing est active pour cet element.
virtual void display(GLenum mode=GL_RENDER)
void highlight(bool state=true)
void setVisibility(bool bVisible)
Definition: OGLElement.h:44
double _m[4][4]
The 4x4 matrix array.
Definition: 3d.h:923