Code_TYMPAN  4.4.0
Industrial site acoustic simulation
TYRenderWindow.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 
25 #include "TYRenderWindow.h"
26 
27 #define IMG(id) OLocalizator::getPicture("TYRenderWindow", (id))
28 
29 TYRenderWindow::TYRenderWindow(QGLFormat glf, QWidget* parent, const char* name) : QGLWidget(glf, parent)
30 {
31  setObjectName(name);
33 }
34 
35 TYRenderWindow::TYRenderWindow(QWidget* parent, const char* name) : QGLWidget(parent)
36 {
37  setObjectName(name);
39 }
40 
42 {
43  _initNeeded = true;
44  _showInfos = false;
45 
47 
48  // Label info
49  OColor oColor;
52  oColor.r = oColor.g = oColor.b = 0.5;
54  _pOGLTextInfoLabel->setFont(IMG("id_font"));
58 
59  // just enable one double buffering
60  // by default, we use the one of vtk
61  /*#ifdef QT_DOUBLEBUFFER
62  // use the double buffering of QT
63  _pRenderWindow->SetSwapBuffers(0);
64  #else
65  // use the double buffering of vtk
66  setAutoBufferSwap(false);
67  #endif*/
68 
69  // Gestion du focus
70  setFocusProxy(parentWidget());
71 }
72 
74 {
75  delete _pOGLTextInfoLabel;
76  //_pInfoLabelMapper->Delete();
77  delete _pRenderer; // az++
78 }
79 
81 {
82  return _pRenderer;
83 }
84 
85 void TYRenderWindow::showInfos(bool state)
86 {
87  _showInfos = state;
89 
90  // if (!_showInfos) {
91  // _pInfoLabelMapper->SetInput("");
92  // }
93 
94  updateGL();
95 }
96 
98 {
99  _pRenderer->init(width(), height()); // xbh
100 }
101 
102 void TYRenderWindow::resizeGL(int w, int h)
103 {
104  _pRenderer->init(width(), height()); // xbh
105  updateGL();
106  // _pRenderer->updateDisplayList();
107 }
108 
110 {
111  makeCurrent();
112  QGLWidget::updateGL();
113 }
114 
116 {
117  // On donne les dimension de la fenetre au SizeManager
118  OSizeManager::get()->setWidth(width());
119  OSizeManager::get()->setHeight(height());
120 
121  clock_t timeBefore = clock();
123  clock_t timeAfter = clock();
124 
125  double timeElaspedInSec = ((double)(timeAfter - timeBefore)) / (double)CLOCKS_PER_SEC;
126 
127  if (_showInfos)
128  {
129  writeOutputMsg(QString("FPS = %1").arg(1.0 / timeElaspedInSec, 0, 'f', 2));
130  _pOGLTextInfoLabel->setTextToDisplay(QString("FPS = %1").arg(1.0 / timeElaspedInSec, 0, 'f', 2));
131  }
132 }
void writeOutputMsg(QString msg)
Affiche un message dans la fenetre de sortie.
pour l'application Tympan (fichier header)
#define IMG(id)
association du graphic (OpenGL) au modeleur (fichier header)
const char * name
Definition: color.h:31
float b
Definition: color.h:33
float r
Definition: color.h:33
float g
Definition: color.h:33
void setVisibility(bool bVisible)
Definition: OGLElement.h:51
void setDisplayPosition(double displayPositionX, double displayPositionY)
Definition: OGLElement.h:46
void setColor(const OColor &oColor)
void setTextToDisplay(const QString &qsText)
void setFont(const QString &qsFontPath)
static LPOSizeManager get()
Realise le rendu VTK et le rendu OpenGL.
void addOGLElement(OGLElement *pOGLElement)
void OpenGLRender(GLenum mode=GL_RENDER, int x=0, int y=0)
void init(int width, int height)
virtual void updateGL()
virtual void initializeGL()
TYRenderWindow(QGLFormat glf, QWidget *pParent=0, const char *name=0)
virtual void resizeGL(int w, int h)
TYOpenGLRenderer * _pRenderer
void showInfos(bool state)
TYOpenGLRenderer * getRenderer()
virtual void paintGL()
OGLTextElement * _pOGLTextInfoLabel