| [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: G4OpenGLImmediateQtViewer.cc,v 1.22 2010/06/23 13:29:23 lgarnier Exp $
|
|---|
| [1307] | 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"
|
|---|
| [914] | 37 | #include "G4OpenGLImmediateSceneHandler.hh"
|
|---|
| [531] | 38 |
|
|---|
| 39 | #include "G4ios.hh"
|
|---|
| 40 |
|
|---|
| [533] | 41 | G4OpenGLImmediateQtViewer::G4OpenGLImmediateQtViewer
|
|---|
| [531] | 42 | (G4OpenGLImmediateSceneHandler& sceneHandler,
|
|---|
| [897] | 43 | const G4String& name):
|
|---|
| [873] | 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
|
|---|
| [1307] | 55 | fHasToRepaint = false;
|
|---|
| 56 | fIsRepainting = false;
|
|---|
| [873] | 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() {
|
|---|
| [911] | 66 | #ifdef G4DEBUG_VIS_OGL
|
|---|
| [873] | 67 | printf("G4OpenGLImmediateQtViewer::Initialise \n");
|
|---|
| [608] | 68 | #endif
|
|---|
| [1040] | 69 | fReadyToPaint = false;
|
|---|
| [873] | 70 | CreateMainWindow (this,QString(fName));
|
|---|
| 71 | CreateFontLists ();
|
|---|
| [541] | 72 |
|
|---|
| [1040] | 73 | fReadyToPaint = true;
|
|---|
| [550] | 74 | }
|
|---|
| 75 |
|
|---|
| [551] | 76 | void G4OpenGLImmediateQtViewer::initializeGL () {
|
|---|
| [550] | 77 |
|
|---|
| [873] | 78 | InitializeGLView ();
|
|---|
| [550] | 79 |
|
|---|
| [531] | 80 |
|
|---|
| [873] | 81 | // If a double buffer context has been forced upon us, ignore the
|
|---|
| 82 | // back buffer for this OpenGLImmediate view.
|
|---|
| 83 | // glDrawBuffer (GL_FRONT); // FIXME : Ne marche pas avec cette ligne, mais affiche le run correctement...
|
|---|
| 84 | // clear the buffers and window.
|
|---|
| [1295] | 85 | ClearView ();
|
|---|
| 86 | FinishView ();
|
|---|
| [531] | 87 |
|
|---|
| [873] | 88 | glDepthFunc (GL_LEQUAL);
|
|---|
| 89 | glDepthMask (GL_TRUE);
|
|---|
| [541] | 90 |
|
|---|
| [873] | 91 | if (fSceneHandler.GetScene() == 0) {
|
|---|
| [1040] | 92 | fHasToRepaint =false;
|
|---|
| [873] | 93 | } else {
|
|---|
| [1040] | 94 | fHasToRepaint =true;
|
|---|
| [873] | 95 | }
|
|---|
| [551] | 96 |
|
|---|
| [877] | 97 | }
|
|---|
| 98 |
|
|---|
| [1125] | 99 |
|
|---|
| [877] | 100 | void G4OpenGLImmediateQtViewer::DrawView() {
|
|---|
| [1039] | 101 | updateQWidget();
|
|---|
| [531] | 102 | }
|
|---|
| 103 |
|
|---|
| [543] | 104 |
|
|---|
| [877] | 105 | void G4OpenGLImmediateQtViewer::ComputeView () {
|
|---|
| [531] | 106 |
|
|---|
| [911] | 107 | #ifdef G4DEBUG_VIS_OGL
|
|---|
| [1295] | 108 | printf("G4OpenGLImmediateQtViewer::ComputeView %d %d VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV\n",getWinWidth(), getWinHeight());
|
|---|
| [608] | 109 | #endif
|
|---|
| [877] | 110 | makeCurrent();
|
|---|
| [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 | if(style!=G4ViewParameters::hlr &&
|
|---|
| 118 | haloing_enabled) {
|
|---|
| 119 |
|
|---|
| 120 | HaloingFirstPass ();
|
|---|
| 121 | NeedKernelVisit ();
|
|---|
| 122 | ProcessView ();
|
|---|
| [1240] | 123 | FinishView();
|
|---|
| [911] | 124 | #ifdef G4DEBUG_VIS_OGL
|
|---|
| [877] | 125 | printf("G4OpenGLImmediateQtViewer::ComputeView First ProcessView ok\n");
|
|---|
| [608] | 126 | #endif
|
|---|
| [873] | 127 | HaloingSecondPass ();
|
|---|
| [552] | 128 |
|
|---|
| [873] | 129 | }
|
|---|
| [552] | 130 |
|
|---|
| [873] | 131 | NeedKernelVisit (); // Always need to visit G4 kernel.
|
|---|
| 132 | ProcessView ();
|
|---|
| [552] | 133 |
|
|---|
| [873] | 134 | if (isRecording()) {
|
|---|
| 135 | savePPMToTemp();
|
|---|
| 136 | }
|
|---|
| 137 |
|
|---|
| [911] | 138 | #ifdef G4DEBUG_VIS_OGL
|
|---|
| [1242] | 139 | printf("G4OpenGLImmediateQtViewer::ComputeView %d %d ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \n",getWinWidth(), getWinHeight());
|
|---|
| [608] | 140 | #endif
|
|---|
| [1040] | 141 | fHasToRepaint = true;
|
|---|
| [552] | 142 | }
|
|---|
| 143 |
|
|---|
| [564] | 144 | /**
|
|---|
| [873] | 145 | - Lors du resize de la fenetre, on doit non pas redessiner le detecteur, mais aussi les evenements
|
|---|
| 146 | */
|
|---|
| [539] | 147 | void G4OpenGLImmediateQtViewer::resizeGL(
|
|---|
| [877] | 148 | int aWidth
|
|---|
| 149 | ,int aHeight)
|
|---|
| [564] | 150 | {
|
|---|
| [1307] | 151 | if ((aWidth > 0) && (aHeight > 0)) {
|
|---|
| 152 | ResizeWindow(aWidth,aHeight);
|
|---|
| 153 | fHasToRepaint = sizeHasChanged();
|
|---|
| 154 | }
|
|---|
| [539] | 155 | }
|
|---|
| 156 |
|
|---|
| [559] | 157 |
|
|---|
| [539] | 158 | void G4OpenGLImmediateQtViewer::paintGL()
|
|---|
| [873] | 159 | {
|
|---|
| [1307] | 160 | if (fIsRepainting) {
|
|---|
| [1311] | 161 | // return ;
|
|---|
| [1307] | 162 | }
|
|---|
| [1040] | 163 | if (!fReadyToPaint) {
|
|---|
| 164 | fReadyToPaint= true;
|
|---|
| [1039] | 165 | return;
|
|---|
| 166 | }
|
|---|
| [1228] | 167 | if ((getWinWidth() == 0) && (getWinHeight() == 0)) {
|
|---|
| 168 | return;
|
|---|
| 169 | }
|
|---|
| 170 |
|
|---|
| [1039] | 171 | // DO NOT RESIZE IF SIZE HAS NOT CHANGE
|
|---|
| [1040] | 172 | if ( !fHasToRepaint) {
|
|---|
| [1141] | 173 | #if QT_VERSION < 0x040000
|
|---|
| 174 | if (((getWinWidth() == (unsigned int)width())) &&(getWinHeight() == (unsigned int) height())) {
|
|---|
| [1227] | 175 | return;
|
|---|
| 176 | }
|
|---|
| [1141] | 177 | #else
|
|---|
| [1131] | 178 | // L. Garnier : Trap to get the size with mac OSX 10.6 and Qt 4.6(devel)
|
|---|
| 179 | // Tested on Qt4.5 on mac, 4.4 on windows, 4.5 on unbuntu
|
|---|
| 180 | int sw = 0;
|
|---|
| 181 | int sh = 0;
|
|---|
| 182 | if (!isMaximized() && !isFullScreen()) {
|
|---|
| 183 | sw = normalGeometry().width();
|
|---|
| 184 | sh = normalGeometry().height();
|
|---|
| 185 | } else {
|
|---|
| 186 | sw = frameGeometry().width();
|
|---|
| 187 | sh = frameGeometry().height();
|
|---|
| 188 | }
|
|---|
| 189 | if ((getWinWidth() == (unsigned int)sw) &&(getWinHeight() == (unsigned int)sh)) {
|
|---|
| [1039] | 190 | return;
|
|---|
| [1227] | 191 |
|
|---|
| 192 | } else if ((sw == 0) && (sh == 0)) { // NOT A TOP LEVEL WIDGET
|
|---|
| 193 | if (((getWinWidth() == (unsigned int)width())) &&(getWinHeight() == (unsigned int) height())) {
|
|---|
| [1228] | 194 | return;
|
|---|
| [1227] | 195 | }
|
|---|
| [1038] | 196 | }
|
|---|
| [1227] | 197 | #endif
|
|---|
| [873] | 198 | }
|
|---|
| [911] | 199 | #ifdef G4DEBUG_VIS_OGL
|
|---|
| [1040] | 200 | printf("G4OpenGLImmediateQtViewer::paintGL VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV ready %d\n",fReadyToPaint);
|
|---|
| [873] | 201 | #endif
|
|---|
| [541] | 202 |
|
|---|
| [1039] | 203 | SetView();
|
|---|
| 204 |
|
|---|
| 205 | ClearView (); //ok, put the background correct
|
|---|
| 206 | ComputeView();
|
|---|
| 207 |
|
|---|
| [1040] | 208 | fHasToRepaint = false; // could be set to false by ComputeView
|
|---|
| [1039] | 209 |
|
|---|
| [911] | 210 | #ifdef G4DEBUG_VIS_OGL
|
|---|
| [1040] | 211 | printf("G4OpenGLImmediateQtViewer::paintGL ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ready %d\n\n\n",fReadyToPaint);
|
|---|
| [608] | 212 | #endif
|
|---|
| [1307] | 213 | fIsRepainting = false;
|
|---|
| [873] | 214 | }
|
|---|
| [551] | 215 |
|
|---|
| [873] | 216 | void G4OpenGLImmediateQtViewer::mousePressEvent(QMouseEvent *event)
|
|---|
| 217 | {
|
|---|
| 218 | G4MousePressEvent(event);
|
|---|
| 219 | }
|
|---|
| 220 |
|
|---|
| 221 | void G4OpenGLImmediateQtViewer::keyPressEvent (QKeyEvent * event)
|
|---|
| 222 | {
|
|---|
| 223 | G4keyPressEvent(event);
|
|---|
| 224 | }
|
|---|
| 225 |
|
|---|
| 226 | void G4OpenGLImmediateQtViewer::wheelEvent (QWheelEvent * event)
|
|---|
| 227 | {
|
|---|
| 228 | G4wheelEvent(event);
|
|---|
| 229 | }
|
|---|
| 230 |
|
|---|
| [1322] | 231 | void G4OpenGLImmediateQtViewer::showEvent (QShowEvent *)
|
|---|
| [1240] | 232 | {
|
|---|
| 233 | fHasToRepaint = true;
|
|---|
| 234 | }
|
|---|
| 235 |
|
|---|
| 236 |
|
|---|
| [873] | 237 | /**
|
|---|
| 238 | * This function was build in order to make a zoom on double clic event.
|
|---|
| 239 | * It was think to build a rubberband on the zoom area, but never work fine
|
|---|
| 240 | */
|
|---|
| [955] | 241 | void G4OpenGLImmediateQtViewer::mouseDoubleClickEvent(QMouseEvent *)
|
|---|
| [873] | 242 | {
|
|---|
| 243 | G4MouseDoubleClickEvent();
|
|---|
| 244 | }
|
|---|
| 245 |
|
|---|
| [955] | 246 | void G4OpenGLImmediateQtViewer::mouseReleaseEvent(QMouseEvent *)
|
|---|
| [873] | 247 | {
|
|---|
| 248 | G4MouseReleaseEvent();
|
|---|
| 249 | }
|
|---|
| 250 |
|
|---|
| 251 | void G4OpenGLImmediateQtViewer::mouseMoveEvent(QMouseEvent *event)
|
|---|
| 252 | {
|
|---|
| 253 | G4MouseMoveEvent(event);
|
|---|
| 254 | }
|
|---|
| 255 |
|
|---|
| 256 |
|
|---|
| 257 | void G4OpenGLImmediateQtViewer::contextMenuEvent(QContextMenuEvent *e)
|
|---|
| 258 | {
|
|---|
| 259 | G4manageContextMenuEvent(e);
|
|---|
| 260 | }
|
|---|
| 261 |
|
|---|
| [1322] | 262 | void G4OpenGLImmediateQtViewer::paintEvent(QPaintEvent *) {
|
|---|
| [1235] | 263 | if ( fHasToRepaint) {
|
|---|
| 264 | updateGL();
|
|---|
| 265 | }
|
|---|
| [1228] | 266 | }
|
|---|
| 267 |
|
|---|
| 268 |
|
|---|
| [564] | 269 | void G4OpenGLImmediateQtViewer::updateQWidget() {
|
|---|
| [1040] | 270 | fHasToRepaint= true;
|
|---|
| [564] | 271 | updateGL();
|
|---|
| [1240] | 272 | repaint();
|
|---|
| [1040] | 273 | fHasToRepaint= false;
|
|---|
| [564] | 274 | }
|
|---|
| [551] | 275 |
|
|---|
| [877] | 276 |
|
|---|
| 277 | void G4OpenGLImmediateQtViewer::ShowView (
|
|---|
| 278 | )
|
|---|
| 279 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 280 | //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
|
|---|
| 281 | {
|
|---|
| [1240] | 282 | fHasToRepaint = true;
|
|---|
| [877] | 283 | #if QT_VERSION < 0x040000
|
|---|
| 284 | setActiveWindow();
|
|---|
| 285 | #else
|
|---|
| 286 | activateWindow();
|
|---|
| [531] | 287 | #endif
|
|---|
| [877] | 288 | }
|
|---|
| 289 | #endif
|
|---|