[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 | // |
---|
[704] | 27 | // $Id: G4OpenGLStoredQtViewer.cc,v 1.9 2008/01/30 10:54:13 lgarnier Exp $ |
---|
[593] | 28 | // GEANT4 tag $Name: $ |
---|
[531] | 29 | // |
---|
[564] | 30 | // |
---|
[533] | 31 | // Class G4OpenGLStoredQtViewer : a class derived from G4OpenGLQtViewer and |
---|
[564] | 32 | // G4OpenGLStoredViewer. |
---|
[531] | 33 | |
---|
[533] | 34 | #ifdef G4VIS_BUILD_OPENGLQT_DRIVER |
---|
[531] | 35 | |
---|
[739] | 36 | //#define GEANT4_QT_DEBUG |
---|
[610] | 37 | |
---|
[533] | 38 | #include "G4OpenGLStoredQtViewer.hh" |
---|
[531] | 39 | |
---|
| 40 | #include "G4ios.hh" |
---|
| 41 | |
---|
[595] | 42 | //#include <qmouseevent.h> |
---|
| 43 | #include <qevent.h> // include <qcontextmenuevent.h> |
---|
[593] | 44 | |
---|
[533] | 45 | G4OpenGLStoredQtViewer::G4OpenGLStoredQtViewer |
---|
[531] | 46 | (G4OpenGLStoredSceneHandler& sceneHandler, |
---|
| 47 | const G4String& name): |
---|
[682] | 48 | G4VViewer (sceneHandler, sceneHandler.IncrementViewCount (), name), |
---|
| 49 | G4OpenGLViewer (sceneHandler), |
---|
| 50 | G4OpenGLQtViewer (sceneHandler), |
---|
[709] | 51 | G4OpenGLStoredViewer (sceneHandler) // FIXME : gerer le pb du parent ! |
---|
[682] | 52 | { |
---|
[709] | 53 | #if QT_VERSION < 0x040000 |
---|
| 54 | setFocusPolicy(QWidget::StrongFocus); // enable keybord events |
---|
| 55 | #else |
---|
[696] | 56 | setFocusPolicy(Qt::StrongFocus); // enable keybord events |
---|
[709] | 57 | #endif |
---|
[682] | 58 | nbPaint =0; |
---|
| 59 | hasToRepaint =false; |
---|
[531] | 60 | if (fViewId < 0) return; // In case error in base class instantiation. |
---|
| 61 | } |
---|
| 62 | |
---|
[564] | 63 | G4OpenGLStoredQtViewer::~G4OpenGLStoredQtViewer() { |
---|
[608] | 64 | #ifdef GEANT4_QT_DEBUG |
---|
[682] | 65 | printf("GLWidget::~GLWidget \n"); |
---|
[608] | 66 | #endif |
---|
[682] | 67 | makeCurrent(); |
---|
| 68 | // this is connect to the Dialog for deleting it properly |
---|
| 69 | // when close event. |
---|
| 70 | // ((QDialog*)window())->reject(); |
---|
[608] | 71 | #ifdef GEANT4_QT_DEBUG |
---|
[682] | 72 | printf("GLWidget::~GLWidget END\n"); |
---|
[608] | 73 | #endif |
---|
[564] | 74 | } |
---|
[531] | 75 | |
---|
[564] | 76 | void G4OpenGLStoredQtViewer::Initialise() { |
---|
[608] | 77 | #ifdef GEANT4_QT_DEBUG |
---|
[682] | 78 | printf("GLWidget::Initialise \n"); |
---|
[608] | 79 | #endif |
---|
[682] | 80 | readyToPaint = false; |
---|
| 81 | CreateGLQtContext (); |
---|
[608] | 82 | #ifdef GEANT4_QT_DEBUG |
---|
[682] | 83 | printf("G4OpenGLStoredQtViewer::Initialise () 2\n"); |
---|
[608] | 84 | #endif |
---|
[564] | 85 | CreateMainWindow (this); |
---|
[608] | 86 | #ifdef GEANT4_QT_DEBUG |
---|
[564] | 87 | printf("G4OpenGLStoredQtViewer::Initialise () 3\n"); |
---|
[608] | 88 | #endif |
---|
[682] | 89 | CreateFontLists (); // FIXME Does nothing! |
---|
[564] | 90 | |
---|
[608] | 91 | #ifdef GEANT4_QT_DEBUG |
---|
[564] | 92 | printf("readyToPaint = true \n"); |
---|
[608] | 93 | #endif |
---|
[564] | 94 | readyToPaint = true; |
---|
| 95 | |
---|
| 96 | // First Draw |
---|
| 97 | SetView(); |
---|
[608] | 98 | #ifdef GEANT4_QT_DEBUG |
---|
[564] | 99 | printf(" ClearView\n"); |
---|
[608] | 100 | #endif |
---|
[564] | 101 | ClearView (); //ok, put the background correct |
---|
| 102 | FinishView(); |
---|
| 103 | } |
---|
[531] | 104 | |
---|
[564] | 105 | void G4OpenGLStoredQtViewer::initializeGL () { |
---|
| 106 | |
---|
[682] | 107 | InitializeGLView (); |
---|
[564] | 108 | |
---|
[608] | 109 | #ifdef GEANT4_QT_DEBUG |
---|
[682] | 110 | printf("G4OpenGLStoredQtViewer::InitialiseGL () 1\n"); |
---|
[608] | 111 | #endif |
---|
[564] | 112 | |
---|
[682] | 113 | // clear the buffers and window. |
---|
| 114 | ClearView (); |
---|
| 115 | // printf("G4OpenGLStoredQtViewer::InitialiseGL () 2\n"); |
---|
| 116 | FinishView (); |
---|
[564] | 117 | |
---|
[682] | 118 | glDepthFunc (GL_LEQUAL); |
---|
| 119 | glDepthMask (GL_TRUE); |
---|
[564] | 120 | |
---|
[682] | 121 | hasToRepaint =true; |
---|
[564] | 122 | |
---|
[608] | 123 | #ifdef GEANT4_QT_DEBUG |
---|
[682] | 124 | printf("G4OpenGLStoredQtViewer::InitialiseGL -------------------------------------------------------------------------------------\n"); |
---|
[608] | 125 | #endif |
---|
[531] | 126 | } |
---|
| 127 | |
---|
[564] | 128 | |
---|
[533] | 129 | void G4OpenGLStoredQtViewer::DrawView () { |
---|
[682] | 130 | |
---|
[608] | 131 | #ifdef GEANT4_QT_DEBUG |
---|
[564] | 132 | printf("G4OpenGLStoredQtViewer::DrawView %d %d VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV\n",WinSize_x, WinSize_y); |
---|
[608] | 133 | #endif |
---|
[682] | 134 | G4ViewParameters::DrawingStyle style = GetViewParameters().GetDrawingStyle(); |
---|
[531] | 135 | |
---|
[682] | 136 | //Make sure current viewer is attached and clean... |
---|
| 137 | //Qt version needed |
---|
| 138 | // glViewport (0, 0, WinSize_x, WinSize_y); |
---|
[531] | 139 | |
---|
[682] | 140 | //See if things have changed from last time and remake if necessary... |
---|
| 141 | // The fNeedKernelVisit flag might have been set by the user in |
---|
| 142 | // /vis/viewer/rebuild, but if not, make decision and set flag only |
---|
| 143 | // if necessary... |
---|
| 144 | if (!fNeedKernelVisit) |
---|
[565] | 145 | |
---|
[682] | 146 | if (!fNeedKernelVisit) KernelVisitDecision (); |
---|
[565] | 147 | |
---|
[682] | 148 | G4bool kernelVisitWasNeeded = fNeedKernelVisit; // Keep (ProcessView resets). |
---|
| 149 | ProcessView (); |
---|
[564] | 150 | |
---|
[531] | 151 | |
---|
[682] | 152 | if(style!=G4ViewParameters::hlr && |
---|
| 153 | haloing_enabled) { |
---|
[608] | 154 | #ifdef GEANT4_QT_DEBUG |
---|
[682] | 155 | printf("G4OpenGLStoredQtViewer::DrawView DANS LE IF\n"); |
---|
[608] | 156 | #endif |
---|
[531] | 157 | |
---|
[682] | 158 | HaloingFirstPass (); |
---|
| 159 | DrawDisplayLists (); |
---|
| 160 | glFlush (); |
---|
[531] | 161 | |
---|
[682] | 162 | HaloingSecondPass (); |
---|
[531] | 163 | |
---|
[682] | 164 | DrawDisplayLists (); |
---|
| 165 | FinishView (); |
---|
[531] | 166 | |
---|
[682] | 167 | } else { |
---|
[608] | 168 | #ifdef GEANT4_QT_DEBUG |
---|
[682] | 169 | printf("*************************** CASE 1 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \n"); |
---|
[608] | 170 | #endif |
---|
[564] | 171 | |
---|
[682] | 172 | // If kernel visit was needed, drawing and FinishView will already |
---|
| 173 | // have been done, so... |
---|
| 174 | if (!kernelVisitWasNeeded) { |
---|
[608] | 175 | #ifdef GEANT4_QT_DEBUG |
---|
[682] | 176 | printf("*************************** CASE 2 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \n"); |
---|
[608] | 177 | #endif |
---|
[682] | 178 | DrawDisplayLists (); |
---|
| 179 | FinishView (); |
---|
| 180 | } else { |
---|
[608] | 181 | #ifdef GEANT4_QT_DEBUG |
---|
[682] | 182 | printf("*************************** CASE 3 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \n"); |
---|
[608] | 183 | #endif |
---|
[682] | 184 | // However, union cutaways are implemented in DrawDisplayLists, so make |
---|
| 185 | // an extra pass... |
---|
| 186 | if (fVP.IsCutaway() && |
---|
| 187 | fVP.GetCutawayMode() == G4ViewParameters::cutawayUnion) { |
---|
| 188 | ClearView(); |
---|
| 189 | DrawDisplayLists (); |
---|
| 190 | FinishView (); |
---|
[608] | 191 | #ifdef GEANT4_QT_DEBUG |
---|
[682] | 192 | printf("*************************** CASE 4 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \n"); |
---|
[608] | 193 | #endif |
---|
[682] | 194 | } else { // ADD TO AVOID KernelVisit=1 and nothing to display |
---|
| 195 | DrawDisplayLists (); |
---|
| 196 | FinishView (); |
---|
| 197 | } |
---|
| 198 | } |
---|
| 199 | } |
---|
[564] | 200 | |
---|
[724] | 201 | if (fRecordFrames) { |
---|
[739] | 202 | savePPMToTemp(); |
---|
[725] | 203 | fRecordFrameNumber++; |
---|
[608] | 204 | #ifdef GEANT4_QT_DEBUG |
---|
[724] | 205 | printf("G4OpenGLStoredQtViewer::record frame %d\n",fRecordFrameNumber); |
---|
| 206 | #endif |
---|
| 207 | } |
---|
| 208 | |
---|
| 209 | #ifdef GEANT4_QT_DEBUG |
---|
[682] | 210 | printf("G4OpenGLStoredQtViewer::DrawView %d %d ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \n",WinSize_x, WinSize_y); |
---|
[608] | 211 | #endif |
---|
[682] | 212 | hasToRepaint =true; |
---|
[531] | 213 | } |
---|
| 214 | |
---|
[564] | 215 | |
---|
[531] | 216 | ////////////////////////////////////////////////////////////////////////////// |
---|
[533] | 217 | void G4OpenGLStoredQtViewer::FinishView ( |
---|
[531] | 218 | ) |
---|
| 219 | ////////////////////////////////////////////////////////////////////////////// |
---|
| 220 | //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// |
---|
| 221 | { |
---|
[608] | 222 | #ifdef GEANT4_QT_DEBUG |
---|
[564] | 223 | printf("G4OpenGLStoredQtViewer::FinishView VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV\n"); |
---|
[608] | 224 | #endif |
---|
[531] | 225 | |
---|
| 226 | glFlush (); |
---|
[564] | 227 | swapBuffers (); |
---|
[608] | 228 | #ifdef GEANT4_QT_DEBUG |
---|
[564] | 229 | printf("G4OpenGLStoredQtViewer::FinishView ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \n"); |
---|
[608] | 230 | #endif |
---|
[564] | 231 | |
---|
[531] | 232 | } |
---|
| 233 | |
---|
[564] | 234 | |
---|
| 235 | /** |
---|
[682] | 236 | - Lors du resize de la fenetre, on doit non pas redessiner le detecteur, mais aussi les evenements |
---|
| 237 | */ |
---|
[564] | 238 | void G4OpenGLStoredQtViewer::resizeGL( |
---|
[682] | 239 | int aWidth |
---|
| 240 | ,int aHeight) |
---|
[564] | 241 | { |
---|
[673] | 242 | setupViewport(aWidth,aHeight); |
---|
[564] | 243 | |
---|
[682] | 244 | if (((WinSize_x != (G4int)aWidth)) || (WinSize_y != (G4int) aHeight)) { |
---|
| 245 | hasToRepaint =true; |
---|
| 246 | } |
---|
| 247 | WinSize_x = (G4int) aWidth; |
---|
| 248 | WinSize_y = (G4int) aHeight; |
---|
| 249 | |
---|
[608] | 250 | #ifdef GEANT4_QT_DEBUG |
---|
[564] | 251 | printf("G4OpenGLStoredQtViewer::resizeGL ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ %d %d=%d %d=%d\n",hasToRepaint,width(),aWidth,height(),aHeight); |
---|
[608] | 252 | #endif |
---|
[564] | 253 | } |
---|
| 254 | |
---|
| 255 | |
---|
[673] | 256 | /** |
---|
[682] | 257 | @see : |
---|
[673] | 258 | */ |
---|
[564] | 259 | |
---|
| 260 | void G4OpenGLStoredQtViewer::paintGL() |
---|
[682] | 261 | { |
---|
| 262 | if (!readyToPaint) { |
---|
[608] | 263 | #ifdef GEANT4_QT_DEBUG |
---|
[682] | 264 | printf("G4OpenGLStoredQtViewer::paintGL ============ Not ready %d\n",readyToPaint); |
---|
[608] | 265 | #endif |
---|
[682] | 266 | readyToPaint= true; |
---|
| 267 | return; |
---|
| 268 | } |
---|
| 269 | // DO NOT RESIZE IF SIZE HAS NOT CHANGE : |
---|
| 270 | // WHEN CLICK ON THE FRAME FOR EXAMPLE |
---|
| 271 | // EXECEPT WHEN MOUSE MOVE EVENT |
---|
| 272 | if ( !hasToRepaint) { |
---|
| 273 | if (((WinSize_x == (G4int)width())) &&(WinSize_y == (G4int) height())) { |
---|
[608] | 274 | #ifdef GEANT4_QT_DEBUG |
---|
[682] | 275 | printf("G4OpenGLStoredQtViewer::paintGL ============ Dont repaint\n"); |
---|
[608] | 276 | #endif |
---|
[682] | 277 | return; |
---|
| 278 | } |
---|
| 279 | } |
---|
| 280 | nbPaint++; |
---|
[608] | 281 | #ifdef GEANT4_QT_DEBUG |
---|
[682] | 282 | printf("G4OpenGLStoredQtViewer::paintGL VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV %d ready %d\n",nbPaint,readyToPaint); |
---|
[608] | 283 | #endif |
---|
[682] | 284 | WinSize_x = (G4int) width(); |
---|
| 285 | WinSize_y = (G4int) height(); |
---|
[673] | 286 | |
---|
[682] | 287 | setupViewport(width(),height()); |
---|
| 288 | // glViewport (0, 0, width(), height()); |
---|
| 289 | // glLoadIdentity(); |
---|
[673] | 290 | |
---|
| 291 | |
---|
[682] | 292 | SetView(); |
---|
[673] | 293 | |
---|
[682] | 294 | // // printf("before ClearView\n"); |
---|
[608] | 295 | #ifdef GEANT4_QT_DEBUG |
---|
[682] | 296 | printf(" ClearView\n"); |
---|
[608] | 297 | #endif |
---|
[673] | 298 | |
---|
[682] | 299 | ClearView (); //ok, put the background correct |
---|
| 300 | DrawView(); |
---|
[673] | 301 | |
---|
[682] | 302 | hasToRepaint =false; |
---|
[673] | 303 | |
---|
[608] | 304 | #ifdef GEANT4_QT_DEBUG |
---|
[682] | 305 | printf("G4OpenGLStoredQtViewer::paintGL ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ %d ready %d\n",nbPaint,readyToPaint); |
---|
[608] | 306 | #endif |
---|
[682] | 307 | } |
---|
[564] | 308 | |
---|
| 309 | void G4OpenGLStoredQtViewer::mousePressEvent(QMouseEvent *event) |
---|
| 310 | { |
---|
[709] | 311 | #if QT_VERSION < 0x040000 |
---|
| 312 | if ((event->button() & Qt::LeftButton) |
---|
| 313 | && !((event->state() & Qt::ShiftButton) |
---|
| 314 | || (event->state() & Qt::ControlButton) |
---|
| 315 | || (event->state() & Qt::AltButton) |
---|
| 316 | || (event->state() & Qt::MetaButton))) { |
---|
| 317 | #else |
---|
[690] | 318 | if ((event->buttons() & Qt::LeftButton) |
---|
| 319 | && !((event->modifiers() & Qt::ShiftModifier) |
---|
| 320 | || (event->modifiers() & Qt::ControlModifier) |
---|
| 321 | || (event->modifiers() & Qt::AltModifier) |
---|
| 322 | || (event->modifiers() & Qt::MetaModifier))) { |
---|
[709] | 323 | #endif |
---|
[608] | 324 | #ifdef GEANT4_QT_DEBUG |
---|
[682] | 325 | printf("G4OpenGLStoredQtViewer::mousePressEvent\n"); |
---|
[608] | 326 | #endif |
---|
[682] | 327 | setMouseTracking(true); |
---|
[720] | 328 | G4MousePressEvent(event->pos(),Qt::LeftButton); |
---|
[682] | 329 | } |
---|
[564] | 330 | } |
---|
| 331 | |
---|
[696] | 332 | void G4OpenGLStoredQtViewer::keyPressEvent (QKeyEvent * event) |
---|
| 333 | { |
---|
| 334 | G4keyPressEvent(event); |
---|
| 335 | } |
---|
| 336 | |
---|
[678] | 337 | /** |
---|
| 338 | * This function was build in order to make a zoom on double clic event. |
---|
| 339 | * It was think to build a rubberband on the zoom area, but never work fine |
---|
| 340 | */ |
---|
[673] | 341 | void G4OpenGLStoredQtViewer::mouseDoubleClickEvent(QMouseEvent *event) |
---|
| 342 | { |
---|
| 343 | #ifdef GEANT4_QT_DEBUG |
---|
| 344 | printf("G4OpenGLStoredQtViewer::mouseDoubleClickEvent\n"); |
---|
| 345 | #endif |
---|
[720] | 346 | setMouseTracking(true); |
---|
[682] | 347 | // glBufferImage = grabFrameBuffer().convertToFormat(QImage::Format_ARGB32);//_Premultiplied); |
---|
[673] | 348 | } |
---|
| 349 | |
---|
| 350 | void G4OpenGLStoredQtViewer::mouseReleaseEvent(QMouseEvent *event) |
---|
| 351 | { |
---|
| 352 | #ifdef GEANT4_QT_DEBUG |
---|
| 353 | printf("G4OpenGLStoredQtViewer::mouseReleaseEvent\n"); |
---|
| 354 | #endif |
---|
[720] | 355 | setMouseTracking(false); |
---|
[673] | 356 | } |
---|
| 357 | |
---|
[564] | 358 | void G4OpenGLStoredQtViewer::mouseMoveEvent(QMouseEvent *event) |
---|
| 359 | { |
---|
[720] | 360 | |
---|
[606] | 361 | #if QT_VERSION < 0x040000 |
---|
[720] | 362 | G4MouseMoveEvent(event->x(),event->y(),event->state()); |
---|
[606] | 363 | #else |
---|
[720] | 364 | G4MouseMoveEvent(event->x(),event->y(),event->buttons()); |
---|
[606] | 365 | #endif |
---|
[720] | 366 | if (hasPendingEvents ()) |
---|
| 367 | G4MouseMoveEvent(event->x(),event->y(),event->buttons(),true); |
---|
[564] | 368 | } |
---|
| 369 | |
---|
| 370 | |
---|
| 371 | void G4OpenGLStoredQtViewer::contextMenuEvent(QContextMenuEvent *e) |
---|
| 372 | { |
---|
[635] | 373 | #ifdef GEANT4_QT_DEBUG |
---|
| 374 | printf("G4OpenGLStoredQtViewer::contextMenuEvent\n"); |
---|
| 375 | #endif |
---|
[564] | 376 | manageContextMenuEvent(e); |
---|
| 377 | } |
---|
| 378 | |
---|
| 379 | void G4OpenGLStoredQtViewer::updateQWidget() { |
---|
| 380 | hasToRepaint= true; |
---|
| 381 | updateGL(); |
---|
| 382 | hasToRepaint= false; |
---|
| 383 | } |
---|
| 384 | |
---|
[673] | 385 | |
---|
[531] | 386 | #endif |
---|