Geant4 10.7.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
32#ifdef G4VIS_BUILD_OPENGLQT_DRIVER
33
35
37#include "G4ios.hh"
38#ifdef G4MULTITHREADED
39#include "G4Threading.hh"
40#endif
41
42#include <qapplication.h>
43#include <qtabwidget.h>
44
45G4OpenGLStoredQtViewer::G4OpenGLStoredQtViewer
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 QGLWidget()
53{
54 fQGLWidgetInitialiseCompleted = false;
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 if (fViewId < 0) return; // In case error in base class instantiation.
65}
66
67G4OpenGLStoredQtViewer::~G4OpenGLStoredQtViewer() {
68 makeCurrent();
69 // this is connect to the Dialog for deleting it properly
70 // when close event.
71 // ((QDialog*)window())->reject();
72}
73
74void G4OpenGLStoredQtViewer::Initialise() {
75 makeCurrent();
76
77 fQGLWidgetInitialiseCompleted = false;
78 CreateMainWindow (this,QString(GetName()));
79
80 glDrawBuffer (GL_BACK);
81
82 // set the good tab active
83 if (QGLWidget::parentWidget()) {
84 QTabWidget *parentTab = dynamic_cast<QTabWidget*> (QGLWidget::parentWidget()->parent()) ;
85 if (parentTab) {
86 parentTab->setCurrentIndex(parentTab->count()-1);
87 }
88 }
89
90 fQGLWidgetInitialiseCompleted = true;
91}
92
93void G4OpenGLStoredQtViewer::initializeGL () {
94
95 InitializeGLView ();
96
97 if (fSceneHandler.GetScene() == 0) {
98 fHasToRepaint =false;
99 } else {
100 fHasToRepaint =true;
101 }
102
103 // Set the component visible
104 // setVisible(true) ;
105
106}
107
108G4bool G4OpenGLStoredQtViewer::CompareForKernelVisit(G4ViewParameters& lastVP)
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 ()) ||
116 (lastVP.GetNumberOfCloudPoints() != fVP.GetNumberOfCloudPoints()) ||
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() !=
123 fVP.GetCBDAlgorithmNumber()) ||
124 (lastVP.IsSection () != fVP.IsSection ()) ||
125 // Section (DCUT) implemented locally. But still need to visit
126 // kernel if status changes so that back plane culling can be
127 // switched.
128 (lastVP.IsCutaway () != fVP.IsCutaway ()) ||
129 // Cutaways implemented locally. But still need to visit kernel
130 // if status changes so that back plane culling can be switched.
131 (lastVP.IsExplode () != fVP.IsExplode ()) ||
132 (lastVP.GetNoOfSides () != fVP.GetNoOfSides ()) ||
133 (lastVP.GetGlobalMarkerScale() != fVP.GetGlobalMarkerScale()) ||
134 (lastVP.GetGlobalLineWidthScale() != fVP.GetGlobalLineWidthScale()) ||
135 (lastVP.IsMarkerNotHidden () != fVP.IsMarkerNotHidden ()) ||
136 (lastVP.GetDefaultVisAttributes()->GetColour() !=
137 fVP.GetDefaultVisAttributes()->GetColour()) ||
139 fVP.GetDefaultTextVisAttributes()->GetColour()) ||
140 (lastVP.GetBackgroundColour ()!= fVP.GetBackgroundColour ())||
141 (lastVP.IsPicking () != fVP.IsPicking ()))
142 return true;
143
144 // Don't check VisAttributesModifiers if this comparison has been
145 // initiated by a mouse interaction on the scene tree.
146 if (fMouseOnSceneTree) {
147 // Reset the flag.
148 fMouseOnSceneTree = false;
149 } else {
150 // Not initiated by a mouse so compare for kernel visit.
151 if (lastVP.GetVisAttributesModifiers() != fVP.GetVisAttributesModifiers()) {
152 return true;
153 }
154 }
155
156 if (lastVP.IsDensityCulling () &&
157 (lastVP.GetVisibleDensity () != fVP.GetVisibleDensity ()))
158 return true;
159
160// /**************************************************************
161// If section (DCUT) is implemented locally, comment this out.
162 if (lastVP.IsSection () &&
163 (lastVP.GetSectionPlane () != fVP.GetSectionPlane ()))
164 return true;
165// ***************************************************************/
166
167 /**************************************************************
168 If cutaways are implemented locally, comment this out.
169 if (lastVP.IsCutaway ()) {
170 if (lastVP.GetCutawayPlanes ().size () !=
171 fVP.GetCutawayPlanes ().size ()) return true;
172 for (size_t i = 0; i < lastVP.GetCutawayPlanes().size(); ++i)
173 if (lastVP.GetCutawayPlanes()[i] != fVP.GetCutawayPlanes()[i])
174 return true;
175 }
176 ***************************************************************/
177
178 if (lastVP.GetCBDAlgorithmNumber() > 0) {
179 if (lastVP.GetCBDParameters().size() != fVP.GetCBDParameters().size()) return true;
180 else if (lastVP.GetCBDParameters() != fVP.GetCBDParameters()) return true;
181 }
182
183 if (lastVP.IsExplode () &&
184 (lastVP.GetExplodeFactor () != fVP.GetExplodeFactor ()))
185 return true;
186
187 return false;
188}
189
190G4bool G4OpenGLStoredQtViewer::POSelected(size_t POListIndex)
191{
192 return isTouchableVisible(POListIndex);
193}
194
195G4bool G4OpenGLStoredQtViewer::TOSelected(size_t)
196{
197 return true;
198}
199
200void G4OpenGLStoredQtViewer::DrawView () {
201 updateQWidget();
202}
203
204void G4OpenGLStoredQtViewer::ComputeView () {
205
206 makeCurrent();
207 G4ViewParameters::DrawingStyle dstyle = GetViewParameters().GetDrawingStyle();
208
209 //Make sure current viewer is attached and clean...
210
211 //See if things have changed from last time and remake if necessary...
212 // The fNeedKernelVisit flag might have been set by the user in
213 // /vis/viewer/rebuild, but if not, make decision and set flag only
214 // if necessary...
215 if (!fNeedKernelVisit) {
216 KernelVisitDecision ();
217 }
218 fLastVP = fVP;
219 G4bool kernelVisitWasNeeded = fNeedKernelVisit; // Keep (ProcessView resets).
220 ProcessView ();
221
222 if (kernelVisitWasNeeded) {
223 displaySceneTreeComponent();
224 }
225
226 if(dstyle!=G4ViewParameters::hlr &&
227 haloing_enabled) {
228
229 HaloingFirstPass ();
230 DrawDisplayLists ();
231 glFlush ();
232
233 HaloingSecondPass ();
234
235 DrawDisplayLists ();
236 FinishView ();
237
238 } else {
239
240 // If kernel visit was needed, drawing and FinishView will already
241 // have been done, so...
242 if (!kernelVisitWasNeeded) {
243 DrawDisplayLists ();
244 FinishView ();
245 } else {
246 // However, union cutaways are implemented in DrawDisplayLists, so make
247 // an extra pass...
248 if (fVP.IsCutaway() &&
249 fVP.GetCutawayMode() == G4ViewParameters::cutawayUnion) {
250 ClearView();
251 DrawDisplayLists ();
252 FinishView ();
253 } else { // ADD TO AVOID KernelVisit=1 and nothing to display
254 DrawDisplayLists ();
255 FinishView ();
256 }
257 }
258 }
259
260 if (isRecording()) {
261 savePPMToTemp();
262 }
263
264 fHasToRepaint = true;
265}
266
267
268/**
269 - Lors du resize de la fenetre, on doit non pas redessiner le detecteur, mais aussi les evenements
270*/
271void G4OpenGLStoredQtViewer::resizeGL(
272 int aWidth
273 ,int aHeight)
274{
275 // Set new size, it will be update when next Repaint()->SetView() called
276 if ((aWidth > 0) && (aHeight > 0)) {
277 ResizeWindow(aWidth,aHeight);
278 fHasToRepaint = sizeHasChanged();
279 }
280}
281
282
283// We have to get several case :
284// - Only activate the windows (mouse click for example) -> Do not redraw
285// - resize window -> redraw
286// - try to avoid recompute everything if we do not rescale picture (side is the same)
287
288void G4OpenGLStoredQtViewer::paintGL()
289{
290 updateToolbarAndMouseContextMenu();
291
292 if (fPaintEventLock) {
293// return ;
294 }
295 fPaintEventLock = true;
296 if ((getWinWidth() == 0) && (getWinHeight() == 0)) {
297 return;
298 }
299
300 if (!fQGLWidgetInitialiseCompleted) {
301 fPaintEventLock = false;
302 return;
303 }
304 // DO NOT RESIZE IF SIZE HAS NOT CHANGE :
305 // WHEN CLICK ON THE FRAME FOR EXAMPLE
306 // EXECEPT WHEN MOUSE MOVE EVENT
307 if ( !fHasToRepaint) {
308 // L. Garnier : Trap to get the size with mac OSX 10.6 and Qt 4.6(devel)
309 // Tested on Qt4.5 on mac, 4.4 on windows, 4.5 on unbuntu
310 int sw = 0;
311 int sh = 0;
312 if (!isMaximized() && !isFullScreen()) {
313 sw = normalGeometry().width();
314 sh = normalGeometry().height();
315 } else {
316 sw = frameGeometry().width();
317 sh = frameGeometry().height();
318 }
319 if ((getWinWidth() == (unsigned int)sw) &&(getWinHeight() == (unsigned int)sh)) {
320 return;
321 }
322 }
323 // Ensure that we really draw the BACK buffer
324 glDrawBuffer (GL_BACK);
325
326 SetView();
327
328 ClearView (); //ok, put the background correct
329 ComputeView();
330
331 fHasToRepaint = false;
332
333 fPaintEventLock = false;
334}
335
336void G4OpenGLStoredQtViewer::paintEvent(QPaintEvent *) {
337 if (! fQGLWidgetInitialiseCompleted) {
338 return;
339 }
340 // Force a repaint next time if the FRAMEBUFFER is not READY
341 fHasToRepaint = isFramebufferReady();
342 if ( fHasToRepaint) {
343 // Will really update the widget by calling CGLFlushDrawable
344 // The widget's rendering context will become the current context and initializeGL()
345 // will be called if it hasn't already been called.
346 // Copies the back buffer of a double-buffered context to the front buffer.
347 updateGL();
348 }
349}
350
351void G4OpenGLStoredQtViewer::mousePressEvent(QMouseEvent *event)
352{
353 G4MousePressEvent(event);
354}
355
356void G4OpenGLStoredQtViewer::keyPressEvent (QKeyEvent * event)
357{
358 G4keyPressEvent(event);
359}
360
361void G4OpenGLStoredQtViewer::keyReleaseEvent (QKeyEvent * event)
362{
363 G4keyReleaseEvent(event);
364}
365
366void G4OpenGLStoredQtViewer::wheelEvent (QWheelEvent * event)
367{
368 G4wheelEvent(event);
369}
370
371void G4OpenGLStoredQtViewer::showEvent (QShowEvent *)
372{
373 if (fQGLWidgetInitialiseCompleted) {
374 fHasToRepaint = true;
375 }
376}
377
378/**
379 * This function was build in order to make a zoom on double clic event.
380 * It was think to build a rubberband on the zoom area, but never work fine
381 */
382void G4OpenGLStoredQtViewer::mouseDoubleClickEvent(QMouseEvent *)
383{
384 G4MouseDoubleClickEvent();
385}
386
387void G4OpenGLStoredQtViewer::mouseReleaseEvent(QMouseEvent *event)
388{
389 G4MouseReleaseEvent(event);
390}
391
392void G4OpenGLStoredQtViewer::mouseMoveEvent(QMouseEvent *event)
393{
394 G4MouseMoveEvent(event);
395}
396
397
398void G4OpenGLStoredQtViewer::contextMenuEvent(QContextMenuEvent *e)
399{
400 G4manageContextMenuEvent(e);
401}
402
403void G4OpenGLStoredQtViewer::updateQWidget() {
404 if (fUpdateGLLock) {
405 return;
406 }
407
408 if (! isCurrentWidget()){
409 return;
410 }
411
412 fUpdateGLLock = true;
413 fHasToRepaint= true;
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 repaint(); // will read scene tree state
419 // updateGL() // From J.Allison picking branch
420 updateViewerPropertiesTableWidget();
421 updateSceneTreeWidget();
422 fUpdateGLLock = false;
423}
424
425void G4OpenGLStoredQtViewer::ShowView (
426)
427//////////////////////////////////////////////////////////////////////////////
428//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
429{
430 // glFlush (); // Tentativley offered by JA 29/04/16.
431
432 // Some X servers fail to draw all trajectories, particularly Mac
433 // XQuartz. Revisit this at a future date. Meanwhile, issue an
434 // extra...
435 // ClearView(); // Necessary? JA 29/04/16
436 // DrawView(); // Necessary? JA 29/04/16
437 activateWindow();
438 // glFlush(); // NO NEED and as drawView will already cause a flush
439 // that could do a double flush
440
441}
442
443
444void G4OpenGLStoredQtViewer::DisplayTimePOColourModification (
445G4Colour& c,
446size_t poIndex) {
447 c = getColorForPoIndex(poIndex);
448}
449
450#endif
bool G4bool
Definition: G4Types.hh:86
static G4bool GetColour(const G4String &key, G4Colour &result)
Definition: G4Colour.cc:162
const std::vector< G4ModelingParameters::VisAttributesModifier > & GetVisAttributesModifiers() const
G4int GetNoOfSides() 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
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)