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

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

modifs de test pour rubberband et mise en place du button mouse zoom

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