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

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

bug fix ?

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