source: trunk/geant4/visualization/OpenGL/src/G4OpenGLStoredQtViewer.cc @ 658

Last change on this file since 658 was 652, checked in by garnier, 17 years ago

ajout du EPS vectoriel ticket #100

  • Property svn:mime-type set to text/cpp
File size: 9.6 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//
[635]27// $Id: G4OpenGLStoredQtViewer.cc,v 1.6 2007/11/15 18:24:28 lgarnier Exp $
[593]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
[635]36#define GEANT4_QT_DEBUG
[610]37
[533]38#include "G4OpenGLStoredQtViewer.hh"
[635]39#include "G4VisManager.hh"
[531]40
41#include "G4ios.hh"
42
[595]43//#include <qmouseevent.h>
44#include <qevent.h> // include <qcontextmenuevent.h>
[593]45
[533]46G4OpenGLStoredQtViewer::G4OpenGLStoredQtViewer
[531]47(G4OpenGLStoredSceneHandler& sceneHandler,
48 const G4String&  name):
[564]49 G4VViewer (sceneHandler, sceneHandler.IncrementViewCount (), name),
50 G4OpenGLViewer (sceneHandler),
51 G4OpenGLQtViewer (sceneHandler),
52 G4OpenGLStoredViewer (sceneHandler),
53 QGLWidget()                      // FIXME : gerer le pb du parent !
54 {
55   nbPaint =0;
56   hasToRepaint =false;
[531]57  if (fViewId < 0) return;  // In case error in base class instantiation.
58}
59
[564]60G4OpenGLStoredQtViewer::~G4OpenGLStoredQtViewer() {
[608]61#ifdef GEANT4_QT_DEBUG
[564]62   printf("GLWidget::~GLWidget \n");
[608]63#endif
[579]64   makeCurrent();
65   // this is connect to the Dialog for deleting it properly
66   // when close event.
67   //   ((QDialog*)window())->reject();
[608]68#ifdef GEANT4_QT_DEBUG
[564]69   printf("GLWidget::~GLWidget END\n");
[608]70#endif
[564]71}
[531]72
[564]73void G4OpenGLStoredQtViewer::Initialise() {
[608]74#ifdef GEANT4_QT_DEBUG
[564]75   printf("GLWidget::Initialise \n");
[608]76#endif
[564]77   readyToPaint = false;
78   CreateGLQtContext ();
[608]79#ifdef GEANT4_QT_DEBUG
[564]80   printf("G4OpenGLStoredQtViewer::Initialise () 2\n");
[608]81#endif
[564]82  CreateMainWindow (this);
[608]83#ifdef GEANT4_QT_DEBUG
[564]84  printf("G4OpenGLStoredQtViewer::Initialise () 3\n");
[608]85#endif
[564]86  CreateFontLists ();  // FIXME Does nothing!
87 
[608]88#ifdef GEANT4_QT_DEBUG
[564]89  printf("readyToPaint = true \n");
[608]90#endif
[564]91  readyToPaint = true;
92 
93  // First Draw
94  SetView();
[608]95#ifdef GEANT4_QT_DEBUG
[564]96  printf("    ClearView\n");
[608]97#endif
[564]98  ClearView (); //ok, put the background correct
99  ShowView();
100  FinishView();
101}
[531]102
[564]103void G4OpenGLStoredQtViewer::initializeGL () {
104
105   InitializeGLView ();
106
[608]107#ifdef GEANT4_QT_DEBUG
[564]108   printf("G4OpenGLStoredQtViewer::InitialiseGL () 1\n");
[608]109#endif
[564]110
111   // clear the buffers and window.
112   ClearView ();
113   //   printf("G4OpenGLStoredQtViewer::InitialiseGL () 2\n");
114   FinishView ();
115   
116   glDepthFunc (GL_LEQUAL);
117   glDepthMask (GL_TRUE);
118
119   hasToRepaint =true;
120
[608]121#ifdef GEANT4_QT_DEBUG
[564]122   printf("G4OpenGLStoredQtViewer::InitialiseGL  -------------------------------------------------------------------------------------\n");
[608]123#endif
[531]124}
125
[564]126
[533]127void G4OpenGLStoredQtViewer::DrawView () {
[531]128
[608]129#ifdef GEANT4_QT_DEBUG
[564]130  printf("G4OpenGLStoredQtViewer::DrawView %d %d   VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV\n",WinSize_x, WinSize_y);
[608]131#endif
[564]132   G4ViewParameters::DrawingStyle style = GetViewParameters().GetDrawingStyle();
[531]133
[564]134   //Make sure current viewer is attached and clean...
135   //Qt version needed
[652]136   //   glViewport (0, 0, WinSize_x, WinSize_y);
[531]137
[564]138   //See if things have changed from last time and remake if necessary...
139   // The fNeedKernelVisit flag might have been set by the user in
140   // /vis/viewer/rebuild, but if not, make decision and set flag only
141   // if necessary...
[565]142   if (!fNeedKernelVisit)
143
[564]144   if (!fNeedKernelVisit) KernelVisitDecision ();
[565]145   
[564]146   G4bool kernelVisitWasNeeded = fNeedKernelVisit; // Keep (ProcessView resets).
147   ProcessView ();
148   
[531]149
[564]150   if(style!=G4ViewParameters::hlr &&
151      haloing_enabled) {
[608]152#ifdef GEANT4_QT_DEBUG
[564]153     printf("G4OpenGLStoredQtViewer::DrawView DANS LE IF\n");
[608]154#endif
[531]155
[564]156     HaloingFirstPass ();
157     DrawDisplayLists ();
158     glFlush ();
[531]159
[564]160     HaloingSecondPass ();
[531]161
[564]162     DrawDisplayLists ();
[565]163     FinishView ();
[531]164
[564]165   } else {
[608]166#ifdef GEANT4_QT_DEBUG
[565]167     printf("***************************  CASE 1 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \n");
[608]168#endif
[564]169     
170     // If kernel visit was needed, drawing and FinishView will already
171     // have been done, so...
172     if (!kernelVisitWasNeeded) {
[608]173#ifdef GEANT4_QT_DEBUG
[565]174       printf("***************************  CASE 2 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \n");
[608]175#endif
[564]176       DrawDisplayLists ();
[565]177       FinishView ();
[564]178     } else {
[608]179#ifdef GEANT4_QT_DEBUG
[565]180       printf("***************************  CASE 3 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \n");
[608]181#endif
[564]182       // However, union cutaways are implemented in DrawDisplayLists, so make
183       // an extra pass...
184       if (fVP.IsCutaway() &&
185           fVP.GetCutawayMode() == G4ViewParameters::cutawayUnion) {
186         ClearView();
187         DrawDisplayLists ();
[565]188         FinishView ();
[608]189#ifdef GEANT4_QT_DEBUG
[565]190         printf("***************************  CASE 4 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \n");
[608]191#endif
[565]192       } else { // ADD TO AVOID KernelVisit=1 and nothing to display
193         DrawDisplayLists ();
194         FinishView ();
[564]195       }
196     }
197   }
198
[608]199#ifdef GEANT4_QT_DEBUG
[565]200   printf("G4OpenGLStoredQtViewer::DrawView %d %d ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \n",WinSize_x, WinSize_y);
[608]201#endif
[564]202   hasToRepaint =true;
[531]203}
204
[564]205
[531]206//////////////////////////////////////////////////////////////////////////////
[533]207void G4OpenGLStoredQtViewer::FinishView (
[531]208)
209//////////////////////////////////////////////////////////////////////////////
210//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
211{
[608]212#ifdef GEANT4_QT_DEBUG
[564]213  printf("G4OpenGLStoredQtViewer::FinishView VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV\n");
[608]214#endif
[531]215
216  glFlush ();
[564]217  swapBuffers ();
[608]218#ifdef GEANT4_QT_DEBUG
[564]219  printf("G4OpenGLStoredQtViewer::FinishView ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \n");
[608]220#endif
[564]221
[531]222}
223
[564]224
225/**
226 - Lors du resize de la fenetre, on doit non pas redessiner le detecteur, mais aussi les evenements
227 */
228void G4OpenGLStoredQtViewer::resizeGL(
229 int aWidth
230,int aHeight)
231
232  glViewport(0, 0, aWidth, aHeight);
233  glMatrixMode(GL_PROJECTION);
234  glMatrixMode(GL_MODELVIEW);
235
236   if (((WinSize_x != (G4int)aWidth)) || (WinSize_y != (G4int) aHeight)) {
237     hasToRepaint =true;
238   }
239   WinSize_x = (G4int) aWidth;
240   WinSize_y = (G4int) aHeight;
241
[608]242#ifdef GEANT4_QT_DEBUG
[564]243  printf("G4OpenGLStoredQtViewer::resizeGL ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ %d %d=%d %d=%d\n",hasToRepaint,width(),aWidth,height(),aHeight);
[608]244#endif
[564]245}
246
247
248
249void G4OpenGLStoredQtViewer::paintGL()
250 {
251   if (!readyToPaint) {
[608]252#ifdef GEANT4_QT_DEBUG
[579]253     printf("G4OpenGLStoredQtViewer::paintGL ============  Not ready %d\n",readyToPaint);
[608]254#endif
[564]255     readyToPaint= true;
256     return;
257   }
258   // DO NOT RESIZE IF SIZE HAS NOT CHANGE :
259   //    WHEN CLICK ON THE FRAME FOR EXAMPLE
260   //    EXECEPT WHEN MOUSE MOVE EVENT
261   if ( !hasToRepaint) {
262     if (((WinSize_x == (G4int)width())) &&(WinSize_y == (G4int) height())) {
[608]263#ifdef GEANT4_QT_DEBUG
[579]264       printf("G4OpenGLStoredQtViewer::paintGL ============  Dont repaint\n");
[608]265#endif
[564]266       return;
267     }
268   }
269   nbPaint++;
[608]270#ifdef GEANT4_QT_DEBUG
[579]271   printf("G4OpenGLStoredQtViewer::paintGL VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV %d ready %d\n",nbPaint,readyToPaint);
[608]272#endif
[564]273   WinSize_x = (G4int) width();
274   WinSize_y = (G4int) height();
275   
276   glViewport (0, 0, width(), height());
277   //   glLoadIdentity();
278   
279
280   SetView();
281
282//   //  printf("before ClearView\n");
[608]283#ifdef GEANT4_QT_DEBUG
[564]284   printf("    ClearView\n");
[608]285#endif
[564]286   
287   ClearView (); //ok, put the background correct
288   DrawView();
289
290   hasToRepaint =false;
291
[608]292#ifdef GEANT4_QT_DEBUG
[579]293   printf("G4OpenGLStoredQtViewer::paintGL ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ %d ready %d\n",nbPaint,readyToPaint);
[608]294#endif
[564]295 }
296
297void G4OpenGLStoredQtViewer::mousePressEvent(QMouseEvent *event)
298{
[608]299#ifdef GEANT4_QT_DEBUG
[564]300  printf("G4OpenGLStoredQtViewer::mousePressEvent\n");
[608]301#endif
[564]302  G4MousePressEvent(event->pos());
303}
304
305void G4OpenGLStoredQtViewer::mouseMoveEvent(QMouseEvent *event)
306{
[606]307#if QT_VERSION < 0x040000
[621]308  G4MouseMoveEvent(event->x(),event->y(),event->state());
[606]309#else
310  G4MouseMoveEvent(event->x(),event->y(),event->buttons());
311#endif
[564]312  //  DrawView();
313}
314
315
316void G4OpenGLStoredQtViewer::contextMenuEvent(QContextMenuEvent *e)
317{
[635]318#ifdef GEANT4_QT_DEBUG
319  printf("G4OpenGLStoredQtViewer::contextMenuEvent\n");
320#endif
[564]321  manageContextMenuEvent(e);
322}
323
324void G4OpenGLStoredQtViewer::updateQWidget() {
325  hasToRepaint= true;
326  updateGL();
327  hasToRepaint= false;
328}
329
[531]330#endif
Note: See TracBrowser for help on using the repository browser.