[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 | // |
---|
[1041] | 27 | // $Id: G4OpenGLStoredQtViewer.cc,v 1.25 2009/05/13 10:28:00 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 | |
---|
[595] | 40 | //#include <qmouseevent.h> |
---|
| 41 | #include <qevent.h> // include <qcontextmenuevent.h> |
---|
[593] | 42 | |
---|
[533] | 43 | G4OpenGLStoredQtViewer::G4OpenGLStoredQtViewer |
---|
[531] | 44 | (G4OpenGLStoredSceneHandler& sceneHandler, |
---|
| 45 | const G4String& name): |
---|
[682] | 46 | G4VViewer (sceneHandler, sceneHandler.IncrementViewCount (), name), |
---|
| 47 | G4OpenGLViewer (sceneHandler), |
---|
| 48 | G4OpenGLQtViewer (sceneHandler), |
---|
[709] | 49 | G4OpenGLStoredViewer (sceneHandler) // FIXME : gerer le pb du parent ! |
---|
[682] | 50 | { |
---|
[863] | 51 | |
---|
| 52 | //set true to picking |
---|
| 53 | fVP.SetPicking(true); |
---|
[709] | 54 | #if QT_VERSION < 0x040000 |
---|
| 55 | setFocusPolicy(QWidget::StrongFocus); // enable keybord events |
---|
| 56 | #else |
---|
[696] | 57 | setFocusPolicy(Qt::StrongFocus); // enable keybord events |
---|
[709] | 58 | #endif |
---|
[1040] | 59 | fHasToRepaint =false; |
---|
[858] | 60 | |
---|
[531] | 61 | if (fViewId < 0) return; // In case error in base class instantiation. |
---|
| 62 | } |
---|
| 63 | |
---|
[564] | 64 | G4OpenGLStoredQtViewer::~G4OpenGLStoredQtViewer() { |
---|
[682] | 65 | makeCurrent(); |
---|
| 66 | // this is connect to the Dialog for deleting it properly |
---|
| 67 | // when close event. |
---|
| 68 | // ((QDialog*)window())->reject(); |
---|
[564] | 69 | } |
---|
[531] | 70 | |
---|
[564] | 71 | void G4OpenGLStoredQtViewer::Initialise() { |
---|
[911] | 72 | #ifdef G4DEBUG_VIS_OGL |
---|
[858] | 73 | printf("G4OpenGLStoredQtViewer::Initialise 1\n"); |
---|
[608] | 74 | #endif |
---|
[1040] | 75 | fReadyToPaint = false; |
---|
[866] | 76 | CreateMainWindow (this,QString(fName)); |
---|
[873] | 77 | CreateFontLists (); |
---|
[564] | 78 | |
---|
[1040] | 79 | fReadyToPaint = true; |
---|
[564] | 80 | } |
---|
[531] | 81 | |
---|
[564] | 82 | void G4OpenGLStoredQtViewer::initializeGL () { |
---|
| 83 | |
---|
[682] | 84 | InitializeGLView (); |
---|
[564] | 85 | |
---|
[911] | 86 | #ifdef G4DEBUG_VIS_OGL |
---|
[682] | 87 | printf("G4OpenGLStoredQtViewer::InitialiseGL () 1\n"); |
---|
[608] | 88 | #endif |
---|
[564] | 89 | |
---|
[682] | 90 | // clear the buffers and window. |
---|
| 91 | ClearView (); |
---|
| 92 | FinishView (); |
---|
[564] | 93 | |
---|
[682] | 94 | glDepthFunc (GL_LEQUAL); |
---|
| 95 | glDepthMask (GL_TRUE); |
---|
[564] | 96 | |
---|
[866] | 97 | if (fSceneHandler.GetScene() == 0) { |
---|
[1040] | 98 | fHasToRepaint =false; |
---|
[866] | 99 | } else { |
---|
[1040] | 100 | fHasToRepaint =true; |
---|
[866] | 101 | } |
---|
[564] | 102 | |
---|
[911] | 103 | #ifdef G4DEBUG_VIS_OGL |
---|
[873] | 104 | printf("G4OpenGLStoredQtViewer::InitialiseGL END\n"); |
---|
[608] | 105 | #endif |
---|
[531] | 106 | } |
---|
| 107 | |
---|
[564] | 108 | |
---|
[533] | 109 | void G4OpenGLStoredQtViewer::DrawView () { |
---|
[911] | 110 | #ifdef G4DEBUG_VIS_OGL |
---|
[877] | 111 | printf("G4OpenGLStoredQtViewer::DrawView VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV\n"); |
---|
| 112 | #endif |
---|
| 113 | // That's no the same logic as Immediate Viewer, I don't know why... |
---|
| 114 | // But if I send updateGL here, we go here : |
---|
| 115 | // updateQWidget -> paintGL -> ComputeView |
---|
| 116 | // whih is not the same as ComputeView Directly |
---|
| 117 | // And we loose the redraw of things ! |
---|
| 118 | |
---|
[1039] | 119 | ComputeView(); |
---|
[911] | 120 | #ifdef G4DEBUG_VIS_OGL |
---|
[877] | 121 | printf("G4OpenGLStoredQtViewer::DrawView ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n"); |
---|
| 122 | #endif |
---|
| 123 | } |
---|
[682] | 124 | |
---|
[877] | 125 | void G4OpenGLStoredQtViewer::ComputeView () { |
---|
| 126 | |
---|
[911] | 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 |
---|
[1040] | 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 | { |
---|
[906] | 210 | // Set new size, it will be update when next Repaint()->SetView() called |
---|
[1039] | 211 | ResizeWindow(aWidth,aHeight); |
---|
[1040] | 212 | fHasToRepaint = sizeHasChanged(); |
---|
[564] | 213 | } |
---|
| 214 | |
---|
| 215 | |
---|
| 216 | void G4OpenGLStoredQtViewer::paintGL() |
---|
[682] | 217 | { |
---|
[911] | 218 | #ifdef G4DEBUG_VIS_OGL |
---|
[1040] | 219 | printf("G4OpenGLStoredQtViewer::paintGL ready:%d fHasTo:%d??\n",fReadyToPaint,fHasToRepaint); |
---|
[873] | 220 | #endif |
---|
[1040] | 221 | if (!fReadyToPaint) { |
---|
| 222 | fReadyToPaint= true; |
---|
[682] | 223 | return; |
---|
| 224 | } |
---|
[1039] | 225 | // DO NOT RESIZE IF SIZE HAS NOT CHANGE : |
---|
| 226 | // WHEN CLICK ON THE FRAME FOR EXAMPLE |
---|
| 227 | // EXECEPT WHEN MOUSE MOVE EVENT |
---|
[1040] | 228 | if ( !fHasToRepaint) { |
---|
[1039] | 229 | if (((getWinWidth() == (unsigned int)width())) &&(getWinHeight() == (unsigned int) height())) { |
---|
| 230 | return; |
---|
| 231 | } |
---|
| 232 | } |
---|
| 233 | #ifdef G4DEBUG_VIS_OGL |
---|
[1040] | 234 | printf("G4OpenGLStoredQtViewer::paintGL VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV ready %d\n",fReadyToPaint); |
---|
[1039] | 235 | #endif |
---|
[873] | 236 | |
---|
[1039] | 237 | SetView(); |
---|
| 238 | |
---|
| 239 | ClearView (); //ok, put the background correct |
---|
| 240 | ComputeView(); |
---|
| 241 | |
---|
[1040] | 242 | fHasToRepaint =false; |
---|
[1039] | 243 | |
---|
[911] | 244 | #ifdef G4DEBUG_VIS_OGL |
---|
[1040] | 245 | printf("G4OpenGLStoredQtViewer::paintGL ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ready %d\n",fReadyToPaint); |
---|
[608] | 246 | #endif |
---|
[682] | 247 | } |
---|
[564] | 248 | |
---|
| 249 | void G4OpenGLStoredQtViewer::mousePressEvent(QMouseEvent *event) |
---|
| 250 | { |
---|
[873] | 251 | G4MousePressEvent(event); |
---|
[564] | 252 | } |
---|
| 253 | |
---|
[696] | 254 | void G4OpenGLStoredQtViewer::keyPressEvent (QKeyEvent * event) |
---|
| 255 | { |
---|
| 256 | G4keyPressEvent(event); |
---|
| 257 | } |
---|
| 258 | |
---|
[804] | 259 | void G4OpenGLStoredQtViewer::wheelEvent (QWheelEvent * event) |
---|
| 260 | { |
---|
| 261 | G4wheelEvent(event); |
---|
| 262 | } |
---|
| 263 | |
---|
[678] | 264 | /** |
---|
| 265 | * This function was build in order to make a zoom on double clic event. |
---|
| 266 | * It was think to build a rubberband on the zoom area, but never work fine |
---|
| 267 | */ |
---|
[955] | 268 | void G4OpenGLStoredQtViewer::mouseDoubleClickEvent(QMouseEvent *) |
---|
[673] | 269 | { |
---|
[873] | 270 | G4MouseDoubleClickEvent(); |
---|
[673] | 271 | } |
---|
| 272 | |
---|
[955] | 273 | void G4OpenGLStoredQtViewer::mouseReleaseEvent(QMouseEvent *) |
---|
[673] | 274 | { |
---|
[797] | 275 | G4MouseReleaseEvent(); |
---|
[673] | 276 | } |
---|
| 277 | |
---|
[564] | 278 | void G4OpenGLStoredQtViewer::mouseMoveEvent(QMouseEvent *event) |
---|
| 279 | { |
---|
[873] | 280 | G4MouseMoveEvent(event); |
---|
[564] | 281 | } |
---|
| 282 | |
---|
| 283 | |
---|
| 284 | void G4OpenGLStoredQtViewer::contextMenuEvent(QContextMenuEvent *e) |
---|
| 285 | { |
---|
[873] | 286 | G4manageContextMenuEvent(e); |
---|
[564] | 287 | } |
---|
| 288 | |
---|
| 289 | void G4OpenGLStoredQtViewer::updateQWidget() { |
---|
[1040] | 290 | fHasToRepaint= true; |
---|
[564] | 291 | updateGL(); |
---|
[1040] | 292 | fHasToRepaint= false; |
---|
[564] | 293 | } |
---|
| 294 | |
---|
[877] | 295 | void G4OpenGLStoredQtViewer::ShowView ( |
---|
| 296 | ) |
---|
| 297 | ////////////////////////////////////////////////////////////////////////////// |
---|
| 298 | //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// |
---|
| 299 | { |
---|
| 300 | #if QT_VERSION < 0x040000 |
---|
| 301 | setActiveWindow(); |
---|
| 302 | #else |
---|
| 303 | activateWindow(); |
---|
| 304 | #endif |
---|
| 305 | } |
---|
[673] | 306 | |
---|
[531] | 307 | #endif |
---|