Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer 3 // * License and Disclaimer * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th 5 // * The Geant4 software is copyright of the Copyright Holders of * 6 // * the Geant4 Collaboration. It is provided 6 // * the Geant4 Collaboration. It is provided under the terms and * 7 // * conditions of the Geant4 Software License 7 // * conditions of the Geant4 Software License, included in the file * 8 // * LICENSE and available at http://cern.ch/ 8 // * LICENSE and available at http://cern.ch/geant4/license . These * 9 // * include a list of copyright holders. 9 // * include a list of copyright holders. * 10 // * 10 // * * 11 // * Neither the authors of this software syst 11 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 12 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 13 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 14 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file 15 // * use. Please see the license in the file LICENSE and URL above * 16 // * for the full disclaimer and the limitatio 16 // * for the full disclaimer and the limitation of liability. * 17 // * 17 // * * 18 // * This code implementation is the result 18 // * This code implementation is the result of the scientific and * 19 // * technical work of the GEANT4 collaboratio 19 // * technical work of the GEANT4 collaboration. * 20 // * By using, copying, modifying or distri 20 // * By using, copying, modifying or distributing the software (or * 21 // * any work based on the software) you ag 21 // * any work based on the software) you agree to acknowledge its * 22 // * use in resulting scientific publicati 22 // * use in resulting scientific publications, and indicate your * 23 // * acceptance of all terms of the Geant4 Sof 23 // * acceptance of all terms of the Geant4 Software license. * 24 // ******************************************* 24 // ******************************************************************** 25 // 25 // 26 // 26 // >> 27 // $Id: G4OpenGLImmediateQtViewer.cc,v 1.3 2007/11/15 18:24:28 lgarnier Exp $ >> 28 // GEANT4 tag $Name: geant4-09-01-patch-02 $ 27 // 29 // 28 // 30 // 29 // Class G4OpenGLImmediateQtViewer : a class d 31 // Class G4OpenGLImmediateQtViewer : a class derived from G4OpenGLQtViewer and 30 // G4OpenGLImme 32 // G4OpenGLImmediateViewer. 31 33 >> 34 #ifdef G4VIS_BUILD_OPENGLQT_DRIVER >> 35 32 #include "G4OpenGLImmediateQtViewer.hh" 36 #include "G4OpenGLImmediateQtViewer.hh" 33 #include "G4OpenGLImmediateSceneHandler.hh" << 37 #include "G4VisManager.hh" 34 38 35 #include "G4ios.hh" 39 #include "G4ios.hh" 36 #include "G4Threading.hh" << 37 #include <qapplication.h> << 38 #include <qtabwidget.h> << 39 #if 0x060000 <= QT_VERSION << 40 #include "G4Qt.hh" << 41 #endif << 42 40 43 G4OpenGLImmediateQtViewer::G4OpenGLImmediateQt 41 G4OpenGLImmediateQtViewer::G4OpenGLImmediateQtViewer 44 (G4OpenGLImmediateSceneHandler& sceneHandler, 42 (G4OpenGLImmediateSceneHandler& sceneHandler, 45 const G4String& name): 43 const G4String& name): 46 G4VViewer (sceneHandler, sceneHandler.Increm << 44 G4VViewer (sceneHandler, sceneHandler.IncrementViewCount (), name), 47 G4OpenGLViewer (sceneHandler), << 45 G4OpenGLViewer (sceneHandler), 48 G4OpenGLQtViewer (sceneHandler), << 46 G4OpenGLQtViewer (sceneHandler), 49 G4OpenGLImmediateViewer (sceneHandler) << 47 G4OpenGLImmediateViewer (sceneHandler), 50 { << 48 QGLWidget() // FIXME : gerer le pb du parent ! 51 #if QT_VERSION < 0x060000 << 49 { 52 fQGLWidgetInitialiseCompleted = false; << 50 nbPaint =0; 53 << 54 setFocusPolicy(Qt::StrongFocus); // enable k << 55 fHasToRepaint = false; << 56 fPaintEventLock = false; << 57 fUpdateGLLock = false; << 58 << 59 if (fViewId < 0) return; // In case error i 51 if (fViewId < 0) return; // In case error in base class instantiation. 60 #else << 61 setFocusPolicy(Qt::StrongFocus); // enable k << 62 #endif << 63 } 52 } 64 53 65 G4OpenGLImmediateQtViewer::~G4OpenGLImmediateQ << 54 G4OpenGLImmediateQtViewer::~G4OpenGLImmediateQtViewer() { 66 << 55 #ifdef GEANT4_QT_DEBUG 67 void G4OpenGLImmediateQtViewer::Initialise() { << 56 printf("GLWidget::~GLWidget \n"); 68 #if QT_VERSION < 0x060000 << 57 #endif 69 << 58 makeCurrent(); 70 fQGLWidgetInitialiseCompleted = false; << 59 #ifdef GEANT4_QT_DEBUG 71 CreateMainWindow (this,QString(GetName())); << 60 printf("GLWidget::~GLWidget END\n"); 72 << 73 makeCurrent(); << 74 glDrawBuffer (GL_BACK); << 75 << 76 // set the good tab active << 77 if (G4QGLWidgetType::parentWidget()) { << 78 auto *parentTab = dynamic_cast<QTabWidget* << 79 if (parentTab) { << 80 parentTab->setCurrentIndex(parentTab->co << 81 } << 82 } << 83 << 84 fQGLWidgetInitialiseCompleted = true; << 85 #else << 86 CreateMainWindow (this,QString(GetName())); << 87 // Set jpg as default export format for Qt v << 88 setExportImageFormat("jpg"); << 89 #endif 61 #endif 90 } 62 } 91 63 92 #if QT_VERSION < 0x060000 << 64 void G4OpenGLImmediateQtViewer::Initialise() { 93 void G4OpenGLImmediateQtViewer::initializeGL ( << 65 #ifdef GEANT4_QT_DEBUG 94 << 66 printf("GLWidget::Initialise \n"); 95 InitializeGLView (); << 67 #endif >> 68 #ifdef GEANT4_QT_DEBUG >> 69 printf("readyToPaint = false \n"); >> 70 #endif >> 71 readyToPaint = false; >> 72 CreateGLQtContext (); >> 73 #ifdef GEANT4_QT_DEBUG >> 74 printf("G4OpenGLImmediateQtViewer::Initialise () 2\n"); >> 75 #endif 96 76 97 // If a double buffer context has been force << 77 CreateMainWindow (this); 98 // back buffer for this OpenGLImmediate view << 78 #ifdef GEANT4_QT_DEBUG 99 // glDrawBuffer (GL_FRONT); // FIXME : Ne m << 79 printf("G4OpenGLImmediateQtViewer::Initialise () 3\n"); 100 << 80 #endif 101 if (fSceneHandler.GetScene() == 0) { << 102 fHasToRepaint =false; << 103 } else { << 104 fHasToRepaint =true; << 105 } << 106 81 107 // Set the component visible << 82 CreateFontLists (); // FIXME Does nothing! 108 83 109 // and update it immediatly before wait for << 84 #ifdef GEANT4_QT_DEBUG 110 // QCoreApplication::sendPostedEvents () ; << 85 printf("readyToPaint = true \n"); 111 << 112 // Set jpg as default export format for Qt v << 113 setExportImageFormat("jpg"); << 114 } << 115 #endif 86 #endif 116 << 87 readyToPaint = true; 117 << 88 118 void G4OpenGLImmediateQtViewer::DrawView() { << 89 // First Draw 119 #if QT_VERSION < 0x060000 << 90 SetView(); 120 #else << 91 #ifdef GEANT4_QT_DEBUG 121 if(IsGettingPickInfos()) { << 92 printf(" ClearView\n"); 122 paintGL(); << 123 return; << 124 } << 125 #endif 93 #endif 126 if (G4Threading::IsMasterThread()) { << 94 ClearView (); //ok, put the background correct 127 updateQWidget(); << 95 ShowView(); 128 } << 96 FinishView(); 129 } 97 } 130 98 >> 99 void G4OpenGLImmediateQtViewer::initializeGL () { 131 100 132 void G4OpenGLImmediateQtViewer::ComputeView () << 101 InitializeGLView (); 133 102 134 #if QT_VERSION < 0x060000 << 103 #ifdef GEANT4_QT_DEBUG 135 makeCurrent(); << 104 printf("G4OpenGLImmediateQtViewer::InitialiseGL () 1\n"); 136 // If a double buffer context has been force << 137 // back buffer for this OpenGLImmediate view << 138 // glDrawBuffer (GL_FRONT); << 139 #endif 105 #endif 140 106 141 G4ViewParameters::DrawingStyle dstyle = GetV << 107 // If a double buffer context has been forced upon us, ignore the 142 << 108 // back buffer for this OpenGLImmediate view. 143 if(dstyle!=G4ViewParameters::hlr && << 109 glDrawBuffer (GL_FRONT); // FIXME : Ne marche pas avec cette ligne, mais affiche le run correctement... 144 haloing_enabled) { << 110 // clear the buffers and window. 145 << 111 ClearView (); 146 HaloingFirstPass (); << 112 #ifdef GEANT4_QT_DEBUG 147 NeedKernelVisit (); << 113 // printf("G4OpenGLImmediateQtViewer::InitialiseGL () 2\n"); 148 ProcessView (); << 114 #endif 149 FinishView(); << 115 FinishView (); 150 HaloingSecondPass (); << 116 151 117 152 } << 153 118 154 NeedKernelVisit (); // Always need to visit << 119 glDepthFunc (GL_LEQUAL); 155 ProcessView (); << 120 glDepthMask (GL_TRUE); 156 121 157 if (isRecording()) { << 122 #ifdef GEANT4_QT_DEBUG 158 savePPMToTemp(); << 123 printf("G4OpenGLImmediateQtViewer::InitialiseGL -------------------------------------------------------------------------------------\n"); 159 } << 160 << 161 #if QT_VERSION < 0x060000 << 162 fHasToRepaint = true; << 163 #endif 124 #endif 164 } 125 } 165 126 166 /** << 167 - Lors du resize de la fenetre, on doit non << 168 */ << 169 void G4OpenGLImmediateQtViewer::resizeGL( << 170 int aWidth << 171 ,int aHeight) << 172 { << 173 if ((aWidth > 0) && (aHeight > 0)) { << 174 #if QT_VERSION < 0x060000 << 175 ResizeWindow(aWidth,aHeight); << 176 fHasToRepaint = sizeHasChanged(); << 177 #else << 178 ResizeWindow(devicePixelRatio()*aWidth,dev << 179 #endif << 180 } << 181 } << 182 127 >> 128 void G4OpenGLImmediateQtViewer::DrawView () { 183 129 184 void G4OpenGLImmediateQtViewer::paintGL() << 130 #ifdef GEANT4_QT_DEBUG 185 { << 131 printf("G4OpenGLImmediateQtViewer::DrawView %d %d VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV\n",WinSize_x, WinSize_y); 186 #if QT_VERSION < 0x060000 << 187 updateToolbarAndMouseContextMenu(); << 188 #else << 189 //G.Barrand: don't do any change in the GUI << 190 #endif 132 #endif >> 133 // If a double buffer context has been forced upon us, ignore the >> 134 // back buffer for this OpenGLImmediate view. >> 135 glDrawBuffer (GL_FRONT); 191 136 192 #if QT_VERSION < 0x060000 << 137 G4ViewParameters::DrawingStyle style = GetViewParameters().GetDrawingStyle(); 193 if (fPaintEventLock) { << 194 // return ; << 195 } << 196 if (!fQGLWidgetInitialiseCompleted) { << 197 fPaintEventLock = false; << 198 return; << 199 } << 200 if ((getWinWidth() == 0) && (getWinHeight() << 201 return; << 202 } << 203 138 204 // DO NOT RESIZE IF SIZE HAS NOT CHANGE << 139 //Make sure current viewer is attached and clean... 205 if ( !fHasToRepaint) { << 140 //Qt version needed 206 // L. Garnier : Trap to get the size with << 141 glViewport (0, 0, WinSize_x, WinSize_y); 207 // Tested on Qt4.5 on mac, 4.4 on windows, << 208 int sw = 0; << 209 int sh = 0; << 210 if (!isMaximized() && !isFullScreen()) { << 211 sw = normalGeometry().width(); << 212 sh = normalGeometry().height(); << 213 } else { << 214 sw = frameGeometry().width(); << 215 sh = frameGeometry().height(); << 216 } << 217 if ((getWinWidth() == (unsigned int)sw) && << 218 return; << 219 << 220 } else if ((sw == 0) && (sh == 0)) { // NO << 221 if (((getWinWidth() == (unsigned int)wid << 222 return; << 223 } << 224 } << 225 } << 226 #else << 227 if ((getWinWidth() == 0) && (getWinHeight() << 228 #endif << 229 142 230 #if QT_VERSION < 0x060000 << 143 if(style!=G4ViewParameters::hlr && 231 #else << 144 haloing_enabled) { 232 InitializeGLView (); << 145 #ifdef GEANT4_QT_DEBUG 233 glDrawBuffer (GL_BACK); << 146 printf("G4OpenGLImmediateQtViewer::DrawView DANS LE IF\n"); 234 #endif 147 #endif 235 148 236 SetView(); << 149 HaloingFirstPass (); 237 << 150 NeedKernelVisit (); 238 ClearView (); //ok, put the background corre << 151 ProcessView (); 239 ComputeView(); << 152 glFlush (); 240 153 241 #if QT_VERSION < 0x060000 << 154 HaloingSecondPass (); 242 fHasToRepaint = false; // could be set to fa << 243 155 244 fPaintEventLock = false; << 156 } >> 157 >> 158 NeedKernelVisit (); // Always need to visit G4 kernel. >> 159 ProcessView (); >> 160 FinishView (); >> 161 #ifdef GEANT4_QT_DEBUG >> 162 printf("G4OpenGLImmediateQtViewer::DrawView %d %d ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \n",WinSize_x, WinSize_y); 245 #endif 163 #endif >> 164 readyToPaint = false; 246 } 165 } 247 166 248 void G4OpenGLImmediateQtViewer::mousePressEven << 249 { << 250 G4MousePressEvent(event); << 251 } << 252 167 253 void G4OpenGLImmediateQtViewer::keyPressEvent << 168 ////////////////////////////////////////////////////////////////////////////// >> 169 void G4OpenGLImmediateQtViewer::FinishView ( >> 170 ) >> 171 ////////////////////////////////////////////////////////////////////////////// >> 172 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// 254 { 173 { 255 G4keyPressEvent(event); << 174 #ifdef GEANT4_QT_DEBUG 256 } << 175 printf("G4OpenGLImmediateQtViewer::FinishView VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV\n"); >> 176 #endif 257 177 258 void G4OpenGLImmediateQtViewer::keyReleaseEven << 178 glFlush (); 259 { << 179 #ifdef GEANT4_QT_DEBUG 260 G4keyReleaseEvent(event); << 180 printf("G4OpenGLImmediateQtViewer::FinishView ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \n"); 261 } << 181 #endif 262 182 263 void G4OpenGLImmediateQtViewer::wheelEvent (QW << 264 { << 265 G4wheelEvent(event); << 266 } 183 } 267 184 268 #if QT_VERSION < 0x060000 << 269 void G4OpenGLImmediateQtViewer::showEvent (QSh << 270 { << 271 if (fQGLWidgetInitialiseCompleted) { << 272 fHasToRepaint = true; << 273 } << 274 } << 275 #endif << 276 185 277 /** 186 /** 278 * This function was build in order to make a << 187 - Lors du resize de la fenetre, on doit non pas redessiner le detecteur, mais aussi les evenements 279 * It was think to build a rubberband on the z << 280 */ 188 */ 281 void G4OpenGLImmediateQtViewer::mouseDoubleCli << 189 void G4OpenGLImmediateQtViewer::resizeGL( 282 { << 190 int width 283 G4MouseDoubleClickEvent(); << 191 ,int height) 284 } << 192 { 285 << 193 int side = width; 286 void G4OpenGLImmediateQtViewer::mouseReleaseEv << 194 if (width > height) { 287 { << 195 side = height; 288 G4MouseReleaseEvent(event); << 196 } 289 } << 197 glViewport((width - side) / 2, (height - side) / 2, side, side); 290 << 198 glMatrixMode(GL_PROJECTION); 291 void G4OpenGLImmediateQtViewer::mouseMoveEvent << 199 glLoadIdentity(); 292 { << 200 glOrtho(-0.5, +0.5, +0.5, -0.5, 4.0, 15.0); 293 G4MouseMoveEvent(event); << 201 glMatrixMode(GL_MODELVIEW); >> 202 #ifdef GEANT4_QT_DEBUG >> 203 printf("G4OpenGLImmediateQtViewer::resizeGL ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \n"); >> 204 #endif 294 } 205 } 295 206 296 207 297 void G4OpenGLImmediateQtViewer::contextMenuEve << 208 void G4OpenGLImmediateQtViewer::paintGL() 298 { << 209 { 299 G4manageContextMenuEvent(e); << 210 if (!readyToPaint) { 300 } << 211 readyToPaint= true; 301 << 212 return; 302 #if QT_VERSION < 0x060000 << 213 } 303 void G4OpenGLImmediateQtViewer::paintEvent(QPa << 214 // DO NOT RESIZE IF SIZE HAS NOT CHANGE 304 if (! fQGLWidgetInitialiseCompleted) { << 215 if (((WinSize_x == (G4int)width())) &&(WinSize_y == (G4int) height())) { 305 return; << 216 return; 306 } << 217 } 307 // Force a repaint next time if the FRAMEBUF << 218 nbPaint++; 308 fHasToRepaint = isFramebufferReady(); << 219 #ifdef GEANT4_QT_DEBUG 309 if ( fHasToRepaint) { << 220 printf("\n\nG4OpenGLImmediateQtViewer::paintGL VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV %d ready %d\n",nbPaint,readyToPaint); 310 #if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0)) << 221 #endif 311 updateGL(); << 222 WinSize_x = (G4int) width(); 312 #else << 223 WinSize_y = (G4int) height(); 313 // Not sure this is correct.... << 224 314 paintGL(); << 225 glViewport (0, 0, width(), height()); >> 226 >> 227 SetView(); >> 228 #ifdef GEANT4_QT_DEBUG >> 229 // // printf("before ClearView\n"); 315 #endif 230 #endif 316 } << 231 #ifdef GEANT4_QT_DEBUG 317 } << 232 printf(" ClearView\n"); 318 #endif 233 #endif >> 234 >> 235 ClearView (); //ok, put the background correct >> 236 DrawView(); >> 237 readyToPaint = true; // could be set to false by DrawView 319 238 320 239 321 void G4OpenGLImmediateQtViewer::updateQWidget( << 240 #ifdef GEANT4_QT_DEBUG 322 #if QT_VERSION < 0x060000 << 241 printf("G4OpenGLImmediateQtViewer::paintGL ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ %d ready %d\n\n\n",nbPaint,readyToPaint); 323 if (fUpdateGLLock) { << 324 return; << 325 } << 326 << 327 if (! isCurrentWidget()){ << 328 return; << 329 } << 330 << 331 fUpdateGLLock = true; << 332 fHasToRepaint= true; << 333 repaint(); << 334 updateViewerPropertiesTableWidget(); << 335 updateSceneTreeWidget(); << 336 fUpdateGLLock= false; << 337 #else << 338 //if (!isCurrentWidget()) return; //G.Barran << 339 //G.Barrand: don't do any change in the GUI << 340 update(); << 341 #endif 242 #endif 342 } << 243 } 343 244 >> 245 void G4OpenGLImmediateQtViewer::updateQWidget() { >> 246 updateGL(); >> 247 } 344 248 345 void G4OpenGLImmediateQtViewer::ShowView () << 346 { << 347 #if QT_VERSION < 0x060000 << 348 fHasToRepaint = true; << 349 activateWindow(); << 350 #else << 351 activateWindow(); << 352 ((QApplication*)G4Qt::getInstance ())->proce << 353 #endif 249 #endif 354 } << 355 250