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