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

Last change on this file since 1339 was 1332, checked in by garnier, 14 years ago

changement des shorcuts

  • Property svn:mime-type set to text/cpp
File size: 9.8 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.32 2010/06/23 13:29:23 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#include "G4OpenGLStoredQtViewer.hh"
37
38#include "G4ios.hh"
39
40G4OpenGLStoredQtViewer::G4OpenGLStoredQtViewer
41(G4OpenGLStoredSceneHandler& sceneHandler,
42 const G4String&  name):
43  G4VViewer (sceneHandler, sceneHandler.IncrementViewCount (), name),
44  G4OpenGLViewer (sceneHandler),
45  G4OpenGLQtViewer (sceneHandler),
46  G4OpenGLStoredViewer (sceneHandler),             // FIXME : gerer le pb du parent !
47  QGLWidget()
48{
49
50#ifdef G4DEBUG_VIS_OGL
51  printf("G4OpenGLStoredQtViewer::constructor VVVVVVVVVVVV\n");
52#endif
53#if QT_VERSION < 0x040000
54  setFocusPolicy(QWidget::StrongFocus); // enable keybord events
55#else
56  setFocusPolicy(Qt::StrongFocus); // enable keybord events
57#endif
58  fHasToRepaint = false;
59  fIsRepainting = false;
60
61#ifdef G4DEBUG_VIS_OGL
62  printf("G4OpenGLStoredQtViewer::constructor ^^^^^^^^^^^^\n");
63#endif
64  if (fViewId < 0) return;  // In case error in base class instantiation.
65}
66
67G4OpenGLStoredQtViewer::~G4OpenGLStoredQtViewer() {
68  makeCurrent();
69  // this is connect to the Dialog for deleting it properly
70  // when close event.
71  //   ((QDialog*)window())->reject();
72}
73
74void G4OpenGLStoredQtViewer::Initialise() {
75#ifdef G4DEBUG_VIS_OGL
76  printf("G4OpenGLStoredQtViewer::Initialise VVVVVVVVVVVV\n");
77#endif
78  fReadyToPaint = false;
79  CreateMainWindow (this,QString(GetName()));
80  CreateFontLists ();
81 
82  fReadyToPaint = true;
83#ifdef G4DEBUG_VIS_OGL
84  printf("G4OpenGLStoredQtViewer::Initialise ^^^^^^^^^^^^\n");
85#endif
86}
87
88void G4OpenGLStoredQtViewer::initializeGL () {
89
90#ifdef G4DEBUG_VIS_OGL
91  printf("G4OpenGLStoredQtViewer::InitialiseGL () 0\n");
92#endif
93  //  return;
94  InitializeGLView ();
95
96#ifdef G4DEBUG_VIS_OGL
97  printf("G4OpenGLStoredQtViewer::InitialiseGL () 1\n");
98#endif
99
100  // clear the buffers and window.
101  ClearView ();
102  FinishView ();
103   
104  glDepthFunc (GL_LEQUAL);
105  glDepthMask (GL_TRUE);
106
107  if (fSceneHandler.GetScene() == 0) {
108    fHasToRepaint =false;
109  } else {
110    fHasToRepaint =true;
111  }
112
113#ifdef G4DEBUG_VIS_OGL
114  printf("G4OpenGLStoredQtViewer::InitialiseGL  END\n");
115#endif
116}
117
118
119void G4OpenGLStoredQtViewer::DrawView () { 
120  updateQWidget();
121}
122
123void G4OpenGLStoredQtViewer::ComputeView () {
124
125#ifdef G4DEBUG_VIS_OGL
126  printf("G4OpenGLStoredQtViewer::ComputeView %d %d   VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV\n",getWinWidth(), getWinHeight());
127#endif
128  makeCurrent();
129  G4ViewParameters::DrawingStyle style = GetViewParameters().GetDrawingStyle();
130
131  //Make sure current viewer is attached and clean...
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    KernelVisitDecision ();
139  }
140  G4bool kernelVisitWasNeeded = fNeedKernelVisit; // Keep (ProcessView resets).
141  ProcessView ();
142   
143
144  if(style!=G4ViewParameters::hlr &&
145     haloing_enabled) {
146#ifdef G4DEBUG_VIS_OGL
147    printf("G4OpenGLStoredQtViewer::ComputeView DANS LE IF\n");
148#endif
149
150    HaloingFirstPass ();
151    DrawDisplayLists ();
152    glFlush ();
153
154    HaloingSecondPass ();
155
156    DrawDisplayLists ();
157    FinishView ();
158
159  } else {
160     
161    // If kernel visit was needed, drawing and FinishView will already
162    // have been done, so...
163    if (!kernelVisitWasNeeded) {
164#ifdef G4DEBUG_VIS_OGL
165      printf("**************************  G4OpenGLStoredQtViewer::ComputeView Don't need kernel Visit \n");
166#endif
167      DrawDisplayLists ();
168      FinishView ();
169    } else {
170#ifdef G4DEBUG_VIS_OGL
171      printf("**************************  G4OpenGLStoredQtViewer::ComputeView need kernel Visit \n");
172#endif
173      // However, union cutaways are implemented in DrawDisplayLists, so make
174      // an extra pass...
175      if (fVP.IsCutaway() &&
176          fVP.GetCutawayMode() == G4ViewParameters::cutawayUnion) {
177        ClearView();
178        DrawDisplayLists ();
179        FinishView ();
180#ifdef G4DEBUG_VIS_OGL
181        printf("***************************  CASE 4 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \n");
182#endif
183      } else { // ADD TO AVOID KernelVisit=1 and nothing to display
184        DrawDisplayLists ();
185        FinishView ();
186      }
187    }
188  }
189
190  if (isRecording()) {
191    savePPMToTemp();
192  }
193
194#ifdef G4DEBUG_VIS_OGL
195  printf("G4OpenGLStoredQtViewer::ComputeView %d %d ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \n",getWinWidth(), getWinHeight());
196#endif
197  fHasToRepaint = true;
198}
199
200
201/**
202   - Lors du resize de la fenetre, on doit non pas redessiner le detecteur, mais aussi les evenements
203*/
204void G4OpenGLStoredQtViewer::resizeGL(
205                                      int aWidth
206                                      ,int aHeight)
207
208  // Set new size, it will be update when next Repaint()->SetView() called
209  if ((aWidth > 0) && (aHeight > 0)) {
210    ResizeWindow(aWidth,aHeight);
211    fHasToRepaint = sizeHasChanged();
212  }
213}
214
215
216// We have to get several case :
217// - Only activate the windows (mouse click for example) -> Do not redraw
218// - resize window -> redraw
219// - try to avoid recompute everything if we do not rescale picture (side is the same)
220 
221void G4OpenGLStoredQtViewer::paintGL()
222{
223#ifdef G4DEBUG_VIS_OGL
224  printf("G4OpenGLStoredQtViewer::paintGL \n");
225#endif
226  if (fIsRepainting) {
227    //    return ;
228  }
229  fIsRepainting = true;
230#ifdef G4DEBUG_VIS_OGL
231  printf("G4OpenGLStoredQtViewer::paintGL ready:%d fHasTo:%d??\n",fReadyToPaint,fHasToRepaint);
232#endif
233  if (!fReadyToPaint) {
234    fReadyToPaint= true;
235    return;
236  }
237  // DO NOT RESIZE IF SIZE HAS NOT CHANGE :
238  //    WHEN CLICK ON THE FRAME FOR EXAMPLE
239  //    EXECEPT WHEN MOUSE MOVE EVENT
240  if ( !fHasToRepaint) {
241#if QT_VERSION < 0x040000
242    if (((getWinWidth() == (unsigned int)width())) &&(getWinHeight() == (unsigned int) height())) {
243#else
244    // L. Garnier : Trap to get the size with mac OSX 10.6 and Qt 4.6(devel)
245    // Tested on Qt4.5 on mac, 4.4 on windows, 4.5 on unbuntu
246    int sw = 0;
247    int sh = 0;
248    if (!isMaximized() && !isFullScreen()) {
249      sw = normalGeometry().width();
250      sh = normalGeometry().height();
251    } else {
252      sw = frameGeometry().width();
253      sh = frameGeometry().height();
254    }
255    if ((getWinWidth() == (unsigned int)sw) &&(getWinHeight() == (unsigned int)sh)) {
256#endif
257      return;
258    }
259  }
260#ifdef G4DEBUG_VIS_OGL
261  printf("G4OpenGLStoredQtViewer::paintGL VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV ready %d\n",fReadyToPaint);
262#endif
263
264  SetView();
265
266  ClearView (); //ok, put the background correct
267  ComputeView();
268
269  fHasToRepaint = false;
270
271#ifdef G4DEBUG_VIS_OGL
272  printf("G4OpenGLStoredQtViewer::paintGL ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ready %d\n",fReadyToPaint);
273#endif
274  fIsRepainting = false;
275}
276
277void G4OpenGLStoredQtViewer::paintEvent(QPaintEvent *) {
278  if ( fHasToRepaint) {
279    updateGL();
280  }
281}
282
283void G4OpenGLStoredQtViewer::mousePressEvent(QMouseEvent *event)
284{
285  G4MousePressEvent(event);
286}
287
288void G4OpenGLStoredQtViewer::keyPressEvent (QKeyEvent * event)
289{
290  G4keyPressEvent(event);
291}
292
293void G4OpenGLStoredQtViewer::wheelEvent (QWheelEvent * event)
294{
295  G4wheelEvent(event);
296}
297
298void G4OpenGLStoredQtViewer::showEvent (QShowEvent *)
299{
300  fHasToRepaint = true;
301}
302
303/**
304 * This function was build in order to make a zoom on double clic event.
305 * It was think to build a rubberband on the zoom area, but never work fine
306 */
307void G4OpenGLStoredQtViewer::mouseDoubleClickEvent(QMouseEvent *)
308{
309  G4MouseDoubleClickEvent();
310}
311
312void G4OpenGLStoredQtViewer::mouseReleaseEvent(QMouseEvent *)
313{
314  G4MouseReleaseEvent();
315}
316
317void G4OpenGLStoredQtViewer::mouseMoveEvent(QMouseEvent *event)
318{
319  G4MouseMoveEvent(event);
320}
321
322
323void G4OpenGLStoredQtViewer::contextMenuEvent(QContextMenuEvent *e)
324{
325  G4manageContextMenuEvent(e);
326}
327
328void G4OpenGLStoredQtViewer::updateQWidget() {
329  fHasToRepaint= true;
330  updateGL();
331  fHasToRepaint= false;
332}
333
334void G4OpenGLStoredQtViewer::ShowView (
335)
336//////////////////////////////////////////////////////////////////////////////
337//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
338{
339#if QT_VERSION < 0x040000
340  setActiveWindow();
341#else
342  activateWindow();
343#endif
344}
345
346#endif
Note: See TracBrowser for help on using the repository browser.