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

Last change on this file since 866 was 866, checked in by garnier, 16 years ago

see history

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