Geant4 11.2.2
Toolkit for the simulation of the passage of particles through matter
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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
45 const G4String& name):
46 G4VViewer (sceneHandler, sceneHandler.IncrementViewCount (), name),
47 G4OpenGLViewer (sceneHandler),
48 G4OpenGLQtViewer (sceneHandler),
49 G4OpenGLImmediateViewer (sceneHandler)
50{
52
53 setFocusPolicy(Qt::StrongFocus); // enable keybord events
54 fHasToRepaint = false;
55 fPaintEventLock = false;
56 fUpdateGLLock = false;
57
58 if (fViewId < 0) return; // In case error in base class instantiation.
59}
60
62 // makeCurrent(); // Not sure why this - commented out 12-Apr-2021 JA
63}
64
66 makeCurrent();
67
69 CreateMainWindow (this,QString(GetName()));
70
71 glDrawBuffer (GL_BACK);
72
73 // set the good tab active
74 if (G4QGLWidgetType::parentWidget()) {
75 auto *parentTab = dynamic_cast<QTabWidget*> (G4QGLWidgetType::parentWidget()->parent()) ;
76 if (parentTab) {
77 parentTab->setCurrentIndex(parentTab->count()-1);
78 }
79 }
80
82}
83
85
87
88 // If a double buffer context has been forced upon us, ignore the
89 // back buffer for this OpenGLImmediate view.
90 // glDrawBuffer (GL_FRONT); // FIXME : Ne marche pas avec cette ligne, mais affiche le run correctement...
91
92 if (fSceneHandler.GetScene() == 0) {
93 fHasToRepaint =false;
94 } else {
95 fHasToRepaint =true;
96 }
97
98 // Set the component visible
99
100 // and update it immediatly before wait for SessionStart() (batch mode)
101// QCoreApplication::sendPostedEvents () ;
102
103 // Set jpg as default export format for Qt viewer
105}
106
107
109#ifdef G4MULTITHREADED
112 }
113#else
115#endif
116}
117
118
119void G4OpenGLImmediateQtViewer::ComputeView () {
120
121 makeCurrent();
122 // If a double buffer context has been forced upon us, ignore the
123 // back buffer for this OpenGLImmediate view.
124 // glDrawBuffer (GL_FRONT);
125
127
128 if(dstyle!=G4ViewParameters::hlr &&
130
133 ProcessView ();
134 FinishView();
136
137 }
138
139 NeedKernelVisit (); // Always need to visit G4 kernel.
140 ProcessView ();
141
142 if (isRecording()) {
144 }
145
146 fHasToRepaint = true;
147}
148
149/**
150 - Lors du resize de la fenetre, on doit non pas redessiner le detecteur, mais aussi les evenements
151*/
153 int aWidth
154,int aHeight)
155{
156 if ((aWidth > 0) && (aHeight > 0)) {
157 ResizeWindow(aWidth,aHeight);
159 }
160}
161
162
164{
166
167 if (fPaintEventLock) {
168// return ;
169 }
171 fPaintEventLock = false;
172 return;
173 }
174 if ((getWinWidth() == 0) && (getWinHeight() == 0)) {
175 return;
176 }
177
178 // DO NOT RESIZE IF SIZE HAS NOT CHANGE
179 if ( !fHasToRepaint) {
180 // L. Garnier : Trap to get the size with mac OSX 10.6 and Qt 4.6(devel)
181 // Tested on Qt4.5 on mac, 4.4 on windows, 4.5 on unbuntu
182 int sw = 0;
183 int sh = 0;
184 if (!isMaximized() && !isFullScreen()) {
185 sw = normalGeometry().width();
186 sh = normalGeometry().height();
187 } else {
188 sw = frameGeometry().width();
189 sh = frameGeometry().height();
190 }
191 if ((getWinWidth() == (unsigned int)sw) &&(getWinHeight() == (unsigned int)sh)) {
192 return;
193
194 } else if ((sw == 0) && (sh == 0)) { // NOT A TOP LEVEL WIDGET
195 if (((getWinWidth() == (unsigned int)width())) &&(getWinHeight() == (unsigned int) height())) {
196 return;
197 }
198 }
199 }
200
201 SetView();
202
203 ClearView (); //ok, put the background correct
204 ComputeView();
205
206 fHasToRepaint = false; // could be set to false by ComputeView
207
208 fPaintEventLock = false;
209}
210
212{
213 G4MousePressEvent(event);
214}
215
217{
218 G4keyPressEvent(event);
219}
220
222{
223 G4keyReleaseEvent(event);
224}
225
227{
228 G4wheelEvent(event);
229}
230
232{
234 fHasToRepaint = true;
235 }
236}
237
238
239/**
240 * This function was build in order to make a zoom on double clic event.
241 * It was think to build a rubberband on the zoom area, but never work fine
242 */
247
249{
250 G4MouseReleaseEvent(event);
251}
252
254{
255 G4MouseMoveEvent(event);
256}
257
258
263
266 return;
267 }
268 // Force a repaint next time if the FRAMEBUFFER is not READY
270 if ( fHasToRepaint) {
271#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
272 updateGL();
273#else
274 // Not sure this is correct....
275 paintGL();
276#endif
277 }
278}
279
280
282 if (fUpdateGLLock) {
283 return;
284 }
285
286 if (! isCurrentWidget()){
287 return;
288 }
289
290 fUpdateGLLock = true;
291 fHasToRepaint= true;
292 repaint();
295 fUpdateGLLock= false;
296}
297
298
300)
301//////////////////////////////////////////////////////////////////////////////
302//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
303{
304 fHasToRepaint = true;
305 activateWindow();
306}
void resizeGL(int width, int height)
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 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(G4QGLWidgetType *, 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()
G4Scene * GetScene() const
const G4String & GetName() const
const G4ViewParameters & GetViewParameters() const
G4VSceneHandler & fSceneHandler
Definition G4VViewer.hh:253
void NeedKernelVisit()
Definition G4VViewer.cc:81
G4int fViewId
Definition G4VViewer.hh:254
DrawingStyle GetDrawingStyle() const
G4int G4GetThreadId()