Geant4 11.4.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
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#include "G4Threading.hh"
37#include "G4UIQt.hh"
38#if 0x060000 <= QT_VERSION
39#include "G4Qt.hh"
40#endif
41
42#include <qapplication.h>
43#include <qtabwidget.h>
44
46(G4OpenGLStoredSceneHandler& sceneHandler,
47 const G4String& name):
48 G4VViewer (sceneHandler, sceneHandler.IncrementViewCount (), name),
49 G4OpenGLViewer (sceneHandler),
50 G4OpenGLQtViewer (sceneHandler),
51 G4OpenGLStoredViewer (sceneHandler), // FIXME : gerer le pb du parent !
52 G4QGLWidgetType()
53{
54 if (fViewId < 0) return; // In case error in base class instantiation.
55
56#if QT_VERSION < 0x060000
58
59 // 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.
60 G4QGLWidgetType::setAttribute (Qt::WA_NoSystemBackground);
61
62 setFocusPolicy(Qt::StrongFocus); // enable keybord events
63 fHasToRepaint = false;
64 fPaintEventLock = false;
65 fUpdateGLLock = false;
66#else
67 // 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.
68 G4QGLWidgetType::setAttribute (Qt::WA_NoSystemBackground);
69
70 setFocusPolicy(Qt::StrongFocus); // enable keybord events
71#endif
72}
73
75
77#if QT_VERSION < 0x060000
78
80 CreateMainWindow (this,QString(GetName()));
81
82 makeCurrent();
83 glDrawBuffer (GL_BACK);
84
85 // set the good tab active
86 if (G4QGLWidgetType::parentWidget()) {
87 auto *parentTab = dynamic_cast<QTabWidget*> (G4QGLWidgetType::parentWidget()->parent()) ;
88 if (parentTab) {
89 parentTab->setCurrentIndex(parentTab->count()-1);
90 }
91 }
92
94#else
95 CreateMainWindow (this,QString(GetName()));
96 // Set jpg as default export format for Qt viewer
98#endif
99}
100
101#if QT_VERSION < 0x060000
103
105
106 if (fSceneHandler.GetScene() == 0) {
107 fHasToRepaint =false;
108 } else {
109 fHasToRepaint =true;
110 }
111
112 // Set the component visible
113 // setVisible(true) ;
114
115 // Set jpg as default export format for Qt viewer
117}
118#endif
119
121{
122 // Identical to G4OpenGLStoredViewer::CompareForKernelVisit except
123 // for checking of VisAttributesModifiers, because
124 // G4OpenGLStoredQtViewer keeps track of its own touchable
125 // modifiers (fTreeItemModels, etc.).
126 if (
127 (lastVP.GetDrawingStyle () != fVP.GetDrawingStyle ()) ||
128 (lastVP.GetNumberOfCloudPoints() != fVP.GetNumberOfCloudPoints()) ||
129 (lastVP.IsAuxEdgeVisible () != fVP.IsAuxEdgeVisible ()) ||
130 (lastVP.IsCulling () != fVP.IsCulling ()) ||
131 (lastVP.IsCullingInvisible () != fVP.IsCullingInvisible ()) ||
132 (lastVP.IsDensityCulling () != fVP.IsDensityCulling ()) ||
133 (lastVP.IsCullingCovered () != fVP.IsCullingCovered ()) ||
134 (lastVP.GetCBDAlgorithmNumber() !=
135 fVP.GetCBDAlgorithmNumber()) ||
136 // Note: Section and Cutaway can reveal back-facing faces. If
137 // backface culling is implemented, the image can look strange because
138 // the back-facing faces are not there. For the moment, we have disabled
139 // (commented out) backface culling (it seems not to affect performance -
140 // in fact, performance seems to improve), so there is no problem.
141 (lastVP.IsSection () != fVP.IsSection ()) ||
142 // Section (DCUT) is NOT implemented locally so we need to visit the kernel.
143 // (lastVP.IsCutaway () != fVP.IsCutaway ()) ||
144 // Cutaways are implemented locally so we do not need to visit the kernel.
145 (lastVP.IsExplode () != fVP.IsExplode ()) ||
146 (lastVP.GetNoOfSides () != fVP.GetNoOfSides ()) ||
147 (lastVP.GetGlobalMarkerScale() != fVP.GetGlobalMarkerScale()) ||
148 (lastVP.GetGlobalLineWidthScale() != fVP.GetGlobalLineWidthScale()) ||
149 (lastVP.IsMarkerNotHidden () != fVP.IsMarkerNotHidden ()) ||
150 (lastVP.GetDefaultVisAttributes()->GetColour() !=
151 fVP.GetDefaultVisAttributes()->GetColour()) ||
153 fVP.GetDefaultTextVisAttributes()->GetColour()) ||
154 (lastVP.GetBackgroundColour ()!= fVP.GetBackgroundColour ())||
155 (lastVP.IsPicking () != fVP.IsPicking ()) ||
156 (lastVP.IsSpecialMeshRendering() != fVP.IsSpecialMeshRendering()) ||
157 (lastVP.GetSpecialMeshRenderingOption() != fVP.GetSpecialMeshRenderingOption()) ||
158 (lastVP.GetTransparencyByDepth() != fVP.GetTransparencyByDepth()) ||
159 (lastVP.IsDotsSmooth() != fVP.IsDotsSmooth()) ||
160 (lastVP.GetDotsSize() != fVP.GetDotsSize())
161 )
162 return true;
163
164 // Don't check VisAttributesModifiers if this comparison has been
165 // initiated by a mouse interaction on the scene tree.
166 if (fMouseOnSceneTree) {
167 // Reset the flag.
168 fMouseOnSceneTree = false;
169 } else {
170 // Not initiated by a mouse so compare for kernel visit.
171 if (lastVP.GetVisAttributesModifiers() != fVP.GetVisAttributesModifiers()) {
172 return true;
173 }
174 }
175
176 if (lastVP.IsDensityCulling () &&
177 (lastVP.GetVisibleDensity () != fVP.GetVisibleDensity ()))
178 return true;
179
180// /**************************************************************
181// If section (DCUT) is implemented locally, comment this out.
182 if (lastVP.IsSection () &&
183 (lastVP.GetSectionPlane () != fVP.GetSectionPlane ()))
184 return true;
185// ***************************************************************/
186
187 /**************************************************************
188 If cutaways are implemented locally, comment this out.
189 if (lastVP.IsCutaway ()) {
190 if (vp.GetCutawayMode() != fVP.GetCutawayMode()) return true;
191 if (lastVP.GetCutawayPlanes ().size () !=
192 fVP.GetCutawayPlanes ().size ()) return true;
193 for (size_t i = 0; i < lastVP.GetCutawayPlanes().size(); ++i)
194 if (lastVP.GetCutawayPlanes()[i] != fVP.GetCutawayPlanes()[i])
195 return true;
196 }
197 ***************************************************************/
198
199 if (lastVP.GetCBDAlgorithmNumber() > 0) {
200 if (lastVP.GetCBDParameters().size() != fVP.GetCBDParameters().size()) return true;
201 else if (lastVP.GetCBDParameters() != fVP.GetCBDParameters()) return true;
202 }
203
204 if (lastVP.IsExplode () &&
205 (lastVP.GetExplodeFactor () != fVP.GetExplodeFactor ()))
206 return true;
207
208 if (lastVP.IsSpecialMeshRendering() &&
209 (lastVP.GetSpecialMeshVolumes() != fVP.GetSpecialMeshVolumes()))
210 return true;
211
212 if (lastVP.GetTransparencyByDepth() > 0. &&
213 lastVP.GetTransparencyByDepthOption() != fVP.GetTransparencyByDepthOption())
214 return true;
215
216 return false;
217}
218
220{
221 return isTouchableVisible((int)POListIndex);
222}
223
225{
226 return true;
227}
228
230#if QT_VERSION < 0x060000
231#else
232 if(IsGettingPickInfos()) {
233 paintGL();
234 return;
235 }
236#endif
237#if (QT_VERSION < 0x060000) || !defined(G4MULTITHREADED)
239#else
242 } else {
243 update(); //G.Barrand: updateQWidget() induces a crash on run beamOn.
244 }
245#endif
246}
247
248void G4OpenGLStoredQtViewer::ComputeView () {
249
250#if QT_VERSION < 0x060000
251 makeCurrent();
252#endif
253
255
256 //Make sure current viewer is attached and clean...
257
258 //See if things have changed from last time and remake if necessary...
259 // The fNeedKernelVisit flag might have been set by the user in
260 // /vis/viewer/rebuild, but if not, make decision and set flag only
261 // if necessary...
262 if (!fNeedKernelVisit) {
264 }
265 fLastVP = fVP;
266 G4bool kernelVisitWasNeeded = fNeedKernelVisit; // Keep (ProcessView resets).
267 ProcessView ();
268
269 if (kernelVisitWasNeeded) {
271 }
272
273 if(dstyle!=G4ViewParameters::hlr &&
275
278 glFlush ();
279
281
283 FinishView ();
284
285 } else {
286
287 // If kernel visit was needed, drawing and FinishView will already
288 // have been done, so...
289 if (!kernelVisitWasNeeded) {
291 FinishView ();
292 } else {
293 // However, union cutaways are implemented in DrawDisplayLists, so make
294 // an extra pass...
295 if (fVP.IsCutaway() &&
296 fVP.GetCutawayMode() == G4ViewParameters::cutawayUnion) {
297 ClearView();
299 FinishView ();
300 } else { // ADD TO AVOID KernelVisit=1 and nothing to display
302 FinishView ();
303 }
304 }
305 }
306
307 if (isRecording()) {
309 }
310
311#if QT_VERSION < 0x060000
312 fHasToRepaint = true;
313#endif
314}
315
316
317/**
318 - Lors du resize de la fenetre, on doit non pas redessiner le detecteur, mais aussi les evenements
319*/
321 int aWidth
322 ,int aHeight)
323{
324 // Set new size, it will be update when next Repaint()->SetView() called
325 if ((aWidth > 0) && (aHeight > 0)) {
326#if QT_VERSION < 0x060000
327 ResizeWindow(aWidth,aHeight);
329#else
330 ResizeWindow(devicePixelRatio()*aWidth,devicePixelRatio()*aHeight);
331#endif
332 }
333}
334
335
336// We have to get several case :
337// - Only activate the windows (mouse click for example) -> Do not redraw
338// - resize window -> redraw
339// - try to avoid recompute everything if we do not rescale picture (side is the same)
340
342{
343#if QT_VERSION < 0x060000
345#else
346 //G.Barrand: don't do any change in the GUI here, just "paint" this widget!
347#endif
348
349#if QT_VERSION < 0x060000
350 if (fPaintEventLock) {
351// return ;
352 }
353 fPaintEventLock = true;
354 if ((getWinWidth() == 0) && (getWinHeight() == 0)) {
355 return;
356 }
357
359 fPaintEventLock = false;
360 return;
361 }
362
363 // DO NOT RESIZE IF SIZE HAS NOT CHANGE :
364 // WHEN CLICK ON THE FRAME FOR EXAMPLE
365 // EXECEPT WHEN MOUSE MOVE EVENT
366 if ( !fHasToRepaint) {
367 // L. Garnier : Trap to get the size with mac OSX 10.6 and Qt 4.6(devel)
368 // Tested on Qt4.5 on mac, 4.4 on windows, 4.5 on unbuntu
369 int sw = 0;
370 int sh = 0;
371 if (!isMaximized() && !isFullScreen()) {
372 sw = normalGeometry().width();
373 sh = normalGeometry().height();
374 } else {
375 sw = frameGeometry().width();
376 sh = frameGeometry().height();
377 }
378 if ((getWinWidth() == (unsigned int)sw) &&(getWinHeight() == (unsigned int)sh)) {
379 return;
380 }
381 }
382#else
383 if ((getWinWidth() == 0) && (getWinHeight() == 0)) return; //G.Barrand: needed?
384#endif
385
386#if QT_VERSION < 0x060000
387#else
389#endif
390
391 // Ensure that we really draw the BACK buffer
392 glDrawBuffer (GL_BACK);
393
394 SetView();
395
396 ClearView (); //ok, put the background correct
397 ComputeView();
398
399#if QT_VERSION < 0x060000
400 fHasToRepaint = false;
401
402 fPaintEventLock = false;
403#endif
404}
405
406#if QT_VERSION < 0x060000
409 return;
410 }
411 // Force a repaint next time if the FRAMEBUFFER is not READY
413 if ( fHasToRepaint) {
414 // Will really update the widget by calling CGLFlushDrawable
415 // The widget's rendering context will become the current context and initializeGL()
416 // will be called if it hasn't already been called.
417 // Copies the back buffer of a double-buffered context to the front buffer.
418#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
419 updateGL();
420#else
421 // Not sure this is correct....
422 paintGL();
423#endif
424 }
425}
426#endif
427
429{
430 G4MousePressEvent(event);
431}
432
434{
435 G4keyPressEvent(event);
436}
437
439{
440 G4keyReleaseEvent(event);
441}
442
443void G4OpenGLStoredQtViewer::wheelEvent (QWheelEvent * event)
444{
445 G4wheelEvent(event);
446}
447
448#if QT_VERSION < 0x060000
450{
452 fHasToRepaint = true;
453 }
454}
455#endif
456
457/**
458 * This function was build in order to make a zoom on double clic event.
459 * It was think to build a rubberband on the zoom area, but never work fine
460 */
465
467{
468 G4MouseReleaseEvent(event);
469}
470
472{
473 G4MouseMoveEvent(event);
474}
475
476
478{
480}
481
483#if QT_VERSION < 0x060000
484 if (fUpdateGLLock) {
485 return;
486 }
487
488 if (! isCurrentWidget()){
489 return;
490 }
491
492 fUpdateGLLock = true;
493 fHasToRepaint= true;
494 // Will really update the widget by calling CGLFlushDrawable
495 // The widget's rendering context will become the current context and initializeGL()
496 // will be called if it hasn't already been called.
497 // Copies the back buffer of a double-buffered context to the front buffer.
498 repaint(); // will read scene tree state
499 // updateGL() // From J.Allison picking branch
502 fUpdateGLLock = false;
503#else
504 //if (!isCurrentWidget()) return; //G.Barrand: Qt must know if it has to activate paintGL() if the widget is not visible.
505 //G.Barrand: don't do any change in the GUI here, just ask to "paint" this widget!
506 update();
507#endif
508}
509
511{
512 activateWindow();
513#if 0x060000 <= QT_VERSION
514 ((QApplication*)G4Qt::getInstance ())->processEvents();
515#endif
516}
517
518
520G4Colour& c,
521size_t poIndex) {
522 c = getColorForPoIndex((int)poIndex);
523}
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)
G4OpenGLQtViewer(G4OpenGLSceneHandler &scene)
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 resizeGL(int width, int height)
G4OpenGLStoredViewer(G4OpenGLStoredSceneHandler &scene)
virtual void SetView()
friend class G4OpenGLStoredSceneHandler
bool setExportImageFormat(std::string format, bool quiet=false)
unsigned int getWinHeight() const
void ResizeWindow(unsigned int, unsigned int)
unsigned int getWinWidth() const
G4OpenGLViewer(G4OpenGLSceneHandler &scene)
bool IsGettingPickInfos() const
virtual void ClearView()
G4bool isFramebufferReady()
G4bool sizeHasChanged()
static G4Qt * getInstance()
Definition G4Qt.cc:61
const G4String & GetName() const
G4bool fNeedKernelVisit
Definition G4VViewer.hh:280
const G4ViewParameters & GetViewParameters() const
void ProcessView()
Definition G4VViewer.cc:112
G4VSceneHandler & fSceneHandler
Definition G4VViewer.hh:268
G4int fViewId
Definition G4VViewer.hh:269
G4ViewParameters fVP
Definition G4VViewer.hh:272
G4VViewer(G4VSceneHandler &, G4int id, const G4String &name="")
Definition G4VViewer.cc:49
const std::vector< G4ModelingParameters::VisAttributesModifier > & GetVisAttributesModifiers() const
G4int GetNoOfSides() const
G4bool IsSpecialMeshRendering() const
G4double GetExplodeFactor() const
G4int GetNumberOfCloudPoints() const
G4bool IsMarkerNotHidden() const
G4double GetGlobalLineWidthScale() const
const G4Colour & GetBackgroundColour() const
G4bool IsSection() const
G4bool IsPicking() const
G4bool IsDotsSmooth() 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
G4int GetTransparencyByDepthOption() const
G4double GetGlobalMarkerScale() const
G4bool IsCullingInvisible() const
const G4VisAttributes * GetDefaultVisAttributes() const
G4bool IsDensityCulling() const
G4double GetVisibleDensity() const
SMROption GetSpecialMeshRenderingOption() const
G4double GetDotsSize() const
G4bool IsCullingCovered() const
const G4Plane3D & GetSectionPlane() const
DrawingStyle GetDrawingStyle() const
G4double GetTransparencyByDepth() const
G4bool IsAuxEdgeVisible() const
const G4Colour & GetColour() const
G4bool IsMasterThread()