source: trunk/geant4/visualization/OpenGL/src/G4OpenGLImmediateQtViewer.cc @ 606

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

r647@mac-90108: laurentgarnier | 2007-11-15 11:32:46 +0100
Ok en Qt 4.3.0

  • Property svn:mime-type set to text/cpp
File size: 6.7 KB
Line 
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//
27// $Id: G4OpenGLImmediateQtViewer.cc,v 1.2 2007/11/13 17:48:51 lgarnier Exp $
28// GEANT4 tag $Name:  $
29//
30//
31// Class G4OpenGLImmediateQtViewer : a class derived from G4OpenGLQtViewer and
32//                                G4OpenGLImmediateViewer.
33
34#ifdef G4VIS_BUILD_OPENGLQT_DRIVER
35
36#include "G4OpenGLImmediateQtViewer.hh"
37#include "G4VisManager.hh"
38
39#include "G4ios.hh"
40
41G4OpenGLImmediateQtViewer::G4OpenGLImmediateQtViewer
42(G4OpenGLImmediateSceneHandler& sceneHandler,
43 const G4String&  name):
44 G4VViewer (sceneHandler, sceneHandler.IncrementViewCount (), name),
45 G4OpenGLViewer (sceneHandler),
46 G4OpenGLQtViewer (sceneHandler),
47 G4OpenGLImmediateViewer (sceneHandler),
48 QGLWidget()                      // FIXME : gerer le pb du parent !
49 {
50   nbPaint =0;
51  if (fViewId < 0) return;  // In case error in base class instantiation.
52}
53
54G4OpenGLImmediateQtViewer::~G4OpenGLImmediateQtViewer() {
55   printf("GLWidget::~GLWidget \n");
56     makeCurrent();
57   printf("GLWidget::~GLWidget END\n");
58}
59
60void G4OpenGLImmediateQtViewer::Initialise() {
61   printf("GLWidget::Initialise \n");
62   printf("readyToPaint = false \n");
63   readyToPaint = false;
64   CreateGLQtContext ();
65   printf("G4OpenGLImmediateQtViewer::Initialise () 2\n");
66
67  CreateMainWindow (this);
68  printf("G4OpenGLImmediateQtViewer::Initialise () 3\n");
69
70  CreateFontLists ();  // FIXME Does nothing!
71 
72  printf("readyToPaint = true \n");
73  readyToPaint = true;
74 
75  // First Draw
76  SetView();
77  printf("    ClearView\n");
78  ClearView (); //ok, put the background correct
79  ShowView();
80  FinishView();
81}
82
83void G4OpenGLImmediateQtViewer::initializeGL () {
84
85   InitializeGLView ();
86
87   printf("G4OpenGLImmediateQtViewer::InitialiseGL () 1\n");
88
89   // If a double buffer context has been forced upon us, ignore the
90   // back buffer for this OpenGLImmediate view.
91   glDrawBuffer (GL_FRONT); // FIXME : Ne marche pas avec cette ligne, mais affiche le run correctement...
92   // clear the buffers and window.
93   ClearView ();
94   //   printf("G4OpenGLImmediateQtViewer::InitialiseGL () 2\n");
95   FinishView ();
96   
97
98
99   glDepthFunc (GL_LEQUAL);
100   glDepthMask (GL_TRUE);
101
102   printf("G4OpenGLImmediateQtViewer::InitialiseGL  -------------------------------------------------------------------------------------\n");
103}
104
105
106void G4OpenGLImmediateQtViewer::DrawView () {
107
108  printf("G4OpenGLImmediateQtViewer::DrawView %d %d   VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV\n",WinSize_x, WinSize_y);
109   // If a double buffer context has been forced upon us, ignore the
110   // back buffer for this OpenGLImmediate view.
111  glDrawBuffer (GL_FRONT);
112
113   G4ViewParameters::DrawingStyle style = GetViewParameters().GetDrawingStyle();
114
115   //Make sure current viewer is attached and clean...
116   //Qt version needed
117   glViewport (0, 0, WinSize_x, WinSize_y);
118
119   if(style!=G4ViewParameters::hlr &&
120      haloing_enabled) {
121     printf("G4OpenGLImmediateQtViewer::DrawView DANS LE IF\n");
122
123     HaloingFirstPass ();
124     NeedKernelVisit ();
125     ProcessView ();
126     glFlush ();
127
128     HaloingSecondPass ();
129
130   }
131
132   NeedKernelVisit ();  // Always need to visit G4 kernel.
133   ProcessView ();
134   FinishView ();
135  printf("G4OpenGLImmediateQtViewer::DrawView %d %d ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \n",WinSize_x, WinSize_y);
136  readyToPaint = false;
137}
138
139
140//////////////////////////////////////////////////////////////////////////////
141void G4OpenGLImmediateQtViewer::FinishView (
142)
143//////////////////////////////////////////////////////////////////////////////
144//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
145{
146  printf("G4OpenGLImmediateQtViewer::FinishView VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV\n");
147
148   glFlush ();
149  printf("G4OpenGLImmediateQtViewer::FinishView ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \n");
150
151}
152
153
154/**
155 - Lors du resize de la fenetre, on doit non pas redessiner le detecteur, mais aussi les evenements
156 */
157void G4OpenGLImmediateQtViewer::resizeGL(
158 int width
159,int height)
160
161  int side = width;
162  if (width > height) {
163    side = height;
164  }
165  glViewport((width - side) / 2, (height - side) / 2, side, side);
166  glMatrixMode(GL_PROJECTION);
167  glLoadIdentity();
168  glOrtho(-0.5, +0.5, +0.5, -0.5, 4.0, 15.0);
169  glMatrixMode(GL_MODELVIEW);
170  printf("G4OpenGLImmediateQtViewer::resizeGL ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \n");
171}
172
173
174void G4OpenGLImmediateQtViewer::paintGL()
175 {
176   if (!readyToPaint) {
177     readyToPaint= true;
178     return;
179   }
180   // DO NOT RESIZE IF SIZE HAS NOT CHANGE
181   if (((WinSize_x == (G4int)width())) &&(WinSize_y == (G4int) height())) {
182     return;
183   }
184   nbPaint++;
185   printf("\n\nG4OpenGLImmediateQtViewer::paintGL VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV %d ready %d\n",nbPaint,readyToPaint);
186   WinSize_x = (G4int) width();
187   WinSize_y = (G4int) height();
188
189   glViewport (0, 0, width(), height());
190
191   SetView();
192//   //  printf("before ClearView\n");
193   printf("    ClearView\n");
194   
195   ClearView (); //ok, put the background correct
196   DrawView();
197   readyToPaint = true; // could be set to false by DrawView
198
199
200   printf("G4OpenGLImmediateQtViewer::paintGL ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ %d ready %d\n\n\n",nbPaint,readyToPaint);
201 }
202
203void G4OpenGLImmediateQtViewer::updateQWidget() {
204  updateGL();
205}
206
207#endif
Note: See TracBrowser for help on using the repository browser.