Code_TYMPAN  4.4.0
Industrial site acoustic simulation
TYGeometryNodeGraphic.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 
21 #include <QtOpenGL> // this MUST be included before GL/*.h
22 #include "TYGeometryNodeGraphic.h"
23 #include "gui/gl/TYRenderContext.h"
24 #include <QtOpenGL>
25 
27  : TYElementGraphic(pElement), _isMatrixDirty(true)
28 {
29 }
30 
32 
33 void TYGeometryNodeGraphic::update(bool force /*=false*/)
34 {
35  // On affecte le meme etat au GeoNode que l'element pour savoir s'il est actif dans le calcul courant
36  if (getModified() || force)
37  {
38  getElement()->setInCurrentCalcul(getElement()->getElement()->isInCurrentCalcul());
39  }
41 }
42 
44 {
45  // Calcul de la matrice du GeometryNode par rapport à son GeomtryNode parent
46  float m[16];
47  TYGeometryNode* geoNode = getElement();
48  OMatrix matrix = geoNode->getMatrix();
49  for (int i = 0; i < 4; i++)
50  {
51  for (int j = 0; j < 4; j++)
52  {
53  m[i * 4 + j] = matrix._m[i][j];
54  }
55  }
56  _matrix = QMatrix4x4{m};
57 
58  // Calcul de la matrice du GeometryNode par rapport au Projet
60  TYGeometryNode* geoNodeParent = geoNode->GetGeoNodeParent();
61  if (geoNodeParent != nullptr)
62  {
63  TYGeometryNodeGraphic* geoNodeGraphic =
64  dynamic_cast<TYGeometryNodeGraphic*>(geoNodeParent->getGraphicObject().getRealPointer());
65  _globalMatrix = geoNodeGraphic->globalMatrix() * _matrix;
66  }
67  _isMatrixDirty = false;
68 }
69 
71 {
72  glPushMatrix();
73 
74  GLdouble m[4][4];
75  OMatrix matrix = getElement()->getMatrix();
76  for (int j = 0; j < 4; j++)
77  {
78  for (int k = 0; k < 4; k++)
79  {
80  m[j][k] = matrix._m[k][j];
81  }
82  }
83  glMultMatrixd((GLdouble*)m);
84 }
86  TYGeometryNode* pDansCeRepere)
87 {
88  TYListPtrGeoNode GeoNodeParents;
89  TYGeometryNode* pThisGeoNode = ((TYGeometryNode*)getElement());
90  pThisGeoNode->GetGeoNodeParentList(GeoNodeParents);
91  TYListPtrGeoNode::iterator ite = GeoNodeParents.end();
92  if (!GeoNodeParents.empty())
93  {
94  ite--; // end n'est jamais valide
95  }
96  int i = 0;
97  int nbPushMatrix = 0;
98  bool bPushMatrix = false;
99  for (i = 0; i < GeoNodeParents.size() && (*ite) != pThisGeoNode; i++)
100  {
101  if (pDansCeRepere == NULL) // NULL = site pere (repere du TYSite le plus haut)
102  {
103  bPushMatrix = true;
104  }
105  if (bPushMatrix)
106  {
107  // PushMatrix
108  TYGeometryNode* pCurrentTYGeometryNode = (TYGeometryNode*)(*ite);
109  LPTYElementGraphic pCurrentTYElementGraphic = pCurrentTYGeometryNode->getGraphicObject();
110  TYGeometryNodeGraphic* pCurrentTYGeometryNodeGraphic =
111  (TYGeometryNodeGraphic*)pCurrentTYElementGraphic.getRealPointer();
112  pCurrentTYGeometryNodeGraphic->pushMatrix();
113  nbPushMatrix++;
114  }
115  if ((*ite) == pDansCeRepere) // NULL = root
116  {
117  bPushMatrix = true;
118  }
119 
120  if (ite != GeoNodeParents.begin())
121  {
122  ite--;
123  }
124  }
125  display(renderContext);
126  // PopMatrix
127  for (i = 0; i < nbPushMatrix; i++)
128  {
129  glPopMatrix();
130  }
131 }
132 
133 void TYGeometryNodeGraphic::getChilds(TYListPtrTYElementGraphic& childs, bool recursif /*=true*/)
134 {
135  TYElement* element = getElement()->getElement();
136  if (element != nullptr)
137  {
138  TYElementGraphic* pTYElementGraphic = element->getGraphicObject();
139  childs.push_back(pTYElementGraphic);
140  if (recursif)
141  {
142  pTYElementGraphic->getChilds(childs, recursif);
143  }
144  }
145 }
146 
148 {
149 
150  _isMatrixDirty = true;
151 
152  // propagation aux enfants;
153  TYListPtrTYElementGraphic children;
154  getChilds(children, true);
155  for (TYListPtrTYElementGraphic::iterator it = children.begin(); it != children.end(); ++it)
156  {
157  TYGeometryNodeGraphic* child = dynamic_cast<TYGeometryNodeGraphic*>(*it);
158  if (child != nullptr)
159  {
160  child->_isMatrixDirty = true;
161  }
162  }
163 }
164 
166 {
168  boundingBox.Enlarge(((TYElementGraphic*)getElement()->getElement()->getGraphicObject())->boundingBox());
169  return boundingBox;
170 }
171 
173 {
174  pushMatrix();
175 
176  LPTYElementGraphic pGraphicObject = getElement()->getElement()->getGraphicObject();
177 
178  pGraphicObject->display(renderContext);
179 
180  glPopMatrix();
181 }
list< TYElementGraphic * > TYListPtrTYElementGraphic
List de pointeur de TYElement.
Representation graphique d'un GeometryNode (fichier header)
std::list< TYGeometryNode * > TYListPtrGeoNode
Liste ordonnee de pointeurs de TYElement.
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
The 4x4 matrix class.
Definition: 3d.h:625
T * getRealPointer()
Definition: smartptr.h:291
classe graphique pour un element de base
OBox boundingBox() const
virtual void update(bool force=false)
virtual void getChilds(TYListPtrTYElementGraphic &childs, bool recursif=true)
virtual void display(TYRenderContext &renderContext)
bool getModified() const
classe graphique pour un GeometryNode
QMatrix4x4 matrix() const
virtual void update(bool force=false)
virtual void getChilds(TYListPtrTYElementGraphic &childs, bool recursif=true)
virtual OBox computeBoundingBox() const
QMatrix4x4 globalMatrix() const
TYGeometryNodeGraphic(TYGeometryNode *pElement)
void displayPushingParentMatrix(TYRenderContext &renderContext, TYGeometryNode *pDansCeRepere)
virtual void display(TYRenderContext &renderContext)
TYGeometryNode * GetGeoNodeParent() const
void GetGeoNodeParentList(TYListPtrGeoNode &GetGeoNodeParents)
OMatrix getMatrix() const