Code_TYMPAN  4.4.0
Industrial site acoustic simulation
TYElementGraphic.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) <2012-2024> <EDF-DTG> <FRANCE>
3  * This file is part of Code_TYMPAN (R).
4  * Code_TYMPAN (R) is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  * Code_TYMPAN (R) is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11  * See the GNU General Public License for more details.
12  * You should have received a copy of the GNU General Public License along
13  * with Code_TYMPAN (R). If not, see <https://www.gnu.org/licenses/>.
14  */
15 
29 
30 #include "TYElementGraphic.h"
36 #include "models/common/3d.h"
37 #include <QtOpenGL>
38 #include <qmatrix4x4.h>
39 #include <qvector3d.h>
40 
41 #define IMG(id) OLocalizator::getPicture("TYElementGraphic", (id))
42 
45 
47 {
48  _pElement = pElt;
49 
50  _modified = true;
51  _visible = true;
52  _highlight = false;
53  _texture = false;
54 
55  // Highlight
56  _viewOnlyHighlight = false;
57  _boundingBoxDirty = true;
58 }
59 
61 
63 {
64  _pElement = pElt;
65 }
66 
68 {
69  TYElement* pParent = _pElement->getParent();
70 
71  // On appelle la methode update surchargee par les objets graphiques
72  update();
73  if (getModified() && pParent && pParent->getGraphicObject())
74  {
75  // On force la mise a jour du parent
76  pParent->setIsGeometryModified(true);
77  // On appelle la methode update surchargee par les objets graphiques
78  // On remonte l'arbre
79  pParent->getGraphicObject()->updateTree();
80  }
81 }
82 
83 void TYElementGraphic::update(bool force /*=false*/)
84 {
85  if (_pElement)
86  {
88  {
90  }
91  else
92  {
93  _visible = false;
94  }
95  }
96 
97  // Update highlight seulement si actif
99 
100  // On repositionne le flag modified
101  setModified(false);
102 
103 #if TY_USE_IHM
104  // Emission du signal de notification de mise a jour
105  activateSignal();
106 #endif // TY_USE_IHM
107 }
108 
110 {
111  return _modified;
112 }
113 
114 void TYElementGraphic::setBoundingBoxVisible(bool state /*=true*/)
115 {
116  // Update
117  _highlight = state;
118 }
119 
121 {
122  OVector3D n = normal; // getElement()->_normale;
123  OPoint3D p2;
124  p2._x = p1._x + n._x;
125  p2._y = p1._y + n._y;
126  p2._z = p1._z + n._z;
127  glColor3f(1.0f, 0.5f, 0.0f);
128  glLineWidth(2);
129  glPointSize(4);
130 
131  glBegin(GL_LINE_STRIP);
132  glVertex3f(p1._x, p1._y, p1._z);
133  glVertex3f(p2._x, p2._y, p2._z);
134  glEnd();
135 }
136 
138 {
140  const TYGeometryNode* pGeoNode = TYGeometryNode::GetGeoNode(renderContext.modelerElement);
141  // pour déterminer la position du texte, il faut le centre de la boundingbox dans le repère du modeleur.
142  QVector3D origin;
143  float org[3];
144  OBox bBox = boundingBox();
145  org[0] = (bBox._min._x + bBox._max._x) / 2;
146  org[1] = (bBox._min._y + bBox._max._y) / 2;
147  org[2] = (bBox._min._z + bBox._max._z) / 2;
148  if (pThisGeoNode)
149  {
150  OMatrix mat;
151  if (pGeoNode != nullptr)
152  {
153  mat = pThisGeoNode->localToGeoNode(pGeoNode);
154  }
155  else
156  {
157  mat = pThisGeoNode->localToGlobal();
158  }
159 
160  origin = QVector3D(
161  org[0] * mat._m[0][0] + org[1] * mat._m[0][1] + org[2] * mat._m[0][2] + mat._m[0][3],
162  org[0] * mat._m[2][0] + org[1] * mat._m[2][1] + org[2] * mat._m[2][2] + mat._m[2][3],
163  -(org[0] * mat._m[1][0] + org[1] * mat._m[1][1] + org[2] * mat._m[1][2] + mat._m[1][3]));
164  }
165  else
166  {
167  origin = QVector3D(org[0], org[2], -org[1]);
168  }
169  QVector3D ret = renderContext.viewport.worldToDisplay(origin);
170 
171  // ajouter une etiquette avec le nom
172  OGLTextElement oOGLTextElement;
173  oOGLTextElement.setFont(IMG("id_font"));
174  oOGLTextElement.setVisibility(true);
175  if (_pElement)
176  {
177  oOGLTextElement.setTextToDisplay(_pElement->getName());
178  }
179  oOGLTextElement.setColor(OColor::BLACK);
180  oOGLTextElement.setDisplayPosition(ret.x() + 22, ret.y() + 40);
181  oOGLTextElement.render();
182 
183  OGLLineElement oglLineElement;
184  oglLineElement.setColor(OColor::BLACK);
185  oglLineElement.setLineWidth(2.0f);
186  oglLineElement.setPoint1(QVector3D(ret.x(), ret.y(), 0));
187  oglLineElement.setPoint2(QVector3D(ret.x() + 20, ret.y() + 40, 0));
188  oglLineElement.setVisibility(true);
189  oglLineElement.render();
190 }
191 
193 {
194  return _highlight;
195 }
196 
198 {
199  return _viewOnlyHighlight;
200 }
201 
202 void TYElementGraphic::setOnlyBoundingBox(bool state /*=true*/)
203 {
204  _viewOnlyHighlight = state;
205 
206  // Active le highlight
208 }
209 
211 {
212 #if TY_USE_IHM
213  // Emission du signal de notification de mise a jour
214  activateSignal();
215 
216 #endif // TY_USE_IHM
217 }
218 
220 {
221  if (_boundingBoxDirty)
222  {
224  _boundingBoxDirty = false;
225  }
226  return _boundingBox;
227 }
228 
230 {
231  OBox Box;
232 
234  getChilds(childs, false);
235  if (childs.size() > 0)
236  {
237  const TYElementGraphic* pChild = nullptr;
238  TYListPtrConstTYElementGraphic::iterator ite = childs.begin();
239  pChild = (*ite);
240  Box = OBox{pChild->boundingBox()};
241  ite++;
242  for (; ite != childs.end(); ite++)
243  {
244  pChild = (*ite);
245  if (pChild != nullptr)
246  {
247  Box.Enlarge(pChild->boundingBox());
248  }
249  }
250  }
251 
252  std::vector<OGLMeshInstance> meshInstances;
253  collectMeshInstances(meshInstances, nullptr);
254  for (const OGLMeshInstance& meshInstance : meshInstances)
255  {
256  Box.Enlarge(meshInstance.mesh()->boundingBox());
257  }
258  return Box;
259 }
260 
262 {
263  if (getTYElement() != nullptr)
264  {
265  TYElement* parent = getTYElement()->getParent();
266  if (parent != nullptr)
267  {
268  LPTYElementGraphic parentGraphicElement = parent->getGraphicObject();
269  if (parentGraphicElement != nullptr)
270  {
271  parentGraphicElement->invalidateBoundingBox();
272  }
273  }
274  LPTYElementArray children;
275  getTYElement()->getChilds(children, false);
276  LPTYElementGraphic childGraphicElement;
277  for (int i = 0; i < children.size(); i++)
278  {
279  childGraphicElement = children[i]->getGraphicObject();
280  if (childGraphicElement != nullptr)
281  {
282  childGraphicElement->_boundingBoxDirty = true;
283  }
284  }
285  }
286  this->_boundingBoxDirty = true;
287 }
288 
289 void TYElementGraphic::collectMeshInstances(std::vector<OGLMeshInstance>& meshInstances,
290  TYRenderContext* renderContext) const {};
291 
293 {
294  if (dynamic_cast<const TYGeometryNodeGraphic*>(this) != nullptr)
295  {
296  return dynamic_cast<const TYGeometryNodeGraphic*>(this);
297  }
298  const TYElement* parent = getTYElement();
299  while (parent != nullptr)
300  {
301  TYGeometryNode* geoNode = const_cast<TYGeometryNode*>(TYGeometryNode::GetGeoNode(parent));
302 
303  if (geoNode != nullptr)
304  {
305  return dynamic_cast<TYGeometryNodeGraphic*>(geoNode->getGraphicObject().getRealPointer());
306  }
307  parent = parent->getParent();
308  }
309  return nullptr;
310 }
311 
313 {
314  const TYGeometryNodeGraphic* geoNodeGraphic = nearestGeoNode();
315  if (geoNodeGraphic != nullptr)
316  {
317  return geoNodeGraphic->globalMatrix();
318  }
319  return {};
320 }
321 void TYElementGraphic::setModified(bool modified)
322 {
323  _modified = modified;
324  if (modified)
325  {
327  }
328 }
All base classes related to 3D manipulation.
#define IMG(id)
Representation graphique d'un element de base (fichier header)
list< const TYElementGraphic * > TYListPtrConstTYElementGraphic
List de pointeur de TYElement.
std::vector< LPTYElement > LPTYElementArray
Definition: TYElement.h:344
Representation graphique d'un GeometryNode (fichier header)
Realise le rendu VTK et le rendu OpenGL (fichier header)
Contexte de rendu utilisé par les fonctions d'affichage.
The box class.
Definition: 3d.h:1346
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:1423
OPoint3D _max
Maximal coordinates of the OBox.
Definition: 3d.h:1424
static const OColor BLACK
Definition: color.h:94
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
void setVisibility(bool bVisible)
Definition: OGLElement.h:51
void setDisplayPosition(double displayPositionX, double displayPositionY)
Definition: OGLElement.h:46
void setPoint2(const QVector3D &point2)
void setColor(const OColor &oColor)
void setLineWidth(float lineWidth)
virtual int render()
void setPoint1(const QVector3D &point1)
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:974
The 3D point class.
Definition: 3d.h:487
The 3D vector class.
Definition: 3d.h:298
classe graphique pour un element de base
bool _modified
Indique si l'element associe a ete modifie.
void setOnlyBoundingBox(bool state=true)
void drawName(TYRenderContext &renderContext)
bool _visible
Inique si l'element est visible.
void setModified(bool modified=true)
TYElement * getTYElement()
static bool _gDrawNormals
Indique si les normals doivent etre visible.
bool _texture
Indique si le texturing est active pour cet element.
OBox boundingBox() const
void setBoundingBoxVisible(bool state=true)
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)
bool isBoundingBoxVisible() const
static bool _gDrawPlafond
Indique si les plafonds doivent etre visible.
virtual void getChilds(TYListPtrTYElementGraphic &childs, bool recursif=true)
virtual void display(TYRenderContext &renderContext)
const TYGeometryNodeGraphic * nearestGeoNode() const
void setElement(TYElement *pElt)
QMatrix4x4 globalMatrix() const
TYElement * _pElement
L'element metier auquel cet element graphique metier est associe.
virtual OBox computeBoundingBox() const
bool getModified() const
virtual ~TYElementGraphic()
virtual void collectMeshInstances(std::vector< OGLMeshInstance > &meshInstances, TYRenderContext *renderContext) const
bool _viewOnlyHighlight
Inique si on affiche la bounding box seule.
bool getOnlyBoundingBox() const
TYElement * getParent() const
Definition: TYElement.h:697
virtual bool isInCurrentCalcul()
Definition: TYElement.h:539
virtual QString getName() const
Definition: TYElement.h:682
virtual void getChilds(LPTYElementArray &childs, bool recursif=true)
Definition: TYElement.h:530
virtual void setIsGeometryModified(bool isModified)
Definition: TYElement.cpp:253
classe graphique pour un GeometryNode
QMatrix4x4 globalMatrix() const
OMatrix localToGlobal() const
OMatrix localToGeoNode(const TYGeometryNode *pGeoNode) const
static TYGeometryNode * GetGeoNode(TYElement *pElement)
TYRenderViewport viewport
TYElement * modelerElement
QVector3D worldToDisplay(const QVector3D &world) const