Code_TYMPAN  4.4.0
Industrial site acoustic simulation
TYGeometryNodeGraphic.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 
21 #include <QtOpenGL> // this MUST be included before GL/*.h
22 #include <GL/gl.h>
23 #include <GL/glu.h>
24 
25 #include "TYGeometryNodeGraphic.h"
26 
28 
30 
31 void TYGeometryNodeGraphic::update(bool force /*=false*/)
32 {
33  // On affecte le meme etat au GeoNode que l'element pour savoir s'il est actif dans le calcul courant
34  getElement()->setInCurrentCalcul(getElement()->getElement()->isInCurrentCalcul());
35 
37 }
38 
40 {
41  glPushMatrix();
42 
43  GLdouble m[4][4];
44  OMatrix matrix = getElement()->getMatrix();
45  for (int j = 0; j < 4; j++)
46  {
47  for (int k = 0; k < 4; k++)
48  {
49  m[j][k] = matrix._m[k][j];
50  }
51  }
52  glMultMatrixd((GLdouble*)m);
53 }
55  TYGeometryNode* pDansCeRepere)
56 {
57  TYListPtrGeoNode GeoNodeParents;
58  TYGeometryNode* pThisGeoNode = ((TYGeometryNode*)getElement());
59  pThisGeoNode->GetGeoNodeParentList(GeoNodeParents);
60  TYListPtrGeoNode::iterator ite = GeoNodeParents.end();
61  if (!GeoNodeParents.empty())
62  {
63  ite--; // end n'est jamais valide
64  }
65  int i = 0;
66  int nbPushMatrix = 0;
67  bool bPushMatrix = false;
68  for (i = 0; i < GeoNodeParents.size() && (*ite) != pThisGeoNode; i++)
69  {
70  if (pDansCeRepere == NULL) // NULL = site pere (repere du TYSite le plus haut)
71  {
72  bPushMatrix = true;
73  }
74  if (bPushMatrix)
75  {
76  // PushMatrix
77  TYGeometryNode* pCurrentTYGeometryNode = (TYGeometryNode*)(*ite);
78  LPTYElementGraphic pCurrentTYElementGraphic = pCurrentTYGeometryNode->getGraphicObject();
79  TYGeometryNodeGraphic* pCurrentTYGeometryNodeGraphic =
80  (TYGeometryNodeGraphic*)pCurrentTYElementGraphic.getRealPointer();
81  pCurrentTYGeometryNodeGraphic->pushMatrix();
82  nbPushMatrix++;
83  }
84  if ((*ite) == pDansCeRepere) // NULL = root
85  {
86  bPushMatrix = true;
87  }
88 
89  if (ite != GeoNodeParents.begin())
90  {
91  ite--;
92  }
93  }
94  display(pModelerElement, mode);
95  // PopMatrix
96  for (i = 0; i < nbPushMatrix; i++)
97  {
98  glPopMatrix();
99  }
100 }
101 
102 void TYGeometryNodeGraphic::getChilds(TYListPtrTYElementGraphic& childs, bool recursif /*=true*/)
103 {
104  TYElementGraphic* pTYElementGraphic = (TYElementGraphic*)getElement()->getElement()->getGraphicObject();
105  childs.push_back(pTYElementGraphic);
106  if (recursif)
107  {
108  pTYElementGraphic->getChilds(childs, recursif);
109  }
110 }
111 
113 {
114  OBox reset;
115  _boundingBox = reset;
116  ((TYElementGraphic*)getElement()->getElement()->getGraphicObject())->computeBoundingBox();
117  _boundingBox.Enlarge(((TYElementGraphic*)getElement()->getElement()->getGraphicObject())->GetBox());
118 }
119 
120 void TYGeometryNodeGraphic::display(TYElement* pModelerElement /*= nullptr*/, GLenum mode /*= GL_RENDER*/)
121 {
122  pushMatrix();
123 
124  LPTYElementGraphic pGraphicObject = getElement()->getElement()->getGraphicObject();
125 
126  pGraphicObject->display(pModelerElement, mode);
127 
128  glPopMatrix();
129 }
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.
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
The 4x4 matrix class.
Definition: 3d.h:625
double _m[4][4]
The 4x4 matrix array.
Definition: 3d.h:922
T * getRealPointer()
Definition: smartptr.h:291
classe graphique pour un element de base
virtual void update(bool force=false)
virtual void getChilds(TYListPtrTYElementGraphic &childs, bool recursif=true)
virtual void display(TYElement *pModelerElement=nullptr, GLenum mode=GL_RENDER)
classe graphique pour un GeometryNode
virtual void update(bool force=false)
void displayPushingParentMatrix(TYElement *pModelerElement, GLenum mode, TYGeometryNode *pDansCeRepere)
virtual void display(TYElement *pModelerElement=nullptr, GLenum mode=GL_RENDER)
virtual void getChilds(TYListPtrTYElementGraphic &childs, bool recursif=true)
TYGeometryNodeGraphic(TYGeometryNode *pElement)
void GetGeoNodeParentList(TYListPtrGeoNode &GetGeoNodeParents)