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