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