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  getElement()->setInCurrentCalcul(getElement()->getElement()->isInCurrentCalcul());
37 
39 }
40 
42 {
43  // Calcul de la matrice du GeometryNode par rapport à son GeomtryNode parent
44  float m[16];
45  TYGeometryNode* geoNode = getElement();
46  OMatrix matrix = geoNode->getMatrix();
47  for (int i = 0; i < 4; i++)
48  {
49  for (int j = 0; j < 4; j++)
50  {
51  m[i * 4 + j] = matrix._m[i][j];
52  }
53  }
54  _matrix = QMatrix4x4{m};
55 
56  // Calcul de la matrice du GeometryNode par rapport au Projet
58  TYGeometryNode* geoNodeParent = geoNode->GetGeoNodeParent();
59  if (geoNodeParent != nullptr)
60  {
61  TYGeometryNodeGraphic* geoNodeGraphic =
62  dynamic_cast<TYGeometryNodeGraphic*>(geoNodeParent->getGraphicObject().getRealPointer());
63  _globalMatrix = geoNodeGraphic->globalMatrix() * _matrix;
64  }
65  _isMatrixDirty = false;
66 }
67 
69 {
70  glPushMatrix();
71 
72  GLdouble m[4][4];
73  OMatrix matrix = getElement()->getMatrix();
74  for (int j = 0; j < 4; j++)
75  {
76  for (int k = 0; k < 4; k++)
77  {
78  m[j][k] = matrix._m[k][j];
79  }
80  }
81  glMultMatrixd((GLdouble*)m);
82 }
84  TYGeometryNode* pDansCeRepere)
85 {
86  TYListPtrGeoNode GeoNodeParents;
87  TYGeometryNode* pThisGeoNode = ((TYGeometryNode*)getElement());
88  pThisGeoNode->GetGeoNodeParentList(GeoNodeParents);
89  TYListPtrGeoNode::iterator ite = GeoNodeParents.end();
90  if (!GeoNodeParents.empty())
91  {
92  ite--; // end n'est jamais valide
93  }
94  int i = 0;
95  int nbPushMatrix = 0;
96  bool bPushMatrix = false;
97  for (i = 0; i < GeoNodeParents.size() && (*ite) != pThisGeoNode; i++)
98  {
99  if (pDansCeRepere == NULL) // NULL = site pere (repere du TYSite le plus haut)
100  {
101  bPushMatrix = true;
102  }
103  if (bPushMatrix)
104  {
105  // PushMatrix
106  TYGeometryNode* pCurrentTYGeometryNode = (TYGeometryNode*)(*ite);
107  LPTYElementGraphic pCurrentTYElementGraphic = pCurrentTYGeometryNode->getGraphicObject();
108  TYGeometryNodeGraphic* pCurrentTYGeometryNodeGraphic =
109  (TYGeometryNodeGraphic*)pCurrentTYElementGraphic.getRealPointer();
110  pCurrentTYGeometryNodeGraphic->pushMatrix();
111  nbPushMatrix++;
112  }
113  if ((*ite) == pDansCeRepere) // NULL = root
114  {
115  bPushMatrix = true;
116  }
117 
118  if (ite != GeoNodeParents.begin())
119  {
120  ite--;
121  }
122  }
123  display(renderContext);
124  // PopMatrix
125  for (i = 0; i < nbPushMatrix; i++)
126  {
127  glPopMatrix();
128  }
129 }
130 
131 void TYGeometryNodeGraphic::getChilds(TYListPtrTYElementGraphic& childs, bool recursif /*=true*/)
132 {
133  TYElement* element = getElement()->getElement();
134  if (element != nullptr)
135  {
136  TYElementGraphic* pTYElementGraphic = element->getGraphicObject();
137  childs.push_back(pTYElementGraphic);
138  if (recursif)
139  {
140  pTYElementGraphic->getChilds(childs, recursif);
141  }
142  }
143 }
144 
146 {
147 
148  _isMatrixDirty = true;
149 
150  // propagation aux enfants;
151  TYListPtrTYElementGraphic children;
152  getChilds(children, true);
153  for (TYListPtrTYElementGraphic::iterator it = children.begin(); it != children.end(); ++it)
154  {
155  TYGeometryNodeGraphic* child = dynamic_cast<TYGeometryNodeGraphic*>(*it);
156  if (child != nullptr)
157  {
158  child->_isMatrixDirty = true;
159  }
160  }
161 }
162 
164 {
166  boundingBox.Enlarge(((TYElementGraphic*)getElement()->getElement()->getGraphicObject())->boundingBox());
167  return boundingBox;
168 }
169 
171 {
172  pushMatrix();
173 
174  LPTYElementGraphic pGraphicObject = getElement()->getElement()->getGraphicObject();
175 
176  pGraphicObject->display(renderContext);
177 
178  glPopMatrix();
179 }
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)
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