source: trunk/geant4/visualization/OpenGL/src/G4OpenGLStoredQtViewer.cc @ 593

Last change on this file since 593 was 593, checked in by garnier, 17 years ago

r627@mac-90108: laurentgarnier | 2007-11-09 07:57:42 +0100
modif dans les includes directives

  • Property svn:mime-type set to text/cpp
File size: 8.7 KB
RevLine 
[531]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//
[593]27// $Id: G4OpenGLStoredQtViewer.cc,v 1.2 2007/11/08 17:00:51 lgarnier Exp $
28// GEANT4 tag $Name:  $
[531]29//
[564]30//
[533]31// Class G4OpenGLStoredQtViewer : a class derived from G4OpenGLQtViewer and
[564]32//                                G4OpenGLStoredViewer.
[531]33
[533]34#ifdef G4VIS_BUILD_OPENGLQT_DRIVER
[531]35
[533]36#include "G4OpenGLStoredQtViewer.hh"
[564]37#include "G4VisManager.hh"
[531]38
39#include "G4ios.hh"
40
[593]41#include <QtGui/QMouseEvent>
42#include <QtGui/QContextMenuEvent>
43
[533]44G4OpenGLStoredQtViewer::G4OpenGLStoredQtViewer
[531]45(G4OpenGLStoredSceneHandler& sceneHandler,
46 const G4String&  name):
[564]47 G4VViewer (sceneHandler, sceneHandler.IncrementViewCount (), name),
48 G4OpenGLViewer (sceneHandler),
49 G4OpenGLQtViewer (sceneHandler),
50 G4OpenGLStoredViewer (sceneHandler),
51 QGLWidget()                      // FIXME : gerer le pb du parent !
52 {
53   nbPaint =0;
54   hasToRepaint =false;
[531]55  if (fViewId < 0) return;  // In case error in base class instantiation.
56}
57
[564]58G4OpenGLStoredQtViewer::~G4OpenGLStoredQtViewer() {
59   printf("GLWidget::~GLWidget \n");
[579]60   makeCurrent();
61   // this is connect to the Dialog for deleting it properly
62   // when close event.
63   //   ((QDialog*)window())->reject();
[564]64   printf("GLWidget::~GLWidget END\n");
65}
[531]66
[564]67void G4OpenGLStoredQtViewer::Initialise() {
68   printf("GLWidget::Initialise \n");
69   readyToPaint = false;
70   CreateGLQtContext ();
71   printf("G4OpenGLStoredQtViewer::Initialise () 2\n");
[531]72
[564]73  CreateMainWindow (this);
74  printf("G4OpenGLStoredQtViewer::Initialise () 3\n");
[531]75
[564]76  CreateFontLists ();  // FIXME Does nothing!
77 
78  printf("readyToPaint = true \n");
79  readyToPaint = true;
80 
81  // First Draw
82  SetView();
83  printf("    ClearView\n");
84  ClearView (); //ok, put the background correct
85  ShowView();
86  FinishView();
87}
[531]88
[564]89void G4OpenGLStoredQtViewer::initializeGL () {
90
91   InitializeGLView ();
92
93   printf("G4OpenGLStoredQtViewer::InitialiseGL () 1\n");
94
95   // clear the buffers and window.
96   ClearView ();
97   //   printf("G4OpenGLStoredQtViewer::InitialiseGL () 2\n");
98   FinishView ();
99   
100   glDepthFunc (GL_LEQUAL);
101   glDepthMask (GL_TRUE);
102
103   hasToRepaint =true;
104
105   printf("G4OpenGLStoredQtViewer::InitialiseGL  -------------------------------------------------------------------------------------\n");
[531]106}
107
[564]108
[533]109void G4OpenGLStoredQtViewer::DrawView () {
[531]110
[564]111  printf("G4OpenGLStoredQtViewer::DrawView %d %d   VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV\n",WinSize_x, WinSize_y);
[579]112  printf("G4OpenGLStoredQtViewer::DrawView Dialog adress : %d\n",GLWindow);
[564]113   G4ViewParameters::DrawingStyle style = GetViewParameters().GetDrawingStyle();
[531]114
[564]115   //Make sure current viewer is attached and clean...
116   //Qt version needed
117   glViewport (0, 0, WinSize_x, WinSize_y);
[531]118
[564]119   //See if things have changed from last time and remake if necessary...
120   // The fNeedKernelVisit flag might have been set by the user in
121   // /vis/viewer/rebuild, but if not, make decision and set flag only
122   // if necessary...
[565]123   if (!fNeedKernelVisit)
124
[564]125   if (!fNeedKernelVisit) KernelVisitDecision ();
[565]126   
[564]127   G4bool kernelVisitWasNeeded = fNeedKernelVisit; // Keep (ProcessView resets).
128   ProcessView ();
129   
[531]130
[564]131   if(style!=G4ViewParameters::hlr &&
132      haloing_enabled) {
133     printf("G4OpenGLStoredQtViewer::DrawView DANS LE IF\n");
[531]134
[564]135     HaloingFirstPass ();
136     DrawDisplayLists ();
137     glFlush ();
[531]138
[564]139     HaloingSecondPass ();
[531]140
[564]141     DrawDisplayLists ();
[565]142     FinishView ();
[531]143
[564]144   } else {
[565]145     printf("***************************  CASE 1 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \n");
[564]146     
147     // If kernel visit was needed, drawing and FinishView will already
148     // have been done, so...
149     if (!kernelVisitWasNeeded) {
[565]150       printf("***************************  CASE 2 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \n");
[564]151       DrawDisplayLists ();
[565]152       FinishView ();
[564]153     } else {
[565]154       printf("***************************  CASE 3 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \n");
[564]155       // However, union cutaways are implemented in DrawDisplayLists, so make
156       // an extra pass...
157       if (fVP.IsCutaway() &&
158           fVP.GetCutawayMode() == G4ViewParameters::cutawayUnion) {
159         ClearView();
160         DrawDisplayLists ();
[565]161         FinishView ();
162         printf("***************************  CASE 4 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \n");
163       } else { // ADD TO AVOID KernelVisit=1 and nothing to display
164         DrawDisplayLists ();
165         FinishView ();
[564]166       }
167     }
168   }
169
[565]170   printf("G4OpenGLStoredQtViewer::DrawView %d %d ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \n",WinSize_x, WinSize_y);
[564]171   hasToRepaint =true;
[531]172}
173
[564]174
[531]175//////////////////////////////////////////////////////////////////////////////
[533]176void G4OpenGLStoredQtViewer::FinishView (
[531]177)
178//////////////////////////////////////////////////////////////////////////////
179//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
180{
[564]181  printf("G4OpenGLStoredQtViewer::FinishView VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV\n");
[531]182
183  glFlush ();
[564]184  swapBuffers ();
185  printf("G4OpenGLStoredQtViewer::FinishView ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \n");
186
[531]187}
188
[564]189
190/**
191 - Lors du resize de la fenetre, on doit non pas redessiner le detecteur, mais aussi les evenements
192 */
193void G4OpenGLStoredQtViewer::resizeGL(
194 int aWidth
195,int aHeight)
196
197  glViewport(0, 0, aWidth, aHeight);
198  glMatrixMode(GL_PROJECTION);
199  glMatrixMode(GL_MODELVIEW);
200
201   if (((WinSize_x != (G4int)aWidth)) || (WinSize_y != (G4int) aHeight)) {
202     hasToRepaint =true;
203   }
204   WinSize_x = (G4int) aWidth;
205   WinSize_y = (G4int) aHeight;
206
207  printf("G4OpenGLStoredQtViewer::resizeGL ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ %d %d=%d %d=%d\n",hasToRepaint,width(),aWidth,height(),aHeight);
208}
209
210
211
212void G4OpenGLStoredQtViewer::paintGL()
213 {
214   if (!readyToPaint) {
[579]215     printf("G4OpenGLStoredQtViewer::paintGL ============  Not ready %d\n",readyToPaint);
[564]216     readyToPaint= true;
217     return;
218   }
219   // DO NOT RESIZE IF SIZE HAS NOT CHANGE :
220   //    WHEN CLICK ON THE FRAME FOR EXAMPLE
221   //    EXECEPT WHEN MOUSE MOVE EVENT
222   if ( !hasToRepaint) {
223     if (((WinSize_x == (G4int)width())) &&(WinSize_y == (G4int) height())) {
[579]224       printf("G4OpenGLStoredQtViewer::paintGL ============  Dont repaint\n");
[564]225       return;
226     }
227   }
228   nbPaint++;
[579]229   printf("G4OpenGLStoredQtViewer::paintGL VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV %d ready %d\n",nbPaint,readyToPaint);
[564]230   WinSize_x = (G4int) width();
231   WinSize_y = (G4int) height();
232   
233   glViewport (0, 0, width(), height());
234   //   glLoadIdentity();
235   
236
237   SetView();
238
239//   //  printf("before ClearView\n");
240   printf("    ClearView\n");
241   
242   ClearView (); //ok, put the background correct
243   DrawView();
244
245   hasToRepaint =false;
246
[579]247   printf("G4OpenGLStoredQtViewer::paintGL ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ %d ready %d\n",nbPaint,readyToPaint);
[564]248 }
249
250void G4OpenGLStoredQtViewer::mousePressEvent(QMouseEvent *event)
251{
252  printf("G4OpenGLStoredQtViewer::mousePressEvent\n");
253  G4MousePressEvent(event->pos());
254}
255
256void G4OpenGLStoredQtViewer::mouseMoveEvent(QMouseEvent *event)
257{
258  G4MouseMoveEvent(event->x(),event->y(),event->buttons());
259  //  DrawView();
260}
261
262
263void G4OpenGLStoredQtViewer::contextMenuEvent(QContextMenuEvent *e)
264{
265  manageContextMenuEvent(e);
266}
267
268void G4OpenGLStoredQtViewer::updateQWidget() {
269  hasToRepaint= true;
270  updateGL();
271  hasToRepaint= false;
272}
273
[531]274#endif
Note: See TracBrowser for help on using the repository browser.