source: trunk/source/visualization/OpenGL/src/G4OpenGLImmediateQtViewer.cc@ 911

Last change on this file since 911 was 911, checked in by garnier, 17 years ago

change debug definition, and tag for files

  • Property svn:mime-type set to text/cpp
File size: 7.5 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: G4OpenGLImmediateQtViewer.cc,v 1.11 2009/01/19 16:53:42 lgarnier Exp $
28// GEANT4 tag $Name: $
29//
30//
31// Class G4OpenGLImmediateQtViewer : a class derived from G4OpenGLQtViewer and
32// G4OpenGLImmediateViewer.
33
34#ifdef G4VIS_BUILD_OPENGLQT_DRIVER
35
36#include "G4OpenGLImmediateQtViewer.hh"
37
38#include "G4ios.hh"
39
40G4OpenGLImmediateQtViewer::G4OpenGLImmediateQtViewer
41(G4OpenGLImmediateSceneHandler& sceneHandler,
42 const G4String& name):
43 G4VViewer (sceneHandler, sceneHandler.IncrementViewCount (), name),
44 G4OpenGLViewer (sceneHandler),
45 G4OpenGLQtViewer (sceneHandler),
46 G4OpenGLImmediateViewer (sceneHandler)
47{
48
49 //set true to picking
50 fVP.SetPicking(true);
51 fDefaultVP.SetPicking(true);
52#if QT_VERSION < 0x040000
53 setFocusPolicy(QWidget::StrongFocus); // enable keybord events
54#else
55 setFocusPolicy(Qt::StrongFocus); // enable keybord events
56#endif
57 hasToRepaint =false;
58
59 if (fViewId < 0) return; // In case error in base class instantiation.
60}
61
62G4OpenGLImmediateQtViewer::~G4OpenGLImmediateQtViewer() {
63 makeCurrent();
64}
65
66void G4OpenGLImmediateQtViewer::Initialise() {
67#ifdef G4DEBUG_VIS_OGL
68 printf("G4OpenGLImmediateQtViewer::Initialise \n");
69#endif
70 readyToPaint = false;
71 CreateMainWindow (this,QString(fName));
72 CreateFontLists ();
73
74 readyToPaint = true;
75}
76
77void G4OpenGLImmediateQtViewer::initializeGL () {
78
79 InitializeGLView ();
80
81
82 // If a double buffer context has been forced upon us, ignore the
83 // back buffer for this OpenGLImmediate view.
84 // glDrawBuffer (GL_FRONT); // FIXME : Ne marche pas avec cette ligne, mais affiche le run correctement...
85 // clear the buffers and window.
86 ClearView ();
87 FinishView ();
88
89 glDepthFunc (GL_LEQUAL);
90 glDepthMask (GL_TRUE);
91
92 if (fSceneHandler.GetScene() == 0) {
93 hasToRepaint =false;
94 } else {
95 hasToRepaint =true;
96 }
97
98}
99
100
101/** To ensure compatibility with DrawView method
102 */
103void G4OpenGLImmediateQtViewer::DrawView() {
104#ifdef G4DEBUG_VIS_OGL
105 printf("G4OpenGLImmediateQtViewer::DrawView VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV\n");
106#endif
107 // That's no the same logic as Stored Viewer, I don't know why...
108 // see G4OpenGLStoredQtViewer::DrawView for more informations
109
110 updateQWidget();
111#ifdef G4DEBUG_VIS_OGL
112 printf("G4OpenGLImmediateQtViewer::DrawView ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n");
113#endif
114}
115
116
117void G4OpenGLImmediateQtViewer::ComputeView () {
118
119#ifdef G4DEBUG_VIS_OGL
120 printf("G4OpenGLImmediateQtViewer::ComputeView %d %d VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV\n",fWinSize_x, fWinSize_y);
121#endif
122 makeCurrent();
123 // If a double buffer context has been forced upon us, ignore the
124 // back buffer for this OpenGLImmediate view.
125 // glDrawBuffer (GL_FRONT);
126
127 G4ViewParameters::DrawingStyle style = GetViewParameters().GetDrawingStyle();
128
129 if(style!=G4ViewParameters::hlr &&
130 haloing_enabled) {
131
132 HaloingFirstPass ();
133 NeedKernelVisit ();
134 ProcessView ();
135 glFlush ();
136#ifdef G4DEBUG_VIS_OGL
137 printf("G4OpenGLImmediateQtViewer::ComputeView First ProcessView ok\n");
138#endif
139 HaloingSecondPass ();
140
141 }
142
143 NeedKernelVisit (); // Always need to visit G4 kernel.
144 ProcessView ();
145
146 if (isRecording()) {
147 savePPMToTemp();
148 }
149
150#ifdef G4DEBUG_VIS_OGL
151 printf("G4OpenGLImmediateQtViewer::ComputeView %d %d ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \n",fWinSize_x, fWinSize_y);
152#endif
153 hasToRepaint = true;
154}
155
156void G4OpenGLImmediateQtViewer::FinishView()
157{
158#ifdef G4DEBUG_VIS_OGL
159 printf("G4OpenGLImmediateQtViewer::FinishView() BEGIN\n");
160#endif
161 glFlush ();
162#ifdef G4DEBUG_VIS_OGL
163 printf("G4OpenGLImmediateQtViewer::FinishView() END\n");
164#endif
165
166}
167
168
169/**
170 - Lors du resize de la fenetre, on doit non pas redessiner le detecteur, mais aussi les evenements
171*/
172void G4OpenGLImmediateQtViewer::resizeGL(
173 int aWidth
174,int aHeight)
175{
176 fWinSize_x = aWidth;
177 fWinSize_y = aHeight;
178 hasToRepaint = true;
179}
180
181
182void G4OpenGLImmediateQtViewer::paintGL()
183{
184#ifdef G4DEBUG_VIS_OGL
185 printf("\n\nG4OpenGLImmediateQtViewer::paintGL ??\n");
186#endif
187 if (!readyToPaint) {
188 readyToPaint= true;
189 return;
190 }
191 // DO NOT RESIZE IF SIZE HAS NOT CHANGE
192 if ( !hasToRepaint) {
193 if (((fWinSize_x == (unsigned int)width())) &&(fWinSize_y == (unsigned int) height())) {
194 return;
195 }
196 }
197#ifdef G4DEBUG_VIS_OGL
198 printf("G4OpenGLImmediateQtViewer::paintGL VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV ready %d\n",readyToPaint);
199#endif
200
201 SetView();
202
203 ClearView (); //ok, put the background correct
204 ComputeView();
205
206 hasToRepaint = false; // could be set to false by ComputeView
207
208#ifdef G4DEBUG_VIS_OGL
209 printf("G4OpenGLImmediateQtViewer::paintGL ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ready %d\n\n\n",readyToPaint);
210#endif
211}
212
213void G4OpenGLImmediateQtViewer::mousePressEvent(QMouseEvent *event)
214{
215 G4MousePressEvent(event);
216}
217
218void G4OpenGLImmediateQtViewer::keyPressEvent (QKeyEvent * event)
219{
220 G4keyPressEvent(event);
221}
222
223void G4OpenGLImmediateQtViewer::wheelEvent (QWheelEvent * event)
224{
225 G4wheelEvent(event);
226}
227
228/**
229 * This function was build in order to make a zoom on double clic event.
230 * It was think to build a rubberband on the zoom area, but never work fine
231 */
232void G4OpenGLImmediateQtViewer::mouseDoubleClickEvent(QMouseEvent *event)
233{
234 G4MouseDoubleClickEvent();
235}
236
237void G4OpenGLImmediateQtViewer::mouseReleaseEvent(QMouseEvent *event)
238{
239 G4MouseReleaseEvent();
240}
241
242void G4OpenGLImmediateQtViewer::mouseMoveEvent(QMouseEvent *event)
243{
244 G4MouseMoveEvent(event);
245}
246
247
248void G4OpenGLImmediateQtViewer::contextMenuEvent(QContextMenuEvent *e)
249{
250 G4manageContextMenuEvent(e);
251}
252
253void G4OpenGLImmediateQtViewer::updateQWidget() {
254 hasToRepaint= true;
255 updateGL();
256 hasToRepaint= false;
257}
258
259
260void G4OpenGLImmediateQtViewer::ShowView (
261)
262//////////////////////////////////////////////////////////////////////////////
263//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
264{
265#if QT_VERSION < 0x040000
266 setActiveWindow();
267#else
268 activateWindow();
269#endif
270}
271#endif
Note: See TracBrowser for help on using the repository browser.