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

Last change on this file since 1104 was 1092, checked in by garnier, 16 years ago

unset picking true when init OGLSQt

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