[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 | // |
---|
[873] | 27 | // $Id: G4OpenGLImmediateQtViewer.cc,v 1.6 2008/10/24 13:49:19 lgarnier Exp $ |
---|
[866] | 28 | // GEANT4 tag $Name: $ |
---|
[531] | 29 | // |
---|
[539] | 30 | // |
---|
[533] | 31 | // Class G4OpenGLImmediateQtViewer : a class derived from G4OpenGLQtViewer and |
---|
[531] | 32 | // G4OpenGLImmediateViewer. |
---|
| 33 | |
---|
[533] | 34 | #ifdef G4VIS_BUILD_OPENGLQT_DRIVER |
---|
[531] | 35 | |
---|
[533] | 36 | #include "G4OpenGLImmediateQtViewer.hh" |
---|
[531] | 37 | |
---|
| 38 | #include "G4ios.hh" |
---|
| 39 | |
---|
[533] | 40 | G4OpenGLImmediateQtViewer::G4OpenGLImmediateQtViewer |
---|
[531] | 41 | (G4OpenGLImmediateSceneHandler& sceneHandler, |
---|
| 42 | const G4String& name): |
---|
[873] | 43 | G4VViewer (sceneHandler, sceneHandler.IncrementViewCount (), name), |
---|
| 44 | G4OpenGLViewer (sceneHandler), |
---|
| 45 | G4OpenGLQtViewer (sceneHandler), |
---|
| 46 | G4OpenGLImmediateViewer (sceneHandler) |
---|
| 47 | { |
---|
| 48 | |
---|
| 49 | //set true to picking |
---|
| 50 | fVP.SetPicking(true); |
---|
| 51 | #if QT_VERSION < 0x040000 |
---|
| 52 | setFocusPolicy(QWidget::StrongFocus); // enable keybord events |
---|
| 53 | #else |
---|
| 54 | setFocusPolicy(Qt::StrongFocus); // enable keybord events |
---|
| 55 | #endif |
---|
| 56 | hasToRepaint =false; |
---|
| 57 | |
---|
[531] | 58 | if (fViewId < 0) return; // In case error in base class instantiation. |
---|
| 59 | } |
---|
| 60 | |
---|
[551] | 61 | G4OpenGLImmediateQtViewer::~G4OpenGLImmediateQtViewer() { |
---|
[873] | 62 | makeCurrent(); |
---|
[551] | 63 | } |
---|
| 64 | |
---|
[543] | 65 | void G4OpenGLImmediateQtViewer::Initialise() { |
---|
[873] | 66 | #ifdef G4DEBUG |
---|
| 67 | printf("G4OpenGLImmediateQtViewer::Initialise \n"); |
---|
[608] | 68 | #endif |
---|
[873] | 69 | readyToPaint = false; |
---|
| 70 | CreateMainWindow (this,QString(fName)); |
---|
| 71 | CreateFontLists (); |
---|
[541] | 72 | |
---|
[552] | 73 | readyToPaint = true; |
---|
[550] | 74 | } |
---|
| 75 | |
---|
[551] | 76 | void G4OpenGLImmediateQtViewer::initializeGL () { |
---|
[550] | 77 | |
---|
[873] | 78 | InitializeGLView (); |
---|
[550] | 79 | |
---|
[873] | 80 | #ifdef G4DEBUG |
---|
| 81 | printf("G4OpenGLImmediateQtViewer::InitialiseGL ()\n"); |
---|
[608] | 82 | #endif |
---|
[531] | 83 | |
---|
[873] | 84 | // If a double buffer context has been forced upon us, ignore the |
---|
| 85 | // back buffer for this OpenGLImmediate view. |
---|
| 86 | // glDrawBuffer (GL_FRONT); // FIXME : Ne marche pas avec cette ligne, mais affiche le run correctement... |
---|
| 87 | // clear the buffers and window. |
---|
| 88 | ClearView (); |
---|
| 89 | FinishView (); |
---|
[531] | 90 | |
---|
[873] | 91 | glDepthFunc (GL_LEQUAL); |
---|
| 92 | glDepthMask (GL_TRUE); |
---|
[541] | 93 | |
---|
[873] | 94 | if (fSceneHandler.GetScene() == 0) { |
---|
| 95 | hasToRepaint =false; |
---|
| 96 | } else { |
---|
| 97 | hasToRepaint =true; |
---|
| 98 | } |
---|
[551] | 99 | |
---|
[873] | 100 | #ifdef G4DEBUG |
---|
| 101 | printf("G4OpenGLImmediateQtViewer::InitialiseGL END\n"); |
---|
[608] | 102 | #endif |
---|
[531] | 103 | } |
---|
| 104 | |
---|
[543] | 105 | |
---|
[533] | 106 | void G4OpenGLImmediateQtViewer::DrawView () { |
---|
[531] | 107 | |
---|
[873] | 108 | #ifdef G4DEBUG |
---|
[542] | 109 | printf("G4OpenGLImmediateQtViewer::DrawView %d %d VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV\n",WinSize_x, WinSize_y); |
---|
[608] | 110 | #endif |
---|
[873] | 111 | // If a double buffer context has been forced upon us, ignore the |
---|
| 112 | // back buffer for this OpenGLImmediate view. |
---|
| 113 | // glDrawBuffer (GL_FRONT); |
---|
[552] | 114 | |
---|
[873] | 115 | G4ViewParameters::DrawingStyle style = GetViewParameters().GetDrawingStyle(); |
---|
[552] | 116 | |
---|
[873] | 117 | //Make sure current viewer is attached and clean... |
---|
| 118 | //Qt version needed |
---|
| 119 | glViewport (0, 0, WinSize_x, WinSize_y); |
---|
[552] | 120 | |
---|
[873] | 121 | if(style!=G4ViewParameters::hlr && |
---|
| 122 | haloing_enabled) { |
---|
| 123 | |
---|
| 124 | HaloingFirstPass (); |
---|
| 125 | NeedKernelVisit (); |
---|
| 126 | ProcessView (); |
---|
| 127 | glFlush (); |
---|
| 128 | #ifdef G4DEBUG |
---|
| 129 | printf("G4OpenGLImmediateQtViewer::DrawView First ProcessView ok\n"); |
---|
[608] | 130 | #endif |
---|
[873] | 131 | HaloingSecondPass (); |
---|
[552] | 132 | |
---|
[873] | 133 | } |
---|
[552] | 134 | |
---|
[873] | 135 | #ifdef G4DEBUG |
---|
| 136 | printf("G4OpenGLImmediateQtViewer::DrawView before needKernelVisit %d\n",fNeedKernelVisit); |
---|
| 137 | #endif |
---|
| 138 | NeedKernelVisit (); // Always need to visit G4 kernel. |
---|
| 139 | #ifdef G4DEBUG |
---|
| 140 | printf("G4OpenGLImmediateQtViewer::DrawView before ProcessView\n"); |
---|
| 141 | #endif |
---|
| 142 | ProcessView (); |
---|
| 143 | #ifdef G4DEBUG |
---|
| 144 | printf("G4OpenGLImmediateQtViewer::DrawView before FinishView ok\n"); |
---|
| 145 | #endif |
---|
| 146 | FinishView (); |
---|
[552] | 147 | |
---|
[873] | 148 | if (isRecording()) { |
---|
| 149 | savePPMToTemp(); |
---|
| 150 | } |
---|
| 151 | |
---|
| 152 | #ifdef G4DEBUG |
---|
[564] | 153 | printf("G4OpenGLImmediateQtViewer::DrawView %d %d ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \n",WinSize_x, WinSize_y); |
---|
[608] | 154 | #endif |
---|
[873] | 155 | hasToRepaint = true; |
---|
[552] | 156 | } |
---|
| 157 | |
---|
[873] | 158 | void G4OpenGLImmediateQtViewer::FinishView() |
---|
[531] | 159 | { |
---|
[554] | 160 | glFlush (); |
---|
[531] | 161 | } |
---|
| 162 | |
---|
[539] | 163 | |
---|
[564] | 164 | /** |
---|
[873] | 165 | - Lors du resize de la fenetre, on doit non pas redessiner le detecteur, mais aussi les evenements |
---|
| 166 | */ |
---|
[539] | 167 | void G4OpenGLImmediateQtViewer::resizeGL( |
---|
[873] | 168 | int aWidth |
---|
| 169 | ,int aHeight) |
---|
[564] | 170 | { |
---|
[873] | 171 | G4resizeGL(aWidth,aHeight); |
---|
[539] | 172 | } |
---|
| 173 | |
---|
[559] | 174 | |
---|
[539] | 175 | void G4OpenGLImmediateQtViewer::paintGL() |
---|
[873] | 176 | { |
---|
| 177 | #ifdef G4DEBUG |
---|
| 178 | printf("\n\nG4OpenGLImmediateQtViewer::paintGL ??\n"); |
---|
[608] | 179 | #endif |
---|
[873] | 180 | if (!readyToPaint) { |
---|
| 181 | readyToPaint= true; |
---|
| 182 | return; |
---|
| 183 | } |
---|
| 184 | // DO NOT RESIZE IF SIZE HAS NOT CHANGE |
---|
| 185 | if ( !hasToRepaint) { |
---|
| 186 | if (((WinSize_x == (G4int)width())) &&(WinSize_y == (G4int) height())) { |
---|
| 187 | return; |
---|
| 188 | } |
---|
| 189 | } |
---|
| 190 | #ifdef G4DEBUG |
---|
| 191 | printf("G4OpenGLImmediateQtViewer::paintGL VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV ready %d\n",readyToPaint); |
---|
| 192 | #endif |
---|
| 193 | WinSize_x = (G4int) width(); |
---|
| 194 | WinSize_y = (G4int) height(); |
---|
[541] | 195 | |
---|
[873] | 196 | setupViewport(width(),height()); |
---|
[541] | 197 | |
---|
[873] | 198 | SetView(); |
---|
[564] | 199 | |
---|
[873] | 200 | ClearView (); //ok, put the background correct |
---|
| 201 | DrawView(); |
---|
[559] | 202 | |
---|
[873] | 203 | hasToRepaint = false; // could be set to false by DrawView |
---|
[543] | 204 | |
---|
[873] | 205 | |
---|
| 206 | #ifdef G4DEBUG |
---|
| 207 | printf("G4OpenGLImmediateQtViewer::paintGL ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ready %d\n\n\n",readyToPaint); |
---|
[608] | 208 | #endif |
---|
[873] | 209 | } |
---|
[551] | 210 | |
---|
[873] | 211 | void G4OpenGLImmediateQtViewer::mousePressEvent(QMouseEvent *event) |
---|
| 212 | { |
---|
| 213 | G4MousePressEvent(event); |
---|
| 214 | } |
---|
| 215 | |
---|
| 216 | void G4OpenGLImmediateQtViewer::keyPressEvent (QKeyEvent * event) |
---|
| 217 | { |
---|
| 218 | G4keyPressEvent(event); |
---|
| 219 | } |
---|
| 220 | |
---|
| 221 | void G4OpenGLImmediateQtViewer::wheelEvent (QWheelEvent * event) |
---|
| 222 | { |
---|
| 223 | G4wheelEvent(event); |
---|
| 224 | } |
---|
| 225 | |
---|
| 226 | /** |
---|
| 227 | * This function was build in order to make a zoom on double clic event. |
---|
| 228 | * It was think to build a rubberband on the zoom area, but never work fine |
---|
| 229 | */ |
---|
| 230 | void G4OpenGLImmediateQtViewer::mouseDoubleClickEvent(QMouseEvent *event) |
---|
| 231 | { |
---|
| 232 | G4MouseDoubleClickEvent(); |
---|
| 233 | } |
---|
| 234 | |
---|
| 235 | void G4OpenGLImmediateQtViewer::mouseReleaseEvent(QMouseEvent *event) |
---|
| 236 | { |
---|
| 237 | G4MouseReleaseEvent(); |
---|
| 238 | } |
---|
| 239 | |
---|
| 240 | void G4OpenGLImmediateQtViewer::mouseMoveEvent(QMouseEvent *event) |
---|
| 241 | { |
---|
| 242 | G4MouseMoveEvent(event); |
---|
| 243 | } |
---|
| 244 | |
---|
| 245 | |
---|
| 246 | void G4OpenGLImmediateQtViewer::contextMenuEvent(QContextMenuEvent *e) |
---|
| 247 | { |
---|
| 248 | G4manageContextMenuEvent(e); |
---|
| 249 | } |
---|
| 250 | |
---|
[564] | 251 | void G4OpenGLImmediateQtViewer::updateQWidget() { |
---|
[873] | 252 | hasToRepaint= true; |
---|
[564] | 253 | updateGL(); |
---|
[873] | 254 | hasToRepaint= false; |
---|
[564] | 255 | } |
---|
[551] | 256 | |
---|
[531] | 257 | #endif |
---|