[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: G4OpenGLStoredQtViewer.cc,v 1.19 2008/10/24 13:49:19 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 |
---|
[682] | 59 | hasToRepaint =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() { |
---|
[873] | 72 | #ifdef G4DEBUG |
---|
[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; |
---|
| 80 | } |
---|
[531] | 81 | |
---|
[564] | 82 | void G4OpenGLStoredQtViewer::initializeGL () { |
---|
| 83 | |
---|
[682] | 84 | InitializeGLView (); |
---|
[564] | 85 | |
---|
[873] | 86 | #ifdef G4DEBUG |
---|
[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) { |
---|
| 98 | hasToRepaint =false; |
---|
| 99 | } else { |
---|
| 100 | hasToRepaint =true; |
---|
| 101 | } |
---|
[564] | 102 | |
---|
[873] | 103 | #ifdef G4DEBUG |
---|
| 104 | printf("G4OpenGLStoredQtViewer::InitialiseGL END\n"); |
---|
[608] | 105 | #endif |
---|
[531] | 106 | } |
---|
| 107 | |
---|
[564] | 108 | |
---|
[533] | 109 | void G4OpenGLStoredQtViewer::DrawView () { |
---|
[682] | 110 | |
---|
[873] | 111 | #ifdef G4DEBUG |
---|
[564] | 112 | printf("G4OpenGLStoredQtViewer::DrawView %d %d VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV\n",WinSize_x, WinSize_y); |
---|
[608] | 113 | #endif |
---|
[682] | 114 | G4ViewParameters::DrawingStyle style = GetViewParameters().GetDrawingStyle(); |
---|
[531] | 115 | |
---|
[682] | 116 | //Make sure current viewer is attached and clean... |
---|
| 117 | //Qt version needed |
---|
| 118 | // glViewport (0, 0, WinSize_x, WinSize_y); |
---|
[531] | 119 | |
---|
[682] | 120 | //See if things have changed from last time and remake if necessary... |
---|
| 121 | // The fNeedKernelVisit flag might have been set by the user in |
---|
| 122 | // /vis/viewer/rebuild, but if not, make decision and set flag only |
---|
| 123 | // if necessary... |
---|
[873] | 124 | if (!fNeedKernelVisit) { |
---|
[682] | 125 | if (!fNeedKernelVisit) KernelVisitDecision (); |
---|
[873] | 126 | } |
---|
[682] | 127 | G4bool kernelVisitWasNeeded = fNeedKernelVisit; // Keep (ProcessView resets). |
---|
| 128 | ProcessView (); |
---|
[564] | 129 | |
---|
[531] | 130 | |
---|
[682] | 131 | if(style!=G4ViewParameters::hlr && |
---|
| 132 | haloing_enabled) { |
---|
[873] | 133 | #ifdef G4DEBUG |
---|
[682] | 134 | printf("G4OpenGLStoredQtViewer::DrawView DANS LE IF\n"); |
---|
[608] | 135 | #endif |
---|
[531] | 136 | |
---|
[682] | 137 | HaloingFirstPass (); |
---|
| 138 | DrawDisplayLists (); |
---|
| 139 | glFlush (); |
---|
[531] | 140 | |
---|
[682] | 141 | HaloingSecondPass (); |
---|
[531] | 142 | |
---|
[682] | 143 | DrawDisplayLists (); |
---|
| 144 | FinishView (); |
---|
[531] | 145 | |
---|
[682] | 146 | } else { |
---|
[564] | 147 | |
---|
[682] | 148 | // If kernel visit was needed, drawing and FinishView will already |
---|
| 149 | // have been done, so... |
---|
| 150 | if (!kernelVisitWasNeeded) { |
---|
[873] | 151 | #ifdef G4DEBUG |
---|
[797] | 152 | printf("************************** G4OpenGLStoredQtViewer::DrawView Don't need kernel Visit \n"); |
---|
[608] | 153 | #endif |
---|
[682] | 154 | DrawDisplayLists (); |
---|
| 155 | FinishView (); |
---|
| 156 | } else { |
---|
[873] | 157 | #ifdef G4DEBUG |
---|
[797] | 158 | printf("************************** G4OpenGLStoredQtViewer::DrawView need kernel Visit \n"); |
---|
[608] | 159 | #endif |
---|
[682] | 160 | // However, union cutaways are implemented in DrawDisplayLists, so make |
---|
| 161 | // an extra pass... |
---|
| 162 | if (fVP.IsCutaway() && |
---|
| 163 | fVP.GetCutawayMode() == G4ViewParameters::cutawayUnion) { |
---|
| 164 | ClearView(); |
---|
| 165 | DrawDisplayLists (); |
---|
| 166 | FinishView (); |
---|
[873] | 167 | #ifdef G4DEBUG |
---|
[682] | 168 | printf("*************************** CASE 4 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \n"); |
---|
[608] | 169 | #endif |
---|
[682] | 170 | } else { // ADD TO AVOID KernelVisit=1 and nothing to display |
---|
| 171 | DrawDisplayLists (); |
---|
| 172 | FinishView (); |
---|
| 173 | } |
---|
| 174 | } |
---|
| 175 | } |
---|
[564] | 176 | |
---|
[745] | 177 | if (isRecording()) { |
---|
[739] | 178 | savePPMToTemp(); |
---|
[724] | 179 | } |
---|
| 180 | |
---|
[873] | 181 | #ifdef G4DEBUG |
---|
[682] | 182 | printf("G4OpenGLStoredQtViewer::DrawView %d %d ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \n",WinSize_x, WinSize_y); |
---|
[608] | 183 | #endif |
---|
[682] | 184 | hasToRepaint =true; |
---|
[531] | 185 | } |
---|
| 186 | |
---|
[564] | 187 | |
---|
| 188 | /** |
---|
[682] | 189 | - Lors du resize de la fenetre, on doit non pas redessiner le detecteur, mais aussi les evenements |
---|
| 190 | */ |
---|
[564] | 191 | void G4OpenGLStoredQtViewer::resizeGL( |
---|
[682] | 192 | int aWidth |
---|
| 193 | ,int aHeight) |
---|
[564] | 194 | { |
---|
[873] | 195 | G4resizeGL(aWidth,aHeight); |
---|
[564] | 196 | } |
---|
| 197 | |
---|
| 198 | |
---|
| 199 | void G4OpenGLStoredQtViewer::paintGL() |
---|
[682] | 200 | { |
---|
[873] | 201 | #ifdef G4DEBUG |
---|
| 202 | printf("G4OpenGLStoredQtViewer::paintGL ??\n"); |
---|
| 203 | #endif |
---|
[682] | 204 | if (!readyToPaint) { |
---|
| 205 | readyToPaint= true; |
---|
| 206 | return; |
---|
| 207 | } |
---|
| 208 | // DO NOT RESIZE IF SIZE HAS NOT CHANGE : |
---|
| 209 | // WHEN CLICK ON THE FRAME FOR EXAMPLE |
---|
| 210 | // EXECEPT WHEN MOUSE MOVE EVENT |
---|
| 211 | if ( !hasToRepaint) { |
---|
| 212 | if (((WinSize_x == (G4int)width())) &&(WinSize_y == (G4int) height())) { |
---|
| 213 | return; |
---|
| 214 | } |
---|
| 215 | } |
---|
[873] | 216 | #ifdef G4DEBUG |
---|
| 217 | printf("G4OpenGLStoredQtViewer::paintGL VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV ready %d\n",readyToPaint); |
---|
[608] | 218 | #endif |
---|
[682] | 219 | WinSize_x = (G4int) width(); |
---|
| 220 | WinSize_y = (G4int) height(); |
---|
[873] | 221 | |
---|
[682] | 222 | setupViewport(width(),height()); |
---|
[873] | 223 | |
---|
[682] | 224 | SetView(); |
---|
[873] | 225 | |
---|
[682] | 226 | ClearView (); //ok, put the background correct |
---|
| 227 | DrawView(); |
---|
[673] | 228 | |
---|
[682] | 229 | hasToRepaint =false; |
---|
[673] | 230 | |
---|
[873] | 231 | #ifdef G4DEBUG |
---|
| 232 | printf("G4OpenGLStoredQtViewer::paintGL ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ready %d\n",readyToPaint); |
---|
[608] | 233 | #endif |
---|
[682] | 234 | } |
---|
[564] | 235 | |
---|
| 236 | void G4OpenGLStoredQtViewer::mousePressEvent(QMouseEvent *event) |
---|
| 237 | { |
---|
[873] | 238 | G4MousePressEvent(event); |
---|
[564] | 239 | } |
---|
| 240 | |
---|
[696] | 241 | void G4OpenGLStoredQtViewer::keyPressEvent (QKeyEvent * event) |
---|
| 242 | { |
---|
| 243 | G4keyPressEvent(event); |
---|
| 244 | } |
---|
| 245 | |
---|
[804] | 246 | void G4OpenGLStoredQtViewer::wheelEvent (QWheelEvent * event) |
---|
| 247 | { |
---|
| 248 | G4wheelEvent(event); |
---|
| 249 | } |
---|
| 250 | |
---|
[678] | 251 | /** |
---|
| 252 | * This function was build in order to make a zoom on double clic event. |
---|
| 253 | * It was think to build a rubberband on the zoom area, but never work fine |
---|
| 254 | */ |
---|
[673] | 255 | void G4OpenGLStoredQtViewer::mouseDoubleClickEvent(QMouseEvent *event) |
---|
| 256 | { |
---|
[873] | 257 | G4MouseDoubleClickEvent(); |
---|
[673] | 258 | } |
---|
| 259 | |
---|
| 260 | void G4OpenGLStoredQtViewer::mouseReleaseEvent(QMouseEvent *event) |
---|
| 261 | { |
---|
[797] | 262 | G4MouseReleaseEvent(); |
---|
[673] | 263 | } |
---|
| 264 | |
---|
[564] | 265 | void G4OpenGLStoredQtViewer::mouseMoveEvent(QMouseEvent *event) |
---|
| 266 | { |
---|
[873] | 267 | G4MouseMoveEvent(event); |
---|
[564] | 268 | } |
---|
| 269 | |
---|
| 270 | |
---|
| 271 | void G4OpenGLStoredQtViewer::contextMenuEvent(QContextMenuEvent *e) |
---|
| 272 | { |
---|
[873] | 273 | G4manageContextMenuEvent(e); |
---|
[564] | 274 | } |
---|
| 275 | |
---|
| 276 | void G4OpenGLStoredQtViewer::updateQWidget() { |
---|
| 277 | hasToRepaint= true; |
---|
| 278 | updateGL(); |
---|
| 279 | hasToRepaint= false; |
---|
| 280 | } |
---|
| 281 | |
---|
[673] | 282 | |
---|
[531] | 283 | #endif |
---|