[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 | // |
---|
[608] | 27 | // $Id: G4OpenGLStoredQtViewer.cc,v 1.6 2007/11/15 18:24:28 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 | |
---|
[610] | 36 | #define GEANT4_QT_DEBUG |
---|
| 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): |
---|
[564] | 48 | G4VViewer (sceneHandler, sceneHandler.IncrementViewCount (), name), |
---|
| 49 | G4OpenGLViewer (sceneHandler), |
---|
| 50 | G4OpenGLQtViewer (sceneHandler), |
---|
| 51 | G4OpenGLStoredViewer (sceneHandler), |
---|
| 52 | QGLWidget() // FIXME : gerer le pb du parent ! |
---|
| 53 | { |
---|
| 54 | nbPaint =0; |
---|
| 55 | hasToRepaint =false; |
---|
[531] | 56 | if (fViewId < 0) return; // In case error in base class instantiation. |
---|
| 57 | } |
---|
| 58 | |
---|
[564] | 59 | G4OpenGLStoredQtViewer::~G4OpenGLStoredQtViewer() { |
---|
[608] | 60 | #ifdef GEANT4_QT_DEBUG |
---|
[564] | 61 | printf("GLWidget::~GLWidget \n"); |
---|
[608] | 62 | #endif |
---|
[579] | 63 | makeCurrent(); |
---|
| 64 | // this is connect to the Dialog for deleting it properly |
---|
| 65 | // when close event. |
---|
| 66 | // ((QDialog*)window())->reject(); |
---|
[608] | 67 | #ifdef GEANT4_QT_DEBUG |
---|
[564] | 68 | printf("GLWidget::~GLWidget END\n"); |
---|
[608] | 69 | #endif |
---|
[564] | 70 | } |
---|
[531] | 71 | |
---|
[564] | 72 | void G4OpenGLStoredQtViewer::Initialise() { |
---|
[608] | 73 | #ifdef GEANT4_QT_DEBUG |
---|
[564] | 74 | printf("GLWidget::Initialise \n"); |
---|
[608] | 75 | #endif |
---|
[564] | 76 | readyToPaint = false; |
---|
| 77 | CreateGLQtContext (); |
---|
[608] | 78 | #ifdef GEANT4_QT_DEBUG |
---|
[564] | 79 | printf("G4OpenGLStoredQtViewer::Initialise () 2\n"); |
---|
[608] | 80 | #endif |
---|
[564] | 81 | CreateMainWindow (this); |
---|
[608] | 82 | #ifdef GEANT4_QT_DEBUG |
---|
[564] | 83 | printf("G4OpenGLStoredQtViewer::Initialise () 3\n"); |
---|
[608] | 84 | #endif |
---|
[564] | 85 | CreateFontLists (); // FIXME Does nothing! |
---|
| 86 | |
---|
[608] | 87 | #ifdef GEANT4_QT_DEBUG |
---|
[564] | 88 | printf("readyToPaint = true \n"); |
---|
[608] | 89 | #endif |
---|
[564] | 90 | readyToPaint = true; |
---|
| 91 | |
---|
| 92 | // First Draw |
---|
| 93 | SetView(); |
---|
[608] | 94 | #ifdef GEANT4_QT_DEBUG |
---|
[564] | 95 | printf(" ClearView\n"); |
---|
[608] | 96 | #endif |
---|
[564] | 97 | ClearView (); //ok, put the background correct |
---|
| 98 | ShowView(); |
---|
| 99 | FinishView(); |
---|
| 100 | } |
---|
[531] | 101 | |
---|
[564] | 102 | void G4OpenGLStoredQtViewer::initializeGL () { |
---|
| 103 | |
---|
| 104 | InitializeGLView (); |
---|
| 105 | |
---|
[608] | 106 | #ifdef GEANT4_QT_DEBUG |
---|
[564] | 107 | printf("G4OpenGLStoredQtViewer::InitialiseGL () 1\n"); |
---|
[608] | 108 | #endif |
---|
[564] | 109 | |
---|
| 110 | // clear the buffers and window. |
---|
| 111 | ClearView (); |
---|
| 112 | // printf("G4OpenGLStoredQtViewer::InitialiseGL () 2\n"); |
---|
| 113 | FinishView (); |
---|
| 114 | |
---|
| 115 | glDepthFunc (GL_LEQUAL); |
---|
| 116 | glDepthMask (GL_TRUE); |
---|
| 117 | |
---|
| 118 | hasToRepaint =true; |
---|
| 119 | |
---|
[608] | 120 | #ifdef GEANT4_QT_DEBUG |
---|
[564] | 121 | printf("G4OpenGLStoredQtViewer::InitialiseGL -------------------------------------------------------------------------------------\n"); |
---|
[608] | 122 | #endif |
---|
[531] | 123 | } |
---|
| 124 | |
---|
[564] | 125 | |
---|
[533] | 126 | void G4OpenGLStoredQtViewer::DrawView () { |
---|
[531] | 127 | |
---|
[608] | 128 | #ifdef GEANT4_QT_DEBUG |
---|
[564] | 129 | printf("G4OpenGLStoredQtViewer::DrawView %d %d VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV\n",WinSize_x, WinSize_y); |
---|
[608] | 130 | #endif |
---|
[564] | 131 | G4ViewParameters::DrawingStyle style = GetViewParameters().GetDrawingStyle(); |
---|
[531] | 132 | |
---|
[564] | 133 | //Make sure current viewer is attached and clean... |
---|
| 134 | //Qt version needed |
---|
| 135 | glViewport (0, 0, WinSize_x, WinSize_y); |
---|
[531] | 136 | |
---|
[564] | 137 | //See if things have changed from last time and remake if necessary... |
---|
| 138 | // The fNeedKernelVisit flag might have been set by the user in |
---|
| 139 | // /vis/viewer/rebuild, but if not, make decision and set flag only |
---|
| 140 | // if necessary... |
---|
[565] | 141 | if (!fNeedKernelVisit) |
---|
| 142 | |
---|
[564] | 143 | if (!fNeedKernelVisit) KernelVisitDecision (); |
---|
[565] | 144 | |
---|
[564] | 145 | G4bool kernelVisitWasNeeded = fNeedKernelVisit; // Keep (ProcessView resets). |
---|
| 146 | ProcessView (); |
---|
| 147 | |
---|
[531] | 148 | |
---|
[564] | 149 | if(style!=G4ViewParameters::hlr && |
---|
| 150 | haloing_enabled) { |
---|
[608] | 151 | #ifdef GEANT4_QT_DEBUG |
---|
[564] | 152 | printf("G4OpenGLStoredQtViewer::DrawView DANS LE IF\n"); |
---|
[608] | 153 | #endif |
---|
[531] | 154 | |
---|
[564] | 155 | HaloingFirstPass (); |
---|
| 156 | DrawDisplayLists (); |
---|
| 157 | glFlush (); |
---|
[531] | 158 | |
---|
[564] | 159 | HaloingSecondPass (); |
---|
[531] | 160 | |
---|
[564] | 161 | DrawDisplayLists (); |
---|
[565] | 162 | FinishView (); |
---|
[531] | 163 | |
---|
[564] | 164 | } else { |
---|
[608] | 165 | #ifdef GEANT4_QT_DEBUG |
---|
[565] | 166 | printf("*************************** CASE 1 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \n"); |
---|
[608] | 167 | #endif |
---|
[564] | 168 | |
---|
| 169 | // If kernel visit was needed, drawing and FinishView will already |
---|
| 170 | // have been done, so... |
---|
| 171 | if (!kernelVisitWasNeeded) { |
---|
[608] | 172 | #ifdef GEANT4_QT_DEBUG |
---|
[565] | 173 | printf("*************************** CASE 2 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \n"); |
---|
[608] | 174 | #endif |
---|
[564] | 175 | DrawDisplayLists (); |
---|
[565] | 176 | FinishView (); |
---|
[564] | 177 | } else { |
---|
[608] | 178 | #ifdef GEANT4_QT_DEBUG |
---|
[565] | 179 | printf("*************************** CASE 3 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \n"); |
---|
[608] | 180 | #endif |
---|
[564] | 181 | // However, union cutaways are implemented in DrawDisplayLists, so make |
---|
| 182 | // an extra pass... |
---|
| 183 | if (fVP.IsCutaway() && |
---|
| 184 | fVP.GetCutawayMode() == G4ViewParameters::cutawayUnion) { |
---|
| 185 | ClearView(); |
---|
| 186 | DrawDisplayLists (); |
---|
[565] | 187 | FinishView (); |
---|
[608] | 188 | #ifdef GEANT4_QT_DEBUG |
---|
[565] | 189 | printf("*************************** CASE 4 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \n"); |
---|
[608] | 190 | #endif |
---|
[565] | 191 | } else { // ADD TO AVOID KernelVisit=1 and nothing to display |
---|
| 192 | DrawDisplayLists (); |
---|
| 193 | FinishView (); |
---|
[564] | 194 | } |
---|
| 195 | } |
---|
| 196 | } |
---|
| 197 | |
---|
[608] | 198 | #ifdef GEANT4_QT_DEBUG |
---|
[565] | 199 | printf("G4OpenGLStoredQtViewer::DrawView %d %d ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \n",WinSize_x, WinSize_y); |
---|
[608] | 200 | #endif |
---|
[564] | 201 | hasToRepaint =true; |
---|
[531] | 202 | } |
---|
| 203 | |
---|
[564] | 204 | |
---|
[531] | 205 | ////////////////////////////////////////////////////////////////////////////// |
---|
[533] | 206 | void G4OpenGLStoredQtViewer::FinishView ( |
---|
[531] | 207 | ) |
---|
| 208 | ////////////////////////////////////////////////////////////////////////////// |
---|
| 209 | //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// |
---|
| 210 | { |
---|
[608] | 211 | #ifdef GEANT4_QT_DEBUG |
---|
[564] | 212 | printf("G4OpenGLStoredQtViewer::FinishView VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV\n"); |
---|
[608] | 213 | #endif |
---|
[531] | 214 | |
---|
| 215 | glFlush (); |
---|
[564] | 216 | swapBuffers (); |
---|
[608] | 217 | #ifdef GEANT4_QT_DEBUG |
---|
[564] | 218 | printf("G4OpenGLStoredQtViewer::FinishView ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \n"); |
---|
[608] | 219 | #endif |
---|
[564] | 220 | |
---|
[531] | 221 | } |
---|
| 222 | |
---|
[564] | 223 | |
---|
| 224 | /** |
---|
| 225 | - Lors du resize de la fenetre, on doit non pas redessiner le detecteur, mais aussi les evenements |
---|
| 226 | */ |
---|
| 227 | void G4OpenGLStoredQtViewer::resizeGL( |
---|
| 228 | int aWidth |
---|
| 229 | ,int aHeight) |
---|
| 230 | { |
---|
| 231 | glViewport(0, 0, aWidth, aHeight); |
---|
| 232 | glMatrixMode(GL_PROJECTION); |
---|
| 233 | glMatrixMode(GL_MODELVIEW); |
---|
| 234 | |
---|
| 235 | if (((WinSize_x != (G4int)aWidth)) || (WinSize_y != (G4int) aHeight)) { |
---|
| 236 | hasToRepaint =true; |
---|
| 237 | } |
---|
| 238 | WinSize_x = (G4int) aWidth; |
---|
| 239 | WinSize_y = (G4int) aHeight; |
---|
| 240 | |
---|
[608] | 241 | #ifdef GEANT4_QT_DEBUG |
---|
[564] | 242 | printf("G4OpenGLStoredQtViewer::resizeGL ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ %d %d=%d %d=%d\n",hasToRepaint,width(),aWidth,height(),aHeight); |
---|
[608] | 243 | #endif |
---|
[564] | 244 | } |
---|
| 245 | |
---|
| 246 | |
---|
| 247 | |
---|
| 248 | void G4OpenGLStoredQtViewer::paintGL() |
---|
| 249 | { |
---|
| 250 | if (!readyToPaint) { |
---|
[608] | 251 | #ifdef GEANT4_QT_DEBUG |
---|
[579] | 252 | printf("G4OpenGLStoredQtViewer::paintGL ============ Not ready %d\n",readyToPaint); |
---|
[608] | 253 | #endif |
---|
[564] | 254 | readyToPaint= true; |
---|
| 255 | return; |
---|
| 256 | } |
---|
| 257 | // DO NOT RESIZE IF SIZE HAS NOT CHANGE : |
---|
| 258 | // WHEN CLICK ON THE FRAME FOR EXAMPLE |
---|
| 259 | // EXECEPT WHEN MOUSE MOVE EVENT |
---|
| 260 | if ( !hasToRepaint) { |
---|
| 261 | if (((WinSize_x == (G4int)width())) &&(WinSize_y == (G4int) height())) { |
---|
[608] | 262 | #ifdef GEANT4_QT_DEBUG |
---|
[579] | 263 | printf("G4OpenGLStoredQtViewer::paintGL ============ Dont repaint\n"); |
---|
[608] | 264 | #endif |
---|
[564] | 265 | return; |
---|
| 266 | } |
---|
| 267 | } |
---|
| 268 | nbPaint++; |
---|
[608] | 269 | #ifdef GEANT4_QT_DEBUG |
---|
[579] | 270 | printf("G4OpenGLStoredQtViewer::paintGL VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV %d ready %d\n",nbPaint,readyToPaint); |
---|
[608] | 271 | #endif |
---|
[564] | 272 | WinSize_x = (G4int) width(); |
---|
| 273 | WinSize_y = (G4int) height(); |
---|
| 274 | |
---|
| 275 | glViewport (0, 0, width(), height()); |
---|
| 276 | // glLoadIdentity(); |
---|
| 277 | |
---|
| 278 | |
---|
| 279 | SetView(); |
---|
| 280 | |
---|
| 281 | // // printf("before ClearView\n"); |
---|
[608] | 282 | #ifdef GEANT4_QT_DEBUG |
---|
[564] | 283 | printf(" ClearView\n"); |
---|
[608] | 284 | #endif |
---|
[564] | 285 | |
---|
| 286 | ClearView (); //ok, put the background correct |
---|
| 287 | DrawView(); |
---|
| 288 | |
---|
| 289 | hasToRepaint =false; |
---|
| 290 | |
---|
[608] | 291 | #ifdef GEANT4_QT_DEBUG |
---|
[579] | 292 | printf("G4OpenGLStoredQtViewer::paintGL ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ %d ready %d\n",nbPaint,readyToPaint); |
---|
[608] | 293 | #endif |
---|
[564] | 294 | } |
---|
| 295 | |
---|
| 296 | void G4OpenGLStoredQtViewer::mousePressEvent(QMouseEvent *event) |
---|
| 297 | { |
---|
[608] | 298 | #ifdef GEANT4_QT_DEBUG |
---|
[564] | 299 | printf("G4OpenGLStoredQtViewer::mousePressEvent\n"); |
---|
[608] | 300 | #endif |
---|
[564] | 301 | G4MousePressEvent(event->pos()); |
---|
| 302 | } |
---|
| 303 | |
---|
| 304 | void G4OpenGLStoredQtViewer::mouseMoveEvent(QMouseEvent *event) |
---|
| 305 | { |
---|
[608] | 306 | #ifdef GEANT4_QT_DEBUG |
---|
[606] | 307 | printf("G4OpenGLStoredQtViewer::mouseMoveEvent\n"); |
---|
[608] | 308 | #endif |
---|
[606] | 309 | #if QT_VERSION < 0x040000 |
---|
[621] | 310 | G4MouseMoveEvent(event->x(),event->y(),event->state()); |
---|
[606] | 311 | #else |
---|
| 312 | G4MouseMoveEvent(event->x(),event->y(),event->buttons()); |
---|
| 313 | #endif |
---|
[564] | 314 | // DrawView(); |
---|
| 315 | } |
---|
| 316 | |
---|
| 317 | |
---|
| 318 | void G4OpenGLStoredQtViewer::contextMenuEvent(QContextMenuEvent *e) |
---|
| 319 | { |
---|
| 320 | manageContextMenuEvent(e); |
---|
| 321 | } |
---|
| 322 | |
---|
| 323 | void G4OpenGLStoredQtViewer::updateQWidget() { |
---|
| 324 | hasToRepaint= true; |
---|
| 325 | updateGL(); |
---|
| 326 | hasToRepaint= false; |
---|
| 327 | } |
---|
| 328 | |
---|
[531] | 329 | #endif |
---|