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

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

r569@mac-90108: laurentgarnier | 2007-08-14 15:07:23 +0200
commenatires et suppression de double rotation

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