Geant4 Cross Reference |
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 // 28 // 29 // Class G4OpenGLImmediateQtViewer : a class derived from G4OpenGLQtViewer and 30 // G4OpenGLImmediateViewer. 31 32 #include "G4OpenGLImmediateQtViewer.hh" 33 #include "G4OpenGLImmediateSceneHandler.hh" 34 35 #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 43 G4OpenGLImmediateQtViewer::G4OpenGLImmediateQtViewer 44 (G4OpenGLImmediateSceneHandler& sceneHandler, 45 const G4String& name): 46 G4VViewer (sceneHandler, sceneHandler.IncrementViewCount (), name), 47 G4OpenGLViewer (sceneHandler), 48 G4OpenGLQtViewer (sceneHandler), 49 G4OpenGLImmediateViewer (sceneHandler) 50 { 51 #if QT_VERSION < 0x060000 52 fQGLWidgetInitialiseCompleted = false; 53 54 setFocusPolicy(Qt::StrongFocus); // enable keybord events 55 fHasToRepaint = false; 56 fPaintEventLock = false; 57 fUpdateGLLock = false; 58 59 if (fViewId < 0) return; // In case error in base class instantiation. 60 #else 61 setFocusPolicy(Qt::StrongFocus); // enable keybord events 62 #endif 63 } 64 65 G4OpenGLImmediateQtViewer::~G4OpenGLImmediateQtViewer() {} 66 67 void G4OpenGLImmediateQtViewer::Initialise() { 68 #if QT_VERSION < 0x060000 69 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*> (G4QGLWidgetType::parentWidget()->parent()) ; 79 if (parentTab) { 80 parentTab->setCurrentIndex(parentTab->count()-1); 81 } 82 } 83 84 fQGLWidgetInitialiseCompleted = true; 85 #else 86 CreateMainWindow (this,QString(GetName())); 87 // Set jpg as default export format for Qt viewer 88 setExportImageFormat("jpg"); 89 #endif 90 } 91 92 #if QT_VERSION < 0x060000 93 void G4OpenGLImmediateQtViewer::initializeGL () { 94 95 InitializeGLView (); 96 97 // If a double buffer context has been forced upon us, ignore the 98 // back buffer for this OpenGLImmediate view. 99 // glDrawBuffer (GL_FRONT); // FIXME : Ne marche pas avec cette ligne, mais affiche le run correctement... 100 101 if (fSceneHandler.GetScene() == 0) { 102 fHasToRepaint =false; 103 } else { 104 fHasToRepaint =true; 105 } 106 107 // Set the component visible 108 109 // and update it immediatly before wait for SessionStart() (batch mode) 110 // QCoreApplication::sendPostedEvents () ; 111 112 // Set jpg as default export format for Qt viewer 113 setExportImageFormat("jpg"); 114 } 115 #endif 116 117 118 void G4OpenGLImmediateQtViewer::DrawView() { 119 #if QT_VERSION < 0x060000 120 #else 121 if(IsGettingPickInfos()) { 122 paintGL(); 123 return; 124 } 125 #endif 126 if (G4Threading::IsMasterThread()) { 127 updateQWidget(); 128 } 129 } 130 131 132 void G4OpenGLImmediateQtViewer::ComputeView () { 133 134 #if QT_VERSION < 0x060000 135 makeCurrent(); 136 // If a double buffer context has been forced upon us, ignore the 137 // back buffer for this OpenGLImmediate view. 138 // glDrawBuffer (GL_FRONT); 139 #endif 140 141 G4ViewParameters::DrawingStyle dstyle = GetViewParameters().GetDrawingStyle(); 142 143 if(dstyle!=G4ViewParameters::hlr && 144 haloing_enabled) { 145 146 HaloingFirstPass (); 147 NeedKernelVisit (); 148 ProcessView (); 149 FinishView(); 150 HaloingSecondPass (); 151 152 } 153 154 NeedKernelVisit (); // Always need to visit G4 kernel. 155 ProcessView (); 156 157 if (isRecording()) { 158 savePPMToTemp(); 159 } 160 161 #if QT_VERSION < 0x060000 162 fHasToRepaint = true; 163 #endif 164 } 165 166 /** 167 - Lors du resize de la fenetre, on doit non pas redessiner le detecteur, mais aussi les evenements 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,devicePixelRatio()*aHeight); 179 #endif 180 } 181 } 182 183 184 void G4OpenGLImmediateQtViewer::paintGL() 185 { 186 #if QT_VERSION < 0x060000 187 updateToolbarAndMouseContextMenu(); 188 #else 189 //G.Barrand: don't do any change in the GUI here, just "paint" this widget! 190 #endif 191 192 #if QT_VERSION < 0x060000 193 if (fPaintEventLock) { 194 // return ; 195 } 196 if (!fQGLWidgetInitialiseCompleted) { 197 fPaintEventLock = false; 198 return; 199 } 200 if ((getWinWidth() == 0) && (getWinHeight() == 0)) { 201 return; 202 } 203 204 // DO NOT RESIZE IF SIZE HAS NOT CHANGE 205 if ( !fHasToRepaint) { 206 // 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, 4.5 on unbuntu 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) &&(getWinHeight() == (unsigned int)sh)) { 218 return; 219 220 } else if ((sw == 0) && (sh == 0)) { // NOT A TOP LEVEL WIDGET 221 if (((getWinWidth() == (unsigned int)width())) &&(getWinHeight() == (unsigned int) height())) { 222 return; 223 } 224 } 225 } 226 #else 227 if ((getWinWidth() == 0) && (getWinHeight() == 0)) return; //G.Barrand: needed? 228 #endif 229 230 #if QT_VERSION < 0x060000 231 #else 232 InitializeGLView (); 233 glDrawBuffer (GL_BACK); 234 #endif 235 236 SetView(); 237 238 ClearView (); //ok, put the background correct 239 ComputeView(); 240 241 #if QT_VERSION < 0x060000 242 fHasToRepaint = false; // could be set to false by ComputeView 243 244 fPaintEventLock = false; 245 #endif 246 } 247 248 void G4OpenGLImmediateQtViewer::mousePressEvent(QMouseEvent *event) 249 { 250 G4MousePressEvent(event); 251 } 252 253 void G4OpenGLImmediateQtViewer::keyPressEvent (QKeyEvent * event) 254 { 255 G4keyPressEvent(event); 256 } 257 258 void G4OpenGLImmediateQtViewer::keyReleaseEvent (QKeyEvent * event) 259 { 260 G4keyReleaseEvent(event); 261 } 262 263 void G4OpenGLImmediateQtViewer::wheelEvent (QWheelEvent * event) 264 { 265 G4wheelEvent(event); 266 } 267 268 #if QT_VERSION < 0x060000 269 void G4OpenGLImmediateQtViewer::showEvent (QShowEvent *) 270 { 271 if (fQGLWidgetInitialiseCompleted) { 272 fHasToRepaint = true; 273 } 274 } 275 #endif 276 277 /** 278 * This function was build in order to make a zoom on double clic event. 279 * It was think to build a rubberband on the zoom area, but never work fine 280 */ 281 void G4OpenGLImmediateQtViewer::mouseDoubleClickEvent(QMouseEvent *) 282 { 283 G4MouseDoubleClickEvent(); 284 } 285 286 void G4OpenGLImmediateQtViewer::mouseReleaseEvent(QMouseEvent *event) 287 { 288 G4MouseReleaseEvent(event); 289 } 290 291 void G4OpenGLImmediateQtViewer::mouseMoveEvent(QMouseEvent *event) 292 { 293 G4MouseMoveEvent(event); 294 } 295 296 297 void G4OpenGLImmediateQtViewer::contextMenuEvent(QContextMenuEvent *e) 298 { 299 G4manageContextMenuEvent(e); 300 } 301 302 #if QT_VERSION < 0x060000 303 void G4OpenGLImmediateQtViewer::paintEvent(QPaintEvent *) { 304 if (! fQGLWidgetInitialiseCompleted) { 305 return; 306 } 307 // Force a repaint next time if the FRAMEBUFFER is not READY 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() { 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; 333 repaint(); 334 updateViewerPropertiesTableWidget(); 335 updateSceneTreeWidget(); 336 fUpdateGLLock= false; 337 #else 338 //if (!isCurrentWidget()) return; //G.Barrand: Qt must know if it has to activate paintGL() if the widget is not visible. 339 //G.Barrand: don't do any change in the GUI here, just ask to "paint" this widget! 340 update(); 341 #endif 342 } 343 344 345 void G4OpenGLImmediateQtViewer::ShowView () 346 { 347 #if QT_VERSION < 0x060000 348 fHasToRepaint = true; 349 activateWindow(); 350 #else 351 activateWindow(); 352 ((QApplication*)G4Qt::getInstance ())->processEvents(); 353 #endif 354 } 355