Geant4 11.1.1
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
40#include <qapplication.h>
41#include <qtabwidget.h>
42
44(G4OpenGLStoredSceneHandler& sceneHandler,
45 const G4String& name):
46 G4VViewer (sceneHandler, sceneHandler.IncrementViewCount (), name),
47 G4OpenGLViewer (sceneHandler),
48 G4OpenGLQtViewer (sceneHandler),
49 G4OpenGLStoredViewer (sceneHandler), // FIXME : gerer le pb du parent !
50 QGLWidget()
51{
52 if (fViewId < 0) return; // In case error in base class instantiation.
53
55
56 // 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.
57 QGLWidget::setAttribute (Qt::WA_NoSystemBackground);
58
59 setFocusPolicy(Qt::StrongFocus); // enable keybord events
60 fHasToRepaint = false;
61 fPaintEventLock = false;
62 fUpdateGLLock = false;
63}
64
66 // makeCurrent(); // Not sure why this - commented out 12-Apr-2021 JA
67 // this is connect to the Dialog for deleting it properly
68 // when close event.
69 // ((QDialog*)window())->reject();
70}
71
73 makeCurrent();
74
76 CreateMainWindow (this,QString(GetName()));
77
78 glDrawBuffer (GL_BACK);
79
80 // set the good tab active
81 if (QGLWidget::parentWidget()) {
82 QTabWidget *parentTab = dynamic_cast<QTabWidget*> (QGLWidget::parentWidget()->parent()) ;
83 if (parentTab) {
84 parentTab->setCurrentIndex(parentTab->count()-1);
85 }
86 }
87
89}
90
92
94
95 if (fSceneHandler.GetScene() == 0) {
96 fHasToRepaint =false;
97 } else {
98 fHasToRepaint =true;
99 }
100
101 // Set the component visible
102 // setVisible(true) ;
103
104 // Set jpg as default export format for Qt viewer
106}
107
109{
110 // Identical to G4OpenGLStoredViewer::CompareForKernelVisit except
111 // for checking of VisAttributesModifiers, because
112 // G4OpenGLStoredQtViewer keeps track of its own touchable
113 // modifiers (fTreeItemModels, etc.).
114 if (
115 (lastVP.GetDrawingStyle () != fVP.GetDrawingStyle ()) ||
117 (lastVP.IsAuxEdgeVisible () != fVP.IsAuxEdgeVisible ()) ||
118 (lastVP.IsCulling () != fVP.IsCulling ()) ||
119 (lastVP.IsCullingInvisible () != fVP.IsCullingInvisible ()) ||
120 (lastVP.IsDensityCulling () != fVP.IsDensityCulling ()) ||
121 (lastVP.IsCullingCovered () != fVP.IsCullingCovered ()) ||
122 (lastVP.GetCBDAlgorithmNumber() !=
124 // Note: Section and Cutaway can reveal back-facing faces. If
125 // backface culling is implemented, the image can look strange because
126 // the back-facing faces are not there. For the moment, we have disabled
127 // (commented out) backface culling (it seems not to affect performance -
128 // in fact, performance seems to improve), so there is no problem.
129 (lastVP.IsSection () != fVP.IsSection ()) ||
130 // Section (DCUT) is NOT implemented locally so we need to visit the kernel.
131 // (lastVP.IsCutaway () != fVP.IsCutaway ()) ||
132 // Cutaways are implemented locally so we do not need to visit the kernel.
133 (lastVP.IsExplode () != fVP.IsExplode ()) ||
134 (lastVP.GetNoOfSides () != fVP.GetNoOfSides ()) ||
137 (lastVP.IsMarkerNotHidden () != fVP.IsMarkerNotHidden ()) ||
138 (lastVP.GetDefaultVisAttributes()->GetColour() !=
143 (lastVP.IsPicking () != fVP.IsPicking ()) ||
146 return true;
147
148 // Don't check VisAttributesModifiers if this comparison has been
149 // initiated by a mouse interaction on the scene tree.
150 if (fMouseOnSceneTree) {
151 // Reset the flag.
152 fMouseOnSceneTree = false;
153 } else {
154 // Not initiated by a mouse so compare for kernel visit.
156 return true;
157 }
158 }
159
160 if (lastVP.IsDensityCulling () &&
161 (lastVP.GetVisibleDensity () != fVP.GetVisibleDensity ()))
162 return true;
163
164// /**************************************************************
165// If section (DCUT) is implemented locally, comment this out.
166 if (lastVP.IsSection () &&
167 (lastVP.GetSectionPlane () != fVP.GetSectionPlane ()))
168 return true;
169// ***************************************************************/
170
171 /**************************************************************
172 If cutaways are implemented locally, comment this out.
173 if (lastVP.IsCutaway ()) {
174 if (vp.GetCutawayMode() != fVP.GetCutawayMode()) return true;
175 if (lastVP.GetCutawayPlanes ().size () !=
176 fVP.GetCutawayPlanes ().size ()) return true;
177 for (size_t i = 0; i < lastVP.GetCutawayPlanes().size(); ++i)
178 if (lastVP.GetCutawayPlanes()[i] != fVP.GetCutawayPlanes()[i])
179 return true;
180 }
181 ***************************************************************/
182
183 if (lastVP.GetCBDAlgorithmNumber() > 0) {
184 if (lastVP.GetCBDParameters().size() != fVP.GetCBDParameters().size()) return true;
185 else if (lastVP.GetCBDParameters() != fVP.GetCBDParameters()) return true;
186 }
187
188 if (lastVP.IsExplode () &&
189 (lastVP.GetExplodeFactor () != fVP.GetExplodeFactor ()))
190 return true;
191
192 if (lastVP.IsSpecialMeshRendering() &&
194 return true;
195
196 return false;
197}
198
200{
201 return isTouchableVisible((int)POListIndex);
202}
203
205{
206 return true;
207}
208
211}
212
213void G4OpenGLStoredQtViewer::ComputeView () {
214
215 makeCurrent();
217
218 //Make sure current viewer is attached and clean...
219
220 //See if things have changed from last time and remake if necessary...
221 // The fNeedKernelVisit flag might have been set by the user in
222 // /vis/viewer/rebuild, but if not, make decision and set flag only
223 // if necessary...
224 if (!fNeedKernelVisit) {
226 }
227 fLastVP = fVP;
228 G4bool kernelVisitWasNeeded = fNeedKernelVisit; // Keep (ProcessView resets).
229 ProcessView ();
230
231 if (kernelVisitWasNeeded) {
233 }
234
235 if(dstyle!=G4ViewParameters::hlr &&
237
240 glFlush ();
241
243
245 FinishView ();
246
247 } else {
248
249 // If kernel visit was needed, drawing and FinishView will already
250 // have been done, so...
251 if (!kernelVisitWasNeeded) {
253 FinishView ();
254 } else {
255 // However, union cutaways are implemented in DrawDisplayLists, so make
256 // an extra pass...
257 if (fVP.IsCutaway() &&
259 ClearView();
261 FinishView ();
262 } else { // ADD TO AVOID KernelVisit=1 and nothing to display
264 FinishView ();
265 }
266 }
267 }
268
269 if (isRecording()) {
271 }
272
273 fHasToRepaint = true;
274}
275
276
277/**
278 - Lors du resize de la fenetre, on doit non pas redessiner le detecteur, mais aussi les evenements
279*/
281 int aWidth
282 ,int aHeight)
283{
284 // Set new size, it will be update when next Repaint()->SetView() called
285 if ((aWidth > 0) && (aHeight > 0)) {
286 ResizeWindow(aWidth,aHeight);
288 }
289}
290
291
292// We have to get several case :
293// - Only activate the windows (mouse click for example) -> Do not redraw
294// - resize window -> redraw
295// - try to avoid recompute everything if we do not rescale picture (side is the same)
296
298{
300
301 if (fPaintEventLock) {
302// return ;
303 }
304 fPaintEventLock = true;
305 if ((getWinWidth() == 0) && (getWinHeight() == 0)) {
306 return;
307 }
308
310 fPaintEventLock = false;
311 return;
312 }
313 // DO NOT RESIZE IF SIZE HAS NOT CHANGE :
314 // WHEN CLICK ON THE FRAME FOR EXAMPLE
315 // EXECEPT WHEN MOUSE MOVE EVENT
316 if ( !fHasToRepaint) {
317 // L. Garnier : Trap to get the size with mac OSX 10.6 and Qt 4.6(devel)
318 // Tested on Qt4.5 on mac, 4.4 on windows, 4.5 on unbuntu
319 int sw = 0;
320 int sh = 0;
321 if (!isMaximized() && !isFullScreen()) {
322 sw = normalGeometry().width();
323 sh = normalGeometry().height();
324 } else {
325 sw = frameGeometry().width();
326 sh = frameGeometry().height();
327 }
328 if ((getWinWidth() == (unsigned int)sw) &&(getWinHeight() == (unsigned int)sh)) {
329 return;
330 }
331 }
332 // Ensure that we really draw the BACK buffer
333 glDrawBuffer (GL_BACK);
334
335 SetView();
336
337 ClearView (); //ok, put the background correct
338 ComputeView();
339
340 fHasToRepaint = false;
341
342 fPaintEventLock = false;
343}
344
347 return;
348 }
349 // Force a repaint next time if the FRAMEBUFFER is not READY
351 if ( fHasToRepaint) {
352 // Will really update the widget by calling CGLFlushDrawable
353 // The widget's rendering context will become the current context and initializeGL()
354 // will be called if it hasn't already been called.
355 // Copies the back buffer of a double-buffered context to the front buffer.
356 updateGL();
357 }
358}
359
361{
362 G4MousePressEvent(event);
363}
364
366{
367 G4keyPressEvent(event);
368}
369
371{
372 G4keyReleaseEvent(event);
373}
374
375void G4OpenGLStoredQtViewer::wheelEvent (QWheelEvent * event)
376{
377 G4wheelEvent(event);
378}
379
381{
383 fHasToRepaint = true;
384 }
385}
386
387/**
388 * This function was build in order to make a zoom on double clic event.
389 * It was think to build a rubberband on the zoom area, but never work fine
390 */
392{
394}
395
397{
398 G4MouseReleaseEvent(event);
399}
400
402{
403 G4MouseMoveEvent(event);
404}
405
406
408{
410}
411
413 if (fUpdateGLLock) {
414 return;
415 }
416
417 if (! isCurrentWidget()){
418 return;
419 }
420
421 fUpdateGLLock = true;
422 fHasToRepaint= true;
423 // Will really update the widget by calling CGLFlushDrawable
424 // The widget's rendering context will become the current context and initializeGL()
425 // will be called if it hasn't already been called.
426 // Copies the back buffer of a double-buffered context to the front buffer.
427 repaint(); // will read scene tree state
428 // updateGL() // From J.Allison picking branch
431 fUpdateGLLock = false;
432}
433
435)
436//////////////////////////////////////////////////////////////////////////////
437//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
438{
439 // glFlush (); // Tentativley offered by JA 29/04/16.
440
441 // Some X servers fail to draw all trajectories, particularly Mac
442 // XQuartz. Revisit this at a future date. Meanwhile, issue an
443 // extra...
444 // ClearView(); // Necessary? JA 29/04/16
445 // DrawView(); // Necessary? JA 29/04/16
446 activateWindow();
447 // glFlush(); // NO NEED and as drawView will already cause a flush
448 // that could do a double flush
449
450}
451
452
454G4Colour& c,
455size_t poIndex) {
456 c = getColorForPoIndex((int)poIndex);
457}
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)
G4Colour getColorForPoIndex(int poIndex)
virtual void CreateMainWindow(QGLWidget *, const QString &)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
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()
void HaloingSecondPass()
G4Scene * GetScene() const
const G4String & GetName() const
G4bool fNeedKernelVisit
Definition: G4VViewer.hh:227
const G4ViewParameters & GetViewParameters() const
void ProcessView()
Definition: G4VViewer.cc:107
G4VSceneHandler & fSceneHandler
Definition: G4VViewer.hh:216
G4int fViewId
Definition: G4VViewer.hh:217
G4ViewParameters fVP
Definition: G4VViewer.hh:220
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