| [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 | //
|
|---|
| [1092] | 27 | // $Id: G4OpenGLStoredQtViewer.cc,v 1.26 2009/07/27 14:01:13 lgarnier Exp $
|
|---|
| [866] | 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 |
|
|---|
| [533] | 36 | #include "G4OpenGLStoredQtViewer.hh"
|
|---|
| [531] | 37 |
|
|---|
| 38 | #include "G4ios.hh"
|
|---|
| 39 |
|
|---|
| [533] | 40 | G4OpenGLStoredQtViewer::G4OpenGLStoredQtViewer
|
|---|
| [531] | 41 | (G4OpenGLStoredSceneHandler& sceneHandler,
|
|---|
| 42 | const G4String& name):
|
|---|
| [682] | 43 | G4VViewer (sceneHandler, sceneHandler.IncrementViewCount (), name),
|
|---|
| 44 | G4OpenGLViewer (sceneHandler),
|
|---|
| 45 | G4OpenGLQtViewer (sceneHandler),
|
|---|
| [1124] | 46 | G4OpenGLStoredViewer (sceneHandler), // FIXME : gerer le pb du parent !
|
|---|
| 47 | QGLWidget()
|
|---|
| [682] | 48 | {
|
|---|
| [1124] | 49 | #ifdef G4DEBUG_VIS_OGL
|
|---|
| 50 | printf("G4OpenGLStoredQtViewer::Creation...................before.............%d x %d\n",width(),height());
|
|---|
| 51 | #endif
|
|---|
| [863] | 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
|
|---|
| [1040] | 58 | fHasToRepaint =false;
|
|---|
| [858] | 59 |
|
|---|
| [531] | 60 | if (fViewId < 0) return; // In case error in base class instantiation.
|
|---|
| 61 | }
|
|---|
| 62 |
|
|---|
| [564] | 63 | G4OpenGLStoredQtViewer::~G4OpenGLStoredQtViewer() {
|
|---|
| [682] | 64 | makeCurrent();
|
|---|
| 65 | // this is connect to the Dialog for deleting it properly
|
|---|
| 66 | // when close event.
|
|---|
| 67 | // ((QDialog*)window())->reject();
|
|---|
| [564] | 68 | }
|
|---|
| [531] | 69 |
|
|---|
| [564] | 70 | void G4OpenGLStoredQtViewer::Initialise() {
|
|---|
| [911] | 71 | #ifdef G4DEBUG_VIS_OGL
|
|---|
| [858] | 72 | printf("G4OpenGLStoredQtViewer::Initialise 1\n");
|
|---|
| [608] | 73 | #endif
|
|---|
| [1040] | 74 | fReadyToPaint = false;
|
|---|
| [1124] | 75 | #ifdef G4DEBUG_VIS_OGL
|
|---|
| 76 | printf("G4OpenGLStoredQtViewer::Initialize...................before.............%d x %d\n",width(),height());
|
|---|
| 77 | #endif
|
|---|
| [866] | 78 | CreateMainWindow (this,QString(fName));
|
|---|
| [1124] | 79 | #ifdef G4DEBUG_VIS_OGL
|
|---|
| 80 | printf("G4OpenGLStoredQtViewer::Initialize...................after.............%d x %d\n",width(),height());
|
|---|
| 81 | #endif
|
|---|
| [873] | 82 | CreateFontLists ();
|
|---|
| [564] | 83 |
|
|---|
| [1040] | 84 | fReadyToPaint = true;
|
|---|
| [564] | 85 | }
|
|---|
| [531] | 86 |
|
|---|
| [564] | 87 | void G4OpenGLStoredQtViewer::initializeGL () {
|
|---|
| 88 |
|
|---|
| [682] | 89 | InitializeGLView ();
|
|---|
| [564] | 90 |
|
|---|
| [911] | 91 | #ifdef G4DEBUG_VIS_OGL
|
|---|
| [682] | 92 | printf("G4OpenGLStoredQtViewer::InitialiseGL () 1\n");
|
|---|
| [608] | 93 | #endif
|
|---|
| [564] | 94 |
|
|---|
| [682] | 95 | // clear the buffers and window.
|
|---|
| 96 | ClearView ();
|
|---|
| 97 | FinishView ();
|
|---|
| [564] | 98 |
|
|---|
| [682] | 99 | glDepthFunc (GL_LEQUAL);
|
|---|
| 100 | glDepthMask (GL_TRUE);
|
|---|
| [564] | 101 |
|
|---|
| [866] | 102 | if (fSceneHandler.GetScene() == 0) {
|
|---|
| [1040] | 103 | fHasToRepaint =false;
|
|---|
| [866] | 104 | } else {
|
|---|
| [1040] | 105 | fHasToRepaint =true;
|
|---|
| [866] | 106 | }
|
|---|
| [564] | 107 |
|
|---|
| [911] | 108 | #ifdef G4DEBUG_VIS_OGL
|
|---|
| [873] | 109 | printf("G4OpenGLStoredQtViewer::InitialiseGL END\n");
|
|---|
| [608] | 110 | #endif
|
|---|
| [531] | 111 | }
|
|---|
| 112 |
|
|---|
| [564] | 113 |
|
|---|
| [533] | 114 | void G4OpenGLStoredQtViewer::DrawView () {
|
|---|
| [911] | 115 | #ifdef G4DEBUG_VIS_OGL
|
|---|
| [877] | 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 |
|
|---|
| [1039] | 124 | ComputeView();
|
|---|
| [911] | 125 | #ifdef G4DEBUG_VIS_OGL
|
|---|
| [877] | 126 | printf("G4OpenGLStoredQtViewer::DrawView ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n");
|
|---|
| 127 | #endif
|
|---|
| 128 | }
|
|---|
| [682] | 129 |
|
|---|
| [877] | 130 | void G4OpenGLStoredQtViewer::ComputeView () {
|
|---|
| [1122] | 131 |
|
|---|
| 132 | #ifdef G4DEBUG_VIS_OGL
|
|---|
| [1039] | 133 | printf("G4OpenGLStoredQtViewer::ComputeView %d %d VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV\n",getWinWidth(), getWinHeight());
|
|---|
| [608] | 134 | #endif
|
|---|
| [877] | 135 | makeCurrent();
|
|---|
| [682] | 136 | G4ViewParameters::DrawingStyle style = GetViewParameters().GetDrawingStyle();
|
|---|
| [531] | 137 |
|
|---|
| [682] | 138 | //Make sure current viewer is attached and clean...
|
|---|
| [531] | 139 |
|
|---|
| [682] | 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...
|
|---|
| [873] | 144 | if (!fNeedKernelVisit) {
|
|---|
| [877] | 145 | KernelVisitDecision ();
|
|---|
| [873] | 146 | }
|
|---|
| [682] | 147 | G4bool kernelVisitWasNeeded = fNeedKernelVisit; // Keep (ProcessView resets).
|
|---|
| 148 | ProcessView ();
|
|---|
| [564] | 149 |
|
|---|
| [531] | 150 |
|
|---|
| [682] | 151 | if(style!=G4ViewParameters::hlr &&
|
|---|
| 152 | haloing_enabled) {
|
|---|
| [911] | 153 | #ifdef G4DEBUG_VIS_OGL
|
|---|
| [877] | 154 | printf("G4OpenGLStoredQtViewer::ComputeView DANS LE IF\n");
|
|---|
| [608] | 155 | #endif
|
|---|
| [531] | 156 |
|
|---|
| [682] | 157 | HaloingFirstPass ();
|
|---|
| 158 | DrawDisplayLists ();
|
|---|
| 159 | glFlush ();
|
|---|
| [531] | 160 |
|
|---|
| [682] | 161 | HaloingSecondPass ();
|
|---|
| [531] | 162 |
|
|---|
| [682] | 163 | DrawDisplayLists ();
|
|---|
| 164 | FinishView ();
|
|---|
| [531] | 165 |
|
|---|
| [682] | 166 | } else {
|
|---|
| [564] | 167 |
|
|---|
| [682] | 168 | // If kernel visit was needed, drawing and FinishView will already
|
|---|
| 169 | // have been done, so...
|
|---|
| 170 | if (!kernelVisitWasNeeded) {
|
|---|
| [911] | 171 | #ifdef G4DEBUG_VIS_OGL
|
|---|
| [877] | 172 | printf("************************** G4OpenGLStoredQtViewer::ComputeView Don't need kernel Visit \n");
|
|---|
| [608] | 173 | #endif
|
|---|
| [682] | 174 | DrawDisplayLists ();
|
|---|
| 175 | FinishView ();
|
|---|
| 176 | } else {
|
|---|
| [911] | 177 | #ifdef G4DEBUG_VIS_OGL
|
|---|
| [877] | 178 | printf("************************** G4OpenGLStoredQtViewer::ComputeView need kernel Visit \n");
|
|---|
| [608] | 179 | #endif
|
|---|
| [682] | 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 ();
|
|---|
| [911] | 187 | #ifdef G4DEBUG_VIS_OGL
|
|---|
| [682] | 188 | printf("*************************** CASE 4 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \n");
|
|---|
| [608] | 189 | #endif
|
|---|
| [682] | 190 | } else { // ADD TO AVOID KernelVisit=1 and nothing to display
|
|---|
| 191 | DrawDisplayLists ();
|
|---|
| 192 | FinishView ();
|
|---|
| 193 | }
|
|---|
| 194 | }
|
|---|
| 195 | }
|
|---|
| [564] | 196 |
|
|---|
| [745] | 197 | if (isRecording()) {
|
|---|
| [739] | 198 | savePPMToTemp();
|
|---|
| [724] | 199 | }
|
|---|
| 200 |
|
|---|
| [911] | 201 | #ifdef G4DEBUG_VIS_OGL
|
|---|
| [1039] | 202 | printf("G4OpenGLStoredQtViewer::ComputeView %d %d ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \n",getWinWidth(), getWinHeight());
|
|---|
| [608] | 203 | #endif
|
|---|
| [1040] | 204 | fHasToRepaint =true;
|
|---|
| [531] | 205 | }
|
|---|
| 206 |
|
|---|
| [564] | 207 |
|
|---|
| 208 | /**
|
|---|
| [682] | 209 | - Lors du resize de la fenetre, on doit non pas redessiner le detecteur, mais aussi les evenements
|
|---|
| 210 | */
|
|---|
| [564] | 211 | void G4OpenGLStoredQtViewer::resizeGL(
|
|---|
| [1039] | 212 | int aWidth
|
|---|
| 213 | ,int aHeight)
|
|---|
| [564] | 214 | {
|
|---|
| [1121] | 215 | #ifdef G4DEBUG_VIS_OGL
|
|---|
| [1124] | 216 | printf("G4OpenGLStoredQtViewer::resizeEvent..%d x %d vvvvvv\n",aWidth,aHeight);
|
|---|
| [1121] | 217 | #endif
|
|---|
| 218 | #ifdef G4DEBUG_VIS_OGL
|
|---|
| [1124] | 219 | printf("G4OpenGLStoredQtViewer::resizeEvent size ? %d x %d\n",width(),height());
|
|---|
| [1121] | 220 | #endif
|
|---|
| 221 | // Set new size, it will be update when next Repaint()->SetView() called
|
|---|
| [1124] | 222 | ResizeWindow(aWidth,aHeight);
|
|---|
| [1040] | 223 | fHasToRepaint = sizeHasChanged();
|
|---|
| [911] | 224 | #ifdef G4DEBUG_VIS_OGL
|
|---|
| [1124] | 225 | printf("G4OpenGLStoredQtViewer::resizeEvent.. ^^^^^^^^\n");
|
|---|
| [1121] | 226 | #endif
|
|---|
| 227 | }
|
|---|
| 228 |
|
|---|
| [1124] | 229 |
|
|---|
| [1121] | 230 | void G4OpenGLStoredQtViewer::paintGL()
|
|---|
| 231 | {
|
|---|
| 232 | #ifdef G4DEBUG_VIS_OGL
|
|---|
| [1040] | 233 | printf("G4OpenGLStoredQtViewer::paintGL ready:%d fHasTo:%d??\n",fReadyToPaint,fHasToRepaint);
|
|---|
| [873] | 234 | #endif
|
|---|
| [1040] | 235 | if (!fReadyToPaint) {
|
|---|
| 236 | fReadyToPaint= true;
|
|---|
| [682] | 237 | return;
|
|---|
| 238 | }
|
|---|
| [1039] | 239 | // DO NOT RESIZE IF SIZE HAS NOT CHANGE :
|
|---|
| 240 | // WHEN CLICK ON THE FRAME FOR EXAMPLE
|
|---|
| 241 | // EXECEPT WHEN MOUSE MOVE EVENT
|
|---|
| [1040] | 242 | if ( !fHasToRepaint) {
|
|---|
| [1124] | 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
|
|---|
| [1039] | 260 | if (((getWinWidth() == (unsigned int)width())) &&(getWinHeight() == (unsigned int) height())) {
|
|---|
| 261 | return;
|
|---|
| 262 | }
|
|---|
| 263 | }
|
|---|
| 264 | #ifdef G4DEBUG_VIS_OGL
|
|---|
| [1040] | 265 | printf("G4OpenGLStoredQtViewer::paintGL VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV ready %d\n",fReadyToPaint);
|
|---|
| [1039] | 266 | #endif
|
|---|
| [873] | 267 |
|
|---|
| [1039] | 268 | SetView();
|
|---|
| 269 |
|
|---|
| 270 | ClearView (); //ok, put the background correct
|
|---|
| 271 | ComputeView();
|
|---|
| 272 |
|
|---|
| [1040] | 273 | fHasToRepaint =false;
|
|---|
| [1039] | 274 |
|
|---|
| [911] | 275 | #ifdef G4DEBUG_VIS_OGL
|
|---|
| [1124] | 276 | printf("G4OpenGLStoredQtViewer::paintGL ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ready %d\n",fReadyToPaint);
|
|---|
| [608] | 277 | #endif
|
|---|
| [682] | 278 | }
|
|---|
| [564] | 279 |
|
|---|
| 280 | void G4OpenGLStoredQtViewer::mousePressEvent(QMouseEvent *event)
|
|---|
| 281 | {
|
|---|
| [1124] | 282 | G4MousePressEvent(event);
|
|---|
| [564] | 283 | }
|
|---|
| 284 |
|
|---|
| [696] | 285 | void G4OpenGLStoredQtViewer::keyPressEvent (QKeyEvent * event)
|
|---|
| 286 | {
|
|---|
| 287 | G4keyPressEvent(event);
|
|---|
| 288 | }
|
|---|
| 289 |
|
|---|
| [804] | 290 | void G4OpenGLStoredQtViewer::wheelEvent (QWheelEvent * event)
|
|---|
| 291 | {
|
|---|
| 292 | G4wheelEvent(event);
|
|---|
| 293 | }
|
|---|
| 294 |
|
|---|
| [678] | 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 | */
|
|---|
| [955] | 299 | void G4OpenGLStoredQtViewer::mouseDoubleClickEvent(QMouseEvent *)
|
|---|
| [673] | 300 | {
|
|---|
| [873] | 301 | G4MouseDoubleClickEvent();
|
|---|
| [673] | 302 | }
|
|---|
| 303 |
|
|---|
| [955] | 304 | void G4OpenGLStoredQtViewer::mouseReleaseEvent(QMouseEvent *)
|
|---|
| [673] | 305 | {
|
|---|
| [797] | 306 | G4MouseReleaseEvent();
|
|---|
| [673] | 307 | }
|
|---|
| 308 |
|
|---|
| [564] | 309 | void G4OpenGLStoredQtViewer::mouseMoveEvent(QMouseEvent *event)
|
|---|
| 310 | {
|
|---|
| [873] | 311 | G4MouseMoveEvent(event);
|
|---|
| [564] | 312 | }
|
|---|
| 313 |
|
|---|
| 314 |
|
|---|
| 315 | void G4OpenGLStoredQtViewer::contextMenuEvent(QContextMenuEvent *e)
|
|---|
| 316 | {
|
|---|
| [873] | 317 | G4manageContextMenuEvent(e);
|
|---|
| [564] | 318 | }
|
|---|
| 319 |
|
|---|
| [1123] | 320 |
|
|---|
| 321 | void G4OpenGLStoredQtViewer::paintEvent ( QPaintEvent * event )
|
|---|
| 322 | {
|
|---|
| 323 | #ifdef G4DEBUG_VIS_OGL
|
|---|
| [1124] | 324 | printf("G4OpenGLStoredQtViewer::paintEvent...................repaint.............%d x %d\n",width(),height());
|
|---|
| [1123] | 325 | #endif
|
|---|
| 326 | QGLWidget::paintEvent(event);
|
|---|
| 327 | }
|
|---|
| 328 |
|
|---|
| [564] | 329 | void G4OpenGLStoredQtViewer::updateQWidget() {
|
|---|
| [1040] | 330 | fHasToRepaint= true;
|
|---|
| [564] | 331 | updateGL();
|
|---|
| [1040] | 332 | fHasToRepaint= false;
|
|---|
| [564] | 333 | }
|
|---|
| 334 |
|
|---|
| [877] | 335 | void G4OpenGLStoredQtViewer::ShowView (
|
|---|
| 336 | )
|
|---|
| 337 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 338 | //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
|
|---|
| 339 | {
|
|---|
| 340 | #if QT_VERSION < 0x040000
|
|---|
| 341 | setActiveWindow();
|
|---|
| 342 | #else
|
|---|
| 343 | activateWindow();
|
|---|
| 344 | #endif
|
|---|
| 345 | }
|
|---|
| [673] | 346 |
|
|---|
| [531] | 347 | #endif
|
|---|