source: trunk/source/visualization/OpenGL/src/G4OpenGLStoredQtViewer.cc @ 846

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

last updates

  • 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.15 2008/06/20 13:55:06 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  printf("G4OpenGLStoredQtViewer::DrawView %d %d   VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV\n",WinSize_x, WinSize_y);
126#endif
127  G4ViewParameters::DrawingStyle style = GetViewParameters().GetDrawingStyle();
128
129  //Make sure current viewer is attached and clean...
130  //Qt version needed
131  //   glViewport (0, 0, WinSize_x, WinSize_y);
132
133  //See if things have changed from last time and remake if necessary...
134  // The fNeedKernelVisit flag might have been set by the user in
135  // /vis/viewer/rebuild, but if not, make decision and set flag only
136  // if necessary...
137  if (!fNeedKernelVisit)
138
139    if (!fNeedKernelVisit) KernelVisitDecision ();
140   
141  G4bool kernelVisitWasNeeded = fNeedKernelVisit; // Keep (ProcessView resets).
142  ProcessView ();
143   
144
145  if(style!=G4ViewParameters::hlr &&
146     haloing_enabled) {
147#ifdef GEANT4_QT_DEBUG
148    printf("G4OpenGLStoredQtViewer::DrawView DANS LE IF\n");
149#endif
150
151    HaloingFirstPass ();
152    DrawDisplayLists ();
153    glFlush ();
154
155    HaloingSecondPass ();
156
157    DrawDisplayLists ();
158    FinishView ();
159
160  } else {
161     
162    // If kernel visit was needed, drawing and FinishView will already
163    // have been done, so...
164    if (!kernelVisitWasNeeded) {
165#ifdef GEANT4_QT_DEBUG
166      printf("**************************  G4OpenGLStoredQtViewer::DrawView Don't need kernel Visit \n");
167#endif
168      DrawDisplayLists ();
169      FinishView ();
170    } else {
171#ifdef GEANT4_QT_DEBUG
172      printf("**************************  G4OpenGLStoredQtViewer::DrawView need kernel Visit \n");
173#endif
174      // However, union cutaways are implemented in DrawDisplayLists, so make
175      // an extra pass...
176      if (fVP.IsCutaway() &&
177          fVP.GetCutawayMode() == G4ViewParameters::cutawayUnion) {
178        ClearView();
179        DrawDisplayLists ();
180        FinishView ();
181#ifdef GEANT4_QT_DEBUG
182        printf("***************************  CASE 4 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \n");
183#endif
184      } else { // ADD TO AVOID KernelVisit=1 and nothing to display
185        DrawDisplayLists ();
186        FinishView ();
187      }
188    }
189  }
190
191  if (isRecording()) {
192    savePPMToTemp();
193  }
194
195#ifdef GEANT4_QT_DEBUG
196  printf("G4OpenGLStoredQtViewer::DrawView %d %d ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \n",WinSize_x, WinSize_y);
197#endif
198  hasToRepaint =true;
199}
200
201
202//////////////////////////////////////////////////////////////////////////////
203void G4OpenGLStoredQtViewer::FinishView (
204)
205//////////////////////////////////////////////////////////////////////////////
206//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
207{
208  glFlush ();
209  swapBuffers ();
210}
211
212
213/**
214   - Lors du resize de la fenetre, on doit non pas redessiner le detecteur, mais aussi les evenements
215*/
216void G4OpenGLStoredQtViewer::resizeGL(
217                                      int aWidth
218                                      ,int aHeight)
219
220  setupViewport(aWidth,aHeight);
221
222  if (((WinSize_x != (G4int)aWidth)) || (WinSize_y != (G4int) aHeight)) {
223    hasToRepaint =true;
224  }
225  WinSize_x = (G4int) aWidth;
226  WinSize_y = (G4int) aHeight;
227 
228#ifdef GEANT4_QT_DEBUG
229  printf("G4OpenGLStoredQtViewer::resizeGL ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ %d %d=%d %d=%d\n",hasToRepaint,width(),aWidth,height(),aHeight);
230#endif
231}
232
233
234/**
235    @see :
236*/
237
238void G4OpenGLStoredQtViewer::paintGL()
239{
240  if (!readyToPaint) {
241#ifdef GEANT4_QT_DEBUG
242    printf("G4OpenGLStoredQtViewer::paintGL ============  Not ready %d\n",readyToPaint);
243#endif
244    readyToPaint= true;
245    return;
246  }
247  // DO NOT RESIZE IF SIZE HAS NOT CHANGE :
248  //    WHEN CLICK ON THE FRAME FOR EXAMPLE
249  //    EXECEPT WHEN MOUSE MOVE EVENT
250  if ( !hasToRepaint) {
251    if (((WinSize_x == (G4int)width())) &&(WinSize_y == (G4int) height())) {
252#ifdef GEANT4_QT_DEBUG
253      printf("G4OpenGLStoredQtViewer::paintGL ============  Dont repaint\n");
254#endif
255      return;
256    }
257  }
258  nbPaint++;
259#ifdef GEANT4_QT_DEBUG
260  printf("G4OpenGLStoredQtViewer::paintGL VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV %d ready %d\n",nbPaint,readyToPaint);
261#endif
262  WinSize_x = (G4int) width();
263  WinSize_y = (G4int) height();
264     
265  setupViewport(width(),height());
266  //     glViewport (0, 0, width(), height());
267  //   glLoadIdentity();
268     
269     
270  SetView();
271     
272  //   //  printf("before ClearView\n");
273#ifdef GEANT4_QT_DEBUG
274  printf("    ClearView\n");
275#endif
276     
277  ClearView (); //ok, put the background correct
278  DrawView();
279     
280  hasToRepaint =false;
281     
282#ifdef GEANT4_QT_DEBUG
283  printf("G4OpenGLStoredQtViewer::paintGL ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ %d ready %d\n",nbPaint,readyToPaint);
284#endif
285}
286
287void G4OpenGLStoredQtViewer::mousePressEvent(QMouseEvent *event)
288{
289#if QT_VERSION < 0x040000
290  if ((event->button() & Qt::LeftButton)
291      && !((event->state() & Qt::ShiftButton)
292           || (event->state() & Qt::ControlButton)
293           || (event->state() & Qt::AltButton)
294           || (event->state() & Qt::MetaButton))) {
295#else
296  if ((event->buttons() & Qt::LeftButton)
297      && !((event->modifiers() & Qt::ShiftModifier)
298           || (event->modifiers() & Qt::ControlModifier)
299           || (event->modifiers() & Qt::AltModifier)
300           || (event->modifiers() & Qt::MetaModifier))) {
301#endif
302#ifdef GEANT4_QT_DEBUG
303    printf("G4OpenGLStoredQtViewer::mousePressEvent\n");
304#endif
305    setMouseTracking(true);
306    G4MousePressEvent(event->pos());
307  }
308}
309
310void G4OpenGLStoredQtViewer::keyPressEvent (QKeyEvent * event)
311{
312  G4keyPressEvent(event);
313}
314
315void G4OpenGLStoredQtViewer::wheelEvent (QWheelEvent * event)
316{
317  G4wheelEvent(event);
318}
319
320/**
321 * This function was build in order to make a zoom on double clic event.
322 * It was think to build a rubberband on the zoom area, but never work fine
323 */
324void G4OpenGLStoredQtViewer::mouseDoubleClickEvent(QMouseEvent *event)
325{
326#ifdef GEANT4_QT_DEBUG
327  printf("G4OpenGLStoredQtViewer::mouseDoubleClickEvent\n");
328#endif
329  setMouseTracking(true);
330  //   glBufferImage = grabFrameBuffer().convertToFormat(QImage::Format_ARGB32);//_Premultiplied); 
331}
332
333void G4OpenGLStoredQtViewer::mouseReleaseEvent(QMouseEvent *event)
334{
335  G4MouseReleaseEvent();
336#ifdef GEANT4_QT_DEBUG
337  printf("G4OpenGLStoredQtViewer::mouseReleaseEvent ================\n");
338#endif
339  setMouseTracking(false);
340}
341
342void G4OpenGLStoredQtViewer::mouseMoveEvent(QMouseEvent *event)
343{
344 
345#if QT_VERSION < 0x040000
346  G4MouseMoveEvent(event->x(),event->y(),event->state());
347#else
348  G4MouseMoveEvent(event->x(),event->y(),event->buttons());
349#endif
350}
351
352
353void G4OpenGLStoredQtViewer::contextMenuEvent(QContextMenuEvent *e)
354{
355#ifdef GEANT4_QT_DEBUG
356  printf("G4OpenGLStoredQtViewer::contextMenuEvent\n");
357#endif
358  manageContextMenuEvent(e);
359}
360
361void G4OpenGLStoredQtViewer::updateQWidget() {
362  hasToRepaint= true;
363  updateGL();
364  hasToRepaint= false;
365}
366
367
368#endif
Note: See TracBrowser for help on using the repository browser.