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 // 27 // 28 // 28 // 29 // Class G4OpenGLImmediateQtViewer : a class d 29 // Class G4OpenGLImmediateQtViewer : a class derived from G4OpenGLQtViewer and 30 // G4OpenGLImme 30 // G4OpenGLImmediateViewer. 31 31 >> 32 #ifdef G4VIS_BUILD_OPENGLQT_DRIVER >> 33 32 #include "G4OpenGLImmediateQtViewer.hh" 34 #include "G4OpenGLImmediateQtViewer.hh" 33 #include "G4OpenGLImmediateSceneHandler.hh" 35 #include "G4OpenGLImmediateSceneHandler.hh" 34 36 35 #include "G4ios.hh" 37 #include "G4ios.hh" >> 38 #ifdef G4MULTITHREADED 36 #include "G4Threading.hh" 39 #include "G4Threading.hh" >> 40 #endif 37 #include <qapplication.h> 41 #include <qapplication.h> 38 #include <qtabwidget.h> 42 #include <qtabwidget.h> 39 #if 0x060000 <= QT_VERSION << 43 40 #include "G4Qt.hh" << 44 #ifdef G4OPENGL_VERSION_2 >> 45 #include <qglshaderprogram.h> 41 #endif 46 #endif 42 47 >> 48 43 G4OpenGLImmediateQtViewer::G4OpenGLImmediateQt 49 G4OpenGLImmediateQtViewer::G4OpenGLImmediateQtViewer 44 (G4OpenGLImmediateSceneHandler& sceneHandler, 50 (G4OpenGLImmediateSceneHandler& sceneHandler, 45 const G4String& name): 51 const G4String& name): 46 G4VViewer (sceneHandler, sceneHandler.Increm 52 G4VViewer (sceneHandler, sceneHandler.IncrementViewCount (), name), 47 G4OpenGLViewer (sceneHandler), 53 G4OpenGLViewer (sceneHandler), 48 G4OpenGLQtViewer (sceneHandler), 54 G4OpenGLQtViewer (sceneHandler), 49 G4OpenGLImmediateViewer (sceneHandler) 55 G4OpenGLImmediateViewer (sceneHandler) 50 { 56 { 51 #if QT_VERSION < 0x060000 << 52 fQGLWidgetInitialiseCompleted = false; 57 fQGLWidgetInitialiseCompleted = false; 53 58 54 setFocusPolicy(Qt::StrongFocus); // enable k 59 setFocusPolicy(Qt::StrongFocus); // enable keybord events 55 fHasToRepaint = false; 60 fHasToRepaint = false; 56 fPaintEventLock = false; 61 fPaintEventLock = false; >> 62 >> 63 // Create a new drawer >> 64 // register the QtDrawer to the OpenGLViewer >> 65 #ifdef G4OPENGL_VERSION_2 >> 66 setVboDrawer(new G4OpenGLVboDrawer(this,"OGL-VBO")); >> 67 #endif >> 68 57 fUpdateGLLock = false; 69 fUpdateGLLock = false; 58 70 59 if (fViewId < 0) return; // In case error i 71 if (fViewId < 0) return; // In case error in base class instantiation. 60 #else << 61 setFocusPolicy(Qt::StrongFocus); // enable k << 62 #endif << 63 } 72 } 64 73 65 G4OpenGLImmediateQtViewer::~G4OpenGLImmediateQ << 74 G4OpenGLImmediateQtViewer::~G4OpenGLImmediateQtViewer() { >> 75 makeCurrent(); >> 76 } 66 77 67 void G4OpenGLImmediateQtViewer::Initialise() { 78 void G4OpenGLImmediateQtViewer::Initialise() { 68 #if QT_VERSION < 0x060000 << 79 makeCurrent(); 69 80 70 fQGLWidgetInitialiseCompleted = false; 81 fQGLWidgetInitialiseCompleted = false; 71 CreateMainWindow (this,QString(GetName())); 82 CreateMainWindow (this,QString(GetName())); 72 83 73 makeCurrent(); << 74 glDrawBuffer (GL_BACK); 84 glDrawBuffer (GL_BACK); 75 85 76 // set the good tab active 86 // set the good tab active 77 if (G4QGLWidgetType::parentWidget()) { << 87 if (QGLWidget::parentWidget()) { 78 auto *parentTab = dynamic_cast<QTabWidget* << 88 QTabWidget *parentTab = dynamic_cast<QTabWidget*> (QGLWidget::parentWidget()->parent()) ; 79 if (parentTab) { 89 if (parentTab) { 80 parentTab->setCurrentIndex(parentTab->co 90 parentTab->setCurrentIndex(parentTab->count()-1); 81 } 91 } 82 } 92 } 83 93 84 fQGLWidgetInitialiseCompleted = true; 94 fQGLWidgetInitialiseCompleted = true; 85 #else << 86 CreateMainWindow (this,QString(GetName())); << 87 // Set jpg as default export format for Qt v << 88 setExportImageFormat("jpg"); << 89 #endif << 90 } 95 } 91 96 92 #if QT_VERSION < 0x060000 << 93 void G4OpenGLImmediateQtViewer::initializeGL ( 97 void G4OpenGLImmediateQtViewer::initializeGL () { 94 98 >> 99 #ifndef G4OPENGL_VERSION_2 95 InitializeGLView (); 100 InitializeGLView (); >> 101 #else >> 102 QGLShaderProgram *aQGLShaderProgram = new QGLShaderProgram (context()); >> 103 fShaderProgram = aQGLShaderProgram->programId (); >> 104 >> 105 aQGLShaderProgram->addShaderFromSourceCode(QGLShader::Vertex, >> 106 fVboDrawer->getVertexShaderSrc()); >> 107 >> 108 aQGLShaderProgram->addShaderFromSourceCode(QGLShader::Fragment, >> 109 fVboDrawer->getFragmentShaderSrc()); >> 110 >> 111 aQGLShaderProgram->link(); >> 112 aQGLShaderProgram->bind(); >> 113 >> 114 fVertexPositionAttribute = glGetAttribLocation(fShaderProgram, "aVertexPosition"); >> 115 fcMatrixUniform = glGetUniformLocation(fShaderProgram, "uCMatrix"); >> 116 fpMatrixUniform = glGetUniformLocation(fShaderProgram, "uPMatrix"); >> 117 ftMatrixUniform = glGetUniformLocation(fShaderProgram, "uTMatrix"); >> 118 fmvMatrixUniform = glGetUniformLocation(fShaderProgram, "uMVMatrix"); >> 119 >> 120 // Load identity at beginning >> 121 float identity[16] = { >> 122 1.0f, 0, 0, 0, >> 123 0, 1.0f, 0, 0, >> 124 0, 0, 1.0f, 0, >> 125 0, 0, 0, 1.0f >> 126 }; >> 127 glUniformMatrix4fv (fcMatrixUniform, 1, 0, identity); >> 128 glUniformMatrix4fv (fpMatrixUniform, 1, 0, identity); >> 129 glUniformMatrix4fv (ftMatrixUniform, 1, 0, identity); >> 130 glUniformMatrix4fv(fmvMatrixUniform, 1, 0, identity); >> 131 >> 132 glUseProgram(fShaderProgram); >> 133 >> 134 setInitialized(); // Should be removed when fuse Wt and Qt >> 135 >> 136 #endif 96 137 97 // If a double buffer context has been force 138 // If a double buffer context has been forced upon us, ignore the 98 // back buffer for this OpenGLImmediate view 139 // back buffer for this OpenGLImmediate view. 99 // glDrawBuffer (GL_FRONT); // FIXME : Ne m 140 // glDrawBuffer (GL_FRONT); // FIXME : Ne marche pas avec cette ligne, mais affiche le run correctement... 100 141 101 if (fSceneHandler.GetScene() == 0) { 142 if (fSceneHandler.GetScene() == 0) { 102 fHasToRepaint =false; 143 fHasToRepaint =false; 103 } else { 144 } else { 104 fHasToRepaint =true; 145 fHasToRepaint =true; 105 } 146 } 106 147 107 // Set the component visible 148 // Set the component visible 108 149 109 // and update it immediatly before wait for 150 // and update it immediatly before wait for SessionStart() (batch mode) 110 // QCoreApplication::sendPostedEvents () ; 151 // QCoreApplication::sendPostedEvents () ; 111 << 112 // Set jpg as default export format for Qt v << 113 setExportImageFormat("jpg"); << 114 } 152 } 115 #endif << 116 153 117 154 118 void G4OpenGLImmediateQtViewer::DrawView() { 155 void G4OpenGLImmediateQtViewer::DrawView() { 119 #if QT_VERSION < 0x060000 << 156 #ifdef G4MULTITHREADED 120 #else << 157 if (G4Threading::G4GetThreadId() == G4Threading::MASTER_ID) { 121 if(IsGettingPickInfos()) { << 122 paintGL(); << 123 return; << 124 } << 125 #endif << 126 if (G4Threading::IsMasterThread()) { << 127 updateQWidget(); 158 updateQWidget(); 128 } 159 } >> 160 #else >> 161 updateQWidget(); >> 162 #endif 129 } 163 } 130 164 131 165 132 void G4OpenGLImmediateQtViewer::ComputeView () 166 void G4OpenGLImmediateQtViewer::ComputeView () { 133 167 134 #if QT_VERSION < 0x060000 << 135 makeCurrent(); 168 makeCurrent(); 136 // If a double buffer context has been force 169 // If a double buffer context has been forced upon us, ignore the 137 // back buffer for this OpenGLImmediate view 170 // back buffer for this OpenGLImmediate view. 138 // glDrawBuffer (GL_FRONT); 171 // glDrawBuffer (GL_FRONT); 139 #endif << 140 172 141 G4ViewParameters::DrawingStyle dstyle = GetV 173 G4ViewParameters::DrawingStyle dstyle = GetViewParameters().GetDrawingStyle(); 142 174 143 if(dstyle!=G4ViewParameters::hlr && 175 if(dstyle!=G4ViewParameters::hlr && 144 haloing_enabled) { 176 haloing_enabled) { 145 177 146 HaloingFirstPass (); 178 HaloingFirstPass (); 147 NeedKernelVisit (); 179 NeedKernelVisit (); 148 ProcessView (); 180 ProcessView (); 149 FinishView(); 181 FinishView(); 150 HaloingSecondPass (); 182 HaloingSecondPass (); 151 183 152 } 184 } 153 185 154 NeedKernelVisit (); // Always need to visit 186 NeedKernelVisit (); // Always need to visit G4 kernel. 155 ProcessView (); 187 ProcessView (); 156 188 157 if (isRecording()) { 189 if (isRecording()) { 158 savePPMToTemp(); 190 savePPMToTemp(); 159 } 191 } 160 192 161 #if QT_VERSION < 0x060000 << 162 fHasToRepaint = true; 193 fHasToRepaint = true; 163 #endif << 164 } 194 } 165 195 166 /** 196 /** 167 - Lors du resize de la fenetre, on doit non 197 - Lors du resize de la fenetre, on doit non pas redessiner le detecteur, mais aussi les evenements 168 */ 198 */ 169 void G4OpenGLImmediateQtViewer::resizeGL( 199 void G4OpenGLImmediateQtViewer::resizeGL( 170 int aWidth 200 int aWidth 171 ,int aHeight) 201 ,int aHeight) 172 { 202 { 173 if ((aWidth > 0) && (aHeight > 0)) { 203 if ((aWidth > 0) && (aHeight > 0)) { 174 #if QT_VERSION < 0x060000 << 175 ResizeWindow(aWidth,aHeight); 204 ResizeWindow(aWidth,aHeight); 176 fHasToRepaint = sizeHasChanged(); 205 fHasToRepaint = sizeHasChanged(); 177 #else << 178 ResizeWindow(devicePixelRatio()*aWidth,dev << 179 #endif << 180 } 206 } 181 } 207 } 182 208 183 209 184 void G4OpenGLImmediateQtViewer::paintGL() 210 void G4OpenGLImmediateQtViewer::paintGL() 185 { 211 { 186 #if QT_VERSION < 0x060000 << 187 updateToolbarAndMouseContextMenu(); 212 updateToolbarAndMouseContextMenu(); 188 #else << 189 //G.Barrand: don't do any change in the GUI << 190 #endif << 191 213 192 #if QT_VERSION < 0x060000 << 193 if (fPaintEventLock) { 214 if (fPaintEventLock) { 194 // return ; 215 // return ; 195 } 216 } 196 if (!fQGLWidgetInitialiseCompleted) { 217 if (!fQGLWidgetInitialiseCompleted) { 197 fPaintEventLock = false; 218 fPaintEventLock = false; 198 return; 219 return; 199 } 220 } 200 if ((getWinWidth() == 0) && (getWinHeight() 221 if ((getWinWidth() == 0) && (getWinHeight() == 0)) { 201 return; 222 return; 202 } 223 } 203 224 204 // DO NOT RESIZE IF SIZE HAS NOT CHANGE 225 // DO NOT RESIZE IF SIZE HAS NOT CHANGE 205 if ( !fHasToRepaint) { 226 if ( !fHasToRepaint) { 206 // L. Garnier : Trap to get the size with 227 // L. Garnier : Trap to get the size with mac OSX 10.6 and Qt 4.6(devel) 207 // Tested on Qt4.5 on mac, 4.4 on windows, 228 // Tested on Qt4.5 on mac, 4.4 on windows, 4.5 on unbuntu 208 int sw = 0; 229 int sw = 0; 209 int sh = 0; 230 int sh = 0; 210 if (!isMaximized() && !isFullScreen()) { 231 if (!isMaximized() && !isFullScreen()) { 211 sw = normalGeometry().width(); 232 sw = normalGeometry().width(); 212 sh = normalGeometry().height(); 233 sh = normalGeometry().height(); 213 } else { 234 } else { 214 sw = frameGeometry().width(); 235 sw = frameGeometry().width(); 215 sh = frameGeometry().height(); 236 sh = frameGeometry().height(); 216 } 237 } 217 if ((getWinWidth() == (unsigned int)sw) && 238 if ((getWinWidth() == (unsigned int)sw) &&(getWinHeight() == (unsigned int)sh)) { 218 return; 239 return; 219 240 220 } else if ((sw == 0) && (sh == 0)) { // NO 241 } else if ((sw == 0) && (sh == 0)) { // NOT A TOP LEVEL WIDGET 221 if (((getWinWidth() == (unsigned int)wid 242 if (((getWinWidth() == (unsigned int)width())) &&(getWinHeight() == (unsigned int) height())) { 222 return; 243 return; 223 } 244 } 224 } 245 } 225 } 246 } 226 #else << 227 if ((getWinWidth() == 0) && (getWinHeight() << 228 #endif << 229 << 230 #if QT_VERSION < 0x060000 << 231 #else << 232 InitializeGLView (); << 233 glDrawBuffer (GL_BACK); << 234 #endif << 235 247 236 SetView(); 248 SetView(); 237 249 238 ClearView (); //ok, put the background corre 250 ClearView (); //ok, put the background correct 239 ComputeView(); 251 ComputeView(); 240 252 241 #if QT_VERSION < 0x060000 << 242 fHasToRepaint = false; // could be set to fa 253 fHasToRepaint = false; // could be set to false by ComputeView 243 254 244 fPaintEventLock = false; 255 fPaintEventLock = false; 245 #endif << 246 } 256 } 247 257 248 void G4OpenGLImmediateQtViewer::mousePressEven 258 void G4OpenGLImmediateQtViewer::mousePressEvent(QMouseEvent *event) 249 { 259 { 250 G4MousePressEvent(event); 260 G4MousePressEvent(event); 251 } 261 } 252 262 253 void G4OpenGLImmediateQtViewer::keyPressEvent 263 void G4OpenGLImmediateQtViewer::keyPressEvent (QKeyEvent * event) 254 { 264 { 255 G4keyPressEvent(event); 265 G4keyPressEvent(event); 256 } 266 } 257 267 258 void G4OpenGLImmediateQtViewer::keyReleaseEven 268 void G4OpenGLImmediateQtViewer::keyReleaseEvent (QKeyEvent * event) 259 { 269 { 260 G4keyReleaseEvent(event); 270 G4keyReleaseEvent(event); 261 } 271 } 262 272 263 void G4OpenGLImmediateQtViewer::wheelEvent (QW 273 void G4OpenGLImmediateQtViewer::wheelEvent (QWheelEvent * event) 264 { 274 { 265 G4wheelEvent(event); 275 G4wheelEvent(event); 266 } 276 } 267 277 268 #if QT_VERSION < 0x060000 << 269 void G4OpenGLImmediateQtViewer::showEvent (QSh 278 void G4OpenGLImmediateQtViewer::showEvent (QShowEvent *) 270 { 279 { 271 if (fQGLWidgetInitialiseCompleted) { 280 if (fQGLWidgetInitialiseCompleted) { 272 fHasToRepaint = true; 281 fHasToRepaint = true; 273 } 282 } 274 } 283 } 275 #endif << 284 276 285 277 /** 286 /** 278 * This function was build in order to make a 287 * This function was build in order to make a zoom on double clic event. 279 * It was think to build a rubberband on the z 288 * It was think to build a rubberband on the zoom area, but never work fine 280 */ 289 */ 281 void G4OpenGLImmediateQtViewer::mouseDoubleCli 290 void G4OpenGLImmediateQtViewer::mouseDoubleClickEvent(QMouseEvent *) 282 { 291 { 283 G4MouseDoubleClickEvent(); 292 G4MouseDoubleClickEvent(); 284 } 293 } 285 294 286 void G4OpenGLImmediateQtViewer::mouseReleaseEv 295 void G4OpenGLImmediateQtViewer::mouseReleaseEvent(QMouseEvent *event) 287 { 296 { 288 G4MouseReleaseEvent(event); 297 G4MouseReleaseEvent(event); 289 } 298 } 290 299 291 void G4OpenGLImmediateQtViewer::mouseMoveEvent 300 void G4OpenGLImmediateQtViewer::mouseMoveEvent(QMouseEvent *event) 292 { 301 { 293 G4MouseMoveEvent(event); 302 G4MouseMoveEvent(event); 294 } 303 } 295 304 296 305 297 void G4OpenGLImmediateQtViewer::contextMenuEve 306 void G4OpenGLImmediateQtViewer::contextMenuEvent(QContextMenuEvent *e) 298 { 307 { 299 G4manageContextMenuEvent(e); 308 G4manageContextMenuEvent(e); 300 } 309 } 301 310 302 #if QT_VERSION < 0x060000 << 303 void G4OpenGLImmediateQtViewer::paintEvent(QPa 311 void G4OpenGLImmediateQtViewer::paintEvent(QPaintEvent *) { 304 if (! fQGLWidgetInitialiseCompleted) { 312 if (! fQGLWidgetInitialiseCompleted) { 305 return; 313 return; 306 } 314 } 307 // Force a repaint next time if the FRAMEBUF 315 // Force a repaint next time if the FRAMEBUFFER is not READY 308 fHasToRepaint = isFramebufferReady(); 316 fHasToRepaint = isFramebufferReady(); 309 if ( fHasToRepaint) { 317 if ( fHasToRepaint) { 310 #if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0)) << 311 updateGL(); 318 updateGL(); 312 #else << 313 // Not sure this is correct.... << 314 paintGL(); << 315 #endif << 316 } 319 } 317 } 320 } 318 #endif << 319 321 320 322 321 void G4OpenGLImmediateQtViewer::updateQWidget( 323 void G4OpenGLImmediateQtViewer::updateQWidget() { 322 #if QT_VERSION < 0x060000 << 323 if (fUpdateGLLock) { 324 if (fUpdateGLLock) { 324 return; 325 return; 325 } 326 } 326 327 327 if (! isCurrentWidget()){ 328 if (! isCurrentWidget()){ 328 return; 329 return; 329 } 330 } 330 331 331 fUpdateGLLock = true; 332 fUpdateGLLock = true; 332 fHasToRepaint= true; 333 fHasToRepaint= true; 333 repaint(); 334 repaint(); 334 updateViewerPropertiesTableWidget(); 335 updateViewerPropertiesTableWidget(); 335 updateSceneTreeWidget(); 336 updateSceneTreeWidget(); 336 fUpdateGLLock= false; 337 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 << 342 } 338 } 343 339 344 340 345 void G4OpenGLImmediateQtViewer::ShowView () << 341 void G4OpenGLImmediateQtViewer::ShowView ( >> 342 ) >> 343 ////////////////////////////////////////////////////////////////////////////// >> 344 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// 346 { 345 { 347 #if QT_VERSION < 0x060000 << 348 fHasToRepaint = true; 346 fHasToRepaint = true; 349 activateWindow(); 347 activateWindow(); 350 #else << 351 activateWindow(); << 352 ((QApplication*)G4Qt::getInstance ())->proce << 353 #endif << 354 } 348 } >> 349 #endif 355 350