Geant4-11
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 ()) ||
145 return true;
146
147 // Don't check VisAttributesModifiers if this comparison has been
148 // initiated by a mouse interaction on the scene tree.
149 if (fMouseOnSceneTree) {
150 // Reset the flag.
151 fMouseOnSceneTree = false;
152 } else {
153 // Not initiated by a mouse so compare for kernel visit.
155 return true;
156 }
157 }
158
159 if (lastVP.IsDensityCulling () &&
160 (lastVP.GetVisibleDensity () != fVP.GetVisibleDensity ()))
161 return true;
162
163// /**************************************************************
164// If section (DCUT) is implemented locally, comment this out.
165 if (lastVP.IsSection () &&
166 (lastVP.GetSectionPlane () != fVP.GetSectionPlane ()))
167 return true;
168// ***************************************************************/
169
170 /**************************************************************
171 If cutaways are implemented locally, comment this out.
172 if (lastVP.IsCutaway ()) {
173 if (lastVP.GetCutawayPlanes ().size () !=
174 fVP.GetCutawayPlanes ().size ()) return true;
175 for (size_t i = 0; i < lastVP.GetCutawayPlanes().size(); ++i)
176 if (lastVP.GetCutawayPlanes()[i] != fVP.GetCutawayPlanes()[i])
177 return true;
178 }
179 ***************************************************************/
180
181 if (lastVP.GetCBDAlgorithmNumber() > 0) {
182 if (lastVP.GetCBDParameters().size() != fVP.GetCBDParameters().size()) return true;
183 else if (lastVP.GetCBDParameters() != fVP.GetCBDParameters()) return true;
184 }
185
186 if (lastVP.IsExplode () &&
187 (lastVP.GetExplodeFactor () != fVP.GetExplodeFactor ()))
188 return true;
189
190 if (lastVP.IsSpecialMeshRendering() &&
192 return true;
193
194 return false;
195}
196
198{
199 return isTouchableVisible(POListIndex);
200}
201
203{
204 return true;
205}
206
209}
210
212
213 makeCurrent();
215
216 //Make sure current viewer is attached and clean...
217
218 //See if things have changed from last time and remake if necessary...
219 // The fNeedKernelVisit flag might have been set by the user in
220 // /vis/viewer/rebuild, but if not, make decision and set flag only
221 // if necessary...
222 if (!fNeedKernelVisit) {
224 }
225 fLastVP = fVP;
226 G4bool kernelVisitWasNeeded = fNeedKernelVisit; // Keep (ProcessView resets).
227 ProcessView ();
228
229 if (kernelVisitWasNeeded) {
231 }
232
233 if(dstyle!=G4ViewParameters::hlr &&
235
238 glFlush ();
239
241
243 FinishView ();
244
245 } else {
246
247 // If kernel visit was needed, drawing and FinishView will already
248 // have been done, so...
249 if (!kernelVisitWasNeeded) {
251 FinishView ();
252 } else {
253 // However, union cutaways are implemented in DrawDisplayLists, so make
254 // an extra pass...
255 if (fVP.IsCutaway() &&
257 ClearView();
259 FinishView ();
260 } else { // ADD TO AVOID KernelVisit=1 and nothing to display
262 FinishView ();
263 }
264 }
265 }
266
267 if (isRecording()) {
269 }
270
271 fHasToRepaint = true;
272}
273
274
279 int aWidth
280 ,int aHeight)
281{
282 // Set new size, it will be update when next Repaint()->SetView() called
283 if ((aWidth > 0) && (aHeight > 0)) {
284 ResizeWindow(aWidth,aHeight);
286 }
287}
288
289
290// We have to get several case :
291// - Only activate the windows (mouse click for example) -> Do not redraw
292// - resize window -> redraw
293// - try to avoid recompute everything if we do not rescale picture (side is the same)
294
296{
298
299 if (fPaintEventLock) {
300// return ;
301 }
302 fPaintEventLock = true;
303 if ((getWinWidth() == 0) && (getWinHeight() == 0)) {
304 return;
305 }
306
308 fPaintEventLock = false;
309 return;
310 }
311 // DO NOT RESIZE IF SIZE HAS NOT CHANGE :
312 // WHEN CLICK ON THE FRAME FOR EXAMPLE
313 // EXECEPT WHEN MOUSE MOVE EVENT
314 if ( !fHasToRepaint) {
315 // L. Garnier : Trap to get the size with mac OSX 10.6 and Qt 4.6(devel)
316 // Tested on Qt4.5 on mac, 4.4 on windows, 4.5 on unbuntu
317 int sw = 0;
318 int sh = 0;
319 if (!isMaximized() && !isFullScreen()) {
320 sw = normalGeometry().width();
321 sh = normalGeometry().height();
322 } else {
323 sw = frameGeometry().width();
324 sh = frameGeometry().height();
325 }
326 if ((getWinWidth() == (unsigned int)sw) &&(getWinHeight() == (unsigned int)sh)) {
327 return;
328 }
329 }
330 // Ensure that we really draw the BACK buffer
331 glDrawBuffer (GL_BACK);
332
333 SetView();
334
335 ClearView (); //ok, put the background correct
336 ComputeView();
337
338 fHasToRepaint = false;
339
340 fPaintEventLock = false;
341}
342
345 return;
346 }
347 // Force a repaint next time if the FRAMEBUFFER is not READY
349 if ( fHasToRepaint) {
350 // Will really update the widget by calling CGLFlushDrawable
351 // The widget's rendering context will become the current context and initializeGL()
352 // will be called if it hasn't already been called.
353 // Copies the back buffer of a double-buffered context to the front buffer.
354 updateGL();
355 }
356}
357
359{
360 G4MousePressEvent(event);
361}
362
364{
365 G4keyPressEvent(event);
366}
367
369{
370 G4keyReleaseEvent(event);
371}
372
373void G4OpenGLStoredQtViewer::wheelEvent (QWheelEvent * event)
374{
375 G4wheelEvent(event);
376}
377
379{
381 fHasToRepaint = true;
382 }
383}
384
390{
392}
393
395{
396 G4MouseReleaseEvent(event);
397}
398
400{
401 G4MouseMoveEvent(event);
402}
403
404
406{
408}
409
411 if (fUpdateGLLock) {
412 return;
413 }
414
415 if (! isCurrentWidget()){
416 return;
417 }
418
419 fUpdateGLLock = true;
420 fHasToRepaint= true;
421 // Will really update the widget by calling CGLFlushDrawable
422 // The widget's rendering context will become the current context and initializeGL()
423 // will be called if it hasn't already been called.
424 // Copies the back buffer of a double-buffered context to the front buffer.
425 repaint(); // will read scene tree state
426 // updateGL() // From J.Allison picking branch
429 fUpdateGLLock = false;
430}
431
433)
434
436{
437 // glFlush (); // Tentativley offered by JA 29/04/16.
438
439 // Some X servers fail to draw all trajectories, particularly Mac
440 // XQuartz. Revisit this at a future date. Meanwhile, issue an
441 // extra...
442 // ClearView(); // Necessary? JA 29/04/16
443 // DrawView(); // Necessary? JA 29/04/16
444 activateWindow();
445 // glFlush(); // NO NEED and as drawView will already cause a flush
446 // that could do a double flush
447
448}
449
450
452G4Colour& c,
453size_t poIndex) {
454 c = getColorForPoIndex(poIndex);
455}
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:224
const G4ViewParameters & GetViewParameters() const
void ProcessView()
Definition: G4VViewer.cc:105
G4VSceneHandler & fSceneHandler
Definition: G4VViewer.hh:215
G4int fViewId
Definition: G4VViewer.hh:216
G4ViewParameters fVP
Definition: G4VViewer.hh:219
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
G4bool IsCullingCovered() const
const G4Plane3D & GetSectionPlane() const
DrawingStyle GetDrawingStyle() const
G4bool IsAuxEdgeVisible() const
const G4Colour & GetColour() const
const char * name(G4int ptype)