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

Last change on this file since 586 was 579, checked in by garnier, 18 years ago

r599@mac-90108: laurentgarnier | 2007-09-18 18:43:19 +0200
correction du ticket #72 et la suppresion de la fenetre OpenGL entraine desormais un message d erreur lors du prochain BeamOn

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