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.28 2009/11/03 11:02:32 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 | #include "G4OpenGLStoredQtViewer.hh" |
---|
37 | |
---|
38 | #include "G4ios.hh" |
---|
39 | |
---|
40 | G4OpenGLStoredQtViewer::G4OpenGLStoredQtViewer |
---|
41 | (G4OpenGLStoredSceneHandler& sceneHandler, |
---|
42 | const G4String& name): |
---|
43 | G4VViewer (sceneHandler, sceneHandler.IncrementViewCount (), name), |
---|
44 | G4OpenGLViewer (sceneHandler), |
---|
45 | G4OpenGLQtViewer (sceneHandler), |
---|
46 | G4OpenGLStoredViewer (sceneHandler), // FIXME : gerer le pb du parent ! |
---|
47 | QGLWidget() |
---|
48 | { |
---|
49 | |
---|
50 | #if QT_VERSION < 0x040000 |
---|
51 | setFocusPolicy(QWidget::StrongFocus); // enable keybord events |
---|
52 | #else |
---|
53 | setFocusPolicy(Qt::StrongFocus); // enable keybord events |
---|
54 | #endif |
---|
55 | fHasToRepaint =false; |
---|
56 | |
---|
57 | if (fViewId < 0) return; // In case error in base class instantiation. |
---|
58 | } |
---|
59 | |
---|
60 | G4OpenGLStoredQtViewer::~G4OpenGLStoredQtViewer() { |
---|
61 | makeCurrent(); |
---|
62 | // this is connect to the Dialog for deleting it properly |
---|
63 | // when close event. |
---|
64 | // ((QDialog*)window())->reject(); |
---|
65 | } |
---|
66 | |
---|
67 | void G4OpenGLStoredQtViewer::Initialise() { |
---|
68 | #ifdef G4DEBUG_VIS_OGL |
---|
69 | printf("G4OpenGLStoredQtViewer::Initialise 1\n"); |
---|
70 | #endif |
---|
71 | fReadyToPaint = false; |
---|
72 | CreateMainWindow (this,QString(GetName())); |
---|
73 | CreateFontLists (); |
---|
74 | |
---|
75 | fReadyToPaint = true; |
---|
76 | } |
---|
77 | |
---|
78 | void G4OpenGLStoredQtViewer::initializeGL () { |
---|
79 | |
---|
80 | InitializeGLView (); |
---|
81 | |
---|
82 | #ifdef G4DEBUG_VIS_OGL |
---|
83 | printf("G4OpenGLStoredQtViewer::InitialiseGL () 1\n"); |
---|
84 | #endif |
---|
85 | |
---|
86 | // clear the buffers and window. |
---|
87 | ClearView (); |
---|
88 | FinishView (); |
---|
89 | |
---|
90 | glDepthFunc (GL_LEQUAL); |
---|
91 | glDepthMask (GL_TRUE); |
---|
92 | |
---|
93 | if (fSceneHandler.GetScene() == 0) { |
---|
94 | fHasToRepaint =false; |
---|
95 | } else { |
---|
96 | fHasToRepaint =true; |
---|
97 | } |
---|
98 | |
---|
99 | #ifdef G4DEBUG_VIS_OGL |
---|
100 | printf("G4OpenGLStoredQtViewer::InitialiseGL END\n"); |
---|
101 | #endif |
---|
102 | } |
---|
103 | |
---|
104 | |
---|
105 | void G4OpenGLStoredQtViewer::DrawView () { |
---|
106 | #ifdef G4DEBUG_VIS_OGL |
---|
107 | printf("G4OpenGLStoredQtViewer::DrawView VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV\n"); |
---|
108 | #endif |
---|
109 | // That's no the same logic as Immediate Viewer, I don't know why... |
---|
110 | // But if I send updateGL here, we go here : |
---|
111 | // updateQWidget -> paintGL -> ComputeView |
---|
112 | // whih is not the same as ComputeView Directly |
---|
113 | // And we loose the redraw of things ! |
---|
114 | |
---|
115 | // ComputeView(); |
---|
116 | #ifdef G4DEBUG_VIS_OGL |
---|
117 | printf("G4OpenGLStoredQtViewer::DrawView ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ llllllllllllllllllllllllllllllll\n"); |
---|
118 | #endif |
---|
119 | updateQWidget(); |
---|
120 | } |
---|
121 | |
---|
122 | void G4OpenGLStoredQtViewer::ComputeView () { |
---|
123 | |
---|
124 | #ifdef G4DEBUG_VIS_OGL |
---|
125 | printf("G4OpenGLStoredQtViewer::ComputeView %d %d VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV\n",getWinWidth(), getWinHeight()); |
---|
126 | #endif |
---|
127 | makeCurrent(); |
---|
128 | G4ViewParameters::DrawingStyle style = GetViewParameters().GetDrawingStyle(); |
---|
129 | |
---|
130 | //Make sure current viewer is attached and clean... |
---|
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 | KernelVisitDecision (); |
---|
138 | } |
---|
139 | G4bool kernelVisitWasNeeded = fNeedKernelVisit; // Keep (ProcessView resets). |
---|
140 | ProcessView (); |
---|
141 | |
---|
142 | |
---|
143 | if(style!=G4ViewParameters::hlr && |
---|
144 | haloing_enabled) { |
---|
145 | #ifdef G4DEBUG_VIS_OGL |
---|
146 | printf("G4OpenGLStoredQtViewer::ComputeView DANS LE IF\n"); |
---|
147 | #endif |
---|
148 | |
---|
149 | HaloingFirstPass (); |
---|
150 | DrawDisplayLists (); |
---|
151 | glFlush (); |
---|
152 | |
---|
153 | HaloingSecondPass (); |
---|
154 | |
---|
155 | DrawDisplayLists (); |
---|
156 | FinishView (); |
---|
157 | |
---|
158 | } else { |
---|
159 | |
---|
160 | // If kernel visit was needed, drawing and FinishView will already |
---|
161 | // have been done, so... |
---|
162 | if (!kernelVisitWasNeeded) { |
---|
163 | #ifdef G4DEBUG_VIS_OGL |
---|
164 | printf("************************** G4OpenGLStoredQtViewer::ComputeView Don't need kernel Visit \n"); |
---|
165 | #endif |
---|
166 | DrawDisplayLists (); |
---|
167 | FinishView (); |
---|
168 | } else { |
---|
169 | #ifdef G4DEBUG_VIS_OGL |
---|
170 | printf("************************** G4OpenGLStoredQtViewer::ComputeView need kernel Visit \n"); |
---|
171 | #endif |
---|
172 | // However, union cutaways are implemented in DrawDisplayLists, so make |
---|
173 | // an extra pass... |
---|
174 | if (fVP.IsCutaway() && |
---|
175 | fVP.GetCutawayMode() == G4ViewParameters::cutawayUnion) { |
---|
176 | ClearView(); |
---|
177 | DrawDisplayLists (); |
---|
178 | FinishView (); |
---|
179 | #ifdef G4DEBUG_VIS_OGL |
---|
180 | printf("*************************** CASE 4 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \n"); |
---|
181 | #endif |
---|
182 | } else { // ADD TO AVOID KernelVisit=1 and nothing to display |
---|
183 | DrawDisplayLists (); |
---|
184 | FinishView (); |
---|
185 | } |
---|
186 | } |
---|
187 | } |
---|
188 | |
---|
189 | if (isRecording()) { |
---|
190 | savePPMToTemp(); |
---|
191 | } |
---|
192 | |
---|
193 | #ifdef G4DEBUG_VIS_OGL |
---|
194 | printf("G4OpenGLStoredQtViewer::ComputeView %d %d ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \n",getWinWidth(), getWinHeight()); |
---|
195 | #endif |
---|
196 | fHasToRepaint =true; |
---|
197 | } |
---|
198 | |
---|
199 | |
---|
200 | /** |
---|
201 | - Lors du resize de la fenetre, on doit non pas redessiner le detecteur, mais aussi les evenements |
---|
202 | */ |
---|
203 | void G4OpenGLStoredQtViewer::resizeGL( |
---|
204 | int aWidth |
---|
205 | ,int aHeight) |
---|
206 | { |
---|
207 | // Set new size, it will be update when next Repaint()->SetView() called |
---|
208 | ResizeWindow(aWidth,aHeight); |
---|
209 | fHasToRepaint = sizeHasChanged(); |
---|
210 | } |
---|
211 | |
---|
212 | |
---|
213 | // We have to get several case : |
---|
214 | // - Only activate the windows (mouse click for example) -> Do not redraw |
---|
215 | // - resize window -> redraw |
---|
216 | // - try to avoid recompute everything if we do not rescale picture (side is the same) |
---|
217 | |
---|
218 | void G4OpenGLStoredQtViewer::paintGL() |
---|
219 | { |
---|
220 | #ifdef G4DEBUG_VIS_OGL |
---|
221 | printf("G4OpenGLStoredQtViewer::paintGL ready:%d fHasTo:%d?? context:%d\n",fReadyToPaint,fHasToRepaint,context()); |
---|
222 | #endif |
---|
223 | if (!fReadyToPaint) { |
---|
224 | fReadyToPaint= true; |
---|
225 | return; |
---|
226 | } |
---|
227 | // DO NOT RESIZE IF SIZE HAS NOT CHANGE : |
---|
228 | // WHEN CLICK ON THE FRAME FOR EXAMPLE |
---|
229 | // EXECEPT WHEN MOUSE MOVE EVENT |
---|
230 | if ( !fHasToRepaint) { |
---|
231 | #if QT_VERSION < 0x040000 |
---|
232 | if (((getWinWidth() == (unsigned int)width())) &&(getWinHeight() == (unsigned int) height())) { |
---|
233 | #else |
---|
234 | // L. Garnier : Trap to get the size with mac OSX 10.6 and Qt 4.6(devel) |
---|
235 | // Tested on Qt4.5 on mac, 4.4 on windows, 4.5 on unbuntu |
---|
236 | int sw = 0; |
---|
237 | int sh = 0; |
---|
238 | if (!isMaximized() && !isFullScreen()) { |
---|
239 | sw = normalGeometry().width(); |
---|
240 | sh = normalGeometry().height(); |
---|
241 | } else { |
---|
242 | sw = frameGeometry().width(); |
---|
243 | sh = frameGeometry().height(); |
---|
244 | } |
---|
245 | if ((getWinWidth() == (unsigned int)sw) &&(getWinHeight() == (unsigned int)sh)) { |
---|
246 | #endif |
---|
247 | return; |
---|
248 | } |
---|
249 | } |
---|
250 | #ifdef G4DEBUG_VIS_OGL |
---|
251 | printf("G4OpenGLStoredQtViewer::paintGL VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV ready %d\n",fReadyToPaint); |
---|
252 | #endif |
---|
253 | |
---|
254 | SetView(); |
---|
255 | |
---|
256 | ClearView (); //ok, put the background correct |
---|
257 | ComputeView(); |
---|
258 | |
---|
259 | fHasToRepaint =false; |
---|
260 | |
---|
261 | #ifdef G4DEBUG_VIS_OGL |
---|
262 | printf("G4OpenGLStoredQtViewer::paintGL ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ready %d\n",fReadyToPaint); |
---|
263 | #endif |
---|
264 | } |
---|
265 | |
---|
266 | void G4OpenGLStoredQtViewer::paintEvent(QPaintEvent *event) { |
---|
267 | #ifdef G4DEBUG_VIS_OGL |
---|
268 | printf("\n\nG4OpenGLStoredQtViewer::paintEvent VVVVVVVVV %d context : %d\n",fHasToRepaint,context()); |
---|
269 | #endif |
---|
270 | if ( fHasToRepaint) { |
---|
271 | updateGL(); |
---|
272 | } |
---|
273 | #ifdef G4DEBUG_VIS_OGL |
---|
274 | printf("\n\nG4OpenGLStoredQtViewer::paintEvent ^^^^^^^^^\n"); |
---|
275 | #endif |
---|
276 | } |
---|
277 | |
---|
278 | void G4OpenGLStoredQtViewer::mousePressEvent(QMouseEvent *event) |
---|
279 | { |
---|
280 | G4MousePressEvent(event); |
---|
281 | } |
---|
282 | |
---|
283 | void G4OpenGLStoredQtViewer::keyPressEvent (QKeyEvent * event) |
---|
284 | { |
---|
285 | G4keyPressEvent(event); |
---|
286 | } |
---|
287 | |
---|
288 | void G4OpenGLStoredQtViewer::wheelEvent (QWheelEvent * event) |
---|
289 | { |
---|
290 | G4wheelEvent(event); |
---|
291 | } |
---|
292 | |
---|
293 | void G4OpenGLStoredQtViewer::showEvent (QShowEvent * event) |
---|
294 | { |
---|
295 | fHasToRepaint = true; |
---|
296 | } |
---|
297 | |
---|
298 | /** |
---|
299 | * This function was build in order to make a zoom on double clic event. |
---|
300 | * It was think to build a rubberband on the zoom area, but never work fine |
---|
301 | */ |
---|
302 | void G4OpenGLStoredQtViewer::mouseDoubleClickEvent(QMouseEvent *) |
---|
303 | { |
---|
304 | G4MouseDoubleClickEvent(); |
---|
305 | } |
---|
306 | |
---|
307 | void G4OpenGLStoredQtViewer::mouseReleaseEvent(QMouseEvent *) |
---|
308 | { |
---|
309 | G4MouseReleaseEvent(); |
---|
310 | } |
---|
311 | |
---|
312 | void G4OpenGLStoredQtViewer::mouseMoveEvent(QMouseEvent *event) |
---|
313 | { |
---|
314 | G4MouseMoveEvent(event); |
---|
315 | } |
---|
316 | |
---|
317 | |
---|
318 | void G4OpenGLStoredQtViewer::contextMenuEvent(QContextMenuEvent *e) |
---|
319 | { |
---|
320 | G4manageContextMenuEvent(e); |
---|
321 | } |
---|
322 | |
---|
323 | void G4OpenGLStoredQtViewer::updateQWidget() { |
---|
324 | fHasToRepaint= true; |
---|
325 | updateGL(); |
---|
326 | fHasToRepaint= false; |
---|
327 | } |
---|
328 | |
---|
329 | void G4OpenGLStoredQtViewer::ShowView ( |
---|
330 | ) |
---|
331 | ////////////////////////////////////////////////////////////////////////////// |
---|
332 | //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// |
---|
333 | { |
---|
334 | #if QT_VERSION < 0x040000 |
---|
335 | setActiveWindow(); |
---|
336 | #else |
---|
337 | activateWindow(); |
---|
338 | #endif |
---|
339 | } |
---|
340 | |
---|
341 | #endif |
---|