| 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: G4OpenGLImmediateQtViewer.cc,v 1.17 2009/11/03 11:02:32 lgarnier Exp $
|
|---|
| 28 | // GEANT4 tag $Name: $
|
|---|
| 29 | //
|
|---|
| 30 | //
|
|---|
| 31 | // Class G4OpenGLImmediateQtViewer : a class derived from G4OpenGLQtViewer and
|
|---|
| 32 | // G4OpenGLImmediateViewer.
|
|---|
| 33 |
|
|---|
| 34 | #ifdef G4VIS_BUILD_OPENGLQT_DRIVER
|
|---|
| 35 |
|
|---|
| 36 | #include "G4OpenGLImmediateQtViewer.hh"
|
|---|
| 37 | #include "G4OpenGLImmediateSceneHandler.hh"
|
|---|
| 38 |
|
|---|
| 39 | #include "G4ios.hh"
|
|---|
| 40 |
|
|---|
| 41 | G4OpenGLImmediateQtViewer::G4OpenGLImmediateQtViewer
|
|---|
| 42 | (G4OpenGLImmediateSceneHandler& sceneHandler,
|
|---|
| 43 | const G4String& name):
|
|---|
| 44 | G4VViewer (sceneHandler, sceneHandler.IncrementViewCount (), name),
|
|---|
| 45 | G4OpenGLViewer (sceneHandler),
|
|---|
| 46 | G4OpenGLQtViewer (sceneHandler),
|
|---|
| 47 | G4OpenGLImmediateViewer (sceneHandler)
|
|---|
| 48 | {
|
|---|
| 49 |
|
|---|
| 50 | #if QT_VERSION < 0x040000
|
|---|
| 51 | setFocusPolicy(QWidget::StrongFocus); // enable keybord events
|
|---|
| 52 | #else
|
|---|
| 53 | setFocusPolicy(Qt::StrongFocus); // enable keybord events
|
|---|
| 54 | #endif
|
|---|
| 55 | fHasToRepaint =false;
|
|---|
| 56 |
|
|---|
| 57 | if (fViewId < 0) return; // In case error in base class instantiation.
|
|---|
| 58 | }
|
|---|
| 59 |
|
|---|
| 60 | G4OpenGLImmediateQtViewer::~G4OpenGLImmediateQtViewer() {
|
|---|
| 61 | makeCurrent();
|
|---|
| 62 | }
|
|---|
| 63 |
|
|---|
| 64 | void G4OpenGLImmediateQtViewer::Initialise() {
|
|---|
| 65 | #ifdef G4DEBUG_VIS_OGL
|
|---|
| 66 | printf("G4OpenGLImmediateQtViewer::Initialise \n");
|
|---|
| 67 | #endif
|
|---|
| 68 | fReadyToPaint = false;
|
|---|
| 69 | CreateMainWindow (this,QString(fName));
|
|---|
| 70 | CreateFontLists ();
|
|---|
| 71 |
|
|---|
| 72 | fReadyToPaint = true;
|
|---|
| 73 | }
|
|---|
| 74 |
|
|---|
| 75 | void G4OpenGLImmediateQtViewer::initializeGL () {
|
|---|
| 76 |
|
|---|
| 77 | InitializeGLView ();
|
|---|
| 78 |
|
|---|
| 79 |
|
|---|
| 80 | // If a double buffer context has been forced upon us, ignore the
|
|---|
| 81 | // back buffer for this OpenGLImmediate view.
|
|---|
| 82 | // glDrawBuffer (GL_FRONT); // FIXME : Ne marche pas avec cette ligne, mais affiche le run correctement...
|
|---|
| 83 | // clear the buffers and window.
|
|---|
| 84 | ClearView ();
|
|---|
| 85 | FinishView ();
|
|---|
| 86 |
|
|---|
| 87 | glDepthFunc (GL_LEQUAL);
|
|---|
| 88 | glDepthMask (GL_TRUE);
|
|---|
| 89 |
|
|---|
| 90 | if (fSceneHandler.GetScene() == 0) {
|
|---|
| 91 | fHasToRepaint =false;
|
|---|
| 92 | } else {
|
|---|
| 93 | fHasToRepaint =true;
|
|---|
| 94 | }
|
|---|
| 95 |
|
|---|
| 96 | }
|
|---|
| 97 |
|
|---|
| 98 |
|
|---|
| 99 | /** To ensure compatibility with DrawView method
|
|---|
| 100 | */
|
|---|
| 101 | void G4OpenGLImmediateQtViewer::DrawView() {
|
|---|
| 102 | #ifdef G4DEBUG_VIS_OGL
|
|---|
| 103 | printf("G4OpenGLImmediateQtViewer::DrawView VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV\n");
|
|---|
| 104 | #endif
|
|---|
| 105 | // That's no the same logic as Stored Viewer, I don't know why...
|
|---|
| 106 | // see G4OpenGLStoredQtViewer::DrawView for more informations
|
|---|
| 107 |
|
|---|
| 108 | updateQWidget();
|
|---|
| 109 | #ifdef G4DEBUG_VIS_OGL
|
|---|
| 110 | printf("G4OpenGLImmediateQtViewer::DrawView ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n");
|
|---|
| 111 | #endif
|
|---|
| 112 | }
|
|---|
| 113 |
|
|---|
| 114 |
|
|---|
| 115 | void G4OpenGLImmediateQtViewer::ComputeView () {
|
|---|
| 116 |
|
|---|
| 117 | #ifdef G4DEBUG_VIS_OGL
|
|---|
| 118 | printf("G4OpenGLImmediateQtViewer::ComputeView %d %d VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV\n",getWinWidth(), getWinHeight());
|
|---|
| 119 | #endif
|
|---|
| 120 | makeCurrent();
|
|---|
| 121 | // If a double buffer context has been forced upon us, ignore the
|
|---|
| 122 | // back buffer for this OpenGLImmediate view.
|
|---|
| 123 | // glDrawBuffer (GL_FRONT);
|
|---|
| 124 |
|
|---|
| 125 | G4ViewParameters::DrawingStyle style = GetViewParameters().GetDrawingStyle();
|
|---|
| 126 |
|
|---|
| 127 | if(style!=G4ViewParameters::hlr &&
|
|---|
| 128 | haloing_enabled) {
|
|---|
| 129 |
|
|---|
| 130 | HaloingFirstPass ();
|
|---|
| 131 | NeedKernelVisit ();
|
|---|
| 132 | ProcessView ();
|
|---|
| 133 | glFlush ();
|
|---|
| 134 | #ifdef G4DEBUG_VIS_OGL
|
|---|
| 135 | printf("G4OpenGLImmediateQtViewer::ComputeView First ProcessView ok\n");
|
|---|
| 136 | #endif
|
|---|
| 137 | HaloingSecondPass ();
|
|---|
| 138 |
|
|---|
| 139 | }
|
|---|
| 140 |
|
|---|
| 141 | NeedKernelVisit (); // Always need to visit G4 kernel.
|
|---|
| 142 | ProcessView ();
|
|---|
| 143 |
|
|---|
| 144 | if (isRecording()) {
|
|---|
| 145 | savePPMToTemp();
|
|---|
| 146 | }
|
|---|
| 147 |
|
|---|
| 148 | #ifdef G4DEBUG_VIS_OGL
|
|---|
| 149 | printf("G4OpenGLImmediateQtViewer::ComputeView %d %d ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \n",getWinWidth(), getWinHeight());
|
|---|
| 150 | #endif
|
|---|
| 151 | fHasToRepaint = true;
|
|---|
| 152 | }
|
|---|
| 153 |
|
|---|
| 154 | void G4OpenGLImmediateQtViewer::FinishView()
|
|---|
| 155 | {
|
|---|
| 156 | #ifdef G4DEBUG_VIS_OGL
|
|---|
| 157 | printf("G4OpenGLImmediateQtViewer::FinishView() BEGIN\n");
|
|---|
| 158 | #endif
|
|---|
| 159 | glFlush ();
|
|---|
| 160 | #ifdef G4DEBUG_VIS_OGL
|
|---|
| 161 | printf("G4OpenGLImmediateQtViewer::FinishView() END\n");
|
|---|
| 162 | #endif
|
|---|
| 163 |
|
|---|
| 164 | }
|
|---|
| 165 |
|
|---|
| 166 |
|
|---|
| 167 | /**
|
|---|
| 168 | - Lors du resize de la fenetre, on doit non pas redessiner le detecteur, mais aussi les evenements
|
|---|
| 169 | */
|
|---|
| 170 | void G4OpenGLImmediateQtViewer::resizeGL(
|
|---|
| 171 | int aWidth
|
|---|
| 172 | ,int aHeight)
|
|---|
| 173 | {
|
|---|
| 174 | ResizeWindow(aWidth,aHeight);
|
|---|
| 175 | fHasToRepaint = sizeHasChanged();
|
|---|
| 176 | }
|
|---|
| 177 |
|
|---|
| 178 |
|
|---|
| 179 | void G4OpenGLImmediateQtViewer::paintGL()
|
|---|
| 180 | {
|
|---|
| 181 | #ifdef G4DEBUG_VIS_OGL
|
|---|
| 182 | printf("\n\nG4OpenGLImmediateQtViewer::paintGL ??\n");
|
|---|
| 183 | #endif
|
|---|
| 184 | if (!fReadyToPaint) {
|
|---|
| 185 | fReadyToPaint= true;
|
|---|
| 186 | return;
|
|---|
| 187 | }
|
|---|
| 188 | // DO NOT RESIZE IF SIZE HAS NOT CHANGE
|
|---|
| 189 | if ( !fHasToRepaint) {
|
|---|
| 190 | #if QT_VERSION < 0x040000
|
|---|
| 191 | if (((getWinWidth() == (unsigned int)width())) &&(getWinHeight() == (unsigned int) height())) {
|
|---|
| 192 | #else
|
|---|
| 193 | // L. Garnier : Trap to get the size with mac OSX 10.6 and Qt 4.6(devel)
|
|---|
| 194 | // Tested on Qt4.5 on mac, 4.4 on windows, 4.5 on unbuntu
|
|---|
| 195 | int sw = 0;
|
|---|
| 196 | int sh = 0;
|
|---|
| 197 | if (!isMaximized() && !isFullScreen()) {
|
|---|
| 198 | sw = normalGeometry().width();
|
|---|
| 199 | sh = normalGeometry().height();
|
|---|
| 200 | } else {
|
|---|
| 201 | sw = frameGeometry().width();
|
|---|
| 202 | sh = frameGeometry().height();
|
|---|
| 203 | }
|
|---|
| 204 | if ((getWinWidth() == (unsigned int)sw) &&(getWinHeight() == (unsigned int)sh)) {
|
|---|
| 205 | #endif
|
|---|
| 206 | return;
|
|---|
| 207 | }
|
|---|
| 208 | }
|
|---|
| 209 | #ifdef G4DEBUG_VIS_OGL
|
|---|
| 210 | printf("G4OpenGLImmediateQtViewer::paintGL VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV ready %d\n",fReadyToPaint);
|
|---|
| 211 | #endif
|
|---|
| 212 |
|
|---|
| 213 | SetView();
|
|---|
| 214 |
|
|---|
| 215 | ClearView (); //ok, put the background correct
|
|---|
| 216 | ComputeView();
|
|---|
| 217 |
|
|---|
| 218 | fHasToRepaint = false; // could be set to false by ComputeView
|
|---|
| 219 |
|
|---|
| 220 | #ifdef G4DEBUG_VIS_OGL
|
|---|
| 221 | printf("G4OpenGLImmediateQtViewer::paintGL ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ready %d\n\n\n",fReadyToPaint);
|
|---|
| 222 | #endif
|
|---|
| 223 | }
|
|---|
| 224 |
|
|---|
| 225 | void G4OpenGLImmediateQtViewer::mousePressEvent(QMouseEvent *event)
|
|---|
| 226 | {
|
|---|
| 227 | G4MousePressEvent(event);
|
|---|
| 228 | }
|
|---|
| 229 |
|
|---|
| 230 | void G4OpenGLImmediateQtViewer::keyPressEvent (QKeyEvent * event)
|
|---|
| 231 | {
|
|---|
| 232 | G4keyPressEvent(event);
|
|---|
| 233 | }
|
|---|
| 234 |
|
|---|
| 235 | void G4OpenGLImmediateQtViewer::wheelEvent (QWheelEvent * event)
|
|---|
| 236 | {
|
|---|
| 237 | G4wheelEvent(event);
|
|---|
| 238 | }
|
|---|
| 239 |
|
|---|
| 240 | /**
|
|---|
| 241 | * This function was build in order to make a zoom on double clic event.
|
|---|
| 242 | * It was think to build a rubberband on the zoom area, but never work fine
|
|---|
| 243 | */
|
|---|
| 244 | void G4OpenGLImmediateQtViewer::mouseDoubleClickEvent(QMouseEvent *)
|
|---|
| 245 | {
|
|---|
| 246 | G4MouseDoubleClickEvent();
|
|---|
| 247 | }
|
|---|
| 248 |
|
|---|
| 249 | void G4OpenGLImmediateQtViewer::mouseReleaseEvent(QMouseEvent *)
|
|---|
| 250 | {
|
|---|
| 251 | G4MouseReleaseEvent();
|
|---|
| 252 | }
|
|---|
| 253 |
|
|---|
| 254 | void G4OpenGLImmediateQtViewer::mouseMoveEvent(QMouseEvent *event)
|
|---|
| 255 | {
|
|---|
| 256 | G4MouseMoveEvent(event);
|
|---|
| 257 | }
|
|---|
| 258 |
|
|---|
| 259 |
|
|---|
| 260 | void G4OpenGLImmediateQtViewer::contextMenuEvent(QContextMenuEvent *e)
|
|---|
| 261 | {
|
|---|
| 262 | G4manageContextMenuEvent(e);
|
|---|
| 263 | }
|
|---|
| 264 |
|
|---|
| 265 | void G4OpenGLImmediateQtViewer::updateQWidget() {
|
|---|
| 266 | fHasToRepaint= true;
|
|---|
| 267 | updateGL();
|
|---|
| 268 | fHasToRepaint= false;
|
|---|
| 269 | }
|
|---|
| 270 |
|
|---|
| 271 |
|
|---|
| 272 | void G4OpenGLImmediateQtViewer::ShowView (
|
|---|
| 273 | )
|
|---|
| 274 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 275 | //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
|
|---|
| 276 | {
|
|---|
| 277 | #if QT_VERSION < 0x040000
|
|---|
| 278 | setActiveWindow();
|
|---|
| 279 | #else
|
|---|
| 280 | activateWindow();
|
|---|
| 281 | #endif
|
|---|
| 282 | }
|
|---|
| 283 | #endif
|
|---|