| 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.14 2009/05/13 10:28:00 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 | #define QT_STORE_46_DBG 1
|
|---|
| 36 |
|
|---|
| 37 | #include "G4VViewer.hh"
|
|---|
| 38 | #include "G4OpenGLImmediateQtViewer.hh"
|
|---|
| 39 | #include "G4OpenGLImmediateSceneHandler.hh"
|
|---|
| 40 |
|
|---|
| 41 | #include "G4ios.hh"
|
|---|
| 42 |
|
|---|
| 43 | G4OpenGLImmediateQtViewer::G4OpenGLImmediateQtViewer
|
|---|
| 44 | (G4OpenGLImmediateSceneHandler& sceneHandler,
|
|---|
| 45 | const G4String& name):
|
|---|
| 46 | G4VViewer (sceneHandler, sceneHandler.IncrementViewCount (), name),
|
|---|
| 47 | G4OpenGLViewer (sceneHandler),
|
|---|
| 48 | G4OpenGLQtViewer (sceneHandler),
|
|---|
| 49 | G4OpenGLImmediateViewer (sceneHandler)
|
|---|
| 50 | {
|
|---|
| 51 |
|
|---|
| 52 | #if QT_VERSION < 0x040000
|
|---|
| 53 | setFocusPolicy(QWidget::StrongFocus); // enable keybord events
|
|---|
| 54 | #else
|
|---|
| 55 | setFocusPolicy(Qt::StrongFocus); // enable keybord events
|
|---|
| 56 | #endif
|
|---|
| 57 | fHasToRepaint =false;
|
|---|
| 58 |
|
|---|
| 59 | if (fViewId < 0) return; // In case error in base class instantiation.
|
|---|
| 60 | }
|
|---|
| 61 |
|
|---|
| 62 | G4OpenGLImmediateQtViewer::~G4OpenGLImmediateQtViewer() {
|
|---|
| 63 | makeCurrent();
|
|---|
| 64 | }
|
|---|
| 65 |
|
|---|
| 66 | void G4OpenGLImmediateQtViewer::Initialise() {
|
|---|
| 67 | #ifdef G4DEBUG_VIS_OGL
|
|---|
| 68 | printf("G4OpenGLImmediateQtViewer::Initialise \n");
|
|---|
| 69 | #endif
|
|---|
| 70 | fReadyToPaint = false;
|
|---|
| 71 | CreateMainWindow (this,QString(fName));
|
|---|
| 72 | CreateFontLists ();
|
|---|
| 73 |
|
|---|
| 74 | fReadyToPaint = true;
|
|---|
| 75 | }
|
|---|
| 76 |
|
|---|
| 77 | #ifdef QT_STORE_46_DBG
|
|---|
| 78 | void G4OpenGLImmediateQtViewer::initializeGL () {
|
|---|
| 79 | glShadeModel(GL_SMOOTH); // Enable Smooth Shading
|
|---|
| 80 | glClearColor(0.0f, 0.0f, 0.0f, 0.5f); // Black Background
|
|---|
| 81 | glClearDepth(1.0f); // Depth Buffer Setup
|
|---|
| 82 | glEnable(GL_DEPTH_TEST); // Enables Depth Testing
|
|---|
| 83 | glDepthFunc(GL_LEQUAL); // The Type Of Depth Testing To Do
|
|---|
| 84 | glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // Really Nice Perspective Calculations
|
|---|
| 85 |
|
|---|
| 86 |
|
|---|
| 87 | return; // Initialization Went OK
|
|---|
| 88 |
|
|---|
| 89 |
|
|---|
| 90 | }
|
|---|
| 91 | #else
|
|---|
| 92 | void G4OpenGLImmediateQtViewer::initializeGL () {
|
|---|
| 93 |
|
|---|
| 94 | InitializeGLView ();
|
|---|
| 95 |
|
|---|
| 96 |
|
|---|
| 97 | // If a double buffer context has been forced upon us, ignore the
|
|---|
| 98 | // back buffer for this OpenGLImmediate view.
|
|---|
| 99 | // glDrawBuffer (GL_FRONT); // FIXME : Ne marche pas avec cette ligne, mais affiche le run correctement...
|
|---|
| 100 | // clear the buffers and window.
|
|---|
| 101 | ClearView ();
|
|---|
| 102 | FinishView ();
|
|---|
| 103 |
|
|---|
| 104 | glDepthFunc (GL_LEQUAL);
|
|---|
| 105 | glDepthMask (GL_TRUE);
|
|---|
| 106 |
|
|---|
| 107 | if (fSceneHandler.GetScene() == 0) {
|
|---|
| 108 | fHasToRepaint =false;
|
|---|
| 109 | } else {
|
|---|
| 110 | fHasToRepaint =true;
|
|---|
| 111 | }
|
|---|
| 112 |
|
|---|
| 113 | }
|
|---|
| 114 | #endif
|
|---|
| 115 |
|
|---|
| 116 | /** To ensure compatibility with DrawView method
|
|---|
| 117 | */
|
|---|
| 118 | void G4OpenGLImmediateQtViewer::DrawView() {
|
|---|
| 119 | #ifdef G4DEBUG_VIS_OGL
|
|---|
| 120 | printf("G4OpenGLImmediateQtViewer::DrawView VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV\n");
|
|---|
| 121 | #endif
|
|---|
| 122 | // That's no the same logic as Stored Viewer, I don't know why...
|
|---|
| 123 | // see G4OpenGLStoredQtViewer::DrawView for more informations
|
|---|
| 124 |
|
|---|
| 125 | updateQWidget();
|
|---|
| 126 | #ifdef G4DEBUG_VIS_OGL
|
|---|
| 127 | printf("G4OpenGLImmediateQtViewer::DrawView ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n");
|
|---|
| 128 | #endif
|
|---|
| 129 | }
|
|---|
| 130 |
|
|---|
| 131 |
|
|---|
| 132 | #ifdef QT_STORE_46_DBG
|
|---|
| 133 | void G4OpenGLImmediateQtViewer::ComputeView () {
|
|---|
| 134 | }
|
|---|
| 135 | #else
|
|---|
| 136 | void G4OpenGLImmediateQtViewer::ComputeView () {
|
|---|
| 137 |
|
|---|
| 138 | #ifdef G4DEBUG_VIS_OGL
|
|---|
| 139 | printf("G4OpenGLImmediateQtViewer::ComputeView %d %d VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV\n",getWinWidth(), getWinHeight());
|
|---|
| 140 | #endif
|
|---|
| 141 | makeCurrent();
|
|---|
| 142 | // If a double buffer context has been forced upon us, ignore the
|
|---|
| 143 | // back buffer for this OpenGLImmediate view.
|
|---|
| 144 | // glDrawBuffer (GL_FRONT);
|
|---|
| 145 |
|
|---|
| 146 | G4ViewParameters::DrawingStyle style = GetViewParameters().GetDrawingStyle();
|
|---|
| 147 |
|
|---|
| 148 | if(style!=G4ViewParameters::hlr &&
|
|---|
| 149 | haloing_enabled) {
|
|---|
| 150 |
|
|---|
| 151 | HaloingFirstPass ();
|
|---|
| 152 | NeedKernelVisit ();
|
|---|
| 153 | ProcessView ();
|
|---|
| 154 | glFlush ();
|
|---|
| 155 | #ifdef G4DEBUG_VIS_OGL
|
|---|
| 156 | printf("G4OpenGLImmediateQtViewer::ComputeView First ProcessView ok\n");
|
|---|
| 157 | #endif
|
|---|
| 158 | HaloingSecondPass ();
|
|---|
| 159 |
|
|---|
| 160 | }
|
|---|
| 161 |
|
|---|
| 162 | NeedKernelVisit (); // Always need to visit G4 kernel.
|
|---|
| 163 | ProcessView ();
|
|---|
| 164 |
|
|---|
| 165 | if (isRecording()) {
|
|---|
| 166 | savePPMToTemp();
|
|---|
| 167 | }
|
|---|
| 168 |
|
|---|
| 169 | #ifdef G4DEBUG_VIS_OGL
|
|---|
| 170 | printf("G4OpenGLImmediateQtViewer::ComputeView %d %d ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \n",getWinWidth(), getWinHeight());
|
|---|
| 171 | #endif
|
|---|
| 172 | fHasToRepaint = true;
|
|---|
| 173 | }
|
|---|
| 174 | #endif
|
|---|
| 175 |
|
|---|
| 176 | void G4OpenGLImmediateQtViewer::FinishView()
|
|---|
| 177 | {
|
|---|
| 178 | #ifdef G4DEBUG_VIS_OGL
|
|---|
| 179 | printf("G4OpenGLImmediateQtViewer::FinishView() BEGIN\n");
|
|---|
| 180 | #endif
|
|---|
| 181 | glFlush ();
|
|---|
| 182 | #ifdef G4DEBUG_VIS_OGL
|
|---|
| 183 | printf("G4OpenGLImmediateQtViewer::FinishView() END\n");
|
|---|
| 184 | #endif
|
|---|
| 185 |
|
|---|
| 186 | }
|
|---|
| 187 |
|
|---|
| 188 |
|
|---|
| 189 | /**
|
|---|
| 190 | - Lors du resize de la fenetre, on doit non pas redessiner le detecteur, mais aussi les evenements
|
|---|
| 191 | */
|
|---|
| 192 | #ifdef QT_STORE_46_DBG
|
|---|
| 193 | void G4OpenGLImmediateQtViewer::resizeGL(
|
|---|
| 194 | int width
|
|---|
| 195 | ,int height)
|
|---|
| 196 | {
|
|---|
| 197 | #ifdef G4DEBUG_VIS_OGL
|
|---|
| 198 | printf("G4OpenGLImmediateQtViewer::resizeGL\n");
|
|---|
| 199 | #endif
|
|---|
| 200 | if (height==0) // Prevent A Divide By Zero By
|
|---|
| 201 | {
|
|---|
| 202 | height=1; // Making Height Equal One
|
|---|
| 203 | }
|
|---|
| 204 |
|
|---|
| 205 | glViewport(0,0,width,height); // Reset The Current Viewport
|
|---|
| 206 |
|
|---|
| 207 | glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
|
|---|
| 208 | glLoadIdentity(); // Reset The Projection Matrix
|
|---|
| 209 |
|
|---|
| 210 | // Calculate The Aspect Ratio Of The Window
|
|---|
| 211 | gluPerspective(45.0f,(GLfloat)width/(GLfloat)height,0.1f,100.0f);
|
|---|
| 212 |
|
|---|
| 213 | glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
|
|---|
| 214 | glLoadIdentity(); // Reset The Modelview Matrix
|
|---|
| 215 |
|
|---|
| 216 | }
|
|---|
| 217 | #else
|
|---|
| 218 | void G4OpenGLImmediateQtViewer::resizeGL(
|
|---|
| 219 | int aWidth
|
|---|
| 220 | ,int aHeight)
|
|---|
| 221 | {
|
|---|
| 222 | ResizeWindow(aWidth,aHeight);
|
|---|
| 223 | fHasToRepaint = sizeHasChanged();
|
|---|
| 224 | }
|
|---|
| 225 | #endif
|
|---|
| 226 |
|
|---|
| 227 |
|
|---|
| 228 | #ifdef QT_STORE_46_DBG
|
|---|
| 229 | void G4OpenGLImmediateQtViewer::paintGL()
|
|---|
| 230 | {
|
|---|
| 231 | #ifdef G4DEBUG_VIS_OGL
|
|---|
| 232 | printf("G4OpenGLImmediateQtViewer::paintGL\n");
|
|---|
| 233 | #endif
|
|---|
| 234 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
|---|
| 235 | glMatrixMode(GL_MODELVIEW);
|
|---|
| 236 | glLoadIdentity();
|
|---|
| 237 | gluLookAt(1,1,1,0,0,0,0,0,1);
|
|---|
| 238 |
|
|---|
| 239 | glBegin(GL_QUADS);
|
|---|
| 240 | //carré rouge
|
|---|
| 241 | glColor3ub(255,0,0);
|
|---|
| 242 | glVertex3d(1,1,0);
|
|---|
| 243 | glVertex3d(1,0,0);
|
|---|
| 244 | glVertex3d(0,0,0);
|
|---|
| 245 | glVertex3d(0,1,0);
|
|---|
| 246 | //carré vert
|
|---|
| 247 | glColor3ub(0,255,0);
|
|---|
| 248 | glVertex3d(1,1,0);
|
|---|
| 249 | glVertex3d(2,1,0);
|
|---|
| 250 | glVertex3d(2,0,0);
|
|---|
| 251 | glVertex3d(1,0,0);
|
|---|
| 252 | //carré vert
|
|---|
| 253 | glColor3ub(0,255,0);
|
|---|
| 254 | glVertex3d(0,2,0);
|
|---|
| 255 | glVertex3d(1,2,0);
|
|---|
| 256 | glVertex3d(1,1,0);
|
|---|
| 257 | glVertex3d(0,1,0);
|
|---|
| 258 | //carré bleu
|
|---|
| 259 | glColor3ub(0,0,255);
|
|---|
| 260 | glVertex3d(2,2,0);
|
|---|
| 261 | glVertex3d(2,1,0);
|
|---|
| 262 | glVertex3d(1,1,0);
|
|---|
| 263 | glVertex3d(1,2,0);
|
|---|
| 264 | //carré bleu
|
|---|
| 265 | glColor3ub(0,0,255);
|
|---|
| 266 | glVertex3d(1,0,0);
|
|---|
| 267 | glVertex3d(1,1,0);
|
|---|
| 268 | glVertex3d(1,1,1);
|
|---|
| 269 | glVertex3d(1,0,1);
|
|---|
| 270 | //carré blanc
|
|---|
| 271 | glColor3ub(255,255,255);
|
|---|
| 272 | glVertex3d(1,1,0);
|
|---|
| 273 | glVertex3d(0,1,0);
|
|---|
| 274 | glVertex3d(0,1,1);
|
|---|
| 275 | glVertex3d(1,1,1);
|
|---|
| 276 | //carré rouge
|
|---|
| 277 | glColor3ub(255,0,0);
|
|---|
| 278 | glVertex3d(1,1,1);
|
|---|
| 279 | glVertex3d(1,0,1);
|
|---|
| 280 | glVertex3d(0,0,1);
|
|---|
| 281 | glVertex3d(0,1,1);
|
|---|
| 282 | glEnd();
|
|---|
| 283 | }
|
|---|
| 284 |
|
|---|
| 285 | #else
|
|---|
| 286 | void G4OpenGLImmediateQtViewer::paintGL()
|
|---|
| 287 | {
|
|---|
| 288 | #ifdef G4DEBUG_VIS_OGL
|
|---|
| 289 | printf("\n\nG4OpenGLImmediateQtViewer::paintGL ??\n");
|
|---|
| 290 | #endif
|
|---|
| 291 | if (!fReadyToPaint) {
|
|---|
| 292 | fReadyToPaint= true;
|
|---|
| 293 | return;
|
|---|
| 294 | }
|
|---|
| 295 | // DO NOT RESIZE IF SIZE HAS NOT CHANGE
|
|---|
| 296 | if ( !fHasToRepaint) {
|
|---|
| 297 | if (((getWinWidth() == (unsigned int)width())) &&(getWinHeight() == (unsigned int) height())) {
|
|---|
| 298 | return;
|
|---|
| 299 | }
|
|---|
| 300 | }
|
|---|
| 301 | #ifdef G4DEBUG_VIS_OGL
|
|---|
| 302 | printf("G4OpenGLImmediateQtViewer::paintGL VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV ready %d\n",fReadyToPaint);
|
|---|
| 303 | #endif
|
|---|
| 304 |
|
|---|
| 305 | SetView();
|
|---|
| 306 |
|
|---|
| 307 | ClearView (); //ok, put the background correct
|
|---|
| 308 | ComputeView();
|
|---|
| 309 |
|
|---|
| 310 | fHasToRepaint = false; // could be set to false by ComputeView
|
|---|
| 311 |
|
|---|
| 312 | #ifdef G4DEBUG_VIS_OGL
|
|---|
| 313 | printf("G4OpenGLImmediateQtViewer::paintGL ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ready %d\n\n\n",fReadyToPaint);
|
|---|
| 314 | #endif
|
|---|
| 315 | }
|
|---|
| 316 | #endif
|
|---|
| 317 |
|
|---|
| 318 |
|
|---|
| 319 | void G4OpenGLImmediateQtViewer::mousePressEvent(QMouseEvent *event)
|
|---|
| 320 | {
|
|---|
| 321 | G4MousePressEvent(event);
|
|---|
| 322 | }
|
|---|
| 323 |
|
|---|
| 324 | void G4OpenGLImmediateQtViewer::keyPressEvent (QKeyEvent * event)
|
|---|
| 325 | {
|
|---|
| 326 | G4keyPressEvent(event);
|
|---|
| 327 | }
|
|---|
| 328 |
|
|---|
| 329 | void G4OpenGLImmediateQtViewer::wheelEvent (QWheelEvent * event)
|
|---|
| 330 | {
|
|---|
| 331 | G4wheelEvent(event);
|
|---|
| 332 | }
|
|---|
| 333 |
|
|---|
| 334 | /**
|
|---|
| 335 | * This function was build in order to make a zoom on double clic event.
|
|---|
| 336 | * It was think to build a rubberband on the zoom area, but never work fine
|
|---|
| 337 | */
|
|---|
| 338 | void G4OpenGLImmediateQtViewer::mouseDoubleClickEvent(QMouseEvent *)
|
|---|
| 339 | {
|
|---|
| 340 | G4MouseDoubleClickEvent();
|
|---|
| 341 | }
|
|---|
| 342 |
|
|---|
| 343 | void G4OpenGLImmediateQtViewer::mouseReleaseEvent(QMouseEvent *)
|
|---|
| 344 | {
|
|---|
| 345 | G4MouseReleaseEvent();
|
|---|
| 346 | }
|
|---|
| 347 |
|
|---|
| 348 | void G4OpenGLImmediateQtViewer::mouseMoveEvent(QMouseEvent *event)
|
|---|
| 349 | {
|
|---|
| 350 | G4MouseMoveEvent(event);
|
|---|
| 351 | }
|
|---|
| 352 |
|
|---|
| 353 |
|
|---|
| 354 | void G4OpenGLImmediateQtViewer::contextMenuEvent(QContextMenuEvent *e)
|
|---|
| 355 | {
|
|---|
| 356 | G4manageContextMenuEvent(e);
|
|---|
| 357 | }
|
|---|
| 358 |
|
|---|
| 359 | void G4OpenGLImmediateQtViewer::updateQWidget() {
|
|---|
| 360 | fHasToRepaint= true;
|
|---|
| 361 | updateGL();
|
|---|
| 362 | fHasToRepaint= false;
|
|---|
| 363 | }
|
|---|
| 364 |
|
|---|
| 365 |
|
|---|
| 366 | void G4OpenGLImmediateQtViewer::ShowView (
|
|---|
| 367 | )
|
|---|
| 368 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 369 | //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
|
|---|
| 370 | {
|
|---|
| 371 | #if QT_VERSION < 0x040000
|
|---|
| 372 | setActiveWindow();
|
|---|
| 373 | #else
|
|---|
| 374 | activateWindow();
|
|---|
| 375 | #endif
|
|---|
| 376 | }
|
|---|
| 377 | #endif
|
|---|