Code_TYMPAN  4.4.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 
30 
31 #include "TYElementGraphic.h"
33 
34 #define IMG(id) OLocalizator::getPicture("TYElementGraphic", (id))
35 
37 
40 
42 {
43  _pElement = pElt;
44 
45  _modified = true;
46  _visible = true;
47  _highlight = false;
48  _texture = false;
49  _bFirstDisp = true;
50 
51  // Highlight
52  _viewOnlyHighlight = false;
53 }
54 
56 
58 {
59  _pElement = pElt;
60 }
61 
63 {
64  TYElement* pParent = _pElement->getParent();
65 
66  if (getModified() && pParent && pParent->getGraphicObject())
67  {
68  // On force la mise a jour du parent
69  pParent->setIsGeometryModified(true);
70  // On remonte l'arbre
71  pParent->getGraphicObject()->updateTree();
72  }
73  else
74  {
75  // On appelle la methode update surchargee par les objets graphiques
76  update();
77  }
78 }
79 
80 void TYElementGraphic::update(bool force /*=false*/)
81 {
83 
84  if (_pElement)
85  {
87  {
89  }
90  else
91  {
92  _visible = false;
93  }
94  }
95 
96  // Update highlight seulement si actif
98 
99  // On repositionne le flag modified
100  setModified(false);
101 
102 #if TY_USE_IHM
103  // Emission du signal de notification de mise a jour
104  activateSignal();
105 #endif // TY_USE_IHM
106 }
107 
108 bool TYElementGraphic::getModified(bool andReset /*=false*/)
109 {
110  bool ret = _modified;
111 
112  if (andReset)
113  {
114  setModified(false);
115  }
116 
117  return ret;
118 }
119 
120 void TYElementGraphic::highlight(bool state /*=true*/)
121 {
122  // Update
123  _highlight = state;
124 }
125 
127 {
128  OVector3D n = normal; // getElement()->_normale;
129  OPoint3D p2;
130  p2._x = p1._x + n._x;
131  p2._y = p1._y + n._y;
132  p2._z = p1._z + n._z;
133  glColor3f(1.0f, 0.5f, 0.0f);
134  glLineWidth(2);
135  glPointSize(4);
136 
137  glBegin(GL_LINE_STRIP);
138  glVertex3f(p1._x, p1._y, p1._z);
139  glVertex3f(p2._x, p2._y, p2._z);
140  glEnd();
141 }
142 
144 {
145  float org[3];
146  org[0] = (_boundingBox._min._x + _boundingBox._max._x) / 2;
147  org[1] = (_boundingBox._min._y + _boundingBox._max._y) / 2;
148  org[2] = (_boundingBox._min._z + _boundingBox._max._z) / 2;
149 
150  // Ajout de 0.1 contre bug faces coplanaires
151  // CLM-NT33 : agrandit la bb avec un % de la taille
152  // double x = 5 + (_boundingBox._max._x - _boundingBox._min._x)/2;
153  // double y = 5 + (_boundingBox._max._y - _boundingBox._min._y)/2;
154  // double z = 5 + (_boundingBox._max._z - _boundingBox._min._z)/2;
155  // OPoint3D d = _boundingBox._max - _boundingBox._min;
156  double x = (_boundingBox._max._x - _boundingBox._min._x) * 1.1f / 2;
157  double y = (_boundingBox._max._y - _boundingBox._min._y) * 1.1f / 2;
158  double z = (_boundingBox._max._z - _boundingBox._min._z) * 1.1f / 2;
159 
160  glColor3f(1.0f, 1.0f, 0.5f);
161  glLineWidth(2);
162  glPointSize(4);
163 
164  glBegin(GL_LINE_LOOP);
165  glVertex3f(org[0] + x, org[1] - y, org[2] - z);
166  glVertex3f(org[0] - x, org[1] - y, org[2] - z);
167  glVertex3f(org[0] - x, org[1] + y, org[2] - z);
168  glVertex3f(org[0] + x, org[1] + y, org[2] - z);
169  glEnd();
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_STRIP);
177  glVertex3f(org[0] + x, org[1] - y, org[2] - z);
178  glVertex3f(org[0] + x, org[1] - y, org[2] + z);
179  glEnd();
180  glBegin(GL_LINE_STRIP);
181  glVertex3f(org[0] - x, org[1] - y, org[2] - z);
182  glVertex3f(org[0] - x, org[1] - y, org[2] + z);
183  glEnd();
184  glBegin(GL_LINE_STRIP);
185  glVertex3f(org[0] - x, org[1] + y, org[2] - z);
186  glVertex3f(org[0] - x, org[1] + y, org[2] + z);
187  glEnd();
188  glBegin(GL_LINE_STRIP);
189  glVertex3f(org[0] + x, org[1] + y, org[2] - z);
190  glVertex3f(org[0] + x, org[1] + y, org[2] + z);
191  glEnd();
192  glBegin(GL_POINTS);
193  glVertex3f(org[0] + x, org[1] - y, org[2] - z);
194  glVertex3f(org[0] - x, org[1] - y, org[2] - z);
195  glVertex3f(org[0] - x, org[1] + y, org[2] - z);
196  glVertex3f(org[0] + x, org[1] + y, org[2] - z);
197  glVertex3f(org[0] + x, org[1] - y, org[2] + z);
198  glVertex3f(org[0] - x, org[1] - y, org[2] + z);
199  glVertex3f(org[0] - x, org[1] + y, org[2] + z);
200  glVertex3f(org[0] + x, org[1] + y, org[2] + z);
201  glEnd();
202 }
203 
204 void TYElementGraphic::drawName(TYElement* pModelerElement /*= nullptr*/)
205 {
207  TYGeometryNode* pGeoNode = TYGeometryNode::GetGeoNode(pModelerElement);
208  // pour déterminer la position du texte, il faut le centre de la boundingbox dans le repère du modeleur.
209  NxVec3 origin;
210  float org[3];
211  org[0] = (_boundingBox._min._x + _boundingBox._max._x) / 2;
212  org[1] = (_boundingBox._min._y + _boundingBox._max._y) / 2;
213  org[2] = (_boundingBox._min._z + _boundingBox._max._z) / 2;
214  if (pThisGeoNode)
215  {
216  OMatrix mat;
217  if (pGeoNode != nullptr)
218  {
219  mat = pThisGeoNode->localToGeoNode(pGeoNode);
220  }
221  else
222  {
223  mat = pThisGeoNode->localToGlobal();
224  }
225 
226  origin =
227  NxVec3(org[0] * mat._m[0][0] + org[1] * mat._m[0][1] + org[2] * mat._m[0][2] + mat._m[0][3],
228  org[0] * mat._m[2][0] + org[1] * mat._m[2][1] + org[2] * mat._m[2][2] + mat._m[2][3],
229  -(org[0] * mat._m[1][0] + org[1] * mat._m[1][1] + org[2] * mat._m[1][2] + mat._m[1][3]));
230  }
231  else
232  {
233  origin = NxVec3(org[0], org[2], -org[1]);
234  }
235  NxVec3 ret = OGLCamera::worldToDisplay(origin);
236 
237  // ajouter une etiquette avec le nom
238  OGLTextElement oOGLTextElement;
239  oOGLTextElement.setFont(IMG("id_font"));
240  oOGLTextElement.setVisibility(true);
241  if (_pElement)
242  {
243  oOGLTextElement.setTextToDisplay(_pElement->getName());
244  }
245  oOGLTextElement.setColor(OColor::BLACK);
246  oOGLTextElement.setDisplayPosition(ret.x + 22, ret.y + 40);
247  oOGLTextElement.render();
248 
249  OGLLineElement oglLineElement;
250  oglLineElement.setColor(OColor::BLACK);
251  oglLineElement.setLineWidth(2.0f);
252  oglLineElement.setPoint1(OPoint3D(ret.x, ret.y, 0));
253  oglLineElement.setPoint2(OPoint3D(ret.x + 20, ret.y + 40, 0));
254  oglLineElement.setVisibility(true);
255  oglLineElement.render();
256 }
257 
259 {
260  float org[3];
261  org[0] = (_boundingBox._min._x + _boundingBox._max._x) / 2;
262  org[1] = (_boundingBox._min._y + _boundingBox._max._y) / 2;
263  org[2] = (_boundingBox._min._z + _boundingBox._max._z) / 2;
264 
265  // Ajout de 0.1 contre bug faces coplanaires
266  double x = 0.1 + (_boundingBox._max._x - _boundingBox._min._x) / 2;
267  double y = 0.1 + (_boundingBox._max._y - _boundingBox._min._y) / 2;
268  double z = 0.1 + (_boundingBox._max._z - _boundingBox._min._z) / 2;
269 
270  glColor4f(1.0f, 1.0f, 0.0f, 0.1f);
271 
272  glBegin(GL_QUADS);
273 
274  glVertex3d(org[0] + x, org[1] + y, org[2] - z);
275  glVertex3d(org[0] - x, org[1] + y, org[2] - z);
276  glVertex3d(org[0] - x, org[1] + y, org[2] + z);
277  glVertex3d(org[0] + x, org[1] + y, org[2] + z);
278 
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  glVertex3f(org[0] + x, org[1] - y, org[2] - z);
283 
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  glVertex3f(org[0] + x, org[1] - y, org[2] + z);
288 
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  glVertex3f(org[0] + x, org[1] + y, org[2] - z);
293 
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  glVertex3f(org[0] - x, org[1] - y, org[2] + z);
298 
299  glVertex3f(org[0] + x, org[1] + y, org[2] - z);
300  glVertex3f(org[0] + x, org[1] + y, org[2] + z);
301  glVertex3f(org[0] + x, org[1] - y, org[2] + z);
302  glVertex3f(org[0] + x, org[1] - y, org[2] - z);
303 
304  glEnd();
305 }
306 void TYElementGraphic::glVertex3fAndEnlargeBB(GLfloat x, GLfloat y, GLfloat z)
307 {
308  glVertex3f(x, y, z);
309  _boundingBox.Enlarge((float)x, (float)y, (float)z);
310 }
311 
312 void TYElementGraphic::glVertex3dAndEnlargeBB(GLdouble x, GLdouble y, GLdouble z)
313 {
314  glVertex3d(x, y, z);
315  _boundingBox.Enlarge((float)x, (float)y, (float)z);
316 }
317 
318 void TYElementGraphic::gluDiskAndEnlargeBB(GLUquadric* qobj, GLdouble innerRadius, GLdouble outerRadius,
319  GLint slices, GLint loops)
320 {
321  gluDisk(qobj, innerRadius, outerRadius, slices, loops);
322 }
323 
324 void TYElementGraphic::gluCylinderAndEnlargeBB(GLUquadric* qobj, GLdouble baseRadius, GLdouble topRadius,
325  GLdouble height, GLint slices, GLint stacks)
326 {
327  gluCylinder(qobj, baseRadius, topRadius, height, slices, stacks);
328 }
329 
330 void TYElementGraphic::gluPartialDiskAndEnlargeBB(GLUquadric* qobj, GLdouble innerRadius,
331  GLdouble outerRadius, GLint slices, GLint loops,
332  GLdouble startAngle, GLdouble sweepAngle)
333 {
334  gluPartialDisk(qobj, innerRadius, outerRadius, slices, loops, startAngle, sweepAngle);
335 }
336 
338 {
339  return _highlight;
340 }
341 
342 void TYElementGraphic::viewOnlyHighlight(bool state /*=true*/)
343 {
344  _viewOnlyHighlight = state;
345 
346  // Active le highlight
348 }
349 
350 void TYElementGraphic::display(TYElement* pModelerElement /*= nullptr*/, GLenum mode /*= GL_RENDER*/)
351 {
352  OBox reset;
353  _boundingBox = reset;
354 #if TY_USE_IHM
355  // Emission du signal de notification de mise a jour
356  activateSignal();
357 
358 #endif // TY_USE_IHM
359 }
360 
361 void TYElementGraphic::setRecursiveVisible(bool visible /*=true*/)
362 {
363  LPTYElementArray childs;
364 
365  _pElement->getChilds(childs);
366 
367  for (int i = 0; i < childs.size(); i++)
368  {
369  childs[i]->getGraphicObject()->setVisible(visible);
370  }
371 }
372 
374 {
375  OBox reset;
376  _boundingBox = reset;
377 
379  getChilds(childs, false);
380  TYListPtrTYElementGraphic::iterator ite;
381  OBox boundingBox;
382  TYElementGraphic* pChild = NULL;
383  for (ite = childs.begin(); ite != childs.end(); ite++)
384  {
385  pChild = (*ite);
386  if (pChild != NULL)
387  {
388  pChild->computeBoundingBox();
389  boundingBox = pChild->GetBox();
390  }
391  _boundingBox.Enlarge(boundingBox);
392  }
393 }
#define IMG(id)
Representation graphique d'un element de base (fichier header)
list< TYElementGraphic * > TYListPtrTYElementGraphic
List de pointeur de TYElement.
std::vector< LPTYElement > LPTYElementArray
Definition: TYElement.h:345
Definition: NxVec3.h:23
NxReal y
Definition: NxVec3.h:80
NxReal x
Definition: NxVec3.h:80
The box class.
Definition: 3d.h:1294
virtual void Enlarge(const OPoint3D &pt)
Enlarge the box with the point if the point is outside the box.
Definition: 3d.cpp:1614
OPoint3D _min
Minimal coordinates of the OBox.
Definition: 3d.h:1371
OPoint3D _max
Maximal coordinates of the OBox.
Definition: 3d.h:1372
static const OColor BLACK
Definition: color.h:86
double _y
y coordinate of OCoord3D
Definition: 3d.h:283
double _z
z coordinate of OCoord3D
Definition: 3d.h:284
double _x
x coordinate of OCoord3D
Definition: 3d.h:282
static NxVec3 worldToDisplay(NxVec3 world)
Definition: OGLCamera.cpp:722
void setVisibility(bool bVisible)
Definition: OGLElement.h:51
void setDisplayPosition(double displayPositionX, double displayPositionY)
Definition: OGLElement.h:46
void setPoint1(const OPoint3D &point1)
void setColor(const OColor &oColor)
void setLineWidth(float lineWidth)
void setPoint2(const OPoint3D &point2)
virtual int render()
virtual int render()
void setColor(const OColor &oColor)
void setTextToDisplay(const QString &qsText)
void setFont(const QString &qsFontPath)
The 4x4 matrix class.
Definition: 3d.h:625
double _m[4][4]
The 4x4 matrix array.
Definition: 3d.h:922
The 3D point class.
Definition: 3d.h:487
The 3D vector class.
Definition: 3d.h:298
classe graphique pour un element de base
void drawName(TYElement *pModelerElement=nullptr)
void glVertex3fAndEnlargeBB(GLfloat x, GLfloat y, GLfloat z)
void glVertex3dAndEnlargeBB(GLdouble x, GLdouble y, GLdouble z)
virtual void computeBoundingBox()
bool _modified
Indique si l'element associe a ete modifie.
static OBox _globalBoundingBox
void gluPartialDiskAndEnlargeBB(GLUquadric *qobj, GLdouble innerRadius, GLdouble outerRadius, GLint slices, GLint loops, GLdouble startAngle, GLdouble sweepAngle)
bool _visible
Inique si l'element est visible.
void setModified(bool modified=true)
void setRecursiveVisible(bool visible=true)
static bool _gDrawNormals
Indique si les normals doivent etre visible.
bool _texture
Indique si le texturing est active pour cet element.
TYElementGraphic(TYElement *pElt)
bool _highlight
Indique si le highlight est active pour cet element.
void displayNormal(OVector3D normal, OPoint3D p1)
virtual void update(bool force=false)
static bool _gDrawPlafond
Indique si les plafonds doivent etre visible.
virtual void getChilds(TYListPtrTYElementGraphic &childs, bool recursif=true)
void setElement(TYElement *pElt)
virtual void display(TYElement *pModelerElement=nullptr, GLenum mode=GL_RENDER)
TYElement * _pElement
L'element metier auquel cet element graphique metier est associe.
void gluDiskAndEnlargeBB(GLUquadric *qobj, GLdouble innerRadius, GLdouble outerRadius, GLint slices, GLint loops)
void viewOnlyHighlight(bool state=true)
void gluCylinderAndEnlargeBB(GLUquadric *qobj, GLdouble baseRadius, GLdouble topRadius, GLdouble height, GLint slices, GLint stacks)
bool getModified(bool andReset=false)
void highlight(bool state=true)
virtual ~TYElementGraphic()
bool _viewOnlyHighlight
Inique si on affiche la bounding box seule.
TYElement * getParent() const
Definition: TYElement.h:699
virtual bool isInCurrentCalcul()
Definition: TYElement.h:541
virtual QString getName() const
Definition: TYElement.h:684
virtual void getChilds(LPTYElementArray &childs, bool recursif=true)
Definition: TYElement.h:532
virtual void setIsGeometryModified(bool isModified)
Definition: TYElement.cpp:253
OMatrix localToGlobal() const
OMatrix localToGeoNode(TYGeometryNode *pGeoNode) const
static TYGeometryNode * GetGeoNode(TYElement *pElement)