| [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 | //
|
|---|
| [1141] | 27 | // $Id: G4OpenGLImmediateQtViewer.cc,v 1.17 2009/11/03 11:02:32 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 | #if QT_VERSION < 0x040000
|
|---|
| 51 | setFocusPolicy(QWidget::StrongFocus); // enable keybord events
|
|---|
| 52 | #else
|
|---|
| 53 | setFocusPolicy(Qt::StrongFocus); // enable keybord events
|
|---|
| 54 | #endif
|
|---|
| [1040] | 55 | fHasToRepaint =false;
|
|---|
| [873] | 56 |
|
|---|
| [531] | 57 | if (fViewId < 0) return; // In case error in base class instantiation.
|
|---|
| 58 | }
|
|---|
| 59 |
|
|---|
| [551] | 60 | G4OpenGLImmediateQtViewer::~G4OpenGLImmediateQtViewer() {
|
|---|
| [873] | 61 | makeCurrent();
|
|---|
| [551] | 62 | }
|
|---|
| 63 |
|
|---|
| [543] | 64 | void G4OpenGLImmediateQtViewer::Initialise() {
|
|---|
| [911] | 65 | #ifdef G4DEBUG_VIS_OGL
|
|---|
| [873] | 66 | printf("G4OpenGLImmediateQtViewer::Initialise \n");
|
|---|
| [608] | 67 | #endif
|
|---|
| [1040] | 68 | fReadyToPaint = false;
|
|---|
| [873] | 69 | CreateMainWindow (this,QString(fName));
|
|---|
| 70 | CreateFontLists ();
|
|---|
| [541] | 71 |
|
|---|
| [1040] | 72 | fReadyToPaint = true;
|
|---|
| [550] | 73 | }
|
|---|
| 74 |
|
|---|
| [551] | 75 | void G4OpenGLImmediateQtViewer::initializeGL () {
|
|---|
| [550] | 76 |
|
|---|
| [873] | 77 | InitializeGLView ();
|
|---|
| [550] | 78 |
|
|---|
| [531] | 79 |
|
|---|
| [873] | 80 | // If a double buffer context has been forced upon us, ignore the
|
|---|
| 81 | // back buffer for this OpenGLImmediate view.
|
|---|
| 82 | // glDrawBuffer (GL_FRONT); // FIXME : Ne marche pas avec cette ligne, mais affiche le run correctement...
|
|---|
| 83 | // clear the buffers and window.
|
|---|
| 84 | ClearView ();
|
|---|
| 85 | FinishView ();
|
|---|
| [531] | 86 |
|
|---|
| [873] | 87 | glDepthFunc (GL_LEQUAL);
|
|---|
| 88 | glDepthMask (GL_TRUE);
|
|---|
| [541] | 89 |
|
|---|
| [873] | 90 | if (fSceneHandler.GetScene() == 0) {
|
|---|
| [1040] | 91 | fHasToRepaint =false;
|
|---|
| [873] | 92 | } else {
|
|---|
| [1040] | 93 | fHasToRepaint =true;
|
|---|
| [873] | 94 | }
|
|---|
| [551] | 95 |
|
|---|
| [877] | 96 | }
|
|---|
| 97 |
|
|---|
| [1125] | 98 |
|
|---|
| [877] | 99 | /** To ensure compatibility with DrawView method
|
|---|
| 100 | */
|
|---|
| 101 | void G4OpenGLImmediateQtViewer::DrawView() {
|
|---|
| [911] | 102 | #ifdef G4DEBUG_VIS_OGL
|
|---|
| [877] | 103 | printf("G4OpenGLImmediateQtViewer::DrawView VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV\n");
|
|---|
| [608] | 104 | #endif
|
|---|
| [1039] | 105 | // That's no the same logic as Stored Viewer, I don't know why...
|
|---|
| 106 | // see G4OpenGLStoredQtViewer::DrawView for more informations
|
|---|
| [877] | 107 |
|
|---|
| [1039] | 108 | updateQWidget();
|
|---|
| [1228] | 109 |
|
|---|
| [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 |
|
|---|
| [877] | 155 |
|
|---|
| [564] | 156 | /**
|
|---|
| [873] | 157 | - Lors du resize de la fenetre, on doit non pas redessiner le detecteur, mais aussi les evenements
|
|---|
| 158 | */
|
|---|
| [539] | 159 | void G4OpenGLImmediateQtViewer::resizeGL(
|
|---|
| [877] | 160 | int aWidth
|
|---|
| 161 | ,int aHeight)
|
|---|
| [564] | 162 | {
|
|---|
| [1228] | 163 | #ifdef G4DEBUG_VIS_OGL
|
|---|
| 164 | printf("\n\nG4OpenGLImmediateQtViewer::resizeGL VVVV\n");
|
|---|
| 165 | #endif
|
|---|
| [1039] | 166 | ResizeWindow(aWidth,aHeight);
|
|---|
| [1040] | 167 | fHasToRepaint = sizeHasChanged();
|
|---|
| [1228] | 168 | #ifdef G4DEBUG_VIS_OGL
|
|---|
| 169 | printf("\n\nG4OpenGLImmediateQtViewer::resizeGL ^^^^^\n");
|
|---|
| 170 | #endif
|
|---|
| [539] | 171 | }
|
|---|
| 172 |
|
|---|
| [559] | 173 |
|
|---|
| [539] | 174 | void G4OpenGLImmediateQtViewer::paintGL()
|
|---|
| [873] | 175 | {
|
|---|
| [911] | 176 | #ifdef G4DEBUG_VIS_OGL
|
|---|
| [1228] | 177 | printf("\n\nG4OpenGLImmediateQtViewer::paintGL ?? %d W:%d H:%d \n",fHasToRepaint,getWinWidth(),getWinHeight());
|
|---|
| [608] | 178 | #endif
|
|---|
| [1040] | 179 | if (!fReadyToPaint) {
|
|---|
| 180 | fReadyToPaint= true;
|
|---|
| [1039] | 181 | return;
|
|---|
| 182 | }
|
|---|
| [1228] | 183 | if ((getWinWidth() == 0) && (getWinHeight() == 0)) {
|
|---|
| 184 | return;
|
|---|
| 185 | }
|
|---|
| 186 |
|
|---|
| [1039] | 187 | // DO NOT RESIZE IF SIZE HAS NOT CHANGE
|
|---|
| [1040] | 188 | if ( !fHasToRepaint) {
|
|---|
| [1141] | 189 | #if QT_VERSION < 0x040000
|
|---|
| 190 | if (((getWinWidth() == (unsigned int)width())) &&(getWinHeight() == (unsigned int) height())) {
|
|---|
| [1227] | 191 | return;
|
|---|
| 192 | }
|
|---|
| [1141] | 193 | #else
|
|---|
| [1131] | 194 | // L. Garnier : Trap to get the size with mac OSX 10.6 and Qt 4.6(devel)
|
|---|
| 195 | // Tested on Qt4.5 on mac, 4.4 on windows, 4.5 on unbuntu
|
|---|
| 196 | int sw = 0;
|
|---|
| 197 | int sh = 0;
|
|---|
| 198 | if (!isMaximized() && !isFullScreen()) {
|
|---|
| 199 | sw = normalGeometry().width();
|
|---|
| 200 | sh = normalGeometry().height();
|
|---|
| 201 | } else {
|
|---|
| 202 | sw = frameGeometry().width();
|
|---|
| 203 | sh = frameGeometry().height();
|
|---|
| 204 | }
|
|---|
| 205 | if ((getWinWidth() == (unsigned int)sw) &&(getWinHeight() == (unsigned int)sh)) {
|
|---|
| [1039] | 206 | return;
|
|---|
| [1227] | 207 |
|
|---|
| 208 | } else if ((sw == 0) && (sh == 0)) { // NOT A TOP LEVEL WIDGET
|
|---|
| 209 | if (((getWinWidth() == (unsigned int)width())) &&(getWinHeight() == (unsigned int) height())) {
|
|---|
| [1228] | 210 | return;
|
|---|
| [1227] | 211 | }
|
|---|
| [1038] | 212 | }
|
|---|
| [1227] | 213 | #endif
|
|---|
| [873] | 214 | }
|
|---|
| [911] | 215 | #ifdef G4DEBUG_VIS_OGL
|
|---|
| [1040] | 216 | printf("G4OpenGLImmediateQtViewer::paintGL VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV ready %d\n",fReadyToPaint);
|
|---|
| [873] | 217 | #endif
|
|---|
| [541] | 218 |
|
|---|
| [1039] | 219 | SetView();
|
|---|
| 220 |
|
|---|
| 221 | ClearView (); //ok, put the background correct
|
|---|
| 222 | ComputeView();
|
|---|
| 223 |
|
|---|
| [1040] | 224 | fHasToRepaint = false; // could be set to false by ComputeView
|
|---|
| [1039] | 225 |
|
|---|
| [911] | 226 | #ifdef G4DEBUG_VIS_OGL
|
|---|
| [1040] | 227 | printf("G4OpenGLImmediateQtViewer::paintGL ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ready %d\n\n\n",fReadyToPaint);
|
|---|
| [608] | 228 | #endif
|
|---|
| [873] | 229 | }
|
|---|
| [551] | 230 |
|
|---|
| [873] | 231 | void G4OpenGLImmediateQtViewer::mousePressEvent(QMouseEvent *event)
|
|---|
| 232 | {
|
|---|
| 233 | G4MousePressEvent(event);
|
|---|
| 234 | }
|
|---|
| 235 |
|
|---|
| 236 | void G4OpenGLImmediateQtViewer::keyPressEvent (QKeyEvent * event)
|
|---|
| 237 | {
|
|---|
| 238 | G4keyPressEvent(event);
|
|---|
| 239 | }
|
|---|
| 240 |
|
|---|
| 241 | void G4OpenGLImmediateQtViewer::wheelEvent (QWheelEvent * event)
|
|---|
| 242 | {
|
|---|
| 243 | G4wheelEvent(event);
|
|---|
| 244 | }
|
|---|
| 245 |
|
|---|
| 246 | /**
|
|---|
| 247 | * This function was build in order to make a zoom on double clic event.
|
|---|
| 248 | * It was think to build a rubberband on the zoom area, but never work fine
|
|---|
| 249 | */
|
|---|
| [955] | 250 | void G4OpenGLImmediateQtViewer::mouseDoubleClickEvent(QMouseEvent *)
|
|---|
| [873] | 251 | {
|
|---|
| 252 | G4MouseDoubleClickEvent();
|
|---|
| 253 | }
|
|---|
| 254 |
|
|---|
| [955] | 255 | void G4OpenGLImmediateQtViewer::mouseReleaseEvent(QMouseEvent *)
|
|---|
| [873] | 256 | {
|
|---|
| 257 | G4MouseReleaseEvent();
|
|---|
| 258 | }
|
|---|
| 259 |
|
|---|
| 260 | void G4OpenGLImmediateQtViewer::mouseMoveEvent(QMouseEvent *event)
|
|---|
| 261 | {
|
|---|
| 262 | G4MouseMoveEvent(event);
|
|---|
| 263 | }
|
|---|
| 264 |
|
|---|
| 265 |
|
|---|
| 266 | void G4OpenGLImmediateQtViewer::contextMenuEvent(QContextMenuEvent *e)
|
|---|
| 267 | {
|
|---|
| 268 | G4manageContextMenuEvent(e);
|
|---|
| 269 | }
|
|---|
| 270 |
|
|---|
| [1228] | 271 | void G4OpenGLImmediateQtViewer::paintEvent(QPaintEvent *event) {
|
|---|
| 272 | // fHasToRepaint= false;
|
|---|
| 273 | #ifdef G4DEBUG_VIS_OGL
|
|---|
| 274 | printf("\n\nG4OpenGLImmediateQtViewer::paintEvent VVVVVVVVV\n");
|
|---|
| 275 | #endif
|
|---|
| 276 | updateGL();
|
|---|
| 277 | #ifdef G4DEBUG_VIS_OGL
|
|---|
| 278 | printf("\n\nG4OpenGLImmediateQtViewer::paintEvent ^^^^^^^^^\n");
|
|---|
| 279 | #endif
|
|---|
| 280 | }
|
|---|
| 281 |
|
|---|
| 282 |
|
|---|
| [564] | 283 | void G4OpenGLImmediateQtViewer::updateQWidget() {
|
|---|
| [1040] | 284 | fHasToRepaint= true;
|
|---|
| [1228] | 285 | #ifdef G4DEBUG_VIS_OGL
|
|---|
| 286 | printf("\n\nG4OpenGLImmediateQtViewer::updateQWidget VVVVVVVVV\n");
|
|---|
| 287 | #endif
|
|---|
| [564] | 288 | updateGL();
|
|---|
| [1228] | 289 | #ifdef G4DEBUG_VIS_OGL
|
|---|
| 290 | printf("\n\nG4OpenGLImmediateQtViewer::updateQWidget ^^^^^^^^^\n");
|
|---|
| 291 | #endif
|
|---|
| [1040] | 292 | fHasToRepaint= false;
|
|---|
| [564] | 293 | }
|
|---|
| [551] | 294 |
|
|---|
| [877] | 295 |
|
|---|
| 296 | void G4OpenGLImmediateQtViewer::ShowView (
|
|---|
| 297 | )
|
|---|
| 298 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 299 | //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
|
|---|
| 300 | {
|
|---|
| [1228] | 301 | #ifdef G4DEBUG_VIS_OGL
|
|---|
| 302 | printf("\n\nG4OpenGLImmediateQtViewer::ShowView VVVV\n");
|
|---|
| 303 | #endif
|
|---|
| [877] | 304 | #if QT_VERSION < 0x040000
|
|---|
| 305 | setActiveWindow();
|
|---|
| 306 | #else
|
|---|
| 307 | activateWindow();
|
|---|
| [531] | 308 | #endif
|
|---|
| [1228] | 309 | #ifdef G4DEBUG_VIS_OGL
|
|---|
| 310 | printf("\n\nG4OpenGLImmediateQtViewer::ShowView ^^^^^\n");
|
|---|
| 311 | #endif
|
|---|
| [877] | 312 | }
|
|---|
| 313 | #endif
|
|---|