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

Last change on this file since 1302 was 1295, checked in by garnier, 15 years ago

CVS update

  • Property svn:mime-type set to text/cpp
File size: 9.2 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.29 2010/03/10 11:03:46 lgarnier Exp $
28// GEANT4 tag $Name: vis-V09-03-06 $
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
40G4OpenGLStoredQtViewer::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
60G4OpenGLStoredQtViewer::~G4OpenGLStoredQtViewer() {
61 makeCurrent();
62 // this is connect to the Dialog for deleting it properly
63 // when close event.
64 // ((QDialog*)window())->reject();
65}
66
67void 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
78void 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
105void G4OpenGLStoredQtViewer::DrawView () {
106 updateQWidget();
107}
108
109void G4OpenGLStoredQtViewer::ComputeView () {
110
111#ifdef G4DEBUG_VIS_OGL
112 printf("G4OpenGLStoredQtViewer::ComputeView %d %d VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV\n",getWinWidth(), getWinHeight());
113#endif
114 makeCurrent();
115 G4ViewParameters::DrawingStyle style = GetViewParameters().GetDrawingStyle();
116
117 //Make sure current viewer is attached and clean...
118
119 //See if things have changed from last time and remake if necessary...
120 // The fNeedKernelVisit flag might have been set by the user in
121 // /vis/viewer/rebuild, but if not, make decision and set flag only
122 // if necessary...
123 if (!fNeedKernelVisit) {
124 KernelVisitDecision ();
125 }
126 G4bool kernelVisitWasNeeded = fNeedKernelVisit; // Keep (ProcessView resets).
127 ProcessView ();
128
129
130 if(style!=G4ViewParameters::hlr &&
131 haloing_enabled) {
132#ifdef G4DEBUG_VIS_OGL
133 printf("G4OpenGLStoredQtViewer::ComputeView DANS LE IF\n");
134#endif
135
136 HaloingFirstPass ();
137 DrawDisplayLists ();
138 glFlush ();
139
140 HaloingSecondPass ();
141
142 DrawDisplayLists ();
143 FinishView ();
144
145 } else {
146
147 // If kernel visit was needed, drawing and FinishView will already
148 // have been done, so...
149 if (!kernelVisitWasNeeded) {
150#ifdef G4DEBUG_VIS_OGL
151 printf("************************** G4OpenGLStoredQtViewer::ComputeView Don't need kernel Visit \n");
152#endif
153 DrawDisplayLists ();
154 FinishView ();
155 } else {
156#ifdef G4DEBUG_VIS_OGL
157 printf("************************** G4OpenGLStoredQtViewer::ComputeView need kernel Visit \n");
158#endif
159 // However, union cutaways are implemented in DrawDisplayLists, so make
160 // an extra pass...
161 if (fVP.IsCutaway() &&
162 fVP.GetCutawayMode() == G4ViewParameters::cutawayUnion) {
163 ClearView();
164 DrawDisplayLists ();
165 FinishView ();
166#ifdef G4DEBUG_VIS_OGL
167 printf("*************************** CASE 4 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \n");
168#endif
169 } else { // ADD TO AVOID KernelVisit=1 and nothing to display
170 DrawDisplayLists ();
171 FinishView ();
172 }
173 }
174 }
175
176 if (isRecording()) {
177 savePPMToTemp();
178 }
179
180#ifdef G4DEBUG_VIS_OGL
181 printf("G4OpenGLStoredQtViewer::ComputeView %d %d ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \n",getWinWidth(), getWinHeight());
182#endif
183 fHasToRepaint =true;
184}
185
186
187/**
188 - Lors du resize de la fenetre, on doit non pas redessiner le detecteur, mais aussi les evenements
189*/
190void G4OpenGLStoredQtViewer::resizeGL(
191 int aWidth
192 ,int aHeight)
193{
194 // Set new size, it will be update when next Repaint()->SetView() called
195 ResizeWindow(aWidth,aHeight);
196 fHasToRepaint = sizeHasChanged();
197}
198
199
200// We have to get several case :
201// - Only activate the windows (mouse click for example) -> Do not redraw
202// - resize window -> redraw
203// - try to avoid recompute everything if we do not rescale picture (side is the same)
204
205void G4OpenGLStoredQtViewer::paintGL()
206{
207#ifdef G4DEBUG_VIS_OGL
208 printf("G4OpenGLStoredQtViewer::paintGL ready:%d fHasTo:%d??\n",fReadyToPaint,fHasToRepaint);
209#endif
210 if (!fReadyToPaint) {
211 fReadyToPaint= true;
212 return;
213 }
214 // DO NOT RESIZE IF SIZE HAS NOT CHANGE :
215 // WHEN CLICK ON THE FRAME FOR EXAMPLE
216 // EXECEPT WHEN MOUSE MOVE EVENT
217 if ( !fHasToRepaint) {
218#if QT_VERSION < 0x040000
219 if (((getWinWidth() == (unsigned int)width())) &&(getWinHeight() == (unsigned int) height())) {
220#else
221 // L. Garnier : Trap to get the size with mac OSX 10.6 and Qt 4.6(devel)
222 // Tested on Qt4.5 on mac, 4.4 on windows, 4.5 on unbuntu
223 int sw = 0;
224 int sh = 0;
225 if (!isMaximized() && !isFullScreen()) {
226 sw = normalGeometry().width();
227 sh = normalGeometry().height();
228 } else {
229 sw = frameGeometry().width();
230 sh = frameGeometry().height();
231 }
232 if ((getWinWidth() == (unsigned int)sw) &&(getWinHeight() == (unsigned int)sh)) {
233#endif
234 return;
235 }
236 }
237#ifdef G4DEBUG_VIS_OGL
238 printf("G4OpenGLStoredQtViewer::paintGL VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV ready %d\n",fReadyToPaint);
239#endif
240
241 SetView();
242
243 ClearView (); //ok, put the background correct
244 ComputeView();
245
246 fHasToRepaint =false;
247
248#ifdef G4DEBUG_VIS_OGL
249 printf("G4OpenGLStoredQtViewer::paintGL ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ready %d\n",fReadyToPaint);
250#endif
251}
252
253void G4OpenGLStoredQtViewer::paintEvent(QPaintEvent *event) {
254 if ( fHasToRepaint) {
255 updateGL();
256 }
257}
258
259void G4OpenGLStoredQtViewer::mousePressEvent(QMouseEvent *event)
260{
261 G4MousePressEvent(event);
262}
263
264void G4OpenGLStoredQtViewer::keyPressEvent (QKeyEvent * event)
265{
266 G4keyPressEvent(event);
267}
268
269void G4OpenGLStoredQtViewer::wheelEvent (QWheelEvent * event)
270{
271 G4wheelEvent(event);
272}
273
274void G4OpenGLStoredQtViewer::showEvent (QShowEvent * event)
275{
276 fHasToRepaint = true;
277}
278
279/**
280 * This function was build in order to make a zoom on double clic event.
281 * It was think to build a rubberband on the zoom area, but never work fine
282 */
283void G4OpenGLStoredQtViewer::mouseDoubleClickEvent(QMouseEvent *)
284{
285 G4MouseDoubleClickEvent();
286}
287
288void G4OpenGLStoredQtViewer::mouseReleaseEvent(QMouseEvent *)
289{
290 G4MouseReleaseEvent();
291}
292
293void G4OpenGLStoredQtViewer::mouseMoveEvent(QMouseEvent *event)
294{
295 G4MouseMoveEvent(event);
296}
297
298
299void G4OpenGLStoredQtViewer::contextMenuEvent(QContextMenuEvent *e)
300{
301 G4manageContextMenuEvent(e);
302}
303
304void G4OpenGLStoredQtViewer::updateQWidget() {
305 fHasToRepaint= true;
306 updateGL();
307 fHasToRepaint= false;
308}
309
310void G4OpenGLStoredQtViewer::ShowView (
311)
312//////////////////////////////////////////////////////////////////////////////
313//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
314{
315#if QT_VERSION < 0x040000
316 setActiveWindow();
317#else
318 activateWindow();
319#endif
320}
321
322#endif
Note: See TracBrowser for help on using the repository browser.