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