source: trunk/geant4/visualization/OpenGL/src/G4OpenGLStoredQtViewer.cc @ 608

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

r657@mac-90108: laurentgarnier | 2007-11-15 19:44:52 +0100
ajout d un flag pour debug

  • Property svn:mime-type set to text/cpp
File size: 9.6 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//
[608]27// $Id: G4OpenGLStoredQtViewer.cc,v 1.6 2007/11/15 18:24:28 lgarnier Exp $
[593]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"
[564]37#include "G4VisManager.hh"
[531]38
39#include "G4ios.hh"
40
[595]41//#include <qmouseevent.h>
42#include <qevent.h> // include <qcontextmenuevent.h>
[593]43
[533]44G4OpenGLStoredQtViewer::G4OpenGLStoredQtViewer
[531]45(G4OpenGLStoredSceneHandler& sceneHandler,
46 const G4String&  name):
[564]47 G4VViewer (sceneHandler, sceneHandler.IncrementViewCount (), name),
48 G4OpenGLViewer (sceneHandler),
49 G4OpenGLQtViewer (sceneHandler),
50 G4OpenGLStoredViewer (sceneHandler),
51 QGLWidget()                      // FIXME : gerer le pb du parent !
52 {
53   nbPaint =0;
54   hasToRepaint =false;
[531]55  if (fViewId < 0) return;  // In case error in base class instantiation.
56}
57
[564]58G4OpenGLStoredQtViewer::~G4OpenGLStoredQtViewer() {
[608]59#ifdef GEANT4_QT_DEBUG
[564]60   printf("GLWidget::~GLWidget \n");
[608]61#endif
[579]62   makeCurrent();
63   // this is connect to the Dialog for deleting it properly
64   // when close event.
65   //   ((QDialog*)window())->reject();
[608]66#ifdef GEANT4_QT_DEBUG
[564]67   printf("GLWidget::~GLWidget END\n");
[608]68#endif
[564]69}
[531]70
[564]71void G4OpenGLStoredQtViewer::Initialise() {
[608]72#ifdef GEANT4_QT_DEBUG
[564]73   printf("GLWidget::Initialise \n");
[608]74#endif
[564]75   readyToPaint = false;
76   CreateGLQtContext ();
[608]77#ifdef GEANT4_QT_DEBUG
[564]78   printf("G4OpenGLStoredQtViewer::Initialise () 2\n");
[608]79#endif
[564]80  CreateMainWindow (this);
[608]81#ifdef GEANT4_QT_DEBUG
[564]82  printf("G4OpenGLStoredQtViewer::Initialise () 3\n");
[608]83#endif
[564]84  CreateFontLists ();  // FIXME Does nothing!
85 
[608]86#ifdef GEANT4_QT_DEBUG
[564]87  printf("readyToPaint = true \n");
[608]88#endif
[564]89  readyToPaint = true;
90 
91  // First Draw
92  SetView();
[608]93#ifdef GEANT4_QT_DEBUG
[564]94  printf("    ClearView\n");
[608]95#endif
[564]96  ClearView (); //ok, put the background correct
97  ShowView();
98  FinishView();
99}
[531]100
[564]101void G4OpenGLStoredQtViewer::initializeGL () {
102
103   InitializeGLView ();
104
[608]105#ifdef GEANT4_QT_DEBUG
[564]106   printf("G4OpenGLStoredQtViewer::InitialiseGL () 1\n");
[608]107#endif
[564]108
109   // clear the buffers and window.
110   ClearView ();
111   //   printf("G4OpenGLStoredQtViewer::InitialiseGL () 2\n");
112   FinishView ();
113   
114   glDepthFunc (GL_LEQUAL);
115   glDepthMask (GL_TRUE);
116
117   hasToRepaint =true;
118
[608]119#ifdef GEANT4_QT_DEBUG
[564]120   printf("G4OpenGLStoredQtViewer::InitialiseGL  -------------------------------------------------------------------------------------\n");
[608]121#endif
[531]122}
123
[564]124
[533]125void G4OpenGLStoredQtViewer::DrawView () {
[531]126
[608]127#ifdef GEANT4_QT_DEBUG
[564]128  printf("G4OpenGLStoredQtViewer::DrawView %d %d   VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV\n",WinSize_x, WinSize_y);
[579]129  printf("G4OpenGLStoredQtViewer::DrawView Dialog adress : %d\n",GLWindow);
[608]130#endif
[564]131   G4ViewParameters::DrawingStyle style = GetViewParameters().GetDrawingStyle();
[531]132
[564]133   //Make sure current viewer is attached and clean...
134   //Qt version needed
135   glViewport (0, 0, WinSize_x, WinSize_y);
[531]136
[564]137   //See if things have changed from last time and remake if necessary...
138   // The fNeedKernelVisit flag might have been set by the user in
139   // /vis/viewer/rebuild, but if not, make decision and set flag only
140   // if necessary...
[565]141   if (!fNeedKernelVisit)
142
[564]143   if (!fNeedKernelVisit) KernelVisitDecision ();
[565]144   
[564]145   G4bool kernelVisitWasNeeded = fNeedKernelVisit; // Keep (ProcessView resets).
146   ProcessView ();
147   
[531]148
[564]149   if(style!=G4ViewParameters::hlr &&
150      haloing_enabled) {
[608]151#ifdef GEANT4_QT_DEBUG
[564]152     printf("G4OpenGLStoredQtViewer::DrawView DANS LE IF\n");
[608]153#endif
[531]154
[564]155     HaloingFirstPass ();
156     DrawDisplayLists ();
157     glFlush ();
[531]158
[564]159     HaloingSecondPass ();
[531]160
[564]161     DrawDisplayLists ();
[565]162     FinishView ();
[531]163
[564]164   } else {
[608]165#ifdef GEANT4_QT_DEBUG
[565]166     printf("***************************  CASE 1 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \n");
[608]167#endif
[564]168     
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
[565]173       printf("***************************  CASE 2 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \n");
[608]174#endif
[564]175       DrawDisplayLists ();
[565]176       FinishView ();
[564]177     } else {
[608]178#ifdef GEANT4_QT_DEBUG
[565]179       printf("***************************  CASE 3 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \n");
[608]180#endif
[564]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 ();
[565]187         FinishView ();
[608]188#ifdef GEANT4_QT_DEBUG
[565]189         printf("***************************  CASE 4 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \n");
[608]190#endif
[565]191       } else { // ADD TO AVOID KernelVisit=1 and nothing to display
192         DrawDisplayLists ();
193         FinishView ();
[564]194       }
195     }
196   }
197
[608]198#ifdef GEANT4_QT_DEBUG
[565]199   printf("G4OpenGLStoredQtViewer::DrawView %d %d ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \n",WinSize_x, WinSize_y);
[608]200#endif
[564]201   hasToRepaint =true;
[531]202}
203
[564]204
[531]205//////////////////////////////////////////////////////////////////////////////
[533]206void G4OpenGLStoredQtViewer::FinishView (
[531]207)
208//////////////////////////////////////////////////////////////////////////////
209//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
210{
[608]211#ifdef GEANT4_QT_DEBUG
[564]212  printf("G4OpenGLStoredQtViewer::FinishView VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV\n");
[608]213#endif
[531]214
215  glFlush ();
[564]216  swapBuffers ();
[608]217#ifdef GEANT4_QT_DEBUG
[564]218  printf("G4OpenGLStoredQtViewer::FinishView ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \n");
[608]219#endif
[564]220
[531]221}
222
[564]223
224/**
225 - Lors du resize de la fenetre, on doit non pas redessiner le detecteur, mais aussi les evenements
226 */
227void G4OpenGLStoredQtViewer::resizeGL(
228 int aWidth
229,int aHeight)
230
231  glViewport(0, 0, aWidth, aHeight);
232  glMatrixMode(GL_PROJECTION);
233  glMatrixMode(GL_MODELVIEW);
234
235   if (((WinSize_x != (G4int)aWidth)) || (WinSize_y != (G4int) aHeight)) {
236     hasToRepaint =true;
237   }
238   WinSize_x = (G4int) aWidth;
239   WinSize_y = (G4int) aHeight;
240
[608]241#ifdef GEANT4_QT_DEBUG
[564]242  printf("G4OpenGLStoredQtViewer::resizeGL ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ %d %d=%d %d=%d\n",hasToRepaint,width(),aWidth,height(),aHeight);
[608]243#endif
[564]244}
245
246
247
248void G4OpenGLStoredQtViewer::paintGL()
249 {
250   if (!readyToPaint) {
[608]251#ifdef GEANT4_QT_DEBUG
[579]252     printf("G4OpenGLStoredQtViewer::paintGL ============  Not ready %d\n",readyToPaint);
[608]253#endif
[564]254     readyToPaint= true;
255     return;
256   }
257   // DO NOT RESIZE IF SIZE HAS NOT CHANGE :
258   //    WHEN CLICK ON THE FRAME FOR EXAMPLE
259   //    EXECEPT WHEN MOUSE MOVE EVENT
260   if ( !hasToRepaint) {
261     if (((WinSize_x == (G4int)width())) &&(WinSize_y == (G4int) height())) {
[608]262#ifdef GEANT4_QT_DEBUG
[579]263       printf("G4OpenGLStoredQtViewer::paintGL ============  Dont repaint\n");
[608]264#endif
[564]265       return;
266     }
267   }
268   nbPaint++;
[608]269#ifdef GEANT4_QT_DEBUG
[579]270   printf("G4OpenGLStoredQtViewer::paintGL VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV %d ready %d\n",nbPaint,readyToPaint);
[608]271#endif
[564]272   WinSize_x = (G4int) width();
273   WinSize_y = (G4int) height();
274   
275   glViewport (0, 0, width(), height());
276   //   glLoadIdentity();
277   
278
279   SetView();
280
281//   //  printf("before ClearView\n");
[608]282#ifdef GEANT4_QT_DEBUG
[564]283   printf("    ClearView\n");
[608]284#endif
[564]285   
286   ClearView (); //ok, put the background correct
287   DrawView();
288
289   hasToRepaint =false;
290
[608]291#ifdef GEANT4_QT_DEBUG
[579]292   printf("G4OpenGLStoredQtViewer::paintGL ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ %d ready %d\n",nbPaint,readyToPaint);
[608]293#endif
[564]294 }
295
296void G4OpenGLStoredQtViewer::mousePressEvent(QMouseEvent *event)
297{
[608]298#ifdef GEANT4_QT_DEBUG
[564]299  printf("G4OpenGLStoredQtViewer::mousePressEvent\n");
[608]300#endif
[564]301  G4MousePressEvent(event->pos());
302}
303
304void G4OpenGLStoredQtViewer::mouseMoveEvent(QMouseEvent *event)
305{
[608]306#ifdef GEANT4_QT_DEBUG
[606]307  printf("G4OpenGLStoredQtViewer::mouseMoveEvent\n");
[608]308#endif
[606]309#if QT_VERSION < 0x040000
[601]310  G4MouseMoveEvent(event->x(),event->y(),event->button());
[606]311#else
312  G4MouseMoveEvent(event->x(),event->y(),event->buttons());
313#endif
[564]314  //  DrawView();
315}
316
317
318void G4OpenGLStoredQtViewer::contextMenuEvent(QContextMenuEvent *e)
319{
320  manageContextMenuEvent(e);
321}
322
323void G4OpenGLStoredQtViewer::updateQWidget() {
324  hasToRepaint= true;
325  updateGL();
326  hasToRepaint= false;
327}
328
[531]329#endif
Note: See TracBrowser for help on using the repository browser.