| [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 | //
|
|---|
| [846] | 27 | // $Id: G4OpenGLStoredQtViewer.cc,v 1.15 2008/06/20 13:55:06 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 |
|
|---|
| [799] | 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 | }
|
|---|
| [531] | 96 |
|
|---|
| [564] | 97 | void G4OpenGLStoredQtViewer::initializeGL () {
|
|---|
| 98 |
|
|---|
| [682] | 99 | InitializeGLView ();
|
|---|
| [564] | 100 |
|
|---|
| [608] | 101 | #ifdef GEANT4_QT_DEBUG
|
|---|
| [682] | 102 | printf("G4OpenGLStoredQtViewer::InitialiseGL () 1\n");
|
|---|
| [608] | 103 | #endif
|
|---|
| [564] | 104 |
|
|---|
| [682] | 105 | // clear the buffers and window.
|
|---|
| 106 | ClearView ();
|
|---|
| 107 | // printf("G4OpenGLStoredQtViewer::InitialiseGL () 2\n");
|
|---|
| 108 | FinishView ();
|
|---|
| [564] | 109 |
|
|---|
| [682] | 110 | glDepthFunc (GL_LEQUAL);
|
|---|
| 111 | glDepthMask (GL_TRUE);
|
|---|
| [564] | 112 |
|
|---|
| [682] | 113 | hasToRepaint =true;
|
|---|
| [564] | 114 |
|
|---|
| [608] | 115 | #ifdef GEANT4_QT_DEBUG
|
|---|
| [682] | 116 | printf("G4OpenGLStoredQtViewer::InitialiseGL -------------------------------------------------------------------------------------\n");
|
|---|
| [608] | 117 | #endif
|
|---|
| [531] | 118 | }
|
|---|
| 119 |
|
|---|
| [564] | 120 |
|
|---|
| [533] | 121 | void G4OpenGLStoredQtViewer::DrawView () {
|
|---|
| [682] | 122 |
|
|---|
| [608] | 123 | #ifdef GEANT4_QT_DEBUG
|
|---|
| [800] | 124 | printf("G4OpenGLQtViewer::setupViewport\n");
|
|---|
| [564] | 125 | printf("G4OpenGLStoredQtViewer::DrawView %d %d VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV\n",WinSize_x, WinSize_y);
|
|---|
| [608] | 126 | #endif
|
|---|
| [682] | 127 | G4ViewParameters::DrawingStyle style = GetViewParameters().GetDrawingStyle();
|
|---|
| [531] | 128 |
|
|---|
| [682] | 129 | //Make sure current viewer is attached and clean...
|
|---|
| 130 | //Qt version needed
|
|---|
| 131 | // glViewport (0, 0, WinSize_x, WinSize_y);
|
|---|
| [531] | 132 |
|
|---|
| [682] | 133 | //See if things have changed from last time and remake if necessary...
|
|---|
| 134 | // The fNeedKernelVisit flag might have been set by the user in
|
|---|
| 135 | // /vis/viewer/rebuild, but if not, make decision and set flag only
|
|---|
| 136 | // if necessary...
|
|---|
| 137 | if (!fNeedKernelVisit)
|
|---|
| [565] | 138 |
|
|---|
| [682] | 139 | if (!fNeedKernelVisit) KernelVisitDecision ();
|
|---|
| [565] | 140 |
|
|---|
| [682] | 141 | G4bool kernelVisitWasNeeded = fNeedKernelVisit; // Keep (ProcessView resets).
|
|---|
| 142 | ProcessView ();
|
|---|
| [564] | 143 |
|
|---|
| [531] | 144 |
|
|---|
| [682] | 145 | if(style!=G4ViewParameters::hlr &&
|
|---|
| 146 | haloing_enabled) {
|
|---|
| [608] | 147 | #ifdef GEANT4_QT_DEBUG
|
|---|
| [682] | 148 | printf("G4OpenGLStoredQtViewer::DrawView DANS LE IF\n");
|
|---|
| [608] | 149 | #endif
|
|---|
| [531] | 150 |
|
|---|
| [682] | 151 | HaloingFirstPass ();
|
|---|
| 152 | DrawDisplayLists ();
|
|---|
| 153 | glFlush ();
|
|---|
| [531] | 154 |
|
|---|
| [682] | 155 | HaloingSecondPass ();
|
|---|
| [531] | 156 |
|
|---|
| [682] | 157 | DrawDisplayLists ();
|
|---|
| 158 | FinishView ();
|
|---|
| [531] | 159 |
|
|---|
| [682] | 160 | } else {
|
|---|
| [564] | 161 |
|
|---|
| [682] | 162 | // If kernel visit was needed, drawing and FinishView will already
|
|---|
| 163 | // have been done, so...
|
|---|
| 164 | if (!kernelVisitWasNeeded) {
|
|---|
| [608] | 165 | #ifdef GEANT4_QT_DEBUG
|
|---|
| [797] | 166 | printf("************************** G4OpenGLStoredQtViewer::DrawView Don't need kernel Visit \n");
|
|---|
| [608] | 167 | #endif
|
|---|
| [682] | 168 | DrawDisplayLists ();
|
|---|
| 169 | FinishView ();
|
|---|
| 170 | } else {
|
|---|
| [608] | 171 | #ifdef GEANT4_QT_DEBUG
|
|---|
| [797] | 172 | printf("************************** G4OpenGLStoredQtViewer::DrawView need kernel Visit \n");
|
|---|
| [608] | 173 | #endif
|
|---|
| [682] | 174 | // However, union cutaways are implemented in DrawDisplayLists, so make
|
|---|
| 175 | // an extra pass...
|
|---|
| 176 | if (fVP.IsCutaway() &&
|
|---|
| 177 | fVP.GetCutawayMode() == G4ViewParameters::cutawayUnion) {
|
|---|
| 178 | ClearView();
|
|---|
| 179 | DrawDisplayLists ();
|
|---|
| 180 | FinishView ();
|
|---|
| [608] | 181 | #ifdef GEANT4_QT_DEBUG
|
|---|
| [682] | 182 | printf("*************************** CASE 4 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \n");
|
|---|
| [608] | 183 | #endif
|
|---|
| [682] | 184 | } else { // ADD TO AVOID KernelVisit=1 and nothing to display
|
|---|
| 185 | DrawDisplayLists ();
|
|---|
| 186 | FinishView ();
|
|---|
| 187 | }
|
|---|
| 188 | }
|
|---|
| 189 | }
|
|---|
| [564] | 190 |
|
|---|
| [745] | 191 | if (isRecording()) {
|
|---|
| [739] | 192 | savePPMToTemp();
|
|---|
| [724] | 193 | }
|
|---|
| 194 |
|
|---|
| 195 | #ifdef GEANT4_QT_DEBUG
|
|---|
| [682] | 196 | printf("G4OpenGLStoredQtViewer::DrawView %d %d ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \n",WinSize_x, WinSize_y);
|
|---|
| [608] | 197 | #endif
|
|---|
| [682] | 198 | hasToRepaint =true;
|
|---|
| [531] | 199 | }
|
|---|
| 200 |
|
|---|
| [564] | 201 |
|
|---|
| [531] | 202 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| [533] | 203 | void G4OpenGLStoredQtViewer::FinishView (
|
|---|
| [531] | 204 | )
|
|---|
| 205 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 206 | //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
|
|---|
| 207 | {
|
|---|
| 208 | glFlush ();
|
|---|
| [564] | 209 | swapBuffers ();
|
|---|
| [531] | 210 | }
|
|---|
| 211 |
|
|---|
| [564] | 212 |
|
|---|
| 213 | /**
|
|---|
| [682] | 214 | - Lors du resize de la fenetre, on doit non pas redessiner le detecteur, mais aussi les evenements
|
|---|
| 215 | */
|
|---|
| [564] | 216 | void G4OpenGLStoredQtViewer::resizeGL(
|
|---|
| [682] | 217 | int aWidth
|
|---|
| 218 | ,int aHeight)
|
|---|
| [564] | 219 | {
|
|---|
| [673] | 220 | setupViewport(aWidth,aHeight);
|
|---|
| [564] | 221 |
|
|---|
| [682] | 222 | if (((WinSize_x != (G4int)aWidth)) || (WinSize_y != (G4int) aHeight)) {
|
|---|
| 223 | hasToRepaint =true;
|
|---|
| 224 | }
|
|---|
| 225 | WinSize_x = (G4int) aWidth;
|
|---|
| 226 | WinSize_y = (G4int) aHeight;
|
|---|
| 227 |
|
|---|
| [608] | 228 | #ifdef GEANT4_QT_DEBUG
|
|---|
| [564] | 229 | printf("G4OpenGLStoredQtViewer::resizeGL ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ %d %d=%d %d=%d\n",hasToRepaint,width(),aWidth,height(),aHeight);
|
|---|
| [608] | 230 | #endif
|
|---|
| [564] | 231 | }
|
|---|
| 232 |
|
|---|
| 233 |
|
|---|
| [673] | 234 | /**
|
|---|
| [682] | 235 | @see :
|
|---|
| [673] | 236 | */
|
|---|
| [564] | 237 |
|
|---|
| 238 | void G4OpenGLStoredQtViewer::paintGL()
|
|---|
| [682] | 239 | {
|
|---|
| 240 | if (!readyToPaint) {
|
|---|
| [608] | 241 | #ifdef GEANT4_QT_DEBUG
|
|---|
| [682] | 242 | printf("G4OpenGLStoredQtViewer::paintGL ============ Not ready %d\n",readyToPaint);
|
|---|
| [608] | 243 | #endif
|
|---|
| [682] | 244 | readyToPaint= true;
|
|---|
| 245 | return;
|
|---|
| 246 | }
|
|---|
| 247 | // DO NOT RESIZE IF SIZE HAS NOT CHANGE :
|
|---|
| 248 | // WHEN CLICK ON THE FRAME FOR EXAMPLE
|
|---|
| 249 | // EXECEPT WHEN MOUSE MOVE EVENT
|
|---|
| 250 | if ( !hasToRepaint) {
|
|---|
| 251 | if (((WinSize_x == (G4int)width())) &&(WinSize_y == (G4int) height())) {
|
|---|
| [608] | 252 | #ifdef GEANT4_QT_DEBUG
|
|---|
| [682] | 253 | printf("G4OpenGLStoredQtViewer::paintGL ============ Dont repaint\n");
|
|---|
| [608] | 254 | #endif
|
|---|
| [682] | 255 | return;
|
|---|
| 256 | }
|
|---|
| 257 | }
|
|---|
| 258 | nbPaint++;
|
|---|
| [608] | 259 | #ifdef GEANT4_QT_DEBUG
|
|---|
| [682] | 260 | printf("G4OpenGLStoredQtViewer::paintGL VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV %d ready %d\n",nbPaint,readyToPaint);
|
|---|
| [608] | 261 | #endif
|
|---|
| [682] | 262 | WinSize_x = (G4int) width();
|
|---|
| 263 | WinSize_y = (G4int) height();
|
|---|
| [673] | 264 |
|
|---|
| [682] | 265 | setupViewport(width(),height());
|
|---|
| 266 | // glViewport (0, 0, width(), height());
|
|---|
| 267 | // glLoadIdentity();
|
|---|
| [673] | 268 |
|
|---|
| 269 |
|
|---|
| [682] | 270 | SetView();
|
|---|
| [673] | 271 |
|
|---|
| [682] | 272 | // // printf("before ClearView\n");
|
|---|
| [608] | 273 | #ifdef GEANT4_QT_DEBUG
|
|---|
| [682] | 274 | printf(" ClearView\n");
|
|---|
| [608] | 275 | #endif
|
|---|
| [673] | 276 |
|
|---|
| [682] | 277 | ClearView (); //ok, put the background correct
|
|---|
| 278 | DrawView();
|
|---|
| [673] | 279 |
|
|---|
| [682] | 280 | hasToRepaint =false;
|
|---|
| [673] | 281 |
|
|---|
| [608] | 282 | #ifdef GEANT4_QT_DEBUG
|
|---|
| [682] | 283 | printf("G4OpenGLStoredQtViewer::paintGL ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ %d ready %d\n",nbPaint,readyToPaint);
|
|---|
| [608] | 284 | #endif
|
|---|
| [682] | 285 | }
|
|---|
| [564] | 286 |
|
|---|
| 287 | void G4OpenGLStoredQtViewer::mousePressEvent(QMouseEvent *event)
|
|---|
| 288 | {
|
|---|
| [709] | 289 | #if QT_VERSION < 0x040000
|
|---|
| 290 | if ((event->button() & Qt::LeftButton)
|
|---|
| 291 | && !((event->state() & Qt::ShiftButton)
|
|---|
| 292 | || (event->state() & Qt::ControlButton)
|
|---|
| 293 | || (event->state() & Qt::AltButton)
|
|---|
| 294 | || (event->state() & Qt::MetaButton))) {
|
|---|
| 295 | #else
|
|---|
| [690] | 296 | if ((event->buttons() & Qt::LeftButton)
|
|---|
| 297 | && !((event->modifiers() & Qt::ShiftModifier)
|
|---|
| 298 | || (event->modifiers() & Qt::ControlModifier)
|
|---|
| 299 | || (event->modifiers() & Qt::AltModifier)
|
|---|
| 300 | || (event->modifiers() & Qt::MetaModifier))) {
|
|---|
| [709] | 301 | #endif
|
|---|
| [608] | 302 | #ifdef GEANT4_QT_DEBUG
|
|---|
| [682] | 303 | printf("G4OpenGLStoredQtViewer::mousePressEvent\n");
|
|---|
| [608] | 304 | #endif
|
|---|
| [682] | 305 | setMouseTracking(true);
|
|---|
| [797] | 306 | G4MousePressEvent(event->pos());
|
|---|
| [682] | 307 | }
|
|---|
| [564] | 308 | }
|
|---|
| 309 |
|
|---|
| [696] | 310 | void G4OpenGLStoredQtViewer::keyPressEvent (QKeyEvent * event)
|
|---|
| 311 | {
|
|---|
| 312 | G4keyPressEvent(event);
|
|---|
| 313 | }
|
|---|
| 314 |
|
|---|
| [804] | 315 | void G4OpenGLStoredQtViewer::wheelEvent (QWheelEvent * event)
|
|---|
| 316 | {
|
|---|
| 317 | G4wheelEvent(event);
|
|---|
| 318 | }
|
|---|
| 319 |
|
|---|
| [678] | 320 | /**
|
|---|
| 321 | * This function was build in order to make a zoom on double clic event.
|
|---|
| 322 | * It was think to build a rubberband on the zoom area, but never work fine
|
|---|
| 323 | */
|
|---|
| [673] | 324 | void G4OpenGLStoredQtViewer::mouseDoubleClickEvent(QMouseEvent *event)
|
|---|
| 325 | {
|
|---|
| 326 | #ifdef GEANT4_QT_DEBUG
|
|---|
| 327 | printf("G4OpenGLStoredQtViewer::mouseDoubleClickEvent\n");
|
|---|
| 328 | #endif
|
|---|
| [720] | 329 | setMouseTracking(true);
|
|---|
| [682] | 330 | // glBufferImage = grabFrameBuffer().convertToFormat(QImage::Format_ARGB32);//_Premultiplied);
|
|---|
| [673] | 331 | }
|
|---|
| 332 |
|
|---|
| 333 | void G4OpenGLStoredQtViewer::mouseReleaseEvent(QMouseEvent *event)
|
|---|
| 334 | {
|
|---|
| [797] | 335 | G4MouseReleaseEvent();
|
|---|
| [673] | 336 | #ifdef GEANT4_QT_DEBUG
|
|---|
| [797] | 337 | printf("G4OpenGLStoredQtViewer::mouseReleaseEvent ================\n");
|
|---|
| [673] | 338 | #endif
|
|---|
| [720] | 339 | setMouseTracking(false);
|
|---|
| [673] | 340 | }
|
|---|
| 341 |
|
|---|
| [564] | 342 | void G4OpenGLStoredQtViewer::mouseMoveEvent(QMouseEvent *event)
|
|---|
| 343 | {
|
|---|
| [720] | 344 |
|
|---|
| [606] | 345 | #if QT_VERSION < 0x040000
|
|---|
| [720] | 346 | G4MouseMoveEvent(event->x(),event->y(),event->state());
|
|---|
| [606] | 347 | #else
|
|---|
| [720] | 348 | G4MouseMoveEvent(event->x(),event->y(),event->buttons());
|
|---|
| [606] | 349 | #endif
|
|---|
| [564] | 350 | }
|
|---|
| 351 |
|
|---|
| 352 |
|
|---|
| 353 | void G4OpenGLStoredQtViewer::contextMenuEvent(QContextMenuEvent *e)
|
|---|
| 354 | {
|
|---|
| [635] | 355 | #ifdef GEANT4_QT_DEBUG
|
|---|
| 356 | printf("G4OpenGLStoredQtViewer::contextMenuEvent\n");
|
|---|
| 357 | #endif
|
|---|
| [564] | 358 | manageContextMenuEvent(e);
|
|---|
| 359 | }
|
|---|
| 360 |
|
|---|
| 361 | void G4OpenGLStoredQtViewer::updateQWidget() {
|
|---|
| 362 | hasToRepaint= true;
|
|---|
| 363 | updateGL();
|
|---|
| 364 | hasToRepaint= false;
|
|---|
| 365 | }
|
|---|
| 366 |
|
|---|
| [673] | 367 |
|
|---|
| [531] | 368 | #endif
|
|---|