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