source: trunk/geant4/visualization/OpenGL/src/G4OpenGLStoredQtViewer.cc@ 586

Last change on this file since 586 was 579, checked in by garnier, 18 years ago

r599@mac-90108: laurentgarnier | 2007-09-18 18:43:19 +0200
correction du ticket #72 et la suppresion de la fenetre OpenGL entraine desormais un message d erreur lors du prochain BeamOn

  • Property svn:mime-type set to text/cpp
File size: 8.6 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.16 2007/06/25 16:38:13 $
28// GEANT4 tag $Name: geant4-08-02-patch-01 $
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#include "G4VisManager.hh"
38
39#include "G4ios.hh"
40
41G4OpenGLStoredQtViewer::G4OpenGLStoredQtViewer
42(G4OpenGLStoredSceneHandler& sceneHandler,
43 const G4String& name):
44 G4VViewer (sceneHandler, sceneHandler.IncrementViewCount (), name),
45 G4OpenGLViewer (sceneHandler),
46 G4OpenGLQtViewer (sceneHandler),
47 G4OpenGLStoredViewer (sceneHandler),
48 QGLWidget() // FIXME : gerer le pb du parent !
49 {
50 nbPaint =0;
51 hasToRepaint =false;
52 if (fViewId < 0) return; // In case error in base class instantiation.
53}
54
55G4OpenGLStoredQtViewer::~G4OpenGLStoredQtViewer() {
56 printf("GLWidget::~GLWidget \n");
57 makeCurrent();
58 // this is connect to the Dialog for deleting it properly
59 // when close event.
60 // ((QDialog*)window())->reject();
61 printf("GLWidget::~GLWidget END\n");
62}
63
64void G4OpenGLStoredQtViewer::Initialise() {
65 printf("GLWidget::Initialise \n");
66 readyToPaint = false;
67 CreateGLQtContext ();
68 printf("G4OpenGLStoredQtViewer::Initialise () 2\n");
69
70 CreateMainWindow (this);
71 printf("G4OpenGLStoredQtViewer::Initialise () 3\n");
72
73 CreateFontLists (); // FIXME Does nothing!
74
75 printf("readyToPaint = true \n");
76 readyToPaint = true;
77
78 // First Draw
79 SetView();
80 printf(" ClearView\n");
81 ClearView (); //ok, put the background correct
82 ShowView();
83 FinishView();
84}
85
86void G4OpenGLStoredQtViewer::initializeGL () {
87
88 InitializeGLView ();
89
90 printf("G4OpenGLStoredQtViewer::InitialiseGL () 1\n");
91
92 // clear the buffers and window.
93 ClearView ();
94 // printf("G4OpenGLStoredQtViewer::InitialiseGL () 2\n");
95 FinishView ();
96
97 glDepthFunc (GL_LEQUAL);
98 glDepthMask (GL_TRUE);
99
100 hasToRepaint =true;
101
102 printf("G4OpenGLStoredQtViewer::InitialiseGL -------------------------------------------------------------------------------------\n");
103}
104
105
106void G4OpenGLStoredQtViewer::DrawView () {
107
108 printf("G4OpenGLStoredQtViewer::DrawView %d %d VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV\n",WinSize_x, WinSize_y);
109 printf("G4OpenGLStoredQtViewer::DrawView Dialog adress : %d\n",GLWindow);
110 G4ViewParameters::DrawingStyle style = GetViewParameters().GetDrawingStyle();
111
112 //Make sure current viewer is attached and clean...
113 //Qt version needed
114 glViewport (0, 0, WinSize_x, WinSize_y);
115
116 //See if things have changed from last time and remake if necessary...
117 // The fNeedKernelVisit flag might have been set by the user in
118 // /vis/viewer/rebuild, but if not, make decision and set flag only
119 // if necessary...
120 if (!fNeedKernelVisit)
121
122 if (!fNeedKernelVisit) KernelVisitDecision ();
123
124 G4bool kernelVisitWasNeeded = fNeedKernelVisit; // Keep (ProcessView resets).
125 ProcessView ();
126
127
128 if(style!=G4ViewParameters::hlr &&
129 haloing_enabled) {
130 printf("G4OpenGLStoredQtViewer::DrawView DANS LE IF\n");
131
132 HaloingFirstPass ();
133 DrawDisplayLists ();
134 glFlush ();
135
136 HaloingSecondPass ();
137
138 DrawDisplayLists ();
139 FinishView ();
140
141 } else {
142 printf("*************************** CASE 1 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \n");
143
144 // If kernel visit was needed, drawing and FinishView will already
145 // have been done, so...
146 if (!kernelVisitWasNeeded) {
147 printf("*************************** CASE 2 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \n");
148 DrawDisplayLists ();
149 FinishView ();
150 } else {
151 printf("*************************** CASE 3 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \n");
152 // However, union cutaways are implemented in DrawDisplayLists, so make
153 // an extra pass...
154 if (fVP.IsCutaway() &&
155 fVP.GetCutawayMode() == G4ViewParameters::cutawayUnion) {
156 ClearView();
157 DrawDisplayLists ();
158 FinishView ();
159 printf("*************************** CASE 4 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \n");
160 } else { // ADD TO AVOID KernelVisit=1 and nothing to display
161 DrawDisplayLists ();
162 FinishView ();
163 }
164 }
165 }
166
167 printf("G4OpenGLStoredQtViewer::DrawView %d %d ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \n",WinSize_x, WinSize_y);
168 hasToRepaint =true;
169}
170
171
172//////////////////////////////////////////////////////////////////////////////
173void G4OpenGLStoredQtViewer::FinishView (
174)
175//////////////////////////////////////////////////////////////////////////////
176//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
177{
178 printf("G4OpenGLStoredQtViewer::FinishView VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV\n");
179
180 glFlush ();
181 swapBuffers ();
182 printf("G4OpenGLStoredQtViewer::FinishView ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \n");
183
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 glViewport(0, 0, aWidth, aHeight);
195 glMatrixMode(GL_PROJECTION);
196 glMatrixMode(GL_MODELVIEW);
197
198 if (((WinSize_x != (G4int)aWidth)) || (WinSize_y != (G4int) aHeight)) {
199 hasToRepaint =true;
200 }
201 WinSize_x = (G4int) aWidth;
202 WinSize_y = (G4int) aHeight;
203
204 printf("G4OpenGLStoredQtViewer::resizeGL ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ %d %d=%d %d=%d\n",hasToRepaint,width(),aWidth,height(),aHeight);
205}
206
207
208
209void G4OpenGLStoredQtViewer::paintGL()
210 {
211 if (!readyToPaint) {
212 printf("G4OpenGLStoredQtViewer::paintGL ============ Not ready %d\n",readyToPaint);
213 readyToPaint= true;
214 return;
215 }
216 // DO NOT RESIZE IF SIZE HAS NOT CHANGE :
217 // WHEN CLICK ON THE FRAME FOR EXAMPLE
218 // EXECEPT WHEN MOUSE MOVE EVENT
219 if ( !hasToRepaint) {
220 if (((WinSize_x == (G4int)width())) &&(WinSize_y == (G4int) height())) {
221 printf("G4OpenGLStoredQtViewer::paintGL ============ Dont repaint\n");
222 return;
223 }
224 }
225 nbPaint++;
226 printf("G4OpenGLStoredQtViewer::paintGL VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV %d ready %d\n",nbPaint,readyToPaint);
227 WinSize_x = (G4int) width();
228 WinSize_y = (G4int) height();
229
230 glViewport (0, 0, width(), height());
231 // glLoadIdentity();
232
233
234 SetView();
235
236// // printf("before ClearView\n");
237 printf(" ClearView\n");
238
239 ClearView (); //ok, put the background correct
240 DrawView();
241
242 hasToRepaint =false;
243
244 printf("G4OpenGLStoredQtViewer::paintGL ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ %d ready %d\n",nbPaint,readyToPaint);
245 }
246
247void G4OpenGLStoredQtViewer::mousePressEvent(QMouseEvent *event)
248{
249 printf("G4OpenGLStoredQtViewer::mousePressEvent\n");
250 G4MousePressEvent(event->pos());
251}
252
253void G4OpenGLStoredQtViewer::mouseMoveEvent(QMouseEvent *event)
254{
255 G4MouseMoveEvent(event->x(),event->y(),event->buttons());
256 // DrawView();
257}
258
259
260void G4OpenGLStoredQtViewer::contextMenuEvent(QContextMenuEvent *e)
261{
262 manageContextMenuEvent(e);
263}
264
265void G4OpenGLStoredQtViewer::updateQWidget() {
266 hasToRepaint= true;
267 updateGL();
268 hasToRepaint= false;
269}
270
271#endif
Note: See TracBrowser for help on using the repository browser.