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