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

Last change on this file since 906 was 906, checked in by garnier, 15 years ago

for aspect radio. Ok for Qt, Xm, but not X. Debug mode

  • Property svn:mime-type set to text/cpp
File size: 8.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.21 2009/01/13 09:47:05 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
40//#include <qmouseevent.h>
41#include <qevent.h> // include <qcontextmenuevent.h>
42
43G4OpenGLStoredQtViewer::G4OpenGLStoredQtViewer
44(G4OpenGLStoredSceneHandler& sceneHandler,
45 const G4String&  name):
46  G4VViewer (sceneHandler, sceneHandler.IncrementViewCount (), name),
47  G4OpenGLViewer (sceneHandler),
48  G4OpenGLQtViewer (sceneHandler),
49  G4OpenGLStoredViewer (sceneHandler)             // FIXME : gerer le pb du parent !
50{
51
52  //set true to picking
53  fVP.SetPicking(true);
54#if QT_VERSION < 0x040000
55  setFocusPolicy(QWidget::StrongFocus); // enable keybord events
56#else
57  setFocusPolicy(Qt::StrongFocus); // enable keybord events
58#endif
59  hasToRepaint =false;
60
61  if (fViewId < 0) return;  // In case error in base class instantiation.
62}
63
64G4OpenGLStoredQtViewer::~G4OpenGLStoredQtViewer() {
65  makeCurrent();
66  // this is connect to the Dialog for deleting it properly
67  // when close event.
68  //   ((QDialog*)window())->reject();
69}
70
71void G4OpenGLStoredQtViewer::Initialise() {
72#ifdef G4DEBUG
73  printf("G4OpenGLStoredQtViewer::Initialise 1\n");
74#endif
75  readyToPaint = false;
76  CreateMainWindow (this,QString(fName));
77  CreateFontLists ();
78 
79  readyToPaint = true;
80}
81
82void G4OpenGLStoredQtViewer::initializeGL () {
83
84  InitializeGLView ();
85
86#ifdef G4DEBUG
87  printf("G4OpenGLStoredQtViewer::InitialiseGL () 1\n");
88#endif
89
90  // clear the buffers and window.
91  ClearView ();
92  FinishView ();
93   
94  glDepthFunc (GL_LEQUAL);
95  glDepthMask (GL_TRUE);
96
97  if (fSceneHandler.GetScene() == 0) {
98    hasToRepaint =false;
99  } else {
100    hasToRepaint =true;
101  }
102
103#ifdef G4DEBUG
104  printf("G4OpenGLStoredQtViewer::InitialiseGL  END\n");
105#endif
106}
107
108
109void G4OpenGLStoredQtViewer::DrawView () {
110#ifdef G4DEBUG
111  printf("G4OpenGLStoredQtViewer::DrawView  VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV\n");
112#endif
113  // That's no the same logic as Immediate Viewer, I don't know why...
114  // But if I send updateGL here, we go here :
115  //  updateQWidget -> paintGL -> ComputeView
116  // whih is not the same as ComputeView Directly
117  // And we loose the redraw of things !
118 
119  ComputeView();
120#ifdef G4DEBUG
121  printf("G4OpenGLStoredQtViewer::DrawView  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n");
122#endif
123}
124
125void G4OpenGLStoredQtViewer::ComputeView () {
126
127#ifdef G4DEBUG
128  printf("G4OpenGLStoredQtViewer::ComputeView %d %d   VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV\n",fWinSize_x, fWinSize_y);
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
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
167      printf("**************************  G4OpenGLStoredQtViewer::ComputeView Don't need kernel Visit \n");
168#endif
169      DrawDisplayLists ();
170      FinishView ();
171    } else {
172#ifdef G4DEBUG
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
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
197  printf("G4OpenGLStoredQtViewer::ComputeView %d %d ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \n",fWinSize_x, fWinSize_y);
198#endif
199  hasToRepaint =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  fWinSize_x = aWidth;
212  fWinSize_y = aHeight;
213  hasToRepaint = true;
214}
215
216
217void G4OpenGLStoredQtViewer::paintGL()
218{
219#ifdef G4DEBUG
220  printf("G4OpenGLStoredQtViewer::paintGL ??\n");
221#endif
222  if (!readyToPaint) {
223    readyToPaint= 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 ( !hasToRepaint) {
230    if (((fWinSize_x == (unsigned int)width())) &&(fWinSize_y == (unsigned int) height())) {
231      return;
232    }
233  }
234#ifdef G4DEBUG
235  printf("G4OpenGLStoredQtViewer::paintGL VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV ready %d\n",readyToPaint);
236#endif
237//   fWinSize_x = (unsigned int) width();
238//   fWinSize_y = (unsigned int) height();
239
240  //  setupViewport(width(),height());
241
242  SetView();
243         
244  ClearView (); //ok, put the background correct
245  ComputeView();
246     
247  hasToRepaint =false;
248     
249#ifdef G4DEBUG
250  printf("G4OpenGLStoredQtViewer::paintGL ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ready %d\n",readyToPaint);
251#endif
252}
253
254void G4OpenGLStoredQtViewer::mousePressEvent(QMouseEvent *event)
255{
256  G4MousePressEvent(event);
257}
258
259void G4OpenGLStoredQtViewer::keyPressEvent (QKeyEvent * event)
260{
261  G4keyPressEvent(event);
262}
263
264void G4OpenGLStoredQtViewer::wheelEvent (QWheelEvent * event)
265{
266  G4wheelEvent(event);
267}
268
269/**
270 * This function was build in order to make a zoom on double clic event.
271 * It was think to build a rubberband on the zoom area, but never work fine
272 */
273void G4OpenGLStoredQtViewer::mouseDoubleClickEvent(QMouseEvent *event)
274{
275  G4MouseDoubleClickEvent();
276}
277
278void G4OpenGLStoredQtViewer::mouseReleaseEvent(QMouseEvent *event)
279{
280  G4MouseReleaseEvent();
281}
282
283void G4OpenGLStoredQtViewer::mouseMoveEvent(QMouseEvent *event)
284{
285  G4MouseMoveEvent(event);
286}
287
288
289void G4OpenGLStoredQtViewer::contextMenuEvent(QContextMenuEvent *e)
290{
291  G4manageContextMenuEvent(e);
292}
293
294void G4OpenGLStoredQtViewer::updateQWidget() {
295  hasToRepaint= true;
296  updateGL();
297  hasToRepaint= false;
298}
299
300void G4OpenGLStoredQtViewer::ShowView (
301)
302//////////////////////////////////////////////////////////////////////////////
303//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
304{
305#if QT_VERSION < 0x040000
306  setActiveWindow();
307#else
308  activateWindow();
309#endif
310  updateQWidget();
311}
312
313#endif
Note: See TracBrowser for help on using the repository browser.