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