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