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