[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; |
---|
[1233] | 69 | #ifdef G4DEBUG_VIS_OGL |
---|
| 70 | printf("G4OpenGLImmediateQtViewer::Initialise VVVVVVVVVVVVVVVV \n"); |
---|
| 71 | #endif |
---|
[873] | 72 | CreateMainWindow (this,QString(fName)); |
---|
[1233] | 73 | #ifdef G4DEBUG_VIS_OGL |
---|
| 74 | printf("G4OpenGLImmediateQtViewer::Initialise ^^^^^^^^^^^^^^^^\n"); |
---|
| 75 | #endif |
---|
[873] | 76 | CreateFontLists (); |
---|
[541] | 77 | |
---|
[1040] | 78 | fReadyToPaint = true; |
---|
[1233] | 79 | #ifdef G4DEBUG_VIS_OGL |
---|
| 80 | printf("G4OpenGLImmediateQtViewer::InitialiseGLView * \n"); |
---|
| 81 | #endif |
---|
| 82 | |
---|
| 83 | // L.Garnier 01/2010 Force a update in order to Init GL |
---|
| 84 | // updateGL(); |
---|
| 85 | #ifdef G4DEBUG_VIS_OGL |
---|
| 86 | printf("G4OpenGLImmediateQtViewer::InitialiseGLView end * \n"); |
---|
| 87 | #endif |
---|
[550] | 88 | } |
---|
| 89 | |
---|
[551] | 90 | void G4OpenGLImmediateQtViewer::initializeGL () { |
---|
[1233] | 91 | #ifdef G4DEBUG_VIS_OGL |
---|
| 92 | printf("G4OpenGLImmediateQtViewer::InitialiseGL * \n"); |
---|
| 93 | #endif |
---|
[550] | 94 | |
---|
[873] | 95 | InitializeGLView (); |
---|
[550] | 96 | |
---|
[531] | 97 | |
---|
[873] | 98 | // If a double buffer context has been forced upon us, ignore the |
---|
| 99 | // back buffer for this OpenGLImmediate view. |
---|
| 100 | // glDrawBuffer (GL_FRONT); // FIXME : Ne marche pas avec cette ligne, mais affiche le run correctement... |
---|
| 101 | // clear the buffers and window. |
---|
| 102 | ClearView (); |
---|
| 103 | FinishView (); |
---|
[531] | 104 | |
---|
[873] | 105 | glDepthFunc (GL_LEQUAL); |
---|
| 106 | glDepthMask (GL_TRUE); |
---|
[541] | 107 | |
---|
[873] | 108 | if (fSceneHandler.GetScene() == 0) { |
---|
[1040] | 109 | fHasToRepaint =false; |
---|
[873] | 110 | } else { |
---|
[1040] | 111 | fHasToRepaint =true; |
---|
[873] | 112 | } |
---|
[551] | 113 | |
---|
[877] | 114 | } |
---|
| 115 | |
---|
[1125] | 116 | |
---|
[877] | 117 | /** To ensure compatibility with DrawView method |
---|
| 118 | */ |
---|
| 119 | void G4OpenGLImmediateQtViewer::DrawView() { |
---|
[911] | 120 | #ifdef G4DEBUG_VIS_OGL |
---|
[877] | 121 | printf("G4OpenGLImmediateQtViewer::DrawView VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV\n"); |
---|
[608] | 122 | #endif |
---|
[1039] | 123 | // That's no the same logic as Stored Viewer, I don't know why... |
---|
| 124 | // see G4OpenGLStoredQtViewer::DrawView for more informations |
---|
[877] | 125 | |
---|
[1039] | 126 | updateQWidget(); |
---|
[1228] | 127 | |
---|
[911] | 128 | #ifdef G4DEBUG_VIS_OGL |
---|
[877] | 129 | printf("G4OpenGLImmediateQtViewer::DrawView ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n"); |
---|
| 130 | #endif |
---|
[531] | 131 | } |
---|
| 132 | |
---|
[543] | 133 | |
---|
[877] | 134 | void G4OpenGLImmediateQtViewer::ComputeView () { |
---|
[531] | 135 | |
---|
[911] | 136 | #ifdef G4DEBUG_VIS_OGL |
---|
[1039] | 137 | printf("G4OpenGLImmediateQtViewer::ComputeView %d %d VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV\n",getWinWidth(), getWinHeight()); |
---|
[608] | 138 | #endif |
---|
[877] | 139 | makeCurrent(); |
---|
[873] | 140 | // If a double buffer context has been forced upon us, ignore the |
---|
| 141 | // back buffer for this OpenGLImmediate view. |
---|
| 142 | // glDrawBuffer (GL_FRONT); |
---|
[552] | 143 | |
---|
[873] | 144 | G4ViewParameters::DrawingStyle style = GetViewParameters().GetDrawingStyle(); |
---|
[552] | 145 | |
---|
[873] | 146 | if(style!=G4ViewParameters::hlr && |
---|
| 147 | haloing_enabled) { |
---|
| 148 | |
---|
| 149 | HaloingFirstPass (); |
---|
| 150 | NeedKernelVisit (); |
---|
| 151 | ProcessView (); |
---|
[1240] | 152 | FinishView(); |
---|
[911] | 153 | #ifdef G4DEBUG_VIS_OGL |
---|
[877] | 154 | printf("G4OpenGLImmediateQtViewer::ComputeView First ProcessView ok\n"); |
---|
[608] | 155 | #endif |
---|
[873] | 156 | HaloingSecondPass (); |
---|
[552] | 157 | |
---|
[873] | 158 | } |
---|
[552] | 159 | |
---|
[873] | 160 | NeedKernelVisit (); // Always need to visit G4 kernel. |
---|
| 161 | ProcessView (); |
---|
[552] | 162 | |
---|
[873] | 163 | if (isRecording()) { |
---|
| 164 | savePPMToTemp(); |
---|
| 165 | } |
---|
| 166 | |
---|
[911] | 167 | #ifdef G4DEBUG_VIS_OGL |
---|
[1240] | 168 | printf("G4OpenGLImmediateQtViewer::ComputeView %d %d hasTo:%d^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \n",getWinWidth(), getWinHeight(),fHasToRepaint); |
---|
[608] | 169 | #endif |
---|
[1040] | 170 | fHasToRepaint = true; |
---|
[552] | 171 | } |
---|
| 172 | |
---|
[877] | 173 | |
---|
[564] | 174 | /** |
---|
[873] | 175 | - Lors du resize de la fenetre, on doit non pas redessiner le detecteur, mais aussi les evenements |
---|
| 176 | */ |
---|
[539] | 177 | void G4OpenGLImmediateQtViewer::resizeGL( |
---|
[877] | 178 | int aWidth |
---|
| 179 | ,int aHeight) |
---|
[564] | 180 | { |
---|
[1228] | 181 | #ifdef G4DEBUG_VIS_OGL |
---|
[1233] | 182 | printf("\n\nG4OpenGLImmediateQtViewer::resizeGL VVVV recu : W:%d H:%d\n",aWidth,aHeight); |
---|
[1228] | 183 | #endif |
---|
[1039] | 184 | ResizeWindow(aWidth,aHeight); |
---|
[1040] | 185 | fHasToRepaint = sizeHasChanged(); |
---|
[1228] | 186 | #ifdef G4DEBUG_VIS_OGL |
---|
| 187 | printf("\n\nG4OpenGLImmediateQtViewer::resizeGL ^^^^^\n"); |
---|
| 188 | #endif |
---|
[539] | 189 | } |
---|
| 190 | |
---|
[559] | 191 | |
---|
[539] | 192 | void G4OpenGLImmediateQtViewer::paintGL() |
---|
[873] | 193 | { |
---|
[911] | 194 | #ifdef G4DEBUG_VIS_OGL |
---|
[1228] | 195 | printf("\n\nG4OpenGLImmediateQtViewer::paintGL ?? %d W:%d H:%d \n",fHasToRepaint,getWinWidth(),getWinHeight()); |
---|
[608] | 196 | #endif |
---|
[1040] | 197 | if (!fReadyToPaint) { |
---|
| 198 | fReadyToPaint= true; |
---|
[1039] | 199 | return; |
---|
| 200 | } |
---|
[1228] | 201 | if ((getWinWidth() == 0) && (getWinHeight() == 0)) { |
---|
| 202 | return; |
---|
| 203 | } |
---|
| 204 | |
---|
[1039] | 205 | // DO NOT RESIZE IF SIZE HAS NOT CHANGE |
---|
[1040] | 206 | if ( !fHasToRepaint) { |
---|
[1141] | 207 | #if QT_VERSION < 0x040000 |
---|
| 208 | if (((getWinWidth() == (unsigned int)width())) &&(getWinHeight() == (unsigned int) height())) { |
---|
[1227] | 209 | return; |
---|
| 210 | } |
---|
[1141] | 211 | #else |
---|
[1131] | 212 | // L. Garnier : Trap to get the size with mac OSX 10.6 and Qt 4.6(devel) |
---|
| 213 | // Tested on Qt4.5 on mac, 4.4 on windows, 4.5 on unbuntu |
---|
| 214 | int sw = 0; |
---|
| 215 | int sh = 0; |
---|
| 216 | if (!isMaximized() && !isFullScreen()) { |
---|
| 217 | sw = normalGeometry().width(); |
---|
| 218 | sh = normalGeometry().height(); |
---|
| 219 | } else { |
---|
| 220 | sw = frameGeometry().width(); |
---|
| 221 | sh = frameGeometry().height(); |
---|
| 222 | } |
---|
| 223 | if ((getWinWidth() == (unsigned int)sw) &&(getWinHeight() == (unsigned int)sh)) { |
---|
[1039] | 224 | return; |
---|
[1227] | 225 | |
---|
| 226 | } else if ((sw == 0) && (sh == 0)) { // NOT A TOP LEVEL WIDGET |
---|
| 227 | if (((getWinWidth() == (unsigned int)width())) &&(getWinHeight() == (unsigned int) height())) { |
---|
[1228] | 228 | return; |
---|
[1227] | 229 | } |
---|
[1038] | 230 | } |
---|
[1227] | 231 | #endif |
---|
[873] | 232 | } |
---|
[911] | 233 | #ifdef G4DEBUG_VIS_OGL |
---|
[1040] | 234 | printf("G4OpenGLImmediateQtViewer::paintGL VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV ready %d\n",fReadyToPaint); |
---|
[873] | 235 | #endif |
---|
[541] | 236 | |
---|
[1039] | 237 | SetView(); |
---|
| 238 | |
---|
| 239 | ClearView (); //ok, put the background correct |
---|
| 240 | ComputeView(); |
---|
| 241 | |
---|
[1040] | 242 | fHasToRepaint = false; // could be set to false by ComputeView |
---|
[1039] | 243 | |
---|
[911] | 244 | #ifdef G4DEBUG_VIS_OGL |
---|
[1040] | 245 | printf("G4OpenGLImmediateQtViewer::paintGL ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ready %d\n\n\n",fReadyToPaint); |
---|
[608] | 246 | #endif |
---|
[873] | 247 | } |
---|
[551] | 248 | |
---|
[873] | 249 | void G4OpenGLImmediateQtViewer::mousePressEvent(QMouseEvent *event) |
---|
| 250 | { |
---|
| 251 | G4MousePressEvent(event); |
---|
| 252 | } |
---|
| 253 | |
---|
| 254 | void G4OpenGLImmediateQtViewer::keyPressEvent (QKeyEvent * event) |
---|
| 255 | { |
---|
| 256 | G4keyPressEvent(event); |
---|
| 257 | } |
---|
| 258 | |
---|
| 259 | void G4OpenGLImmediateQtViewer::wheelEvent (QWheelEvent * event) |
---|
| 260 | { |
---|
| 261 | G4wheelEvent(event); |
---|
| 262 | } |
---|
| 263 | |
---|
[1240] | 264 | void G4OpenGLImmediateQtViewer::showEvent (QShowEvent * event) |
---|
| 265 | { |
---|
| 266 | fHasToRepaint = true; |
---|
| 267 | } |
---|
| 268 | |
---|
| 269 | |
---|
[873] | 270 | /** |
---|
| 271 | * This function was build in order to make a zoom on double clic event. |
---|
| 272 | * It was think to build a rubberband on the zoom area, but never work fine |
---|
| 273 | */ |
---|
[955] | 274 | void G4OpenGLImmediateQtViewer::mouseDoubleClickEvent(QMouseEvent *) |
---|
[873] | 275 | { |
---|
| 276 | G4MouseDoubleClickEvent(); |
---|
| 277 | } |
---|
| 278 | |
---|
[955] | 279 | void G4OpenGLImmediateQtViewer::mouseReleaseEvent(QMouseEvent *) |
---|
[873] | 280 | { |
---|
| 281 | G4MouseReleaseEvent(); |
---|
| 282 | } |
---|
| 283 | |
---|
| 284 | void G4OpenGLImmediateQtViewer::mouseMoveEvent(QMouseEvent *event) |
---|
| 285 | { |
---|
| 286 | G4MouseMoveEvent(event); |
---|
| 287 | } |
---|
| 288 | |
---|
| 289 | |
---|
| 290 | void G4OpenGLImmediateQtViewer::contextMenuEvent(QContextMenuEvent *e) |
---|
| 291 | { |
---|
| 292 | G4manageContextMenuEvent(e); |
---|
| 293 | } |
---|
| 294 | |
---|
[1228] | 295 | void G4OpenGLImmediateQtViewer::paintEvent(QPaintEvent *event) { |
---|
| 296 | // fHasToRepaint= false; |
---|
| 297 | #ifdef G4DEBUG_VIS_OGL |
---|
[1235] | 298 | printf("\n\nG4OpenGLImmediateQtViewer::paintEvent VVVVVVVVV %d\n",fHasToRepaint); |
---|
[1228] | 299 | #endif |
---|
[1235] | 300 | if ( fHasToRepaint) { |
---|
| 301 | updateGL(); |
---|
| 302 | } |
---|
[1228] | 303 | #ifdef G4DEBUG_VIS_OGL |
---|
[1240] | 304 | printf("\n\nG4OpenGLImmediateQtViewer::paintEvent ^^^^^^^^^ %d\n",fHasToRepaint); |
---|
[1228] | 305 | #endif |
---|
| 306 | } |
---|
| 307 | |
---|
| 308 | |
---|
[564] | 309 | void G4OpenGLImmediateQtViewer::updateQWidget() { |
---|
[1040] | 310 | fHasToRepaint= true; |
---|
[1228] | 311 | #ifdef G4DEBUG_VIS_OGL |
---|
[1235] | 312 | printf("\n\nG4OpenGLImmediateQtViewer::updateQWidget VVVVVVVVV HasTo:%d\n",fHasToRepaint); |
---|
[1228] | 313 | #endif |
---|
[564] | 314 | updateGL(); |
---|
[1240] | 315 | repaint(); |
---|
[1228] | 316 | #ifdef G4DEBUG_VIS_OGL |
---|
| 317 | printf("\n\nG4OpenGLImmediateQtViewer::updateQWidget ^^^^^^^^^\n"); |
---|
| 318 | #endif |
---|
[1040] | 319 | fHasToRepaint= false; |
---|
[564] | 320 | } |
---|
[551] | 321 | |
---|
[877] | 322 | |
---|
| 323 | void G4OpenGLImmediateQtViewer::ShowView ( |
---|
| 324 | ) |
---|
| 325 | ////////////////////////////////////////////////////////////////////////////// |
---|
| 326 | //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// |
---|
| 327 | { |
---|
[1228] | 328 | #ifdef G4DEBUG_VIS_OGL |
---|
| 329 | printf("\n\nG4OpenGLImmediateQtViewer::ShowView VVVV\n"); |
---|
| 330 | #endif |
---|
[1240] | 331 | fHasToRepaint = true; |
---|
[877] | 332 | #if QT_VERSION < 0x040000 |
---|
| 333 | setActiveWindow(); |
---|
| 334 | #else |
---|
| 335 | activateWindow(); |
---|
[531] | 336 | #endif |
---|
[1228] | 337 | #ifdef G4DEBUG_VIS_OGL |
---|
| 338 | printf("\n\nG4OpenGLImmediateQtViewer::ShowView ^^^^^\n"); |
---|
| 339 | #endif |
---|
[877] | 340 | } |
---|
| 341 | #endif |
---|