source: trunk/source/visualization/OpenGL/src/G4OpenGLStoredQtViewer.cc@ 859

Last change on this file since 859 was 858, checked in by garnier, 17 years ago

protection against no scene + Qapp could be now get on external app

  • Property svn:mime-type set to text/cpp
File size: 10.9 KB
RevLine 
[531]1//
2// ********************************************************************
3// * License and Disclaimer *
4// * *
5// * The Geant4 software is copyright of the Copyright Holders of *
6// * the Geant4 Collaboration. It is provided under the terms and *
7// * conditions of the Geant4 Software License, included in the file *
8// * LICENSE and available at http://cern.ch/geant4/license . These *
9// * include a list of copyright holders. *
10// * *
11// * Neither the authors of this software system, nor their employing *
12// * institutes,nor the agencies providing financial support for this *
13// * work make any representation or warranty, express or implied, *
14// * regarding this software system or assume any liability for its *
15// * use. Please see the license in the file LICENSE and URL above *
16// * for the full disclaimer and the limitation of liability. *
17// * *
18// * This code implementation is the result of the scientific and *
19// * technical work of the GEANT4 collaboration. *
20// * By using, copying, modifying or distributing the software (or *
21// * any work based on the software) you agree to acknowledge its *
22// * use in resulting scientific publications, and indicate your *
23// * acceptance of all terms of the Geant4 Software license. *
24// ********************************************************************
25//
26//
[846]27// $Id: G4OpenGLStoredQtViewer.cc,v 1.15 2008/06/20 13:55:06 lgarnier Exp $
[850]28// GEANT4 tag $Name: HEAD $
[531]29//
[564]30//
[533]31// Class G4OpenGLStoredQtViewer : a class derived from G4OpenGLQtViewer and
[564]32// G4OpenGLStoredViewer.
[531]33
[533]34#ifdef G4VIS_BUILD_OPENGLQT_DRIVER
[531]35
[799]36//#define GEANT4_QT_DEBUG
[610]37
[533]38#include "G4OpenGLStoredQtViewer.hh"
[531]39
40#include "G4ios.hh"
41
[595]42//#include <qmouseevent.h>
43#include <qevent.h> // include <qcontextmenuevent.h>
[593]44
[533]45G4OpenGLStoredQtViewer::G4OpenGLStoredQtViewer
[531]46(G4OpenGLStoredSceneHandler& sceneHandler,
47 const G4String& name):
[682]48 G4VViewer (sceneHandler, sceneHandler.IncrementViewCount (), name),
49 G4OpenGLViewer (sceneHandler),
50 G4OpenGLQtViewer (sceneHandler),
[709]51 G4OpenGLStoredViewer (sceneHandler) // FIXME : gerer le pb du parent !
[682]52{
[709]53#if QT_VERSION < 0x040000
54 setFocusPolicy(QWidget::StrongFocus); // enable keybord events
55#else
[696]56 setFocusPolicy(Qt::StrongFocus); // enable keybord events
[709]57#endif
[682]58 nbPaint =0;
59 hasToRepaint =false;
[858]60
61 // if no scene...
62 if (fSceneHandler.GetScene() == 0) {
63 G4cerr << "G4OpenGLStoredQtViewer: Creating a Viewer without a scene is not allowed. \nPlease use /vis/scene/create before /vis/open/.... "
64 << G4endl;
65 return;
66 }
[531]67 if (fViewId < 0) return; // In case error in base class instantiation.
68}
69
[564]70G4OpenGLStoredQtViewer::~G4OpenGLStoredQtViewer() {
[608]71#ifdef GEANT4_QT_DEBUG
[682]72 printf("GLWidget::~GLWidget \n");
[608]73#endif
[682]74 makeCurrent();
75 // this is connect to the Dialog for deleting it properly
76 // when close event.
77 // ((QDialog*)window())->reject();
[608]78#ifdef GEANT4_QT_DEBUG
[682]79 printf("GLWidget::~GLWidget END\n");
[608]80#endif
[564]81}
[531]82
[564]83void G4OpenGLStoredQtViewer::Initialise() {
[608]84#ifdef GEANT4_QT_DEBUG
[858]85 printf("G4OpenGLStoredQtViewer::Initialise 1\n");
[608]86#endif
[682]87 readyToPaint = false;
88 CreateGLQtContext ();
[608]89#ifdef GEANT4_QT_DEBUG
[682]90 printf("G4OpenGLStoredQtViewer::Initialise () 2\n");
[608]91#endif
[564]92 CreateMainWindow (this);
[608]93#ifdef GEANT4_QT_DEBUG
[564]94 printf("G4OpenGLStoredQtViewer::Initialise () 3\n");
[608]95#endif
[682]96 CreateFontLists (); // FIXME Does nothing!
[564]97
[608]98#ifdef GEANT4_QT_DEBUG
[564]99 printf("readyToPaint = true \n");
[608]100#endif
[564]101 readyToPaint = true;
102}
[531]103
[564]104void G4OpenGLStoredQtViewer::initializeGL () {
105
[682]106 InitializeGLView ();
[564]107
[608]108#ifdef GEANT4_QT_DEBUG
[682]109 printf("G4OpenGLStoredQtViewer::InitialiseGL () 1\n");
[608]110#endif
[564]111
[682]112 // clear the buffers and window.
113 ClearView ();
114 // printf("G4OpenGLStoredQtViewer::InitialiseGL () 2\n");
115 FinishView ();
[564]116
[682]117 glDepthFunc (GL_LEQUAL);
118 glDepthMask (GL_TRUE);
[564]119
[682]120 hasToRepaint =true;
[564]121
[608]122#ifdef GEANT4_QT_DEBUG
[682]123 printf("G4OpenGLStoredQtViewer::InitialiseGL -------------------------------------------------------------------------------------\n");
[608]124#endif
[531]125}
126
[564]127
[533]128void G4OpenGLStoredQtViewer::DrawView () {
[682]129
[608]130#ifdef GEANT4_QT_DEBUG
[800]131 printf("G4OpenGLQtViewer::setupViewport\n");
[564]132 printf("G4OpenGLStoredQtViewer::DrawView %d %d VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV\n",WinSize_x, WinSize_y);
[608]133#endif
[682]134 G4ViewParameters::DrawingStyle style = GetViewParameters().GetDrawingStyle();
[531]135
[682]136 //Make sure current viewer is attached and clean...
137 //Qt version needed
138 // glViewport (0, 0, WinSize_x, WinSize_y);
[531]139
[682]140 //See if things have changed from last time and remake if necessary...
141 // The fNeedKernelVisit flag might have been set by the user in
142 // /vis/viewer/rebuild, but if not, make decision and set flag only
143 // if necessary...
144 if (!fNeedKernelVisit)
[565]145
[682]146 if (!fNeedKernelVisit) KernelVisitDecision ();
[565]147
[682]148 G4bool kernelVisitWasNeeded = fNeedKernelVisit; // Keep (ProcessView resets).
149 ProcessView ();
[564]150
[531]151
[682]152 if(style!=G4ViewParameters::hlr &&
153 haloing_enabled) {
[608]154#ifdef GEANT4_QT_DEBUG
[682]155 printf("G4OpenGLStoredQtViewer::DrawView DANS LE IF\n");
[608]156#endif
[531]157
[682]158 HaloingFirstPass ();
159 DrawDisplayLists ();
160 glFlush ();
[531]161
[682]162 HaloingSecondPass ();
[531]163
[682]164 DrawDisplayLists ();
165 FinishView ();
[531]166
[682]167 } else {
[564]168
[682]169 // If kernel visit was needed, drawing and FinishView will already
170 // have been done, so...
171 if (!kernelVisitWasNeeded) {
[608]172#ifdef GEANT4_QT_DEBUG
[797]173 printf("************************** G4OpenGLStoredQtViewer::DrawView Don't need kernel Visit \n");
[608]174#endif
[682]175 DrawDisplayLists ();
176 FinishView ();
177 } else {
[608]178#ifdef GEANT4_QT_DEBUG
[797]179 printf("************************** G4OpenGLStoredQtViewer::DrawView need kernel Visit \n");
[608]180#endif
[682]181 // However, union cutaways are implemented in DrawDisplayLists, so make
182 // an extra pass...
183 if (fVP.IsCutaway() &&
184 fVP.GetCutawayMode() == G4ViewParameters::cutawayUnion) {
185 ClearView();
186 DrawDisplayLists ();
187 FinishView ();
[608]188#ifdef GEANT4_QT_DEBUG
[682]189 printf("*************************** CASE 4 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \n");
[608]190#endif
[682]191 } else { // ADD TO AVOID KernelVisit=1 and nothing to display
192 DrawDisplayLists ();
193 FinishView ();
194 }
195 }
196 }
[564]197
[745]198 if (isRecording()) {
[739]199 savePPMToTemp();
[724]200 }
201
202#ifdef GEANT4_QT_DEBUG
[682]203 printf("G4OpenGLStoredQtViewer::DrawView %d %d ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \n",WinSize_x, WinSize_y);
[608]204#endif
[682]205 hasToRepaint =true;
[531]206}
207
[564]208
[531]209//////////////////////////////////////////////////////////////////////////////
[533]210void G4OpenGLStoredQtViewer::FinishView (
[531]211)
212//////////////////////////////////////////////////////////////////////////////
213//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
214{
215 glFlush ();
[564]216 swapBuffers ();
[531]217}
218
[564]219
220/**
[682]221 - Lors du resize de la fenetre, on doit non pas redessiner le detecteur, mais aussi les evenements
222*/
[564]223void G4OpenGLStoredQtViewer::resizeGL(
[682]224 int aWidth
225 ,int aHeight)
[564]226{
[673]227 setupViewport(aWidth,aHeight);
[564]228
[682]229 if (((WinSize_x != (G4int)aWidth)) || (WinSize_y != (G4int) aHeight)) {
230 hasToRepaint =true;
231 }
232 WinSize_x = (G4int) aWidth;
233 WinSize_y = (G4int) aHeight;
234
[608]235#ifdef GEANT4_QT_DEBUG
[564]236 printf("G4OpenGLStoredQtViewer::resizeGL ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ %d %d=%d %d=%d\n",hasToRepaint,width(),aWidth,height(),aHeight);
[608]237#endif
[564]238}
239
240
[673]241/**
[682]242 @see :
[673]243*/
[564]244
245void G4OpenGLStoredQtViewer::paintGL()
[682]246{
247 if (!readyToPaint) {
[608]248#ifdef GEANT4_QT_DEBUG
[682]249 printf("G4OpenGLStoredQtViewer::paintGL ============ Not ready %d\n",readyToPaint);
[608]250#endif
[682]251 readyToPaint= true;
252 return;
253 }
254 // DO NOT RESIZE IF SIZE HAS NOT CHANGE :
255 // WHEN CLICK ON THE FRAME FOR EXAMPLE
256 // EXECEPT WHEN MOUSE MOVE EVENT
257 if ( !hasToRepaint) {
258 if (((WinSize_x == (G4int)width())) &&(WinSize_y == (G4int) height())) {
[608]259#ifdef GEANT4_QT_DEBUG
[682]260 printf("G4OpenGLStoredQtViewer::paintGL ============ Dont repaint\n");
[608]261#endif
[682]262 return;
263 }
264 }
265 nbPaint++;
[608]266#ifdef GEANT4_QT_DEBUG
[682]267 printf("G4OpenGLStoredQtViewer::paintGL VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV %d ready %d\n",nbPaint,readyToPaint);
[608]268#endif
[682]269 WinSize_x = (G4int) width();
270 WinSize_y = (G4int) height();
[673]271
[682]272 setupViewport(width(),height());
273 // glViewport (0, 0, width(), height());
274 // glLoadIdentity();
[673]275
276
[682]277 SetView();
[673]278
[682]279 // // printf("before ClearView\n");
[608]280#ifdef GEANT4_QT_DEBUG
[682]281 printf(" ClearView\n");
[608]282#endif
[673]283
[682]284 ClearView (); //ok, put the background correct
285 DrawView();
[673]286
[682]287 hasToRepaint =false;
[673]288
[608]289#ifdef GEANT4_QT_DEBUG
[682]290 printf("G4OpenGLStoredQtViewer::paintGL ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ %d ready %d\n",nbPaint,readyToPaint);
[608]291#endif
[682]292}
[564]293
294void G4OpenGLStoredQtViewer::mousePressEvent(QMouseEvent *event)
295{
[709]296#if QT_VERSION < 0x040000
297 if ((event->button() & Qt::LeftButton)
298 && !((event->state() & Qt::ShiftButton)
299 || (event->state() & Qt::ControlButton)
300 || (event->state() & Qt::AltButton)
301 || (event->state() & Qt::MetaButton))) {
302#else
[690]303 if ((event->buttons() & Qt::LeftButton)
304 && !((event->modifiers() & Qt::ShiftModifier)
305 || (event->modifiers() & Qt::ControlModifier)
306 || (event->modifiers() & Qt::AltModifier)
307 || (event->modifiers() & Qt::MetaModifier))) {
[709]308#endif
[608]309#ifdef GEANT4_QT_DEBUG
[682]310 printf("G4OpenGLStoredQtViewer::mousePressEvent\n");
[608]311#endif
[682]312 setMouseTracking(true);
[797]313 G4MousePressEvent(event->pos());
[682]314 }
[564]315}
316
[696]317void G4OpenGLStoredQtViewer::keyPressEvent (QKeyEvent * event)
318{
319 G4keyPressEvent(event);
320}
321
[804]322void G4OpenGLStoredQtViewer::wheelEvent (QWheelEvent * event)
323{
324 G4wheelEvent(event);
325}
326
[678]327/**
328 * This function was build in order to make a zoom on double clic event.
329 * It was think to build a rubberband on the zoom area, but never work fine
330 */
[673]331void G4OpenGLStoredQtViewer::mouseDoubleClickEvent(QMouseEvent *event)
332{
333#ifdef GEANT4_QT_DEBUG
334 printf("G4OpenGLStoredQtViewer::mouseDoubleClickEvent\n");
335#endif
[720]336 setMouseTracking(true);
[682]337 // glBufferImage = grabFrameBuffer().convertToFormat(QImage::Format_ARGB32);//_Premultiplied);
[673]338}
339
340void G4OpenGLStoredQtViewer::mouseReleaseEvent(QMouseEvent *event)
341{
[797]342 G4MouseReleaseEvent();
[673]343#ifdef GEANT4_QT_DEBUG
[797]344 printf("G4OpenGLStoredQtViewer::mouseReleaseEvent ================\n");
[673]345#endif
[720]346 setMouseTracking(false);
[673]347}
348
[564]349void G4OpenGLStoredQtViewer::mouseMoveEvent(QMouseEvent *event)
350{
[720]351
[606]352#if QT_VERSION < 0x040000
[720]353 G4MouseMoveEvent(event->x(),event->y(),event->state());
[606]354#else
[720]355 G4MouseMoveEvent(event->x(),event->y(),event->buttons());
[606]356#endif
[564]357}
358
359
360void G4OpenGLStoredQtViewer::contextMenuEvent(QContextMenuEvent *e)
361{
[635]362#ifdef GEANT4_QT_DEBUG
363 printf("G4OpenGLStoredQtViewer::contextMenuEvent\n");
364#endif
[564]365 manageContextMenuEvent(e);
366}
367
368void G4OpenGLStoredQtViewer::updateQWidget() {
369 hasToRepaint= true;
370 updateGL();
371 hasToRepaint= false;
372}
373
[673]374
[531]375#endif
Note: See TracBrowser for help on using the repository browser.