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

Last change on this file since 624 was 621, checked in by garnier, 18 years ago

correction du ticket #89

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