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