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