| 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.26 2009/07/27 14:01:13 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 | #include "G4OpenGLStoredQtViewer.hh"
|
|---|
| 37 |
|
|---|
| 38 | #include "G4ios.hh"
|
|---|
| 39 |
|
|---|
| 40 | G4OpenGLStoredQtViewer::G4OpenGLStoredQtViewer
|
|---|
| 41 | (G4OpenGLStoredSceneHandler& sceneHandler,
|
|---|
| 42 | const G4String& name):
|
|---|
| 43 | G4VViewer (sceneHandler, sceneHandler.IncrementViewCount (), name),
|
|---|
| 44 | G4OpenGLViewer (sceneHandler),
|
|---|
| 45 | G4OpenGLQtViewer (sceneHandler),
|
|---|
| 46 | G4OpenGLStoredViewer (sceneHandler), // FIXME : gerer le pb du parent !
|
|---|
| 47 | QGLWidget()
|
|---|
| 48 | {
|
|---|
| 49 | #ifdef G4DEBUG_VIS_OGL
|
|---|
| 50 | printf("G4OpenGLStoredQtViewer::Creation...................before.............%d x %d\n",width(),height());
|
|---|
| 51 | #endif
|
|---|
| 52 |
|
|---|
| 53 | #if QT_VERSION < 0x040000
|
|---|
| 54 | setFocusPolicy(QWidget::StrongFocus); // enable keybord events
|
|---|
| 55 | #else
|
|---|
| 56 | setFocusPolicy(Qt::StrongFocus); // enable keybord events
|
|---|
| 57 | #endif
|
|---|
| 58 | fHasToRepaint =false;
|
|---|
| 59 |
|
|---|
| 60 | if (fViewId < 0) return; // In case error in base class instantiation.
|
|---|
| 61 | }
|
|---|
| 62 |
|
|---|
| 63 | G4OpenGLStoredQtViewer::~G4OpenGLStoredQtViewer() {
|
|---|
| 64 | makeCurrent();
|
|---|
| 65 | // this is connect to the Dialog for deleting it properly
|
|---|
| 66 | // when close event.
|
|---|
| 67 | // ((QDialog*)window())->reject();
|
|---|
| 68 | }
|
|---|
| 69 |
|
|---|
| 70 | void G4OpenGLStoredQtViewer::Initialise() {
|
|---|
| 71 | #ifdef G4DEBUG_VIS_OGL
|
|---|
| 72 | printf("G4OpenGLStoredQtViewer::Initialise 1\n");
|
|---|
| 73 | #endif
|
|---|
| 74 | fReadyToPaint = false;
|
|---|
| 75 | #ifdef G4DEBUG_VIS_OGL
|
|---|
| 76 | printf("G4OpenGLStoredQtViewer::Initialize...................before.............%d x %d\n",width(),height());
|
|---|
| 77 | #endif
|
|---|
| 78 | CreateMainWindow (this,QString(fName));
|
|---|
| 79 | #ifdef G4DEBUG_VIS_OGL
|
|---|
| 80 | printf("G4OpenGLStoredQtViewer::Initialize...................after.............%d x %d\n",width(),height());
|
|---|
| 81 | #endif
|
|---|
| 82 | CreateFontLists ();
|
|---|
| 83 |
|
|---|
| 84 | fReadyToPaint = true;
|
|---|
| 85 | }
|
|---|
| 86 |
|
|---|
| 87 | void G4OpenGLStoredQtViewer::initializeGL () {
|
|---|
| 88 |
|
|---|
| 89 | InitializeGLView ();
|
|---|
| 90 |
|
|---|
| 91 | #ifdef G4DEBUG_VIS_OGL
|
|---|
| 92 | printf("G4OpenGLStoredQtViewer::InitialiseGL () 1\n");
|
|---|
| 93 | #endif
|
|---|
| 94 |
|
|---|
| 95 | // clear the buffers and window.
|
|---|
| 96 | ClearView ();
|
|---|
| 97 | FinishView ();
|
|---|
| 98 |
|
|---|
| 99 | glDepthFunc (GL_LEQUAL);
|
|---|
| 100 | glDepthMask (GL_TRUE);
|
|---|
| 101 |
|
|---|
| 102 | if (fSceneHandler.GetScene() == 0) {
|
|---|
| 103 | fHasToRepaint =false;
|
|---|
| 104 | } else {
|
|---|
| 105 | fHasToRepaint =true;
|
|---|
| 106 | }
|
|---|
| 107 |
|
|---|
| 108 | #ifdef G4DEBUG_VIS_OGL
|
|---|
| 109 | printf("G4OpenGLStoredQtViewer::InitialiseGL END\n");
|
|---|
| 110 | #endif
|
|---|
| 111 | }
|
|---|
| 112 |
|
|---|
| 113 |
|
|---|
| 114 | void G4OpenGLStoredQtViewer::DrawView () {
|
|---|
| 115 | #ifdef G4DEBUG_VIS_OGL
|
|---|
| 116 | printf("G4OpenGLStoredQtViewer::DrawView VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV\n");
|
|---|
| 117 | #endif
|
|---|
| 118 | // That's no the same logic as Immediate Viewer, I don't know why...
|
|---|
| 119 | // But if I send updateGL here, we go here :
|
|---|
| 120 | // updateQWidget -> paintGL -> ComputeView
|
|---|
| 121 | // whih is not the same as ComputeView Directly
|
|---|
| 122 | // And we loose the redraw of things !
|
|---|
| 123 |
|
|---|
| 124 | ComputeView();
|
|---|
| 125 | #ifdef G4DEBUG_VIS_OGL
|
|---|
| 126 | printf("G4OpenGLStoredQtViewer::DrawView ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n");
|
|---|
| 127 | #endif
|
|---|
| 128 | }
|
|---|
| 129 |
|
|---|
| 130 | void G4OpenGLStoredQtViewer::ComputeView () {
|
|---|
| 131 |
|
|---|
| 132 | #ifdef G4DEBUG_VIS_OGL
|
|---|
| 133 | printf("G4OpenGLStoredQtViewer::ComputeView %d %d VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV\n",getWinWidth(), getWinHeight());
|
|---|
| 134 | #endif
|
|---|
| 135 | makeCurrent();
|
|---|
| 136 | G4ViewParameters::DrawingStyle style = GetViewParameters().GetDrawingStyle();
|
|---|
| 137 |
|
|---|
| 138 | //Make sure current viewer is attached and clean...
|
|---|
| 139 |
|
|---|
| 140 | //See if things have changed from last time and remake if necessary...
|
|---|
| 141 | // The fNeedKernelVisit flag might have been set by the user in
|
|---|
| 142 | // /vis/viewer/rebuild, but if not, make decision and set flag only
|
|---|
| 143 | // if necessary...
|
|---|
| 144 | if (!fNeedKernelVisit) {
|
|---|
| 145 | KernelVisitDecision ();
|
|---|
| 146 | }
|
|---|
| 147 | G4bool kernelVisitWasNeeded = fNeedKernelVisit; // Keep (ProcessView resets).
|
|---|
| 148 | ProcessView ();
|
|---|
| 149 |
|
|---|
| 150 |
|
|---|
| 151 | if(style!=G4ViewParameters::hlr &&
|
|---|
| 152 | haloing_enabled) {
|
|---|
| 153 | #ifdef G4DEBUG_VIS_OGL
|
|---|
| 154 | printf("G4OpenGLStoredQtViewer::ComputeView DANS LE IF\n");
|
|---|
| 155 | #endif
|
|---|
| 156 |
|
|---|
| 157 | HaloingFirstPass ();
|
|---|
| 158 | DrawDisplayLists ();
|
|---|
| 159 | glFlush ();
|
|---|
| 160 |
|
|---|
| 161 | HaloingSecondPass ();
|
|---|
| 162 |
|
|---|
| 163 | DrawDisplayLists ();
|
|---|
| 164 | FinishView ();
|
|---|
| 165 |
|
|---|
| 166 | } else {
|
|---|
| 167 |
|
|---|
| 168 | // If kernel visit was needed, drawing and FinishView will already
|
|---|
| 169 | // have been done, so...
|
|---|
| 170 | if (!kernelVisitWasNeeded) {
|
|---|
| 171 | #ifdef G4DEBUG_VIS_OGL
|
|---|
| 172 | printf("************************** G4OpenGLStoredQtViewer::ComputeView Don't need kernel Visit \n");
|
|---|
| 173 | #endif
|
|---|
| 174 | DrawDisplayLists ();
|
|---|
| 175 | FinishView ();
|
|---|
| 176 | } else {
|
|---|
| 177 | #ifdef G4DEBUG_VIS_OGL
|
|---|
| 178 | printf("************************** G4OpenGLStoredQtViewer::ComputeView need kernel Visit \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 G4DEBUG_VIS_OGL
|
|---|
| 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 | if (isRecording()) {
|
|---|
| 198 | savePPMToTemp();
|
|---|
| 199 | }
|
|---|
| 200 |
|
|---|
| 201 | #ifdef G4DEBUG_VIS_OGL
|
|---|
| 202 | printf("G4OpenGLStoredQtViewer::ComputeView %d %d ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \n",getWinWidth(), getWinHeight());
|
|---|
| 203 | #endif
|
|---|
| 204 | fHasToRepaint =true;
|
|---|
| 205 | }
|
|---|
| 206 |
|
|---|
| 207 |
|
|---|
| 208 | /**
|
|---|
| 209 | - Lors du resize de la fenetre, on doit non pas redessiner le detecteur, mais aussi les evenements
|
|---|
| 210 | */
|
|---|
| 211 | void G4OpenGLStoredQtViewer::resizeGL(
|
|---|
| 212 | int aWidth
|
|---|
| 213 | ,int aHeight)
|
|---|
| 214 | {
|
|---|
| 215 | #ifdef G4DEBUG_VIS_OGL
|
|---|
| 216 | printf("G4OpenGLStoredQtViewer::resizeEvent..%d x %d vvvvvv\n",aWidth,aHeight);
|
|---|
| 217 | #endif
|
|---|
| 218 | #ifdef G4DEBUG_VIS_OGL
|
|---|
| 219 | printf("G4OpenGLStoredQtViewer::resizeEvent size ? %d x %d\n",width(),height());
|
|---|
| 220 | #endif
|
|---|
| 221 | // Set new size, it will be update when next Repaint()->SetView() called
|
|---|
| 222 | ResizeWindow(aWidth,aHeight);
|
|---|
| 223 | fHasToRepaint = sizeHasChanged();
|
|---|
| 224 | #ifdef G4DEBUG_VIS_OGL
|
|---|
| 225 | printf("G4OpenGLStoredQtViewer::resizeEvent.. ^^^^^^^^\n");
|
|---|
| 226 | #endif
|
|---|
| 227 | }
|
|---|
| 228 |
|
|---|
| 229 |
|
|---|
| 230 | void G4OpenGLStoredQtViewer::paintGL()
|
|---|
| 231 | {
|
|---|
| 232 | #ifdef G4DEBUG_VIS_OGL
|
|---|
| 233 | printf("G4OpenGLStoredQtViewer::paintGL ready:%d fHasTo:%d??\n",fReadyToPaint,fHasToRepaint);
|
|---|
| 234 | #endif
|
|---|
| 235 | if (!fReadyToPaint) {
|
|---|
| 236 | fReadyToPaint= true;
|
|---|
| 237 | return;
|
|---|
| 238 | }
|
|---|
| 239 | // DO NOT RESIZE IF SIZE HAS NOT CHANGE :
|
|---|
| 240 | // WHEN CLICK ON THE FRAME FOR EXAMPLE
|
|---|
| 241 | // EXECEPT WHEN MOUSE MOVE EVENT
|
|---|
| 242 | if ( !fHasToRepaint) {
|
|---|
| 243 | #ifdef G4DEBUG_VIS_OGL
|
|---|
| 244 | printf("G4OpenGLStoredQtViewer::paintGL size ? %d x %d\n",width(),height());
|
|---|
| 245 | #endif
|
|---|
| 246 | #ifdef G4DEBUG_VIS_OGL
|
|---|
| 247 | printf("G4OpenGLStoredQtViewer::paintGL %d = %d %d = %d\n",getWinWidth(),width(),getWinHeight(),height());
|
|---|
| 248 | int sw = 0;
|
|---|
| 249 | int sh = 0;
|
|---|
| 250 | if (!isMaximized() && !isFullScreen()) {
|
|---|
| 251 | sw = normalGeometry().width();
|
|---|
| 252 | sh = normalGeometry().height();
|
|---|
| 253 | } else {
|
|---|
| 254 | sw = frameGeometry().width();
|
|---|
| 255 | sh = frameGeometry().height();
|
|---|
| 256 | }
|
|---|
| 257 | printf("G4OpenGLStoredQtViewer::paintGL ................................%d x %d \n",sw,sh);
|
|---|
| 258 |
|
|---|
| 259 | #endif
|
|---|
| 260 | if (((getWinWidth() == (unsigned int)width())) &&(getWinHeight() == (unsigned int) height())) {
|
|---|
| 261 | return;
|
|---|
| 262 | }
|
|---|
| 263 | }
|
|---|
| 264 | #ifdef G4DEBUG_VIS_OGL
|
|---|
| 265 | printf("G4OpenGLStoredQtViewer::paintGL VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV ready %d\n",fReadyToPaint);
|
|---|
| 266 | #endif
|
|---|
| 267 |
|
|---|
| 268 | SetView();
|
|---|
| 269 |
|
|---|
| 270 | ClearView (); //ok, put the background correct
|
|---|
| 271 | ComputeView();
|
|---|
| 272 |
|
|---|
| 273 | fHasToRepaint =false;
|
|---|
| 274 |
|
|---|
| 275 | #ifdef G4DEBUG_VIS_OGL
|
|---|
| 276 | printf("G4OpenGLStoredQtViewer::paintGL ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ready %d\n",fReadyToPaint);
|
|---|
| 277 | #endif
|
|---|
| 278 | }
|
|---|
| 279 |
|
|---|
| 280 | void G4OpenGLStoredQtViewer::mousePressEvent(QMouseEvent *event)
|
|---|
| 281 | {
|
|---|
| 282 | G4MousePressEvent(event);
|
|---|
| 283 | }
|
|---|
| 284 |
|
|---|
| 285 | void G4OpenGLStoredQtViewer::keyPressEvent (QKeyEvent * event)
|
|---|
| 286 | {
|
|---|
| 287 | G4keyPressEvent(event);
|
|---|
| 288 | }
|
|---|
| 289 |
|
|---|
| 290 | void G4OpenGLStoredQtViewer::wheelEvent (QWheelEvent * event)
|
|---|
| 291 | {
|
|---|
| 292 | G4wheelEvent(event);
|
|---|
| 293 | }
|
|---|
| 294 |
|
|---|
| 295 | /**
|
|---|
| 296 | * This function was build in order to make a zoom on double clic event.
|
|---|
| 297 | * It was think to build a rubberband on the zoom area, but never work fine
|
|---|
| 298 | */
|
|---|
| 299 | void G4OpenGLStoredQtViewer::mouseDoubleClickEvent(QMouseEvent *)
|
|---|
| 300 | {
|
|---|
| 301 | G4MouseDoubleClickEvent();
|
|---|
| 302 | }
|
|---|
| 303 |
|
|---|
| 304 | void G4OpenGLStoredQtViewer::mouseReleaseEvent(QMouseEvent *)
|
|---|
| 305 | {
|
|---|
| 306 | G4MouseReleaseEvent();
|
|---|
| 307 | }
|
|---|
| 308 |
|
|---|
| 309 | void G4OpenGLStoredQtViewer::mouseMoveEvent(QMouseEvent *event)
|
|---|
| 310 | {
|
|---|
| 311 | G4MouseMoveEvent(event);
|
|---|
| 312 | }
|
|---|
| 313 |
|
|---|
| 314 |
|
|---|
| 315 | void G4OpenGLStoredQtViewer::contextMenuEvent(QContextMenuEvent *e)
|
|---|
| 316 | {
|
|---|
| 317 | G4manageContextMenuEvent(e);
|
|---|
| 318 | }
|
|---|
| 319 |
|
|---|
| 320 |
|
|---|
| 321 | void G4OpenGLStoredQtViewer::paintEvent ( QPaintEvent * event )
|
|---|
| 322 | {
|
|---|
| 323 | #ifdef G4DEBUG_VIS_OGL
|
|---|
| 324 | printf("G4OpenGLStoredQtViewer::paintEvent...................repaint.............%d x %d\n",width(),height());
|
|---|
| 325 | #endif
|
|---|
| 326 | QGLWidget::paintEvent(event);
|
|---|
| 327 | }
|
|---|
| 328 |
|
|---|
| 329 | void G4OpenGLStoredQtViewer::updateQWidget() {
|
|---|
| 330 | fHasToRepaint= true;
|
|---|
| 331 | updateGL();
|
|---|
| 332 | fHasToRepaint= false;
|
|---|
| 333 | }
|
|---|
| 334 |
|
|---|
| 335 | void G4OpenGLStoredQtViewer::ShowView (
|
|---|
| 336 | )
|
|---|
| 337 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 338 | //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
|
|---|
| 339 | {
|
|---|
| 340 | #if QT_VERSION < 0x040000
|
|---|
| 341 | setActiveWindow();
|
|---|
| 342 | #else
|
|---|
| 343 | activateWindow();
|
|---|
| 344 | #endif
|
|---|
| 345 | }
|
|---|
| 346 |
|
|---|
| 347 | #endif
|
|---|