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

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

fixes et cvs update

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