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