Geant4_10
G4OpenGLImmediateQtViewer.cc
Go to the documentation of this file.
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 66373 2012-12-18 09:41:34Z gcosmo $
28 //
29 //
30 // Class G4OpenGLImmediateQtViewer : a class derived from G4OpenGLQtViewer and
31 // G4OpenGLImmediateViewer.
32 
33 #ifdef G4VIS_BUILD_OPENGLQT_DRIVER
34 
37 
38 #include "G4ios.hh"
39 
40 #include <qapplication.h>
41 
42 G4OpenGLImmediateQtViewer::G4OpenGLImmediateQtViewer
43 (G4OpenGLImmediateSceneHandler& sceneHandler,
44  const G4String& name):
45  G4VViewer (sceneHandler, sceneHandler.IncrementViewCount (), name),
46  G4OpenGLViewer (sceneHandler),
47  G4OpenGLQtViewer (sceneHandler),
48  G4OpenGLImmediateViewer (sceneHandler)
49 {
50 
51  setFocusPolicy(Qt::StrongFocus); // enable keybord events
52  fHasToRepaint = false;
53  fIsRepainting = false;
54 
55  resize(fVP.GetWindowSizeHintX(),fVP.GetWindowSizeHintY());
56 
57  if (fViewId < 0) return; // In case error in base class instantiation.
58 }
59 
60 G4OpenGLImmediateQtViewer::~G4OpenGLImmediateQtViewer() {
61  makeCurrent();
62 }
63 
64 void G4OpenGLImmediateQtViewer::Initialise() {
65 #ifdef G4DEBUG_VIS_OGL
66  printf("G4OpenGLImmediateQtViewer::Initialise \n");
67 #endif
68  fReadyToPaint = false;
69  CreateMainWindow (this,QString(GetName()));
70  CreateFontLists ();
71 
72  fReadyToPaint = true;
73 }
74 
75 void G4OpenGLImmediateQtViewer::initializeGL () {
76 
77  InitializeGLView ();
78 
79  // If a double buffer context has been forced upon us, ignore the
80  // back buffer for this OpenGLImmediate view.
81  // glDrawBuffer (GL_FRONT); // FIXME : Ne marche pas avec cette ligne, mais affiche le run correctement...
82 
83  if (fSceneHandler.GetScene() == 0) {
84  fHasToRepaint =false;
85  } else {
86  fHasToRepaint =true;
87  }
88 
89  // Set the component visible
90  setVisible(true) ;
91 
92  // and update it immediatly before wait for SessionStart() (batch mode)
93  QCoreApplication::sendPostedEvents () ;
94 }
95 
96 
97 void G4OpenGLImmediateQtViewer::DrawView() {
98  updateQWidget();
99 }
100 
101 
102 void G4OpenGLImmediateQtViewer::ComputeView () {
103 
104 #ifdef G4DEBUG_VIS_OGL
105  printf("G4OpenGLImmediateQtViewer::ComputeView %d %d VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV\n",getWinWidth(), getWinHeight());
106 #endif
107  makeCurrent();
108  // If a double buffer context has been forced upon us, ignore the
109  // back buffer for this OpenGLImmediate view.
110  // glDrawBuffer (GL_FRONT);
111 
112  G4ViewParameters::DrawingStyle dstyle = GetViewParameters().GetDrawingStyle();
113 
114  if(dstyle!=G4ViewParameters::hlr &&
115  haloing_enabled) {
116 
117  HaloingFirstPass ();
118  NeedKernelVisit ();
119  ProcessView ();
120  FinishView();
121 #ifdef G4DEBUG_VIS_OGL
122  printf("G4OpenGLImmediateQtViewer::ComputeView First ProcessView ok\n");
123 #endif
124  HaloingSecondPass ();
125 
126  }
127 
128  NeedKernelVisit (); // Always need to visit G4 kernel.
129  ProcessView ();
130 
131  if (isRecording()) {
132  savePPMToTemp();
133  }
134 
135 #ifdef G4DEBUG_VIS_OGL
136  printf("G4OpenGLImmediateQtViewer::ComputeView %d %d ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \n",getWinWidth(), getWinHeight());
137 #endif
138  fHasToRepaint = true;
139 }
140 
144 void G4OpenGLImmediateQtViewer::resizeGL(
145  int aWidth
146 ,int aHeight)
147 {
148  if ((aWidth > 0) && (aHeight > 0)) {
149  ResizeWindow(aWidth,aHeight);
150  fHasToRepaint = sizeHasChanged();
151  }
152 }
153 
154 
155 void G4OpenGLImmediateQtViewer::paintGL()
156 {
157  updateToolbarAndMouseContextMenu();
158 
159  if (fIsRepainting) {
160  // return ;
161  }
162  if (!fReadyToPaint) {
163  fReadyToPaint= true;
164  return;
165  }
166  if ((getWinWidth() == 0) && (getWinHeight() == 0)) {
167  return;
168  }
169 
170  // DO NOT RESIZE IF SIZE HAS NOT CHANGE
171  if ( !fHasToRepaint) {
172  // L. Garnier : Trap to get the size with mac OSX 10.6 and Qt 4.6(devel)
173  // Tested on Qt4.5 on mac, 4.4 on windows, 4.5 on unbuntu
174  int sw = 0;
175  int sh = 0;
176  if (!isMaximized() && !isFullScreen()) {
177  sw = normalGeometry().width();
178  sh = normalGeometry().height();
179  } else {
180  sw = frameGeometry().width();
181  sh = frameGeometry().height();
182  }
183  if ((getWinWidth() == (unsigned int)sw) &&(getWinHeight() == (unsigned int)sh)) {
184  return;
185 
186  } else if ((sw == 0) && (sh == 0)) { // NOT A TOP LEVEL WIDGET
187  if (((getWinWidth() == (unsigned int)width())) &&(getWinHeight() == (unsigned int) height())) {
188  return;
189  }
190  }
191  }
192 #ifdef G4DEBUG_VIS_OGL
193  printf("G4OpenGLImmediateQtViewer::paintGL VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV ready %d\n",fReadyToPaint);
194 #endif
195 
196  SetView();
197 
198  ClearView (); //ok, put the background correct
199  ComputeView();
200 
201  fHasToRepaint = false; // could be set to false by ComputeView
202 
203 #ifdef G4DEBUG_VIS_OGL
204  printf("G4OpenGLImmediateQtViewer::paintGL ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ready %d\n\n\n",fReadyToPaint);
205 #endif
206  fIsRepainting = false;
207 }
208 
209 void G4OpenGLImmediateQtViewer::mousePressEvent(QMouseEvent *event)
210 {
211  G4MousePressEvent(event);
212 }
213 
214 void G4OpenGLImmediateQtViewer::keyPressEvent (QKeyEvent * event)
215 {
216  G4keyPressEvent(event);
217 }
218 
219 void G4OpenGLImmediateQtViewer::wheelEvent (QWheelEvent * event)
220 {
221  G4wheelEvent(event);
222 }
223 
224 void G4OpenGLImmediateQtViewer::showEvent (QShowEvent *)
225 {
226  fHasToRepaint = true;
227 }
228 
229 
234 void G4OpenGLImmediateQtViewer::mouseDoubleClickEvent(QMouseEvent *)
235 {
236  G4MouseDoubleClickEvent();
237 }
238 
239 void G4OpenGLImmediateQtViewer::mouseReleaseEvent(QMouseEvent *)
240 {
241  G4MouseReleaseEvent();
242 }
243 
244 void G4OpenGLImmediateQtViewer::mouseMoveEvent(QMouseEvent *event)
245 {
246  G4MouseMoveEvent(event);
247 }
248 
249 
250 void G4OpenGLImmediateQtViewer::contextMenuEvent(QContextMenuEvent *e)
251 {
252  G4manageContextMenuEvent(e);
253 }
254 
255 void G4OpenGLImmediateQtViewer::paintEvent(QPaintEvent *) {
256  if ( fHasToRepaint) {
257  updateGL();
258  }
259 }
260 
261 
262 void G4OpenGLImmediateQtViewer::updateQWidget() {
263  fHasToRepaint= true;
264  updateGL();
265  repaint();
266  fHasToRepaint= false;
267 }
268 
269 
270 void G4OpenGLImmediateQtViewer::ShowView (
271 )
272 {
275  fHasToRepaint = true;
276  activateWindow();
277 }
278 #endif
#define width
const XML_Char * name
Definition: expat.h:151
printf("%d Experimental points found\n", nlines)