source: trunk/source/visualization/OpenGL/src/G4OpenGLStoredQtViewer.cc@ 1318

Last change on this file since 1318 was 1311, checked in by garnier, 15 years ago

isRepainting problem, remove it for the moment

  • Property svn:mime-type set to text/cpp
File size: 9.4 KB
RevLine 
[531]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//
[1311]27// $Id: G4OpenGLStoredQtViewer.cc,v 1.31 2010/06/04 16:21:47 lgarnier Exp $
[1307]28// GEANT4 tag $Name: $
[531]29//
[564]30//
[533]31// Class G4OpenGLStoredQtViewer : a class derived from G4OpenGLQtViewer and
[564]32// G4OpenGLStoredViewer.
[531]33
[533]34#ifdef G4VIS_BUILD_OPENGLQT_DRIVER
[531]35
[533]36#include "G4OpenGLStoredQtViewer.hh"
[531]37
38#include "G4ios.hh"
39
[533]40G4OpenGLStoredQtViewer::G4OpenGLStoredQtViewer
[531]41(G4OpenGLStoredSceneHandler& sceneHandler,
42 const G4String& name):
[682]43 G4VViewer (sceneHandler, sceneHandler.IncrementViewCount (), name),
44 G4OpenGLViewer (sceneHandler),
45 G4OpenGLQtViewer (sceneHandler),
[1124]46 G4OpenGLStoredViewer (sceneHandler), // FIXME : gerer le pb du parent !
47 QGLWidget()
[682]48{
[863]49
[709]50#if QT_VERSION < 0x040000
51 setFocusPolicy(QWidget::StrongFocus); // enable keybord events
52#else
[696]53 setFocusPolicy(Qt::StrongFocus); // enable keybord events
[709]54#endif
[1307]55 fHasToRepaint = false;
56 fIsRepainting = false;
[858]57
[531]58 if (fViewId < 0) return; // In case error in base class instantiation.
59}
60
[564]61G4OpenGLStoredQtViewer::~G4OpenGLStoredQtViewer() {
[682]62 makeCurrent();
63 // this is connect to the Dialog for deleting it properly
64 // when close event.
65 // ((QDialog*)window())->reject();
[564]66}
[531]67
[564]68void G4OpenGLStoredQtViewer::Initialise() {
[911]69#ifdef G4DEBUG_VIS_OGL
[858]70 printf("G4OpenGLStoredQtViewer::Initialise 1\n");
[608]71#endif
[1040]72 fReadyToPaint = false;
[1164]73 CreateMainWindow (this,QString(GetName()));
[873]74 CreateFontLists ();
[564]75
[1040]76 fReadyToPaint = true;
[564]77}
[531]78
[564]79void G4OpenGLStoredQtViewer::initializeGL () {
80
[682]81 InitializeGLView ();
[564]82
[911]83#ifdef G4DEBUG_VIS_OGL
[682]84 printf("G4OpenGLStoredQtViewer::InitialiseGL () 1\n");
[608]85#endif
[564]86
[682]87 // clear the buffers and window.
[1295]88 ClearView ();
89 FinishView ();
[564]90
[682]91 glDepthFunc (GL_LEQUAL);
92 glDepthMask (GL_TRUE);
[564]93
[866]94 if (fSceneHandler.GetScene() == 0) {
[1040]95 fHasToRepaint =false;
[866]96 } else {
[1040]97 fHasToRepaint =true;
[866]98 }
[564]99
[911]100#ifdef G4DEBUG_VIS_OGL
[873]101 printf("G4OpenGLStoredQtViewer::InitialiseGL END\n");
[608]102#endif
[531]103}
104
[564]105
[1242]106void G4OpenGLStoredQtViewer::DrawView () {
[1238]107 updateQWidget();
[877]108}
[682]109
[877]110void G4OpenGLStoredQtViewer::ComputeView () {
[1122]111
112#ifdef G4DEBUG_VIS_OGL
[1039]113 printf("G4OpenGLStoredQtViewer::ComputeView %d %d VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV\n",getWinWidth(), getWinHeight());
[608]114#endif
[877]115 makeCurrent();
[682]116 G4ViewParameters::DrawingStyle style = GetViewParameters().GetDrawingStyle();
[531]117
[682]118 //Make sure current viewer is attached and clean...
[531]119
[682]120 //See if things have changed from last time and remake if necessary...
121 // The fNeedKernelVisit flag might have been set by the user in
122 // /vis/viewer/rebuild, but if not, make decision and set flag only
123 // if necessary...
[873]124 if (!fNeedKernelVisit) {
[877]125 KernelVisitDecision ();
[873]126 }
[682]127 G4bool kernelVisitWasNeeded = fNeedKernelVisit; // Keep (ProcessView resets).
128 ProcessView ();
[564]129
[531]130
[682]131 if(style!=G4ViewParameters::hlr &&
132 haloing_enabled) {
[911]133#ifdef G4DEBUG_VIS_OGL
[877]134 printf("G4OpenGLStoredQtViewer::ComputeView DANS LE IF\n");
[608]135#endif
[531]136
[682]137 HaloingFirstPass ();
138 DrawDisplayLists ();
139 glFlush ();
[531]140
[682]141 HaloingSecondPass ();
[531]142
[682]143 DrawDisplayLists ();
144 FinishView ();
[531]145
[682]146 } else {
[564]147
[682]148 // If kernel visit was needed, drawing and FinishView will already
149 // have been done, so...
150 if (!kernelVisitWasNeeded) {
[911]151#ifdef G4DEBUG_VIS_OGL
[877]152 printf("************************** G4OpenGLStoredQtViewer::ComputeView Don't need kernel Visit \n");
[608]153#endif
[682]154 DrawDisplayLists ();
155 FinishView ();
156 } else {
[911]157#ifdef G4DEBUG_VIS_OGL
[877]158 printf("************************** G4OpenGLStoredQtViewer::ComputeView need kernel Visit \n");
[608]159#endif
[682]160 // However, union cutaways are implemented in DrawDisplayLists, so make
161 // an extra pass...
162 if (fVP.IsCutaway() &&
163 fVP.GetCutawayMode() == G4ViewParameters::cutawayUnion) {
164 ClearView();
165 DrawDisplayLists ();
166 FinishView ();
[911]167#ifdef G4DEBUG_VIS_OGL
[682]168 printf("*************************** CASE 4 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \n");
[608]169#endif
[682]170 } else { // ADD TO AVOID KernelVisit=1 and nothing to display
171 DrawDisplayLists ();
172 FinishView ();
173 }
174 }
175 }
[564]176
[745]177 if (isRecording()) {
[739]178 savePPMToTemp();
[724]179 }
180
[911]181#ifdef G4DEBUG_VIS_OGL
[1039]182 printf("G4OpenGLStoredQtViewer::ComputeView %d %d ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \n",getWinWidth(), getWinHeight());
[608]183#endif
[1307]184 fHasToRepaint = true;
[531]185}
186
[564]187
188/**
[682]189 - Lors du resize de la fenetre, on doit non pas redessiner le detecteur, mais aussi les evenements
190*/
[564]191void G4OpenGLStoredQtViewer::resizeGL(
[1039]192 int aWidth
193 ,int aHeight)
[564]194{
[1121]195 // Set new size, it will be update when next Repaint()->SetView() called
[1307]196 if ((aWidth > 0) && (aHeight > 0)) {
197 ResizeWindow(aWidth,aHeight);
198 fHasToRepaint = sizeHasChanged();
199 }
[1121]200}
201
[1124]202
[1227]203// We have to get several case :
204// - Only activate the windows (mouse click for example) -> Do not redraw
205// - resize window -> redraw
206// - try to avoid recompute everything if we do not rescale picture (side is the same)
207
[1121]208void G4OpenGLStoredQtViewer::paintGL()
209{
[1310]210#ifdef G4DEBUG_VIS_OGL
211 printf("G4OpenGLStoredQtViewer::paintGL \n");
212#endif
[1307]213 if (fIsRepainting) {
[1311]214 // return ;
[1307]215 }
216 fIsRepainting = true;
[1121]217#ifdef G4DEBUG_VIS_OGL
[1242]218 printf("G4OpenGLStoredQtViewer::paintGL ready:%d fHasTo:%d??\n",fReadyToPaint,fHasToRepaint);
[873]219#endif
[1040]220 if (!fReadyToPaint) {
221 fReadyToPaint= true;
[682]222 return;
223 }
[1039]224 // DO NOT RESIZE IF SIZE HAS NOT CHANGE :
225 // WHEN CLICK ON THE FRAME FOR EXAMPLE
226 // EXECEPT WHEN MOUSE MOVE EVENT
[1040]227 if ( !fHasToRepaint) {
[1141]228#if QT_VERSION < 0x040000
229 if (((getWinWidth() == (unsigned int)width())) &&(getWinHeight() == (unsigned int) height())) {
230#else
[1125]231 // L. Garnier : Trap to get the size with mac OSX 10.6 and Qt 4.6(devel)
232 // Tested on Qt4.5 on mac, 4.4 on windows, 4.5 on unbuntu
233 int sw = 0;
234 int sh = 0;
235 if (!isMaximized() && !isFullScreen()) {
236 sw = normalGeometry().width();
237 sh = normalGeometry().height();
238 } else {
239 sw = frameGeometry().width();
240 sh = frameGeometry().height();
241 }
[1126]242 if ((getWinWidth() == (unsigned int)sw) &&(getWinHeight() == (unsigned int)sh)) {
[1141]243#endif
[1039]244 return;
245 }
246 }
247#ifdef G4DEBUG_VIS_OGL
[1040]248 printf("G4OpenGLStoredQtViewer::paintGL VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV ready %d\n",fReadyToPaint);
[1039]249#endif
[873]250
[1141]251 SetView();
[1307]252
[1141]253 ClearView (); //ok, put the background correct
[1039]254 ComputeView();
[1227]255
[1307]256 fHasToRepaint = false;
[1242]257
[911]258#ifdef G4DEBUG_VIS_OGL
[1124]259 printf("G4OpenGLStoredQtViewer::paintGL ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ready %d\n",fReadyToPaint);
[608]260#endif
[1307]261 fIsRepainting = false;
[682]262}
[564]263
[1235]264void G4OpenGLStoredQtViewer::paintEvent(QPaintEvent *event) {
265 if ( fHasToRepaint) {
266 updateGL();
267 }
268}
269
[564]270void G4OpenGLStoredQtViewer::mousePressEvent(QMouseEvent *event)
271{
[1124]272 G4MousePressEvent(event);
[564]273}
274
[696]275void G4OpenGLStoredQtViewer::keyPressEvent (QKeyEvent * event)
276{
277 G4keyPressEvent(event);
278}
279
[804]280void G4OpenGLStoredQtViewer::wheelEvent (QWheelEvent * event)
281{
282 G4wheelEvent(event);
283}
284
[1240]285void G4OpenGLStoredQtViewer::showEvent (QShowEvent * event)
286{
287 fHasToRepaint = true;
288}
289
[678]290/**
291 * This function was build in order to make a zoom on double clic event.
292 * It was think to build a rubberband on the zoom area, but never work fine
293 */
[955]294void G4OpenGLStoredQtViewer::mouseDoubleClickEvent(QMouseEvent *)
[673]295{
[873]296 G4MouseDoubleClickEvent();
[673]297}
298
[955]299void G4OpenGLStoredQtViewer::mouseReleaseEvent(QMouseEvent *)
[673]300{
[797]301 G4MouseReleaseEvent();
[673]302}
303
[564]304void G4OpenGLStoredQtViewer::mouseMoveEvent(QMouseEvent *event)
305{
[873]306 G4MouseMoveEvent(event);
[564]307}
308
309
310void G4OpenGLStoredQtViewer::contextMenuEvent(QContextMenuEvent *e)
311{
[873]312 G4manageContextMenuEvent(e);
[564]313}
314
315void G4OpenGLStoredQtViewer::updateQWidget() {
[1040]316 fHasToRepaint= true;
[564]317 updateGL();
[1040]318 fHasToRepaint= false;
[564]319}
320
[877]321void G4OpenGLStoredQtViewer::ShowView (
322)
323//////////////////////////////////////////////////////////////////////////////
324//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
325{
326#if QT_VERSION < 0x040000
327 setActiveWindow();
328#else
329 activateWindow();
330#endif
331}
[673]332
[531]333#endif
Note: See TracBrowser for help on using the repository browser.