| [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 | //
|
|---|
| [1324] | 27 | // $Id: G4OpenGLStoredQtViewer.cc,v 1.32 2010/06/23 13:29:23 lgarnier Exp $
|
|---|
| [1307] | 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 |
|
|---|
| [533] | 40 | G4OpenGLStoredQtViewer::G4OpenGLStoredQtViewer
|
|---|
| [531] | 41 | (G4OpenGLStoredSceneHandler& sceneHandler,
|
|---|
| 42 | const G4String& name):
|
|---|
| [682] | 43 | G4VViewer (sceneHandler, sceneHandler.IncrementViewCount (), name),
|
|---|
| 44 | G4OpenGLViewer (sceneHandler),
|
|---|
| 45 | G4OpenGLQtViewer (sceneHandler),
|
|---|
| [1124] | 46 | G4OpenGLStoredViewer (sceneHandler), // FIXME : gerer le pb du parent !
|
|---|
| 47 | QGLWidget()
|
|---|
| [682] | 48 | {
|
|---|
| [863] | 49 |
|
|---|
| [1327] | 50 | #ifdef G4DEBUG_VIS_OGL
|
|---|
| 51 | printf("G4OpenGLStoredQtViewer::constructor VVVVVVVVVVVV\n");
|
|---|
| 52 | #endif
|
|---|
| [709] | 53 | #if QT_VERSION < 0x040000
|
|---|
| 54 | setFocusPolicy(QWidget::StrongFocus); // enable keybord events
|
|---|
| 55 | #else
|
|---|
| [696] | 56 | setFocusPolicy(Qt::StrongFocus); // enable keybord events
|
|---|
| [709] | 57 | #endif
|
|---|
| [1307] | 58 | fHasToRepaint = false;
|
|---|
| 59 | fIsRepainting = false;
|
|---|
| [858] | 60 |
|
|---|
| [1327] | 61 | #ifdef G4DEBUG_VIS_OGL
|
|---|
| 62 | printf("G4OpenGLStoredQtViewer::constructor ^^^^^^^^^^^^\n");
|
|---|
| 63 | #endif
|
|---|
| [531] | 64 | if (fViewId < 0) return; // In case error in base class instantiation.
|
|---|
| 65 | }
|
|---|
| 66 |
|
|---|
| [564] | 67 | G4OpenGLStoredQtViewer::~G4OpenGLStoredQtViewer() {
|
|---|
| [682] | 68 | makeCurrent();
|
|---|
| 69 | // this is connect to the Dialog for deleting it properly
|
|---|
| 70 | // when close event.
|
|---|
| 71 | // ((QDialog*)window())->reject();
|
|---|
| [564] | 72 | }
|
|---|
| [531] | 73 |
|
|---|
| [564] | 74 | void G4OpenGLStoredQtViewer::Initialise() {
|
|---|
| [911] | 75 | #ifdef G4DEBUG_VIS_OGL
|
|---|
| [1327] | 76 | printf("G4OpenGLStoredQtViewer::Initialise VVVVVVVVVVVV\n");
|
|---|
| [608] | 77 | #endif
|
|---|
| [1040] | 78 | fReadyToPaint = false;
|
|---|
| [1164] | 79 | CreateMainWindow (this,QString(GetName()));
|
|---|
| [873] | 80 | CreateFontLists ();
|
|---|
| [564] | 81 |
|
|---|
| [1040] | 82 | fReadyToPaint = true;
|
|---|
| [1327] | 83 | #ifdef G4DEBUG_VIS_OGL
|
|---|
| 84 | printf("G4OpenGLStoredQtViewer::Initialise ^^^^^^^^^^^^\n");
|
|---|
| 85 | #endif
|
|---|
| [564] | 86 | }
|
|---|
| [531] | 87 |
|
|---|
| [564] | 88 | void G4OpenGLStoredQtViewer::initializeGL () {
|
|---|
| 89 |
|
|---|
| [1327] | 90 | #ifdef G4DEBUG_VIS_OGL
|
|---|
| 91 | printf("G4OpenGLStoredQtViewer::InitialiseGL () 0\n");
|
|---|
| 92 | #endif
|
|---|
| 93 | // return;
|
|---|
| [1328] | 94 | InitializeGLView ();
|
|---|
| [564] | 95 |
|
|---|
| [911] | 96 | #ifdef G4DEBUG_VIS_OGL
|
|---|
| [682] | 97 | printf("G4OpenGLStoredQtViewer::InitialiseGL () 1\n");
|
|---|
| [608] | 98 | #endif
|
|---|
| [564] | 99 |
|
|---|
| [682] | 100 | // clear the buffers and window.
|
|---|
| [1295] | 101 | ClearView ();
|
|---|
| 102 | FinishView ();
|
|---|
| [564] | 103 |
|
|---|
| [682] | 104 | glDepthFunc (GL_LEQUAL);
|
|---|
| 105 | glDepthMask (GL_TRUE);
|
|---|
| [564] | 106 |
|
|---|
| [866] | 107 | if (fSceneHandler.GetScene() == 0) {
|
|---|
| [1040] | 108 | fHasToRepaint =false;
|
|---|
| [866] | 109 | } else {
|
|---|
| [1040] | 110 | fHasToRepaint =true;
|
|---|
| [866] | 111 | }
|
|---|
| [564] | 112 |
|
|---|
| [911] | 113 | #ifdef G4DEBUG_VIS_OGL
|
|---|
| [873] | 114 | printf("G4OpenGLStoredQtViewer::InitialiseGL END\n");
|
|---|
| [608] | 115 | #endif
|
|---|
| [531] | 116 | }
|
|---|
| 117 |
|
|---|
| [564] | 118 |
|
|---|
| [1242] | 119 | void G4OpenGLStoredQtViewer::DrawView () {
|
|---|
| [1238] | 120 | updateQWidget();
|
|---|
| [877] | 121 | }
|
|---|
| [682] | 122 |
|
|---|
| [877] | 123 | void G4OpenGLStoredQtViewer::ComputeView () {
|
|---|
| [1122] | 124 |
|
|---|
| 125 | #ifdef G4DEBUG_VIS_OGL
|
|---|
| [1039] | 126 | printf("G4OpenGLStoredQtViewer::ComputeView %d %d VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV\n",getWinWidth(), getWinHeight());
|
|---|
| [608] | 127 | #endif
|
|---|
| [877] | 128 | makeCurrent();
|
|---|
| [682] | 129 | G4ViewParameters::DrawingStyle style = GetViewParameters().GetDrawingStyle();
|
|---|
| [531] | 130 |
|
|---|
| [682] | 131 | //Make sure current viewer is attached and clean...
|
|---|
| [531] | 132 |
|
|---|
| [682] | 133 | //See if things have changed from last time and remake if necessary...
|
|---|
| 134 | // The fNeedKernelVisit flag might have been set by the user in
|
|---|
| 135 | // /vis/viewer/rebuild, but if not, make decision and set flag only
|
|---|
| 136 | // if necessary...
|
|---|
| [873] | 137 | if (!fNeedKernelVisit) {
|
|---|
| [877] | 138 | KernelVisitDecision ();
|
|---|
| [873] | 139 | }
|
|---|
| [682] | 140 | G4bool kernelVisitWasNeeded = fNeedKernelVisit; // Keep (ProcessView resets).
|
|---|
| 141 | ProcessView ();
|
|---|
| [564] | 142 |
|
|---|
| [531] | 143 |
|
|---|
| [682] | 144 | if(style!=G4ViewParameters::hlr &&
|
|---|
| 145 | haloing_enabled) {
|
|---|
| [911] | 146 | #ifdef G4DEBUG_VIS_OGL
|
|---|
| [877] | 147 | printf("G4OpenGLStoredQtViewer::ComputeView DANS LE IF\n");
|
|---|
| [608] | 148 | #endif
|
|---|
| [531] | 149 |
|
|---|
| [682] | 150 | HaloingFirstPass ();
|
|---|
| 151 | DrawDisplayLists ();
|
|---|
| 152 | glFlush ();
|
|---|
| [531] | 153 |
|
|---|
| [682] | 154 | HaloingSecondPass ();
|
|---|
| [531] | 155 |
|
|---|
| [682] | 156 | DrawDisplayLists ();
|
|---|
| 157 | FinishView ();
|
|---|
| [531] | 158 |
|
|---|
| [682] | 159 | } else {
|
|---|
| [564] | 160 |
|
|---|
| [682] | 161 | // If kernel visit was needed, drawing and FinishView will already
|
|---|
| 162 | // have been done, so...
|
|---|
| 163 | if (!kernelVisitWasNeeded) {
|
|---|
| [911] | 164 | #ifdef G4DEBUG_VIS_OGL
|
|---|
| [877] | 165 | printf("************************** G4OpenGLStoredQtViewer::ComputeView Don't need kernel Visit \n");
|
|---|
| [608] | 166 | #endif
|
|---|
| [682] | 167 | DrawDisplayLists ();
|
|---|
| 168 | FinishView ();
|
|---|
| 169 | } else {
|
|---|
| [911] | 170 | #ifdef G4DEBUG_VIS_OGL
|
|---|
| [877] | 171 | printf("************************** G4OpenGLStoredQtViewer::ComputeView need kernel Visit \n");
|
|---|
| [608] | 172 | #endif
|
|---|
| [682] | 173 | // However, union cutaways are implemented in DrawDisplayLists, so make
|
|---|
| 174 | // an extra pass...
|
|---|
| 175 | if (fVP.IsCutaway() &&
|
|---|
| 176 | fVP.GetCutawayMode() == G4ViewParameters::cutawayUnion) {
|
|---|
| 177 | ClearView();
|
|---|
| 178 | DrawDisplayLists ();
|
|---|
| 179 | FinishView ();
|
|---|
| [911] | 180 | #ifdef G4DEBUG_VIS_OGL
|
|---|
| [682] | 181 | printf("*************************** CASE 4 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \n");
|
|---|
| [608] | 182 | #endif
|
|---|
| [682] | 183 | } else { // ADD TO AVOID KernelVisit=1 and nothing to display
|
|---|
| 184 | DrawDisplayLists ();
|
|---|
| 185 | FinishView ();
|
|---|
| 186 | }
|
|---|
| 187 | }
|
|---|
| 188 | }
|
|---|
| [564] | 189 |
|
|---|
| [745] | 190 | if (isRecording()) {
|
|---|
| [739] | 191 | savePPMToTemp();
|
|---|
| [724] | 192 | }
|
|---|
| 193 |
|
|---|
| [911] | 194 | #ifdef G4DEBUG_VIS_OGL
|
|---|
| [1039] | 195 | printf("G4OpenGLStoredQtViewer::ComputeView %d %d ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \n",getWinWidth(), getWinHeight());
|
|---|
| [608] | 196 | #endif
|
|---|
| [1307] | 197 | fHasToRepaint = true;
|
|---|
| [531] | 198 | }
|
|---|
| 199 |
|
|---|
| [564] | 200 |
|
|---|
| 201 | /**
|
|---|
| [682] | 202 | - Lors du resize de la fenetre, on doit non pas redessiner le detecteur, mais aussi les evenements
|
|---|
| 203 | */
|
|---|
| [564] | 204 | void G4OpenGLStoredQtViewer::resizeGL(
|
|---|
| [1039] | 205 | int aWidth
|
|---|
| 206 | ,int aHeight)
|
|---|
| [564] | 207 | {
|
|---|
| [1121] | 208 | // Set new size, it will be update when next Repaint()->SetView() called
|
|---|
| [1307] | 209 | if ((aWidth > 0) && (aHeight > 0)) {
|
|---|
| 210 | ResizeWindow(aWidth,aHeight);
|
|---|
| 211 | fHasToRepaint = sizeHasChanged();
|
|---|
| 212 | }
|
|---|
| [1121] | 213 | }
|
|---|
| 214 |
|
|---|
| [1124] | 215 |
|
|---|
| [1227] | 216 | // We have to get several case :
|
|---|
| 217 | // - Only activate the windows (mouse click for example) -> Do not redraw
|
|---|
| 218 | // - resize window -> redraw
|
|---|
| 219 | // - try to avoid recompute everything if we do not rescale picture (side is the same)
|
|---|
| 220 |
|
|---|
| [1121] | 221 | void G4OpenGLStoredQtViewer::paintGL()
|
|---|
| 222 | {
|
|---|
| [1310] | 223 | #ifdef G4DEBUG_VIS_OGL
|
|---|
| 224 | printf("G4OpenGLStoredQtViewer::paintGL \n");
|
|---|
| 225 | #endif
|
|---|
| [1307] | 226 | if (fIsRepainting) {
|
|---|
| [1311] | 227 | // return ;
|
|---|
| [1307] | 228 | }
|
|---|
| 229 | fIsRepainting = true;
|
|---|
| [1121] | 230 | #ifdef G4DEBUG_VIS_OGL
|
|---|
| [1242] | 231 | printf("G4OpenGLStoredQtViewer::paintGL ready:%d fHasTo:%d??\n",fReadyToPaint,fHasToRepaint);
|
|---|
| [873] | 232 | #endif
|
|---|
| [1040] | 233 | if (!fReadyToPaint) {
|
|---|
| 234 | fReadyToPaint= true;
|
|---|
| [682] | 235 | return;
|
|---|
| 236 | }
|
|---|
| [1039] | 237 | // DO NOT RESIZE IF SIZE HAS NOT CHANGE :
|
|---|
| 238 | // WHEN CLICK ON THE FRAME FOR EXAMPLE
|
|---|
| 239 | // EXECEPT WHEN MOUSE MOVE EVENT
|
|---|
| [1040] | 240 | if ( !fHasToRepaint) {
|
|---|
| [1141] | 241 | #if QT_VERSION < 0x040000
|
|---|
| 242 | if (((getWinWidth() == (unsigned int)width())) &&(getWinHeight() == (unsigned int) height())) {
|
|---|
| 243 | #else
|
|---|
| [1125] | 244 | // L. Garnier : Trap to get the size with mac OSX 10.6 and Qt 4.6(devel)
|
|---|
| 245 | // Tested on Qt4.5 on mac, 4.4 on windows, 4.5 on unbuntu
|
|---|
| 246 | int sw = 0;
|
|---|
| 247 | int sh = 0;
|
|---|
| 248 | if (!isMaximized() && !isFullScreen()) {
|
|---|
| 249 | sw = normalGeometry().width();
|
|---|
| 250 | sh = normalGeometry().height();
|
|---|
| 251 | } else {
|
|---|
| 252 | sw = frameGeometry().width();
|
|---|
| 253 | sh = frameGeometry().height();
|
|---|
| 254 | }
|
|---|
| [1126] | 255 | if ((getWinWidth() == (unsigned int)sw) &&(getWinHeight() == (unsigned int)sh)) {
|
|---|
| [1141] | 256 | #endif
|
|---|
| [1039] | 257 | return;
|
|---|
| 258 | }
|
|---|
| 259 | }
|
|---|
| 260 | #ifdef G4DEBUG_VIS_OGL
|
|---|
| [1040] | 261 | printf("G4OpenGLStoredQtViewer::paintGL VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV ready %d\n",fReadyToPaint);
|
|---|
| [1039] | 262 | #endif
|
|---|
| [873] | 263 |
|
|---|
| [1141] | 264 | SetView();
|
|---|
| [1307] | 265 |
|
|---|
| [1141] | 266 | ClearView (); //ok, put the background correct
|
|---|
| [1039] | 267 | ComputeView();
|
|---|
| [1227] | 268 |
|
|---|
| [1307] | 269 | fHasToRepaint = false;
|
|---|
| [1242] | 270 |
|
|---|
| [911] | 271 | #ifdef G4DEBUG_VIS_OGL
|
|---|
| [1124] | 272 | printf("G4OpenGLStoredQtViewer::paintGL ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ready %d\n",fReadyToPaint);
|
|---|
| [608] | 273 | #endif
|
|---|
| [1307] | 274 | fIsRepainting = false;
|
|---|
| [682] | 275 | }
|
|---|
| [564] | 276 |
|
|---|
| [1322] | 277 | void G4OpenGLStoredQtViewer::paintEvent(QPaintEvent *) {
|
|---|
| [1235] | 278 | if ( fHasToRepaint) {
|
|---|
| 279 | updateGL();
|
|---|
| 280 | }
|
|---|
| 281 | }
|
|---|
| 282 |
|
|---|
| [564] | 283 | void G4OpenGLStoredQtViewer::mousePressEvent(QMouseEvent *event)
|
|---|
| 284 | {
|
|---|
| [1124] | 285 | G4MousePressEvent(event);
|
|---|
| [564] | 286 | }
|
|---|
| 287 |
|
|---|
| [696] | 288 | void G4OpenGLStoredQtViewer::keyPressEvent (QKeyEvent * event)
|
|---|
| 289 | {
|
|---|
| 290 | G4keyPressEvent(event);
|
|---|
| 291 | }
|
|---|
| 292 |
|
|---|
| [804] | 293 | void G4OpenGLStoredQtViewer::wheelEvent (QWheelEvent * event)
|
|---|
| 294 | {
|
|---|
| 295 | G4wheelEvent(event);
|
|---|
| 296 | }
|
|---|
| 297 |
|
|---|
| [1322] | 298 | void G4OpenGLStoredQtViewer::showEvent (QShowEvent *)
|
|---|
| [1240] | 299 | {
|
|---|
| 300 | fHasToRepaint = true;
|
|---|
| 301 | }
|
|---|
| 302 |
|
|---|
| [678] | 303 | /**
|
|---|
| 304 | * This function was build in order to make a zoom on double clic event.
|
|---|
| 305 | * It was think to build a rubberband on the zoom area, but never work fine
|
|---|
| 306 | */
|
|---|
| [955] | 307 | void G4OpenGLStoredQtViewer::mouseDoubleClickEvent(QMouseEvent *)
|
|---|
| [673] | 308 | {
|
|---|
| [873] | 309 | G4MouseDoubleClickEvent();
|
|---|
| [673] | 310 | }
|
|---|
| 311 |
|
|---|
| [955] | 312 | void G4OpenGLStoredQtViewer::mouseReleaseEvent(QMouseEvent *)
|
|---|
| [673] | 313 | {
|
|---|
| [797] | 314 | G4MouseReleaseEvent();
|
|---|
| [673] | 315 | }
|
|---|
| 316 |
|
|---|
| [564] | 317 | void G4OpenGLStoredQtViewer::mouseMoveEvent(QMouseEvent *event)
|
|---|
| 318 | {
|
|---|
| [873] | 319 | G4MouseMoveEvent(event);
|
|---|
| [564] | 320 | }
|
|---|
| 321 |
|
|---|
| 322 |
|
|---|
| 323 | void G4OpenGLStoredQtViewer::contextMenuEvent(QContextMenuEvent *e)
|
|---|
| 324 | {
|
|---|
| [873] | 325 | G4manageContextMenuEvent(e);
|
|---|
| [564] | 326 | }
|
|---|
| 327 |
|
|---|
| 328 | void G4OpenGLStoredQtViewer::updateQWidget() {
|
|---|
| [1040] | 329 | fHasToRepaint= true;
|
|---|
| [564] | 330 | updateGL();
|
|---|
| [1040] | 331 | fHasToRepaint= false;
|
|---|
| [564] | 332 | }
|
|---|
| 333 |
|
|---|
| [877] | 334 | void G4OpenGLStoredQtViewer::ShowView (
|
|---|
| 335 | )
|
|---|
| 336 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 337 | //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
|
|---|
| 338 | {
|
|---|
| 339 | #if QT_VERSION < 0x040000
|
|---|
| 340 | setActiveWindow();
|
|---|
| 341 | #else
|
|---|
| 342 | activateWindow();
|
|---|
| 343 | #endif
|
|---|
| 344 | }
|
|---|
| [673] | 345 |
|
|---|
| [531] | 346 | #endif
|
|---|