Geant4-11
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//
28//
29// Class G4OpenGLImmediateQtViewer : a class derived from G4OpenGLQtViewer and
30// G4OpenGLImmediateViewer.
31
34
35#include "G4ios.hh"
36#ifdef G4MULTITHREADED
37#include "G4Threading.hh"
38#endif
39#include <qapplication.h>
40#include <qtabwidget.h>
41
42#ifdef G4OPENGL_VERSION_2
43#include <qglshaderprogram.h>
44#endif
45
46
49 const G4String& name):
50 G4VViewer (sceneHandler, sceneHandler.IncrementViewCount (), name),
51 G4OpenGLViewer (sceneHandler),
52 G4OpenGLQtViewer (sceneHandler),
53 G4OpenGLImmediateViewer (sceneHandler)
54{
56
57 setFocusPolicy(Qt::StrongFocus); // enable keybord events
58 fHasToRepaint = false;
59 fPaintEventLock = false;
60
61 // Create a new drawer
62 // register the QtDrawer to the OpenGLViewer
63#ifdef G4OPENGL_VERSION_2
64 setVboDrawer(new G4OpenGLVboDrawer(this,"OGL-VBO"));
65#endif
66
67 fUpdateGLLock = false;
68
69 if (fViewId < 0) return; // In case error in base class instantiation.
70}
71
73 // makeCurrent(); // Not sure why this - commented out 12-Apr-2021 JA
74}
75
77 makeCurrent();
78
80 CreateMainWindow (this,QString(GetName()));
81
82 glDrawBuffer (GL_BACK);
83
84 // set the good tab active
85 if (QGLWidget::parentWidget()) {
86 QTabWidget *parentTab = dynamic_cast<QTabWidget*> (QGLWidget::parentWidget()->parent()) ;
87 if (parentTab) {
88 parentTab->setCurrentIndex(parentTab->count()-1);
89 }
90 }
91
93}
94
96
97#ifndef G4OPENGL_VERSION_2
99#else
100 QGLShaderProgram *aQGLShaderProgram = new QGLShaderProgram (context());
101 fShaderProgram = aQGLShaderProgram->programId ();
102
103 aQGLShaderProgram->addShaderFromSourceCode(QGLShader::Vertex,
104 fVboDrawer->getVertexShaderSrc());
105
106 aQGLShaderProgram->addShaderFromSourceCode(QGLShader::Fragment,
107 fVboDrawer->getFragmentShaderSrc());
108
109 aQGLShaderProgram->link();
110 aQGLShaderProgram->bind();
111
112 fVertexPositionAttribute = glGetAttribLocation(fShaderProgram, "aVertexPosition");
113 fcMatrixUniform = glGetUniformLocation(fShaderProgram, "uCMatrix");
114 fpMatrixUniform = glGetUniformLocation(fShaderProgram, "uPMatrix");
115 ftMatrixUniform = glGetUniformLocation(fShaderProgram, "uTMatrix");
116 fmvMatrixUniform = glGetUniformLocation(fShaderProgram, "uMVMatrix");
117
118 // Load identity at beginning
119 float identity[16] = {
120 1.0f, 0, 0, 0,
121 0, 1.0f, 0, 0,
122 0, 0, 1.0f, 0,
123 0, 0, 0, 1.0f
124 };
125 glUniformMatrix4fv (fcMatrixUniform, 1, 0, identity);
126 glUniformMatrix4fv (fpMatrixUniform, 1, 0, identity);
127 glUniformMatrix4fv (ftMatrixUniform, 1, 0, identity);
128 glUniformMatrix4fv(fmvMatrixUniform, 1, 0, identity);
129
130 glUseProgram(fShaderProgram);
131
132#endif
133
134 // If a double buffer context has been forced upon us, ignore the
135 // back buffer for this OpenGLImmediate view.
136 // glDrawBuffer (GL_FRONT); // FIXME : Ne marche pas avec cette ligne, mais affiche le run correctement...
137
138 if (fSceneHandler.GetScene() == 0) {
139 fHasToRepaint =false;
140 } else {
141 fHasToRepaint =true;
142 }
143
144 // Set the component visible
145
146 // and update it immediatly before wait for SessionStart() (batch mode)
147// QCoreApplication::sendPostedEvents () ;
148
149 // Set jpg as default export format for Qt viewer
151}
152
153
155#ifdef G4MULTITHREADED
158 }
159#else
161#endif
162}
163
164
166
167 makeCurrent();
168 // If a double buffer context has been forced upon us, ignore the
169 // back buffer for this OpenGLImmediate view.
170 // glDrawBuffer (GL_FRONT);
171
173
174 if(dstyle!=G4ViewParameters::hlr &&
176
179 ProcessView ();
180 FinishView();
182
183 }
184
185 NeedKernelVisit (); // Always need to visit G4 kernel.
186 ProcessView ();
187
188 if (isRecording()) {
190 }
191
192 fHasToRepaint = true;
193}
194
199 int aWidth
200,int aHeight)
201{
202 if ((aWidth > 0) && (aHeight > 0)) {
203 ResizeWindow(aWidth,aHeight);
205 }
206}
207
208
210{
212
213 if (fPaintEventLock) {
214// return ;
215 }
217 fPaintEventLock = false;
218 return;
219 }
220 if ((getWinWidth() == 0) && (getWinHeight() == 0)) {
221 return;
222 }
223
224 // DO NOT RESIZE IF SIZE HAS NOT CHANGE
225 if ( !fHasToRepaint) {
226 // L. Garnier : Trap to get the size with mac OSX 10.6 and Qt 4.6(devel)
227 // Tested on Qt4.5 on mac, 4.4 on windows, 4.5 on unbuntu
228 int sw = 0;
229 int sh = 0;
230 if (!isMaximized() && !isFullScreen()) {
231 sw = normalGeometry().width();
232 sh = normalGeometry().height();
233 } else {
234 sw = frameGeometry().width();
235 sh = frameGeometry().height();
236 }
237 if ((getWinWidth() == (unsigned int)sw) &&(getWinHeight() == (unsigned int)sh)) {
238 return;
239
240 } else if ((sw == 0) && (sh == 0)) { // NOT A TOP LEVEL WIDGET
241 if (((getWinWidth() == (unsigned int)width())) &&(getWinHeight() == (unsigned int) height())) {
242 return;
243 }
244 }
245 }
246
247 SetView();
248
249 ClearView (); //ok, put the background correct
250 ComputeView();
251
252 fHasToRepaint = false; // could be set to false by ComputeView
253
254 fPaintEventLock = false;
255}
256
258{
259 G4MousePressEvent(event);
260}
261
263{
264 G4keyPressEvent(event);
265}
266
268{
269 G4keyReleaseEvent(event);
270}
271
273{
274 G4wheelEvent(event);
275}
276
278{
280 fHasToRepaint = true;
281 }
282}
283
284
290{
292}
293
295{
296 G4MouseReleaseEvent(event);
297}
298
300{
301 G4MouseMoveEvent(event);
302}
303
304
306{
308}
309
312 return;
313 }
314 // Force a repaint next time if the FRAMEBUFFER is not READY
316 if ( fHasToRepaint) {
317 updateGL();
318 }
319}
320
321
323 if (fUpdateGLLock) {
324 return;
325 }
326
327 if (! isCurrentWidget()){
328 return;
329 }
330
331 fUpdateGLLock = true;
332 fHasToRepaint= true;
333 repaint();
336 fUpdateGLLock= false;
337}
338
339
341)
342
344{
345 fHasToRepaint = true;
346 activateWindow();
347}
void resizeGL(int width, int height)
void keyPressEvent(QKeyEvent *event)
void paintEvent(QPaintEvent *event)
void mouseMoveEvent(QMouseEvent *event)
void mousePressEvent(QMouseEvent *event)
void wheelEvent(QWheelEvent *event)
void mouseDoubleClickEvent(QMouseEvent *event)
G4OpenGLImmediateQtViewer(G4OpenGLImmediateSceneHandler &scene, const G4String &name="")
void mouseReleaseEvent(QMouseEvent *event)
void keyReleaseEvent(QKeyEvent *event)
void ShowView()
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
void contextMenuEvent(QContextMenuEvent *e)
void G4MouseReleaseEvent(QMouseEvent *evnt)
void G4MouseMoveEvent(QMouseEvent *event)
void G4keyPressEvent(QKeyEvent *event)
void updateViewerPropertiesTableWidget()
void G4MousePressEvent(QMouseEvent *event)
void G4wheelEvent(QWheelEvent *event)
void G4manageContextMenuEvent(QContextMenuEvent *e)
void updateToolbarAndMouseContextMenu()
void G4keyReleaseEvent(QKeyEvent *event)
virtual void CreateMainWindow(QGLWidget *, const QString &)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
bool setExportImageFormat(std::string format, bool quiet=false)
unsigned int getWinHeight() const
void ResizeWindow(unsigned int, unsigned int)
unsigned int getWinWidth() const
G4bool isFramebufferReady()
G4bool sizeHasChanged()
void HaloingSecondPass()
G4Scene * GetScene() const
const G4String & GetName() const
const G4ViewParameters & GetViewParameters() const
G4VSceneHandler & fSceneHandler
Definition: G4VViewer.hh:215
void NeedKernelVisit()
Definition: G4VViewer.cc:78
G4int fViewId
Definition: G4VViewer.hh:216
DrawingStyle GetDrawingStyle() const
const char * name(G4int ptype)
G4int G4GetThreadId()
Definition: G4Threading.cc:122
context
Definition: g4zmq.py:11