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
G4OpenGLStoredQtViewer.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 G4OpenGLStoredQtViewer : a class derived from G4OpenGLQtViewer and
30// G4OpenGLStoredViewer.
31
33
35#include "G4ios.hh"
36#ifdef G4MULTITHREADED
37#include "G4Threading.hh"
38#endif
39#include "G4UIQt.hh"
40
41#include <qapplication.h>
42#include <qtabwidget.h>
43
45(G4OpenGLStoredSceneHandler& sceneHandler,
46 const G4String& name):
47 G4VViewer (sceneHandler, sceneHandler.IncrementViewCount (), name),
48 G4OpenGLViewer (sceneHandler),
49 G4OpenGLQtViewer (sceneHandler),
50 G4OpenGLStoredViewer (sceneHandler), // FIXME : gerer le pb du parent !
52{
53 if (fViewId < 0) return; // In case error in base class instantiation.
54
56
57 // Indicates that the widget has no background, i.e. when the widget receives paint events, the background is not automatically repainted. Note: Unlike WA_OpaquePaintEvent, newly exposed areas are never filled with the background (e.g., after showing a window for the first time the user can see "through" it until the application processes the paint events). This flag is set or cleared by the widget's author.
58 G4QGLWidgetType::setAttribute (Qt::WA_NoSystemBackground);
59
60 setFocusPolicy(Qt::StrongFocus); // enable keybord events
61 fHasToRepaint = false;
62 fPaintEventLock = false;
63 fUpdateGLLock = false;
64}
65
67 // makeCurrent(); // Not sure why this - commented out 12-Apr-2021 JA
68 // this is connect to the Dialog for deleting it properly
69 // when close event.
70 // ((QDialog*)window())->reject();
71}
72
74 makeCurrent();
75
77 CreateMainWindow (this,QString(GetName()));
78
79 glDrawBuffer (GL_BACK);
80
81 // set the good tab active
82 if (G4QGLWidgetType::parentWidget()) {
83 auto *parentTab = dynamic_cast<QTabWidget*> (G4QGLWidgetType::parentWidget()->parent()) ;
84 if (parentTab) {
85 parentTab->setCurrentIndex(parentTab->count()-1);
86 }
87 }
88
90}
91
93
95
96 if (fSceneHandler.GetScene() == 0) {
97 fHasToRepaint =false;
98 } else {
99 fHasToRepaint =true;
100 }
101
102 // Set the component visible
103 // setVisible(true) ;
104
105 // Set jpg as default export format for Qt viewer
107}
108
110{
111 // Identical to G4OpenGLStoredViewer::CompareForKernelVisit except
112 // for checking of VisAttributesModifiers, because
113 // G4OpenGLStoredQtViewer keeps track of its own touchable
114 // modifiers (fTreeItemModels, etc.).
115 if (
116 (lastVP.GetDrawingStyle () != fVP.GetDrawingStyle ()) ||
118 (lastVP.IsAuxEdgeVisible () != fVP.IsAuxEdgeVisible ()) ||
119 (lastVP.IsCulling () != fVP.IsCulling ()) ||
120 (lastVP.IsCullingInvisible () != fVP.IsCullingInvisible ()) ||
121 (lastVP.IsDensityCulling () != fVP.IsDensityCulling ()) ||
122 (lastVP.IsCullingCovered () != fVP.IsCullingCovered ()) ||
123 (lastVP.GetCBDAlgorithmNumber() !=
125 // Note: Section and Cutaway can reveal back-facing faces. If
126 // backface culling is implemented, the image can look strange because
127 // the back-facing faces are not there. For the moment, we have disabled
128 // (commented out) backface culling (it seems not to affect performance -
129 // in fact, performance seems to improve), so there is no problem.
130 (lastVP.IsSection () != fVP.IsSection ()) ||
131 // Section (DCUT) is NOT implemented locally so we need to visit the kernel.
132 // (lastVP.IsCutaway () != fVP.IsCutaway ()) ||
133 // Cutaways are implemented locally so we do not need to visit the kernel.
134 (lastVP.IsExplode () != fVP.IsExplode ()) ||
135 (lastVP.GetNoOfSides () != fVP.GetNoOfSides ()) ||
138 (lastVP.IsMarkerNotHidden () != fVP.IsMarkerNotHidden ()) ||
139 (lastVP.GetDefaultVisAttributes()->GetColour() !=
144 (lastVP.IsPicking () != fVP.IsPicking ()) ||
147 return true;
148
149 // Don't check VisAttributesModifiers if this comparison has been
150 // initiated by a mouse interaction on the scene tree.
151 if (fMouseOnSceneTree) {
152 // Reset the flag.
153 fMouseOnSceneTree = false;
154 } else {
155 // Not initiated by a mouse so compare for kernel visit.
157 return true;
158 }
159 }
160
161 if (lastVP.IsDensityCulling () &&
162 (lastVP.GetVisibleDensity () != fVP.GetVisibleDensity ()))
163 return true;
164
165// /**************************************************************
166// If section (DCUT) is implemented locally, comment this out.
167 if (lastVP.IsSection () &&
168 (lastVP.GetSectionPlane () != fVP.GetSectionPlane ()))
169 return true;
170// ***************************************************************/
171
172 /**************************************************************
173 If cutaways are implemented locally, comment this out.
174 if (lastVP.IsCutaway ()) {
175 if (vp.GetCutawayMode() != fVP.GetCutawayMode()) return true;
176 if (lastVP.GetCutawayPlanes ().size () !=
177 fVP.GetCutawayPlanes ().size ()) return true;
178 for (size_t i = 0; i < lastVP.GetCutawayPlanes().size(); ++i)
179 if (lastVP.GetCutawayPlanes()[i] != fVP.GetCutawayPlanes()[i])
180 return true;
181 }
182 ***************************************************************/
183
184 if (lastVP.GetCBDAlgorithmNumber() > 0) {
185 if (lastVP.GetCBDParameters().size() != fVP.GetCBDParameters().size()) return true;
186 else if (lastVP.GetCBDParameters() != fVP.GetCBDParameters()) return true;
187 }
188
189 if (lastVP.IsExplode () &&
190 (lastVP.GetExplodeFactor () != fVP.GetExplodeFactor ()))
191 return true;
192
193 if (lastVP.IsSpecialMeshRendering() &&
195 return true;
196
197 return false;
198}
199
201{
202 return isTouchableVisible((int)POListIndex);
203}
204
206{
207 return true;
208}
209
213
214void G4OpenGLStoredQtViewer::ComputeView () {
215
216 makeCurrent();
218
219 //Make sure current viewer is attached and clean...
220
221 //See if things have changed from last time and remake if necessary...
222 // The fNeedKernelVisit flag might have been set by the user in
223 // /vis/viewer/rebuild, but if not, make decision and set flag only
224 // if necessary...
225 if (!fNeedKernelVisit) {
227 }
228 fLastVP = fVP;
229 G4bool kernelVisitWasNeeded = fNeedKernelVisit; // Keep (ProcessView resets).
230 ProcessView ();
231
232 if (kernelVisitWasNeeded) {
234 }
235
236 if(dstyle!=G4ViewParameters::hlr &&
238
241 glFlush ();
242
244
246 FinishView ();
247
248 } else {
249
250 // If kernel visit was needed, drawing and FinishView will already
251 // have been done, so...
252 if (!kernelVisitWasNeeded) {
254 FinishView ();
255 } else {
256 // However, union cutaways are implemented in DrawDisplayLists, so make
257 // an extra pass...
258 if (fVP.IsCutaway() &&
260 ClearView();
262 FinishView ();
263 } else { // ADD TO AVOID KernelVisit=1 and nothing to display
265 FinishView ();
266 }
267 }
268 }
269
270 if (isRecording()) {
272 }
273
274 fHasToRepaint = true;
275}
276
277
278/**
279 - Lors du resize de la fenetre, on doit non pas redessiner le detecteur, mais aussi les evenements
280*/
282 int aWidth
283 ,int aHeight)
284{
285 // Set new size, it will be update when next Repaint()->SetView() called
286 if ((aWidth > 0) && (aHeight > 0)) {
287 ResizeWindow(aWidth,aHeight);
289 }
290}
291
292
293// We have to get several case :
294// - Only activate the windows (mouse click for example) -> Do not redraw
295// - resize window -> redraw
296// - try to avoid recompute everything if we do not rescale picture (side is the same)
297
299{
301
302 if (fPaintEventLock) {
303// return ;
304 }
305 fPaintEventLock = true;
306 if ((getWinWidth() == 0) && (getWinHeight() == 0)) {
307 return;
308 }
309
311 fPaintEventLock = false;
312 return;
313 }
314 // DO NOT RESIZE IF SIZE HAS NOT CHANGE :
315 // WHEN CLICK ON THE FRAME FOR EXAMPLE
316 // EXECEPT WHEN MOUSE MOVE EVENT
317 if ( !fHasToRepaint) {
318 // L. Garnier : Trap to get the size with mac OSX 10.6 and Qt 4.6(devel)
319 // Tested on Qt4.5 on mac, 4.4 on windows, 4.5 on unbuntu
320 int sw = 0;
321 int sh = 0;
322 if (!isMaximized() && !isFullScreen()) {
323 sw = normalGeometry().width();
324 sh = normalGeometry().height();
325 } else {
326 sw = frameGeometry().width();
327 sh = frameGeometry().height();
328 }
329 if ((getWinWidth() == (unsigned int)sw) &&(getWinHeight() == (unsigned int)sh)) {
330 return;
331 }
332 }
333 // Ensure that we really draw the BACK buffer
334 glDrawBuffer (GL_BACK);
335
336 SetView();
337
338 ClearView (); //ok, put the background correct
339 ComputeView();
340
341 fHasToRepaint = false;
342
343 fPaintEventLock = false;
344}
345
348 return;
349 }
350 // Force a repaint next time if the FRAMEBUFFER is not READY
352 if ( fHasToRepaint) {
353 // Will really update the widget by calling CGLFlushDrawable
354 // The widget's rendering context will become the current context and initializeGL()
355 // will be called if it hasn't already been called.
356 // Copies the back buffer of a double-buffered context to the front buffer.
357#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
358 updateGL();
359#else
360 // Not sure this is correct....
361 paintGL();
362#endif
363 }
364}
365
367{
368 G4MousePressEvent(event);
369}
370
372{
373 G4keyPressEvent(event);
374}
375
377{
378 G4keyReleaseEvent(event);
379}
380
381void G4OpenGLStoredQtViewer::wheelEvent (QWheelEvent * event)
382{
383 G4wheelEvent(event);
384}
385
387{
389 fHasToRepaint = true;
390 }
391}
392
393/**
394 * This function was build in order to make a zoom on double clic event.
395 * It was think to build a rubberband on the zoom area, but never work fine
396 */
401
403{
404 G4MouseReleaseEvent(event);
405}
406
408{
409 G4MouseMoveEvent(event);
410}
411
412
414{
416}
417
419 if (fUpdateGLLock) {
420 return;
421 }
422
423 if (! isCurrentWidget()){
424 return;
425 }
426
427 fUpdateGLLock = true;
428 fHasToRepaint= true;
429 // Will really update the widget by calling CGLFlushDrawable
430 // The widget's rendering context will become the current context and initializeGL()
431 // will be called if it hasn't already been called.
432 // Copies the back buffer of a double-buffered context to the front buffer.
433 repaint(); // will read scene tree state
434 // updateGL() // From J.Allison picking branch
437 fUpdateGLLock = false;
438}
439
441)
442//////////////////////////////////////////////////////////////////////////////
443//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
444{
445 // glFlush (); // Tentativley offered by JA 29/04/16.
446
447 // Some X servers fail to draw all trajectories, particularly Mac
448 // XQuartz. Revisit this at a future date. Meanwhile, issue an
449 // extra...
450 // ClearView(); // Necessary? JA 29/04/16
451 // DrawView(); // Necessary? JA 29/04/16
452 activateWindow();
453 // glFlush(); // NO NEED and as drawView will already cause a flush
454 // that could do a double flush
455
456}
457
458
460G4Colour& c,
461size_t poIndex) {
462 c = getColorForPoIndex((int)poIndex);
463}
QOpenGLWidget G4QGLWidgetType
bool G4bool
Definition G4Types.hh:86
void G4MouseReleaseEvent(QMouseEvent *evnt)
void G4MouseMoveEvent(QMouseEvent *event)
void G4keyPressEvent(QKeyEvent *event)
void updateViewerPropertiesTableWidget()
void G4MousePressEvent(QMouseEvent *event)
void G4wheelEvent(QWheelEvent *event)
bool isTouchableVisible(int POindex)
void G4manageContextMenuEvent(QContextMenuEvent *e)
void updateToolbarAndMouseContextMenu()
void G4keyReleaseEvent(QKeyEvent *event)
virtual void CreateMainWindow(G4QGLWidgetType *, const QString &)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
G4Colour getColorForPoIndex(int poIndex)
void keyReleaseEvent(QKeyEvent *event)
void mouseReleaseEvent(QMouseEvent *event)
G4bool CompareForKernelVisit(G4ViewParameters &)
G4OpenGLStoredQtViewer(G4OpenGLStoredSceneHandler &scene, const G4String &name="")
void mouseDoubleClickEvent(QMouseEvent *event)
G4bool TOSelected(size_t TOListIndex)
void mousePressEvent(QMouseEvent *event)
void keyPressEvent(QKeyEvent *event)
void paintEvent(QPaintEvent *event)
void mouseMoveEvent(QMouseEvent *event)
void wheelEvent(QWheelEvent *event)
void showEvent(QShowEvent *event)
G4bool POSelected(size_t POListIndex)
void DisplayTimePOColourModification(G4Colour &, size_t)
void contextMenuEvent(QContextMenuEvent *e)
void ShowView()
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
void resizeGL(int width, int height)
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
G4bool fNeedKernelVisit
Definition G4VViewer.hh:266
const G4ViewParameters & GetViewParameters() const
void ProcessView()
Definition G4VViewer.cc:108
G4VSceneHandler & fSceneHandler
Definition G4VViewer.hh:253
G4int fViewId
Definition G4VViewer.hh:254
G4ViewParameters fVP
Definition G4VViewer.hh:257
const std::vector< G4ModelingParameters::VisAttributesModifier > & GetVisAttributesModifiers() const
G4int GetNoOfSides() const
G4bool IsSpecialMeshRendering() const
CutawayMode GetCutawayMode() const
G4double GetExplodeFactor() const
G4int GetNumberOfCloudPoints() const
G4bool IsMarkerNotHidden() const
G4double GetGlobalLineWidthScale() const
G4bool IsCutaway() const
const G4Colour & GetBackgroundColour() const
G4bool IsSection() const
G4bool IsPicking() const
G4bool IsCulling() const
const G4VisAttributes * GetDefaultTextVisAttributes() const
G4bool IsExplode() const
const std::vector< G4double > & GetCBDParameters() const
G4int GetCBDAlgorithmNumber() const
const std::vector< G4ModelingParameters::PVNameCopyNo > & GetSpecialMeshVolumes() const
G4double GetGlobalMarkerScale() const
G4bool IsCullingInvisible() const
const G4VisAttributes * GetDefaultVisAttributes() const
G4bool IsDensityCulling() const
G4double GetVisibleDensity() const
SMROption GetSpecialMeshRenderingOption() const
G4bool IsCullingCovered() const
const G4Plane3D & GetSectionPlane() const
DrawingStyle GetDrawingStyle() const
G4bool IsAuxEdgeVisible() const
const G4Colour & GetColour() const