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

Last change on this file since 1340 was 1340, checked in by garnier, 14 years ago

update ti head

  • Property svn:mime-type set to text/cpp
File size: 9.2 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//
[1324]27// $Id: G4OpenGLStoredQtViewer.cc,v 1.32 2010/06/23 13:29:23 lgarnier Exp $
[1307]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
[533]36#include "G4OpenGLStoredQtViewer.hh"
[531]37
38#include "G4ios.hh"
39
[533]40G4OpenGLStoredQtViewer::G4OpenGLStoredQtViewer
[531]41(G4OpenGLStoredSceneHandler& sceneHandler,
42 const G4String&  name):
[682]43  G4VViewer (sceneHandler, sceneHandler.IncrementViewCount (), name),
44  G4OpenGLViewer (sceneHandler),
45  G4OpenGLQtViewer (sceneHandler),
[1124]46  G4OpenGLStoredViewer (sceneHandler),             // FIXME : gerer le pb du parent !
47  QGLWidget()
[682]48{
[863]49
[709]50#if QT_VERSION < 0x040000
51  setFocusPolicy(QWidget::StrongFocus); // enable keybord events
52#else
[696]53  setFocusPolicy(Qt::StrongFocus); // enable keybord events
[709]54#endif
[1307]55  fHasToRepaint = false;
56  fIsRepainting = false;
[858]57
[531]58  if (fViewId < 0) return;  // In case error in base class instantiation.
59}
60
[564]61G4OpenGLStoredQtViewer::~G4OpenGLStoredQtViewer() {
[682]62  makeCurrent();
63  // this is connect to the Dialog for deleting it properly
64  // when close event.
65  //   ((QDialog*)window())->reject();
[564]66}
[531]67
[564]68void G4OpenGLStoredQtViewer::Initialise() {
[1040]69  fReadyToPaint = false;
[1164]70  CreateMainWindow (this,QString(GetName()));
[873]71  CreateFontLists ();
[564]72 
[1040]73  fReadyToPaint = true;
[564]74}
[531]75
[564]76void G4OpenGLStoredQtViewer::initializeGL () {
77
[1327]78  //  return;
[1328]79  InitializeGLView ();
[564]80
81
[682]82  // clear the buffers and window.
[1295]83  ClearView ();
84  FinishView ();
[564]85   
[682]86  glDepthFunc (GL_LEQUAL);
87  glDepthMask (GL_TRUE);
[564]88
[866]89  if (fSceneHandler.GetScene() == 0) {
[1040]90    fHasToRepaint =false;
[866]91  } else {
[1040]92    fHasToRepaint =true;
[866]93  }
[564]94
[911]95#ifdef G4DEBUG_VIS_OGL
[873]96  printf("G4OpenGLStoredQtViewer::InitialiseGL  END\n");
[608]97#endif
[531]98}
99
[564]100
[1242]101void G4OpenGLStoredQtViewer::DrawView () { 
[1238]102  updateQWidget();
[877]103}
[682]104
[877]105void G4OpenGLStoredQtViewer::ComputeView () {
[1122]106
107#ifdef G4DEBUG_VIS_OGL
[1039]108  printf("G4OpenGLStoredQtViewer::ComputeView %d %d   VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV\n",getWinWidth(), getWinHeight());
[608]109#endif
[877]110  makeCurrent();
[682]111  G4ViewParameters::DrawingStyle style = GetViewParameters().GetDrawingStyle();
[531]112
[682]113  //Make sure current viewer is attached and clean...
[531]114
[682]115  //See if things have changed from last time and remake if necessary...
116  // The fNeedKernelVisit flag might have been set by the user in
117  // /vis/viewer/rebuild, but if not, make decision and set flag only
118  // if necessary...
[873]119  if (!fNeedKernelVisit) {
[877]120    KernelVisitDecision ();
[873]121  }
[682]122  G4bool kernelVisitWasNeeded = fNeedKernelVisit; // Keep (ProcessView resets).
123  ProcessView ();
[564]124   
[531]125
[682]126  if(style!=G4ViewParameters::hlr &&
127     haloing_enabled) {
[911]128#ifdef G4DEBUG_VIS_OGL
[877]129    printf("G4OpenGLStoredQtViewer::ComputeView DANS LE IF\n");
[608]130#endif
[531]131
[682]132    HaloingFirstPass ();
133    DrawDisplayLists ();
134    glFlush ();
[531]135
[682]136    HaloingSecondPass ();
[531]137
[682]138    DrawDisplayLists ();
139    FinishView ();
[531]140
[682]141  } else {
[564]142     
[682]143    // If kernel visit was needed, drawing and FinishView will already
144    // have been done, so...
145    if (!kernelVisitWasNeeded) {
[911]146#ifdef G4DEBUG_VIS_OGL
[877]147      printf("**************************  G4OpenGLStoredQtViewer::ComputeView Don't need kernel Visit \n");
[608]148#endif
[682]149      DrawDisplayLists ();
150      FinishView ();
151    } else {
[911]152#ifdef G4DEBUG_VIS_OGL
[877]153      printf("**************************  G4OpenGLStoredQtViewer::ComputeView need kernel Visit \n");
[608]154#endif
[682]155      // However, union cutaways are implemented in DrawDisplayLists, so make
156      // an extra pass...
157      if (fVP.IsCutaway() &&
158          fVP.GetCutawayMode() == G4ViewParameters::cutawayUnion) {
159        ClearView();
160        DrawDisplayLists ();
161        FinishView ();
[911]162#ifdef G4DEBUG_VIS_OGL
[682]163        printf("***************************  CASE 4 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \n");
[608]164#endif
[682]165      } else { // ADD TO AVOID KernelVisit=1 and nothing to display
166        DrawDisplayLists ();
167        FinishView ();
168      }
169    }
170  }
[564]171
[745]172  if (isRecording()) {
[739]173    savePPMToTemp();
[724]174  }
175
[911]176#ifdef G4DEBUG_VIS_OGL
[1039]177  printf("G4OpenGLStoredQtViewer::ComputeView %d %d ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \n",getWinWidth(), getWinHeight());
[608]178#endif
[1307]179  fHasToRepaint = true;
[531]180}
181
[564]182
183/**
[682]184   - Lors du resize de la fenetre, on doit non pas redessiner le detecteur, mais aussi les evenements
185*/
[564]186void G4OpenGLStoredQtViewer::resizeGL(
[1039]187                                      int aWidth
188                                      ,int aHeight)
[564]189
[1121]190  // Set new size, it will be update when next Repaint()->SetView() called
[1307]191  if ((aWidth > 0) && (aHeight > 0)) {
192    ResizeWindow(aWidth,aHeight);
193    fHasToRepaint = sizeHasChanged();
194  }
[1121]195}
196
[1124]197
[1227]198// We have to get several case :
199// - Only activate the windows (mouse click for example) -> Do not redraw
200// - resize window -> redraw
201// - try to avoid recompute everything if we do not rescale picture (side is the same)
202 
[1121]203void G4OpenGLStoredQtViewer::paintGL()
204{
[1310]205#ifdef G4DEBUG_VIS_OGL
206  printf("G4OpenGLStoredQtViewer::paintGL \n");
207#endif
[1307]208  if (fIsRepainting) {
[1311]209    //    return ;
[1307]210  }
211  fIsRepainting = true;
[1121]212#ifdef G4DEBUG_VIS_OGL
[1242]213  printf("G4OpenGLStoredQtViewer::paintGL ready:%d fHasTo:%d??\n",fReadyToPaint,fHasToRepaint);
[873]214#endif
[1040]215  if (!fReadyToPaint) {
216    fReadyToPaint= true;
[682]217    return;
218  }
[1039]219  // DO NOT RESIZE IF SIZE HAS NOT CHANGE :
220  //    WHEN CLICK ON THE FRAME FOR EXAMPLE
221  //    EXECEPT WHEN MOUSE MOVE EVENT
[1040]222  if ( !fHasToRepaint) {
[1141]223#if QT_VERSION < 0x040000
224    if (((getWinWidth() == (unsigned int)width())) &&(getWinHeight() == (unsigned int) height())) {
225#else
[1125]226    // L. Garnier : Trap to get the size with mac OSX 10.6 and Qt 4.6(devel)
227    // Tested on Qt4.5 on mac, 4.4 on windows, 4.5 on unbuntu
228    int sw = 0;
229    int sh = 0;
230    if (!isMaximized() && !isFullScreen()) {
231      sw = normalGeometry().width();
232      sh = normalGeometry().height();
233    } else {
234      sw = frameGeometry().width();
235      sh = frameGeometry().height();
236    }
[1126]237    if ((getWinWidth() == (unsigned int)sw) &&(getWinHeight() == (unsigned int)sh)) {
[1141]238#endif
[1039]239      return;
240    }
241  }
242#ifdef G4DEBUG_VIS_OGL
[1040]243  printf("G4OpenGLStoredQtViewer::paintGL VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV ready %d\n",fReadyToPaint);
[1039]244#endif
[873]245
[1141]246  SetView();
[1307]247
[1141]248  ClearView (); //ok, put the background correct
[1039]249  ComputeView();
[1227]250
[1307]251  fHasToRepaint = false;
[1242]252
[911]253#ifdef G4DEBUG_VIS_OGL
[1124]254  printf("G4OpenGLStoredQtViewer::paintGL ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ready %d\n",fReadyToPaint);
[608]255#endif
[1307]256  fIsRepainting = false;
[682]257}
[564]258
[1322]259void G4OpenGLStoredQtViewer::paintEvent(QPaintEvent *) {
[1235]260  if ( fHasToRepaint) {
261    updateGL();
262  }
263}
264
[564]265void G4OpenGLStoredQtViewer::mousePressEvent(QMouseEvent *event)
266{
[1124]267  G4MousePressEvent(event);
[564]268}
269
[696]270void G4OpenGLStoredQtViewer::keyPressEvent (QKeyEvent * event)
271{
272  G4keyPressEvent(event);
273}
274
[804]275void G4OpenGLStoredQtViewer::wheelEvent (QWheelEvent * event)
276{
277  G4wheelEvent(event);
278}
279
[1322]280void G4OpenGLStoredQtViewer::showEvent (QShowEvent *)
[1240]281{
282  fHasToRepaint = true;
283}
284
[678]285/**
286 * This function was build in order to make a zoom on double clic event.
287 * It was think to build a rubberband on the zoom area, but never work fine
288 */
[955]289void G4OpenGLStoredQtViewer::mouseDoubleClickEvent(QMouseEvent *)
[673]290{
[873]291  G4MouseDoubleClickEvent();
[673]292}
293
[955]294void G4OpenGLStoredQtViewer::mouseReleaseEvent(QMouseEvent *)
[673]295{
[797]296  G4MouseReleaseEvent();
[673]297}
298
[564]299void G4OpenGLStoredQtViewer::mouseMoveEvent(QMouseEvent *event)
300{
[873]301  G4MouseMoveEvent(event);
[564]302}
303
304
305void G4OpenGLStoredQtViewer::contextMenuEvent(QContextMenuEvent *e)
306{
[873]307  G4manageContextMenuEvent(e);
[564]308}
309
310void G4OpenGLStoredQtViewer::updateQWidget() {
[1040]311  fHasToRepaint= true;
[564]312  updateGL();
[1040]313  fHasToRepaint= false;
[564]314}
315
[877]316void G4OpenGLStoredQtViewer::ShowView (
317)
318//////////////////////////////////////////////////////////////////////////////
319//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
320{
321#if QT_VERSION < 0x040000
322  setActiveWindow();
323#else
324  activateWindow();
325#endif
326}
[673]327
[531]328#endif
Note: See TracBrowser for help on using the repository browser.