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

Last change on this file since 804 was 804, checked in by garnier, 16 years ago

r846@wl-72126: garnier | 2008-05-29 12:20:22 +0200
prise en compte de la roulette de souris

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