| 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.7 2008/11/06 13:43:44 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 |
|
|---|
| 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.
|
|---|
| 85 | ClearView ();
|
|---|
| 86 | FinishView ();
|
|---|
| 87 |
|
|---|
| 88 | glDepthFunc (GL_LEQUAL);
|
|---|
| 89 | glDepthMask (GL_TRUE);
|
|---|
| 90 |
|
|---|
| 91 | if (fSceneHandler.GetScene() == 0) {
|
|---|
| 92 | hasToRepaint =false;
|
|---|
| 93 | } else {
|
|---|
| 94 | hasToRepaint =true;
|
|---|
| 95 | }
|
|---|
| 96 |
|
|---|
| 97 | }
|
|---|
| 98 |
|
|---|
| 99 |
|
|---|
| 100 | /** To ensure compatibility with DrawView method
|
|---|
| 101 | */
|
|---|
| 102 | void G4OpenGLImmediateQtViewer::DrawView() {
|
|---|
| 103 | #ifdef G4DEBUG
|
|---|
| 104 | printf("G4OpenGLImmediateQtViewer::DrawView VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV\n");
|
|---|
| 105 | #endif
|
|---|
| 106 | // That's no the same logic as Stored Viewer, I don't know why...
|
|---|
| 107 | // see G4OpenGLStoredQtViewer::DrawView for more informations
|
|---|
| 108 |
|
|---|
| 109 | updateQWidget();
|
|---|
| 110 | #ifdef G4DEBUG
|
|---|
| 111 | printf("G4OpenGLImmediateQtViewer::DrawView ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n");
|
|---|
| 112 | #endif
|
|---|
| 113 | }
|
|---|
| 114 |
|
|---|
| 115 |
|
|---|
| 116 | void G4OpenGLImmediateQtViewer::ComputeView () {
|
|---|
| 117 |
|
|---|
| 118 | #ifdef G4DEBUG
|
|---|
| 119 | printf("G4OpenGLImmediateQtViewer::ComputeView %d %d VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV\n",WinSize_x, WinSize_y);
|
|---|
| 120 | #endif
|
|---|
| 121 | makeCurrent();
|
|---|
| 122 | // If a double buffer context has been forced upon us, ignore the
|
|---|
| 123 | // back buffer for this OpenGLImmediate view.
|
|---|
| 124 | // glDrawBuffer (GL_FRONT);
|
|---|
| 125 |
|
|---|
| 126 | G4ViewParameters::DrawingStyle style = GetViewParameters().GetDrawingStyle();
|
|---|
| 127 |
|
|---|
| 128 | //Make sure current viewer is attached and clean...
|
|---|
| 129 | //Qt version needed
|
|---|
| 130 | // glViewport (0, 0, WinSize_x, WinSize_y);
|
|---|
| 131 |
|
|---|
| 132 | if(style!=G4ViewParameters::hlr &&
|
|---|
| 133 | haloing_enabled) {
|
|---|
| 134 |
|
|---|
| 135 | HaloingFirstPass ();
|
|---|
| 136 | NeedKernelVisit ();
|
|---|
| 137 | ProcessView ();
|
|---|
| 138 | glFlush ();
|
|---|
| 139 | #ifdef G4DEBUG
|
|---|
| 140 | printf("G4OpenGLImmediateQtViewer::ComputeView First ProcessView ok\n");
|
|---|
| 141 | #endif
|
|---|
| 142 | HaloingSecondPass ();
|
|---|
| 143 |
|
|---|
| 144 | }
|
|---|
| 145 |
|
|---|
| 146 | NeedKernelVisit (); // Always need to visit G4 kernel.
|
|---|
| 147 | ProcessView ();
|
|---|
| 148 |
|
|---|
| 149 | if (isRecording()) {
|
|---|
| 150 | savePPMToTemp();
|
|---|
| 151 | }
|
|---|
| 152 |
|
|---|
| 153 | #ifdef G4DEBUG
|
|---|
| 154 | printf("G4OpenGLImmediateQtViewer::ComputeView %d %d ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \n",WinSize_x, WinSize_y);
|
|---|
| 155 | #endif
|
|---|
| 156 | hasToRepaint = true;
|
|---|
| 157 | }
|
|---|
| 158 |
|
|---|
| 159 | void G4OpenGLImmediateQtViewer::FinishView()
|
|---|
| 160 | {
|
|---|
| 161 | #ifdef G4DEBUG
|
|---|
| 162 | printf("G4OpenGLImmediateQtViewer::FinishView() BEGIN\n");
|
|---|
| 163 | #endif
|
|---|
| 164 | glFlush ();
|
|---|
| 165 | #ifdef G4DEBUG
|
|---|
| 166 | printf("G4OpenGLImmediateQtViewer::FinishView() END\n");
|
|---|
| 167 | #endif
|
|---|
| 168 |
|
|---|
| 169 | }
|
|---|
| 170 |
|
|---|
| 171 |
|
|---|
| 172 | /**
|
|---|
| 173 | - Lors du resize de la fenetre, on doit non pas redessiner le detecteur, mais aussi les evenements
|
|---|
| 174 | */
|
|---|
| 175 | void G4OpenGLImmediateQtViewer::resizeGL(
|
|---|
| 176 | int aWidth
|
|---|
| 177 | ,int aHeight)
|
|---|
| 178 | {
|
|---|
| 179 | G4resizeGL(aWidth,aHeight);
|
|---|
| 180 | }
|
|---|
| 181 |
|
|---|
| 182 |
|
|---|
| 183 | void G4OpenGLImmediateQtViewer::paintGL()
|
|---|
| 184 | {
|
|---|
| 185 | #ifdef G4DEBUG
|
|---|
| 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 (((WinSize_x == (G4int)width())) &&(WinSize_y == (G4int) height())) {
|
|---|
| 195 | return;
|
|---|
| 196 | }
|
|---|
| 197 | }
|
|---|
| 198 | #ifdef G4DEBUG
|
|---|
| 199 | printf("G4OpenGLImmediateQtViewer::paintGL VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV ready %d\n",readyToPaint);
|
|---|
| 200 | #endif
|
|---|
| 201 | WinSize_x = (G4int) width();
|
|---|
| 202 | WinSize_y = (G4int) height();
|
|---|
| 203 |
|
|---|
| 204 | setupViewport(width(),height());
|
|---|
| 205 |
|
|---|
| 206 | SetView();
|
|---|
| 207 |
|
|---|
| 208 | ClearView (); //ok, put the background correct
|
|---|
| 209 | ComputeView();
|
|---|
| 210 |
|
|---|
| 211 | hasToRepaint = false; // could be set to false by ComputeView
|
|---|
| 212 |
|
|---|
| 213 | #ifdef G4DEBUG
|
|---|
| 214 | printf("G4OpenGLImmediateQtViewer::paintGL ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ready %d\n\n\n",readyToPaint);
|
|---|
| 215 | #endif
|
|---|
| 216 | }
|
|---|
| 217 |
|
|---|
| 218 | void G4OpenGLImmediateQtViewer::mousePressEvent(QMouseEvent *event)
|
|---|
| 219 | {
|
|---|
| 220 | G4MousePressEvent(event);
|
|---|
| 221 | }
|
|---|
| 222 |
|
|---|
| 223 | void G4OpenGLImmediateQtViewer::keyPressEvent (QKeyEvent * event)
|
|---|
| 224 | {
|
|---|
| 225 | G4keyPressEvent(event);
|
|---|
| 226 | }
|
|---|
| 227 |
|
|---|
| 228 | void G4OpenGLImmediateQtViewer::wheelEvent (QWheelEvent * event)
|
|---|
| 229 | {
|
|---|
| 230 | G4wheelEvent(event);
|
|---|
| 231 | }
|
|---|
| 232 |
|
|---|
| 233 | /**
|
|---|
| 234 | * This function was build in order to make a zoom on double clic event.
|
|---|
| 235 | * It was think to build a rubberband on the zoom area, but never work fine
|
|---|
| 236 | */
|
|---|
| 237 | void G4OpenGLImmediateQtViewer::mouseDoubleClickEvent(QMouseEvent *event)
|
|---|
| 238 | {
|
|---|
| 239 | G4MouseDoubleClickEvent();
|
|---|
| 240 | }
|
|---|
| 241 |
|
|---|
| 242 | void G4OpenGLImmediateQtViewer::mouseReleaseEvent(QMouseEvent *event)
|
|---|
| 243 | {
|
|---|
| 244 | G4MouseReleaseEvent();
|
|---|
| 245 | }
|
|---|
| 246 |
|
|---|
| 247 | void G4OpenGLImmediateQtViewer::mouseMoveEvent(QMouseEvent *event)
|
|---|
| 248 | {
|
|---|
| 249 | G4MouseMoveEvent(event);
|
|---|
| 250 | }
|
|---|
| 251 |
|
|---|
| 252 |
|
|---|
| 253 | void G4OpenGLImmediateQtViewer::contextMenuEvent(QContextMenuEvent *e)
|
|---|
| 254 | {
|
|---|
| 255 | G4manageContextMenuEvent(e);
|
|---|
| 256 | }
|
|---|
| 257 |
|
|---|
| 258 | void G4OpenGLImmediateQtViewer::updateQWidget() {
|
|---|
| 259 | hasToRepaint= true;
|
|---|
| 260 | updateGL();
|
|---|
| 261 | hasToRepaint= false;
|
|---|
| 262 | }
|
|---|
| 263 |
|
|---|
| 264 |
|
|---|
| 265 | void G4OpenGLImmediateQtViewer::ShowView (
|
|---|
| 266 | )
|
|---|
| 267 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 268 | //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
|
|---|
| 269 | {
|
|---|
| 270 | #if QT_VERSION < 0x040000
|
|---|
| 271 | setActiveWindow();
|
|---|
| 272 | #else
|
|---|
| 273 | activateWindow();
|
|---|
| 274 | #endif
|
|---|
| 275 | }
|
|---|
| 276 | #endif
|
|---|