[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 | // |
---|
[976] | 27 | // $Id: G4OpenGLStoredQtViewer.cc,v 1.24 2009/03/31 17:14:42 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 |
---|
[1038] | 59 | fNeedRepaint =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 |
---|
[682] | 75 | readyToPaint = false; |
---|
[866] | 76 | CreateMainWindow (this,QString(fName)); |
---|
[873] | 77 | CreateFontLists (); |
---|
[564] | 78 | |
---|
| 79 | readyToPaint = true; |
---|
[1038] | 80 | #ifdef G4DEBUG_VIS_OGL |
---|
| 81 | printf("G4OpenGLStoredQtViewer::Initialise END\n"); |
---|
| 82 | #endif |
---|
[564] | 83 | } |
---|
[531] | 84 | |
---|
[564] | 85 | void G4OpenGLStoredQtViewer::initializeGL () { |
---|
| 86 | |
---|
[682] | 87 | InitializeGLView (); |
---|
[564] | 88 | |
---|
[911] | 89 | #ifdef G4DEBUG_VIS_OGL |
---|
[682] | 90 | printf("G4OpenGLStoredQtViewer::InitialiseGL () 1\n"); |
---|
[608] | 91 | #endif |
---|
[564] | 92 | |
---|
[682] | 93 | // clear the buffers and window. |
---|
| 94 | ClearView (); |
---|
| 95 | FinishView (); |
---|
[564] | 96 | |
---|
[682] | 97 | glDepthFunc (GL_LEQUAL); |
---|
| 98 | glDepthMask (GL_TRUE); |
---|
[564] | 99 | |
---|
[866] | 100 | if (fSceneHandler.GetScene() == 0) { |
---|
[1038] | 101 | fNeedRepaint =false; |
---|
[866] | 102 | } else { |
---|
[1038] | 103 | fNeedRepaint =true; |
---|
[866] | 104 | } |
---|
[564] | 105 | |
---|
[911] | 106 | #ifdef G4DEBUG_VIS_OGL |
---|
[873] | 107 | printf("G4OpenGLStoredQtViewer::InitialiseGL END\n"); |
---|
[608] | 108 | #endif |
---|
[531] | 109 | } |
---|
| 110 | |
---|
[564] | 111 | |
---|
[533] | 112 | void G4OpenGLStoredQtViewer::DrawView () { |
---|
[911] | 113 | #ifdef G4DEBUG_VIS_OGL |
---|
[877] | 114 | printf("G4OpenGLStoredQtViewer::DrawView VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV\n"); |
---|
| 115 | #endif |
---|
| 116 | // That's no the same logic as Immediate Viewer, I don't know why... |
---|
| 117 | // But if I send updateGL here, we go here : |
---|
| 118 | // updateQWidget -> paintGL -> ComputeView |
---|
| 119 | // whih is not the same as ComputeView Directly |
---|
| 120 | // And we loose the redraw of things ! |
---|
| 121 | |
---|
[1038] | 122 | // avoid problems at initialisation |
---|
| 123 | if (readyToPaint) { |
---|
| 124 | ComputeView(); |
---|
| 125 | } |
---|
| 126 | |
---|
[911] | 127 | #ifdef G4DEBUG_VIS_OGL |
---|
[877] | 128 | printf("G4OpenGLStoredQtViewer::DrawView ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n"); |
---|
| 129 | #endif |
---|
| 130 | } |
---|
[682] | 131 | |
---|
[877] | 132 | void G4OpenGLStoredQtViewer::ComputeView () { |
---|
| 133 | |
---|
[911] | 134 | #ifdef G4DEBUG_VIS_OGL |
---|
[1037] | 135 | printf("G4OpenGLStoredQtViewer::ComputeView VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV\n"); |
---|
[608] | 136 | #endif |
---|
[877] | 137 | makeCurrent(); |
---|
[682] | 138 | G4ViewParameters::DrawingStyle style = GetViewParameters().GetDrawingStyle(); |
---|
[531] | 139 | |
---|
[682] | 140 | //Make sure current viewer is attached and clean... |
---|
[531] | 141 | |
---|
[682] | 142 | //See if things have changed from last time and remake if necessary... |
---|
| 143 | // The fNeedKernelVisit flag might have been set by the user in |
---|
| 144 | // /vis/viewer/rebuild, but if not, make decision and set flag only |
---|
| 145 | // if necessary... |
---|
[873] | 146 | if (!fNeedKernelVisit) { |
---|
[877] | 147 | KernelVisitDecision (); |
---|
[873] | 148 | } |
---|
[682] | 149 | G4bool kernelVisitWasNeeded = fNeedKernelVisit; // Keep (ProcessView resets). |
---|
| 150 | ProcessView (); |
---|
[564] | 151 | |
---|
[531] | 152 | |
---|
[682] | 153 | if(style!=G4ViewParameters::hlr && |
---|
| 154 | haloing_enabled) { |
---|
[911] | 155 | #ifdef G4DEBUG_VIS_OGL |
---|
[877] | 156 | printf("G4OpenGLStoredQtViewer::ComputeView DANS LE IF\n"); |
---|
[608] | 157 | #endif |
---|
[531] | 158 | |
---|
[682] | 159 | HaloingFirstPass (); |
---|
| 160 | DrawDisplayLists (); |
---|
| 161 | glFlush (); |
---|
[531] | 162 | |
---|
[682] | 163 | HaloingSecondPass (); |
---|
[531] | 164 | |
---|
[682] | 165 | DrawDisplayLists (); |
---|
| 166 | FinishView (); |
---|
[531] | 167 | |
---|
[682] | 168 | } else { |
---|
[564] | 169 | |
---|
[682] | 170 | // If kernel visit was needed, drawing and FinishView will already |
---|
| 171 | // have been done, so... |
---|
| 172 | if (!kernelVisitWasNeeded) { |
---|
[911] | 173 | #ifdef G4DEBUG_VIS_OGL |
---|
[877] | 174 | printf("************************** G4OpenGLStoredQtViewer::ComputeView Don't need kernel Visit \n"); |
---|
[608] | 175 | #endif |
---|
[682] | 176 | DrawDisplayLists (); |
---|
| 177 | FinishView (); |
---|
| 178 | } else { |
---|
[911] | 179 | #ifdef G4DEBUG_VIS_OGL |
---|
[877] | 180 | printf("************************** G4OpenGLStoredQtViewer::ComputeView need kernel Visit \n"); |
---|
[608] | 181 | #endif |
---|
[682] | 182 | // However, union cutaways are implemented in DrawDisplayLists, so make |
---|
| 183 | // an extra pass... |
---|
| 184 | if (fVP.IsCutaway() && |
---|
| 185 | fVP.GetCutawayMode() == G4ViewParameters::cutawayUnion) { |
---|
| 186 | ClearView(); |
---|
| 187 | DrawDisplayLists (); |
---|
| 188 | FinishView (); |
---|
[911] | 189 | #ifdef G4DEBUG_VIS_OGL |
---|
[682] | 190 | printf("*************************** CASE 4 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \n"); |
---|
[608] | 191 | #endif |
---|
[682] | 192 | } else { // ADD TO AVOID KernelVisit=1 and nothing to display |
---|
| 193 | DrawDisplayLists (); |
---|
| 194 | FinishView (); |
---|
| 195 | } |
---|
| 196 | } |
---|
| 197 | } |
---|
[564] | 198 | |
---|
[745] | 199 | if (isRecording()) { |
---|
[739] | 200 | savePPMToTemp(); |
---|
[724] | 201 | } |
---|
| 202 | |
---|
[911] | 203 | #ifdef G4DEBUG_VIS_OGL |
---|
[1037] | 204 | printf("G4OpenGLStoredQtViewer::ComputeView ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \n"); |
---|
[608] | 205 | #endif |
---|
[531] | 206 | } |
---|
| 207 | |
---|
[564] | 208 | |
---|
| 209 | /** |
---|
[682] | 210 | - Lors du resize de la fenetre, on doit non pas redessiner le detecteur, mais aussi les evenements |
---|
| 211 | */ |
---|
[564] | 212 | void G4OpenGLStoredQtViewer::resizeGL( |
---|
[1038] | 213 | int aWidth |
---|
| 214 | ,int aHeight) |
---|
[564] | 215 | { |
---|
[906] | 216 | // Set new size, it will be update when next Repaint()->SetView() called |
---|
[1037] | 217 | ResizeGLView(aWidth,aHeight); |
---|
[1038] | 218 | // fNeedRepaint = true; |
---|
[564] | 219 | } |
---|
| 220 | |
---|
| 221 | |
---|
| 222 | void G4OpenGLStoredQtViewer::paintGL() |
---|
[682] | 223 | { |
---|
[911] | 224 | #ifdef G4DEBUG_VIS_OGL |
---|
[944] | 225 | printf("G4OpenGLStoredQtViewer::paintGL ??\n"); |
---|
[873] | 226 | #endif |
---|
[682] | 227 | if (!readyToPaint) { |
---|
| 228 | readyToPaint= true; |
---|
| 229 | return; |
---|
| 230 | } |
---|
[1038] | 231 | RepaintGLView(); |
---|
[873] | 232 | |
---|
[911] | 233 | #ifdef G4DEBUG_VIS_OGL |
---|
[873] | 234 | printf("G4OpenGLStoredQtViewer::paintGL ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ready %d\n",readyToPaint); |
---|
[608] | 235 | #endif |
---|
[682] | 236 | } |
---|
[564] | 237 | |
---|
| 238 | void G4OpenGLStoredQtViewer::mousePressEvent(QMouseEvent *event) |
---|
| 239 | { |
---|
[873] | 240 | G4MousePressEvent(event); |
---|
[564] | 241 | } |
---|
| 242 | |
---|
[696] | 243 | void G4OpenGLStoredQtViewer::keyPressEvent (QKeyEvent * event) |
---|
| 244 | { |
---|
| 245 | G4keyPressEvent(event); |
---|
| 246 | } |
---|
| 247 | |
---|
[804] | 248 | void G4OpenGLStoredQtViewer::wheelEvent (QWheelEvent * event) |
---|
| 249 | { |
---|
| 250 | G4wheelEvent(event); |
---|
| 251 | } |
---|
| 252 | |
---|
[678] | 253 | /** |
---|
| 254 | * This function was build in order to make a zoom on double clic event. |
---|
| 255 | * It was think to build a rubberband on the zoom area, but never work fine |
---|
| 256 | */ |
---|
[955] | 257 | void G4OpenGLStoredQtViewer::mouseDoubleClickEvent(QMouseEvent *) |
---|
[673] | 258 | { |
---|
[873] | 259 | G4MouseDoubleClickEvent(); |
---|
[673] | 260 | } |
---|
| 261 | |
---|
[955] | 262 | void G4OpenGLStoredQtViewer::mouseReleaseEvent(QMouseEvent *) |
---|
[673] | 263 | { |
---|
[797] | 264 | G4MouseReleaseEvent(); |
---|
[673] | 265 | } |
---|
| 266 | |
---|
[564] | 267 | void G4OpenGLStoredQtViewer::mouseMoveEvent(QMouseEvent *event) |
---|
| 268 | { |
---|
[873] | 269 | G4MouseMoveEvent(event); |
---|
[564] | 270 | } |
---|
| 271 | |
---|
| 272 | |
---|
| 273 | void G4OpenGLStoredQtViewer::contextMenuEvent(QContextMenuEvent *e) |
---|
| 274 | { |
---|
[873] | 275 | G4manageContextMenuEvent(e); |
---|
[564] | 276 | } |
---|
| 277 | |
---|
| 278 | void G4OpenGLStoredQtViewer::updateQWidget() { |
---|
[1038] | 279 | fNeedRepaint= true; |
---|
[564] | 280 | updateGL(); |
---|
[1038] | 281 | fNeedRepaint= false; |
---|
[564] | 282 | } |
---|
| 283 | |
---|
[877] | 284 | void G4OpenGLStoredQtViewer::ShowView ( |
---|
| 285 | ) |
---|
| 286 | ////////////////////////////////////////////////////////////////////////////// |
---|
| 287 | //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// |
---|
| 288 | { |
---|
| 289 | #if QT_VERSION < 0x040000 |
---|
| 290 | setActiveWindow(); |
---|
| 291 | #else |
---|
| 292 | activateWindow(); |
---|
| 293 | #endif |
---|
| 294 | updateQWidget(); |
---|
| 295 | } |
---|
[673] | 296 | |
---|
[531] | 297 | #endif |
---|