| [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 | //
|
|---|
| [688] | 27 | // $Id: G4OpenGLStoredQtViewer.cc,v 1.8 2008/01/15 11:05:08 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 |
|
|---|
| [635] | 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),
|
|---|
| 51 | G4OpenGLStoredViewer (sceneHandler),
|
|---|
| 52 | QGLWidget(QGLFormat(QGL::SampleBuffers)) // FIXME : gerer le pb du parent !
|
|---|
| 53 | {
|
|---|
| [696] | 54 | setFocusPolicy(Qt::StrongFocus); // enable keybord events
|
|---|
| [682] | 55 | nbPaint =0;
|
|---|
| 56 | hasToRepaint =false;
|
|---|
| [531] | 57 | if (fViewId < 0) return; // In case error in base class instantiation.
|
|---|
| 58 | }
|
|---|
| 59 |
|
|---|
| [564] | 60 | G4OpenGLStoredQtViewer::~G4OpenGLStoredQtViewer() {
|
|---|
| [608] | 61 | #ifdef GEANT4_QT_DEBUG
|
|---|
| [682] | 62 | printf("GLWidget::~GLWidget \n");
|
|---|
| [608] | 63 | #endif
|
|---|
| [682] | 64 | makeCurrent();
|
|---|
| 65 | // this is connect to the Dialog for deleting it properly
|
|---|
| 66 | // when close event.
|
|---|
| 67 | // ((QDialog*)window())->reject();
|
|---|
| [608] | 68 | #ifdef GEANT4_QT_DEBUG
|
|---|
| [682] | 69 | printf("GLWidget::~GLWidget END\n");
|
|---|
| [608] | 70 | #endif
|
|---|
| [564] | 71 | }
|
|---|
| [531] | 72 |
|
|---|
| [564] | 73 | void G4OpenGLStoredQtViewer::Initialise() {
|
|---|
| [608] | 74 | #ifdef GEANT4_QT_DEBUG
|
|---|
| [682] | 75 | printf("GLWidget::Initialise \n");
|
|---|
| [608] | 76 | #endif
|
|---|
| [682] | 77 | readyToPaint = false;
|
|---|
| 78 | CreateGLQtContext ();
|
|---|
| [608] | 79 | #ifdef GEANT4_QT_DEBUG
|
|---|
| [682] | 80 | printf("G4OpenGLStoredQtViewer::Initialise () 2\n");
|
|---|
| [608] | 81 | #endif
|
|---|
| [564] | 82 | CreateMainWindow (this);
|
|---|
| [608] | 83 | #ifdef GEANT4_QT_DEBUG
|
|---|
| [564] | 84 | printf("G4OpenGLStoredQtViewer::Initialise () 3\n");
|
|---|
| [608] | 85 | #endif
|
|---|
| [682] | 86 | CreateFontLists (); // FIXME Does nothing!
|
|---|
| [564] | 87 |
|
|---|
| [608] | 88 | #ifdef GEANT4_QT_DEBUG
|
|---|
| [564] | 89 | printf("readyToPaint = true \n");
|
|---|
| [608] | 90 | #endif
|
|---|
| [564] | 91 | readyToPaint = true;
|
|---|
| 92 |
|
|---|
| 93 | // First Draw
|
|---|
| 94 | SetView();
|
|---|
| [608] | 95 | #ifdef GEANT4_QT_DEBUG
|
|---|
| [564] | 96 | printf(" ClearView\n");
|
|---|
| [608] | 97 | #endif
|
|---|
| [564] | 98 | ClearView (); //ok, put the background correct
|
|---|
| 99 | FinishView();
|
|---|
| 100 | }
|
|---|
| [531] | 101 |
|
|---|
| [564] | 102 | void G4OpenGLStoredQtViewer::initializeGL () {
|
|---|
| 103 |
|
|---|
| [682] | 104 | InitializeGLView ();
|
|---|
| [564] | 105 |
|
|---|
| [608] | 106 | #ifdef GEANT4_QT_DEBUG
|
|---|
| [682] | 107 | printf("G4OpenGLStoredQtViewer::InitialiseGL () 1\n");
|
|---|
| [608] | 108 | #endif
|
|---|
| [564] | 109 |
|
|---|
| [682] | 110 | // clear the buffers and window.
|
|---|
| 111 | ClearView ();
|
|---|
| 112 | // printf("G4OpenGLStoredQtViewer::InitialiseGL () 2\n");
|
|---|
| 113 | FinishView ();
|
|---|
| [564] | 114 |
|
|---|
| [682] | 115 | glDepthFunc (GL_LEQUAL);
|
|---|
| 116 | glDepthMask (GL_TRUE);
|
|---|
| [564] | 117 |
|
|---|
| [682] | 118 | hasToRepaint =true;
|
|---|
| [564] | 119 |
|
|---|
| [608] | 120 | #ifdef GEANT4_QT_DEBUG
|
|---|
| [682] | 121 | printf("G4OpenGLStoredQtViewer::InitialiseGL -------------------------------------------------------------------------------------\n");
|
|---|
| [608] | 122 | #endif
|
|---|
| [531] | 123 | }
|
|---|
| 124 |
|
|---|
| [564] | 125 |
|
|---|
| [533] | 126 | void G4OpenGLStoredQtViewer::DrawView () {
|
|---|
| [682] | 127 |
|
|---|
| [608] | 128 | #ifdef GEANT4_QT_DEBUG
|
|---|
| [564] | 129 | printf("G4OpenGLStoredQtViewer::DrawView %d %d VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV\n",WinSize_x, WinSize_y);
|
|---|
| [608] | 130 | #endif
|
|---|
| [682] | 131 | G4ViewParameters::DrawingStyle style = GetViewParameters().GetDrawingStyle();
|
|---|
| [531] | 132 |
|
|---|
| [682] | 133 | //Make sure current viewer is attached and clean...
|
|---|
| 134 | //Qt version needed
|
|---|
| 135 | // glViewport (0, 0, WinSize_x, WinSize_y);
|
|---|
| [531] | 136 |
|
|---|
| [682] | 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...
|
|---|
| 141 | if (!fNeedKernelVisit)
|
|---|
| [565] | 142 |
|
|---|
| [682] | 143 | if (!fNeedKernelVisit) KernelVisitDecision ();
|
|---|
| [565] | 144 |
|
|---|
| [682] | 145 | G4bool kernelVisitWasNeeded = fNeedKernelVisit; // Keep (ProcessView resets).
|
|---|
| 146 | ProcessView ();
|
|---|
| [564] | 147 |
|
|---|
| [531] | 148 |
|
|---|
| [682] | 149 | if(style!=G4ViewParameters::hlr &&
|
|---|
| 150 | haloing_enabled) {
|
|---|
| [608] | 151 | #ifdef GEANT4_QT_DEBUG
|
|---|
| [682] | 152 | printf("G4OpenGLStoredQtViewer::DrawView DANS LE IF\n");
|
|---|
| [608] | 153 | #endif
|
|---|
| [531] | 154 |
|
|---|
| [682] | 155 | HaloingFirstPass ();
|
|---|
| 156 | DrawDisplayLists ();
|
|---|
| 157 | glFlush ();
|
|---|
| [531] | 158 |
|
|---|
| [682] | 159 | HaloingSecondPass ();
|
|---|
| [531] | 160 |
|
|---|
| [682] | 161 | DrawDisplayLists ();
|
|---|
| 162 | FinishView ();
|
|---|
| [531] | 163 |
|
|---|
| [682] | 164 | } else {
|
|---|
| [608] | 165 | #ifdef GEANT4_QT_DEBUG
|
|---|
| [682] | 166 | printf("*************************** CASE 1 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \n");
|
|---|
| [608] | 167 | #endif
|
|---|
| [564] | 168 |
|
|---|
| [682] | 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
|
|---|
| [682] | 173 | printf("*************************** CASE 2 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \n");
|
|---|
| [608] | 174 | #endif
|
|---|
| [682] | 175 | DrawDisplayLists ();
|
|---|
| 176 | FinishView ();
|
|---|
| 177 | } else {
|
|---|
| [608] | 178 | #ifdef GEANT4_QT_DEBUG
|
|---|
| [682] | 179 | printf("*************************** CASE 3 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \n");
|
|---|
| [608] | 180 | #endif
|
|---|
| [682] | 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 ();
|
|---|
| 187 | FinishView ();
|
|---|
| [608] | 188 | #ifdef GEANT4_QT_DEBUG
|
|---|
| [682] | 189 | printf("*************************** CASE 4 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \n");
|
|---|
| [608] | 190 | #endif
|
|---|
| [682] | 191 | } else { // ADD TO AVOID KernelVisit=1 and nothing to display
|
|---|
| 192 | DrawDisplayLists ();
|
|---|
| 193 | FinishView ();
|
|---|
| 194 | }
|
|---|
| 195 | }
|
|---|
| 196 | }
|
|---|
| [564] | 197 |
|
|---|
| [608] | 198 | #ifdef GEANT4_QT_DEBUG
|
|---|
| [682] | 199 | printf("G4OpenGLStoredQtViewer::DrawView %d %d ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \n",WinSize_x, WinSize_y);
|
|---|
| [608] | 200 | #endif
|
|---|
| [682] | 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 | /**
|
|---|
| [682] | 225 | - Lors du resize de la fenetre, on doit non pas redessiner le detecteur, mais aussi les evenements
|
|---|
| 226 | */
|
|---|
| [564] | 227 | void G4OpenGLStoredQtViewer::resizeGL(
|
|---|
| [682] | 228 | int aWidth
|
|---|
| 229 | ,int aHeight)
|
|---|
| [564] | 230 | {
|
|---|
| [673] | 231 | setupViewport(aWidth,aHeight);
|
|---|
| [564] | 232 |
|
|---|
| [682] | 233 | if (((WinSize_x != (G4int)aWidth)) || (WinSize_y != (G4int) aHeight)) {
|
|---|
| 234 | hasToRepaint =true;
|
|---|
| 235 | }
|
|---|
| 236 | WinSize_x = (G4int) aWidth;
|
|---|
| 237 | WinSize_y = (G4int) aHeight;
|
|---|
| 238 |
|
|---|
| [608] | 239 | #ifdef GEANT4_QT_DEBUG
|
|---|
| [564] | 240 | printf("G4OpenGLStoredQtViewer::resizeGL ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ %d %d=%d %d=%d\n",hasToRepaint,width(),aWidth,height(),aHeight);
|
|---|
| [608] | 241 | #endif
|
|---|
| [564] | 242 | }
|
|---|
| 243 |
|
|---|
| 244 |
|
|---|
| [673] | 245 | /**
|
|---|
| [682] | 246 | @see :
|
|---|
| [673] | 247 | */
|
|---|
| [564] | 248 |
|
|---|
| 249 | void G4OpenGLStoredQtViewer::paintGL()
|
|---|
| [682] | 250 | {
|
|---|
| [675] | 251 |
|
|---|
| [682] | 252 | if (!readyToPaint) {
|
|---|
| [608] | 253 | #ifdef GEANT4_QT_DEBUG
|
|---|
| [682] | 254 | printf("G4OpenGLStoredQtViewer::paintGL ============ Not ready %d\n",readyToPaint);
|
|---|
| [608] | 255 | #endif
|
|---|
| [682] | 256 | readyToPaint= true;
|
|---|
| 257 | return;
|
|---|
| 258 | }
|
|---|
| 259 | // DO NOT RESIZE IF SIZE HAS NOT CHANGE :
|
|---|
| 260 | // WHEN CLICK ON THE FRAME FOR EXAMPLE
|
|---|
| 261 | // EXECEPT WHEN MOUSE MOVE EVENT
|
|---|
| 262 | if ( !hasToRepaint) {
|
|---|
| 263 | if (((WinSize_x == (G4int)width())) &&(WinSize_y == (G4int) height())) {
|
|---|
| [608] | 264 | #ifdef GEANT4_QT_DEBUG
|
|---|
| [682] | 265 | printf("G4OpenGLStoredQtViewer::paintGL ============ Dont repaint\n");
|
|---|
| [608] | 266 | #endif
|
|---|
| [682] | 267 | return;
|
|---|
| 268 | }
|
|---|
| 269 | }
|
|---|
| 270 | nbPaint++;
|
|---|
| [608] | 271 | #ifdef GEANT4_QT_DEBUG
|
|---|
| [682] | 272 | printf("G4OpenGLStoredQtViewer::paintGL VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV %d ready %d\n",nbPaint,readyToPaint);
|
|---|
| [608] | 273 | #endif
|
|---|
| [682] | 274 | WinSize_x = (G4int) width();
|
|---|
| 275 | WinSize_y = (G4int) height();
|
|---|
| [673] | 276 |
|
|---|
| [682] | 277 | setupViewport(width(),height());
|
|---|
| 278 | // glViewport (0, 0, width(), height());
|
|---|
| 279 | // glLoadIdentity();
|
|---|
| [673] | 280 |
|
|---|
| 281 |
|
|---|
| [682] | 282 | SetView();
|
|---|
| [673] | 283 |
|
|---|
| [682] | 284 | // // printf("before ClearView\n");
|
|---|
| [608] | 285 | #ifdef GEANT4_QT_DEBUG
|
|---|
| [682] | 286 | printf(" ClearView\n");
|
|---|
| [608] | 287 | #endif
|
|---|
| [673] | 288 |
|
|---|
| [682] | 289 | ClearView (); //ok, put the background correct
|
|---|
| 290 | DrawView();
|
|---|
| [673] | 291 |
|
|---|
| [682] | 292 | hasToRepaint =false;
|
|---|
| [673] | 293 |
|
|---|
| [608] | 294 | #ifdef GEANT4_QT_DEBUG
|
|---|
| [682] | 295 | printf("G4OpenGLStoredQtViewer::paintGL ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ %d ready %d\n",nbPaint,readyToPaint);
|
|---|
| [608] | 296 | #endif
|
|---|
| [682] | 297 | }
|
|---|
| [564] | 298 |
|
|---|
| 299 | void G4OpenGLStoredQtViewer::mousePressEvent(QMouseEvent *event)
|
|---|
| 300 | {
|
|---|
| [690] | 301 | if ((event->buttons() & Qt::LeftButton)
|
|---|
| 302 | && !((event->modifiers() & Qt::ShiftModifier)
|
|---|
| 303 | || (event->modifiers() & Qt::ControlModifier)
|
|---|
| 304 | || (event->modifiers() & Qt::AltModifier)
|
|---|
| 305 | || (event->modifiers() & Qt::MetaModifier))) {
|
|---|
| [608] | 306 | #ifdef GEANT4_QT_DEBUG
|
|---|
| [682] | 307 | printf("G4OpenGLStoredQtViewer::mousePressEvent\n");
|
|---|
| [608] | 308 | #endif
|
|---|
| [682] | 309 | setMouseTracking(true);
|
|---|
| 310 | G4MousePressEvent(event->pos());
|
|---|
| 311 | }
|
|---|
| [564] | 312 | }
|
|---|
| 313 |
|
|---|
| [696] | 314 | void G4OpenGLStoredQtViewer::keyPressEvent (QKeyEvent * event)
|
|---|
| 315 | {
|
|---|
| 316 | G4keyPressEvent(event);
|
|---|
| 317 | }
|
|---|
| 318 |
|
|---|
| [678] | 319 | /**
|
|---|
| 320 | * This function was build in order to make a zoom on double clic event.
|
|---|
| 321 | * It was think to build a rubberband on the zoom area, but never work fine
|
|---|
| 322 | */
|
|---|
| [673] | 323 | void G4OpenGLStoredQtViewer::mouseDoubleClickEvent(QMouseEvent *event)
|
|---|
| 324 | {
|
|---|
| 325 | #ifdef GEANT4_QT_DEBUG
|
|---|
| 326 | printf("G4OpenGLStoredQtViewer::mouseDoubleClickEvent\n");
|
|---|
| 327 | #endif
|
|---|
| [682] | 328 | // setMouseTracking(true);
|
|---|
| 329 | // glBufferImage = grabFrameBuffer().convertToFormat(QImage::Format_ARGB32);//_Premultiplied);
|
|---|
| [673] | 330 | }
|
|---|
| 331 |
|
|---|
| 332 | void G4OpenGLStoredQtViewer::mouseReleaseEvent(QMouseEvent *event)
|
|---|
| 333 | {
|
|---|
| 334 | #ifdef GEANT4_QT_DEBUG
|
|---|
| 335 | printf("G4OpenGLStoredQtViewer::mouseReleaseEvent\n");
|
|---|
| 336 | #endif
|
|---|
| [682] | 337 | // setMouseTracking(false);
|
|---|
| [673] | 338 | }
|
|---|
| 339 |
|
|---|
| [564] | 340 | void G4OpenGLStoredQtViewer::mouseMoveEvent(QMouseEvent *event)
|
|---|
| 341 | {
|
|---|
| [678] | 342 |
|
|---|
| [606] | 343 | #if QT_VERSION < 0x040000
|
|---|
| [696] | 344 | G4MouseEvent(event->x(),event->y(),event->state());
|
|---|
| [606] | 345 | #else
|
|---|
| [696] | 346 | G4MouseEvent(event->x(),event->y(),event->buttons());
|
|---|
| [606] | 347 | #endif
|
|---|
| [564] | 348 | }
|
|---|
| 349 |
|
|---|
| 350 |
|
|---|
| 351 | void G4OpenGLStoredQtViewer::contextMenuEvent(QContextMenuEvent *e)
|
|---|
| 352 | {
|
|---|
| [635] | 353 | #ifdef GEANT4_QT_DEBUG
|
|---|
| 354 | printf("G4OpenGLStoredQtViewer::contextMenuEvent\n");
|
|---|
| 355 | #endif
|
|---|
| [564] | 356 | manageContextMenuEvent(e);
|
|---|
| 357 | }
|
|---|
| 358 |
|
|---|
| 359 | void G4OpenGLStoredQtViewer::updateQWidget() {
|
|---|
| 360 | hasToRepaint= true;
|
|---|
| 361 | updateGL();
|
|---|
| 362 | hasToRepaint= false;
|
|---|
| 363 | }
|
|---|
| 364 |
|
|---|
| [673] | 365 |
|
|---|
| [531] | 366 | #endif
|
|---|