| [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 | //
|
|---|
| [1324] | 27 | // $Id: G4OpenGLStoredQtViewer.cc,v 1.32 2010/06/23 13:29:23 lgarnier Exp $
|
|---|
| [1307] | 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 | {
|
|---|
| [863] | 49 |
|
|---|
| [1327] | 50 | #ifdef G4DEBUG_VIS_OGL
|
|---|
| 51 | printf("G4OpenGLStoredQtViewer::constructor VVVVVVVVVVVV\n");
|
|---|
| 52 | #endif
|
|---|
| [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
|
|---|
| [1307] | 58 | fHasToRepaint = false;
|
|---|
| 59 | fIsRepainting = false;
|
|---|
| [858] | 60 |
|
|---|
| [1327] | 61 | #ifdef G4DEBUG_VIS_OGL
|
|---|
| 62 | printf("G4OpenGLStoredQtViewer::constructor ^^^^^^^^^^^^\n");
|
|---|
| 63 | #endif
|
|---|
| [531] | 64 | if (fViewId < 0) return; // In case error in base class instantiation.
|
|---|
| 65 | }
|
|---|
| 66 |
|
|---|
| [564] | 67 | G4OpenGLStoredQtViewer::~G4OpenGLStoredQtViewer() {
|
|---|
| [682] | 68 | makeCurrent();
|
|---|
| 69 | // this is connect to the Dialog for deleting it properly
|
|---|
| 70 | // when close event.
|
|---|
| 71 | // ((QDialog*)window())->reject();
|
|---|
| [564] | 72 | }
|
|---|
| [531] | 73 |
|
|---|
| [564] | 74 | void G4OpenGLStoredQtViewer::Initialise() {
|
|---|
| [911] | 75 | #ifdef G4DEBUG_VIS_OGL
|
|---|
| [1327] | 76 | printf("G4OpenGLStoredQtViewer::Initialise VVVVVVVVVVVV\n");
|
|---|
| [608] | 77 | #endif
|
|---|
| [1040] | 78 | fReadyToPaint = false;
|
|---|
| [1327] | 79 | initializeGL ();
|
|---|
| [1164] | 80 | CreateMainWindow (this,QString(GetName()));
|
|---|
| [873] | 81 | CreateFontLists ();
|
|---|
| [564] | 82 |
|
|---|
| [1040] | 83 | fReadyToPaint = true;
|
|---|
| [1327] | 84 | #ifdef G4DEBUG_VIS_OGL
|
|---|
| 85 | printf("G4OpenGLStoredQtViewer::Initialise ^^^^^^^^^^^^\n");
|
|---|
| 86 | #endif
|
|---|
| [564] | 87 | }
|
|---|
| [531] | 88 |
|
|---|
| [564] | 89 | void G4OpenGLStoredQtViewer::initializeGL () {
|
|---|
| 90 |
|
|---|
| [1327] | 91 | QGLWidget::initializeGL();
|
|---|
| 92 | #ifdef G4DEBUG_VIS_OGL
|
|---|
| 93 | printf("G4OpenGLStoredQtViewer::InitialiseGL () 0\n");
|
|---|
| 94 | #endif
|
|---|
| 95 | // return;
|
|---|
| [1328] | 96 | InitializeGLView ();
|
|---|
| [564] | 97 |
|
|---|
| [911] | 98 | #ifdef G4DEBUG_VIS_OGL
|
|---|
| [682] | 99 | printf("G4OpenGLStoredQtViewer::InitialiseGL () 1\n");
|
|---|
| [608] | 100 | #endif
|
|---|
| [564] | 101 |
|
|---|
| [682] | 102 | // clear the buffers and window.
|
|---|
| [1295] | 103 | ClearView ();
|
|---|
| 104 | FinishView ();
|
|---|
| [564] | 105 |
|
|---|
| [682] | 106 | glDepthFunc (GL_LEQUAL);
|
|---|
| 107 | glDepthMask (GL_TRUE);
|
|---|
| [564] | 108 |
|
|---|
| [866] | 109 | if (fSceneHandler.GetScene() == 0) {
|
|---|
| [1040] | 110 | fHasToRepaint =false;
|
|---|
| [866] | 111 | } else {
|
|---|
| [1040] | 112 | fHasToRepaint =true;
|
|---|
| [866] | 113 | }
|
|---|
| [564] | 114 |
|
|---|
| [911] | 115 | #ifdef G4DEBUG_VIS_OGL
|
|---|
| [873] | 116 | printf("G4OpenGLStoredQtViewer::InitialiseGL END\n");
|
|---|
| [608] | 117 | #endif
|
|---|
| [531] | 118 | }
|
|---|
| 119 |
|
|---|
| [564] | 120 |
|
|---|
| [1242] | 121 | void G4OpenGLStoredQtViewer::DrawView () {
|
|---|
| [1238] | 122 | updateQWidget();
|
|---|
| [877] | 123 | }
|
|---|
| [682] | 124 |
|
|---|
| [877] | 125 | void G4OpenGLStoredQtViewer::ComputeView () {
|
|---|
| [1122] | 126 |
|
|---|
| 127 | #ifdef G4DEBUG_VIS_OGL
|
|---|
| [1039] | 128 | printf("G4OpenGLStoredQtViewer::ComputeView %d %d VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV\n",getWinWidth(), getWinHeight());
|
|---|
| [608] | 129 | #endif
|
|---|
| [877] | 130 | makeCurrent();
|
|---|
| [682] | 131 | G4ViewParameters::DrawingStyle style = GetViewParameters().GetDrawingStyle();
|
|---|
| [531] | 132 |
|
|---|
| [682] | 133 | //Make sure current viewer is attached and clean...
|
|---|
| [531] | 134 |
|
|---|
| [682] | 135 | //See if things have changed from last time and remake if necessary...
|
|---|
| 136 | // The fNeedKernelVisit flag might have been set by the user in
|
|---|
| 137 | // /vis/viewer/rebuild, but if not, make decision and set flag only
|
|---|
| 138 | // if necessary...
|
|---|
| [873] | 139 | if (!fNeedKernelVisit) {
|
|---|
| [877] | 140 | KernelVisitDecision ();
|
|---|
| [873] | 141 | }
|
|---|
| [682] | 142 | G4bool kernelVisitWasNeeded = fNeedKernelVisit; // Keep (ProcessView resets).
|
|---|
| 143 | ProcessView ();
|
|---|
| [564] | 144 |
|
|---|
| [531] | 145 |
|
|---|
| [682] | 146 | if(style!=G4ViewParameters::hlr &&
|
|---|
| 147 | haloing_enabled) {
|
|---|
| [911] | 148 | #ifdef G4DEBUG_VIS_OGL
|
|---|
| [877] | 149 | printf("G4OpenGLStoredQtViewer::ComputeView DANS LE IF\n");
|
|---|
| [608] | 150 | #endif
|
|---|
| [531] | 151 |
|
|---|
| [682] | 152 | HaloingFirstPass ();
|
|---|
| 153 | DrawDisplayLists ();
|
|---|
| 154 | glFlush ();
|
|---|
| [531] | 155 |
|
|---|
| [682] | 156 | HaloingSecondPass ();
|
|---|
| [531] | 157 |
|
|---|
| [682] | 158 | DrawDisplayLists ();
|
|---|
| 159 | FinishView ();
|
|---|
| [531] | 160 |
|
|---|
| [682] | 161 | } else {
|
|---|
| [564] | 162 |
|
|---|
| [682] | 163 | // If kernel visit was needed, drawing and FinishView will already
|
|---|
| 164 | // have been done, so...
|
|---|
| 165 | if (!kernelVisitWasNeeded) {
|
|---|
| [911] | 166 | #ifdef G4DEBUG_VIS_OGL
|
|---|
| [877] | 167 | printf("************************** G4OpenGLStoredQtViewer::ComputeView Don't need kernel Visit \n");
|
|---|
| [608] | 168 | #endif
|
|---|
| [682] | 169 | DrawDisplayLists ();
|
|---|
| 170 | FinishView ();
|
|---|
| 171 | } else {
|
|---|
| [911] | 172 | #ifdef G4DEBUG_VIS_OGL
|
|---|
| [877] | 173 | printf("************************** G4OpenGLStoredQtViewer::ComputeView need kernel Visit \n");
|
|---|
| [608] | 174 | #endif
|
|---|
| [682] | 175 | // However, union cutaways are implemented in DrawDisplayLists, so make
|
|---|
| 176 | // an extra pass...
|
|---|
| 177 | if (fVP.IsCutaway() &&
|
|---|
| 178 | fVP.GetCutawayMode() == G4ViewParameters::cutawayUnion) {
|
|---|
| 179 | ClearView();
|
|---|
| 180 | DrawDisplayLists ();
|
|---|
| 181 | FinishView ();
|
|---|
| [911] | 182 | #ifdef G4DEBUG_VIS_OGL
|
|---|
| [682] | 183 | printf("*************************** CASE 4 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \n");
|
|---|
| [608] | 184 | #endif
|
|---|
| [682] | 185 | } else { // ADD TO AVOID KernelVisit=1 and nothing to display
|
|---|
| 186 | DrawDisplayLists ();
|
|---|
| 187 | FinishView ();
|
|---|
| 188 | }
|
|---|
| 189 | }
|
|---|
| 190 | }
|
|---|
| [564] | 191 |
|
|---|
| [745] | 192 | if (isRecording()) {
|
|---|
| [739] | 193 | savePPMToTemp();
|
|---|
| [724] | 194 | }
|
|---|
| 195 |
|
|---|
| [911] | 196 | #ifdef G4DEBUG_VIS_OGL
|
|---|
| [1039] | 197 | printf("G4OpenGLStoredQtViewer::ComputeView %d %d ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \n",getWinWidth(), getWinHeight());
|
|---|
| [608] | 198 | #endif
|
|---|
| [1307] | 199 | fHasToRepaint = true;
|
|---|
| [531] | 200 | }
|
|---|
| 201 |
|
|---|
| [564] | 202 |
|
|---|
| 203 | /**
|
|---|
| [682] | 204 | - Lors du resize de la fenetre, on doit non pas redessiner le detecteur, mais aussi les evenements
|
|---|
| 205 | */
|
|---|
| [564] | 206 | void G4OpenGLStoredQtViewer::resizeGL(
|
|---|
| [1039] | 207 | int aWidth
|
|---|
| 208 | ,int aHeight)
|
|---|
| [564] | 209 | {
|
|---|
| [1121] | 210 | // Set new size, it will be update when next Repaint()->SetView() called
|
|---|
| [1307] | 211 | if ((aWidth > 0) && (aHeight > 0)) {
|
|---|
| 212 | ResizeWindow(aWidth,aHeight);
|
|---|
| 213 | fHasToRepaint = sizeHasChanged();
|
|---|
| 214 | }
|
|---|
| [1121] | 215 | }
|
|---|
| 216 |
|
|---|
| [1124] | 217 |
|
|---|
| [1227] | 218 | // We have to get several case :
|
|---|
| 219 | // - Only activate the windows (mouse click for example) -> Do not redraw
|
|---|
| 220 | // - resize window -> redraw
|
|---|
| 221 | // - try to avoid recompute everything if we do not rescale picture (side is the same)
|
|---|
| 222 |
|
|---|
| [1121] | 223 | void G4OpenGLStoredQtViewer::paintGL()
|
|---|
| 224 | {
|
|---|
| [1310] | 225 | #ifdef G4DEBUG_VIS_OGL
|
|---|
| 226 | printf("G4OpenGLStoredQtViewer::paintGL \n");
|
|---|
| 227 | #endif
|
|---|
| [1307] | 228 | if (fIsRepainting) {
|
|---|
| [1311] | 229 | // return ;
|
|---|
| [1307] | 230 | }
|
|---|
| 231 | fIsRepainting = true;
|
|---|
| [1121] | 232 | #ifdef G4DEBUG_VIS_OGL
|
|---|
| [1242] | 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) {
|
|---|
| [1141] | 243 | #if QT_VERSION < 0x040000
|
|---|
| 244 | if (((getWinWidth() == (unsigned int)width())) &&(getWinHeight() == (unsigned int) height())) {
|
|---|
| 245 | #else
|
|---|
| [1125] | 246 | // L. Garnier : Trap to get the size with mac OSX 10.6 and Qt 4.6(devel)
|
|---|
| 247 | // Tested on Qt4.5 on mac, 4.4 on windows, 4.5 on unbuntu
|
|---|
| 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 | }
|
|---|
| [1126] | 257 | if ((getWinWidth() == (unsigned int)sw) &&(getWinHeight() == (unsigned int)sh)) {
|
|---|
| [1141] | 258 | #endif
|
|---|
| [1039] | 259 | return;
|
|---|
| 260 | }
|
|---|
| 261 | }
|
|---|
| 262 | #ifdef G4DEBUG_VIS_OGL
|
|---|
| [1040] | 263 | printf("G4OpenGLStoredQtViewer::paintGL VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV ready %d\n",fReadyToPaint);
|
|---|
| [1039] | 264 | #endif
|
|---|
| [873] | 265 |
|
|---|
| [1141] | 266 | SetView();
|
|---|
| [1307] | 267 |
|
|---|
| [1141] | 268 | ClearView (); //ok, put the background correct
|
|---|
| [1039] | 269 | ComputeView();
|
|---|
| [1227] | 270 |
|
|---|
| [1307] | 271 | fHasToRepaint = false;
|
|---|
| [1242] | 272 |
|
|---|
| [911] | 273 | #ifdef G4DEBUG_VIS_OGL
|
|---|
| [1124] | 274 | printf("G4OpenGLStoredQtViewer::paintGL ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ready %d\n",fReadyToPaint);
|
|---|
| [608] | 275 | #endif
|
|---|
| [1307] | 276 | fIsRepainting = false;
|
|---|
| [682] | 277 | }
|
|---|
| [564] | 278 |
|
|---|
| [1322] | 279 | void G4OpenGLStoredQtViewer::paintEvent(QPaintEvent *) {
|
|---|
| [1235] | 280 | if ( fHasToRepaint) {
|
|---|
| 281 | updateGL();
|
|---|
| 282 | }
|
|---|
| 283 | }
|
|---|
| 284 |
|
|---|
| [564] | 285 | void G4OpenGLStoredQtViewer::mousePressEvent(QMouseEvent *event)
|
|---|
| 286 | {
|
|---|
| [1124] | 287 | G4MousePressEvent(event);
|
|---|
| [564] | 288 | }
|
|---|
| 289 |
|
|---|
| [696] | 290 | void G4OpenGLStoredQtViewer::keyPressEvent (QKeyEvent * event)
|
|---|
| 291 | {
|
|---|
| 292 | G4keyPressEvent(event);
|
|---|
| 293 | }
|
|---|
| 294 |
|
|---|
| [804] | 295 | void G4OpenGLStoredQtViewer::wheelEvent (QWheelEvent * event)
|
|---|
| 296 | {
|
|---|
| 297 | G4wheelEvent(event);
|
|---|
| 298 | }
|
|---|
| 299 |
|
|---|
| [1322] | 300 | void G4OpenGLStoredQtViewer::showEvent (QShowEvent *)
|
|---|
| [1240] | 301 | {
|
|---|
| 302 | fHasToRepaint = true;
|
|---|
| 303 | }
|
|---|
| 304 |
|
|---|
| [678] | 305 | /**
|
|---|
| 306 | * This function was build in order to make a zoom on double clic event.
|
|---|
| 307 | * It was think to build a rubberband on the zoom area, but never work fine
|
|---|
| 308 | */
|
|---|
| [955] | 309 | void G4OpenGLStoredQtViewer::mouseDoubleClickEvent(QMouseEvent *)
|
|---|
| [673] | 310 | {
|
|---|
| [873] | 311 | G4MouseDoubleClickEvent();
|
|---|
| [673] | 312 | }
|
|---|
| 313 |
|
|---|
| [955] | 314 | void G4OpenGLStoredQtViewer::mouseReleaseEvent(QMouseEvent *)
|
|---|
| [673] | 315 | {
|
|---|
| [797] | 316 | G4MouseReleaseEvent();
|
|---|
| [673] | 317 | }
|
|---|
| 318 |
|
|---|
| [564] | 319 | void G4OpenGLStoredQtViewer::mouseMoveEvent(QMouseEvent *event)
|
|---|
| 320 | {
|
|---|
| [873] | 321 | G4MouseMoveEvent(event);
|
|---|
| [564] | 322 | }
|
|---|
| 323 |
|
|---|
| 324 |
|
|---|
| 325 | void G4OpenGLStoredQtViewer::contextMenuEvent(QContextMenuEvent *e)
|
|---|
| 326 | {
|
|---|
| [873] | 327 | G4manageContextMenuEvent(e);
|
|---|
| [564] | 328 | }
|
|---|
| 329 |
|
|---|
| 330 | void G4OpenGLStoredQtViewer::updateQWidget() {
|
|---|
| [1040] | 331 | fHasToRepaint= true;
|
|---|
| [564] | 332 | updateGL();
|
|---|
| [1040] | 333 | fHasToRepaint= false;
|
|---|
| [564] | 334 | }
|
|---|
| 335 |
|
|---|
| [877] | 336 | void G4OpenGLStoredQtViewer::ShowView (
|
|---|
| 337 | )
|
|---|
| 338 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 339 | //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
|
|---|
| 340 | {
|
|---|
| 341 | #if QT_VERSION < 0x040000
|
|---|
| 342 | setActiveWindow();
|
|---|
| 343 | #else
|
|---|
| 344 | activateWindow();
|
|---|
| 345 | #endif
|
|---|
| 346 | }
|
|---|
| [673] | 347 |
|
|---|
| [531] | 348 | #endif
|
|---|