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