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

Last change on this file since 701 was 696, checked in by garnier, 18 years ago

avancement sur la zone de recherche

  • Property svn:mime-type set to text/cpp
File size: 10.6 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.8 2008/01/15 11:05:08 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(QGLFormat(QGL::SampleBuffers)) // FIXME : gerer le pb du parent !
53{
54 setFocusPolicy(Qt::StrongFocus); // enable keybord events
55 nbPaint =0;
56 hasToRepaint =false;
57 if (fViewId < 0) return; // In case error in base class instantiation.
58}
59
60G4OpenGLStoredQtViewer::~G4OpenGLStoredQtViewer() {
61#ifdef GEANT4_QT_DEBUG
62 printf("GLWidget::~GLWidget \n");
63#endif
64 makeCurrent();
65 // this is connect to the Dialog for deleting it properly
66 // when close event.
67 // ((QDialog*)window())->reject();
68#ifdef GEANT4_QT_DEBUG
69 printf("GLWidget::~GLWidget END\n");
70#endif
71}
72
73void G4OpenGLStoredQtViewer::Initialise() {
74#ifdef GEANT4_QT_DEBUG
75 printf("GLWidget::Initialise \n");
76#endif
77 readyToPaint = false;
78 CreateGLQtContext ();
79#ifdef GEANT4_QT_DEBUG
80 printf("G4OpenGLStoredQtViewer::Initialise () 2\n");
81#endif
82 CreateMainWindow (this);
83#ifdef GEANT4_QT_DEBUG
84 printf("G4OpenGLStoredQtViewer::Initialise () 3\n");
85#endif
86 CreateFontLists (); // FIXME Does nothing!
87
88#ifdef GEANT4_QT_DEBUG
89 printf("readyToPaint = true \n");
90#endif
91 readyToPaint = true;
92
93 // First Draw
94 SetView();
95#ifdef GEANT4_QT_DEBUG
96 printf(" ClearView\n");
97#endif
98 ClearView (); //ok, put the background correct
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 setupViewport(aWidth,aHeight);
232
233 if (((WinSize_x != (G4int)aWidth)) || (WinSize_y != (G4int) aHeight)) {
234 hasToRepaint =true;
235 }
236 WinSize_x = (G4int) aWidth;
237 WinSize_y = (G4int) aHeight;
238
239#ifdef GEANT4_QT_DEBUG
240 printf("G4OpenGLStoredQtViewer::resizeGL ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ %d %d=%d %d=%d\n",hasToRepaint,width(),aWidth,height(),aHeight);
241#endif
242}
243
244
245/**
246 @see :
247*/
248
249void G4OpenGLStoredQtViewer::paintGL()
250{
251
252 if (!readyToPaint) {
253#ifdef GEANT4_QT_DEBUG
254 printf("G4OpenGLStoredQtViewer::paintGL ============ Not ready %d\n",readyToPaint);
255#endif
256 readyToPaint= true;
257 return;
258 }
259 // DO NOT RESIZE IF SIZE HAS NOT CHANGE :
260 // WHEN CLICK ON THE FRAME FOR EXAMPLE
261 // EXECEPT WHEN MOUSE MOVE EVENT
262 if ( !hasToRepaint) {
263 if (((WinSize_x == (G4int)width())) &&(WinSize_y == (G4int) height())) {
264#ifdef GEANT4_QT_DEBUG
265 printf("G4OpenGLStoredQtViewer::paintGL ============ Dont repaint\n");
266#endif
267 return;
268 }
269 }
270 nbPaint++;
271#ifdef GEANT4_QT_DEBUG
272 printf("G4OpenGLStoredQtViewer::paintGL VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV %d ready %d\n",nbPaint,readyToPaint);
273#endif
274 WinSize_x = (G4int) width();
275 WinSize_y = (G4int) height();
276
277 setupViewport(width(),height());
278 // glViewport (0, 0, width(), height());
279 // glLoadIdentity();
280
281
282 SetView();
283
284 // // printf("before ClearView\n");
285#ifdef GEANT4_QT_DEBUG
286 printf(" ClearView\n");
287#endif
288
289 ClearView (); //ok, put the background correct
290 DrawView();
291
292 hasToRepaint =false;
293
294#ifdef GEANT4_QT_DEBUG
295 printf("G4OpenGLStoredQtViewer::paintGL ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ %d ready %d\n",nbPaint,readyToPaint);
296#endif
297}
298
299void G4OpenGLStoredQtViewer::mousePressEvent(QMouseEvent *event)
300{
301 if ((event->buttons() & Qt::LeftButton)
302 && !((event->modifiers() & Qt::ShiftModifier)
303 || (event->modifiers() & Qt::ControlModifier)
304 || (event->modifiers() & Qt::AltModifier)
305 || (event->modifiers() & Qt::MetaModifier))) {
306#ifdef GEANT4_QT_DEBUG
307 printf("G4OpenGLStoredQtViewer::mousePressEvent\n");
308#endif
309 setMouseTracking(true);
310 G4MousePressEvent(event->pos());
311 }
312}
313
314void G4OpenGLStoredQtViewer::keyPressEvent (QKeyEvent * event)
315{
316 G4keyPressEvent(event);
317}
318
319/**
320 * This function was build in order to make a zoom on double clic event.
321 * It was think to build a rubberband on the zoom area, but never work fine
322 */
323void G4OpenGLStoredQtViewer::mouseDoubleClickEvent(QMouseEvent *event)
324{
325#ifdef GEANT4_QT_DEBUG
326 printf("G4OpenGLStoredQtViewer::mouseDoubleClickEvent\n");
327#endif
328 // setMouseTracking(true);
329 // glBufferImage = grabFrameBuffer().convertToFormat(QImage::Format_ARGB32);//_Premultiplied);
330}
331
332void G4OpenGLStoredQtViewer::mouseReleaseEvent(QMouseEvent *event)
333{
334#ifdef GEANT4_QT_DEBUG
335 printf("G4OpenGLStoredQtViewer::mouseReleaseEvent\n");
336#endif
337 // setMouseTracking(false);
338}
339
340void G4OpenGLStoredQtViewer::mouseMoveEvent(QMouseEvent *event)
341{
342
343#if QT_VERSION < 0x040000
344 G4MouseEvent(event->x(),event->y(),event->state());
345#else
346 G4MouseEvent(event->x(),event->y(),event->buttons());
347#endif
348}
349
350
351void G4OpenGLStoredQtViewer::contextMenuEvent(QContextMenuEvent *e)
352{
353#ifdef GEANT4_QT_DEBUG
354 printf("G4OpenGLStoredQtViewer::contextMenuEvent\n");
355#endif
356 manageContextMenuEvent(e);
357}
358
359void G4OpenGLStoredQtViewer::updateQWidget() {
360 hasToRepaint= true;
361 updateGL();
362 hasToRepaint= false;
363}
364
365
366#endif
Note: See TracBrowser for help on using the repository browser.