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

Last change on this file since 1098 was 1092, checked in by garnier, 16 years ago

unset picking true when init OGLSQt

  • Property svn:mime-type set to text/cpp
File size: 8.8 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.26 2009/07/27 14:01:13 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//#include <qmouseevent.h>
41#include <qevent.h> // include <qcontextmenuevent.h>
42
43G4OpenGLStoredQtViewer::G4OpenGLStoredQtViewer
44(G4OpenGLStoredSceneHandler& sceneHandler,
45 const G4String& name):
46 G4VViewer (sceneHandler, sceneHandler.IncrementViewCount (), name),
47 G4OpenGLViewer (sceneHandler),
48 G4OpenGLQtViewer (sceneHandler),
49 G4OpenGLStoredViewer (sceneHandler) // FIXME : gerer le pb du parent !
50{
51
52#if QT_VERSION < 0x040000
53 setFocusPolicy(QWidget::StrongFocus); // enable keybord events
54#else
55 setFocusPolicy(Qt::StrongFocus); // enable keybord events
56#endif
57 fHasToRepaint =false;
58
59 if (fViewId < 0) return; // In case error in base class instantiation.
60}
61
62G4OpenGLStoredQtViewer::~G4OpenGLStoredQtViewer() {
63 makeCurrent();
64 // this is connect to the Dialog for deleting it properly
65 // when close event.
66 // ((QDialog*)window())->reject();
67}
68
69void G4OpenGLStoredQtViewer::Initialise() {
70#ifdef G4DEBUG_VIS_OGL
71 printf("G4OpenGLStoredQtViewer::Initialise 1\n");
72#endif
73 fReadyToPaint = false;
74 CreateMainWindow (this,QString(fName));
75 CreateFontLists ();
76
77 fReadyToPaint = true;
78}
79
80void G4OpenGLStoredQtViewer::initializeGL () {
81
82 InitializeGLView ();
83
84#ifdef G4DEBUG_VIS_OGL
85 printf("G4OpenGLStoredQtViewer::InitialiseGL () 1\n");
86#endif
87
88 // clear the buffers and window.
89 ClearView ();
90 FinishView ();
91
92 glDepthFunc (GL_LEQUAL);
93 glDepthMask (GL_TRUE);
94
95 if (fSceneHandler.GetScene() == 0) {
96 fHasToRepaint =false;
97 } else {
98 fHasToRepaint =true;
99 }
100
101#ifdef G4DEBUG_VIS_OGL
102 printf("G4OpenGLStoredQtViewer::InitialiseGL END\n");
103#endif
104}
105
106
107void G4OpenGLStoredQtViewer::DrawView () {
108#ifdef G4DEBUG_VIS_OGL
109 printf("G4OpenGLStoredQtViewer::DrawView VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV\n");
110#endif
111 // That's no the same logic as Immediate Viewer, I don't know why...
112 // But if I send updateGL here, we go here :
113 // updateQWidget -> paintGL -> ComputeView
114 // whih is not the same as ComputeView Directly
115 // And we loose the redraw of things !
116
117 ComputeView();
118#ifdef G4DEBUG_VIS_OGL
119 printf("G4OpenGLStoredQtViewer::DrawView ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n");
120#endif
121}
122
123void G4OpenGLStoredQtViewer::ComputeView () {
124
125#ifdef G4DEBUG_VIS_OGL
126 printf("G4OpenGLStoredQtViewer::ComputeView %d %d VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV\n",getWinWidth(), getWinHeight());
127#endif
128 makeCurrent();
129 G4ViewParameters::DrawingStyle style = GetViewParameters().GetDrawingStyle();
130
131 //Make sure current viewer is attached and clean...
132
133 //See if things have changed from last time and remake if necessary...
134 // The fNeedKernelVisit flag might have been set by the user in
135 // /vis/viewer/rebuild, but if not, make decision and set flag only
136 // if necessary...
137 if (!fNeedKernelVisit) {
138 KernelVisitDecision ();
139 }
140 G4bool kernelVisitWasNeeded = fNeedKernelVisit; // Keep (ProcessView resets).
141 ProcessView ();
142
143
144 if(style!=G4ViewParameters::hlr &&
145 haloing_enabled) {
146#ifdef G4DEBUG_VIS_OGL
147 printf("G4OpenGLStoredQtViewer::ComputeView 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 G4DEBUG_VIS_OGL
165 printf("************************** G4OpenGLStoredQtViewer::ComputeView Don't need kernel Visit \n");
166#endif
167 DrawDisplayLists ();
168 FinishView ();
169 } else {
170#ifdef G4DEBUG_VIS_OGL
171 printf("************************** G4OpenGLStoredQtViewer::ComputeView 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 G4DEBUG_VIS_OGL
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 G4DEBUG_VIS_OGL
195 printf("G4OpenGLStoredQtViewer::ComputeView %d %d ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \n",getWinWidth(), getWinHeight());
196#endif
197 fHasToRepaint =true;
198}
199
200
201/**
202 - Lors du resize de la fenetre, on doit non pas redessiner le detecteur, mais aussi les evenements
203*/
204void G4OpenGLStoredQtViewer::resizeGL(
205 int aWidth
206 ,int aHeight)
207{
208 // Set new size, it will be update when next Repaint()->SetView() called
209 ResizeWindow(aWidth,aHeight);
210 fHasToRepaint = sizeHasChanged();
211}
212
213
214void G4OpenGLStoredQtViewer::paintGL()
215{
216#ifdef G4DEBUG_VIS_OGL
217 printf("G4OpenGLStoredQtViewer::paintGL ready:%d fHasTo:%d??\n",fReadyToPaint,fHasToRepaint);
218#endif
219 if (!fReadyToPaint) {
220 fReadyToPaint= true;
221 return;
222 }
223 // DO NOT RESIZE IF SIZE HAS NOT CHANGE :
224 // WHEN CLICK ON THE FRAME FOR EXAMPLE
225 // EXECEPT WHEN MOUSE MOVE EVENT
226 if ( !fHasToRepaint) {
227 if (((getWinWidth() == (unsigned int)width())) &&(getWinHeight() == (unsigned int) height())) {
228 return;
229 }
230 }
231#ifdef G4DEBUG_VIS_OGL
232 printf("G4OpenGLStoredQtViewer::paintGL VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV ready %d\n",fReadyToPaint);
233#endif
234
235 SetView();
236
237 ClearView (); //ok, put the background correct
238 ComputeView();
239
240 fHasToRepaint =false;
241
242#ifdef G4DEBUG_VIS_OGL
243 printf("G4OpenGLStoredQtViewer::paintGL ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ready %d\n",fReadyToPaint);
244#endif
245}
246
247void G4OpenGLStoredQtViewer::mousePressEvent(QMouseEvent *event)
248{
249 G4MousePressEvent(event);
250}
251
252void G4OpenGLStoredQtViewer::keyPressEvent (QKeyEvent * event)
253{
254 G4keyPressEvent(event);
255}
256
257void G4OpenGLStoredQtViewer::wheelEvent (QWheelEvent * event)
258{
259 G4wheelEvent(event);
260}
261
262/**
263 * This function was build in order to make a zoom on double clic event.
264 * It was think to build a rubberband on the zoom area, but never work fine
265 */
266void G4OpenGLStoredQtViewer::mouseDoubleClickEvent(QMouseEvent *)
267{
268 G4MouseDoubleClickEvent();
269}
270
271void G4OpenGLStoredQtViewer::mouseReleaseEvent(QMouseEvent *)
272{
273 G4MouseReleaseEvent();
274}
275
276void G4OpenGLStoredQtViewer::mouseMoveEvent(QMouseEvent *event)
277{
278 G4MouseMoveEvent(event);
279}
280
281
282void G4OpenGLStoredQtViewer::contextMenuEvent(QContextMenuEvent *e)
283{
284 G4manageContextMenuEvent(e);
285}
286
287void G4OpenGLStoredQtViewer::updateQWidget() {
288 fHasToRepaint= true;
289 updateGL();
290 fHasToRepaint= false;
291}
292
293void G4OpenGLStoredQtViewer::ShowView (
294)
295//////////////////////////////////////////////////////////////////////////////
296//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
297{
298#if QT_VERSION < 0x040000
299 setActiveWindow();
300#else
301 activateWindow();
302#endif
303}
304
305#endif
Note: See TracBrowser for help on using the repository browser.