| [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 | //
|
|---|
| [877] | 27 | // $Id: G4OpenGLImmediateQtViewer.cc,v 1.7 2008/11/06 13:43:44 lgarnier Exp $
|
|---|
| [866] | 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"
|
|---|
| [531] | 37 |
|
|---|
| 38 | #include "G4ios.hh"
|
|---|
| 39 |
|
|---|
| [533] | 40 | G4OpenGLImmediateQtViewer::G4OpenGLImmediateQtViewer
|
|---|
| [531] | 41 | (G4OpenGLImmediateSceneHandler& sceneHandler,
|
|---|
| [897] | 42 | const G4String& name):
|
|---|
| [873] | 43 | G4VViewer (sceneHandler, sceneHandler.IncrementViewCount (), name),
|
|---|
| 44 | G4OpenGLViewer (sceneHandler),
|
|---|
| 45 | G4OpenGLQtViewer (sceneHandler),
|
|---|
| 46 | G4OpenGLImmediateViewer (sceneHandler)
|
|---|
| 47 | {
|
|---|
| 48 |
|
|---|
| 49 | //set true to picking
|
|---|
| 50 | fVP.SetPicking(true);
|
|---|
| [896] | 51 | fDefaultVP.SetPicking(true);
|
|---|
| [873] | 52 | #if QT_VERSION < 0x040000
|
|---|
| 53 | setFocusPolicy(QWidget::StrongFocus); // enable keybord events
|
|---|
| 54 | #else
|
|---|
| 55 | setFocusPolicy(Qt::StrongFocus); // enable keybord events
|
|---|
| 56 | #endif
|
|---|
| 57 | hasToRepaint =false;
|
|---|
| 58 |
|
|---|
| [531] | 59 | if (fViewId < 0) return; // In case error in base class instantiation.
|
|---|
| 60 | }
|
|---|
| 61 |
|
|---|
| [551] | 62 | G4OpenGLImmediateQtViewer::~G4OpenGLImmediateQtViewer() {
|
|---|
| [873] | 63 | makeCurrent();
|
|---|
| [551] | 64 | }
|
|---|
| 65 |
|
|---|
| [543] | 66 | void G4OpenGLImmediateQtViewer::Initialise() {
|
|---|
| [873] | 67 | #ifdef G4DEBUG
|
|---|
| 68 | printf("G4OpenGLImmediateQtViewer::Initialise \n");
|
|---|
| [608] | 69 | #endif
|
|---|
| [873] | 70 | readyToPaint = false;
|
|---|
| 71 | CreateMainWindow (this,QString(fName));
|
|---|
| 72 | CreateFontLists ();
|
|---|
| [541] | 73 |
|
|---|
| [552] | 74 | readyToPaint = true;
|
|---|
| [550] | 75 | }
|
|---|
| 76 |
|
|---|
| [551] | 77 | void G4OpenGLImmediateQtViewer::initializeGL () {
|
|---|
| [550] | 78 |
|
|---|
| [873] | 79 | InitializeGLView ();
|
|---|
| [550] | 80 |
|
|---|
| [531] | 81 |
|
|---|
| [873] | 82 | // If a double buffer context has been forced upon us, ignore the
|
|---|
| 83 | // back buffer for this OpenGLImmediate view.
|
|---|
| 84 | // glDrawBuffer (GL_FRONT); // FIXME : Ne marche pas avec cette ligne, mais affiche le run correctement...
|
|---|
| 85 | // clear the buffers and window.
|
|---|
| 86 | ClearView ();
|
|---|
| 87 | FinishView ();
|
|---|
| [531] | 88 |
|
|---|
| [873] | 89 | glDepthFunc (GL_LEQUAL);
|
|---|
| 90 | glDepthMask (GL_TRUE);
|
|---|
| [541] | 91 |
|
|---|
| [873] | 92 | if (fSceneHandler.GetScene() == 0) {
|
|---|
| 93 | hasToRepaint =false;
|
|---|
| 94 | } else {
|
|---|
| 95 | hasToRepaint =true;
|
|---|
| 96 | }
|
|---|
| [551] | 97 |
|
|---|
| [877] | 98 | }
|
|---|
| 99 |
|
|---|
| 100 |
|
|---|
| 101 | /** To ensure compatibility with DrawView method
|
|---|
| 102 | */
|
|---|
| 103 | void G4OpenGLImmediateQtViewer::DrawView() {
|
|---|
| [873] | 104 | #ifdef G4DEBUG
|
|---|
| [877] | 105 | printf("G4OpenGLImmediateQtViewer::DrawView VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV\n");
|
|---|
| [608] | 106 | #endif
|
|---|
| [877] | 107 | // That's no the same logic as Stored Viewer, I don't know why...
|
|---|
| 108 | // see G4OpenGLStoredQtViewer::DrawView for more informations
|
|---|
| 109 |
|
|---|
| 110 | updateQWidget();
|
|---|
| 111 | #ifdef G4DEBUG
|
|---|
| 112 | printf("G4OpenGLImmediateQtViewer::DrawView ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n");
|
|---|
| 113 | #endif
|
|---|
| [531] | 114 | }
|
|---|
| 115 |
|
|---|
| [543] | 116 |
|
|---|
| [877] | 117 | void G4OpenGLImmediateQtViewer::ComputeView () {
|
|---|
| [531] | 118 |
|
|---|
| [873] | 119 | #ifdef G4DEBUG
|
|---|
| [897] | 120 | printf("G4OpenGLImmediateQtViewer::ComputeView %d %d VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV\n",fWinSize_x, fWinSize_y);
|
|---|
| [608] | 121 | #endif
|
|---|
| [877] | 122 | makeCurrent();
|
|---|
| [873] | 123 | // If a double buffer context has been forced upon us, ignore the
|
|---|
| 124 | // back buffer for this OpenGLImmediate view.
|
|---|
| 125 | // glDrawBuffer (GL_FRONT);
|
|---|
| [552] | 126 |
|
|---|
| [873] | 127 | G4ViewParameters::DrawingStyle style = GetViewParameters().GetDrawingStyle();
|
|---|
| [552] | 128 |
|
|---|
| [873] | 129 | //Make sure current viewer is attached and clean...
|
|---|
| 130 | //Qt version needed
|
|---|
| [897] | 131 | // glViewport (0, 0, fWinSize_x, fWinSize_y);
|
|---|
| [552] | 132 |
|
|---|
| [873] | 133 | if(style!=G4ViewParameters::hlr &&
|
|---|
| 134 | haloing_enabled) {
|
|---|
| 135 |
|
|---|
| 136 | HaloingFirstPass ();
|
|---|
| 137 | NeedKernelVisit ();
|
|---|
| 138 | ProcessView ();
|
|---|
| 139 | glFlush ();
|
|---|
| 140 | #ifdef G4DEBUG
|
|---|
| [877] | 141 | printf("G4OpenGLImmediateQtViewer::ComputeView First ProcessView ok\n");
|
|---|
| [608] | 142 | #endif
|
|---|
| [873] | 143 | HaloingSecondPass ();
|
|---|
| [552] | 144 |
|
|---|
| [873] | 145 | }
|
|---|
| [552] | 146 |
|
|---|
| [873] | 147 | NeedKernelVisit (); // Always need to visit G4 kernel.
|
|---|
| 148 | ProcessView ();
|
|---|
| [552] | 149 |
|
|---|
| [873] | 150 | if (isRecording()) {
|
|---|
| 151 | savePPMToTemp();
|
|---|
| 152 | }
|
|---|
| 153 |
|
|---|
| 154 | #ifdef G4DEBUG
|
|---|
| [897] | 155 | printf("G4OpenGLImmediateQtViewer::ComputeView %d %d ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \n",fWinSize_x, fWinSize_y);
|
|---|
| [608] | 156 | #endif
|
|---|
| [873] | 157 | hasToRepaint = true;
|
|---|
| [552] | 158 | }
|
|---|
| 159 |
|
|---|
| [873] | 160 | void G4OpenGLImmediateQtViewer::FinishView()
|
|---|
| [531] | 161 | {
|
|---|
| [877] | 162 | #ifdef G4DEBUG
|
|---|
| 163 | printf("G4OpenGLImmediateQtViewer::FinishView() BEGIN\n");
|
|---|
| 164 | #endif
|
|---|
| 165 | glFlush ();
|
|---|
| 166 | #ifdef G4DEBUG
|
|---|
| 167 | printf("G4OpenGLImmediateQtViewer::FinishView() END\n");
|
|---|
| 168 | #endif
|
|---|
| 169 |
|
|---|
| [531] | 170 | }
|
|---|
| 171 |
|
|---|
| [539] | 172 |
|
|---|
| [564] | 173 | /**
|
|---|
| [873] | 174 | - Lors du resize de la fenetre, on doit non pas redessiner le detecteur, mais aussi les evenements
|
|---|
| 175 | */
|
|---|
| [539] | 176 | void G4OpenGLImmediateQtViewer::resizeGL(
|
|---|
| [877] | 177 | int aWidth
|
|---|
| 178 | ,int aHeight)
|
|---|
| [564] | 179 | {
|
|---|
| [873] | 180 | G4resizeGL(aWidth,aHeight);
|
|---|
| [539] | 181 | }
|
|---|
| 182 |
|
|---|
| [559] | 183 |
|
|---|
| [539] | 184 | void G4OpenGLImmediateQtViewer::paintGL()
|
|---|
| [873] | 185 | {
|
|---|
| 186 | #ifdef G4DEBUG
|
|---|
| 187 | printf("\n\nG4OpenGLImmediateQtViewer::paintGL ??\n");
|
|---|
| [608] | 188 | #endif
|
|---|
| [873] | 189 | if (!readyToPaint) {
|
|---|
| 190 | readyToPaint= true;
|
|---|
| 191 | return;
|
|---|
| 192 | }
|
|---|
| 193 | // DO NOT RESIZE IF SIZE HAS NOT CHANGE
|
|---|
| 194 | if ( !hasToRepaint) {
|
|---|
| [897] | 195 | if (((fWinSize_x == (unsigned int)width())) &&(fWinSize_y == (unsigned int) height())) {
|
|---|
| [873] | 196 | return;
|
|---|
| 197 | }
|
|---|
| 198 | }
|
|---|
| 199 | #ifdef G4DEBUG
|
|---|
| 200 | printf("G4OpenGLImmediateQtViewer::paintGL VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV ready %d\n",readyToPaint);
|
|---|
| 201 | #endif
|
|---|
| [897] | 202 | fWinSize_x = (unsigned int) width();
|
|---|
| 203 | fWinSize_y = (unsigned int) height();
|
|---|
| [541] | 204 |
|
|---|
| [873] | 205 | setupViewport(width(),height());
|
|---|
| [541] | 206 |
|
|---|
| [873] | 207 | SetView();
|
|---|
| [564] | 208 |
|
|---|
| [873] | 209 | ClearView (); //ok, put the background correct
|
|---|
| [877] | 210 | ComputeView();
|
|---|
| [559] | 211 |
|
|---|
| [877] | 212 | hasToRepaint = false; // could be set to false by ComputeView
|
|---|
| [543] | 213 |
|
|---|
| [873] | 214 | #ifdef G4DEBUG
|
|---|
| 215 | printf("G4OpenGLImmediateQtViewer::paintGL ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ready %d\n\n\n",readyToPaint);
|
|---|
| [608] | 216 | #endif
|
|---|
| [873] | 217 | }
|
|---|
| [551] | 218 |
|
|---|
| [873] | 219 | void G4OpenGLImmediateQtViewer::mousePressEvent(QMouseEvent *event)
|
|---|
| 220 | {
|
|---|
| 221 | G4MousePressEvent(event);
|
|---|
| 222 | }
|
|---|
| 223 |
|
|---|
| 224 | void G4OpenGLImmediateQtViewer::keyPressEvent (QKeyEvent * event)
|
|---|
| 225 | {
|
|---|
| 226 | G4keyPressEvent(event);
|
|---|
| 227 | }
|
|---|
| 228 |
|
|---|
| 229 | void G4OpenGLImmediateQtViewer::wheelEvent (QWheelEvent * event)
|
|---|
| 230 | {
|
|---|
| 231 | G4wheelEvent(event);
|
|---|
| 232 | }
|
|---|
| 233 |
|
|---|
| 234 | /**
|
|---|
| 235 | * This function was build in order to make a zoom on double clic event.
|
|---|
| 236 | * It was think to build a rubberband on the zoom area, but never work fine
|
|---|
| 237 | */
|
|---|
| 238 | void G4OpenGLImmediateQtViewer::mouseDoubleClickEvent(QMouseEvent *event)
|
|---|
| 239 | {
|
|---|
| 240 | G4MouseDoubleClickEvent();
|
|---|
| 241 | }
|
|---|
| 242 |
|
|---|
| 243 | void G4OpenGLImmediateQtViewer::mouseReleaseEvent(QMouseEvent *event)
|
|---|
| 244 | {
|
|---|
| 245 | G4MouseReleaseEvent();
|
|---|
| 246 | }
|
|---|
| 247 |
|
|---|
| 248 | void G4OpenGLImmediateQtViewer::mouseMoveEvent(QMouseEvent *event)
|
|---|
| 249 | {
|
|---|
| 250 | G4MouseMoveEvent(event);
|
|---|
| 251 | }
|
|---|
| 252 |
|
|---|
| 253 |
|
|---|
| 254 | void G4OpenGLImmediateQtViewer::contextMenuEvent(QContextMenuEvent *e)
|
|---|
| 255 | {
|
|---|
| 256 | G4manageContextMenuEvent(e);
|
|---|
| 257 | }
|
|---|
| 258 |
|
|---|
| [564] | 259 | void G4OpenGLImmediateQtViewer::updateQWidget() {
|
|---|
| [873] | 260 | hasToRepaint= true;
|
|---|
| [564] | 261 | updateGL();
|
|---|
| [873] | 262 | hasToRepaint= false;
|
|---|
| [564] | 263 | }
|
|---|
| [551] | 264 |
|
|---|
| [877] | 265 |
|
|---|
| 266 | void G4OpenGLImmediateQtViewer::ShowView (
|
|---|
| 267 | )
|
|---|
| 268 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 269 | //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
|
|---|
| 270 | {
|
|---|
| 271 | #if QT_VERSION < 0x040000
|
|---|
| 272 | setActiveWindow();
|
|---|
| 273 | #else
|
|---|
| 274 | activateWindow();
|
|---|
| [531] | 275 | #endif
|
|---|
| [877] | 276 | }
|
|---|
| 277 | #endif
|
|---|