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

Last change on this file since 1192 was 1172, checked in by garnier, 16 years ago

fix delete bug

  • Property svn:mime-type set to text/cpp
File size: 9.3 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//
[1141]27// $Id: G4OpenGLStoredQtViewer.cc,v 1.28 2009/11/03 11:02:32 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
[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
[1040]55 fHasToRepaint =false;
[858]56
[531]57 if (fViewId < 0) return; // In case error in base class instantiation.
58}
59
[564]60G4OpenGLStoredQtViewer::~G4OpenGLStoredQtViewer() {
[682]61 makeCurrent();
62 // this is connect to the Dialog for deleting it properly
63 // when close event.
64 // ((QDialog*)window())->reject();
[1172]65 GetSceneHandler()->RemoveViewerFromList(this);
[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.
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
[533]106void G4OpenGLStoredQtViewer::DrawView () {
[911]107#ifdef G4DEBUG_VIS_OGL
[877]108 printf("G4OpenGLStoredQtViewer::DrawView VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV\n");
109#endif
110 // That's no the same logic as Immediate Viewer, I don't know why...
111 // But if I send updateGL here, we go here :
112 // updateQWidget -> paintGL -> ComputeView
113 // whih is not the same as ComputeView Directly
114 // And we loose the redraw of things !
115
[1039]116 ComputeView();
[911]117#ifdef G4DEBUG_VIS_OGL
[877]118 printf("G4OpenGLStoredQtViewer::DrawView ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n");
119#endif
120}
[682]121
[877]122void G4OpenGLStoredQtViewer::ComputeView () {
[1122]123
124#ifdef G4DEBUG_VIS_OGL
[1039]125 printf("G4OpenGLStoredQtViewer::ComputeView %d %d VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV\n",getWinWidth(), getWinHeight());
[608]126#endif
[877]127 makeCurrent();
[682]128 G4ViewParameters::DrawingStyle style = GetViewParameters().GetDrawingStyle();
[531]129
[682]130 //Make sure current viewer is attached and clean...
[531]131
[682]132 //See if things have changed from last time and remake if necessary...
133 // The fNeedKernelVisit flag might have been set by the user in
134 // /vis/viewer/rebuild, but if not, make decision and set flag only
135 // if necessary...
[873]136 if (!fNeedKernelVisit) {
[877]137 KernelVisitDecision ();
[873]138 }
[682]139 G4bool kernelVisitWasNeeded = fNeedKernelVisit; // Keep (ProcessView resets).
140 ProcessView ();
[564]141
[531]142
[682]143 if(style!=G4ViewParameters::hlr &&
144 haloing_enabled) {
[911]145#ifdef G4DEBUG_VIS_OGL
[877]146 printf("G4OpenGLStoredQtViewer::ComputeView DANS LE IF\n");
[608]147#endif
[531]148
[682]149 HaloingFirstPass ();
150 DrawDisplayLists ();
151 glFlush ();
[531]152
[682]153 HaloingSecondPass ();
[531]154
[682]155 DrawDisplayLists ();
156 FinishView ();
[531]157
[682]158 } else {
[564]159
[682]160 // If kernel visit was needed, drawing and FinishView will already
161 // have been done, so...
162 if (!kernelVisitWasNeeded) {
[911]163#ifdef G4DEBUG_VIS_OGL
[877]164 printf("************************** G4OpenGLStoredQtViewer::ComputeView Don't need kernel Visit \n");
[608]165#endif
[682]166 DrawDisplayLists ();
167 FinishView ();
168 } else {
[911]169#ifdef G4DEBUG_VIS_OGL
[877]170 printf("************************** G4OpenGLStoredQtViewer::ComputeView need kernel Visit \n");
[608]171#endif
[682]172 // However, union cutaways are implemented in DrawDisplayLists, so make
173 // an extra pass...
174 if (fVP.IsCutaway() &&
175 fVP.GetCutawayMode() == G4ViewParameters::cutawayUnion) {
176 ClearView();
177 DrawDisplayLists ();
178 FinishView ();
[911]179#ifdef G4DEBUG_VIS_OGL
[682]180 printf("*************************** CASE 4 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \n");
[608]181#endif
[682]182 } else { // ADD TO AVOID KernelVisit=1 and nothing to display
183 DrawDisplayLists ();
184 FinishView ();
185 }
186 }
187 }
[564]188
[745]189 if (isRecording()) {
[739]190 savePPMToTemp();
[724]191 }
192
[911]193#ifdef G4DEBUG_VIS_OGL
[1039]194 printf("G4OpenGLStoredQtViewer::ComputeView %d %d ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \n",getWinWidth(), getWinHeight());
[608]195#endif
[1040]196 fHasToRepaint =true;
[531]197}
198
[564]199
200/**
[682]201 - Lors du resize de la fenetre, on doit non pas redessiner le detecteur, mais aussi les evenements
202*/
[564]203void G4OpenGLStoredQtViewer::resizeGL(
[1039]204 int aWidth
205 ,int aHeight)
[564]206{
[1121]207 // Set new size, it will be update when next Repaint()->SetView() called
[1124]208 ResizeWindow(aWidth,aHeight);
[1040]209 fHasToRepaint = sizeHasChanged();
[1121]210}
211
[1124]212
[1121]213void G4OpenGLStoredQtViewer::paintGL()
214{
215#ifdef G4DEBUG_VIS_OGL
[1040]216 printf("G4OpenGLStoredQtViewer::paintGL ready:%d fHasTo:%d??\n",fReadyToPaint,fHasToRepaint);
[873]217#endif
[1040]218 if (!fReadyToPaint) {
219 fReadyToPaint= true;
[682]220 return;
221 }
[1039]222 // DO NOT RESIZE IF SIZE HAS NOT CHANGE :
223 // WHEN CLICK ON THE FRAME FOR EXAMPLE
224 // EXECEPT WHEN MOUSE MOVE EVENT
[1040]225 if ( !fHasToRepaint) {
[1141]226#if QT_VERSION < 0x040000
227 if (((getWinWidth() == (unsigned int)width())) &&(getWinHeight() == (unsigned int) height())) {
228#else
[1125]229 // L. Garnier : Trap to get the size with mac OSX 10.6 and Qt 4.6(devel)
230 // Tested on Qt4.5 on mac, 4.4 on windows, 4.5 on unbuntu
231 int sw = 0;
232 int sh = 0;
233 if (!isMaximized() && !isFullScreen()) {
234 sw = normalGeometry().width();
235 sh = normalGeometry().height();
236 } else {
237 sw = frameGeometry().width();
238 sh = frameGeometry().height();
239 }
[1126]240 if ((getWinWidth() == (unsigned int)sw) &&(getWinHeight() == (unsigned int)sh)) {
[1141]241#endif
[1039]242 return;
243 }
244 }
245#ifdef G4DEBUG_VIS_OGL
[1040]246 printf("G4OpenGLStoredQtViewer::paintGL VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV ready %d\n",fReadyToPaint);
[1039]247#endif
[873]248
[1141]249 SetView();
[1039]250
[1141]251 ClearView (); //ok, put the background correct
[1039]252 ComputeView();
253
[1040]254 fHasToRepaint =false;
[1039]255
[911]256#ifdef G4DEBUG_VIS_OGL
[1124]257 printf("G4OpenGLStoredQtViewer::paintGL ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ready %d\n",fReadyToPaint);
[608]258#endif
[682]259}
[564]260
261void G4OpenGLStoredQtViewer::mousePressEvent(QMouseEvent *event)
262{
[1124]263 G4MousePressEvent(event);
[564]264}
265
[696]266void G4OpenGLStoredQtViewer::keyPressEvent (QKeyEvent * event)
267{
268 G4keyPressEvent(event);
269}
270
[804]271void G4OpenGLStoredQtViewer::wheelEvent (QWheelEvent * event)
272{
273 G4wheelEvent(event);
274}
275
[678]276/**
277 * This function was build in order to make a zoom on double clic event.
278 * It was think to build a rubberband on the zoom area, but never work fine
279 */
[955]280void G4OpenGLStoredQtViewer::mouseDoubleClickEvent(QMouseEvent *)
[673]281{
[873]282 G4MouseDoubleClickEvent();
[673]283}
284
[955]285void G4OpenGLStoredQtViewer::mouseReleaseEvent(QMouseEvent *)
[673]286{
[797]287 G4MouseReleaseEvent();
[673]288}
289
[564]290void G4OpenGLStoredQtViewer::mouseMoveEvent(QMouseEvent *event)
291{
[873]292 G4MouseMoveEvent(event);
[564]293}
294
295
296void G4OpenGLStoredQtViewer::contextMenuEvent(QContextMenuEvent *e)
297{
[873]298 G4manageContextMenuEvent(e);
[564]299}
300
301void G4OpenGLStoredQtViewer::updateQWidget() {
[1040]302 fHasToRepaint= true;
[564]303 updateGL();
[1040]304 fHasToRepaint= false;
[564]305}
306
[877]307void G4OpenGLStoredQtViewer::ShowView (
308)
309//////////////////////////////////////////////////////////////////////////////
310//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
311{
312#if QT_VERSION < 0x040000
313 setActiveWindow();
314#else
315 activateWindow();
316#endif
317}
[673]318
[531]319#endif
Note: See TracBrowser for help on using the repository browser.