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

Last change on this file since 682 was 682, checked in by garnier, 18 years ago

modifs

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