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.7.2.1 2009/03/13 09:02:57 gcosmo Exp $ >> 28 // GEANT4 tag $Name: geant4-09-02-patch-03 $ 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" << 34 37 35 #include "G4ios.hh" 38 #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 39 43 G4OpenGLImmediateQtViewer::G4OpenGLImmediateQt 40 G4OpenGLImmediateQtViewer::G4OpenGLImmediateQtViewer 44 (G4OpenGLImmediateSceneHandler& sceneHandler, 41 (G4OpenGLImmediateSceneHandler& sceneHandler, 45 const G4String& name): 42 const G4String& name): 46 G4VViewer (sceneHandler, sceneHandler.Increm 43 G4VViewer (sceneHandler, sceneHandler.IncrementViewCount (), name), 47 G4OpenGLViewer (sceneHandler), 44 G4OpenGLViewer (sceneHandler), 48 G4OpenGLQtViewer (sceneHandler), 45 G4OpenGLQtViewer (sceneHandler), 49 G4OpenGLImmediateViewer (sceneHandler) 46 G4OpenGLImmediateViewer (sceneHandler) 50 { 47 { 51 #if QT_VERSION < 0x060000 << 52 fQGLWidgetInitialiseCompleted = false; << 53 48 54 setFocusPolicy(Qt::StrongFocus); // enable k << 49 //set true to picking 55 fHasToRepaint = false; << 50 fVP.SetPicking(true); 56 fPaintEventLock = false; << 51 fDefaultVP.SetPicking(true); 57 fUpdateGLLock = false; << 52 #if QT_VERSION < 0x040000 58 << 53 setFocusPolicy(QWidget::StrongFocus); // enable keybord events 59 if (fViewId < 0) return; // In case error i << 60 #else 54 #else 61 setFocusPolicy(Qt::StrongFocus); // enable k 55 setFocusPolicy(Qt::StrongFocus); // enable keybord events 62 #endif 56 #endif >> 57 hasToRepaint =false; >> 58 >> 59 if (fViewId < 0) return; // In case error in base class instantiation. 63 } 60 } 64 61 65 G4OpenGLImmediateQtViewer::~G4OpenGLImmediateQ << 62 G4OpenGLImmediateQtViewer::~G4OpenGLImmediateQtViewer() { >> 63 makeCurrent(); >> 64 } 66 65 67 void G4OpenGLImmediateQtViewer::Initialise() { 66 void G4OpenGLImmediateQtViewer::Initialise() { 68 #if QT_VERSION < 0x060000 << 67 #ifdef G4DEBUG_VIS_OGL 69 << 68 printf("G4OpenGLImmediateQtViewer::Initialise \n"); 70 fQGLWidgetInitialiseCompleted = false; << 71 CreateMainWindow (this,QString(GetName())); << 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 69 #endif >> 70 readyToPaint = false; >> 71 CreateMainWindow (this,QString(fName)); >> 72 CreateFontLists (); >> 73 >> 74 readyToPaint = true; 90 } 75 } 91 76 92 #if QT_VERSION < 0x060000 << 93 void G4OpenGLImmediateQtViewer::initializeGL ( 77 void G4OpenGLImmediateQtViewer::initializeGL () { 94 78 95 InitializeGLView (); 79 InitializeGLView (); 96 80 >> 81 97 // If a double buffer context has been force 82 // If a double buffer context has been forced upon us, ignore the 98 // back buffer for this OpenGLImmediate view 83 // back buffer for this OpenGLImmediate view. 99 // glDrawBuffer (GL_FRONT); // FIXME : Ne m << 84 // glDrawBuffer (GL_FRONT); // FIXME : Ne marche pas avec cette ligne, mais affiche le run correctement... >> 85 // clear the buffers and window. >> 86 ClearView (); >> 87 FinishView (); >> 88 >> 89 glDepthFunc (GL_LEQUAL); >> 90 glDepthMask (GL_TRUE); 100 91 101 if (fSceneHandler.GetScene() == 0) { 92 if (fSceneHandler.GetScene() == 0) { 102 fHasToRepaint =false; << 93 hasToRepaint =false; 103 } else { 94 } else { 104 fHasToRepaint =true; << 95 hasToRepaint =true; 105 } 96 } 106 97 107 // Set the component visible << 108 << 109 // and update it immediatly before wait for << 110 // QCoreApplication::sendPostedEvents () ; << 111 << 112 // Set jpg as default export format for Qt v << 113 setExportImageFormat("jpg"); << 114 } 98 } 115 #endif << 116 99 117 100 >> 101 /** To ensure compatibility with DrawView method >> 102 */ 118 void G4OpenGLImmediateQtViewer::DrawView() { 103 void G4OpenGLImmediateQtViewer::DrawView() { 119 #if QT_VERSION < 0x060000 << 104 #ifdef G4DEBUG_VIS_OGL 120 #else << 105 printf("G4OpenGLImmediateQtViewer::DrawView VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV\n"); 121 if(IsGettingPickInfos()) { << 106 #endif 122 paintGL(); << 107 // That's no the same logic as Stored Viewer, I don't know why... 123 return; << 108 // see G4OpenGLStoredQtViewer::DrawView for more informations 124 } << 109 >> 110 updateQWidget(); >> 111 #ifdef G4DEBUG_VIS_OGL >> 112 printf("G4OpenGLImmediateQtViewer::DrawView ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n"); 125 #endif 113 #endif 126 if (G4Threading::IsMasterThread()) { << 127 updateQWidget(); << 128 } << 129 } 114 } 130 115 131 116 132 void G4OpenGLImmediateQtViewer::ComputeView () 117 void G4OpenGLImmediateQtViewer::ComputeView () { 133 118 134 #if QT_VERSION < 0x060000 << 119 #ifdef G4DEBUG_VIS_OGL >> 120 printf("G4OpenGLImmediateQtViewer::ComputeView %d %d VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV\n",fWinSize_x, fWinSize_y); >> 121 #endif 135 makeCurrent(); 122 makeCurrent(); 136 // If a double buffer context has been force 123 // If a double buffer context has been forced upon us, ignore the 137 // back buffer for this OpenGLImmediate view 124 // back buffer for this OpenGLImmediate view. 138 // glDrawBuffer (GL_FRONT); 125 // glDrawBuffer (GL_FRONT); 139 #endif << 140 126 141 G4ViewParameters::DrawingStyle dstyle = GetV << 127 G4ViewParameters::DrawingStyle style = GetViewParameters().GetDrawingStyle(); 142 128 143 if(dstyle!=G4ViewParameters::hlr && << 129 if(style!=G4ViewParameters::hlr && 144 haloing_enabled) { 130 haloing_enabled) { 145 131 146 HaloingFirstPass (); 132 HaloingFirstPass (); 147 NeedKernelVisit (); 133 NeedKernelVisit (); 148 ProcessView (); 134 ProcessView (); 149 FinishView(); << 135 glFlush (); >> 136 #ifdef G4DEBUG_VIS_OGL >> 137 printf("G4OpenGLImmediateQtViewer::ComputeView First ProcessView ok\n"); >> 138 #endif 150 HaloingSecondPass (); 139 HaloingSecondPass (); 151 140 152 } 141 } 153 142 154 NeedKernelVisit (); // Always need to visit 143 NeedKernelVisit (); // Always need to visit G4 kernel. 155 ProcessView (); 144 ProcessView (); 156 145 157 if (isRecording()) { 146 if (isRecording()) { 158 savePPMToTemp(); 147 savePPMToTemp(); 159 } 148 } 160 149 161 #if QT_VERSION < 0x060000 << 150 #ifdef G4DEBUG_VIS_OGL 162 fHasToRepaint = true; << 151 printf("G4OpenGLImmediateQtViewer::ComputeView %d %d ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \n",fWinSize_x, fWinSize_y); 163 #endif 152 #endif >> 153 hasToRepaint = true; 164 } 154 } 165 155 >> 156 void G4OpenGLImmediateQtViewer::FinishView() >> 157 { >> 158 #ifdef G4DEBUG_VIS_OGL >> 159 printf("G4OpenGLImmediateQtViewer::FinishView() BEGIN\n"); >> 160 #endif >> 161 glFlush (); >> 162 #ifdef G4DEBUG_VIS_OGL >> 163 printf("G4OpenGLImmediateQtViewer::FinishView() END\n"); >> 164 #endif >> 165 >> 166 } >> 167 >> 168 166 /** 169 /** 167 - Lors du resize de la fenetre, on doit non 170 - Lors du resize de la fenetre, on doit non pas redessiner le detecteur, mais aussi les evenements 168 */ 171 */ 169 void G4OpenGLImmediateQtViewer::resizeGL( 172 void G4OpenGLImmediateQtViewer::resizeGL( 170 int aWidth 173 int aWidth 171 ,int aHeight) 174 ,int aHeight) 172 { 175 { 173 if ((aWidth > 0) && (aHeight > 0)) { << 176 fWinSize_x = aWidth; 174 #if QT_VERSION < 0x060000 << 177 fWinSize_y = aHeight; 175 ResizeWindow(aWidth,aHeight); << 178 hasToRepaint = true; 176 fHasToRepaint = sizeHasChanged(); << 177 #else << 178 ResizeWindow(devicePixelRatio()*aWidth,dev << 179 #endif << 180 } << 181 } 179 } 182 180 183 181 184 void G4OpenGLImmediateQtViewer::paintGL() 182 void G4OpenGLImmediateQtViewer::paintGL() 185 { 183 { 186 #if QT_VERSION < 0x060000 << 184 #ifdef G4DEBUG_VIS_OGL 187 updateToolbarAndMouseContextMenu(); << 185 printf("\n\nG4OpenGLImmediateQtViewer::paintGL ??\n"); 188 #else << 189 //G.Barrand: don't do any change in the GUI << 190 #endif 186 #endif 191 << 187 if (!readyToPaint) { 192 #if QT_VERSION < 0x060000 << 188 readyToPaint= true; 193 if (fPaintEventLock) { << 194 // return ; << 195 } << 196 if (!fQGLWidgetInitialiseCompleted) { << 197 fPaintEventLock = false; << 198 return; 189 return; 199 } 190 } 200 if ((getWinWidth() == 0) && (getWinHeight() << 201 return; << 202 } << 203 << 204 // DO NOT RESIZE IF SIZE HAS NOT CHANGE 191 // DO NOT RESIZE IF SIZE HAS NOT CHANGE 205 if ( !fHasToRepaint) { << 192 if ( !hasToRepaint) { 206 // L. Garnier : Trap to get the size with << 193 if (((fWinSize_x == (unsigned int)width())) &&(fWinSize_y == (unsigned int) height())) { 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; 194 return; 219 << 220 } else if ((sw == 0) && (sh == 0)) { // NO << 221 if (((getWinWidth() == (unsigned int)wid << 222 return; << 223 } << 224 } 195 } 225 } 196 } 226 #else << 197 #ifdef G4DEBUG_VIS_OGL 227 if ((getWinWidth() == 0) && (getWinHeight() << 198 printf("G4OpenGLImmediateQtViewer::paintGL VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV ready %d\n",readyToPaint); 228 #endif << 229 << 230 #if QT_VERSION < 0x060000 << 231 #else << 232 InitializeGLView (); << 233 glDrawBuffer (GL_BACK); << 234 #endif 199 #endif 235 200 236 SetView(); 201 SetView(); 237 202 238 ClearView (); //ok, put the background corre 203 ClearView (); //ok, put the background correct 239 ComputeView(); 204 ComputeView(); 240 205 241 #if QT_VERSION < 0x060000 << 206 hasToRepaint = false; // could be set to false by ComputeView 242 fHasToRepaint = false; // could be set to fa << 243 207 244 fPaintEventLock = false; << 208 #ifdef G4DEBUG_VIS_OGL >> 209 printf("G4OpenGLImmediateQtViewer::paintGL ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ready %d\n\n\n",readyToPaint); 245 #endif 210 #endif 246 } 211 } 247 212 248 void G4OpenGLImmediateQtViewer::mousePressEven 213 void G4OpenGLImmediateQtViewer::mousePressEvent(QMouseEvent *event) 249 { 214 { 250 G4MousePressEvent(event); 215 G4MousePressEvent(event); 251 } 216 } 252 217 253 void G4OpenGLImmediateQtViewer::keyPressEvent 218 void G4OpenGLImmediateQtViewer::keyPressEvent (QKeyEvent * event) 254 { 219 { 255 G4keyPressEvent(event); 220 G4keyPressEvent(event); 256 } 221 } 257 222 258 void G4OpenGLImmediateQtViewer::keyReleaseEven << 223 void G4OpenGLImmediateQtViewer::wheelEvent (QWheelEvent * event) 259 { << 260 G4keyReleaseEvent(event); << 261 } << 262 << 263 void G4OpenGLImmediateQtViewer::wheelEvent (QW << 264 { 224 { 265 G4wheelEvent(event); 225 G4wheelEvent(event); 266 } 226 } 267 227 268 #if QT_VERSION < 0x060000 << 269 void G4OpenGLImmediateQtViewer::showEvent (QSh << 270 { << 271 if (fQGLWidgetInitialiseCompleted) { << 272 fHasToRepaint = true; << 273 } << 274 } << 275 #endif << 276 << 277 /** 228 /** 278 * This function was build in order to make a 229 * 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 230 * It was think to build a rubberband on the zoom area, but never work fine 280 */ 231 */ 281 void G4OpenGLImmediateQtViewer::mouseDoubleCli << 232 void G4OpenGLImmediateQtViewer::mouseDoubleClickEvent(QMouseEvent *event) 282 { 233 { 283 G4MouseDoubleClickEvent(); 234 G4MouseDoubleClickEvent(); 284 } 235 } 285 236 286 void G4OpenGLImmediateQtViewer::mouseReleaseEv 237 void G4OpenGLImmediateQtViewer::mouseReleaseEvent(QMouseEvent *event) 287 { 238 { 288 G4MouseReleaseEvent(event); << 239 G4MouseReleaseEvent(); 289 } 240 } 290 241 291 void G4OpenGLImmediateQtViewer::mouseMoveEvent 242 void G4OpenGLImmediateQtViewer::mouseMoveEvent(QMouseEvent *event) 292 { 243 { 293 G4MouseMoveEvent(event); 244 G4MouseMoveEvent(event); 294 } 245 } 295 246 296 247 297 void G4OpenGLImmediateQtViewer::contextMenuEve 248 void G4OpenGLImmediateQtViewer::contextMenuEvent(QContextMenuEvent *e) 298 { 249 { 299 G4manageContextMenuEvent(e); 250 G4manageContextMenuEvent(e); 300 } 251 } 301 252 302 #if QT_VERSION < 0x060000 << 303 void G4OpenGLImmediateQtViewer::paintEvent(QPa << 304 if (! fQGLWidgetInitialiseCompleted) { << 305 return; << 306 } << 307 // Force a repaint next time if the FRAMEBUF << 308 fHasToRepaint = isFramebufferReady(); << 309 if ( fHasToRepaint) { << 310 #if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0)) << 311 updateGL(); << 312 #else << 313 // Not sure this is correct.... << 314 paintGL(); << 315 #endif << 316 } << 317 } << 318 #endif << 319 << 320 << 321 void G4OpenGLImmediateQtViewer::updateQWidget( 253 void G4OpenGLImmediateQtViewer::updateQWidget() { 322 #if QT_VERSION < 0x060000 << 254 hasToRepaint= true; 323 if (fUpdateGLLock) { << 255 updateGL(); 324 return; << 256 hasToRepaint= false; 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 << 342 } 257 } 343 258 344 259 345 void G4OpenGLImmediateQtViewer::ShowView () << 260 void G4OpenGLImmediateQtViewer::ShowView ( >> 261 ) >> 262 ////////////////////////////////////////////////////////////////////////////// >> 263 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// 346 { 264 { 347 #if QT_VERSION < 0x060000 << 265 #if QT_VERSION < 0x040000 348 fHasToRepaint = true; << 266 setActiveWindow(); 349 activateWindow(); << 350 #else 267 #else 351 activateWindow(); 268 activateWindow(); 352 ((QApplication*)G4Qt::getInstance ())->proce << 353 #endif 269 #endif 354 } 270 } >> 271 #endif 355 272