| 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: G4OpenGLStoredQtViewer.cc,v 1.3 2007/11/09 15:03:22 lgarnier Exp $
|
|---|
| 28 | // GEANT4 tag $Name: $
|
|---|
| 29 | //
|
|---|
| 30 | //
|
|---|
| 31 | // Class G4OpenGLStoredQtViewer : a class derived from G4OpenGLQtViewer and
|
|---|
| 32 | // G4OpenGLStoredViewer.
|
|---|
| 33 |
|
|---|
| 34 | #ifdef G4VIS_BUILD_OPENGLQT_DRIVER
|
|---|
| 35 |
|
|---|
| 36 | #include "G4OpenGLStoredQtViewer.hh"
|
|---|
| 37 | #include "G4VisManager.hh"
|
|---|
| 38 |
|
|---|
| 39 | #include "G4ios.hh"
|
|---|
| 40 |
|
|---|
| 41 | //#include <qmouseevent.h>
|
|---|
| 42 | #include <qevent.h> // include <qcontextmenuevent.h>
|
|---|
| 43 |
|
|---|
| 44 | G4OpenGLStoredQtViewer::G4OpenGLStoredQtViewer
|
|---|
| 45 | (G4OpenGLStoredSceneHandler& sceneHandler,
|
|---|
| 46 | const G4String& name):
|
|---|
| 47 | G4VViewer (sceneHandler, sceneHandler.IncrementViewCount (), name),
|
|---|
| 48 | G4OpenGLViewer (sceneHandler),
|
|---|
| 49 | G4OpenGLQtViewer (sceneHandler),
|
|---|
| 50 | G4OpenGLStoredViewer (sceneHandler),
|
|---|
| 51 | QGLWidget() // FIXME : gerer le pb du parent !
|
|---|
| 52 | {
|
|---|
| 53 | nbPaint =0;
|
|---|
| 54 | hasToRepaint =false;
|
|---|
| 55 | if (fViewId < 0) return; // In case error in base class instantiation.
|
|---|
| 56 | }
|
|---|
| 57 |
|
|---|
| 58 | G4OpenGLStoredQtViewer::~G4OpenGLStoredQtViewer() {
|
|---|
| 59 | printf("GLWidget::~GLWidget \n");
|
|---|
| 60 | makeCurrent();
|
|---|
| 61 | // this is connect to the Dialog for deleting it properly
|
|---|
| 62 | // when close event.
|
|---|
| 63 | // ((QDialog*)window())->reject();
|
|---|
| 64 | printf("GLWidget::~GLWidget END\n");
|
|---|
| 65 | }
|
|---|
| 66 |
|
|---|
| 67 | void G4OpenGLStoredQtViewer::Initialise() {
|
|---|
| 68 | printf("GLWidget::Initialise \n");
|
|---|
| 69 | readyToPaint = false;
|
|---|
| 70 | CreateGLQtContext ();
|
|---|
| 71 | printf("G4OpenGLStoredQtViewer::Initialise () 2\n");
|
|---|
| 72 |
|
|---|
| 73 | CreateMainWindow (this);
|
|---|
| 74 | printf("G4OpenGLStoredQtViewer::Initialise () 3\n");
|
|---|
| 75 |
|
|---|
| 76 | CreateFontLists (); // FIXME Does nothing!
|
|---|
| 77 |
|
|---|
| 78 | printf("readyToPaint = true \n");
|
|---|
| 79 | readyToPaint = true;
|
|---|
| 80 |
|
|---|
| 81 | // First Draw
|
|---|
| 82 | SetView();
|
|---|
| 83 | printf(" ClearView\n");
|
|---|
| 84 | ClearView (); //ok, put the background correct
|
|---|
| 85 | ShowView();
|
|---|
| 86 | FinishView();
|
|---|
| 87 | }
|
|---|
| 88 |
|
|---|
| 89 | void G4OpenGLStoredQtViewer::initializeGL () {
|
|---|
| 90 |
|
|---|
| 91 | InitializeGLView ();
|
|---|
| 92 |
|
|---|
| 93 | printf("G4OpenGLStoredQtViewer::InitialiseGL () 1\n");
|
|---|
| 94 |
|
|---|
| 95 | // clear the buffers and window.
|
|---|
| 96 | ClearView ();
|
|---|
| 97 | // printf("G4OpenGLStoredQtViewer::InitialiseGL () 2\n");
|
|---|
| 98 | FinishView ();
|
|---|
| 99 |
|
|---|
| 100 | glDepthFunc (GL_LEQUAL);
|
|---|
| 101 | glDepthMask (GL_TRUE);
|
|---|
| 102 |
|
|---|
| 103 | hasToRepaint =true;
|
|---|
| 104 |
|
|---|
| 105 | printf("G4OpenGLStoredQtViewer::InitialiseGL -------------------------------------------------------------------------------------\n");
|
|---|
| 106 | }
|
|---|
| 107 |
|
|---|
| 108 |
|
|---|
| 109 | void G4OpenGLStoredQtViewer::DrawView () {
|
|---|
| 110 |
|
|---|
| 111 | printf("G4OpenGLStoredQtViewer::DrawView %d %d VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV\n",WinSize_x, WinSize_y);
|
|---|
| 112 | printf("G4OpenGLStoredQtViewer::DrawView Dialog adress : %d\n",GLWindow);
|
|---|
| 113 | G4ViewParameters::DrawingStyle style = GetViewParameters().GetDrawingStyle();
|
|---|
| 114 |
|
|---|
| 115 | //Make sure current viewer is attached and clean...
|
|---|
| 116 | //Qt version needed
|
|---|
| 117 | glViewport (0, 0, WinSize_x, WinSize_y);
|
|---|
| 118 |
|
|---|
| 119 | //See if things have changed from last time and remake if necessary...
|
|---|
| 120 | // The fNeedKernelVisit flag might have been set by the user in
|
|---|
| 121 | // /vis/viewer/rebuild, but if not, make decision and set flag only
|
|---|
| 122 | // if necessary...
|
|---|
| 123 | if (!fNeedKernelVisit)
|
|---|
| 124 |
|
|---|
| 125 | if (!fNeedKernelVisit) KernelVisitDecision ();
|
|---|
| 126 |
|
|---|
| 127 | G4bool kernelVisitWasNeeded = fNeedKernelVisit; // Keep (ProcessView resets).
|
|---|
| 128 | ProcessView ();
|
|---|
| 129 |
|
|---|
| 130 |
|
|---|
| 131 | if(style!=G4ViewParameters::hlr &&
|
|---|
| 132 | haloing_enabled) {
|
|---|
| 133 | printf("G4OpenGLStoredQtViewer::DrawView DANS LE IF\n");
|
|---|
| 134 |
|
|---|
| 135 | HaloingFirstPass ();
|
|---|
| 136 | DrawDisplayLists ();
|
|---|
| 137 | glFlush ();
|
|---|
| 138 |
|
|---|
| 139 | HaloingSecondPass ();
|
|---|
| 140 |
|
|---|
| 141 | DrawDisplayLists ();
|
|---|
| 142 | FinishView ();
|
|---|
| 143 |
|
|---|
| 144 | } else {
|
|---|
| 145 | printf("*************************** CASE 1 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \n");
|
|---|
| 146 |
|
|---|
| 147 | // If kernel visit was needed, drawing and FinishView will already
|
|---|
| 148 | // have been done, so...
|
|---|
| 149 | if (!kernelVisitWasNeeded) {
|
|---|
| 150 | printf("*************************** CASE 2 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \n");
|
|---|
| 151 | DrawDisplayLists ();
|
|---|
| 152 | FinishView ();
|
|---|
| 153 | } else {
|
|---|
| 154 | printf("*************************** CASE 3 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \n");
|
|---|
| 155 | // However, union cutaways are implemented in DrawDisplayLists, so make
|
|---|
| 156 | // an extra pass...
|
|---|
| 157 | if (fVP.IsCutaway() &&
|
|---|
| 158 | fVP.GetCutawayMode() == G4ViewParameters::cutawayUnion) {
|
|---|
| 159 | ClearView();
|
|---|
| 160 | DrawDisplayLists ();
|
|---|
| 161 | FinishView ();
|
|---|
| 162 | printf("*************************** CASE 4 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \n");
|
|---|
| 163 | } else { // ADD TO AVOID KernelVisit=1 and nothing to display
|
|---|
| 164 | DrawDisplayLists ();
|
|---|
| 165 | FinishView ();
|
|---|
| 166 | }
|
|---|
| 167 | }
|
|---|
| 168 | }
|
|---|
| 169 |
|
|---|
| 170 | printf("G4OpenGLStoredQtViewer::DrawView %d %d ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \n",WinSize_x, WinSize_y);
|
|---|
| 171 | hasToRepaint =true;
|
|---|
| 172 | }
|
|---|
| 173 |
|
|---|
| 174 |
|
|---|
| 175 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 176 | void G4OpenGLStoredQtViewer::FinishView (
|
|---|
| 177 | )
|
|---|
| 178 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 179 | //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
|
|---|
| 180 | {
|
|---|
| 181 | printf("G4OpenGLStoredQtViewer::FinishView VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV\n");
|
|---|
| 182 |
|
|---|
| 183 | glFlush ();
|
|---|
| 184 | swapBuffers ();
|
|---|
| 185 | printf("G4OpenGLStoredQtViewer::FinishView ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \n");
|
|---|
| 186 |
|
|---|
| 187 | }
|
|---|
| 188 |
|
|---|
| 189 |
|
|---|
| 190 | /**
|
|---|
| 191 | - Lors du resize de la fenetre, on doit non pas redessiner le detecteur, mais aussi les evenements
|
|---|
| 192 | */
|
|---|
| 193 | void G4OpenGLStoredQtViewer::resizeGL(
|
|---|
| 194 | int aWidth
|
|---|
| 195 | ,int aHeight)
|
|---|
| 196 | {
|
|---|
| 197 | glViewport(0, 0, aWidth, aHeight);
|
|---|
| 198 | glMatrixMode(GL_PROJECTION);
|
|---|
| 199 | glMatrixMode(GL_MODELVIEW);
|
|---|
| 200 |
|
|---|
| 201 | if (((WinSize_x != (G4int)aWidth)) || (WinSize_y != (G4int) aHeight)) {
|
|---|
| 202 | hasToRepaint =true;
|
|---|
| 203 | }
|
|---|
| 204 | WinSize_x = (G4int) aWidth;
|
|---|
| 205 | WinSize_y = (G4int) aHeight;
|
|---|
| 206 |
|
|---|
| 207 | printf("G4OpenGLStoredQtViewer::resizeGL ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ %d %d=%d %d=%d\n",hasToRepaint,width(),aWidth,height(),aHeight);
|
|---|
| 208 | }
|
|---|
| 209 |
|
|---|
| 210 |
|
|---|
| 211 |
|
|---|
| 212 | void G4OpenGLStoredQtViewer::paintGL()
|
|---|
| 213 | {
|
|---|
| 214 | if (!readyToPaint) {
|
|---|
| 215 | printf("G4OpenGLStoredQtViewer::paintGL ============ Not ready %d\n",readyToPaint);
|
|---|
| 216 | readyToPaint= true;
|
|---|
| 217 | return;
|
|---|
| 218 | }
|
|---|
| 219 | // DO NOT RESIZE IF SIZE HAS NOT CHANGE :
|
|---|
| 220 | // WHEN CLICK ON THE FRAME FOR EXAMPLE
|
|---|
| 221 | // EXECEPT WHEN MOUSE MOVE EVENT
|
|---|
| 222 | if ( !hasToRepaint) {
|
|---|
| 223 | if (((WinSize_x == (G4int)width())) &&(WinSize_y == (G4int) height())) {
|
|---|
| 224 | printf("G4OpenGLStoredQtViewer::paintGL ============ Dont repaint\n");
|
|---|
| 225 | return;
|
|---|
| 226 | }
|
|---|
| 227 | }
|
|---|
| 228 | nbPaint++;
|
|---|
| 229 | printf("G4OpenGLStoredQtViewer::paintGL VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV %d ready %d\n",nbPaint,readyToPaint);
|
|---|
| 230 | WinSize_x = (G4int) width();
|
|---|
| 231 | WinSize_y = (G4int) height();
|
|---|
| 232 |
|
|---|
| 233 | glViewport (0, 0, width(), height());
|
|---|
| 234 | // glLoadIdentity();
|
|---|
| 235 |
|
|---|
| 236 |
|
|---|
| 237 | SetView();
|
|---|
| 238 |
|
|---|
| 239 | // // printf("before ClearView\n");
|
|---|
| 240 | printf(" ClearView\n");
|
|---|
| 241 |
|
|---|
| 242 | ClearView (); //ok, put the background correct
|
|---|
| 243 | DrawView();
|
|---|
| 244 |
|
|---|
| 245 | hasToRepaint =false;
|
|---|
| 246 |
|
|---|
| 247 | printf("G4OpenGLStoredQtViewer::paintGL ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ %d ready %d\n",nbPaint,readyToPaint);
|
|---|
| 248 | }
|
|---|
| 249 |
|
|---|
| 250 | void G4OpenGLStoredQtViewer::mousePressEvent(QMouseEvent *event)
|
|---|
| 251 | {
|
|---|
| 252 | printf("G4OpenGLStoredQtViewer::mousePressEvent\n");
|
|---|
| 253 | G4MousePressEvent(event->pos());
|
|---|
| 254 | }
|
|---|
| 255 |
|
|---|
| 256 | void G4OpenGLStoredQtViewer::mouseMoveEvent(QMouseEvent *event)
|
|---|
| 257 | {
|
|---|
| 258 | G4MouseMoveEvent(event->x(),event->y(),event->button());
|
|---|
| 259 | // DrawView();
|
|---|
| 260 | }
|
|---|
| 261 |
|
|---|
| 262 |
|
|---|
| 263 | void G4OpenGLStoredQtViewer::contextMenuEvent(QContextMenuEvent *e)
|
|---|
| 264 | {
|
|---|
| 265 | manageContextMenuEvent(e);
|
|---|
| 266 | }
|
|---|
| 267 |
|
|---|
| 268 | void G4OpenGLStoredQtViewer::updateQWidget() {
|
|---|
| 269 | hasToRepaint= true;
|
|---|
| 270 | updateGL();
|
|---|
| 271 | hasToRepaint= false;
|
|---|
| 272 | }
|
|---|
| 273 |
|
|---|
| 274 | #endif
|
|---|