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

Last change on this file since 679 was 678, checked in by garnier, 18 years ago

modifs de test pour rubberband et mise en place du button mouse zoom

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