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

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

debud de la video

  • Property svn:mime-type set to text/cpp
File size: 11.3 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.9 2008/01/30 10:54:13 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  // First Draw
97  SetView();
98#ifdef GEANT4_QT_DEBUG
99  printf("    ClearView\n");
100#endif
101  ClearView (); //ok, put the background correct
102  FinishView();
103}
104
105void G4OpenGLStoredQtViewer::initializeGL () {
106
107  InitializeGLView ();
108
109#ifdef GEANT4_QT_DEBUG
110  printf("G4OpenGLStoredQtViewer::InitialiseGL () 1\n");
111#endif
112
113  // clear the buffers and window.
114  ClearView ();
115  //   printf("G4OpenGLStoredQtViewer::InitialiseGL () 2\n");
116  FinishView ();
117   
118  glDepthFunc (GL_LEQUAL);
119  glDepthMask (GL_TRUE);
120
121  hasToRepaint =true;
122
123#ifdef GEANT4_QT_DEBUG
124  printf("G4OpenGLStoredQtViewer::InitialiseGL  -------------------------------------------------------------------------------------\n");
125#endif
126}
127
128
129void G4OpenGLStoredQtViewer::DrawView () {
130
131#ifdef GEANT4_QT_DEBUG
132  printf("G4OpenGLStoredQtViewer::DrawView %d %d   VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV\n",WinSize_x, WinSize_y);
133#endif
134  G4ViewParameters::DrawingStyle style = GetViewParameters().GetDrawingStyle();
135
136  //Make sure current viewer is attached and clean...
137  //Qt version needed
138  //   glViewport (0, 0, WinSize_x, WinSize_y);
139
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...
144  if (!fNeedKernelVisit)
145
146    if (!fNeedKernelVisit) KernelVisitDecision ();
147   
148  G4bool kernelVisitWasNeeded = fNeedKernelVisit; // Keep (ProcessView resets).
149  ProcessView ();
150   
151
152  if(style!=G4ViewParameters::hlr &&
153     haloing_enabled) {
154#ifdef GEANT4_QT_DEBUG
155    printf("G4OpenGLStoredQtViewer::DrawView DANS LE IF\n");
156#endif
157
158    HaloingFirstPass ();
159    DrawDisplayLists ();
160    glFlush ();
161
162    HaloingSecondPass ();
163
164    DrawDisplayLists ();
165    FinishView ();
166
167  } else {
168#ifdef GEANT4_QT_DEBUG
169    printf("***************************  CASE 1 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \n");
170#endif
171     
172    // If kernel visit was needed, drawing and FinishView will already
173    // have been done, so...
174    if (!kernelVisitWasNeeded) {
175#ifdef GEANT4_QT_DEBUG
176      printf("***************************  CASE 2 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \n");
177#endif
178      DrawDisplayLists ();
179      FinishView ();
180    } else {
181#ifdef GEANT4_QT_DEBUG
182      printf("***************************  CASE 3 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \n");
183#endif
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 ();
190        FinishView ();
191#ifdef GEANT4_QT_DEBUG
192        printf("***************************  CASE 4 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \n");
193#endif
194      } else { // ADD TO AVOID KernelVisit=1 and nothing to display
195        DrawDisplayLists ();
196        FinishView ();
197      }
198    }
199  }
200
201#ifdef GEANT4_QT_DEBUG
202  printf("G4OpenGLStoredQtViewer::DrawView %d %d ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \n",WinSize_x, WinSize_y);
203#endif
204  hasToRepaint =true;
205}
206
207
208//////////////////////////////////////////////////////////////////////////////
209void G4OpenGLStoredQtViewer::FinishView (
210)
211//////////////////////////////////////////////////////////////////////////////
212//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
213{
214#ifdef GEANT4_QT_DEBUG
215  printf("G4OpenGLStoredQtViewer::FinishView VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV\n");
216#endif
217
218  glFlush ();
219  swapBuffers ();
220#ifdef GEANT4_QT_DEBUG
221  printf("G4OpenGLStoredQtViewer::FinishView ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \n");
222#endif
223
224}
225
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
234  setupViewport(aWidth,aHeight);
235
236  if (((WinSize_x != (G4int)aWidth)) || (WinSize_y != (G4int) aHeight)) {
237    hasToRepaint =true;
238  }
239  WinSize_x = (G4int) aWidth;
240  WinSize_y = (G4int) aHeight;
241 
242#ifdef GEANT4_QT_DEBUG
243  printf("G4OpenGLStoredQtViewer::resizeGL ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ %d %d=%d %d=%d\n",hasToRepaint,width(),aWidth,height(),aHeight);
244#endif
245}
246
247
248/**
249    @see :
250*/
251
252void G4OpenGLStoredQtViewer::paintGL()
253{
254  if (!readyToPaint) {
255#ifdef GEANT4_QT_DEBUG
256    printf("G4OpenGLStoredQtViewer::paintGL ============  Not ready %d\n",readyToPaint);
257#endif
258    readyToPaint= true;
259    return;
260  }
261  // DO NOT RESIZE IF SIZE HAS NOT CHANGE :
262  //    WHEN CLICK ON THE FRAME FOR EXAMPLE
263  //    EXECEPT WHEN MOUSE MOVE EVENT
264  if ( !hasToRepaint) {
265    if (((WinSize_x == (G4int)width())) &&(WinSize_y == (G4int) height())) {
266#ifdef GEANT4_QT_DEBUG
267      printf("G4OpenGLStoredQtViewer::paintGL ============  Dont repaint\n");
268#endif
269      return;
270    }
271  }
272  nbPaint++;
273#ifdef GEANT4_QT_DEBUG
274  printf("G4OpenGLStoredQtViewer::paintGL VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV %d ready %d\n",nbPaint,readyToPaint);
275#endif
276  WinSize_x = (G4int) width();
277  WinSize_y = (G4int) height();
278     
279  setupViewport(width(),height());
280  //     glViewport (0, 0, width(), height());
281  //   glLoadIdentity();
282     
283     
284  SetView();
285     
286  //   //  printf("before ClearView\n");
287#ifdef GEANT4_QT_DEBUG
288  printf("    ClearView\n");
289#endif
290     
291  ClearView (); //ok, put the background correct
292  DrawView();
293     
294  if (fRecordFrames) {
295    saveForVideo(QString("/temp/Test")+QString::number(fRecordFrameNumber));
296    fRecordFrameNumber++;
297#ifdef GEANT4_QT_DEBUG
298    printf("G4OpenGLStoredQtViewer::record frame %d\n",fRecordFrameNumber);
299#endif
300  }
301  hasToRepaint =false;
302     
303#ifdef GEANT4_QT_DEBUG
304  printf("G4OpenGLStoredQtViewer::paintGL ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ %d ready %d\n",nbPaint,readyToPaint);
305#endif
306}
307
308void G4OpenGLStoredQtViewer::mousePressEvent(QMouseEvent *event)
309{
310#if QT_VERSION < 0x040000
311  if ((event->button() & Qt::LeftButton)
312      && !((event->state() & Qt::ShiftButton)
313           || (event->state() & Qt::ControlButton)
314           || (event->state() & Qt::AltButton)
315           || (event->state() & Qt::MetaButton))) {
316#else
317  if ((event->buttons() & Qt::LeftButton)
318      && !((event->modifiers() & Qt::ShiftModifier)
319           || (event->modifiers() & Qt::ControlModifier)
320           || (event->modifiers() & Qt::AltModifier)
321           || (event->modifiers() & Qt::MetaModifier))) {
322#endif
323#ifdef GEANT4_QT_DEBUG
324    printf("G4OpenGLStoredQtViewer::mousePressEvent\n");
325#endif
326    setMouseTracking(true);
327    G4MousePressEvent(event->pos(),Qt::LeftButton);
328  }
329}
330
331void G4OpenGLStoredQtViewer::keyPressEvent (QKeyEvent * event)
332{
333  G4keyPressEvent(event);
334}
335
336/**
337 * This function was build in order to make a zoom on double clic event.
338 * It was think to build a rubberband on the zoom area, but never work fine
339 */
340void G4OpenGLStoredQtViewer::mouseDoubleClickEvent(QMouseEvent *event)
341{
342#ifdef GEANT4_QT_DEBUG
343  printf("G4OpenGLStoredQtViewer::mouseDoubleClickEvent\n");
344#endif
345  setMouseTracking(true);
346  //   glBufferImage = grabFrameBuffer().convertToFormat(QImage::Format_ARGB32);//_Premultiplied); 
347}
348
349void G4OpenGLStoredQtViewer::mouseReleaseEvent(QMouseEvent *event)
350{
351#ifdef GEANT4_QT_DEBUG
352  printf("G4OpenGLStoredQtViewer::mouseReleaseEvent\n");
353#endif
354  setMouseTracking(false);
355}
356
357void G4OpenGLStoredQtViewer::mouseMoveEvent(QMouseEvent *event)
358{
359 
360#if QT_VERSION < 0x040000
361  G4MouseMoveEvent(event->x(),event->y(),event->state());
362#else
363  G4MouseMoveEvent(event->x(),event->y(),event->buttons());
364#endif
365#ifdef GEANT4_QT_DEBUG
366  if (hasPendingEvents ())
367    G4MouseMoveEvent(event->x(),event->y(),event->buttons(),true);
368#endif
369}
370
371
372void G4OpenGLStoredQtViewer::contextMenuEvent(QContextMenuEvent *e)
373{
374#ifdef GEANT4_QT_DEBUG
375  printf("G4OpenGLStoredQtViewer::contextMenuEvent\n");
376#endif
377  manageContextMenuEvent(e);
378}
379
380void G4OpenGLStoredQtViewer::updateQWidget() {
381  hasToRepaint= true;
382  updateGL();
383  hasToRepaint= false;
384}
385
386
387#endif
Note: See TracBrowser for help on using the repository browser.