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