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