G4OpenGLStoredQtViewer.cc

Go to the documentation of this file.
00001 //
00002 // ********************************************************************
00003 // * License and Disclaimer                                           *
00004 // *                                                                  *
00005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
00006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
00007 // * conditions of the Geant4 Software License,  included in the file *
00008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
00009 // * include a list of copyright holders.                             *
00010 // *                                                                  *
00011 // * Neither the authors of this software system, nor their employing *
00012 // * institutes,nor the agencies providing financial support for this *
00013 // * work  make  any representation or  warranty, express or implied, *
00014 // * regarding  this  software system or assume any liability for its *
00015 // * use.  Please see the license in the file  LICENSE  and URL above *
00016 // * for the full disclaimer and the limitation of liability.         *
00017 // *                                                                  *
00018 // * This  code  implementation is the result of  the  scientific and *
00019 // * technical work of the GEANT4 collaboration.                      *
00020 // * By using,  copying,  modifying or  distributing the software (or *
00021 // * any work based  on the software)  you  agree  to acknowledge its *
00022 // * use  in  resulting  scientific  publications,  and indicate your *
00023 // * acceptance of all terms of the Geant4 Software license.          *
00024 // ********************************************************************
00025 //
00026 //
00027 // $Id$
00028 //
00029 //
00030 // Class G4OpenGLStoredQtViewer : a class derived from G4OpenGLQtViewer and
00031 //                                G4OpenGLStoredViewer.
00032 
00033 #ifdef G4VIS_BUILD_OPENGLQT_DRIVER
00034 
00035 #include "G4OpenGLStoredQtViewer.hh"
00036 
00037 #include "G4OpenGLStoredSceneHandler.hh"
00038 #include "G4ios.hh"
00039 
00040 #include <qapplication.h>
00041 
00042 G4OpenGLStoredQtViewer::G4OpenGLStoredQtViewer
00043 (G4OpenGLStoredSceneHandler& sceneHandler,
00044  const G4String&  name):
00045   G4VViewer (sceneHandler, sceneHandler.IncrementViewCount (), name),
00046   G4OpenGLViewer (sceneHandler),
00047   G4OpenGLQtViewer (sceneHandler),
00048   G4OpenGLStoredViewer (sceneHandler),             // FIXME : gerer le pb du parent !
00049   QGLWidget()
00050 {
00051 
00052   setFocusPolicy(Qt::StrongFocus); // enable keybord events
00053   fHasToRepaint = false;
00054   fIsRepainting = false;
00055 
00056   resize(fVP.GetWindowSizeHintX(),fVP.GetWindowSizeHintY());
00057 
00058   if (fViewId < 0) return;  // In case error in base class instantiation.
00059 }
00060 
00061 G4OpenGLStoredQtViewer::~G4OpenGLStoredQtViewer() {
00062   makeCurrent();
00063   // this is connect to the Dialog for deleting it properly
00064   // when close event.
00065   //   ((QDialog*)window())->reject();
00066 }
00067 
00068 void G4OpenGLStoredQtViewer::Initialise() {
00069 #ifdef G4DEBUG_VIS_OGL
00070   printf("G4OpenGLStoredQtViewer::Initialise 1\n");
00071 #endif
00072   fReadyToPaint = false;
00073   CreateMainWindow (this,QString(GetName()));
00074 
00075   glDrawBuffer (GL_BACK);
00076 
00077   fReadyToPaint = true;
00078 }
00079 
00080 void G4OpenGLStoredQtViewer::initializeGL () {
00081 
00082   InitializeGLView ();
00083 
00084 #ifdef G4DEBUG_VIS_OGL
00085   printf("G4OpenGLStoredQtViewer::InitialiseGL () 1 %d\n", this);
00086 #endif
00087 
00088   if (fSceneHandler.GetScene() == 0) {
00089     fHasToRepaint =false;
00090   } else {
00091     fHasToRepaint =true;
00092   }
00093 
00094    // Set the component visible
00095    setVisible(true) ;
00096 
00097    // and update it immediatly before wait for SessionStart() (batch mode)
00098   QCoreApplication::sendPostedEvents () ;
00099 
00100 #ifdef G4DEBUG_VIS_OGL
00101   printf("G4OpenGLStoredQtViewer::InitialiseGL  END\n");
00102 #endif
00103 }
00104 
00105 G4bool G4OpenGLStoredQtViewer::CompareForKernelVisit(G4ViewParameters& lastVP)
00106 {
00107   // Identical to G4OpenGLStoredViewer::CompareForKernelVisit except
00108   // for checking of VisAttributesModifiers, because
00109   // G4OpenGLStoredQtViewer keeps track of its own touchable
00110   // modifiers (fTreeItemModels, etc.).
00111   if (
00112       (lastVP.GetDrawingStyle ()    != fVP.GetDrawingStyle ())    ||
00113       (lastVP.IsAuxEdgeVisible ()   != fVP.IsAuxEdgeVisible ())   ||
00114       (lastVP.GetRepStyle ()        != fVP.GetRepStyle ())        ||
00115       (lastVP.IsCulling ()          != fVP.IsCulling ())          ||
00116       (lastVP.IsCullingInvisible () != fVP.IsCullingInvisible ()) ||
00117       (lastVP.IsDensityCulling ()   != fVP.IsDensityCulling ())   ||
00118       (lastVP.IsCullingCovered ()   != fVP.IsCullingCovered ())   ||
00119       (lastVP.IsSection ()          != fVP.IsSection ())          ||
00120       // Section (DCUT) implemented locally.  But still need to visit
00121       // kernel if status changes so that back plane culling can be
00122       // switched.
00123       (lastVP.IsCutaway ()          != fVP.IsCutaway ())          ||
00124       // Cutaways implemented locally.  But still need to visit kernel
00125       // if status changes so that back plane culling can be switched.
00126       (lastVP.IsExplode ()          != fVP.IsExplode ())          ||
00127       (lastVP.GetNoOfSides ()       != fVP.GetNoOfSides ())       ||
00128       (lastVP.GetDefaultVisAttributes()->GetColour() !=
00129        fVP.GetDefaultVisAttributes()->GetColour())                ||
00130       (lastVP.GetDefaultTextVisAttributes()->GetColour() !=
00131        fVP.GetDefaultTextVisAttributes()->GetColour())            ||
00132       (lastVP.GetBackgroundColour ()!= fVP.GetBackgroundColour ())||
00133       (lastVP.IsPicking ()          != fVP.IsPicking ())
00134 //      ||
00135 //      (lastVP.GetVisAttributesModifiers().size() !=
00136 //       fVP.GetVisAttributesModifiers().size())
00137       )
00138     return true;
00139 
00140   if (lastVP.IsDensityCulling () &&
00141       (lastVP.GetVisibleDensity () != fVP.GetVisibleDensity ()))
00142     return true;
00143 
00144   /**************************************************************
00145    Section (DCUT) implemented locally.  No need to visit kernel if
00146    section plane itself changes.
00147    if (lastVP.IsSection () &&
00148    (lastVP.GetSectionPlane () != fVP.GetSectionPlane ()))
00149    return true;
00150    ***************************************************************/
00151 
00152   /**************************************************************
00153    Cutaways implemented locally.  No need to visit kernel if cutaway
00154    planes themselves change.
00155    if (lastVP.IsCutaway ()) {
00156    if (lastVP.GetCutawayPlanes ().size () !=
00157    fVP.GetCutawayPlanes ().size ()) return true;
00158    for (size_t i = 0; i < lastVP.GetCutawayPlanes().size(); ++i)
00159    if (lastVP.GetCutawayPlanes()[i] != fVP.GetCutawayPlanes()[i])
00160    return true;
00161    }
00162    ***************************************************************/
00163 
00164   if (lastVP.IsExplode () &&
00165       (lastVP.GetExplodeFactor () != fVP.GetExplodeFactor ()))
00166     return true;
00167 
00168   return false;
00169 }
00170 
00171 G4bool G4OpenGLStoredQtViewer::POSelected(size_t POListIndex)
00172 {
00173   return isTouchableVisible(POListIndex);
00174 }
00175 
00176 G4bool G4OpenGLStoredQtViewer::TOSelected(size_t)
00177 {
00178   return true;
00179 }
00180 
00181 void G4OpenGLStoredQtViewer::DrawView () {  
00182   updateQWidget();
00183 }
00184 
00185 void G4OpenGLStoredQtViewer::ComputeView () {
00186 
00187 #ifdef G4DEBUG_VIS_OGL
00188   printf("G4OpenGLStoredQtViewer::ComputeView %d %d   VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV\n",getWinWidth(), getWinHeight());
00189 #endif
00190   makeCurrent();
00191   G4ViewParameters::DrawingStyle dstyle = GetViewParameters().GetDrawingStyle();
00192 
00193   //Make sure current viewer is attached and clean...
00194 
00195   //See if things have changed from last time and remake if necessary...
00196   // The fNeedKernelVisit flag might have been set by the user in
00197   // /vis/viewer/rebuild, but if not, make decision and set flag only
00198   // if necessary...
00199   if (!fNeedKernelVisit) {
00200     KernelVisitDecision ();
00201   }
00202   G4bool kernelVisitWasNeeded = fNeedKernelVisit; // Keep (ProcessView resets).
00203   ProcessView ();
00204    
00205 
00206   if(dstyle!=G4ViewParameters::hlr &&
00207      haloing_enabled) {
00208 #ifdef G4DEBUG_VIS_OGL
00209     printf("G4OpenGLStoredQtViewer::ComputeView DANS LE IF\n");
00210 #endif
00211 
00212     HaloingFirstPass ();
00213     DrawDisplayLists ();
00214     glFlush ();
00215 
00216     HaloingSecondPass ();
00217 
00218     DrawDisplayLists ();
00219     FinishView ();
00220 
00221   } else {
00222      
00223     // If kernel visit was needed, drawing and FinishView will already
00224     // have been done, so...
00225     if (!kernelVisitWasNeeded) {
00226 #ifdef G4DEBUG_VIS_OGL
00227       printf("**************************  G4OpenGLStoredQtViewer::ComputeView Don't need kernel Visit \n");
00228 #endif
00229       DrawDisplayLists ();
00230       FinishView ();
00231     } else {
00232 #ifdef G4DEBUG_VIS_OGL
00233       printf("**************************  G4OpenGLStoredQtViewer::ComputeView need kernel Visit \n");
00234 #endif
00235       // However, union cutaways are implemented in DrawDisplayLists, so make
00236       // an extra pass...
00237       if (fVP.IsCutaway() &&
00238           fVP.GetCutawayMode() == G4ViewParameters::cutawayUnion) {
00239         ClearView();
00240         DrawDisplayLists ();
00241         FinishView ();
00242 #ifdef G4DEBUG_VIS_OGL
00243         printf("***************************  CASE 4 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \n");
00244 #endif
00245       } else { // ADD TO AVOID KernelVisit=1 and nothing to display
00246         DrawDisplayLists ();
00247         FinishView ();
00248       }
00249     }
00250   }
00251 
00252   if (isRecording()) {
00253     savePPMToTemp();
00254   }
00255 
00256 #ifdef G4DEBUG_VIS_OGL
00257   printf("G4OpenGLStoredQtViewer::ComputeView %d %d ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \n",getWinWidth(), getWinHeight());
00258 #endif
00259   fHasToRepaint = true;
00260 }
00261 
00262 
00266 void G4OpenGLStoredQtViewer::resizeGL(
00267                                       int aWidth
00268                                       ,int aHeight)
00269 {  
00270   // Set new size, it will be update when next Repaint()->SetView() called
00271   if ((aWidth > 0) && (aHeight > 0)) {
00272     ResizeWindow(aWidth,aHeight);
00273     fHasToRepaint = sizeHasChanged();
00274   }
00275 }
00276 
00277 
00278 // We have to get several case :
00279 // - Only activate the windows (mouse click for example) -> Do not redraw
00280 // - resize window -> redraw
00281 // - try to avoid recompute everything if we do not rescale picture (side is the same)
00282  
00283 void G4OpenGLStoredQtViewer::paintGL()
00284 {
00285   updateToolbarAndMouseContextMenu();
00286 
00287 #ifdef G4DEBUG_VIS_OGL
00288   printf("G4OpenGLStoredQtViewer::paintGL \n");
00289 #endif
00290   if (fIsRepainting) {
00291     //    return ;
00292   }
00293   fIsRepainting = true;
00294 #ifdef G4DEBUG_VIS_OGL
00295   printf("G4OpenGLStoredQtViewer::paintGL ready:%d fHasTo:%d??\n",fReadyToPaint,fHasToRepaint);
00296 #endif
00297   if (!fReadyToPaint) {
00298     fReadyToPaint= true;
00299     return;
00300   }
00301   // DO NOT RESIZE IF SIZE HAS NOT CHANGE :
00302   //    WHEN CLICK ON THE FRAME FOR EXAMPLE
00303   //    EXECEPT WHEN MOUSE MOVE EVENT
00304   if ( !fHasToRepaint) {
00305     // L. Garnier : Trap to get the size with mac OSX 10.6 and Qt 4.6(devel)
00306     // Tested on Qt4.5 on mac, 4.4 on windows, 4.5 on unbuntu
00307     int sw = 0;
00308     int sh = 0;
00309     if (!isMaximized() && !isFullScreen()) {
00310       sw = normalGeometry().width();
00311       sh = normalGeometry().height();
00312     } else {
00313       sw = frameGeometry().width();
00314       sh = frameGeometry().height();
00315     }
00316     if ((getWinWidth() == (unsigned int)sw) &&(getWinHeight() == (unsigned int)sh)) {
00317       return;
00318     }
00319   }
00320 #ifdef G4DEBUG_VIS_OGL
00321   printf("G4OpenGLStoredQtViewer::paintGL VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV ready %d\n",fReadyToPaint);
00322 #endif
00323 
00324   SetView();
00325 
00326   ClearView (); //ok, put the background correct
00327   ComputeView();
00328 
00329   fHasToRepaint = false;
00330 
00331   // update the view component tree
00332   displaySceneTreeComponent();
00333 #ifdef G4DEBUG_VIS_OGL
00334   printf("G4OpenGLStoredQtViewer::paintGL ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ready %d\n",fReadyToPaint);
00335 #endif
00336   fIsRepainting = false;
00337 }
00338 
00339 void G4OpenGLStoredQtViewer::paintEvent(QPaintEvent *) {
00340   if ( fHasToRepaint) {
00341     updateGL();
00342   }
00343 }
00344 
00345 void G4OpenGLStoredQtViewer::mousePressEvent(QMouseEvent *event)
00346 {
00347   G4MousePressEvent(event);
00348 }
00349 
00350 void G4OpenGLStoredQtViewer::keyPressEvent (QKeyEvent * event) 
00351 {
00352   G4keyPressEvent(event);
00353 }
00354 
00355 void G4OpenGLStoredQtViewer::wheelEvent (QWheelEvent * event) 
00356 {
00357   G4wheelEvent(event);
00358 }
00359 
00360 void G4OpenGLStoredQtViewer::showEvent (QShowEvent *) 
00361 {
00362   fHasToRepaint = true;
00363 }
00364 
00369 void G4OpenGLStoredQtViewer::mouseDoubleClickEvent(QMouseEvent *)
00370 {
00371   G4MouseDoubleClickEvent();
00372 }
00373 
00374 void G4OpenGLStoredQtViewer::mouseReleaseEvent(QMouseEvent *)
00375 {
00376   G4MouseReleaseEvent();
00377 }
00378 
00379 void G4OpenGLStoredQtViewer::mouseMoveEvent(QMouseEvent *event)
00380 {
00381   G4MouseMoveEvent(event);
00382 }
00383 
00384 
00385 void G4OpenGLStoredQtViewer::contextMenuEvent(QContextMenuEvent *e)
00386 {
00387   G4manageContextMenuEvent(e);
00388 }
00389 
00390 void G4OpenGLStoredQtViewer::updateQWidget() {
00391   fHasToRepaint= true;
00392   updateGL();
00393   fHasToRepaint= false;
00394 }
00395 
00396 void G4OpenGLStoredQtViewer::ShowView (
00397 ) 
00398 
00399 
00400 {
00401   // Some X servers fail to draw all trajectories, particularly Mac
00402   // XQuartz.  Revisit this at a future date.  Meanwhile, issue an
00403   // extra...
00404   ClearView();
00405   DrawView();
00406   activateWindow();
00407   glFlush();
00408 
00409 }
00410 
00411 
00412 void G4OpenGLStoredQtViewer::DisplayTimePOColourModification (
00413 G4Colour& c,
00414 size_t poIndex) {
00415   c = getColorForPoIndex(poIndex);
00416 }
00417 
00418 #endif

Generated on Mon May 27 17:49:10 2013 for Geant4 by  doxygen 1.4.7