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

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

avant maj de CVS

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