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