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

Last change on this file since 1111 was 1108, checked in by garnier, 16 years ago

modif mineure

  • Property svn:mime-type set to text/cpp
File size: 8.8 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//
[1092]27// $Id: G4OpenGLStoredQtViewer.cc,v 1.26 2009/07/27 14:01:13 lgarnier Exp $
[866]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
[595]40//#include <qmouseevent.h>
41#include <qevent.h> // include <qcontextmenuevent.h>
[593]42
[533]43G4OpenGLStoredQtViewer::G4OpenGLStoredQtViewer
[531]44(G4OpenGLStoredSceneHandler& sceneHandler,
45 const G4String& name):
[682]46 G4VViewer (sceneHandler, sceneHandler.IncrementViewCount (), name),
47 G4OpenGLViewer (sceneHandler),
48 G4OpenGLQtViewer (sceneHandler),
[1108]49 G4OpenGLStoredViewer (sceneHandler), // FIXME : gerer le pb du parent !
50 QGLWidget()
[682]51{
[863]52
[709]53#if QT_VERSION < 0x040000
54 setFocusPolicy(QWidget::StrongFocus); // enable keybord events
55#else
[696]56 setFocusPolicy(Qt::StrongFocus); // enable keybord events
[709]57#endif
[1040]58 fHasToRepaint =false;
[858]59
[531]60 if (fViewId < 0) return; // In case error in base class instantiation.
61}
62
[564]63G4OpenGLStoredQtViewer::~G4OpenGLStoredQtViewer() {
[682]64 makeCurrent();
65 // this is connect to the Dialog for deleting it properly
66 // when close event.
67 // ((QDialog*)window())->reject();
[564]68}
[531]69
[564]70void G4OpenGLStoredQtViewer::Initialise() {
[911]71#ifdef G4DEBUG_VIS_OGL
[858]72 printf("G4OpenGLStoredQtViewer::Initialise 1\n");
[608]73#endif
[1040]74 fReadyToPaint = false;
[866]75 CreateMainWindow (this,QString(fName));
[873]76 CreateFontLists ();
[564]77
[1040]78 fReadyToPaint = true;
[564]79}
[531]80
[564]81void G4OpenGLStoredQtViewer::initializeGL () {
82
[682]83 InitializeGLView ();
[564]84
[911]85#ifdef G4DEBUG_VIS_OGL
[682]86 printf("G4OpenGLStoredQtViewer::InitialiseGL () 1\n");
[608]87#endif
[564]88
[682]89 // clear the buffers and window.
90 ClearView ();
91 FinishView ();
[564]92
[682]93 glDepthFunc (GL_LEQUAL);
94 glDepthMask (GL_TRUE);
[564]95
[866]96 if (fSceneHandler.GetScene() == 0) {
[1040]97 fHasToRepaint =false;
[866]98 } else {
[1040]99 fHasToRepaint =true;
[866]100 }
[564]101
[911]102#ifdef G4DEBUG_VIS_OGL
[873]103 printf("G4OpenGLStoredQtViewer::InitialiseGL END\n");
[608]104#endif
[531]105}
106
[564]107
[533]108void G4OpenGLStoredQtViewer::DrawView () {
[911]109#ifdef G4DEBUG_VIS_OGL
[877]110 printf("G4OpenGLStoredQtViewer::DrawView VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV\n");
111#endif
112 // That's no the same logic as Immediate Viewer, I don't know why...
113 // But if I send updateGL here, we go here :
114 // updateQWidget -> paintGL -> ComputeView
115 // whih is not the same as ComputeView Directly
116 // And we loose the redraw of things !
117
[1039]118 ComputeView();
[911]119#ifdef G4DEBUG_VIS_OGL
[877]120 printf("G4OpenGLStoredQtViewer::DrawView ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n");
121#endif
122}
[682]123
[877]124void G4OpenGLStoredQtViewer::ComputeView () {
125
[911]126#ifdef G4DEBUG_VIS_OGL
[1039]127 printf("G4OpenGLStoredQtViewer::ComputeView %d %d VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV\n",getWinWidth(), getWinHeight());
[608]128#endif
[877]129 makeCurrent();
[682]130 G4ViewParameters::DrawingStyle style = GetViewParameters().GetDrawingStyle();
[531]131
[682]132 //Make sure current viewer is attached and clean...
[531]133
[682]134 //See if things have changed from last time and remake if necessary...
135 // The fNeedKernelVisit flag might have been set by the user in
136 // /vis/viewer/rebuild, but if not, make decision and set flag only
137 // if necessary...
[873]138 if (!fNeedKernelVisit) {
[877]139 KernelVisitDecision ();
[873]140 }
[682]141 G4bool kernelVisitWasNeeded = fNeedKernelVisit; // Keep (ProcessView resets).
142 ProcessView ();
[564]143
[531]144
[682]145 if(style!=G4ViewParameters::hlr &&
146 haloing_enabled) {
[911]147#ifdef G4DEBUG_VIS_OGL
[877]148 printf("G4OpenGLStoredQtViewer::ComputeView DANS LE IF\n");
[608]149#endif
[531]150
[682]151 HaloingFirstPass ();
152 DrawDisplayLists ();
153 glFlush ();
[531]154
[682]155 HaloingSecondPass ();
[531]156
[682]157 DrawDisplayLists ();
158 FinishView ();
[531]159
[682]160 } else {
[564]161
[682]162 // If kernel visit was needed, drawing and FinishView will already
163 // have been done, so...
164 if (!kernelVisitWasNeeded) {
[911]165#ifdef G4DEBUG_VIS_OGL
[877]166 printf("************************** G4OpenGLStoredQtViewer::ComputeView Don't need kernel Visit \n");
[608]167#endif
[682]168 DrawDisplayLists ();
169 FinishView ();
170 } else {
[911]171#ifdef G4DEBUG_VIS_OGL
[877]172 printf("************************** G4OpenGLStoredQtViewer::ComputeView need kernel Visit \n");
[608]173#endif
[682]174 // However, union cutaways are implemented in DrawDisplayLists, so make
175 // an extra pass...
176 if (fVP.IsCutaway() &&
177 fVP.GetCutawayMode() == G4ViewParameters::cutawayUnion) {
178 ClearView();
179 DrawDisplayLists ();
180 FinishView ();
[911]181#ifdef G4DEBUG_VIS_OGL
[682]182 printf("*************************** CASE 4 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \n");
[608]183#endif
[682]184 } else { // ADD TO AVOID KernelVisit=1 and nothing to display
185 DrawDisplayLists ();
186 FinishView ();
187 }
188 }
189 }
[564]190
[745]191 if (isRecording()) {
[739]192 savePPMToTemp();
[724]193 }
194
[911]195#ifdef G4DEBUG_VIS_OGL
[1039]196 printf("G4OpenGLStoredQtViewer::ComputeView %d %d ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \n",getWinWidth(), getWinHeight());
[608]197#endif
[1040]198 fHasToRepaint =true;
[531]199}
200
[564]201
202/**
[682]203 - Lors du resize de la fenetre, on doit non pas redessiner le detecteur, mais aussi les evenements
204*/
[564]205void G4OpenGLStoredQtViewer::resizeGL(
[1039]206 int aWidth
207 ,int aHeight)
[564]208{
[906]209 // Set new size, it will be update when next Repaint()->SetView() called
[1039]210 ResizeWindow(aWidth,aHeight);
[1040]211 fHasToRepaint = sizeHasChanged();
[564]212}
213
214
215void G4OpenGLStoredQtViewer::paintGL()
[682]216{
[911]217#ifdef G4DEBUG_VIS_OGL
[1040]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) {
[1039]228 if (((getWinWidth() == (unsigned int)width())) &&(getWinHeight() == (unsigned int) height())) {
229 return;
230 }
231 }
232#ifdef G4DEBUG_VIS_OGL
[1040]233 printf("G4OpenGLStoredQtViewer::paintGL VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV ready %d\n",fReadyToPaint);
[1039]234#endif
[873]235
[1039]236 SetView();
237
238 ClearView (); //ok, put the background correct
239 ComputeView();
240
[1040]241 fHasToRepaint =false;
[1039]242
[911]243#ifdef G4DEBUG_VIS_OGL
[1040]244 printf("G4OpenGLStoredQtViewer::paintGL ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ready %d\n",fReadyToPaint);
[608]245#endif
[682]246}
[564]247
248void G4OpenGLStoredQtViewer::mousePressEvent(QMouseEvent *event)
249{
[873]250 G4MousePressEvent(event);
[564]251}
252
[696]253void G4OpenGLStoredQtViewer::keyPressEvent (QKeyEvent * event)
254{
255 G4keyPressEvent(event);
256}
257
[804]258void G4OpenGLStoredQtViewer::wheelEvent (QWheelEvent * event)
259{
260 G4wheelEvent(event);
261}
262
[678]263/**
264 * This function was build in order to make a zoom on double clic event.
265 * It was think to build a rubberband on the zoom area, but never work fine
266 */
[955]267void G4OpenGLStoredQtViewer::mouseDoubleClickEvent(QMouseEvent *)
[673]268{
[873]269 G4MouseDoubleClickEvent();
[673]270}
271
[955]272void G4OpenGLStoredQtViewer::mouseReleaseEvent(QMouseEvent *)
[673]273{
[797]274 G4MouseReleaseEvent();
[673]275}
276
[564]277void G4OpenGLStoredQtViewer::mouseMoveEvent(QMouseEvent *event)
278{
[873]279 G4MouseMoveEvent(event);
[564]280}
281
282
283void G4OpenGLStoredQtViewer::contextMenuEvent(QContextMenuEvent *e)
284{
[873]285 G4manageContextMenuEvent(e);
[564]286}
287
288void G4OpenGLStoredQtViewer::updateQWidget() {
[1040]289 fHasToRepaint= true;
[564]290 updateGL();
[1040]291 fHasToRepaint= false;
[564]292}
293
[877]294void G4OpenGLStoredQtViewer::ShowView (
295)
296//////////////////////////////////////////////////////////////////////////////
297//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
298{
299#if QT_VERSION < 0x040000
300 setActiveWindow();
301#else
302 activateWindow();
303#endif
304}
[673]305
[531]306#endif
Note: See TracBrowser for help on using the repository browser.