[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 | // |
---|
[1141] | 27 | // $Id: G4OpenGLStoredQtViewer.cc,v 1.28 2009/11/03 11:02:32 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 | { |
---|
[863] | 49 | |
---|
[709] | 50 | #if QT_VERSION < 0x040000 |
---|
| 51 | setFocusPolicy(QWidget::StrongFocus); // enable keybord events |
---|
| 52 | #else |
---|
[696] | 53 | setFocusPolicy(Qt::StrongFocus); // enable keybord events |
---|
[709] | 54 | #endif |
---|
[1040] | 55 | fHasToRepaint =false; |
---|
[858] | 56 | |
---|
[531] | 57 | if (fViewId < 0) return; // In case error in base class instantiation. |
---|
| 58 | } |
---|
| 59 | |
---|
[564] | 60 | G4OpenGLStoredQtViewer::~G4OpenGLStoredQtViewer() { |
---|
[682] | 61 | makeCurrent(); |
---|
| 62 | // this is connect to the Dialog for deleting it properly |
---|
| 63 | // when close event. |
---|
| 64 | // ((QDialog*)window())->reject(); |
---|
[564] | 65 | } |
---|
[531] | 66 | |
---|
[564] | 67 | void G4OpenGLStoredQtViewer::Initialise() { |
---|
[911] | 68 | #ifdef G4DEBUG_VIS_OGL |
---|
[858] | 69 | printf("G4OpenGLStoredQtViewer::Initialise 1\n"); |
---|
[608] | 70 | #endif |
---|
[1040] | 71 | fReadyToPaint = false; |
---|
[866] | 72 | CreateMainWindow (this,QString(fName)); |
---|
[873] | 73 | CreateFontLists (); |
---|
[564] | 74 | |
---|
[1040] | 75 | fReadyToPaint = true; |
---|
[564] | 76 | } |
---|
[531] | 77 | |
---|
[564] | 78 | void G4OpenGLStoredQtViewer::initializeGL () { |
---|
| 79 | |
---|
[682] | 80 | InitializeGLView (); |
---|
[564] | 81 | |
---|
[911] | 82 | #ifdef G4DEBUG_VIS_OGL |
---|
[682] | 83 | printf("G4OpenGLStoredQtViewer::InitialiseGL () 1\n"); |
---|
[608] | 84 | #endif |
---|
[564] | 85 | |
---|
[682] | 86 | // clear the buffers and window. |
---|
| 87 | ClearView (); |
---|
| 88 | FinishView (); |
---|
[564] | 89 | |
---|
[682] | 90 | glDepthFunc (GL_LEQUAL); |
---|
| 91 | glDepthMask (GL_TRUE); |
---|
[564] | 92 | |
---|
[866] | 93 | if (fSceneHandler.GetScene() == 0) { |
---|
[1040] | 94 | fHasToRepaint =false; |
---|
[866] | 95 | } else { |
---|
[1040] | 96 | fHasToRepaint =true; |
---|
[866] | 97 | } |
---|
[564] | 98 | |
---|
[911] | 99 | #ifdef G4DEBUG_VIS_OGL |
---|
[873] | 100 | printf("G4OpenGLStoredQtViewer::InitialiseGL END\n"); |
---|
[608] | 101 | #endif |
---|
[531] | 102 | } |
---|
| 103 | |
---|
[564] | 104 | |
---|
[533] | 105 | void G4OpenGLStoredQtViewer::DrawView () { |
---|
[911] | 106 | #ifdef G4DEBUG_VIS_OGL |
---|
[877] | 107 | printf("G4OpenGLStoredQtViewer::DrawView VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV\n"); |
---|
| 108 | #endif |
---|
| 109 | // That's no the same logic as Immediate Viewer, I don't know why... |
---|
| 110 | // But if I send updateGL here, we go here : |
---|
| 111 | // updateQWidget -> paintGL -> ComputeView |
---|
| 112 | // whih is not the same as ComputeView Directly |
---|
| 113 | // And we loose the redraw of things ! |
---|
| 114 | |
---|
[1039] | 115 | ComputeView(); |
---|
[911] | 116 | #ifdef G4DEBUG_VIS_OGL |
---|
[877] | 117 | printf("G4OpenGLStoredQtViewer::DrawView ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n"); |
---|
| 118 | #endif |
---|
| 119 | } |
---|
[682] | 120 | |
---|
[877] | 121 | void G4OpenGLStoredQtViewer::ComputeView () { |
---|
[1122] | 122 | |
---|
| 123 | #ifdef G4DEBUG_VIS_OGL |
---|
[1039] | 124 | printf("G4OpenGLStoredQtViewer::ComputeView %d %d VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV\n",getWinWidth(), getWinHeight()); |
---|
[608] | 125 | #endif |
---|
[877] | 126 | makeCurrent(); |
---|
[682] | 127 | G4ViewParameters::DrawingStyle style = GetViewParameters().GetDrawingStyle(); |
---|
[531] | 128 | |
---|
[682] | 129 | //Make sure current viewer is attached and clean... |
---|
[531] | 130 | |
---|
[682] | 131 | //See if things have changed from last time and remake if necessary... |
---|
| 132 | // The fNeedKernelVisit flag might have been set by the user in |
---|
| 133 | // /vis/viewer/rebuild, but if not, make decision and set flag only |
---|
| 134 | // if necessary... |
---|
[873] | 135 | if (!fNeedKernelVisit) { |
---|
[877] | 136 | KernelVisitDecision (); |
---|
[873] | 137 | } |
---|
[682] | 138 | G4bool kernelVisitWasNeeded = fNeedKernelVisit; // Keep (ProcessView resets). |
---|
| 139 | ProcessView (); |
---|
[564] | 140 | |
---|
[531] | 141 | |
---|
[682] | 142 | if(style!=G4ViewParameters::hlr && |
---|
| 143 | haloing_enabled) { |
---|
[911] | 144 | #ifdef G4DEBUG_VIS_OGL |
---|
[877] | 145 | printf("G4OpenGLStoredQtViewer::ComputeView DANS LE IF\n"); |
---|
[608] | 146 | #endif |
---|
[531] | 147 | |
---|
[682] | 148 | HaloingFirstPass (); |
---|
| 149 | DrawDisplayLists (); |
---|
| 150 | glFlush (); |
---|
[531] | 151 | |
---|
[682] | 152 | HaloingSecondPass (); |
---|
[531] | 153 | |
---|
[682] | 154 | DrawDisplayLists (); |
---|
| 155 | FinishView (); |
---|
[531] | 156 | |
---|
[682] | 157 | } else { |
---|
[564] | 158 | |
---|
[682] | 159 | // If kernel visit was needed, drawing and FinishView will already |
---|
| 160 | // have been done, so... |
---|
| 161 | if (!kernelVisitWasNeeded) { |
---|
[911] | 162 | #ifdef G4DEBUG_VIS_OGL |
---|
[877] | 163 | printf("************************** G4OpenGLStoredQtViewer::ComputeView Don't need kernel Visit \n"); |
---|
[608] | 164 | #endif |
---|
[682] | 165 | DrawDisplayLists (); |
---|
| 166 | FinishView (); |
---|
| 167 | } else { |
---|
[911] | 168 | #ifdef G4DEBUG_VIS_OGL |
---|
[877] | 169 | printf("************************** G4OpenGLStoredQtViewer::ComputeView need kernel Visit \n"); |
---|
[608] | 170 | #endif |
---|
[682] | 171 | // However, union cutaways are implemented in DrawDisplayLists, so make |
---|
| 172 | // an extra pass... |
---|
| 173 | if (fVP.IsCutaway() && |
---|
| 174 | fVP.GetCutawayMode() == G4ViewParameters::cutawayUnion) { |
---|
| 175 | ClearView(); |
---|
| 176 | DrawDisplayLists (); |
---|
| 177 | FinishView (); |
---|
[911] | 178 | #ifdef G4DEBUG_VIS_OGL |
---|
[682] | 179 | printf("*************************** CASE 4 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \n"); |
---|
[608] | 180 | #endif |
---|
[682] | 181 | } else { // ADD TO AVOID KernelVisit=1 and nothing to display |
---|
| 182 | DrawDisplayLists (); |
---|
| 183 | FinishView (); |
---|
| 184 | } |
---|
| 185 | } |
---|
| 186 | } |
---|
[564] | 187 | |
---|
[745] | 188 | if (isRecording()) { |
---|
[739] | 189 | savePPMToTemp(); |
---|
[724] | 190 | } |
---|
| 191 | |
---|
[911] | 192 | #ifdef G4DEBUG_VIS_OGL |
---|
[1039] | 193 | printf("G4OpenGLStoredQtViewer::ComputeView %d %d ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \n",getWinWidth(), getWinHeight()); |
---|
[608] | 194 | #endif |
---|
[1040] | 195 | fHasToRepaint =true; |
---|
[531] | 196 | } |
---|
| 197 | |
---|
[564] | 198 | |
---|
| 199 | /** |
---|
[682] | 200 | - Lors du resize de la fenetre, on doit non pas redessiner le detecteur, mais aussi les evenements |
---|
| 201 | */ |
---|
[564] | 202 | void G4OpenGLStoredQtViewer::resizeGL( |
---|
[1039] | 203 | int aWidth |
---|
| 204 | ,int aHeight) |
---|
[564] | 205 | { |
---|
[1121] | 206 | // Set new size, it will be update when next Repaint()->SetView() called |
---|
[1124] | 207 | ResizeWindow(aWidth,aHeight); |
---|
[1040] | 208 | fHasToRepaint = sizeHasChanged(); |
---|
[1121] | 209 | } |
---|
| 210 | |
---|
[1124] | 211 | |
---|
[1121] | 212 | void G4OpenGLStoredQtViewer::paintGL() |
---|
| 213 | { |
---|
| 214 | #ifdef G4DEBUG_VIS_OGL |
---|
[1040] | 215 | printf("G4OpenGLStoredQtViewer::paintGL ready:%d fHasTo:%d??\n",fReadyToPaint,fHasToRepaint); |
---|
[873] | 216 | #endif |
---|
[1040] | 217 | if (!fReadyToPaint) { |
---|
| 218 | fReadyToPaint= true; |
---|
[682] | 219 | return; |
---|
| 220 | } |
---|
[1039] | 221 | // DO NOT RESIZE IF SIZE HAS NOT CHANGE : |
---|
| 222 | // WHEN CLICK ON THE FRAME FOR EXAMPLE |
---|
| 223 | // EXECEPT WHEN MOUSE MOVE EVENT |
---|
[1040] | 224 | if ( !fHasToRepaint) { |
---|
[1141] | 225 | #if QT_VERSION < 0x040000 |
---|
| 226 | if (((getWinWidth() == (unsigned int)width())) &&(getWinHeight() == (unsigned int) height())) { |
---|
| 227 | #else |
---|
[1125] | 228 | // L. Garnier : Trap to get the size with mac OSX 10.6 and Qt 4.6(devel) |
---|
| 229 | // Tested on Qt4.5 on mac, 4.4 on windows, 4.5 on unbuntu |
---|
| 230 | int sw = 0; |
---|
| 231 | int sh = 0; |
---|
| 232 | if (!isMaximized() && !isFullScreen()) { |
---|
| 233 | sw = normalGeometry().width(); |
---|
| 234 | sh = normalGeometry().height(); |
---|
| 235 | } else { |
---|
| 236 | sw = frameGeometry().width(); |
---|
| 237 | sh = frameGeometry().height(); |
---|
| 238 | } |
---|
[1126] | 239 | if ((getWinWidth() == (unsigned int)sw) &&(getWinHeight() == (unsigned int)sh)) { |
---|
[1141] | 240 | #endif |
---|
[1039] | 241 | return; |
---|
| 242 | } |
---|
| 243 | } |
---|
| 244 | #ifdef G4DEBUG_VIS_OGL |
---|
[1040] | 245 | printf("G4OpenGLStoredQtViewer::paintGL VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV ready %d\n",fReadyToPaint); |
---|
[1039] | 246 | #endif |
---|
[873] | 247 | |
---|
[1141] | 248 | SetView(); |
---|
[1039] | 249 | |
---|
[1141] | 250 | ClearView (); //ok, put the background correct |
---|
[1039] | 251 | ComputeView(); |
---|
| 252 | |
---|
[1040] | 253 | fHasToRepaint =false; |
---|
[1039] | 254 | |
---|
[911] | 255 | #ifdef G4DEBUG_VIS_OGL |
---|
[1124] | 256 | printf("G4OpenGLStoredQtViewer::paintGL ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ready %d\n",fReadyToPaint); |
---|
[608] | 257 | #endif |
---|
[682] | 258 | } |
---|
[564] | 259 | |
---|
| 260 | void G4OpenGLStoredQtViewer::mousePressEvent(QMouseEvent *event) |
---|
| 261 | { |
---|
[1124] | 262 | G4MousePressEvent(event); |
---|
[564] | 263 | } |
---|
| 264 | |
---|
[696] | 265 | void G4OpenGLStoredQtViewer::keyPressEvent (QKeyEvent * event) |
---|
| 266 | { |
---|
| 267 | G4keyPressEvent(event); |
---|
| 268 | } |
---|
| 269 | |
---|
[804] | 270 | void G4OpenGLStoredQtViewer::wheelEvent (QWheelEvent * event) |
---|
| 271 | { |
---|
| 272 | G4wheelEvent(event); |
---|
| 273 | } |
---|
| 274 | |
---|
[678] | 275 | /** |
---|
| 276 | * This function was build in order to make a zoom on double clic event. |
---|
| 277 | * It was think to build a rubberband on the zoom area, but never work fine |
---|
| 278 | */ |
---|
[955] | 279 | void G4OpenGLStoredQtViewer::mouseDoubleClickEvent(QMouseEvent *) |
---|
[673] | 280 | { |
---|
[873] | 281 | G4MouseDoubleClickEvent(); |
---|
[673] | 282 | } |
---|
| 283 | |
---|
[955] | 284 | void G4OpenGLStoredQtViewer::mouseReleaseEvent(QMouseEvent *) |
---|
[673] | 285 | { |
---|
[797] | 286 | G4MouseReleaseEvent(); |
---|
[673] | 287 | } |
---|
| 288 | |
---|
[564] | 289 | void G4OpenGLStoredQtViewer::mouseMoveEvent(QMouseEvent *event) |
---|
| 290 | { |
---|
[873] | 291 | G4MouseMoveEvent(event); |
---|
[564] | 292 | } |
---|
| 293 | |
---|
| 294 | |
---|
| 295 | void G4OpenGLStoredQtViewer::contextMenuEvent(QContextMenuEvent *e) |
---|
| 296 | { |
---|
[873] | 297 | G4manageContextMenuEvent(e); |
---|
[564] | 298 | } |
---|
| 299 | |
---|
| 300 | void G4OpenGLStoredQtViewer::updateQWidget() { |
---|
[1040] | 301 | fHasToRepaint= true; |
---|
[564] | 302 | updateGL(); |
---|
[1040] | 303 | fHasToRepaint= false; |
---|
[564] | 304 | } |
---|
| 305 | |
---|
[877] | 306 | void G4OpenGLStoredQtViewer::ShowView ( |
---|
| 307 | ) |
---|
| 308 | ////////////////////////////////////////////////////////////////////////////// |
---|
| 309 | //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// |
---|
| 310 | { |
---|
| 311 | #if QT_VERSION < 0x040000 |
---|
| 312 | setActiveWindow(); |
---|
| 313 | #else |
---|
| 314 | activateWindow(); |
---|
| 315 | #endif |
---|
| 316 | } |
---|
[673] | 317 | |
---|
[531] | 318 | #endif |
---|