source: trunk/source/visualization/OpenGL/src/G4OpenGLStoredQtViewer.cc@ 939

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

test pour GL_POINTS au lieu de glBitmap

  • Property svn:mime-type set to text/cpp
File size: 8.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.23 2009/01/19 16:26:40 lgarnier Exp $
28// GEANT4 tag $Name: $
29//
30//
31// Class G4OpenGLStoredQtViewer : a class derived from G4OpenGLQtViewer and
32// G4OpenGLStoredViewer.
33
34#define G4DEBUG_VIS_OGL
35
36#ifdef G4VIS_BUILD_OPENGLQT_DRIVER
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) // FIXME : gerer le pb du parent !
52{
53
54 //set true to picking
55 fVP.SetPicking(true);
56#if QT_VERSION < 0x040000
57 setFocusPolicy(QWidget::StrongFocus); // enable keybord events
58#else
59 setFocusPolicy(Qt::StrongFocus); // enable keybord events
60#endif
61 hasToRepaint =false;
62
63 if (fViewId < 0) return; // In case error in base class instantiation.
64}
65
66G4OpenGLStoredQtViewer::~G4OpenGLStoredQtViewer() {
67 makeCurrent();
68 // this is connect to the Dialog for deleting it properly
69 // when close event.
70 // ((QDialog*)window())->reject();
71}
72
73void G4OpenGLStoredQtViewer::Initialise() {
74#ifdef G4DEBUG_VIS_OGL
75 printf("G4OpenGLStoredQtViewer::Initialise 1\n");
76#endif
77 readyToPaint = false;
78 CreateMainWindow (this,QString(fName));
79 CreateFontLists ();
80
81 readyToPaint = true;
82}
83
84void G4OpenGLStoredQtViewer::initializeGL () {
85
86 InitializeGLView ();
87
88#ifdef G4DEBUG_VIS_OGL
89 printf("G4OpenGLStoredQtViewer::InitialiseGL () 1\n");
90#endif
91
92 // clear the buffers and window.
93 ClearView ();
94 FinishView ();
95
96 glDepthFunc (GL_LEQUAL);
97 glDepthMask (GL_TRUE);
98
99 if (fSceneHandler.GetScene() == 0) {
100 hasToRepaint =false;
101 } else {
102 hasToRepaint =true;
103 }
104
105#ifdef G4DEBUG_VIS_OGL
106 printf("G4OpenGLStoredQtViewer::InitialiseGL END\n");
107#endif
108}
109
110
111void G4OpenGLStoredQtViewer::DrawView () {
112#ifdef G4DEBUG_VIS_OGL
113 printf("G4OpenGLStoredQtViewer::DrawView VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV\n");
114#endif
115 // That's no the same logic as Immediate Viewer, I don't know why...
116 // But if I send updateGL here, we go here :
117 // updateQWidget -> paintGL -> ComputeView
118 // whih is not the same as ComputeView Directly
119 // And we loose the redraw of things !
120
121 ComputeView();
122#ifdef G4DEBUG_VIS_OGL
123 printf("G4OpenGLStoredQtViewer::DrawView ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n");
124#endif
125}
126
127void G4OpenGLStoredQtViewer::ComputeView () {
128
129#ifdef G4DEBUG_VIS_OGL
130 printf("G4OpenGLStoredQtViewer::ComputeView %d %d VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV\n",fWinSize_x, fWinSize_y);
131#endif
132 makeCurrent();
133 G4ViewParameters::DrawingStyle style = GetViewParameters().GetDrawingStyle();
134
135 //Make sure current viewer is attached and clean...
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 KernelVisitDecision ();
143 }
144 G4bool kernelVisitWasNeeded = fNeedKernelVisit; // Keep (ProcessView resets).
145 ProcessView ();
146
147
148 if(style!=G4ViewParameters::hlr &&
149 haloing_enabled) {
150#ifdef G4DEBUG_VIS_OGL
151 printf("G4OpenGLStoredQtViewer::ComputeView DANS LE IF\n");
152#endif
153
154 HaloingFirstPass ();
155 DrawDisplayLists ();
156 glFlush ();
157
158 HaloingSecondPass ();
159
160 DrawDisplayLists ();
161 FinishView ();
162
163 } else {
164
165 // If kernel visit was needed, drawing and FinishView will already
166 // have been done, so...
167 if (!kernelVisitWasNeeded) {
168#ifdef G4DEBUG_VIS_OGL
169 printf("************************** G4OpenGLStoredQtViewer::ComputeView Don't need kernel Visit \n");
170#endif
171 DrawDisplayLists ();
172 FinishView ();
173 } else {
174#ifdef G4DEBUG_VIS_OGL
175 printf("************************** G4OpenGLStoredQtViewer::ComputeView need kernel Visit \n");
176#endif
177 // However, union cutaways are implemented in DrawDisplayLists, so make
178 // an extra pass...
179 if (fVP.IsCutaway() &&
180 fVP.GetCutawayMode() == G4ViewParameters::cutawayUnion) {
181 ClearView();
182 DrawDisplayLists ();
183 FinishView ();
184#ifdef G4DEBUG_VIS_OGL
185 printf("*************************** CASE 4 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \n");
186#endif
187 } else { // ADD TO AVOID KernelVisit=1 and nothing to display
188 DrawDisplayLists ();
189 FinishView ();
190 }
191 }
192 }
193
194 if (isRecording()) {
195 savePPMToTemp();
196 }
197
198#ifdef G4DEBUG_VIS_OGL
199 printf("G4OpenGLStoredQtViewer::ComputeView %d %d ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \n",fWinSize_x, fWinSize_y);
200#endif
201 hasToRepaint =true;
202}
203
204
205/**
206 - Lors du resize de la fenetre, on doit non pas redessiner le detecteur, mais aussi les evenements
207*/
208void G4OpenGLStoredQtViewer::resizeGL(
209 int aWidth
210 ,int aHeight)
211{
212 // Set new size, it will be update when next Repaint()->SetView() called
213 fWinSize_x = aWidth;
214 fWinSize_y = aHeight;
215 hasToRepaint = true;
216}
217
218
219void G4OpenGLStoredQtViewer::paintGL()
220{
221#ifdef G4DEBUG_VIS_OGL
222 printf("G4OpenGLStoredQtViewer::paintGL ready %d hasTorepaint:%d\n",readyToPaint,hasToRepaint);
223#endif
224 if (!readyToPaint) {
225 readyToPaint= true;
226 return;
227 }
228 // DO NOT RESIZE IF SIZE HAS NOT CHANGE :
229 // WHEN CLICK ON THE FRAME FOR EXAMPLE
230 // EXECEPT WHEN MOUSE MOVE EVENT
231 if ( !hasToRepaint) {
232 if (((fWinSize_x == (unsigned int)width())) &&(fWinSize_y == (unsigned int) height())) {
233 return;
234 }
235 }
236#ifdef G4DEBUG_VIS_OGL
237 printf("G4OpenGLStoredQtViewer::paintGL VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV ready %d\n",readyToPaint);
238#endif
239
240 SetView();
241
242 ClearView (); //ok, put the background correct
243 ComputeView();
244
245 hasToRepaint =false;
246
247#ifdef G4DEBUG_VIS_OGL
248 printf("G4OpenGLStoredQtViewer::paintGL ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ready %d\n",readyToPaint);
249#endif
250}
251
252void G4OpenGLStoredQtViewer::mousePressEvent(QMouseEvent *event)
253{
254 G4MousePressEvent(event);
255}
256
257void G4OpenGLStoredQtViewer::keyPressEvent (QKeyEvent * event)
258{
259 G4keyPressEvent(event);
260}
261
262void G4OpenGLStoredQtViewer::wheelEvent (QWheelEvent * event)
263{
264 G4wheelEvent(event);
265}
266
267/**
268 * This function was build in order to make a zoom on double clic event.
269 * It was think to build a rubberband on the zoom area, but never work fine
270 */
271void G4OpenGLStoredQtViewer::mouseDoubleClickEvent(QMouseEvent *event)
272{
273 G4MouseDoubleClickEvent();
274}
275
276void G4OpenGLStoredQtViewer::mouseReleaseEvent(QMouseEvent *event)
277{
278 G4MouseReleaseEvent();
279}
280
281void G4OpenGLStoredQtViewer::mouseMoveEvent(QMouseEvent *event)
282{
283 G4MouseMoveEvent(event);
284}
285
286
287void G4OpenGLStoredQtViewer::contextMenuEvent(QContextMenuEvent *e)
288{
289 G4manageContextMenuEvent(e);
290}
291
292void G4OpenGLStoredQtViewer::updateQWidget() {
293 hasToRepaint= true;
294 updateGL();
295 hasToRepaint= false;
296}
297
298void G4OpenGLStoredQtViewer::ShowView (
299)
300//////////////////////////////////////////////////////////////////////////////
301//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
302{
303#if QT_VERSION < 0x040000
304 setActiveWindow();
305#else
306 activateWindow();
307#endif
308 updateQWidget();
309}
310
311#endif
Note: See TracBrowser for help on using the repository browser.