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 // >> 27 // $Id: G4OpenGLQtViewer.cc 77557 2013-11-26 08:57:39Z gcosmo $ >> 28 // >> 29 // 26 // G4OpenGLQtViewer : Class to provide Qt spec 30 // G4OpenGLQtViewer : Class to provide Qt specific 27 // functionality for OpenG 31 // functionality for OpenGL in GEANT4 28 // 32 // 29 // 27/06/2003 : G.Barrand : implementation (at 33 // 27/06/2003 : G.Barrand : implementation (at last !). 30 // 30/06/2014 : M.Kelsey : Change QPixmap obj << 31 34 32 #include "G4LogicalVolumeStore.hh" << 35 #ifdef G4VIS_BUILD_OPENGLQT_DRIVER 33 #include "G4PhysicalVolumeStore.hh" << 34 #include "G4VisCommandsGeometrySet.hh" << 35 #include "G4PhysicalVolumeModel.hh" << 36 #include "G4Text.hh" << 37 #include "G4UnitsTable.hh" << 38 #include "G4OpenGLStoredQtViewer.hh" << 39 #include "G4Threading.hh" << 40 36 41 #include "G4OpenGLQtViewer.hh" 37 #include "G4OpenGLQtViewer.hh" >> 38 42 #include "G4OpenGLSceneHandler.hh" 39 #include "G4OpenGLSceneHandler.hh" >> 40 #include "G4VSolid.hh" 43 #include "G4OpenGLQtExportDialog.hh" 41 #include "G4OpenGLQtExportDialog.hh" 44 #include "G4OpenGLQtMovieDialog.hh" 42 #include "G4OpenGLQtMovieDialog.hh" 45 #include "G4Qt.hh" 43 #include "G4Qt.hh" 46 #include "G4UIQt.hh" 44 #include "G4UIQt.hh" 47 #include "G4UImanager.hh" 45 #include "G4UImanager.hh" 48 #include "G4UIcommandTree.hh" 46 #include "G4UIcommandTree.hh" >> 47 #include "G4LogicalVolumeStore.hh" >> 48 #include "G4PhysicalVolumeStore.hh" >> 49 #include "G4VisCommandsGeometrySet.hh" >> 50 #include "G4PhysicalVolumeModel.hh" >> 51 #include "G4Text.hh" 49 52 50 #include <CLHEP/Units/SystemOfUnits.h> 53 #include <CLHEP/Units/SystemOfUnits.h> 51 54 52 #include <typeinfo> 55 #include <typeinfo> 53 #include <mutex> << 54 56 55 #include <qlayout.h> 57 #include <qlayout.h> 56 #include <qlabel.h> 58 #include <qlabel.h> 57 #include <qdialog.h> 59 #include <qdialog.h> 58 #include <qpushbutton.h> 60 #include <qpushbutton.h> 59 #include <qprocess.h> 61 #include <qprocess.h> >> 62 #include <qapplication.h> >> 63 #include <qdesktopwidget.h> >> 64 60 #include <qmenu.h> 65 #include <qmenu.h> 61 #include <qimagewriter.h> 66 #include <qimagewriter.h> 62 67 63 #include <qtextedit.h> 68 #include <qtextedit.h> 64 #include <qtreewidget.h> 69 #include <qtreewidget.h> 65 #include <qapplication.h> 70 #include <qapplication.h> 66 #include <qmessagebox.h> 71 #include <qmessagebox.h> 67 #include <qfiledialog.h> 72 #include <qfiledialog.h> >> 73 #include <qprinter.h> 68 #include <qdatetime.h> 74 #include <qdatetime.h> 69 #if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)) << 70 #include <qelapsedtimer.h> << 71 #endif << 72 #if (QT_VERSION < QT_VERSION_CHECK(5, 10, 0)) << 73 #include "qdesktopwidget.h" << 74 #endif << 75 #include <qpainter.h> 75 #include <qpainter.h> >> 76 #include <qgl.h> // include <qglwidget.h> 76 #include <qdialog.h> 77 #include <qdialog.h> 77 #include <qcolordialog.h> 78 #include <qcolordialog.h> 78 #include <qevent.h> //include <qcontextmenueve 79 #include <qevent.h> //include <qcontextmenuevent.h> 79 #include <qobject.h> 80 #include <qobject.h> 80 #include <qgroupbox.h> 81 #include <qgroupbox.h> 81 #include <qcombobox.h> 82 #include <qcombobox.h> 82 #include <qlineedit.h> 83 #include <qlineedit.h> 83 #include <qscreen.h> << 84 #include <qsignalmapper.h> 84 #include <qmainwindow.h> << 85 #include <qtablewidget.h> << 86 #include <qheaderview.h> << 87 #include <qscrollarea.h> << 88 #include <qsplitter.h> << 89 #include <qcheckbox.h> << 90 #include <qcursor.h> << 91 #include <qthread.h> << 92 << 93 #if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0)) << 94 #include <QGLContext> << 95 #else << 96 #include <QOpenGLContext> << 97 #endif << 98 << 99 #ifndef G4GMAKE << 100 #include "moc_G4OpenGLQtViewer.cpp" << 101 #endif << 102 85 103 ////////////////////////////////////////////// 86 ////////////////////////////////////////////////////////////////////////////// 104 void G4OpenGLQtViewer::CreateMainWindow ( 87 void G4OpenGLQtViewer::CreateMainWindow ( 105 G4QGLWidgetType* glWidget << 88 QGLWidget* glWidget 106 ,const QString& name 89 ,const QString& name 107 ) << 90 ) 108 ////////////////////////////////////////////// 91 ////////////////////////////////////////////////////////////////////////////// 109 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 92 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// 110 { 93 { 111 94 112 if(fGLWidget) return; //Done. << 95 if(fWindow) return; //Done. 113 96 114 fGLWidget = glWidget ; << 97 fWindow = glWidget ; >> 98 // fWindow->makeCurrent(); 115 99 116 #if QT_VERSION < 0x060000 << 100 G4Qt* interactorManager = G4Qt::getInstance (); 117 ResizeWindow(fVP.GetWindowSizeHintX(),fVP.Ge << 118 #else << 119 ResizeWindow(glWidget->devicePixelRatio()*fV << 120 #endif << 121 101 122 // FIXME L.Garnier 9/11/09 Has to be check ! << 102 ResizeWindow(fVP.GetWindowSizeHintX(),fVP.GetWindowSizeHintY()); >> 103 >> 104 // FIXME L.Garnier 9/11/09 Has to be check !!! 123 // Qt UI with Qt Vis 105 // Qt UI with Qt Vis 124 // Qt UI with X Vis 106 // Qt UI with X Vis 125 // X UI with Qt Vis 107 // X UI with Qt Vis 126 // X UI with X Vis 108 // X UI with X Vis 127 // Ne marche pas avec un UIBatch !! (ecran b 109 // Ne marche pas avec un UIBatch !! (ecran blanc) 128 110 129 // return false if G4UIQt was not launch 111 // return false if G4UIQt was not launch 130 112 131 G4UImanager* UI = G4UImanager::GetUIpointer( 113 G4UImanager* UI = G4UImanager::GetUIpointer(); 132 if (UI == NULL) return; 114 if (UI == NULL) return; 133 115 134 if (! static_cast<G4UIQt*> (UI->GetG4UIWindo 116 if (! static_cast<G4UIQt*> (UI->GetG4UIWindow())) { 135 // NO UI, should be batch mode 117 // NO UI, should be batch mode 136 fBatchMode = true; 118 fBatchMode = true; 137 return; 119 return; 138 } 120 } 139 fUiQt = static_cast<G4UIQt*> (UI->GetG4UIWin 121 fUiQt = static_cast<G4UIQt*> (UI->GetG4UIWindow()); 140 << 122 141 bool isTabbedView = false; 123 bool isTabbedView = false; 142 if ( fUiQt) { 124 if ( fUiQt) { 143 if (!fBatchMode) { 125 if (!fBatchMode) { 144 G4Qt* interactorManager = G4Qt::getInsta << 145 if (!interactorManager->IsExternalApp()) 126 if (!interactorManager->IsExternalApp()) { 146 // INIT size << 127 isTabbedView = fUiQt->AddTabWidget((QWidget*)fWindow,name,getWinWidth(),getWinHeight()); 147 fWinSize_x = fVP.GetWindowSizeHintX(); << 128 fUISceneTreeComponentsTBWidget = fUiQt->GetSceneTreeComponentsTBWidget(); 148 fWinSize_y = fVP.GetWindowSizeHintY(); << 129 isTabbedView = true; 149 << 150 isTabbedView = fUiQt->AddTabWidget((QW << 151 QObject::connect(fUiQt->GetViewerTabWi << 152 SIGNAL(currentChanged << 153 this, << 154 SLOT(currentTabActiva << 155 << 156 #if QT_VERSION < 0x060000 << 157 #else << 158 createViewerPropertiesWidget(); << 159 #endif << 160 << 161 } 130 } 162 createSceneTreeWidget(); << 163 // activate them << 164 } 131 } 165 } 132 } >> 133 #ifdef G4DEBUG_VIS_OGL >> 134 else { >> 135 printf("G4OpenGLQtViewer::CreateMainWindow :: UIQt NOt found \n"); >> 136 } >> 137 #endif 166 138 167 if (!isTabbedView) { // we have to do a dial 139 if (!isTabbedView) { // we have to do a dialog 168 140 169 QWidget *glDialogWidget = getParentWidget( << 141 QWidget *myParent = getParentWidget(); 170 if (glDialogWidget == NULL) { << 142 #ifdef G4DEBUG_VIS_OGL 171 return; << 143 printf("G4OpenGLQtViewer::CreateMainWindow :: getParent OK \n"); >> 144 #endif >> 145 if (myParent != NULL) { >> 146 glWidget->setParent(myParent); 172 } 147 } 173 glWidget->setParent(glDialogWidget); << 174 QHBoxLayout *mainLayout = new QHBoxLayout( 148 QHBoxLayout *mainLayout = new QHBoxLayout(); 175 << 149 176 mainLayout->setContentsMargins(0,0,0,0); << 150 mainLayout->setMargin(0); 177 mainLayout->setSpacing(0); << 151 mainLayout->setSpacing(0); 178 mainLayout->addWidget(fGLWidget); << 152 mainLayout->addWidget(fWindow); 179 if (fGLWidget->inherits("QMainWindow")) { << 153 if (fGLWindow->inherits("QMainWindow")) { 180 fGLWidget->setWindowTitle( name); << 154 fGLWindow->setWindowTitle( name); 181 } 155 } 182 glDialogWidget->setLayout(mainLayout); << 156 fGLWindow->setLayout(mainLayout); 183 << 184 157 >> 158 185 //useful for MACOSX, we have to compt the 159 //useful for MACOSX, we have to compt the menuBar height 186 #if (QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)) << 160 int offset = QApplication::desktop()->height() 187 G4int offset = QGuiApplication::primaryS << 161 - QApplication::desktop()->availableGeometry().height(); 188 - QGuiApplication::screenAt(QPoint(2 << 162 189 #else << 163 G4int YPos= fVP.GetWindowAbsoluteLocationHintY(QApplication::desktop()->height()); 190 G4int offset = QApplication::desktop()-> << 164 if (fVP.GetWindowAbsoluteLocationHintY(QApplication::desktop()->height())< offset) { 191 - QApplication::desktop()->available << 192 #endif << 193 << 194 G4int YPos= fVP.GetWindowAbsoluteLocationH << 195 if (fVP.GetWindowAbsoluteLocationHintY(QGu << 196 YPos = offset; 165 YPos = offset; 197 } 166 } 198 glDialogWidget->resize(getWinWidth(), getW << 167 #ifdef G4DEBUG_VIS_OGL 199 glDialogWidget->move(fVP.GetWindowAbsolute << 168 printf("G4OpenGLQtViewer::CreateMainWindow :: resizing to %d %d \n",getWinWidth(), getWinHeight()); 200 glDialogWidget->show(); << 169 #endif >> 170 fGLWindow->move(fVP.GetWindowAbsoluteLocationHintX(QApplication::desktop()->width()),YPos); >> 171 fGLWindow->show(); >> 172 } else { >> 173 fGLWindow = fWindow; 201 } 174 } 202 175 203 if(!fGLWidget) return; << 176 if(!fWindow) return; 204 << 177 205 if (!fContextMenu) << 178 if (!fContextMenu) 206 createPopupMenu(); 179 createPopupMenu(); 207 180 208 } 181 } 209 182 210 183 211 ////////////////////////////////////////////// 184 ////////////////////////////////////////////////////////////////////////////// 212 G4OpenGLQtViewer::G4OpenGLQtViewer ( 185 G4OpenGLQtViewer::G4OpenGLQtViewer ( 213 G4OpenGLSceneHandler& scene 186 G4OpenGLSceneHandler& scene 214 ) 187 ) 215 :G4VViewer (scene, -1) 188 :G4VViewer (scene, -1) 216 ,G4OpenGLViewer (scene) 189 ,G4OpenGLViewer (scene) 217 ,fUiQt(NULL) << 190 ,fWindow(NULL) 218 ,fGLWidget(NULL) << 191 ,fGLWindow(NULL) 219 ,fRecordFrameNumber(0) 192 ,fRecordFrameNumber(0) 220 ,fMouseOnSceneTree(false) << 221 ,fContextMenu(0) 193 ,fContextMenu(0) 222 ,fLastPickPoint(-1,-1) << 223 ,fDeltaDepth(0.01) 194 ,fDeltaDepth(0.01) 224 ,fDeltaZoom(0.05) 195 ,fDeltaZoom(0.05) 225 ,fHoldKeyEvent(false) 196 ,fHoldKeyEvent(false) 226 ,fHoldMoveEvent(false) 197 ,fHoldMoveEvent(false) 227 ,fHoldRotateEvent(false) 198 ,fHoldRotateEvent(false) 228 ,fAutoMove(false) 199 ,fAutoMove(false) 229 ,fEncoderPath("") 200 ,fEncoderPath("") 230 ,fTempFolderPath("") 201 ,fTempFolderPath("") 231 ,fMovieTempFolderPath("") 202 ,fMovieTempFolderPath("") 232 ,fSaveFileName("") 203 ,fSaveFileName("") 233 ,fParameterFileName("ppmtompeg_encode_parame 204 ,fParameterFileName("ppmtompeg_encode_parameter_file.par") 234 ,fMovieParametersDialog(NULL) 205 ,fMovieParametersDialog(NULL) 235 ,fRecordingStep(WAIT) 206 ,fRecordingStep(WAIT) 236 ,fProcess(NULL) 207 ,fProcess(NULL) 237 ,fNbMaxFramesPerSec(100) 208 ,fNbMaxFramesPerSec(100) 238 ,fNbMaxAnglePerSec(360) 209 ,fNbMaxAnglePerSec(360) 239 ,fLaunchSpinDelay(100) 210 ,fLaunchSpinDelay(100) 240 ,fUISceneTreeWidget(NULL) << 211 ,fUISceneTreeComponentsTBWidget(NULL) 241 ,fUIViewerPropertiesWidget(NULL) << 242 ,fUIPickInfosWidget(NULL) << 243 ,fNoKeyPress(true) 212 ,fNoKeyPress(true) 244 ,fAltKeyPress(false) 213 ,fAltKeyPress(false) 245 ,fControlKeyPress(false) 214 ,fControlKeyPress(false) 246 ,fShiftKeyPress(false) 215 ,fShiftKeyPress(false) 247 ,fBatchMode(false) 216 ,fBatchMode(false) 248 ,fCheckSceneTreeComponentSignalLock(false) 217 ,fCheckSceneTreeComponentSignalLock(false) 249 ,fViewerPropertiesTableWidgetIsInit(false) << 250 ,fSceneTreeComponentTreeWidget(NULL) 218 ,fSceneTreeComponentTreeWidget(NULL) >> 219 ,fOldSceneTreeComponentTreeWidget(NULL) 251 ,fSceneTreeWidget(NULL) 220 ,fSceneTreeWidget(NULL) 252 ,fPVRootNodeCreate(false) 221 ,fPVRootNodeCreate(false) 253 ,fFilterOutput(NULL) << 222 ,fHelpLine(NULL) 254 ,fNbRotation(0) 223 ,fNbRotation(0) 255 ,fTimeRotation(0) 224 ,fTimeRotation(0) 256 ,fTouchableVolumes("Touchables") 225 ,fTouchableVolumes("Touchables") 257 ,fShortcutsDialog(NULL) 226 ,fShortcutsDialog(NULL) 258 ,fViewerPropertiesTableWidget(NULL) << 259 ,fPickInfosWidget(NULL) << 260 ,fPickInfosScrollArea(NULL) << 261 ,fTreeWidgetInfosIgnoredCommands(0) << 262 ,fSceneTreeDepthSlider(NULL) 227 ,fSceneTreeDepthSlider(NULL) 263 ,fSceneTreeDepth(1) 228 ,fSceneTreeDepth(1) 264 ,fModelShortNameItem(NULL) 229 ,fModelShortNameItem(NULL) 265 ,fMaxPOindexInserted(-1) 230 ,fMaxPOindexInserted(-1) 266 ,fTreeIconOpen(NULL) << 231 ,fUiQt(NULL) 267 ,fTreeIconClosed(NULL) << 232 ,signalMapperMouse(NULL) 268 ,fLastExportSliderValue(80) << 233 ,signalMapperSurface(NULL) 269 ,fLastHighlightColor(G4Color(0,0,0,0)) << 270 ,fLastHighlightName(0) << 271 ,fIsDeleting(false) << 272 { 234 { >> 235 273 // launch Qt if not 236 // launch Qt if not 274 if (QCoreApplication::instance () == NULL) { 237 if (QCoreApplication::instance () == NULL) { 275 fBatchMode = true; 238 fBatchMode = true; 276 } 239 } 277 G4Qt::getInstance (); 240 G4Qt::getInstance (); 278 241 279 fLastPos3 = QPoint(-1,-1); << 242 fLastPos3 = QPoint(-1,-1); 280 fLastPos2 = QPoint(-1,-1); << 243 fLastPos2 = QPoint(-1,-1); 281 fLastPos1 = QPoint(-1,-1); << 244 fLastPos1 = QPoint(-1,-1); 282 << 245 283 initMovieParameters(); 246 initMovieParameters(); 284 247 285 #if (QT_VERSION < QT_VERSION_CHECK(5, 14, 0)) << 286 fLastEventTime = new QTime(); 248 fLastEventTime = new QTime(); 287 #else << 249 signalMapperMouse = new QSignalMapper(this); 288 fLastEventTime = new QElapsedTimer(); << 250 signalMapperSurface = new QSignalMapper(this); 289 #endif << 251 290 // Set default path and format 252 // Set default path and format 291 fFileSavePath = QDir::currentPath(); 253 fFileSavePath = QDir::currentPath(); >> 254 fDefaultSaveFileFormat = "png"; 292 255 293 // add available export format << 256 #ifdef G4DEBUG_VIS_OGL 294 QList<QByteArray> formats = QImageWriter::s << 257 printf("G4OpenGLQtViewer::G4OpenGLQtViewer END\n"); 295 for (int i = 0; i < formats.size(); ++i) { << 258 #endif 296 addExportImageFormat(formats.at(i).data()) << 297 } << 298 << 299 const char * const icon1[]={ << 300 /* columns rows colors chars-per-pixel */ << 301 "20 20 34 1", << 302 " c None", << 303 ". c #7C7C7C7C7C7C", << 304 "X c #7D7D7D7D7D7D", << 305 "o c #828282828282", << 306 "O c #838383838383", << 307 "+ c #848484848484", << 308 "@ c #858585858585", << 309 "# c #878787878787", << 310 "$ c #888888888888", << 311 "% c #8B8B8B8B8B8B", << 312 "& c #8C8C8C8C8C8C", << 313 "* c #8F8F8F8F8F8F", << 314 "= c #909090909090", << 315 "- c #919191919191", << 316 "; c #999999999999", << 317 ": c #9D9D9D9D9D9D", << 318 "> c #A2A2A2A2A2A2", << 319 ", c #A3A3A3A3A3A3", << 320 "< c #A5A5A5A5A5A5", << 321 "1 c #A6A6A6A6A6A6", << 322 "2 c #B3B3B3B3B3B3", << 323 "3 c #B6B6B6B6B6B6", << 324 "4 c #C2C2C2C2C2C2", << 325 "5 c #C6C6C6C6C6C6", << 326 "6 c #CACACACACACA", << 327 "7 c #CFCFCFCFCFCF", << 328 "8 c #D0D0D0D0D0D0", << 329 "9 c #D4D4D4D4D4D4", << 330 "0 c #D7D7D7D7D7D7", << 331 "q c #DEDEDEDEDEDE", << 332 "w c #E0E0E0E0E0E0", << 333 "e c #E7E7E7E7E7E7", << 334 "r c #F4F4F4F4F4F4", << 335 "t c #F7F7F7F7F7F7", << 336 " ", << 337 " ", << 338 " ", << 339 " ", << 340 " ", << 341 " ", << 342 " =========> ", << 343 " 7&X+++Oo<e ", << 344 " 2o+@@+-8 ", << 345 " w;.#@+3 ", << 346 " 4$o@:q ", << 347 " r1X%5 ", << 348 " 9*,t ", << 349 " 60 ", << 350 " ", << 351 " ", << 352 " ", << 353 " ", << 354 " ", << 355 " " << 356 }; << 357 const char * const icon2[]={ << 358 "20 20 68 1", << 359 " c None", << 360 ". c #5F5F10102323", << 361 "X c #40405F5F1010", << 362 "o c #696963632E2E", << 363 "O c #101019194C4C", << 364 "+ c #101023237070", << 365 "@ c #70702D2D6363", << 366 "# c #73732D2D6464", << 367 "$ c #79792E2E6767", << 368 "% c #19194C4C5353", << 369 "& c #2D2D63636161", << 370 "* c #2E2E61617070", << 371 "= c #6F6F6E6E4343", << 372 "- c #707065655F5F", << 373 "; c #727279795454", << 374 ": c #535341417070", << 375 "> c #797954547979", << 376 ", c #434361617474", << 377 "< c #414170707070", << 378 "1 c #686869696363", << 379 "2 c #6C6C69696363", << 380 "3 c #656567676F6F", << 381 "4 c #69696F6F6E6E", << 382 "5 c #747465656767", << 383 "6 c #757562626C6C", << 384 "7 c #70706C6C6969", << 385 "8 c #616174746565", << 386 "9 c #656573736969", << 387 "0 c #616174746969", << 388 "q c #707075756262", << 389 "w c #797970706565", << 390 "e c #636361617474", << 391 "r c #67676F6F7272", << 392 "t c #727261617070", << 393 "y c #616170707070", << 394 "u c #6F6F72727979", << 395 "i c #67676E6ED1D1", << 396 "p c #808080808080", << 397 "a c #828282828282", << 398 "s c #838383838383", << 399 "d c #848484848484", << 400 "f c #858585858585", << 401 "g c #868686868686", << 402 "h c #888888888888", << 403 "j c #8A8A8A8A8A8A", << 404 "k c #8D8D8D8D8D8D", << 405 "l c #8F8F8F8F8F8F", << 406 "z c #909090909090", << 407 "x c #949494949494", << 408 "c c #9C9C9C9C9C9C", << 409 "v c #9F9F9F9F9F9F", << 410 "b c #A2A2A2A2A2A2", << 411 "n c #AEAEAEAEAEAE", << 412 "m c #B7B7B7B7B7B7", << 413 "M c #C7C7C7C7C7C7", << 414 "N c #C9C9C9C9C9C9", << 415 "B c #D1D1D1D1D1D1", << 416 "V c #D4D4D4D4D4D4", << 417 "C c #D9D9D9D9D9D9", << 418 "Z c #E0E0E0E0E0E0", << 419 "A c #E2E2E2E2E2E2", << 420 "S c #EEEEEEEEEEEE", << 421 "D c #F0F0F0F0F0F0", << 422 "F c #F5F5F5F5F5F5", << 423 "G c #F6F6F6F6F6F6", << 424 "H c #F9F9F9F9F9F9", << 425 "J c #FCFCFCFCFCFC", << 426 "K c #FDFDFDFDFDFD", << 427 " ", << 428 " ", << 429 " ", << 430 " ", << 431 " ", << 432 " bC ", << 433 " zjnD ", << 434 " ldjjMK ", << 435 " zdhdjcA ", << 436 " zddhdddVK ", << 437 " zghdalBH ", << 438 " zghamSK ", << 439 " lubZH ", << 440 " xMF ", << 441 " G ", << 442 " ", << 443 " ", << 444 " ", << 445 " ", << 446 " ", << 447 << 448 }; << 449 << 450 const char * const search[] = { << 451 /* columns rows colors chars-per-pixel */ << 452 "19 19 8 1", << 453 " c #5C5C5C", << 454 ". c #7D7D7D", << 455 "X c #9B9B9B", << 456 "o c #C3C3C3", << 457 "O c None", << 458 "+ c #000000", << 459 "@ c #000000", << 460 "# c None", << 461 /* pixels */ << 462 "OOOOOOOOOOOOOOOOOOO", << 463 "OOOOOOOOOOOOOOOOOOO", << 464 "OOOOOOOo. .oOOOOOO", << 465 "OOOOOOX XOOOOO", << 466 "OOOOOo XOOX oOOOO", << 467 "OOOOO. XOOOOX .OOOO", << 468 "OOOOO OOOOOO OOOO", << 469 "OOOOO OOOOOO OOOO", << 470 "OOOOO. XOOOOo .OOOO", << 471 "OOOOOo oOOo oOOOO", << 472 "OOOOOOX XOOOO", << 473 "OOOOOOOo. . XOOO", << 474 "OOOOOOOOOOOOO. XOO", << 475 "OOOOOOOOOOOOOO. XOO", << 476 "OOOOOOOOOOOOOOOoOOO", << 477 "OOOOOOOOOOOOOOOOOOO", << 478 "OOOOOOOOOOOOOOOOOOO", << 479 "OOOOOOOOOOOOOOOOOOO", << 480 "OOOOOOOOOOOOOOOOOOO" << 481 }; << 482 << 483 fSearchIcon = new QPixmap(search); << 484 fTreeIconOpen = new QPixmap(icon1); << 485 fTreeIconClosed = new QPixmap(icon2); << 486 << 487 } 259 } 488 260 489 ////////////////////////////////////////////// 261 ////////////////////////////////////////////////////////////////////////////// 490 G4OpenGLQtViewer::~G4OpenGLQtViewer ( 262 G4OpenGLQtViewer::~G4OpenGLQtViewer ( 491 ) << 263 ) 492 ////////////////////////////////////////////// 264 ////////////////////////////////////////////////////////////////////////////// 493 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 265 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// 494 { 266 { 495 fIsDeleting = true; << 496 << 497 // remove scene tree from layout 267 // remove scene tree from layout 498 // Delete all the existing buttons in the la 268 // Delete all the existing buttons in the layout 499 QLayoutItem *wItem; 269 QLayoutItem *wItem; 500 if (fSceneTreeWidget != NULL) { 270 if (fSceneTreeWidget != NULL) { 501 if (fSceneTreeWidget->layout() != NULL) { 271 if (fSceneTreeWidget->layout() != NULL) { 502 while ((wItem = fSceneTreeWidget->layout 272 while ((wItem = fSceneTreeWidget->layout()->takeAt(0)) != 0) { 503 delete wItem->widget(); 273 delete wItem->widget(); 504 delete wItem; 274 delete wItem; 505 } 275 } 506 } 276 } >> 277 if (fUISceneTreeComponentsTBWidget != NULL) { >> 278 fUISceneTreeComponentsTBWidget->removeTab(fUISceneTreeComponentsTBWidget->indexOf(fSceneTreeWidget)); >> 279 } 507 } 280 } 508 << 281 G4cout <<removeTempFolder().toStdString().c_str() <<G4endl; 509 // Delete the open/close icons << 510 delete fTreeIconOpen; << 511 delete fTreeIconClosed; << 512 << 513 #if QT_VERSION < 0x060000 << 514 G4cout <<removeTempFolder().toStdString().c_ << 515 #endif << 516 << 517 } 282 } 518 283 519 G4bool G4OpenGLQtViewer::ReadyToDraw() { << 520 #if QT_VERSION < 0x060000 << 521 return true; << 522 #else << 523 if(!fGLWidget) return false; << 524 auto* qGLW = dynamic_cast<G4QGLWidgetType*>( << 525 if (!qGLW) return false; << 526 return qGLW->isValid(); << 527 #endif << 528 } << 529 284 530 // 285 // 531 // Create a popup menu for the widget. This 286 // Create a popup menu for the widget. This menu is activated by right-mouse click 532 // 287 // 533 void G4OpenGLQtViewer::createPopupMenu() { 288 void G4OpenGLQtViewer::createPopupMenu() { 534 289 535 fContextMenu = new QMenu("All"); 290 fContextMenu = new QMenu("All"); 536 291 537 QMenu *mMouseAction = fContextMenu->addMenu( 292 QMenu *mMouseAction = fContextMenu->addMenu("&Mouse actions"); 538 fMouseRotateAction = mMouseAction->addAction << 293 539 fMouseMoveAction = mMouseAction->addAction(" << 294 fMouseRotateAction = mMouseAction->addAction("Rotate", signalMapperMouse, SLOT(map())); 540 fMousePickAction = mMouseAction->addAction(" << 295 fMouseMoveAction = mMouseAction->addAction("Move", signalMapperMouse, SLOT(map())); 541 fMouseZoomOutAction = mMouseAction->addActio << 296 fMousePickAction = mMouseAction->addAction("Pick", signalMapperMouse, SLOT(map())); 542 fMouseZoomInAction = mMouseAction->addAction << 297 fMouseZoomOutAction = mMouseAction->addAction("Zoom out", signalMapperMouse, SLOT(map())); >> 298 fMouseZoomInAction = mMouseAction->addAction("Zoom in", signalMapperMouse, SLOT(map())); 543 QAction *shortcutsAction = mMouseAction->add 299 QAction *shortcutsAction = mMouseAction->addAction("Show shortcuts"); 544 300 545 fMouseRotateAction->setCheckable(true); 301 fMouseRotateAction->setCheckable(true); 546 fMouseMoveAction->setCheckable(true); 302 fMouseMoveAction->setCheckable(true); 547 fMousePickAction->setCheckable(true); 303 fMousePickAction->setCheckable(true); 548 fMouseZoomOutAction->setCheckable(true); 304 fMouseZoomOutAction->setCheckable(true); 549 fMouseZoomInAction->setCheckable(true); 305 fMouseZoomInAction->setCheckable(true); 550 shortcutsAction->setCheckable(false); 306 shortcutsAction->setCheckable(false); 551 307 552 QObject::connect(shortcutsAction, << 308 connect(signalMapperMouse, SIGNAL(mapped(int)),this, SLOT(toggleMouseAction(int))); >> 309 signalMapperMouse->setMapping(fMouseRotateAction,1); >> 310 signalMapperMouse->setMapping(fMouseMoveAction,2); >> 311 signalMapperMouse->setMapping(fMousePickAction,3); >> 312 signalMapperMouse->setMapping(fMouseZoomOutAction,4); >> 313 signalMapperMouse->setMapping(fMouseZoomInAction,5); >> 314 >> 315 QObject::connect(shortcutsAction, 553 SIGNAL(triggered(bool)), 316 SIGNAL(triggered(bool)), 554 this, << 317 this, 555 SLOT(showShortcuts())); 318 SLOT(showShortcuts())); 556 319 557 // === Style Menu === 320 // === Style Menu === 558 QMenu *mStyle = fContextMenu->addMenu("&Styl 321 QMenu *mStyle = fContextMenu->addMenu("&Style"); 559 322 560 QMenu *mProjection = mStyle->addMenu("&Proje 323 QMenu *mProjection = mStyle->addMenu("&Projection"); 561 324 562 // no more radioAction, not realy useful and << 325 fProjectionOrtho = mProjection->addAction("Orthographic", signalMapperSurface, SLOT(map())); 563 fProjectionOrtho = mProjection->addAction("O << 326 fProjectionPerspective = mProjection->addAction("Persepective", signalMapperSurface, SLOT(map())); 564 fProjectionPerspective = mProjection->addAct << 327 >> 328 // INIT mProjection >> 329 if (fVP.GetFieldHalfAngle() == 0) { >> 330 createRadioAction(fProjectionOrtho, fProjectionPerspective,SLOT(toggleProjection(bool)),1); >> 331 } else { >> 332 createRadioAction(fProjectionOrtho, fProjectionPerspective,SLOT(toggleProjection(bool)),2); >> 333 } >> 334 565 // === Drawing Menu === 335 // === Drawing Menu === 566 QMenu *mDrawing = mStyle->addMenu("&Drawing" 336 QMenu *mDrawing = mStyle->addMenu("&Drawing"); 567 fDrawingWireframe = mDrawing->addAction("Wir << 337 568 fDrawingLineRemoval = mDrawing->addAction("H << 338 fDrawingWireframe = mDrawing->addAction("Wireframe", signalMapperSurface, SLOT(map())); 569 fDrawingSurfaceRemoval = mDrawing->addAction << 339 570 fDrawingLineSurfaceRemoval = mDrawing->addAc << 340 fDrawingLineRemoval = mDrawing->addAction("Hidden line removal", signalMapperSurface, SLOT(map())); >> 341 >> 342 fDrawingSurfaceRemoval = mDrawing->addAction("Hidden Surface removal", signalMapperSurface, SLOT(map())); >> 343 >> 344 fDrawingLineSurfaceRemoval = mDrawing->addAction("Hidden line and surface removal", signalMapperSurface, SLOT(map())); 571 345 572 fDrawingWireframe->setCheckable(true); 346 fDrawingWireframe->setCheckable(true); 573 fDrawingLineRemoval->setCheckable(true); 347 fDrawingLineRemoval->setCheckable(true); 574 fDrawingSurfaceRemoval->setCheckable(true); 348 fDrawingSurfaceRemoval->setCheckable(true); 575 fDrawingLineSurfaceRemoval->setCheckable(tru 349 fDrawingLineSurfaceRemoval->setCheckable(true); 576 350 >> 351 connect(signalMapperSurface, SIGNAL(mapped(int)),this, SLOT(toggleSurfaceAction(int))); >> 352 signalMapperSurface->setMapping(fDrawingWireframe,1); >> 353 signalMapperSurface->setMapping(fDrawingLineRemoval,2); >> 354 signalMapperSurface->setMapping(fDrawingSurfaceRemoval,3); >> 355 signalMapperSurface->setMapping(fDrawingLineSurfaceRemoval,4); >> 356 >> 357 577 // Background Color 358 // Background Color 578 359 579 QAction *backgroundColorChooser ; 360 QAction *backgroundColorChooser ; 580 // === Action Menu === 361 // === Action Menu === 581 backgroundColorChooser = mStyle->addAction(" 362 backgroundColorChooser = mStyle->addAction("Background color"); 582 QObject ::connect(backgroundColorChooser, << 363 QObject ::connect(backgroundColorChooser, 583 SIGNAL(triggered()), 364 SIGNAL(triggered()), 584 this, 365 this, 585 SLOT(actionChangeBackgroun 366 SLOT(actionChangeBackgroundColor())); 586 367 587 // Text Color 368 // Text Color 588 369 589 QAction *textColorChooser ; 370 QAction *textColorChooser ; 590 // === Action Menu === 371 // === Action Menu === 591 textColorChooser = mStyle->addAction("Text c 372 textColorChooser = mStyle->addAction("Text color"); 592 QObject ::connect(textColorChooser, << 373 QObject ::connect(textColorChooser, 593 SIGNAL(triggered()), 374 SIGNAL(triggered()), 594 this, 375 this, 595 SLOT(actionChangeTextColor 376 SLOT(actionChangeTextColor())); 596 377 597 // Default Color 378 // Default Color 598 379 599 QAction *defaultColorChooser ; 380 QAction *defaultColorChooser ; 600 // === Action Menu === 381 // === Action Menu === 601 defaultColorChooser = mStyle->addAction("Def 382 defaultColorChooser = mStyle->addAction("Default color"); 602 QObject ::connect(defaultColorChooser, << 383 QObject ::connect(defaultColorChooser, 603 SIGNAL(triggered()), 384 SIGNAL(triggered()), 604 this, 385 this, 605 SLOT(actionChangeDefaultCo 386 SLOT(actionChangeDefaultColor())); 606 387 607 388 608 // === Action Menu === 389 // === Action Menu === 609 QMenu *mActions = fContextMenu->addMenu("&Ac 390 QMenu *mActions = fContextMenu->addMenu("&Actions"); 610 QAction *createEPS = mActions->addAction("Sa 391 QAction *createEPS = mActions->addAction("Save as ..."); 611 QObject ::connect(createEPS, << 392 QObject ::connect(createEPS, 612 SIGNAL(triggered()), 393 SIGNAL(triggered()), 613 this, 394 this, 614 SLOT(actionSaveImage())); 395 SLOT(actionSaveImage())); 615 396 616 // === Action Menu === 397 // === Action Menu === 617 QAction *movieParameters = mActions->addActi << 398 QAction *movieParameters = mActions->addAction("Movie parameters..."); 618 QObject ::connect(movieParameters, << 399 QObject ::connect(movieParameters, 619 SIGNAL(triggered()), 400 SIGNAL(triggered()), 620 this, 401 this, 621 SLOT(actionMovieParameters 402 SLOT(actionMovieParameters())); 622 403 623 404 624 405 625 406 626 // === Special Menu === 407 // === Special Menu === 627 QMenu *mSpecial = fContextMenu->addMenu("S&p 408 QMenu *mSpecial = fContextMenu->addMenu("S&pecial"); 628 QMenu *mTransparency = mSpecial->addMenu("Tr 409 QMenu *mTransparency = mSpecial->addMenu("Transparency"); 629 QAction *transparencyOn = mTransparency->add 410 QAction *transparencyOn = mTransparency->addAction("On"); 630 QAction *transparencyOff = mTransparency->ad 411 QAction *transparencyOff = mTransparency->addAction("Off"); 631 412 632 if (transparency_enabled == false) { 413 if (transparency_enabled == false) { 633 createRadioAction(transparencyOn,transpare 414 createRadioAction(transparencyOn,transparencyOff,SLOT(toggleTransparency(bool)),2); 634 } else if (transparency_enabled == true) { 415 } else if (transparency_enabled == true) { 635 createRadioAction(transparencyOn,transpare 416 createRadioAction(transparencyOn,transparencyOff,SLOT(toggleTransparency(bool)),1); 636 } else { 417 } else { 637 mSpecial->clear(); 418 mSpecial->clear(); 638 } 419 } 639 420 640 421 641 QMenu *mAntialiasing = mSpecial->addMenu("An 422 QMenu *mAntialiasing = mSpecial->addMenu("Antialiasing"); 642 QAction *antialiasingOn = mAntialiasing->add 423 QAction *antialiasingOn = mAntialiasing->addAction("On"); 643 QAction *antialiasingOff = mAntialiasing->ad 424 QAction *antialiasingOff = mAntialiasing->addAction("Off"); 644 425 645 if (antialiasing_enabled == false) { 426 if (antialiasing_enabled == false) { 646 createRadioAction(antialiasingOn,antialias 427 createRadioAction(antialiasingOn,antialiasingOff,SLOT(toggleAntialiasing(bool)),2); 647 } else if (antialiasing_enabled == true) { 428 } else if (antialiasing_enabled == true) { 648 createRadioAction(antialiasingOn,antialias 429 createRadioAction(antialiasingOn,antialiasingOff,SLOT(toggleAntialiasing(bool)),1); 649 } else { 430 } else { 650 mAntialiasing->clear(); 431 mAntialiasing->clear(); 651 } 432 } 652 433 653 QMenu *mHaloing = mSpecial->addMenu("Haloing 434 QMenu *mHaloing = mSpecial->addMenu("Haloing"); 654 QAction *haloingOn = mHaloing->addAction("On 435 QAction *haloingOn = mHaloing->addAction("On"); 655 QAction *haloingOff = mHaloing->addAction("O 436 QAction *haloingOff = mHaloing->addAction("Off"); 656 if (haloing_enabled == false) { 437 if (haloing_enabled == false) { 657 createRadioAction(haloingOn,haloingOff,SLO 438 createRadioAction(haloingOn,haloingOff,SLOT(toggleHaloing(bool)),2); 658 } else if (haloing_enabled == true) { 439 } else if (haloing_enabled == true) { 659 createRadioAction(haloingOn,haloingOff,SLO 440 createRadioAction(haloingOn,haloingOff,SLOT(toggleHaloing(bool)),1); 660 } else { 441 } else { 661 mHaloing->clear(); 442 mHaloing->clear(); 662 } 443 } 663 444 664 QMenu *mAux = mSpecial->addMenu("Auxiliary e 445 QMenu *mAux = mSpecial->addMenu("Auxiliary edges"); 665 QAction *auxOn = mAux->addAction("On"); 446 QAction *auxOn = mAux->addAction("On"); 666 QAction *auxOff = mAux->addAction("Off"); 447 QAction *auxOff = mAux->addAction("Off"); 667 if (!fVP.IsAuxEdgeVisible()) { 448 if (!fVP.IsAuxEdgeVisible()) { 668 createRadioAction(auxOn,auxOff,SLOT(toggle 449 createRadioAction(auxOn,auxOff,SLOT(toggleAux(bool)),2); 669 } else { 450 } else { 670 createRadioAction(auxOn,auxOff,SLOT(toggle 451 createRadioAction(auxOn,auxOff,SLOT(toggleAux(bool)),1); 671 } 452 } 672 453 673 454 674 QMenu *mHiddenMarkers = mSpecial->addMenu("H 455 QMenu *mHiddenMarkers = mSpecial->addMenu("Hidden markers"); 675 QAction *hiddenMarkersOn = mHiddenMarkers->a 456 QAction *hiddenMarkersOn = mHiddenMarkers->addAction("On"); 676 QAction *hiddenMarkersOff = mHiddenMarkers-> 457 QAction *hiddenMarkersOff = mHiddenMarkers->addAction("Off"); 677 if (fVP.IsMarkerNotHidden()) { 458 if (fVP.IsMarkerNotHidden()) { 678 createRadioAction(hiddenMarkersOn,hiddenMa 459 createRadioAction(hiddenMarkersOn,hiddenMarkersOff,SLOT(toggleHiddenMarkers(bool)),2); 679 } else { 460 } else { 680 createRadioAction(hiddenMarkersOn,hiddenMa 461 createRadioAction(hiddenMarkersOn,hiddenMarkersOff,SLOT(toggleHiddenMarkers(bool)),1); 681 } 462 } 682 463 683 464 684 465 685 QMenu *mFullScreen = mSpecial->addMenu("&Ful 466 QMenu *mFullScreen = mSpecial->addMenu("&Full screen"); 686 fFullScreenOn = mFullScreen->addAction("On") 467 fFullScreenOn = mFullScreen->addAction("On"); 687 fFullScreenOff = mFullScreen->addAction("Off 468 fFullScreenOff = mFullScreen->addAction("Off"); 688 createRadioAction(fFullScreenOn,fFullScreenO 469 createRadioAction(fFullScreenOn,fFullScreenOff,SLOT(toggleFullScreen(bool)),2); 689 470 690 // INIT All 471 // INIT All 691 updateToolbarAndMouseContextMenu(); 472 updateToolbarAndMouseContextMenu(); 692 } 473 } 693 474 >> 475 694 void G4OpenGLQtViewer::G4manageContextMenuEven 476 void G4OpenGLQtViewer::G4manageContextMenuEvent(QContextMenuEvent *e) 695 { 477 { 696 if (!fGLWidget) { << 478 if (!fGLWindow) { 697 G4cerr << "Visualization window not define 479 G4cerr << "Visualization window not defined, please choose one before" << G4endl; 698 } else { 480 } else { 699 << 481 700 if (!fContextMenu) << 482 if (!fContextMenu) 701 createPopupMenu(); 483 createPopupMenu(); 702 << 484 703 // launch menu 485 // launch menu 704 if ( fContextMenu ) { 486 if ( fContextMenu ) { 705 fContextMenu->exec( e->globalPos() ); 487 fContextMenu->exec( e->globalPos() ); 706 // delete fContextMenu; 488 // delete fContextMenu; 707 } 489 } 708 } 490 } 709 e->accept(); 491 e->accept(); 710 } 492 } 711 493 712 494 713 /** 495 /** 714 Create a radio button menu. The two menu wi 496 Create a radio button menu. The two menu will be connected. When click on one, 715 eatch state will be invert and callback met 497 eatch state will be invert and callback method will be called. 716 @param action1 first action to connect 498 @param action1 first action to connect 717 @param action2 second action to connect 499 @param action2 second action to connect 718 @param method callback method 500 @param method callback method 719 @param nCheck: 1 : first action will be set 501 @param nCheck: 1 : first action will be set true. 2 : second action will be set true 720 */ 502 */ 721 void G4OpenGLQtViewer::createRadioAction(QActi 503 void G4OpenGLQtViewer::createRadioAction(QAction *action1,QAction *action2, const std::string& method,unsigned int nCheck) { 722 504 723 action1->setCheckable(true); 505 action1->setCheckable(true); 724 action2->setCheckable(true); 506 action2->setCheckable(true); 725 507 726 if (nCheck ==1) 508 if (nCheck ==1) 727 action1->setChecked (true); 509 action1->setChecked (true); 728 else 510 else 729 action2->setChecked (true); 511 action2->setChecked (true); 730 << 512 731 QObject ::connect(action1, SIGNAL(triggered( 513 QObject ::connect(action1, SIGNAL(triggered(bool)),action2, SLOT(toggle())); 732 QObject ::connect(action2, SIGNAL(triggered( 514 QObject ::connect(action2, SIGNAL(triggered(bool)),action1, SLOT(toggle())); 733 515 734 QObject ::connect(action1, SIGNAL(toggled(bo 516 QObject ::connect(action1, SIGNAL(toggled(bool)),this, method.c_str()); 735 517 736 } 518 } 737 519 738 520 739 521 740 /** 522 /** 741 Show shortcuts for this mouse action 523 Show shortcuts for this mouse action 742 */ 524 */ 743 void G4OpenGLQtViewer::showShortcuts() { 525 void G4OpenGLQtViewer::showShortcuts() { 744 G4String text; 526 G4String text; 745 527 746 text = "========= Mouse Shortcuts =========\ 528 text = "========= Mouse Shortcuts =========\n"; 747 if (fUiQt != NULL) { 529 if (fUiQt != NULL) { 748 if (fUiQt->IsIconRotateSelected()) { // r 530 if (fUiQt->IsIconRotateSelected()) { // rotate 749 text += "Click and move mouse to rotate 531 text += "Click and move mouse to rotate volume \n"; 750 text += "ALT + Click and move mouse to r 532 text += "ALT + Click and move mouse to rotate volume (Toggle View/Theta-Phi Direction) \n"; 751 text += "CTRL + Click and move mouse to 533 text += "CTRL + Click and move mouse to zoom in/out \n"; 752 text += "SHIFT + Click and move mouse to 534 text += "SHIFT + Click and move mouse to change camera point of view \n"; 753 } else if (fUiQt->IsIconMoveSelected()) { 535 } else if (fUiQt->IsIconMoveSelected()) { //move 754 text += "Move camera point of view with 536 text += "Move camera point of view with mouse \n"; 755 } else if (fUiQt->IsIconPickSelected()) { 537 } else if (fUiQt->IsIconPickSelected()) { //pick 756 text += "Click and pick \n"; 538 text += "Click and pick \n"; 757 } 539 } 758 } else { 540 } else { 759 text += "Click and move mouse to rotate vo 541 text += "Click and move mouse to rotate volume \n"; 760 text += "ALT + Click and move mouse to rot 542 text += "ALT + Click and move mouse to rotate volume (Toggle View/Theta-Phi Direction) \n"; 761 text += "CTRL + Click and zoom mouse to zo 543 text += "CTRL + Click and zoom mouse to zoom in/out \n"; 762 text += "SHIFT + Click and zoommove camera 544 text += "SHIFT + Click and zoommove camera point of view \n"; 763 } 545 } 764 text += "========= Move Shortcuts ========= 546 text += "========= Move Shortcuts ========= \n"; 765 text += "Press left/right arrows to move vol 547 text += "Press left/right arrows to move volume left/right \n"; 766 text += "Press up/down arrows to move volume 548 text += "Press up/down arrows to move volume up/down \n"; 767 text += "Press '+'/'-' to move volume toward 549 text += "Press '+'/'-' to move volume toward/forward \n"; 768 text += "\n"; 550 text += "\n"; 769 text += "========= Rotation (Theta/Phi) Shor 551 text += "========= Rotation (Theta/Phi) Shortcuts ========= \n"; 770 text += "Press SHIFT + left/right arrows to 552 text += "Press SHIFT + left/right arrows to rotate volume left/right \n"; 771 text += "Press SHIFT + up/down arrows to rot 553 text += "Press SHIFT + up/down arrows to rotate volume up/down \n"; 772 text += "\n"; 554 text += "\n"; 773 text += "========= Rotation (View Direction) 555 text += "========= Rotation (View Direction) Shortcuts ========= \n"; 774 text += "Press ALT + left/right to rotate vo 556 text += "Press ALT + left/right to rotate volume around vertical direction \n"; 775 text += "Press ALT + up/down to rotate volum 557 text += "Press ALT + up/down to rotate volume around horizontal direction \n"; 776 text += "\n"; 558 text += "\n"; 777 text += "========= Zoom View ========= \n"; 559 text += "========= Zoom View ========= \n"; 778 text += "Press CTRL + '+'/'-' to zoom into v 560 text += "Press CTRL + '+'/'-' to zoom into volume \n"; 779 text += "\n"; 561 text += "\n"; 780 text += "========= Misc ========= \n"; 562 text += "========= Misc ========= \n"; 781 text += "Press ALT +/- to slow/speed rotatio 563 text += "Press ALT +/- to slow/speed rotation/move \n"; 782 text += "Press H to reset view \n"; 564 text += "Press H to reset view \n"; 783 text += "Press Esc to exit FullScreen \n"; 565 text += "Press Esc to exit FullScreen \n"; 784 text += "\n"; 566 text += "\n"; 785 text += "========= Video ========= \n"; 567 text += "========= Video ========= \n"; 786 text += "In video mode : \n"; 568 text += "In video mode : \n"; 787 text += " Press SPACE to Start/Pause video r 569 text += " Press SPACE to Start/Pause video recording \n"; 788 text += " Press RETURN to Stop video recordi 570 text += " Press RETURN to Stop video recording \n"; 789 text += "\n"; 571 text += "\n"; 790 572 791 G4cout << text; 573 G4cout << text; 792 574 793 if ( fShortcutsDialog == NULL) { 575 if ( fShortcutsDialog == NULL) { 794 fShortcutsDialog = new QDialog(); 576 fShortcutsDialog = new QDialog(); 795 fShortcutsDialogInfos = new QTextEdit() ; 577 fShortcutsDialogInfos = new QTextEdit() ; 796 QVBoxLayout *mainLayout = new QVBoxLayout; 578 QVBoxLayout *mainLayout = new QVBoxLayout; 797 mainLayout->addWidget(fShortcutsDialogInfo 579 mainLayout->addWidget(fShortcutsDialogInfos); 798 fShortcutsDialog->setLayout(mainLayout); 580 fShortcutsDialog->setLayout(mainLayout); 799 fShortcutsDialog->setWindowTitle(tr("Short 581 fShortcutsDialog->setWindowTitle(tr("Shortcuts")); 800 } 582 } 801 << 583 802 fShortcutsDialogInfos->setPlainText(text.dat 584 fShortcutsDialogInfos->setPlainText(text.data()); 803 fShortcutsDialog->show(); << 585 fShortcutsDialog->show(); 804 } 586 } 805 587 806 588 807 589 808 /** 590 /** 809 Slot activated when mouse action is toggle 591 Slot activated when mouse action is toggle 810 @param aAction : 1 rotate, 2 move, 3 pick, 592 @param aAction : 1 rotate, 2 move, 3 pick, 4 zoom out, 5 zoom in 811 @see G4OpenGLStoredQtViewer::DrawView 593 @see G4OpenGLStoredQtViewer::DrawView 812 @see G4XXXStoredViewer::CompareForKernelVis 594 @see G4XXXStoredViewer::CompareForKernelVisit 813 */ 595 */ 814 void G4OpenGLQtViewer::toggleMouseAction(int a 596 void G4OpenGLQtViewer::toggleMouseAction(int aAction) { 815 597 816 if (aAction == 1) { 598 if (aAction == 1) { 817 fUiQt->SetIconRotateSelected(); 599 fUiQt->SetIconRotateSelected(); 818 } else if (aAction == 2) { 600 } else if (aAction == 2) { 819 fUiQt->SetIconMoveSelected(); 601 fUiQt->SetIconMoveSelected(); 820 } else if (aAction == 3) { 602 } else if (aAction == 3) { 821 togglePicking(); << 603 fUiQt->SetIconPickSelected(); 822 } else if (aAction == 4) { 604 } else if (aAction == 4) { 823 fUiQt->SetIconZoomOutSelected(); 605 fUiQt->SetIconZoomOutSelected(); 824 } else if (aAction == 5) { 606 } else if (aAction == 5) { 825 fUiQt->SetIconZoomInSelected(); 607 fUiQt->SetIconZoomInSelected(); 826 } 608 } 827 609 828 updateQWidget(); << 829 updateToolbarAndMouseContextMenu(); 610 updateToolbarAndMouseContextMenu(); 830 } 611 } 831 612 832 613 833 /** 614 /** 834 Slot activated when drawing menu is toggle 615 Slot activated when drawing menu is toggle 835 Warning : When G4OpenGLStoredQtViewer::Draw 616 Warning : When G4OpenGLStoredQtViewer::DrawView() method call, 836 KernelVisitDecision () will be call and wil 617 KernelVisitDecision () will be call and will set the fNeedKernelVisit 837 to 1. See G4XXXStoredViewer::CompareForKern 618 to 1. See G4XXXStoredViewer::CompareForKernelVisit for explanations. 838 It will cause a redraw of the view 619 It will cause a redraw of the view 839 @param aAction : 1 wireframe, 2 line remova 620 @param aAction : 1 wireframe, 2 line removal, 3 surface removal, 4 line & surface removal 840 @see G4OpenGLStoredQtViewer::DrawView 621 @see G4OpenGLStoredQtViewer::DrawView 841 @see G4XXXStoredViewer::CompareForKernelVis 622 @see G4XXXStoredViewer::CompareForKernelVisit 842 */ 623 */ 843 void G4OpenGLQtViewer::toggleSurfaceAction(int 624 void G4OpenGLQtViewer::toggleSurfaceAction(int aAction) { 844 625 845 G4ViewParameters::DrawingStyle d_style = G4V 626 G4ViewParameters::DrawingStyle d_style = G4ViewParameters::wireframe; 846 << 627 847 if (aAction ==1) { 628 if (aAction ==1) { 848 d_style = G4ViewParameters::wireframe; 629 d_style = G4ViewParameters::wireframe; 849 630 850 } else if (aAction ==2) { 631 } else if (aAction ==2) { 851 d_style = G4ViewParameters::hlr; 632 d_style = G4ViewParameters::hlr; 852 633 853 } else if (aAction ==3) { 634 } else if (aAction ==3) { 854 d_style = G4ViewParameters::hsr; 635 d_style = G4ViewParameters::hsr; 855 636 856 } else if (aAction ==4) { 637 } else if (aAction ==4) { 857 d_style = G4ViewParameters::hlhsr; 638 d_style = G4ViewParameters::hlhsr; 858 } 639 } 859 fVP.SetDrawingStyle(d_style); 640 fVP.SetDrawingStyle(d_style); 860 641 861 updateToolbarAndMouseContextMenu(); 642 updateToolbarAndMouseContextMenu(); 862 updateQWidget(); 643 updateQWidget(); 863 } 644 } 864 645 865 646 866 /** 647 /** 867 SLOT Activate by a click on the projection 648 SLOT Activate by a click on the projection menu 868 Warning : When G4OpenGLStoredQtViewer::Draw 649 Warning : When G4OpenGLStoredQtViewer::DrawView() method call, 869 KernelVisitDecision () will be call and wil 650 KernelVisitDecision () will be call and will set the fNeedKernelVisit 870 to 1. See G4XXXStoredViewer::CompareForKern 651 to 1. See G4XXXStoredViewer::CompareForKernelVisit for explanations. 871 It will cause a redraw of the view 652 It will cause a redraw of the view 872 @param check : 1 orthographic, 2 perspectiv 653 @param check : 1 orthographic, 2 perspective 873 @see G4OpenGLStoredQtViewer::DrawView 654 @see G4OpenGLStoredQtViewer::DrawView 874 @see G4XXXStoredViewer::CompareForKernelVis 655 @see G4XXXStoredViewer::CompareForKernelVisit 875 */ 656 */ 876 void G4OpenGLQtViewer::toggleProjection(bool c 657 void G4OpenGLQtViewer::toggleProjection(bool check) { 877 658 878 if (check) { << 659 if (check == 1) { 879 fVP.SetOrthogonalProjection (); 660 fVP.SetOrthogonalProjection (); 880 } else { 661 } else { 881 fVP.SetPerspectiveProjection(); 662 fVP.SetPerspectiveProjection(); 882 } << 663 } 883 updateToolbarAndMouseContextMenu(); 664 updateToolbarAndMouseContextMenu(); 884 updateQWidget(); 665 updateQWidget(); 885 } 666 } 886 667 887 668 888 /** 669 /** 889 SLOT Activate by a click on the transparenc 670 SLOT Activate by a click on the transparency menu 890 @param check : 1 , 0 671 @param check : 1 , 0 891 */ 672 */ 892 void G4OpenGLQtViewer::toggleTransparency(bool 673 void G4OpenGLQtViewer::toggleTransparency(bool check) { 893 << 674 894 if (check) { 675 if (check) { 895 transparency_enabled = true; 676 transparency_enabled = true; 896 } else { 677 } else { 897 transparency_enabled = false; 678 transparency_enabled = false; 898 } 679 } 899 SetNeedKernelVisit (true); 680 SetNeedKernelVisit (true); 900 updateToolbarAndMouseContextMenu(); 681 updateToolbarAndMouseContextMenu(); 901 updateQWidget(); 682 updateQWidget(); 902 } 683 } 903 684 904 /** 685 /** 905 SLOT Activate by a click on the antialiasin 686 SLOT Activate by a click on the antialiasing menu 906 @param check : 1 , 0 687 @param check : 1 , 0 907 */ 688 */ 908 void G4OpenGLQtViewer::toggleAntialiasing(bool 689 void G4OpenGLQtViewer::toggleAntialiasing(bool check) { 909 690 910 if (!check) { 691 if (!check) { 911 antialiasing_enabled = false; 692 antialiasing_enabled = false; 912 glDisable (GL_LINE_SMOOTH); 693 glDisable (GL_LINE_SMOOTH); 913 glDisable (GL_POLYGON_SMOOTH); 694 glDisable (GL_POLYGON_SMOOTH); 914 } else { 695 } else { 915 antialiasing_enabled = true; 696 antialiasing_enabled = true; 916 glEnable (GL_LINE_SMOOTH); 697 glEnable (GL_LINE_SMOOTH); 917 glHint (GL_LINE_SMOOTH_HINT, GL_NICEST); 698 glHint (GL_LINE_SMOOTH_HINT, GL_NICEST); 918 glEnable (GL_POLYGON_SMOOTH); 699 glEnable (GL_POLYGON_SMOOTH); 919 glHint (GL_POLYGON_SMOOTH_HINT, GL_NICEST) 700 glHint (GL_POLYGON_SMOOTH_HINT, GL_NICEST); 920 } 701 } 921 702 922 updateToolbarAndMouseContextMenu(); 703 updateToolbarAndMouseContextMenu(); 923 updateQWidget(); 704 updateQWidget(); 924 } 705 } 925 706 926 /** 707 /** 927 SLOT Activate by a click on the haloing men 708 SLOT Activate by a click on the haloing menu 928 @param check : 1 , 0 709 @param check : 1 , 0 929 */ 710 */ 930 //FIXME : I SEE NOTHING... 711 //FIXME : I SEE NOTHING... 931 void G4OpenGLQtViewer::toggleHaloing(bool chec 712 void G4OpenGLQtViewer::toggleHaloing(bool check) { 932 if (check) { 713 if (check) { 933 haloing_enabled = false; 714 haloing_enabled = false; 934 } else { 715 } else { 935 haloing_enabled = true; 716 haloing_enabled = true; 936 } 717 } 937 718 938 updateToolbarAndMouseContextMenu(); 719 updateToolbarAndMouseContextMenu(); 939 updateQWidget(); 720 updateQWidget(); 940 721 941 } 722 } 942 723 943 /** 724 /** 944 SLOT Activate by a click on the auxiliaire 725 SLOT Activate by a click on the auxiliaire edges menu 945 @param check : 1 , 0 726 @param check : 1 , 0 946 */ 727 */ 947 void G4OpenGLQtViewer::toggleAux(bool check) { 728 void G4OpenGLQtViewer::toggleAux(bool check) { 948 if (check) { 729 if (check) { 949 fVP.SetAuxEdgeVisible(true); 730 fVP.SetAuxEdgeVisible(true); 950 } else { 731 } else { 951 fVP.SetAuxEdgeVisible(false); 732 fVP.SetAuxEdgeVisible(false); 952 } 733 } 953 SetNeedKernelVisit (true); 734 SetNeedKernelVisit (true); 954 updateToolbarAndMouseContextMenu(); 735 updateToolbarAndMouseContextMenu(); 955 updateQWidget(); 736 updateQWidget(); 956 } 737 } 957 738 958 << 959 void G4OpenGLQtViewer::togglePicking() { << 960 // FIXME : Not the good way to do, we should << 961 if (fUiQt) { << 962 if (!fVP.IsPicking()) { << 963 fUiQt->SetIconPickSelected(); << 964 } else { << 965 fUiQt->SetIconRotateSelected(); << 966 } << 967 } << 968 << 969 G4UImanager* UI = G4UImanager::GetUIpointer( << 970 if(UI != NULL) { << 971 if (!fVP.IsPicking()) { << 972 UI->ApplyCommand(std::string("/vis/viewe << 973 } else { << 974 UI->ApplyCommand(std::string("/vis/viewe << 975 } << 976 } << 977 << 978 } << 979 << 980 << 981 /** 739 /** 982 SLOT Activate by a click on the hidden mark 740 SLOT Activate by a click on the hidden marker menu 983 @param check : 1 , 0 741 @param check : 1 , 0 984 */ 742 */ 985 void G4OpenGLQtViewer::toggleHiddenMarkers(boo 743 void G4OpenGLQtViewer::toggleHiddenMarkers(bool check) { 986 if (check) { 744 if (check) { 987 fVP.SetMarkerHidden(); 745 fVP.SetMarkerHidden(); 988 } else { 746 } else { 989 fVP.SetMarkerNotHidden(); 747 fVP.SetMarkerNotHidden(); 990 } 748 } 991 // SetNeedKernelVisit (true); 749 // SetNeedKernelVisit (true); 992 updateToolbarAndMouseContextMenu(); 750 updateToolbarAndMouseContextMenu(); 993 updateQWidget(); 751 updateQWidget(); 994 } 752 } 995 753 996 /** 754 /** 997 SLOT Activate by a click on the full screen 755 SLOT Activate by a click on the full screen menu 998 */ 756 */ 999 void G4OpenGLQtViewer::toggleFullScreen(bool c 757 void G4OpenGLQtViewer::toggleFullScreen(bool check) { 1000 if (check != fGLWidget->isFullScreen()) { / << 758 if (check != fGLWindow->isFullScreen()) { //toggle 1001 fGLWidget->setWindowState(fGLWidget->wind << 759 fGLWindow->setWindowState(fGLWindow->windowState() ^ Qt::WindowFullScreen); 1002 } 760 } 1003 } 761 } 1004 762 1005 763 1006 void G4OpenGLQtViewer::savePPMToTemp() { 764 void G4OpenGLQtViewer::savePPMToTemp() { 1007 if (fMovieTempFolderPath == "") { 765 if (fMovieTempFolderPath == "") { 1008 return; 766 return; 1009 } 767 } 1010 auto qGLW = dynamic_cast<G4QGLWidgetType*> << 1011 if (! qGLW) { << 1012 return; << 1013 } << 1014 QString fileName ="Test"+QString::number(fR 768 QString fileName ="Test"+QString::number(fRecordFrameNumber)+".ppm"; 1015 QString filePath =fMovieTempFolderPath+file 769 QString filePath =fMovieTempFolderPath+fileName; 1016 770 1017 QImage image; 771 QImage image; 1018 #if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0)) << 772 image = fWindow->grabFrameBuffer(); 1019 image = qGLW->grabFrameBuffer(); << 1020 #else << 1021 image = qGLW->grabFramebuffer(); << 1022 #endif << 1023 bool res = false; 773 bool res = false; 1024 << 774 1025 res = image.save(filePath,0); 775 res = image.save(filePath,0); 1026 if (res == false) { << 776 if (res == false) { 1027 resetRecording(); 777 resetRecording(); 1028 setRecordingInfos("Can't save tmp file "+ 778 setRecordingInfos("Can't save tmp file "+filePath); 1029 return; 779 return; 1030 } 780 } 1031 << 781 1032 setRecordingInfos("File "+fileName+" saved" 782 setRecordingInfos("File "+fileName+" saved"); 1033 fRecordFrameNumber++; 783 fRecordFrameNumber++; 1034 } 784 } 1035 785 1036 786 1037 787 1038 void G4OpenGLQtViewer::actionSaveImage() { 788 void G4OpenGLQtViewer::actionSaveImage() { 1039 QString filters; 789 QString filters; 1040 for (unsigned int i = 0; i < fExportImageFo << 790 QList<QByteArray> formats = QImageWriter::supportedImageFormats (); 1041 filters += QString("*.") + fExportImageFo << 791 for (int i = 0; i < formats.size(); ++i) { >> 792 filters +=formats.at(i) + ";;"; 1042 } 793 } >> 794 filters += "eps;;"; >> 795 filters += "ps;;"; >> 796 filters += "pdf"; 1043 797 1044 QString* selectedFormat = new QString(fDefa << 798 QString* selectedFormat = new QString(fDefaultSaveFileFormat); 1045 QString qFilename; 799 QString qFilename; 1046 qFilename = QFileDialog::getSaveFileName ( << 800 qFilename = QFileDialog::getSaveFileName ( fGLWindow, 1047 tr(" 801 tr("Save as ..."), 1048 fFil << 802 ".", 1049 filt 803 filters, 1050 sele 804 selectedFormat ); 1051 805 1052 << 806 1053 std::string name = qFilename.toStdString(). 807 std::string name = qFilename.toStdString().c_str(); 1054 808 1055 // bmp jpg jpeg png ppm xbm xpm 809 // bmp jpg jpeg png ppm xbm xpm 1056 if (name.empty()) { 810 if (name.empty()) { 1057 return; 811 return; 1058 } 812 } 1059 813 1060 fFileSavePath = QFileInfo(qFilename).path() 814 fFileSavePath = QFileInfo(qFilename).path(); 1061 << 815 if (! qFilename.endsWith(QString(selectedFormat->toStdString().c_str()),Qt::CaseInsensitive)) { 1062 std::string format = selectedFormat->toLowe << 816 name += "." + selectedFormat->toStdString(); 1063 << 1064 // set the format to current << 1065 fExportImageFormat = format.substr(format.f << 1066 << 1067 std::string filename = name; << 1068 std::string extension = ""; << 1069 if (name.find_last_of(".") != std::string:: << 1070 filename = name.substr(0,name.find_last_o << 1071 extension = name.substr(name.find_last_of << 1072 } else { << 1073 extension = fExportImageFormat; << 1074 } << 1075 << 1076 filename+= "."+ extension; << 1077 << 1078 if (!setExportFilename(filename.c_str(),0)) << 1079 return; << 1080 } 817 } 1081 << 818 1082 G4OpenGLQtExportDialog* exportDialog= new G << 819 QString format = selectedFormat->toLower(); >> 820 >> 821 // set the default format to current >> 822 fDefaultSaveFileFormat = format; >> 823 >> 824 setPrintFilename(name.c_str(),0); >> 825 G4OpenGLQtExportDialog* exportDialog= new G4OpenGLQtExportDialog(fGLWindow,format,fWindow->height(),fWindow->width()); 1083 if( exportDialog->exec()) { 826 if( exportDialog->exec()) { 1084 827 1085 if ((exportDialog->getWidth() !=fGLWidget << 828 QImage image; 1086 (exportDialog->getHeight() !=fGLWidge << 829 bool res = false; 1087 setExportSize(exportDialog->getWidth(), << 830 if ((exportDialog->getWidth() !=fWindow->width()) || 1088 << 831 (exportDialog->getHeight() !=fWindow->height())) { 1089 } << 832 setPrintSize(exportDialog->getWidth(),exportDialog->getHeight()); 1090 if (fExportImageFormat == "eps") { << 833 if ((format != QString("eps")) && (format != QString("ps"))) { >> 834 G4cerr << "Export->Change Size : This function is not implemented, to export in another size, please resize your frame to what you need" << G4endl; >> 835 >> 836 // rescaleImage(exportDialog->getWidth(),exportDialog->getHeight());// re-scale image >> 837 // QGLWidget* glResized = fWindow; >> 838 >> 839 // FIXME : >> 840 // L.Garnier : I've try to implement change size function, but the problem is >> 841 // the renderPixmap function call the QGLWidget to resize and it doesn't draw >> 842 // the content of this widget... It only draw the background. >> 843 >> 844 // fWindow->renderPixmap (exportDialog->getWidth()*2,exportDialog->getHeight()*2,true ); >> 845 >> 846 // QPixmap pixmap = fWindow->renderPixmap (); >> 847 >> 848 // image = pixmap->toImage(); >> 849 // glResized->resize(exportDialog->getWidth()*2,exportDialog->getHeight()*2); >> 850 // image = glResized->grabFrameBuffer(); >> 851 } >> 852 } else { >> 853 image = fWindow->grabFrameBuffer(); >> 854 } >> 855 if (format == QString("eps")) { 1091 fVectoredPs = exportDialog->getVectorEP 856 fVectoredPs = exportDialog->getVectorEPS(); 1092 } else if (fExportImageFormat == "ps") { << 857 printEPS(); >> 858 } else if (format == "ps") { 1093 fVectoredPs = true; 859 fVectoredPs = true; 1094 } << 860 printEPS(); 1095 fLastExportSliderValue = exportDialog->ge << 861 } else if (format == "pdf") { 1096 862 1097 if (exportImage(filename)) { << 863 res = printPDF(name,exportDialog->getNbColor(),image); 1098 // set the default format to current << 864 1099 fDefaultExportImageFormat = format; << 865 } else if ((format == "tif") || >> 866 (format == "tiff") || >> 867 (format == "jpg") || >> 868 (format == "jpeg") || >> 869 (format == "png") || >> 870 (format == "pbm") || >> 871 (format == "pgm") || >> 872 (format == "ppm") || >> 873 (format == "bmp") || >> 874 (format == "xbm") || >> 875 (format == "xpm")) { >> 876 res = image.save(QString(name.c_str()),0,exportDialog->getSliderValue()); >> 877 } else { >> 878 G4cerr << "This version of G4UI Could not generate the selected format" << G4endl; >> 879 } >> 880 if ((format == QString("eps")) && (format == QString("ps"))) { >> 881 if (res == false) { >> 882 G4cerr << "Error while saving file... "<<name.c_str()<< G4endl; >> 883 } else { >> 884 G4cout << "File "<<name.c_str()<<" has been saved " << G4endl; >> 885 } 1100 } 886 } >> 887 1101 } else { // cancel selected 888 } else { // cancel selected 1102 return; 889 return; 1103 } 890 } 1104 << 891 1105 } 892 } 1106 893 1107 894 1108 void G4OpenGLQtViewer::actionChangeBackground 895 void G4OpenGLQtViewer::actionChangeBackgroundColor() { 1109 896 1110 // //I need to revisit the kernel if the 897 // //I need to revisit the kernel if the background colour changes and 1111 // //hidden line removal is enabled, beca 898 // //hidden line removal is enabled, because hlr drawing utilises the 1112 // //background colour in its drawing... 899 // //background colour in its drawing... 1113 // // (Note added by JA 13/9/2005) Backgr 900 // // (Note added by JA 13/9/2005) Background now handled in view 1114 // // parameters. A kernel visit is trig 901 // // parameters. A kernel visit is triggered on change of background. >> 902 >> 903 #if QT_VERSION < 0x040500 >> 904 bool a; >> 905 const QColor color = QColor(QColorDialog::getRgba (QColor(Qt::black).rgba(),&a,fGLWindow)); >> 906 #else 1115 const QColor color = 907 const QColor color = 1116 QColorDialog::getColor(Qt::black, 908 QColorDialog::getColor(Qt::black, 1117 fGLWidget, << 909 fGLWindow, 1118 " Get background c 910 " Get background color and transparency", 1119 QColorDialog::Show 911 QColorDialog::ShowAlphaChannel); >> 912 #endif 1120 if (color.isValid()) { 913 if (color.isValid()) { 1121 G4Colour colour(((G4double)color.red())/2 914 G4Colour colour(((G4double)color.red())/255, 1122 ((G4double)color.green()) 915 ((G4double)color.green())/255, 1123 ((G4double)color.blue())/ 916 ((G4double)color.blue())/255, 1124 ((G4double)color.alpha()) 917 ((G4double)color.alpha())/255); 1125 fVP.SetBackgroundColour(colour); 918 fVP.SetBackgroundColour(colour); 1126 919 1127 updateToolbarAndMouseContextMenu(); 920 updateToolbarAndMouseContextMenu(); 1128 updateQWidget(); 921 updateQWidget(); 1129 } 922 } 1130 } 923 } 1131 924 1132 void G4OpenGLQtViewer::actionChangeTextColor( 925 void G4OpenGLQtViewer::actionChangeTextColor() { >> 926 >> 927 #if QT_VERSION < 0x040500 >> 928 bool a; >> 929 const QColor color = QColor(QColorDialog::getRgba (QColor(Qt::yellow).rgba(),&a,fGLWindow)); >> 930 #else 1133 const QColor& color = 931 const QColor& color = 1134 QColorDialog::getColor(Qt::yellow, 932 QColorDialog::getColor(Qt::yellow, 1135 fGLWidget, << 933 fGLWindow, 1136 " Get text color a 934 " Get text color and transparency", 1137 QColorDialog::Show 935 QColorDialog::ShowAlphaChannel); >> 936 #endif 1138 if (color.isValid()) { 937 if (color.isValid()) { 1139 G4Colour colour(((G4double)color.red())/2 938 G4Colour colour(((G4double)color.red())/255, 1140 ((G4double)color.green()) 939 ((G4double)color.green())/255, 1141 ((G4double)color.blue())/ 940 ((G4double)color.blue())/255, 1142 ((G4double)color.alpha()) 941 ((G4double)color.alpha())/255); 1143 942 1144 fVP.SetDefaultTextColour(colour); 943 fVP.SetDefaultTextColour(colour); 1145 944 1146 updateToolbarAndMouseContextMenu(); 945 updateToolbarAndMouseContextMenu(); 1147 updateQWidget(); 946 updateQWidget(); 1148 } 947 } 1149 } 948 } 1150 949 1151 void G4OpenGLQtViewer::actionChangeDefaultCol 950 void G4OpenGLQtViewer::actionChangeDefaultColor() { >> 951 >> 952 #if QT_VERSION < 0x040500 >> 953 bool a; >> 954 const QColor color = QColor(QColorDialog::getRgba (QColor(Qt::white).rgba(),&a,fGLWindow)); >> 955 #else 1152 const QColor& color = 956 const QColor& color = 1153 QColorDialog::getColor(Qt::white, 957 QColorDialog::getColor(Qt::white, 1154 fGLWidget, << 958 fGLWindow, 1155 " Get default colo 959 " Get default color and transparency", 1156 QColorDialog::Show 960 QColorDialog::ShowAlphaChannel); >> 961 #endif 1157 if (color.isValid()) { 962 if (color.isValid()) { 1158 G4Colour colour(((G4double)color.red())/2 963 G4Colour colour(((G4double)color.red())/255, 1159 ((G4double)color.green()) 964 ((G4double)color.green())/255, 1160 ((G4double)color.blue())/ 965 ((G4double)color.blue())/255, 1161 ((G4double)color.alpha()) 966 ((G4double)color.alpha())/255); 1162 967 1163 fVP.SetDefaultColour(colour); 968 fVP.SetDefaultColour(colour); 1164 969 1165 updateToolbarAndMouseContextMenu(); 970 updateToolbarAndMouseContextMenu(); 1166 updateQWidget(); 971 updateQWidget(); 1167 } 972 } 1168 } 973 } 1169 974 1170 975 1171 void G4OpenGLQtViewer::actionMovieParameters( 976 void G4OpenGLQtViewer::actionMovieParameters() { 1172 showMovieParametersDialog(); 977 showMovieParametersDialog(); 1173 } 978 } 1174 979 1175 980 1176 void G4OpenGLQtViewer::showMovieParametersDia 981 void G4OpenGLQtViewer::showMovieParametersDialog() { 1177 if (!fMovieParametersDialog) { 982 if (!fMovieParametersDialog) { 1178 fMovieParametersDialog= new G4OpenGLQtMov << 983 fMovieParametersDialog= new G4OpenGLQtMovieDialog(this,fGLWindow); 1179 displayRecordingStatus(); 984 displayRecordingStatus(); 1180 fMovieParametersDialog->checkEncoderSwPar 985 fMovieParametersDialog->checkEncoderSwParameters(); 1181 fMovieParametersDialog->checkSaveFileName 986 fMovieParametersDialog->checkSaveFileNameParameters(); 1182 fMovieParametersDialog->checkTempFolderPa 987 fMovieParametersDialog->checkTempFolderParameters(); 1183 if (getEncoderPath() == "") { 988 if (getEncoderPath() == "") { 1184 setRecordingInfos("ppmtompeg is needed 989 setRecordingInfos("ppmtompeg is needed to encode in video format. It is available here: http://netpbm.sourceforge.net "); 1185 } 990 } 1186 } 991 } 1187 fMovieParametersDialog->show(); 992 fMovieParametersDialog->show(); 1188 } 993 } 1189 994 1190 995 >> 996 /* >> 997 // http://www.google.com/codesearch?hl=en&q=+jpg+Qt+quality+QDialog+show:FZkUoth8oiw:TONpW2mR-_c:tyTfrKMO-xI&sa=N&cd=2&ct=rc&cs_p=http://soft.proindependent.com/src/qtiplot-0.8.9.zip&cs_f=qtiplot-0.8.9/qtiplot/src/application.cpp#a0 >> 998 >> 999 void Graph::exportToSVG(const QString& fname) >> 1000 { >> 1001 // enable workaround for Qt3 misalignments >> 1002 QwtPainter::setSVGMode(true); >> 1003 QPicture picture; >> 1004 QPainter p(&picture); >> 1005 d_plot->print(&p, d_plot->rect()); >> 1006 p.end(); >> 1007 >> 1008 picture.save(fname, "svg"); >> 1009 } >> 1010 */ >> 1011 >> 1012 1191 1013 1192 void G4OpenGLQtViewer::FinishView() 1014 void G4OpenGLQtViewer::FinishView() 1193 { 1015 { 1194 /* From Apple doc: << 1195 CGLFlushDrawable : Copies the back buffer o << 1196 If the backing store attribute is set to fa << 1197 */ << 1198 glFlush (); 1016 glFlush (); 1199 1017 1200 // L. Garnier 10/2009 : Not necessary and c 1018 // L. Garnier 10/2009 : Not necessary and cause problems on mac OS X 10.6 1201 // fGLWidget->swapBuffers (); << 1019 // fWindow->swapBuffers (); 1202 } 1020 } 1203 1021 1204 /** 1022 /** 1205 Save the current mouse press point 1023 Save the current mouse press point 1206 @param p mouse click point 1024 @param p mouse click point 1207 */ 1025 */ 1208 void G4OpenGLQtViewer::G4MousePressEvent(QMou 1026 void G4OpenGLQtViewer::G4MousePressEvent(QMouseEvent *evnt) 1209 { 1027 { 1210 if (evnt->button() == Qt::RightButton) { 1028 if (evnt->button() == Qt::RightButton) { 1211 return; 1029 return; 1212 } 1030 } 1213 if ((evnt->button() & Qt::LeftButton) && (! 1031 if ((evnt->button() & Qt::LeftButton) && (! (evnt->modifiers() & Qt::ControlModifier ))){ 1214 fGLWidget->setMouseTracking(true); << 1032 fWindow->setMouseTracking(true); 1215 fAutoMove = false; // stop automove 1033 fAutoMove = false; // stop automove 1216 fLastPos1 = evnt->pos(); 1034 fLastPos1 = evnt->pos(); 1217 fLastPos2 = fLastPos1; 1035 fLastPos2 = fLastPos1; 1218 fLastPos3 = fLastPos2; 1036 fLastPos3 = fLastPos2; 1219 fLastEventTime->start(); 1037 fLastEventTime->start(); 1220 if (fUiQt != NULL) { 1038 if (fUiQt != NULL) { 1221 1039 1222 if (fUiQt->IsIconZoomInSelected()) { / << 1040 if (fUiQt->IsIconPickSelected()){ // pick >> 1041 fVP.SetPicking(true); >> 1042 Pick(evnt->pos().x(),evnt->pos().y()); >> 1043 fVP.SetPicking(false); >> 1044 >> 1045 } else if (fUiQt->IsIconZoomInSelected()) { // zoomIn 1223 // Move click point to center of OGL 1046 // Move click point to center of OGL 1224 1047 1225 float deltaX = ((float)getWinWidth()/ 1048 float deltaX = ((float)getWinWidth()/2-evnt->pos().x()); 1226 float deltaY = ((float)getWinHeight() 1049 float deltaY = ((float)getWinHeight()/2-evnt->pos().y()); 1227 1050 1228 G4double coefTrans = 0; 1051 G4double coefTrans = 0; 1229 coefTrans = ((G4double)getSceneNearWi 1052 coefTrans = ((G4double)getSceneNearWidth())/((G4double)getWinWidth()); 1230 if (getWinHeight() <getWinWidth()) { 1053 if (getWinHeight() <getWinWidth()) { 1231 coefTrans = ((G4double)getSceneNear 1054 coefTrans = ((G4double)getSceneNearWidth())/((G4double)getWinHeight()); 1232 } 1055 } 1233 fVP.IncrementPan(-deltaX*coefTrans,de 1056 fVP.IncrementPan(-deltaX*coefTrans,deltaY*coefTrans,0); 1234 fVP.SetZoomFactor(1.5 * fVP.GetZoomFa 1057 fVP.SetZoomFactor(1.5 * fVP.GetZoomFactor()); 1235 << 1058 1236 updateQWidget(); 1059 updateQWidget(); 1237 << 1060 1238 } else if (fUiQt->IsIconZoomOutSelected 1061 } else if (fUiQt->IsIconZoomOutSelected()) { // zoomOut 1239 // Move click point to center of OGL 1062 // Move click point to center of OGL 1240 moveScene(((float)getWinWidth()/2-evn 1063 moveScene(((float)getWinWidth()/2-evnt->pos().x()),((float)getWinHeight()/2-evnt->pos().y()),0,true); 1241 1064 1242 fVP.SetZoomFactor(0.75 * fVP.GetZoomF 1065 fVP.SetZoomFactor(0.75 * fVP.GetZoomFactor()); 1243 updateQWidget(); 1066 updateQWidget(); 1244 1067 1245 } else if (fUiQt->IsIconRotateSelected( << 1246 << 1247 if (fShiftKeyPress) { // move << 1248 fGLWidget->setCursor(QCursor(Qt::Si << 1249 << 1250 } else { // rotate << 1251 fGLWidget->setCursor(QCursor(Qt::Cl << 1252 } << 1253 } else if (fUiQt->IsIconMoveSelected()) << 1254 fGLWidget->setCursor(QCursor(Qt::Size << 1255 } else if (fUiQt->IsIconPickSelected()) << 1256 fGLWidget->setCursor(QCursor(Qt::Poin << 1257 } 1068 } 1258 } 1069 } 1259 } 1070 } 1260 } 1071 } 1261 1072 1262 /** 1073 /** 1263 */ 1074 */ 1264 void G4OpenGLQtViewer::G4MouseReleaseEvent(QM << 1075 void G4OpenGLQtViewer::G4MouseReleaseEvent() 1265 { 1076 { 1266 #if QT_VERSION < 0x060000 << 1077 fSpinningDelay = fLastEventTime->elapsed(); 1267 #else << 1078 QPoint delta = (fLastPos3-fLastPos1); 1268 {auto* qGLW = dynamic_cast<G4QGLWidgetType*> << 1079 if ((delta.x() == 0) && (delta.y() == 0)) { 1269 if (qGLW) qGLW->makeCurrent();} << 1080 return; 1270 ResizeGLView(); << 1081 } 1271 #endif << 1082 if (fSpinningDelay < fLaunchSpinDelay ) { 1272 GLint viewport[4]; << 1273 glGetIntegerv(GL_VIEWPORT, viewport); << 1274 << 1275 // factorX == factorY << 1276 double factorX = ((double)viewport[2]/fGLW << 1277 double factorY = ((double)viewport[3]/fGLW << 1278 fSpinningDelay = (int)fLastEventTime->elaps << 1279 QPoint delta = (fLastPos3-fLastPos1)*factor << 1280 << 1281 // reset cursor state << 1282 fGLWidget->setCursor(QCursor(Qt::ArrowCurso << 1283 << 1284 if (fVP.IsPicking()){ // pick << 1285 if ((delta.x() != 0) || (delta.y() != 0)) << 1286 return; << 1287 } << 1288 updatePickInfosWidget(evnt->pos().x()*fac << 1289 << 1290 } else if (fSpinningDelay < fLaunchSpinDela << 1291 if ((delta.x() == 0) && (delta.y() == 0)) << 1292 return; << 1293 } << 1294 << 1295 fAutoMove = true; 1083 fAutoMove = true; 1296 #if (QT_VERSION < QT_VERSION_CHECK(5, 14, 0)) << 1297 QTime lastMoveTime; 1084 QTime lastMoveTime; 1298 #else << 1299 QElapsedTimer lastMoveTime; << 1300 #endif << 1301 lastMoveTime.start(); 1085 lastMoveTime.start(); 1302 // try to addapt speed move/rotate lookin 1086 // try to addapt speed move/rotate looking to drawing speed 1303 float correctionFactor = 5; 1087 float correctionFactor = 5; 1304 while (fAutoMove) { 1088 while (fAutoMove) { 1305 if ( lastMoveTime.elapsed() >= (int)(10 1089 if ( lastMoveTime.elapsed() >= (int)(1000/fNbMaxFramesPerSec)) { 1306 float lTime = 1000.0f/lastMoveTime.el << 1090 float lTime = 1000/lastMoveTime.elapsed(); 1307 if (((((float)delta.x())/correctionFa 1091 if (((((float)delta.x())/correctionFactor)*lTime > fNbMaxAnglePerSec) || 1308 ((((float)delta.x())/correctionFa 1092 ((((float)delta.x())/correctionFactor)*lTime < -fNbMaxAnglePerSec) ) { 1309 correctionFactor = (float)delta.x() 1093 correctionFactor = (float)delta.x()*(lTime/fNbMaxAnglePerSec); 1310 if (delta.x() <0 ) { 1094 if (delta.x() <0 ) { 1311 correctionFactor = -correctionFac 1095 correctionFactor = -correctionFactor; 1312 } 1096 } 1313 } 1097 } 1314 if (((((float)delta.y())/correctionFa 1098 if (((((float)delta.y())/correctionFactor)*lTime > fNbMaxAnglePerSec) || 1315 ((((float)delta.y())/correctionFa 1099 ((((float)delta.y())/correctionFactor)*lTime < -fNbMaxAnglePerSec) ) { 1316 correctionFactor = (float)delta.y() 1100 correctionFactor = (float)delta.y()*(lTime/fNbMaxAnglePerSec); 1317 if (delta.y() <0 ) { 1101 if (delta.y() <0 ) { 1318 correctionFactor = -correctionFac 1102 correctionFactor = -correctionFactor; 1319 } 1103 } 1320 } 1104 } 1321 << 1105 1322 // Check Qt Versions for META Keys 1106 // Check Qt Versions for META Keys 1323 << 1107 1324 // Click and move mouse to rotate vol 1108 // Click and move mouse to rotate volume 1325 // ALT + Click and move mouse to rota 1109 // ALT + Click and move mouse to rotate volume (View Direction) 1326 // SHIFT + Click and move camera poin 1110 // SHIFT + Click and move camera point of view 1327 // CTRL + Click and zoom mouse to zoo 1111 // CTRL + Click and zoom mouse to zoom in/out 1328 1112 1329 lastMoveTime.start(); 1113 lastMoveTime.start(); 1330 1114 1331 bool rotate = false; 1115 bool rotate = false; 1332 bool move = false; 1116 bool move = false; 1333 1117 1334 if (fUiQt != NULL) { 1118 if (fUiQt != NULL) { 1335 if (fUiQt->IsIconRotateSelected()) 1119 if (fUiQt->IsIconRotateSelected()) { // rotate 1336 rotate = true; 1120 rotate = true; 1337 } else if (fUiQt->IsIconMoveSelecte 1121 } else if (fUiQt->IsIconMoveSelected()) { // move 1338 move = true; 1122 move = true; 1339 } 1123 } 1340 } else { 1124 } else { 1341 rotate = true; 1125 rotate = true; 1342 } 1126 } 1343 // prevent from closing widget when r << 1344 if (fIsDeleting) { << 1345 return; << 1346 } << 1347 << 1348 if (rotate) { // rotate 1127 if (rotate) { // rotate 1349 if (fNoKeyPress) { 1128 if (fNoKeyPress) { 1350 rotateQtScene(((float)delta.x())/ 1129 rotateQtScene(((float)delta.x())/correctionFactor,((float)delta.y())/correctionFactor); 1351 } else if (fAltKeyPress) { 1130 } else if (fAltKeyPress) { 1352 rotateQtSceneToggle(((float)delta 1131 rotateQtSceneToggle(((float)delta.x())/correctionFactor,((float)delta.y())/correctionFactor); 1353 } 1132 } 1354 << 1133 #ifdef G4DEBUG_VIS_OGL >> 1134 fNbRotation ++; >> 1135 fTimeRotation += lastMoveTime.elapsed(); >> 1136 printf("G4OpenGLQtViewer %f \n",fTimeRotation/(float)fNbRotation); >> 1137 #endif >> 1138 1355 } else if (move) { // move 1139 } else if (move) { // move 1356 moveScene(-((float)delta.x())/corre 1140 moveScene(-((float)delta.x())/correctionFactor,-((float)delta.y())/correctionFactor,0,true); 1357 } 1141 } 1358 } 1142 } 1359 ((QApplication*)G4Qt::getInstance ())-> 1143 ((QApplication*)G4Qt::getInstance ())->processEvents(); 1360 } 1144 } 1361 } 1145 } 1362 fGLWidget->setMouseTracking(false); << 1146 fWindow->setMouseTracking(false); 1363 1147 1364 } 1148 } 1365 1149 1366 1150 1367 void G4OpenGLQtViewer::G4MouseDoubleClickEven 1151 void G4OpenGLQtViewer::G4MouseDoubleClickEvent() 1368 { 1152 { 1369 fGLWidget->setMouseTracking(true); << 1153 fWindow->setMouseTracking(true); 1370 } 1154 } 1371 1155 1372 1156 1373 /** 1157 /** 1374 @param pos_x mouse x position 1158 @param pos_x mouse x position 1375 @param pos_y mouse y position 1159 @param pos_y mouse y position 1376 @param mButtons mouse button active 1160 @param mButtons mouse button active 1377 @param mAutoMove true: apply this move til 1161 @param mAutoMove true: apply this move till another evnt came, false :one time move 1378 */ 1162 */ 1379 1163 1380 void G4OpenGLQtViewer::G4MouseMoveEvent(QMous 1164 void G4OpenGLQtViewer::G4MouseMoveEvent(QMouseEvent *evnt) 1381 { 1165 { 1382 1166 1383 Qt::MouseButtons mButtons = evnt->buttons() 1167 Qt::MouseButtons mButtons = evnt->buttons(); 1384 1168 1385 updateKeyModifierState(evnt->modifiers()); 1169 updateKeyModifierState(evnt->modifiers()); 1386 1170 1387 if (fAutoMove) { 1171 if (fAutoMove) { 1388 return; 1172 return; 1389 } 1173 } 1390 1174 1391 fLastPos3 = fLastPos2; 1175 fLastPos3 = fLastPos2; 1392 fLastPos2 = fLastPos1; 1176 fLastPos2 = fLastPos1; 1393 << 1394 #if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0)) << 1395 fLastPos1 = QPoint(evnt->x(), evnt->y()); 1177 fLastPos1 = QPoint(evnt->x(), evnt->y()); 1396 #else << 1397 fLastPos1 = QPoint(evnt->position().x(), ev << 1398 #endif << 1399 1178 1400 int deltaX = fLastPos2.x()-fLastPos1.x(); 1179 int deltaX = fLastPos2.x()-fLastPos1.x(); 1401 int deltaY = fLastPos2.y()-fLastPos1.y(); 1180 int deltaY = fLastPos2.y()-fLastPos1.y(); 1402 1181 >> 1182 bool rotate = false; 1403 bool move = false; 1183 bool move = false; 1404 if (fUiQt != NULL) { 1184 if (fUiQt != NULL) { 1405 if (fUiQt->IsIconMoveSelected()) { // mo << 1185 if (fUiQt->IsIconRotateSelected()) { // rotate >> 1186 rotate = true; >> 1187 } else if (fUiQt->IsIconMoveSelected()) { // move 1406 move = true; 1188 move = true; 1407 } 1189 } >> 1190 } else { >> 1191 rotate = true; 1408 } 1192 } 1409 if (!move) { // rotate, pick, zoom... << 1193 if (rotate) { // rotate 1410 if (mButtons & Qt::LeftButton) { 1194 if (mButtons & Qt::LeftButton) { 1411 if (fNoKeyPress) { 1195 if (fNoKeyPress) { 1412 rotateQtScene(((float)deltaX),((float 1196 rotateQtScene(((float)deltaX),((float)deltaY)); 1413 } else if (fAltKeyPress) { 1197 } else if (fAltKeyPress) { 1414 rotateQtSceneToggle(((float)deltaX),( 1198 rotateQtSceneToggle(((float)deltaX),((float)deltaY)); 1415 } else if (fShiftKeyPress) { 1199 } else if (fShiftKeyPress) { 1416 unsigned int sizeWin; 1200 unsigned int sizeWin; 1417 sizeWin = getWinWidth(); 1201 sizeWin = getWinWidth(); 1418 if (getWinHeight() < getWinWidth()) { 1202 if (getWinHeight() < getWinWidth()) { 1419 sizeWin = getWinHeight(); 1203 sizeWin = getWinHeight(); 1420 } 1204 } 1421 1205 1422 // L.Garnier : 08/2010 100 is the goo 1206 // L.Garnier : 08/2010 100 is the good value, but don't ask me why ! 1423 float factor = ((float)100/(float)siz 1207 float factor = ((float)100/(float)sizeWin) ; 1424 moveScene(-(float)deltaX*factor,-(flo 1208 moveScene(-(float)deltaX*factor,-(float)deltaY*factor,0,false); 1425 } else if (fControlKeyPress) { 1209 } else if (fControlKeyPress) { 1426 fVP.SetZoomFactor(fVP.GetZoomFactor() << 1210 fVP.SetZoomFactor(fVP.GetZoomFactor()*(1+((float)deltaY))); 1427 } 1211 } 1428 } 1212 } 1429 } else if (move) { // move 1213 } else if (move) { // move 1430 if (mButtons & Qt::LeftButton) { 1214 if (mButtons & Qt::LeftButton) { 1431 moveScene(-(float)deltaX,-(float)deltaY 1215 moveScene(-(float)deltaX,-(float)deltaY,0,true); 1432 } 1216 } 1433 } 1217 } 1434 1218 1435 fLastEventTime->start(); 1219 fLastEventTime->start(); 1436 } 1220 } 1437 1221 1438 1222 1439 /** 1223 /** 1440 Move the scene of dx, dy, dz values. 1224 Move the scene of dx, dy, dz values. 1441 @param dx delta mouse x position 1225 @param dx delta mouse x position 1442 @param dy delta mouse y position 1226 @param dy delta mouse y position 1443 @param mouseMove : true if event comes fro 1227 @param mouseMove : true if event comes from a mouse move, false if event comes from key action 1444 */ 1228 */ 1445 1229 1446 void G4OpenGLQtViewer::moveScene(float dx,flo 1230 void G4OpenGLQtViewer::moveScene(float dx,float dy, float dz,bool mouseMove) 1447 { 1231 { 1448 if (fHoldMoveEvent) 1232 if (fHoldMoveEvent) 1449 return; 1233 return; 1450 fHoldMoveEvent = true; 1234 fHoldMoveEvent = true; 1451 1235 1452 G4double coefTrans = 0; 1236 G4double coefTrans = 0; 1453 GLdouble coefDepth = 0; 1237 GLdouble coefDepth = 0; 1454 if(mouseMove) { 1238 if(mouseMove) { 1455 coefTrans = ((G4double)getSceneNearWidth( 1239 coefTrans = ((G4double)getSceneNearWidth())/((G4double)getWinWidth()); 1456 if (getWinHeight() <getWinWidth()) { 1240 if (getWinHeight() <getWinWidth()) { 1457 coefTrans = ((G4double)getSceneNearWidt 1241 coefTrans = ((G4double)getSceneNearWidth())/((G4double)getWinHeight()); 1458 } 1242 } 1459 } else { 1243 } else { 1460 coefTrans = getSceneNearWidth()*fPan_sens 1244 coefTrans = getSceneNearWidth()*fPan_sens; 1461 coefDepth = getSceneDepth()*fDeltaDepth; 1245 coefDepth = getSceneDepth()*fDeltaDepth; 1462 } 1246 } 1463 fVP.IncrementPan(-dx*coefTrans,dy*coefTrans 1247 fVP.IncrementPan(-dx*coefTrans,dy*coefTrans,dz*coefDepth); 1464 << 1248 1465 updateQWidget(); 1249 updateQWidget(); 1466 if (fAutoMove) 1250 if (fAutoMove) 1467 ((QApplication*)G4Qt::getInstance ())->pr 1251 ((QApplication*)G4Qt::getInstance ())->processEvents(); 1468 << 1252 1469 fHoldMoveEvent = false; 1253 fHoldMoveEvent = false; 1470 } 1254 } 1471 1255 1472 1256 1473 /** 1257 /** 1474 @param dx delta mouse x position 1258 @param dx delta mouse x position 1475 @param dy delta mouse y position 1259 @param dy delta mouse y position 1476 */ 1260 */ 1477 1261 1478 void G4OpenGLQtViewer::rotateQtScene(float dx 1262 void G4OpenGLQtViewer::rotateQtScene(float dx, float dy) 1479 { 1263 { 1480 if (fHoldRotateEvent) 1264 if (fHoldRotateEvent) 1481 return; 1265 return; 1482 fHoldRotateEvent = true; 1266 fHoldRotateEvent = true; 1483 << 1267 1484 rotateScene(dx,dy); 1268 rotateScene(dx,dy); 1485 1269 1486 updateQWidget(); 1270 updateQWidget(); 1487 << 1271 1488 fHoldRotateEvent = false; 1272 fHoldRotateEvent = false; 1489 } 1273 } 1490 1274 1491 /** 1275 /** 1492 @param dx delta mouse x position 1276 @param dx delta mouse x position 1493 @param dy delta mouse y position 1277 @param dy delta mouse y position 1494 */ 1278 */ 1495 1279 1496 void G4OpenGLQtViewer::rotateQtSceneToggle(fl 1280 void G4OpenGLQtViewer::rotateQtSceneToggle(float dx, float dy) 1497 { 1281 { 1498 if (fHoldRotateEvent) 1282 if (fHoldRotateEvent) 1499 return; 1283 return; 1500 fHoldRotateEvent = true; 1284 fHoldRotateEvent = true; 1501 << 1285 1502 rotateSceneToggle(dx,dy); 1286 rotateSceneToggle(dx,dy); 1503 1287 1504 updateQWidget(); 1288 updateQWidget(); 1505 << 1289 1506 fHoldRotateEvent = false; 1290 fHoldRotateEvent = false; 1507 } 1291 } 1508 1292 1509 1293 1510 1294 1511 1295 1512 1296 1513 /** This is the benning of a rescale function 1297 /** This is the benning of a rescale function. It does nothing for the moment 1514 @param aWidth : new width 1298 @param aWidth : new width 1515 @param aHeight : new height 1299 @param aHeight : new height 1516 */ 1300 */ 1517 void G4OpenGLQtViewer::rescaleImage( 1301 void G4OpenGLQtViewer::rescaleImage( 1518 int /* aWidth */ 1302 int /* aWidth */ 1519 ,int /* aHeight */ 1303 ,int /* aHeight */ 1520 ){ 1304 ){ 1521 // GLfloat* feedback_buffer; 1305 // GLfloat* feedback_buffer; 1522 // GLint returned; 1306 // GLint returned; 1523 // FILE* file; 1307 // FILE* file; 1524 << 1308 1525 // feedback_buffer = new GLfloat[size]; 1309 // feedback_buffer = new GLfloat[size]; 1526 // glFeedbackBuffer (size, GL_3D_COLOR, f 1310 // glFeedbackBuffer (size, GL_3D_COLOR, feedback_buffer); 1527 // glRenderMode (GL_FEEDBACK); 1311 // glRenderMode (GL_FEEDBACK); 1528 << 1312 1529 // DrawView(); 1313 // DrawView(); 1530 // returned = glRenderMode (GL_RENDER); 1314 // returned = glRenderMode (GL_RENDER); 1531 1315 1532 } 1316 } 1533 1317 1534 1318 1535 1319 1536 << 1320 /** 1537 void G4OpenGLQtViewer::G4wheelEvent (QWheelEv << 1321 Generate Postscript or PDF form image >> 1322 @param aFilename : name of file >> 1323 @param aInColor : numbers of colors : 1->BW 2->RGB >> 1324 @param aImage : Image to print >> 1325 */ >> 1326 bool G4OpenGLQtViewer::printPDF ( >> 1327 const std::string aFilename >> 1328 ,int aInColor >> 1329 ,QImage aImage >> 1330 ) 1538 { 1331 { 1539 #if (QT_VERSION < QT_VERSION_CHECK(5, 15, 0)) << 1332 1540 fVP.SetZoomFactor(fVP.GetZoomFactor()+(fVP. << 1333 QPrinter printer; >> 1334 // printer.setPageSize(pageSize); >> 1335 >> 1336 // FIXME : L. Garnier 4/12/07 >> 1337 // This is not working, it does nothing. Image is staying in color mode >> 1338 // So I have desactivate the B/W button in GUI >> 1339 if ((!aImage.isGrayscale ()) &&(aInColor ==1 )) { >> 1340 aImage = aImage.convertToFormat ( aImage.format(), Qt::MonoOnly); >> 1341 } >> 1342 >> 1343 >> 1344 if (aFilename.substr(aFilename.size()-3) == ".ps") { >> 1345 #if QT_VERSION > 0x040200 >> 1346 #if QT_VERSION < 0x050000 >> 1347 printer.setOutputFormat(QPrinter::PostScriptFormat); >> 1348 #else >> 1349 G4cout << "Output in postscript not implemented in this Qt version" << G4endl; >> 1350 #endif 1541 #else 1351 #else 1542 fVP.SetZoomFactor(fVP.GetZoomFactor()+(fVP. << 1352 G4cout << "Output in postscript not implemented in this Qt version" << G4endl; 1543 #endif 1353 #endif >> 1354 } else { >> 1355 #if QT_VERSION > 0x040100 >> 1356 printer.setOutputFormat(QPrinter::PdfFormat); >> 1357 #endif >> 1358 } >> 1359 #if QT_VERSION > 0x040100 >> 1360 printer.setOutputFileName(QString(aFilename.c_str())); >> 1361 #endif >> 1362 // printer.setFullPage ( true); >> 1363 QPainter paint(&printer); >> 1364 paint.drawImage (0,0,aImage); >> 1365 paint.end(); >> 1366 return true; >> 1367 } >> 1368 >> 1369 >> 1370 void G4OpenGLQtViewer::G4wheelEvent (QWheelEvent * evnt) >> 1371 { >> 1372 fVP.SetZoomFactor(fVP.GetZoomFactor()+(fVP.GetZoomFactor()*(evnt->delta())/1200)); 1544 updateQWidget(); 1373 updateQWidget(); 1545 } 1374 } 1546 1375 1547 1376 1548 void G4OpenGLQtViewer::G4keyPressEvent (QKeyE << 1377 void G4OpenGLQtViewer::G4keyPressEvent (QKeyEvent * evnt) 1549 { 1378 { 1550 if (fHoldKeyEvent) 1379 if (fHoldKeyEvent) 1551 return; 1380 return; 1552 1381 1553 fHoldKeyEvent = true; 1382 fHoldKeyEvent = true; 1554 1383 1555 << 1384 1556 // with no modifiers 1385 // with no modifiers 1557 updateKeyModifierState(evnt->modifiers()); 1386 updateKeyModifierState(evnt->modifiers()); 1558 if ((fNoKeyPress) || (evnt->modifiers() == 1387 if ((fNoKeyPress) || (evnt->modifiers() == Qt::KeypadModifier )) { 1559 if (evnt->key() == Qt::Key_Down) { // go 1388 if (evnt->key() == Qt::Key_Down) { // go down 1560 moveScene(0,1,0,false); 1389 moveScene(0,1,0,false); 1561 } 1390 } 1562 else if (evnt->key() == Qt::Key_Up) { // 1391 else if (evnt->key() == Qt::Key_Up) { // go up 1563 moveScene(0,-1,0,false); 1392 moveScene(0,-1,0,false); 1564 } 1393 } 1565 if (evnt->key() == Qt::Key_Left) { // go 1394 if (evnt->key() == Qt::Key_Left) { // go left 1566 moveScene(-1,0,0,false); 1395 moveScene(-1,0,0,false); 1567 } 1396 } 1568 else if (evnt->key() == Qt::Key_Right) { 1397 else if (evnt->key() == Qt::Key_Right) { // go right 1569 moveScene(1,0,0,false); 1398 moveScene(1,0,0,false); 1570 } 1399 } 1571 if (evnt->key() == Qt::Key_Minus) { // go 1400 if (evnt->key() == Qt::Key_Minus) { // go backward 1572 moveScene(0,0,1,false); 1401 moveScene(0,0,1,false); 1573 } 1402 } 1574 else if (evnt->key() == Qt::Key_Plus) { / 1403 else if (evnt->key() == Qt::Key_Plus) { // go forward 1575 moveScene(0,0,-1,false); 1404 moveScene(0,0,-1,false); 1576 } 1405 } >> 1406 1577 // escaped from full screen 1407 // escaped from full screen 1578 if (evnt->key() == Qt::Key_Escape) { 1408 if (evnt->key() == Qt::Key_Escape) { 1579 toggleFullScreen(false); 1409 toggleFullScreen(false); 1580 } 1410 } 1581 } << 1411 } 1582 // several case here : If return is pressed 1412 // several case here : If return is pressed, in every case -> display the movie parameters dialog 1583 // If one parameter is wrong -> put it in r 1413 // If one parameter is wrong -> put it in red (only save filenam could be wrong..) 1584 // If encoder not found-> does nothing.Only 1414 // If encoder not found-> does nothing.Only display a message in status box 1585 // If all ok-> generate parameter file 1415 // If all ok-> generate parameter file 1586 // If ok -> put encoder button enabled 1416 // If ok -> put encoder button enabled 1587 << 1417 1588 if ((evnt->key() == Qt::Key_Return) || (evn 1418 if ((evnt->key() == Qt::Key_Return) || (evnt->key() == Qt::Key_Enter)){ // end of video 1589 stopVideo(); 1419 stopVideo(); 1590 } 1420 } 1591 if (evnt->key() == Qt::Key_Space){ // start 1421 if (evnt->key() == Qt::Key_Space){ // start/pause of video 1592 startPauseVideo(); 1422 startPauseVideo(); 1593 } 1423 } 1594 << 1424 1595 // H : Return Home view 1425 // H : Return Home view 1596 if (evnt->key() == Qt::Key_H){ // go Home 1426 if (evnt->key() == Qt::Key_H){ // go Home 1597 ResetView(); 1427 ResetView(); 1598 1428 1599 updateQWidget(); 1429 updateQWidget(); 1600 } 1430 } 1601 1431 1602 // Shift Modifier 1432 // Shift Modifier 1603 if (fShiftKeyPress) { 1433 if (fShiftKeyPress) { 1604 fGLWidget->setCursor(QCursor(Qt::SizeAllC << 1605 << 1606 if (evnt->key() == Qt::Key_Down) { // rot 1434 if (evnt->key() == Qt::Key_Down) { // rotate phi 1607 rotateQtScene(0,-fRot_sens); 1435 rotateQtScene(0,-fRot_sens); 1608 } 1436 } 1609 else if (evnt->key() == Qt::Key_Up) { // 1437 else if (evnt->key() == Qt::Key_Up) { // rotate phi 1610 rotateQtScene(0,fRot_sens); 1438 rotateQtScene(0,fRot_sens); 1611 } 1439 } 1612 if (evnt->key() == Qt::Key_Left) { // rot 1440 if (evnt->key() == Qt::Key_Left) { // rotate theta 1613 rotateQtScene(fRot_sens,0); 1441 rotateQtScene(fRot_sens,0); 1614 } 1442 } 1615 else if (evnt->key() == Qt::Key_Right) { 1443 else if (evnt->key() == Qt::Key_Right) { // rotate theta 1616 rotateQtScene(-fRot_sens,0); 1444 rotateQtScene(-fRot_sens,0); 1617 } 1445 } 1618 if (evnt->key() == Qt::Key_Plus) { // go << 1446 if (evnt->key() == Qt::Key_Plus) { // go forward ("Plus" imply 1619 // "Shift" on Mac French keyboard 1447 // "Shift" on Mac French keyboard 1620 moveScene(0,0,-1,false); 1448 moveScene(0,0,-1,false); 1621 } 1449 } 1622 1450 1623 // Alt Modifier 1451 // Alt Modifier 1624 } 1452 } 1625 if ((fAltKeyPress)) { 1453 if ((fAltKeyPress)) { 1626 fGLWidget->setCursor(QCursor(Qt::ClosedHa << 1627 << 1628 if (evnt->key() == Qt::Key_Down) { // rot 1454 if (evnt->key() == Qt::Key_Down) { // rotate phi 1629 rotateQtSceneToggle(0,-fRot_sens); 1455 rotateQtSceneToggle(0,-fRot_sens); 1630 } 1456 } 1631 else if (evnt->key() == Qt::Key_Up) { // 1457 else if (evnt->key() == Qt::Key_Up) { // rotate phi 1632 rotateQtSceneToggle(0,fRot_sens); 1458 rotateQtSceneToggle(0,fRot_sens); 1633 } 1459 } 1634 if (evnt->key() == Qt::Key_Left) { // rot 1460 if (evnt->key() == Qt::Key_Left) { // rotate theta 1635 rotateQtSceneToggle(fRot_sens,0); 1461 rotateQtSceneToggle(fRot_sens,0); 1636 } 1462 } 1637 else if (evnt->key() == Qt::Key_Right) { 1463 else if (evnt->key() == Qt::Key_Right) { // rotate theta 1638 rotateQtSceneToggle(-fRot_sens,0); 1464 rotateQtSceneToggle(-fRot_sens,0); 1639 } 1465 } 1640 1466 1641 // Rotatio +/- 1467 // Rotatio +/- 1642 if (evnt->key() == Qt::Key_Plus) { 1468 if (evnt->key() == Qt::Key_Plus) { 1643 fRot_sens = fRot_sens/0.7; 1469 fRot_sens = fRot_sens/0.7; 1644 G4cout << "Auto-rotation set to : " << 1470 G4cout << "Auto-rotation set to : " << fRot_sens << G4endl; 1645 } 1471 } 1646 else if (evnt->key() == Qt::Key_Minus) { 1472 else if (evnt->key() == Qt::Key_Minus) { 1647 fRot_sens = fRot_sens*0.7; 1473 fRot_sens = fRot_sens*0.7; 1648 G4cout << "Auto-rotation set to : " << 1474 G4cout << "Auto-rotation set to : " << fRot_sens << G4endl; 1649 } 1475 } 1650 1476 1651 // Control Modifier OR Command on MAC 1477 // Control Modifier OR Command on MAC 1652 } 1478 } 1653 if ((fControlKeyPress)) { 1479 if ((fControlKeyPress)) { 1654 if (evnt->key() == Qt::Key_Plus) { 1480 if (evnt->key() == Qt::Key_Plus) { 1655 fVP.SetZoomFactor(fVP.GetZoomFactor()*( << 1481 fVP.SetZoomFactor(fVP.GetZoomFactor()*(1+fDeltaZoom)); 1656 updateQWidget(); 1482 updateQWidget(); 1657 } 1483 } 1658 else if (evnt->key() == Qt::Key_Minus) { 1484 else if (evnt->key() == Qt::Key_Minus) { 1659 fVP.SetZoomFactor(fVP.GetZoomFactor()*( << 1485 fVP.SetZoomFactor(fVP.GetZoomFactor()*(1-fDeltaZoom)); 1660 updateQWidget(); 1486 updateQWidget(); 1661 } 1487 } 1662 } << 1488 } 1663 << 1489 1664 fHoldKeyEvent = false; 1490 fHoldKeyEvent = false; 1665 } 1491 } 1666 << 1492 1667 << 1668 void G4OpenGLQtViewer::G4keyReleaseEvent (QKe << 1669 { << 1670 fGLWidget->setCursor(QCursor(Qt::ArrowCurso << 1671 } << 1672 << 1673 1493 1674 void G4OpenGLQtViewer::updateKeyModifierStat 1494 void G4OpenGLQtViewer::updateKeyModifierState(const Qt::KeyboardModifiers& modifier) { 1675 // Check Qt Versions for META Keys 1495 // Check Qt Versions for META Keys 1676 << 1496 1677 fNoKeyPress = true; 1497 fNoKeyPress = true; 1678 fAltKeyPress = false; 1498 fAltKeyPress = false; 1679 fShiftKeyPress = false; 1499 fShiftKeyPress = false; 1680 fControlKeyPress = false; 1500 fControlKeyPress = false; 1681 << 1501 1682 if (modifier & Qt::AltModifier ) { 1502 if (modifier & Qt::AltModifier ) { 1683 fAltKeyPress = true; 1503 fAltKeyPress = true; 1684 fNoKeyPress = false; 1504 fNoKeyPress = false; 1685 } 1505 } 1686 if (modifier & Qt::ShiftModifier ) { 1506 if (modifier & Qt::ShiftModifier ) { 1687 fShiftKeyPress = true; 1507 fShiftKeyPress = true; 1688 fNoKeyPress = false; 1508 fNoKeyPress = false; 1689 } 1509 } 1690 if (modifier & Qt::ControlModifier ) { 1510 if (modifier & Qt::ControlModifier ) { 1691 fControlKeyPress = true; 1511 fControlKeyPress = true; 1692 fNoKeyPress = false; 1512 fNoKeyPress = false; 1693 } 1513 } 1694 } 1514 } 1695 1515 1696 1516 1697 /** Stop the video. Check all parameters and 1517 /** Stop the video. Check all parameters and enable encoder button if all is ok. 1698 */ 1518 */ 1699 void G4OpenGLQtViewer::stopVideo() { 1519 void G4OpenGLQtViewer::stopVideo() { 1700 1520 1701 // if encoder parameter is wrong, display p 1521 // if encoder parameter is wrong, display parameters dialog and return 1702 if (!fMovieParametersDialog) { 1522 if (!fMovieParametersDialog) { 1703 showMovieParametersDialog(); 1523 showMovieParametersDialog(); 1704 } 1524 } 1705 setRecordingStatus(STOP); 1525 setRecordingStatus(STOP); 1706 1526 1707 if (fRecordFrameNumber >0) { 1527 if (fRecordFrameNumber >0) { 1708 // check parameters if they were modified 1528 // check parameters if they were modified (Re APPLY them...) 1709 if (!(fMovieParametersDialog->checkEncode 1529 if (!(fMovieParametersDialog->checkEncoderSwParameters())) { 1710 setRecordingStatus(BAD_ENCODER); 1530 setRecordingStatus(BAD_ENCODER); 1711 } else if (!(fMovieParametersDialog->che 1531 } else if (!(fMovieParametersDialog->checkSaveFileNameParameters())) { 1712 setRecordingStatus(BAD_OUTPUT); 1532 setRecordingStatus(BAD_OUTPUT); 1713 } 1533 } 1714 } else { 1534 } else { 1715 resetRecording(); 1535 resetRecording(); 1716 setRecordingInfos("No frame to encode."); 1536 setRecordingInfos("No frame to encode."); 1717 } 1537 } 1718 } 1538 } 1719 1539 1720 /** Stop the video. Check all parameters and 1540 /** Stop the video. Check all parameters and enable encoder button if all is ok. 1721 */ 1541 */ 1722 void G4OpenGLQtViewer::saveVideo() { 1542 void G4OpenGLQtViewer::saveVideo() { 1723 1543 1724 // if encoder parameter is wrong, display p 1544 // if encoder parameter is wrong, display parameters dialog and return 1725 if (!fMovieParametersDialog) { 1545 if (!fMovieParametersDialog) { 1726 showMovieParametersDialog(); 1546 showMovieParametersDialog(); 1727 } 1547 } 1728 1548 1729 fMovieParametersDialog->checkEncoderSwParam 1549 fMovieParametersDialog->checkEncoderSwParameters(); 1730 fMovieParametersDialog->checkSaveFileNamePa 1550 fMovieParametersDialog->checkSaveFileNameParameters(); 1731 << 1551 1732 if (fRecordingStep == STOP) { 1552 if (fRecordingStep == STOP) { 1733 setRecordingStatus(SAVE); 1553 setRecordingStatus(SAVE); 1734 generateMpegEncoderParameters(); 1554 generateMpegEncoderParameters(); 1735 encodeVideo(); 1555 encodeVideo(); 1736 } 1556 } 1737 } 1557 } 1738 1558 1739 1559 1740 /** Start/Pause the video.. 1560 /** Start/Pause the video.. 1741 */ 1561 */ 1742 void G4OpenGLQtViewer::startPauseVideo() { 1562 void G4OpenGLQtViewer::startPauseVideo() { 1743 << 1563 1744 // first time, if temp parameter is wrong, 1564 // first time, if temp parameter is wrong, display parameters dialog and return 1745 1565 1746 if ( fRecordingStep == WAIT) { 1566 if ( fRecordingStep == WAIT) { 1747 if ( fRecordFrameNumber == 0) { 1567 if ( fRecordFrameNumber == 0) { 1748 if (getTempFolderPath() == "") { // BAD 1568 if (getTempFolderPath() == "") { // BAD_OUTPUT 1749 showMovieParametersDialog(); 1569 showMovieParametersDialog(); 1750 setRecordingInfos("You should specifi 1570 setRecordingInfos("You should specified the temp folder in order to make movie"); 1751 return; 1571 return; 1752 } else { 1572 } else { 1753 // remove temp folder if it was creat 1573 // remove temp folder if it was create 1754 QString tmp = removeTempFolder(); 1574 QString tmp = removeTempFolder(); 1755 if (tmp !="") { 1575 if (tmp !="") { 1756 setRecordingInfos(tmp); 1576 setRecordingInfos(tmp); 1757 return; 1577 return; 1758 } 1578 } 1759 tmp = createTempFolder(); 1579 tmp = createTempFolder(); 1760 if (tmp != "") { 1580 if (tmp != "") { 1761 setRecordingInfos("Can't create tem 1581 setRecordingInfos("Can't create temp folder."+tmp); 1762 return; 1582 return; 1763 } 1583 } 1764 } 1584 } 1765 } 1585 } 1766 } 1586 } 1767 if (fRecordingStep == WAIT) { 1587 if (fRecordingStep == WAIT) { 1768 setRecordingStatus(START); << 1588 setRecordingStatus(START); 1769 } else if (fRecordingStep == START) { 1589 } else if (fRecordingStep == START) { 1770 setRecordingStatus(PAUSE); 1590 setRecordingStatus(PAUSE); 1771 } else if (fRecordingStep == PAUSE) { 1591 } else if (fRecordingStep == PAUSE) { 1772 setRecordingStatus(CONTINUE); 1592 setRecordingStatus(CONTINUE); 1773 } else if (fRecordingStep == CONTINUE) { 1593 } else if (fRecordingStep == CONTINUE) { 1774 setRecordingStatus(PAUSE); 1594 setRecordingStatus(PAUSE); 1775 } 1595 } 1776 } 1596 } 1777 1597 1778 void G4OpenGLQtViewer::setRecordingStatus(REC 1598 void G4OpenGLQtViewer::setRecordingStatus(RECORDING_STEP step) { 1779 1599 1780 fRecordingStep = step; 1600 fRecordingStep = step; 1781 displayRecordingStatus(); 1601 displayRecordingStatus(); 1782 } 1602 } 1783 1603 1784 1604 1785 void G4OpenGLQtViewer::displayRecordingStatus 1605 void G4OpenGLQtViewer::displayRecordingStatus() { 1786 << 1606 1787 QString txtStatus = ""; 1607 QString txtStatus = ""; 1788 if (fRecordingStep == WAIT) { 1608 if (fRecordingStep == WAIT) { 1789 txtStatus = "Waiting to start..."; 1609 txtStatus = "Waiting to start..."; 1790 fRecordFrameNumber = 0; // reset the fram 1610 fRecordFrameNumber = 0; // reset the frame number 1791 } else if (fRecordingStep == START) { 1611 } else if (fRecordingStep == START) { 1792 txtStatus = "Start Recording..."; 1612 txtStatus = "Start Recording..."; 1793 } else if (fRecordingStep == PAUSE) { 1613 } else if (fRecordingStep == PAUSE) { 1794 txtStatus = "Pause Recording..."; 1614 txtStatus = "Pause Recording..."; 1795 } else if (fRecordingStep == CONTINUE) { 1615 } else if (fRecordingStep == CONTINUE) { 1796 txtStatus = "Continue Recording..."; 1616 txtStatus = "Continue Recording..."; 1797 } else if (fRecordingStep == STOP) { 1617 } else if (fRecordingStep == STOP) { 1798 txtStatus = "Stop Recording..."; 1618 txtStatus = "Stop Recording..."; 1799 } else if (fRecordingStep == READY_TO_ENCOD 1619 } else if (fRecordingStep == READY_TO_ENCODE) { 1800 txtStatus = "Ready to Encode..."; 1620 txtStatus = "Ready to Encode..."; 1801 } else if (fRecordingStep == ENCODING) { 1621 } else if (fRecordingStep == ENCODING) { 1802 txtStatus = "Encoding..."; 1622 txtStatus = "Encoding..."; 1803 } else if (fRecordingStep == FAILED) { 1623 } else if (fRecordingStep == FAILED) { 1804 txtStatus = "Failed to encode..."; 1624 txtStatus = "Failed to encode..."; 1805 } else if ((fRecordingStep == BAD_ENCODER) 1625 } else if ((fRecordingStep == BAD_ENCODER) 1806 || (fRecordingStep == BAD_OUTPUT 1626 || (fRecordingStep == BAD_OUTPUT) 1807 || (fRecordingStep == BAD_TMP)) 1627 || (fRecordingStep == BAD_TMP)) { 1808 txtStatus = "Correct above errors first" 1628 txtStatus = "Correct above errors first"; 1809 } else if (fRecordingStep == SUCCESS) { 1629 } else if (fRecordingStep == SUCCESS) { 1810 txtStatus = "File encoded successfully"; 1630 txtStatus = "File encoded successfully"; 1811 } else { 1631 } else { 1812 } 1632 } 1813 1633 1814 if (fMovieParametersDialog) { 1634 if (fMovieParametersDialog) { 1815 fMovieParametersDialog->setRecordingStatu 1635 fMovieParametersDialog->setRecordingStatus(txtStatus); 1816 } else { 1636 } else { 1817 G4cout << txtStatus.toStdString().c_str() 1637 G4cout << txtStatus.toStdString().c_str() << G4endl; 1818 } 1638 } 1819 setRecordingInfos(""); 1639 setRecordingInfos(""); 1820 } 1640 } 1821 1641 1822 1642 1823 void G4OpenGLQtViewer::setRecordingInfos(cons 1643 void G4OpenGLQtViewer::setRecordingInfos(const QString& txt) { 1824 if (fMovieParametersDialog) { 1644 if (fMovieParametersDialog) { 1825 fMovieParametersDialog->setRecordingInfos 1645 fMovieParametersDialog->setRecordingInfos(txt); 1826 } else { 1646 } else { 1827 G4cout << txt.toStdString().c_str() << G4 1647 G4cout << txt.toStdString().c_str() << G4endl; 1828 } 1648 } 1829 } 1649 } 1830 1650 1831 /** Init the movie parameters. Temp dir and e 1651 /** Init the movie parameters. Temp dir and encoder path 1832 */ 1652 */ 1833 void G4OpenGLQtViewer::initMovieParameters() 1653 void G4OpenGLQtViewer::initMovieParameters() { 1834 //init encoder 1654 //init encoder 1835 << 1655 1836 //look for encoderPath 1656 //look for encoderPath 1837 fProcess = new QProcess(); 1657 fProcess = new QProcess(); 1838 << 1658 1839 QObject ::connect(fProcess,SIGNAL(finished 1659 QObject ::connect(fProcess,SIGNAL(finished ( int)), 1840 this,SLOT(processLookForF 1660 this,SLOT(processLookForFinished())); 1841 fProcess->setProcessChannelMode(QProcess::M << 1661 fProcess->setReadChannelMode(QProcess::MergedChannels); 1842 #if (QT_VERSION < QT_VERSION_CHECK(5, 15, 0)) << 1843 fProcess->start ("which ppmtompeg"); 1662 fProcess->start ("which ppmtompeg"); 1844 #else << 1663 1845 fProcess->start ("which ppmtompeg", QString << 1846 #endif << 1847 } 1664 } 1848 1665 1849 /** @return encoder path or "" if it does not 1666 /** @return encoder path or "" if it does not exist 1850 */ 1667 */ 1851 QString G4OpenGLQtViewer::getEncoderPath() { 1668 QString G4OpenGLQtViewer::getEncoderPath() { 1852 return fEncoderPath; 1669 return fEncoderPath; 1853 } 1670 } 1854 << 1671 1855 1672 1856 /** 1673 /** 1857 * set the new encoder path 1674 * set the new encoder path 1858 * @return "" if correct. The error otherwise 1675 * @return "" if correct. The error otherwise 1859 */ 1676 */ 1860 QString G4OpenGLQtViewer::setEncoderPath(QStr 1677 QString G4OpenGLQtViewer::setEncoderPath(QString path) { 1861 if (path == "") { 1678 if (path == "") { 1862 return "ppmtompeg is needed to encode in << 1679 return "File does not exist"; 1863 } 1680 } 1864 1681 1865 path = QDir::cleanPath(path); 1682 path = QDir::cleanPath(path); 1866 QFileInfo *f = new QFileInfo(path); 1683 QFileInfo *f = new QFileInfo(path); 1867 if (!f->exists()) { 1684 if (!f->exists()) { 1868 return "File does not exist"; 1685 return "File does not exist"; 1869 } else if (f->isDir()) { 1686 } else if (f->isDir()) { 1870 return "This is a directory"; 1687 return "This is a directory"; 1871 } else if (!f->isExecutable()) { 1688 } else if (!f->isExecutable()) { 1872 return "File exist but is not executable" 1689 return "File exist but is not executable"; 1873 } else if (!f->isFile()) { 1690 } else if (!f->isFile()) { 1874 return "This is not a file"; 1691 return "This is not a file"; 1875 } 1692 } 1876 fEncoderPath = path; 1693 fEncoderPath = path; 1877 1694 1878 if (fRecordingStep == BAD_ENCODER) { 1695 if (fRecordingStep == BAD_ENCODER) { 1879 setRecordingStatus(STOP); 1696 setRecordingStatus(STOP); 1880 } << 1697 } 1881 return ""; 1698 return ""; 1882 } 1699 } 1883 1700 1884 1701 1885 bool G4OpenGLQtViewer::isRecording(){ 1702 bool G4OpenGLQtViewer::isRecording(){ 1886 if ((fRecordingStep == START) || (fRecordin 1703 if ((fRecordingStep == START) || (fRecordingStep == CONTINUE)) { 1887 return true; 1704 return true; 1888 } 1705 } 1889 return false; 1706 return false; 1890 } 1707 } 1891 1708 1892 bool G4OpenGLQtViewer::isPaused(){ 1709 bool G4OpenGLQtViewer::isPaused(){ 1893 if (fRecordingStep == PAUSE) { 1710 if (fRecordingStep == PAUSE) { 1894 return true; 1711 return true; 1895 } 1712 } 1896 return false; 1713 return false; 1897 } 1714 } 1898 1715 1899 bool G4OpenGLQtViewer::isEncoding(){ 1716 bool G4OpenGLQtViewer::isEncoding(){ 1900 if (fRecordingStep == ENCODING) { 1717 if (fRecordingStep == ENCODING) { 1901 return true; 1718 return true; 1902 } 1719 } 1903 return false; 1720 return false; 1904 } 1721 } 1905 1722 1906 bool G4OpenGLQtViewer::isWaiting(){ 1723 bool G4OpenGLQtViewer::isWaiting(){ 1907 if (fRecordingStep == WAIT) { 1724 if (fRecordingStep == WAIT) { 1908 return true; 1725 return true; 1909 } 1726 } 1910 return false; 1727 return false; 1911 } 1728 } 1912 1729 1913 bool G4OpenGLQtViewer::isStopped(){ 1730 bool G4OpenGLQtViewer::isStopped(){ 1914 if (fRecordingStep == STOP) { 1731 if (fRecordingStep == STOP) { 1915 return true; 1732 return true; 1916 } 1733 } 1917 return false; 1734 return false; 1918 } 1735 } 1919 1736 1920 bool G4OpenGLQtViewer::isFailed(){ 1737 bool G4OpenGLQtViewer::isFailed(){ 1921 if (fRecordingStep == FAILED) { 1738 if (fRecordingStep == FAILED) { 1922 return true; 1739 return true; 1923 } 1740 } 1924 return false; 1741 return false; 1925 } 1742 } 1926 1743 1927 bool G4OpenGLQtViewer::isSuccess(){ 1744 bool G4OpenGLQtViewer::isSuccess(){ 1928 if (fRecordingStep == SUCCESS) { 1745 if (fRecordingStep == SUCCESS) { 1929 return true; 1746 return true; 1930 } 1747 } 1931 return false; 1748 return false; 1932 } 1749 } 1933 1750 1934 bool G4OpenGLQtViewer::isBadEncoder(){ 1751 bool G4OpenGLQtViewer::isBadEncoder(){ 1935 if (fRecordingStep == BAD_ENCODER) { 1752 if (fRecordingStep == BAD_ENCODER) { 1936 return true; 1753 return true; 1937 } 1754 } 1938 return false; 1755 return false; 1939 } 1756 } 1940 bool G4OpenGLQtViewer::isBadTmp(){ 1757 bool G4OpenGLQtViewer::isBadTmp(){ 1941 if (fRecordingStep == BAD_TMP) { 1758 if (fRecordingStep == BAD_TMP) { 1942 return true; 1759 return true; 1943 } 1760 } 1944 return false; 1761 return false; 1945 } 1762 } 1946 bool G4OpenGLQtViewer::isBadOutput(){ 1763 bool G4OpenGLQtViewer::isBadOutput(){ 1947 if (fRecordingStep == BAD_OUTPUT) { 1764 if (fRecordingStep == BAD_OUTPUT) { 1948 return true; 1765 return true; 1949 } 1766 } 1950 return false; 1767 return false; 1951 } 1768 } 1952 1769 1953 void G4OpenGLQtViewer::setBadEncoder(){ 1770 void G4OpenGLQtViewer::setBadEncoder(){ 1954 fRecordingStep = BAD_ENCODER; 1771 fRecordingStep = BAD_ENCODER; 1955 displayRecordingStatus(); 1772 displayRecordingStatus(); 1956 } 1773 } 1957 void G4OpenGLQtViewer::setBadTmp(){ 1774 void G4OpenGLQtViewer::setBadTmp(){ 1958 fRecordingStep = BAD_TMP; 1775 fRecordingStep = BAD_TMP; 1959 displayRecordingStatus(); 1776 displayRecordingStatus(); 1960 } 1777 } 1961 void G4OpenGLQtViewer::setBadOutput(){ 1778 void G4OpenGLQtViewer::setBadOutput(){ 1962 fRecordingStep = BAD_OUTPUT; 1779 fRecordingStep = BAD_OUTPUT; 1963 displayRecordingStatus(); 1780 displayRecordingStatus(); 1964 } 1781 } 1965 1782 1966 void G4OpenGLQtViewer::setWaiting(){ 1783 void G4OpenGLQtViewer::setWaiting(){ 1967 fRecordingStep = WAIT; 1784 fRecordingStep = WAIT; 1968 displayRecordingStatus(); 1785 displayRecordingStatus(); 1969 } 1786 } 1970 1787 1971 1788 1972 bool G4OpenGLQtViewer::isReadyToEncode(){ 1789 bool G4OpenGLQtViewer::isReadyToEncode(){ 1973 if (fRecordingStep == READY_TO_ENCODE) { 1790 if (fRecordingStep == READY_TO_ENCODE) { 1974 return true; 1791 return true; 1975 } 1792 } 1976 return false; 1793 return false; 1977 } 1794 } 1978 1795 1979 void G4OpenGLQtViewer::resetRecording() { 1796 void G4OpenGLQtViewer::resetRecording() { 1980 setRecordingStatus(WAIT); 1797 setRecordingStatus(WAIT); 1981 } 1798 } 1982 1799 1983 /** 1800 /** 1984 * set the temp folder path 1801 * set the temp folder path 1985 * @return "" if correct. The error otherwise 1802 * @return "" if correct. The error otherwise 1986 */ 1803 */ 1987 QString G4OpenGLQtViewer::setTempFolderPath(Q 1804 QString G4OpenGLQtViewer::setTempFolderPath(QString path) { 1988 1805 1989 if (path == "") { 1806 if (path == "") { 1990 return "Path does not exist"; 1807 return "Path does not exist"; 1991 } 1808 } 1992 path = QDir::cleanPath(path); 1809 path = QDir::cleanPath(path); 1993 QFileInfo *d = new QFileInfo(path); 1810 QFileInfo *d = new QFileInfo(path); 1994 if (!d->exists()) { 1811 if (!d->exists()) { 1995 return "Path does not exist"; 1812 return "Path does not exist"; 1996 } else if (!d->isDir()) { 1813 } else if (!d->isDir()) { 1997 return "This is not a directory"; 1814 return "This is not a directory"; 1998 } else if (!d->isReadable()) { 1815 } else if (!d->isReadable()) { 1999 return path +" is read protected"; 1816 return path +" is read protected"; 2000 } else if (!d->isWritable()) { 1817 } else if (!d->isWritable()) { 2001 return path +" is write protected"; 1818 return path +" is write protected"; 2002 } 1819 } 2003 << 1820 2004 if (fRecordingStep == BAD_TMP) { 1821 if (fRecordingStep == BAD_TMP) { 2005 setRecordingStatus(WAIT); << 1822 setRecordingStatus(WAIT); 2006 } 1823 } 2007 fTempFolderPath = path; 1824 fTempFolderPath = path; 2008 return ""; 1825 return ""; 2009 } 1826 } 2010 1827 2011 /** @return the temp folder path or "" if it 1828 /** @return the temp folder path or "" if it does not exist 2012 */ 1829 */ 2013 QString G4OpenGLQtViewer::getTempFolderPath() 1830 QString G4OpenGLQtViewer::getTempFolderPath() { 2014 return fTempFolderPath; 1831 return fTempFolderPath; 2015 } 1832 } 2016 << 1833 2017 /** 1834 /** 2018 * set the save file name path 1835 * set the save file name path 2019 * @return "" if correct. The error otherwise 1836 * @return "" if correct. The error otherwise 2020 */ 1837 */ 2021 QString G4OpenGLQtViewer::setSaveFileName(QSt 1838 QString G4OpenGLQtViewer::setSaveFileName(QString path) { 2022 1839 2023 if (path == "") { 1840 if (path == "") { 2024 return "Path does not exist"; 1841 return "Path does not exist"; 2025 } 1842 } 2026 << 1843 2027 QFileInfo *file = new QFileInfo(path); 1844 QFileInfo *file = new QFileInfo(path); 2028 QDir dir = file->dir(); 1845 QDir dir = file->dir(); 2029 path = QDir::cleanPath(path); 1846 path = QDir::cleanPath(path); 2030 if (file->exists()) { 1847 if (file->exists()) { 2031 return "File already exist, please choose 1848 return "File already exist, please choose a new one"; 2032 } else if (!dir.exists()) { 1849 } else if (!dir.exists()) { 2033 return "Dir does not exist"; 1850 return "Dir does not exist"; 2034 } else if (!dir.isReadable()) { 1851 } else if (!dir.isReadable()) { 2035 return path +" is read protected"; 1852 return path +" is read protected"; 2036 } 1853 } 2037 << 1854 2038 if (fRecordingStep == BAD_OUTPUT) { 1855 if (fRecordingStep == BAD_OUTPUT) { 2039 setRecordingStatus(STOP); << 1856 setRecordingStatus(STOP); 2040 } 1857 } 2041 fSaveFileName = path; 1858 fSaveFileName = path; 2042 return ""; 1859 return ""; 2043 } 1860 } 2044 1861 2045 /** @return the save file path 1862 /** @return the save file path 2046 */ 1863 */ 2047 QString G4OpenGLQtViewer::getSaveFileName() { 1864 QString G4OpenGLQtViewer::getSaveFileName() { 2048 return fSaveFileName ; 1865 return fSaveFileName ; 2049 } 1866 } 2050 1867 2051 /** Create a Qt_temp folder in the temp folde 1868 /** Create a Qt_temp folder in the temp folder given 2052 * The temp folder will be like this /tmp/QtM 1869 * The temp folder will be like this /tmp/QtMovie_12-02-2008_12_12_58/ 2053 * @return "" if success. Error message if no 1870 * @return "" if success. Error message if not. 2054 */ 1871 */ 2055 QString G4OpenGLQtViewer::createTempFolder() 1872 QString G4OpenGLQtViewer::createTempFolder() { 2056 fMovieTempFolderPath = ""; 1873 fMovieTempFolderPath = ""; 2057 //check 1874 //check 2058 QString tmp = setTempFolderPath(fTempFolder 1875 QString tmp = setTempFolderPath(fTempFolderPath); 2059 if (tmp != "") { 1876 if (tmp != "") { 2060 return tmp; 1877 return tmp; 2061 } 1878 } 2062 QString sep = QString(QDir::separator()); 1879 QString sep = QString(QDir::separator()); 2063 QString path = sep+"QtMovie_"+QDateTime::cu << 1880 QString path = sep+"QtMovie_"+QDateTime::currentDateTime ().toString("dd-MM-yyyy_hh-mm-ss")+sep; 2064 QDir *d = new QDir(QDir::cleanPath(fTempFol 1881 QDir *d = new QDir(QDir::cleanPath(fTempFolderPath)); 2065 // check if it is already present 1882 // check if it is already present 2066 if (d->exists(path)) { 1883 if (d->exists(path)) { 2067 return "Folder "+path+" already exists.Pl 1884 return "Folder "+path+" already exists.Please remove it first"; 2068 } 1885 } 2069 if (d->mkdir(fTempFolderPath+path)) { 1886 if (d->mkdir(fTempFolderPath+path)) { 2070 fMovieTempFolderPath = fTempFolderPath+pa 1887 fMovieTempFolderPath = fTempFolderPath+path; 2071 return ""; 1888 return ""; 2072 } 1889 } 2073 return "Can't create "+fTempFolderPath+path 1890 return "Can't create "+fTempFolderPath+path; 2074 } 1891 } 2075 1892 2076 /** Remove the Qt_temp folder in the temp fol 1893 /** Remove the Qt_temp folder in the temp folder 2077 */ 1894 */ 2078 QString G4OpenGLQtViewer::removeTempFolder() 1895 QString G4OpenGLQtViewer::removeTempFolder() { 2079 // remove files in Qt_temp folder 1896 // remove files in Qt_temp folder 2080 if (fMovieTempFolderPath == "") { 1897 if (fMovieTempFolderPath == "") { 2081 return ""; 1898 return ""; 2082 } 1899 } 2083 QDir *d = new QDir(QDir::cleanPath(fMovieTe 1900 QDir *d = new QDir(QDir::cleanPath(fMovieTempFolderPath)); 2084 if (!d->exists()) { 1901 if (!d->exists()) { 2085 return ""; // already remove 1902 return ""; // already remove 2086 } 1903 } 2087 1904 2088 d->setFilter( QDir::Files ); 1905 d->setFilter( QDir::Files ); 2089 QStringList subDirList = d->entryList(); 1906 QStringList subDirList = d->entryList(); 2090 int res = true; 1907 int res = true; 2091 QString error = ""; 1908 QString error = ""; 2092 for (QStringList::ConstIterator it = subDir 1909 for (QStringList::ConstIterator it = subDirList.begin() ;(it != subDirList.end()) ; it++) { 2093 const QString currentFile = *it; 1910 const QString currentFile = *it; 2094 if (!d->remove(currentFile)) { 1911 if (!d->remove(currentFile)) { 2095 res = false; 1912 res = false; 2096 QString file = fMovieTempFolderPath+cur 1913 QString file = fMovieTempFolderPath+currentFile; 2097 error +="Removing file failed : "+file; 1914 error +="Removing file failed : "+file; 2098 } else { 1915 } else { 2099 } 1916 } 2100 } 1917 } 2101 if (res) { 1918 if (res) { 2102 if (d->rmdir(fMovieTempFolderPath)) { 1919 if (d->rmdir(fMovieTempFolderPath)) { 2103 fMovieTempFolderPath = ""; 1920 fMovieTempFolderPath = ""; 2104 return ""; 1921 return ""; 2105 } else { 1922 } else { 2106 return "Dir "+fMovieTempFolderPath+" sh 1923 return "Dir "+fMovieTempFolderPath+" should be empty, but could not remove it"; 2107 } 1924 } 2108 1925 2109 } 1926 } 2110 return "Could not remove "+fMovieTempFolder 1927 return "Could not remove "+fMovieTempFolderPath+" because of the following errors :"+error; 2111 } 1928 } 2112 1929 2113 /** << 2114 Export image. Try to get the format accordi << 2115 If not present, the last one choosen by /vi << 2116 If not, will take the default format : eps << 2117 Best format actually available is pdf (vect << 2118 If name is not set, it will take the defaul << 2119 */ << 2120 bool G4OpenGLQtViewer::exportImage(std::strin << 2121 1930 2122 auto* qGLW = dynamic_cast<G4QGLWidgetType*> << 2123 if (! qGLW) { << 2124 return false; << 2125 } << 2126 // If there is already an extention << 2127 bool increaseFileNumber = true; << 2128 // if << 2129 if (name.size() != name.substr(name.find_la << 2130 increaseFileNumber = false; << 2131 } << 2132 if (! setExportFilename(name,increaseFileNu << 2133 return false; << 2134 } << 2135 if ((width !=-1) && (height != -1)) { << 2136 setExportSize(width, height); << 2137 } << 2138 // first, try to do it with generic functio << 2139 if (G4OpenGLViewer::exportImage(name, width << 2140 return true; << 2141 << 2142 // Then try Qt saving functions << 2143 } else { << 2144 QImage image; << 2145 #if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0)) << 2146 image = qGLW->grabFrameBuffer(); << 2147 #else << 2148 image = qGLW->grabFramebuffer(); << 2149 #endif << 2150 << 2151 bool res = image.save(QString(getRealPrin << 2152 1931 2153 if (!res) { << 1932 bool G4OpenGLQtViewer::hasPendingEvents () { 2154 G4cerr << "Error saving file... " << ge << 1933 return ((QApplication*)G4Qt::getInstance ())->hasPendingEvents (); 2155 return false; << 2156 } else { << 2157 G4cout << "File " << getRealPrintFilena << 2158 fExportFilenameIndex++; << 2159 } << 2160 } << 2161 return true; << 2162 } 1934 } 2163 1935 2164 bool G4OpenGLQtViewer::generateMpegEncoderPar 1936 bool G4OpenGLQtViewer::generateMpegEncoderParameters () { 2165 1937 2166 // save the parameter file 1938 // save the parameter file 2167 FILE* fp; 1939 FILE* fp; 2168 fp = fopen (QString(fMovieTempFolderPath+fP 1940 fp = fopen (QString(fMovieTempFolderPath+fParameterFileName).toStdString().c_str(), "w"); 2169 1941 2170 if (fp == NULL) { 1942 if (fp == NULL) { 2171 setRecordingInfos("Generation of paramete 1943 setRecordingInfos("Generation of parameter file failed"); 2172 return false; 1944 return false; 2173 } 1945 } 2174 1946 2175 fprintf (fp,"# Pattern affects speed, quali 1947 fprintf (fp,"# Pattern affects speed, quality and compression. See the User's Guide\n"); 2176 fprintf (fp,"# for more info.\n"); 1948 fprintf (fp,"# for more info.\n"); 2177 fprintf (fp,"\n"); 1949 fprintf (fp,"\n"); 2178 fprintf (fp,"PATTERN I\n"); << 1950 fprintf (fp,"PATTERN IBBPBBPBBPBBPBBP\n"); 2179 fprintf (fp,"OUTPUT %s\n",getSaveFileName 1951 fprintf (fp,"OUTPUT %s\n",getSaveFileName().toStdString().c_str()); 2180 fprintf (fp,"\n"); 1952 fprintf (fp,"\n"); 2181 fprintf (fp,"# You must specify the type of 1953 fprintf (fp,"# You must specify the type of the input files. The choices are:\n"); 2182 fprintf (fp,"# YUV, PPM, JMOVIE, Y, JPEG 1954 fprintf (fp,"# YUV, PPM, JMOVIE, Y, JPEG, PNM\n"); 2183 fprintf (fp,"# (must be upper case)\n"); 1955 fprintf (fp,"# (must be upper case)\n"); 2184 fprintf (fp,"#\n"); 1956 fprintf (fp,"#\n"); 2185 fprintf (fp,"BASE_FILE_FORMAT PPM\n"); 1957 fprintf (fp,"BASE_FILE_FORMAT PPM\n"); 2186 fprintf (fp,"\n"); 1958 fprintf (fp,"\n"); >> 1959 fprintf (fp,"#\n"); >> 1960 fprintf (fp,"# if YUV format (or using parallel version), must provide width and height\n"); >> 1961 fprintf (fp,"# YUV_SIZE widthxheight\n"); >> 1962 fprintf (fp,"# this option is ignored if BASE_FILE_FORMAT is not YUV and you're running\n"); >> 1963 fprintf (fp,"# on just one machine\n"); >> 1964 fprintf (fp,"#\n"); >> 1965 fprintf (fp,"YUV_SIZE 352x240\n"); 2187 fprintf (fp,"\n"); 1966 fprintf (fp,"\n"); 2188 fprintf (fp,"# If you are using YUV, there 1967 fprintf (fp,"# If you are using YUV, there are different supported file formats.\n"); 2189 fprintf (fp,"# EYUV or UCB are the same as 1968 fprintf (fp,"# EYUV or UCB are the same as previous versions of this encoder.\n"); 2190 fprintf (fp,"# (All the Y's, then U's then 1969 fprintf (fp,"# (All the Y's, then U's then V's, in 4:2:0 subsampling.)\n"); 2191 fprintf (fp,"# Other formats, such as Abeka 1970 fprintf (fp,"# Other formats, such as Abekas, Phillips, or a general format are\n"); 2192 fprintf (fp,"# permissible, the general for 1971 fprintf (fp,"# permissible, the general format is a string of Y's, U's, and V's\n"); 2193 fprintf (fp,"# to specify the file order.\n 1972 fprintf (fp,"# to specify the file order.\n"); 2194 fprintf (fp,"\n"); 1973 fprintf (fp,"\n"); 2195 fprintf (fp,"INPUT_FORMAT UCB\n"); 1974 fprintf (fp,"INPUT_FORMAT UCB\n"); 2196 fprintf (fp,"\n"); 1975 fprintf (fp,"\n"); 2197 fprintf (fp,"# the conversion statement\n") 1976 fprintf (fp,"# the conversion statement\n"); 2198 fprintf (fp,"#\n"); 1977 fprintf (fp,"#\n"); 2199 fprintf (fp,"# Each occurrence of '*' will 1978 fprintf (fp,"# Each occurrence of '*' will be replaced by the input file\n"); 2200 fprintf (fp,"#\n"); 1979 fprintf (fp,"#\n"); 2201 fprintf (fp,"# e.g., if you have a bunch of 1980 fprintf (fp,"# e.g., if you have a bunch of GIF files, then this might be:\n"); 2202 fprintf (fp,"# INPUT_CONVERT giftoppm *\n" 1981 fprintf (fp,"# INPUT_CONVERT giftoppm *\n"); 2203 fprintf (fp,"#\n"); 1982 fprintf (fp,"#\n"); 2204 fprintf (fp,"# e.g., if you have a bunch of 1983 fprintf (fp,"# e.g., if you have a bunch of files like a.Y a.U a.V, etc., then:\n"); 2205 fprintf (fp,"# INPUT_CONVERT cat *.Y *.U * 1984 fprintf (fp,"# INPUT_CONVERT cat *.Y *.U *.V\n"); 2206 fprintf (fp,"#\n"); 1985 fprintf (fp,"#\n"); 2207 fprintf (fp,"# e.g., if you are grabbing fr 1986 fprintf (fp,"# e.g., if you are grabbing from laser disc you might have something like\n"); 2208 fprintf (fp,"# INPUT_CONVERT goto frame *; 1987 fprintf (fp,"# INPUT_CONVERT goto frame *; grabppm\n"); 2209 fprintf (fp,"# 'INPUT_CONVERT *' means the 1988 fprintf (fp,"# 'INPUT_CONVERT *' means the files are already in the base file format\n"); 2210 fprintf (fp,"#\n"); 1989 fprintf (fp,"#\n"); 2211 fprintf (fp,"INPUT_CONVERT * \n"); 1990 fprintf (fp,"INPUT_CONVERT * \n"); 2212 fprintf (fp,"\n"); 1991 fprintf (fp,"\n"); 2213 fprintf (fp,"# number of frames in a GOP.\n 1992 fprintf (fp,"# number of frames in a GOP.\n"); 2214 fprintf (fp,"#\n"); 1993 fprintf (fp,"#\n"); 2215 fprintf (fp,"# since each GOP must have at 1994 fprintf (fp,"# since each GOP must have at least one I-frame, the encoder will find the\n"); 2216 fprintf (fp,"# the first I-frame after GOP_ 1995 fprintf (fp,"# the first I-frame after GOP_SIZE frames to start the next GOP\n"); 2217 fprintf (fp,"#\n"); 1996 fprintf (fp,"#\n"); 2218 fprintf (fp,"# later, will add more flexibl 1997 fprintf (fp,"# later, will add more flexible GOP signalling\n"); 2219 fprintf (fp,"#\n"); 1998 fprintf (fp,"#\n"); 2220 fprintf (fp,"GOP_SIZE 1\n"); << 1999 fprintf (fp,"GOP_SIZE 16\n"); 2221 fprintf (fp,"\n"); 2000 fprintf (fp,"\n"); 2222 fprintf (fp,"# number of slices in a frame\ 2001 fprintf (fp,"# number of slices in a frame\n"); 2223 fprintf (fp,"#\n"); 2002 fprintf (fp,"#\n"); 2224 fprintf (fp,"# 1 is a good number. another 2003 fprintf (fp,"# 1 is a good number. another possibility is the number of macroblock rows\n"); 2225 fprintf (fp,"# (which is the height divided 2004 fprintf (fp,"# (which is the height divided by 16)\n"); 2226 fprintf (fp,"#\n"); 2005 fprintf (fp,"#\n"); 2227 fprintf (fp,"SLICES_PER_FRAME 1\n"); 2006 fprintf (fp,"SLICES_PER_FRAME 1\n"); 2228 fprintf (fp,"PIXEL HALF"); << 2229 fprintf (fp,"\n"); 2007 fprintf (fp,"\n"); 2230 fprintf (fp,"# directory to get all input f 2008 fprintf (fp,"# directory to get all input files from (makes this file easier to read)\n"); 2231 fprintf (fp,"INPUT_DIR %s\n",fMovieTempFol 2009 fprintf (fp,"INPUT_DIR %s\n",fMovieTempFolderPath.toStdString().c_str()); 2232 fprintf (fp,"\n"); 2010 fprintf (fp,"\n"); 2233 fprintf (fp,"# There are a bunch of ways to 2011 fprintf (fp,"# There are a bunch of ways to specify the input files.\n"); 2234 fprintf (fp,"# from a simple one-per-line l 2012 fprintf (fp,"# from a simple one-per-line listing, to the following \n"); 2235 fprintf (fp,"# way of numbering them. See 2013 fprintf (fp,"# way of numbering them. See the manual for more information.\n"); 2236 fprintf (fp,"INPUT\n"); 2014 fprintf (fp,"INPUT\n"); 2237 fprintf (fp,"# '*' is replaced by the numbe 2015 fprintf (fp,"# '*' is replaced by the numbers 01, 02, 03, 04\n"); 2238 fprintf (fp,"# if I instead do [01-11], it 2016 fprintf (fp,"# if I instead do [01-11], it would be 01, 02, ..., 09, 10, 11\n"); 2239 fprintf (fp,"# if I instead do [1-11], it w 2017 fprintf (fp,"# if I instead do [1-11], it would be 1, 2, 3, ..., 9, 10, 11\n"); 2240 fprintf (fp,"# if I instead do [1-11+3], it 2018 fprintf (fp,"# if I instead do [1-11+3], it would be 1, 4, 7, 10\n"); 2241 fprintf (fp,"# the program assumes none of 2019 fprintf (fp,"# the program assumes none of your input files has a name ending in ']'\n"); 2242 fprintf (fp,"# if you do, too bad!!!\n"); 2020 fprintf (fp,"# if you do, too bad!!!\n"); 2243 fprintf (fp,"#\n"); 2021 fprintf (fp,"#\n"); 2244 fprintf (fp,"#\n"); 2022 fprintf (fp,"#\n"); 2245 fprintf (fp,"Test*.ppm [0-%d]\n",fRecordFr 2023 fprintf (fp,"Test*.ppm [0-%d]\n",fRecordFrameNumber-1); 2246 fprintf (fp,"# can have more files here if 2024 fprintf (fp,"# can have more files here if you want...there is no limit on the number\n"); 2247 fprintf (fp,"# of files\n"); 2025 fprintf (fp,"# of files\n"); 2248 fprintf (fp,"END_INPUT\n"); 2026 fprintf (fp,"END_INPUT\n"); 2249 fprintf (fp,"\n"); 2027 fprintf (fp,"\n"); 2250 fprintf (fp,"\n"); 2028 fprintf (fp,"\n"); 2251 fprintf (fp,"\n"); 2029 fprintf (fp,"\n"); 2252 fprintf (fp,"# Many of the remaining option 2030 fprintf (fp,"# Many of the remaining options have to do with the motion search and qscale\n"); 2253 fprintf (fp,"\n"); 2031 fprintf (fp,"\n"); 2254 fprintf (fp,"# FULL or HALF -- must be uppe 2032 fprintf (fp,"# FULL or HALF -- must be upper case\n"); 2255 fprintf (fp,"# Should be FULL for computer 2033 fprintf (fp,"# Should be FULL for computer generated images\n"); 2256 fprintf (fp,"PIXEL FULL\n"); 2034 fprintf (fp,"PIXEL FULL\n"); 2257 fprintf (fp,"\n"); 2035 fprintf (fp,"\n"); 2258 fprintf (fp,"# means +/- this many pixels f 2036 fprintf (fp,"# means +/- this many pixels for both P and B frame searches\n"); 2259 fprintf (fp,"# specify two numbers if you w 2037 fprintf (fp,"# specify two numbers if you wish to serc different ranges in the two.\n"); 2260 fprintf (fp,"RANGE 10\n"); 2038 fprintf (fp,"RANGE 10\n"); 2261 fprintf (fp,"\n"); 2039 fprintf (fp,"\n"); 2262 fprintf (fp,"# The two search algorithm par 2040 fprintf (fp,"# The two search algorithm parameters below mostly affect speed,\n"); 2263 fprintf (fp,"# with some affect on compress 2041 fprintf (fp,"# with some affect on compression and almost none on quality.\n"); 2264 fprintf (fp,"\n"); 2042 fprintf (fp,"\n"); 2265 fprintf (fp,"# this must be one of {EXHAUST 2043 fprintf (fp,"# this must be one of {EXHAUSTIVE, SUBSAMPLE, LOGARITHMIC}\n"); 2266 fprintf (fp,"PSEARCH_ALG LOGARITHMIC\n"); 2044 fprintf (fp,"PSEARCH_ALG LOGARITHMIC\n"); 2267 fprintf (fp,"\n"); 2045 fprintf (fp,"\n"); 2268 fprintf (fp,"# this must be one of {SIMPLE, 2046 fprintf (fp,"# this must be one of {SIMPLE, CROSS2, EXHAUSTIVE}\n"); 2269 fprintf (fp,"#\n"); 2047 fprintf (fp,"#\n"); 2270 fprintf (fp,"# note that EXHAUSTIVE is real 2048 fprintf (fp,"# note that EXHAUSTIVE is really, really, really slow\n"); 2271 fprintf (fp,"#\n"); 2049 fprintf (fp,"#\n"); 2272 fprintf (fp,"BSEARCH_ALG SIMPLE\n"); 2050 fprintf (fp,"BSEARCH_ALG SIMPLE\n"); 2273 fprintf (fp,"\n"); 2051 fprintf (fp,"\n"); 2274 fprintf (fp,"#\n"); 2052 fprintf (fp,"#\n"); 2275 fprintf (fp,"# these specify the q-scale fo 2053 fprintf (fp,"# these specify the q-scale for I, P, and B frames\n"); 2276 fprintf (fp,"# (values must be between 1 an 2054 fprintf (fp,"# (values must be between 1 and 31)\n"); 2277 fprintf (fp,"# These are the Qscale values 2055 fprintf (fp,"# These are the Qscale values for the entire frame in variable bit-rate\n"); 2278 fprintf (fp,"# mode, and starting points (b 2056 fprintf (fp,"# mode, and starting points (but not important) for constant bit rate\n"); 2279 fprintf (fp,"#\n"); 2057 fprintf (fp,"#\n"); 2280 fprintf (fp,"\n"); 2058 fprintf (fp,"\n"); 2281 fprintf (fp,"# Qscale (Quantization scale) 2059 fprintf (fp,"# Qscale (Quantization scale) affects quality and compression,\n"); 2282 fprintf (fp,"# but has very little effect o 2060 fprintf (fp,"# but has very little effect on speed.\n"); 2283 fprintf (fp,"\n"); 2061 fprintf (fp,"\n"); 2284 fprintf (fp,"IQSCALE 4\n"); 2062 fprintf (fp,"IQSCALE 4\n"); 2285 fprintf (fp,"PQSCALE 5\n"); 2063 fprintf (fp,"PQSCALE 5\n"); 2286 fprintf (fp,"BQSCALE 12\n"); 2064 fprintf (fp,"BQSCALE 12\n"); 2287 fprintf (fp,"\n"); 2065 fprintf (fp,"\n"); 2288 fprintf (fp,"# this must be ORIGINAL or DEC 2066 fprintf (fp,"# this must be ORIGINAL or DECODED\n"); 2289 fprintf (fp,"REFERENCE_FRAME ORIGINAL\n"); 2067 fprintf (fp,"REFERENCE_FRAME ORIGINAL\n"); 2290 fprintf (fp,"\n"); 2068 fprintf (fp,"\n"); 2291 fprintf (fp,"# for parallel parameters see << 2069 fprintf (fp,"# for parallel parameters see parallel.param in the exmaples subdirectory\n"); 2292 fprintf (fp,"\n"); 2070 fprintf (fp,"\n"); 2293 fprintf (fp,"# if you want constant bit-rat 2071 fprintf (fp,"# if you want constant bit-rate mode, specify it as follows (number is bits/sec):\n"); 2294 fprintf (fp,"#BIT_RATE 1000000\n"); 2072 fprintf (fp,"#BIT_RATE 1000000\n"); 2295 fprintf (fp,"\n"); 2073 fprintf (fp,"\n"); 2296 fprintf (fp,"# To specify the buffer size ( 2074 fprintf (fp,"# To specify the buffer size (327680 is default, measused in bits, for 16bit words)\n"); 2297 fprintf (fp,"BUFFER_SIZE 327680\n"); 2075 fprintf (fp,"BUFFER_SIZE 327680\n"); 2298 fprintf (fp,"\n"); 2076 fprintf (fp,"\n"); 2299 fprintf (fp,"# The frame rate is the number 2077 fprintf (fp,"# The frame rate is the number of frames/second (legal values:\n"); 2300 fprintf (fp,"# 23.976, 24, 25, 29.97, 30, 5 2078 fprintf (fp,"# 23.976, 24, 25, 29.97, 30, 50 ,59.94, 60\n"); 2301 fprintf (fp,"FRAME_RATE 30\n"); 2079 fprintf (fp,"FRAME_RATE 30\n"); 2302 fprintf (fp,"\n"); 2080 fprintf (fp,"\n"); 2303 fprintf (fp,"# There are many more options, 2081 fprintf (fp,"# There are many more options, see the users manual for examples....\n"); 2304 fprintf (fp,"# ASPECT_RATIO, USER_DATA, GAM 2082 fprintf (fp,"# ASPECT_RATIO, USER_DATA, GAMMA, IQTABLE, etc.\n"); 2305 fprintf (fp,"\n"); 2083 fprintf (fp,"\n"); 2306 fprintf (fp,"\n"); 2084 fprintf (fp,"\n"); 2307 fclose (fp); 2085 fclose (fp); 2308 2086 2309 setRecordingInfos("Parameter file "+fParame 2087 setRecordingInfos("Parameter file "+fParameterFileName+" generated in "+fMovieTempFolderPath); 2310 setRecordingStatus(READY_TO_ENCODE); 2088 setRecordingStatus(READY_TO_ENCODE); 2311 return true; 2089 return true; 2312 } 2090 } 2313 2091 2314 void G4OpenGLQtViewer::encodeVideo() 2092 void G4OpenGLQtViewer::encodeVideo() 2315 { 2093 { 2316 if ((getEncoderPath() != "") && (getSaveFil 2094 if ((getEncoderPath() != "") && (getSaveFileName() != "")) { 2317 setRecordingStatus(ENCODING); 2095 setRecordingStatus(ENCODING); 2318 << 2096 2319 fProcess = new QProcess(); 2097 fProcess = new QProcess(); >> 2098 #if QT_VERSION > 0x040100 2320 QObject ::connect(fProcess,SIGNAL(finishe 2099 QObject ::connect(fProcess,SIGNAL(finished ( int,QProcess::ExitStatus)), 2321 this,SLOT(processEncode 2100 this,SLOT(processEncodeFinished())); 2322 QObject ::connect(fProcess,SIGNAL(readyRe 2101 QObject ::connect(fProcess,SIGNAL(readyReadStandardOutput ()), 2323 this,SLOT(processEncode 2102 this,SLOT(processEncodeStdout())); 2324 #if (QT_VERSION < QT_VERSION_CHECK(5, 10, 0)) << 2325 fProcess->setReadChannelMode(QProcess::Me << 2326 #else 2103 #else 2327 fProcess->setProcessChannelMode(QProcess: << 2104 QObject ::connect(fProcess,SIGNAL(finished ( int)), >> 2105 this,SLOT(processEncodeFinished())); >> 2106 QObject ::connect(fProcess,SIGNAL(readyReadStandardOutput ()), >> 2107 this,SLOT(processEncodeStdout())); 2328 #endif 2108 #endif >> 2109 fProcess->setReadChannelMode(QProcess::MergedChannels); 2329 fProcess->start (fEncoderPath, QStringLis 2110 fProcess->start (fEncoderPath, QStringList(fMovieTempFolderPath+fParameterFileName)); 2330 } 2111 } 2331 } 2112 } 2332 2113 2333 2114 2334 // FIXME : does not work on Qt3 2115 // FIXME : does not work on Qt3 2335 void G4OpenGLQtViewer::processEncodeStdout() 2116 void G4OpenGLQtViewer::processEncodeStdout() 2336 { 2117 { 2337 QString tmp = fProcess->readAllStandardOutp 2118 QString tmp = fProcess->readAllStandardOutput ().data(); 2338 auto start = tmp.lastIndexOf("ESTIMATED TIM << 2119 int start = tmp.lastIndexOf("ESTIMATED TIME"); 2339 tmp = tmp.mid(start,tmp.indexOf("\n",start) 2120 tmp = tmp.mid(start,tmp.indexOf("\n",start)-start); 2340 setRecordingInfos(tmp); 2121 setRecordingInfos(tmp); 2341 } 2122 } 2342 2123 2343 2124 2344 void G4OpenGLQtViewer::processEncodeFinished( 2125 void G4OpenGLQtViewer::processEncodeFinished() 2345 { 2126 { 2346 2127 2347 QString txt = ""; 2128 QString txt = ""; 2348 txt = getProcessErrorMsg(); 2129 txt = getProcessErrorMsg(); 2349 if (txt == "") { 2130 if (txt == "") { 2350 setRecordingStatus(SUCCESS); 2131 setRecordingStatus(SUCCESS); 2351 } else { 2132 } else { 2352 setRecordingStatus(FAILED); 2133 setRecordingStatus(FAILED); 2353 } 2134 } 2354 // setRecordingInfos(txt+removeTempFolder( 2135 // setRecordingInfos(txt+removeTempFolder()); 2355 } 2136 } 2356 2137 2357 2138 2358 void G4OpenGLQtViewer::processLookForFinished << 2139 void G4OpenGLQtViewer::processLookForFinished() 2359 { 2140 { 2360 2141 2361 QString txt = getProcessErrorMsg(); 2142 QString txt = getProcessErrorMsg(); 2362 if (txt != "") { 2143 if (txt != "") { 2363 fEncoderPath = ""; 2144 fEncoderPath = ""; 2364 } else { 2145 } else { 2365 fEncoderPath = QString(fProcess->readAllS 2146 fEncoderPath = QString(fProcess->readAllStandardOutput ().data()).trimmed(); 2366 // if not found, return "not found" 2147 // if not found, return "not found" 2367 if (fEncoderPath.contains(" ")) { 2148 if (fEncoderPath.contains(" ")) { 2368 fEncoderPath = ""; 2149 fEncoderPath = ""; 2369 } else if (!fEncoderPath.contains("ppmtom 2150 } else if (!fEncoderPath.contains("ppmtompeg")) { 2370 fEncoderPath = ""; 2151 fEncoderPath = ""; 2371 } 2152 } 2372 setEncoderPath(fEncoderPath); 2153 setEncoderPath(fEncoderPath); 2373 } 2154 } 2374 // init temp folder 2155 // init temp folder 2375 setTempFolderPath(QDir::temp ().absolutePat 2156 setTempFolderPath(QDir::temp ().absolutePath ()); 2376 } 2157 } 2377 2158 2378 2159 2379 QString G4OpenGLQtViewer::getProcessErrorMsg( 2160 QString G4OpenGLQtViewer::getProcessErrorMsg() 2380 { 2161 { 2381 QString txt = ""; 2162 QString txt = ""; 2382 if (fProcess->exitCode() != 0) { 2163 if (fProcess->exitCode() != 0) { 2383 switch (fProcess->error()) { 2164 switch (fProcess->error()) { 2384 case QProcess::FailedToStart: 2165 case QProcess::FailedToStart: 2385 txt = "The process failed to start. Eit 2166 txt = "The process failed to start. Either the invoked program is missing, or you may have insufficient permissions to invoke the program.\n"; 2386 break; 2167 break; 2387 case QProcess::Crashed: 2168 case QProcess::Crashed: 2388 txt = "The process crashed some time af 2169 txt = "The process crashed some time after starting successfully.\n"; 2389 break; 2170 break; 2390 case QProcess::Timedout: 2171 case QProcess::Timedout: 2391 txt = "The last waitFor...() function t 2172 txt = "The last waitFor...() function timed out. The state of QProcess is unchanged, and you can try calling waitFor...() again.\n"; 2392 break; 2173 break; 2393 case QProcess::WriteError: 2174 case QProcess::WriteError: 2394 txt = "An error occurred when attemptin 2175 txt = "An error occurred when attempting to write to the process. For example, the process may not be running, or it may have closed its input channel.\n"; 2395 break; 2176 break; 2396 case QProcess::ReadError: 2177 case QProcess::ReadError: 2397 txt = "An error occurred when attemptin 2178 txt = "An error occurred when attempting to read from the process. For example, the process may not be running.\n"; 2398 break; 2179 break; 2399 case QProcess::UnknownError: 2180 case QProcess::UnknownError: 2400 txt = "An unknown error occurred. This 2181 txt = "An unknown error occurred. This is the default return value of error().\n"; 2401 break; 2182 break; 2402 } 2183 } 2403 } 2184 } 2404 return txt; 2185 return txt; 2405 } 2186 } 2406 2187 2407 2188 2408 2189 2409 2190 2410 QWidget *G4OpenGLQtViewer::getParentWidget() << 2191 QWidget *G4OpenGLQtViewer::getParentWidget() 2411 { 2192 { 2412 // launch Qt if not 2193 // launch Qt if not 2413 G4Qt* interactorManager = G4Qt::getInstance 2194 G4Qt* interactorManager = G4Qt::getInstance (); 2414 << 2195 // G4UImanager* UI = >> 2196 // G4UImanager::GetUIpointer(); >> 2197 2415 bool found = false; 2198 bool found = false; 2416 QDialog* dialog = NULL; << 2199 2417 // create window 2200 // create window 2418 if (((QApplication*)interactorManager->GetM 2201 if (((QApplication*)interactorManager->GetMainInteractor())) { 2419 // look for the main window 2202 // look for the main window 2420 QWidgetList wl = QApplication::allWidgets 2203 QWidgetList wl = QApplication::allWidgets(); 2421 QWidget *widget = NULL; 2204 QWidget *widget = NULL; 2422 for (int i=0; i < wl.size(); i++) { 2205 for (int i=0; i < wl.size(); i++) { 2423 widget = wl.at(i); 2206 widget = wl.at(i); 2424 if ((found== false) && (widget->inherit 2207 if ((found== false) && (widget->inherits("QMainWindow"))) { 2425 dialog = new QDialog(widget,Qt::Windo << 2208 fGLWindow = new QDialog(widget,Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowMinMaxButtonsHint); 2426 found = true; 2209 found = true; 2427 } 2210 } 2428 } 2211 } 2429 << 2212 2430 if (found==false) { 2213 if (found==false) { 2431 dialog = new QDialog(); << 2214 #ifdef G4DEBUG_VIS_OGL >> 2215 printf("G4OpenGLQtViewer::CreateMainWindow case Qapp exist, but not found\n"); >> 2216 #endif >> 2217 fGLWindow = new QDialog(); 2432 } 2218 } 2433 } else { 2219 } else { 2434 dialog= new QDialog(); << 2220 #ifdef G4DEBUG_VIS_OGL >> 2221 printf("G4OpenGLQtViewer::CreateMainWindow case Qapp exist\n"); >> 2222 #endif >> 2223 fGLWindow = new QDialog(); >> 2224 #ifdef G4DEBUG_VIS_OGL >> 2225 printf("G4OpenGLQtViewer::GetParentWidget fGLWindow\n"); >> 2226 #endif 2435 } 2227 } 2436 if (found) { 2228 if (found) { 2437 return dialog; << 2229 return fGLWindow; 2438 } else { 2230 } else { 2439 return NULL; 2231 return NULL; 2440 } 2232 } 2441 } 2233 } 2442 2234 2443 2235 2444 void G4OpenGLQtViewer::createSceneTreeWidget( << 2236 void G4OpenGLQtViewer::initSceneTreeComponent(){ 2445 fUISceneTreeWidget = fUiQt->GetSceneTreeWid << 2446 << 2447 if (!fUISceneTreeWidget) { << 2448 return; << 2449 } << 2450 << 2451 // do not remove previous widgets, hide the << 2452 QLayoutItem * wItem; << 2453 bool found = false; << 2454 if (fUISceneTreeWidget->layout()->count() ) << 2455 for(int idx = 0; idx < fUISceneTreeWidget << 2456 wItem = fUISceneTreeWidget->layout()->i << 2457 if (fSceneTreeWidget) { << 2458 if(dynamic_cast<QWidget *>(wItem->wid << 2459 if (wItem->widget()->windowTitle() << 2460 wItem->widget()->show(); << 2461 found = true; << 2462 } else { << 2463 wItem->widget()->hide(); << 2464 } << 2465 } << 2466 } else { << 2467 // wItem->widget()->hide(); << 2468 } << 2469 } << 2470 } << 2471 << 2472 if (!found) { << 2473 // initialize scene tree / viewer propert << 2474 fSceneTreeWidget = new QWidget(); << 2475 QVBoxLayout* layoutSceneTree = new QVBoxL << 2476 fSceneTreeWidget->setStyleSheet ("padding << 2477 << 2478 fSceneTreeWidget->setLayout(layoutSceneTr << 2479 fSceneTreeWidget->layout()->setContentsMa << 2480 fSceneTreeWidget->setWindowTitle(QString( << 2481 2237 2482 if (fUISceneTreeWidget != NULL) { << 2238 fSceneTreeWidget = new QWidget(); 2483 // fUISceneTreeWidget->layout()->addWidg << 2239 QVBoxLayout* layoutSceneTreeComponentsTBWidget = new QVBoxLayout(); 2484 } << 2240 fSceneTreeWidget->setLayout (layoutSceneTreeComponentsTBWidget); 2485 2241 2486 // not available for Immediate mode << 2242 if (fUISceneTreeComponentsTBWidget != NULL) { 2487 if (dynamic_cast<G4OpenGLStoredQtViewer*> << 2243 fUISceneTreeComponentsTBWidget->addTab(fSceneTreeWidget,QString(GetName().data())); 2488 createSceneTreeComponent(); << 2489 } << 2490 } 2244 } 2491 } << 2492 2245 2493 2246 2494 void G4OpenGLQtViewer::createSceneTreeCompone << 2495 << 2496 QLayout* vLayout = fSceneTreeWidget->layout << 2497 << 2498 // Search line << 2499 QWidget* coutButtonWidget = new QWidget(); << 2500 QHBoxLayout* layoutCoutTBButtons = new QHBo << 2501 << 2502 fFilterOutput = new QLineEdit(); << 2503 fFilterOutput->setToolTip("Filter output by << 2504 fFilterOutput->setStyleSheet ("padding: 0px << 2505 << 2506 QPixmap* searchIcon = fUiQt->getSearchIcon( << 2507 fFilterOutput->addAction(*searchIcon,QLineE << 2508 fFilterOutput->setStyleSheet ("border-radiu << 2509 layoutCoutTBButtons->addWidget(fFilterOutpu << 2510 << 2511 coutButtonWidget->setLayout(layoutCoutTBBut << 2512 vLayout->addWidget(coutButtonWidget); << 2513 << 2514 // reduce margins 2247 // reduce margins 2515 vLayout->setContentsMargins(0,0,0,0); << 2248 layoutSceneTreeComponentsTBWidget->setContentsMargins(5,5,5,5); 2516 2249 2517 2250 2518 fSceneTreeComponentTreeWidget = new QTreeWi 2251 fSceneTreeComponentTreeWidget = new QTreeWidget(); 2519 fSceneTreeComponentTreeWidget->setSelection 2252 fSceneTreeComponentTreeWidget->setSelectionMode(QAbstractItemView::SingleSelection); 2520 fSceneTreeComponentTreeWidget->setHeaderLab 2253 fSceneTreeComponentTreeWidget->setHeaderLabel ("Scene tree : "+QString(GetName().data())); 2521 fSceneTreeComponentTreeWidget->setColumnHid 2254 fSceneTreeComponentTreeWidget->setColumnHidden (1,true); // copy number 2522 fSceneTreeComponentTreeWidget->setColumnHid 2255 fSceneTreeComponentTreeWidget->setColumnHidden (2,true); // PO index 2523 fSceneTreeComponentTreeWidget->setColumnHid 2256 fSceneTreeComponentTreeWidget->setColumnHidden (3,true); // Informations 2524 // data(0) : POindex 2257 // data(0) : POindex 2525 // data(1) : copy number 2258 // data(1) : copy number 2526 // data(2) : g4color 2259 // data(2) : g4color 2527 2260 2528 vLayout->addWidget(fSceneTreeComponentTreeW << 2261 layoutSceneTreeComponentsTBWidget->addWidget(fSceneTreeComponentTreeWidget); 2529 2262 2530 connect(fSceneTreeComponentTreeWidget,SIGNA 2263 connect(fSceneTreeComponentTreeWidget,SIGNAL(itemChanged(QTreeWidgetItem*, int)),SLOT(sceneTreeComponentItemChanged(QTreeWidgetItem*, int))); 2531 connect(fSceneTreeComponentTreeWidget,SIGNA 2264 connect(fSceneTreeComponentTreeWidget,SIGNAL(itemSelectionChanged ()),SLOT(sceneTreeComponentSelected())); 2532 connect(fSceneTreeComponentTreeWidget,SIGNA 2265 connect(fSceneTreeComponentTreeWidget,SIGNAL(itemDoubleClicked ( QTreeWidgetItem*, int)),SLOT(changeColorAndTransparency( QTreeWidgetItem*, int))); 2533 2266 2534 2267 2535 // Depth slider 2268 // Depth slider 2536 QWidget *helpWidget = new QWidget(); << 2269 QLabel *depth = new QLabel(); 2537 QHBoxLayout *helpLayout = new QHBoxLayout() << 2270 depth->setText("Depth :"); 2538 2271 2539 QWidget* depthWidget = new QWidget(); 2272 QWidget* depthWidget = new QWidget(); 2540 QWidget *showBox = new QWidget(depthWidget) << 2273 QGroupBox *groupBox = new QGroupBox(tr("Touchables slider"),depthWidget); 2541 QHBoxLayout *showBoxLayout = new QHBoxLayou << 2274 QHBoxLayout *groupBoxLayout = new QHBoxLayout(); 2542 2275 2543 // reduce margins 2276 // reduce margins 2544 showBoxLayout->setContentsMargins(5,5,5,5); << 2277 groupBoxLayout->setContentsMargins(5,5,5,5); 2545 2278 2546 QLabel *zero = new QLabel(); 2279 QLabel *zero = new QLabel(); 2547 zero->setText("Show all"); << 2280 zero->setText("Show all"); 2548 QLabel *one = new QLabel(); 2281 QLabel *one = new QLabel(); 2549 one->setText("Hide all"); 2282 one->setText("Hide all"); 2550 fSceneTreeDepthSlider = new QSlider ( Qt::H 2283 fSceneTreeDepthSlider = new QSlider ( Qt::Horizontal); 2551 fSceneTreeDepthSlider->setMaximum (1000); 2284 fSceneTreeDepthSlider->setMaximum (1000); 2552 fSceneTreeDepthSlider->setMinimum (0); 2285 fSceneTreeDepthSlider->setMinimum (0); 2553 fSceneTreeDepthSlider->setTickPosition(QSli 2286 fSceneTreeDepthSlider->setTickPosition(QSlider::TicksAbove); 2554 // set a minimum size 2287 // set a minimum size 2555 fSceneTreeDepthSlider->setMinimumWidth (40) 2288 fSceneTreeDepthSlider->setMinimumWidth (40); 2556 2289 2557 showBoxLayout->addWidget(zero); << 2290 groupBoxLayout->addWidget(zero); 2558 showBoxLayout->addWidget(fSceneTreeDepthSli << 2291 groupBoxLayout->addWidget(fSceneTreeDepthSlider); 2559 showBoxLayout->addWidget(one); << 2292 groupBoxLayout->addWidget(one); 2560 2293 2561 showBox->setLayout(showBoxLayout); << 2294 groupBox->setLayout(groupBoxLayout); 2562 << 2295 layoutSceneTreeComponentsTBWidget->addWidget(groupBox); 2563 helpLayout->addWidget(showBox); << 2564 helpWidget->setLayout(helpLayout); << 2565 helpLayout->setContentsMargins(0,0,0,0); << 2566 << 2567 vLayout->addWidget(helpWidget); << 2568 2296 2569 connect( fSceneTreeDepthSlider, SIGNAL( val 2297 connect( fSceneTreeDepthSlider, SIGNAL( valueChanged(int) ), this, SLOT( changeDepthInSceneTree(int) ) ); 2570 connect( fFilterOutput, SIGNAL( textEdited << 2571 fTreeItemModels.clear(); << 2572 2298 2573 fPVRootNodeCreate = false; << 2299 // Search line 2574 << 2300 QWidget *helpWidget = new QWidget(); 2575 fMaxPOindexInserted = -1; << 2301 QHBoxLayout *helpLayout = new QHBoxLayout(); 2576 << 2302 QPushButton* select = new QPushButton("select item(s)"); 2577 << 2303 fHelpLine = new QLineEdit(); 2578 } << 2304 helpLayout->addWidget(fHelpLine); 2579 << 2305 helpLayout->addWidget(select); 2580 << 2306 helpWidget->setLayout(helpLayout); 2581 void G4OpenGLQtViewer::createViewerProperties << 2307 helpLayout->setContentsMargins(0,0,0,0); 2582 << 2583 // Get the pointer to the Viewer Properties << 2584 fUIViewerPropertiesWidget = fUiQt->GetViewe << 2585 << 2586 if (!fUIViewerPropertiesWidget) { << 2587 return; << 2588 } << 2589 << 2590 // remove previous widgets << 2591 QLayoutItem * wItem; << 2592 if (fUIViewerPropertiesWidget->layout()->co << 2593 while ((wItem = fUIViewerPropertiesWidget << 2594 delete wItem->widget(); << 2595 delete wItem; << 2596 } << 2597 } << 2598 << 2599 // add properties << 2600 QGroupBox *groupBox = new QGroupBox(); << 2601 groupBox->setTitle(GetName().data()); << 2602 QVBoxLayout *vbox = new QVBoxLayout; << 2603 << 2604 // add properties content << 2605 fViewerPropertiesTableWidget = new QTableWi << 2606 << 2607 QSizePolicy vPolicy = fViewerPropertiesTabl << 2608 vPolicy.setVerticalStretch(4); << 2609 << 2610 vbox->addWidget(fViewerPropertiesTableWidge << 2611 groupBox->setLayout(vbox); << 2612 fUIViewerPropertiesWidget->layout()->addWid << 2613 << 2614 connect(fViewerPropertiesTableWidget, SIGNA << 2615 << 2616 updateViewerPropertiesTableWidget(); << 2617 << 2618 QDialog* dial = static_cast<QDialog*> (fUIV << 2619 if (dial) { << 2620 // change name << 2621 dial->setWindowTitle(QString("Viewer prop << 2622 } << 2623 } << 2624 << 2625 << 2626 void G4OpenGLQtViewer::createPickInfosWidget( << 2627 << 2628 // Get the pointer to the Pick infos widget << 2629 fUIPickInfosWidget = fUiQt->GetPickInfosWid << 2630 << 2631 if (!fUIPickInfosWidget) { << 2632 return; << 2633 } << 2634 << 2635 // remove previous widgets << 2636 QLayoutItem * wItem; << 2637 if (fUIPickInfosWidget->layout()->count()) << 2638 while ((wItem = fUIPickInfosWidget->layou << 2639 delete wItem->widget(); << 2640 delete wItem; << 2641 } << 2642 } << 2643 << 2644 QGroupBox *groupBox = new QGroupBox(""); << 2645 QVBoxLayout *vbox = new QVBoxLayout; << 2646 << 2647 // add picking infos << 2648 QWidget *pickingInfoWidget = new QWidget(); << 2649 QHBoxLayout *pickingInfoLayout = new QHBoxL << 2650 2308 2651 pickingInfoWidget->setStyleSheet ("padding- << 2309 // set a minimum size 2652 pickingInfoWidget->setLayout(pickingInfoLay << 2310 fHelpLine->setMinimumWidth (20); 2653 2311 2654 vbox->addWidget(pickingInfoWidget); << 2312 QSizePolicy policy = fHelpLine->sizePolicy(); 2655 // add picking content << 2313 policy.setHorizontalStretch(10); >> 2314 fHelpLine->setSizePolicy(policy); 2656 2315 2657 fPickInfosScrollArea = new QScrollArea(); << 2316 policy = select->sizePolicy(); 2658 fPickInfosScrollArea->setWidgetResizable(tr << 2317 policy.setHorizontalStretch(1); >> 2318 select->setSizePolicy(policy); 2659 2319 >> 2320 layoutSceneTreeComponentsTBWidget->addWidget(helpWidget); 2660 2321 2661 fPickInfosWidget = new QWidget(); << 2322 connect( fHelpLine, SIGNAL( returnPressed () ), this, SLOT(changeSearchSelection())); 2662 fPickInfosWidget->setStyleSheet ("padding: << 2323 connect( select, SIGNAL( clicked () ), this, SLOT(changeSearchSelection())); 2663 2324 2664 QVBoxLayout* vLayout = new QVBoxLayout(); << 2665 fPickInfosWidget->setLayout (vLayout); << 2666 fPickInfosScrollArea->setWidget(fPickInfosW << 2667 2325 2668 QSizePolicy vPolicy = fPickInfosWidget->siz << 2326 fTreeItemModels.clear(); 2669 vPolicy.setVerticalStretch(4); << 2670 vbox->addWidget(fPickInfosScrollArea); << 2671 pickingInfoLayout->setContentsMargins(0,0,0 << 2672 vLayout->setContentsMargins(0,0,0,0); << 2673 vbox->setContentsMargins(1,1,1,1); << 2674 2327 2675 groupBox->setLayout(vbox); << 2328 fPVRootNodeCreate = false; 2676 fUIPickInfosWidget->layout()->addWidget(gro << 2677 2329 2678 updatePickInfosWidget(fLastPickPoint.x(),fL << 2330 fMaxPOindexInserted = -1; 2679 } 2331 } 2680 2332 2681 2333 2682 // set the component to check/unchecked, also 2334 // set the component to check/unchecked, also go into its child 2683 // and set the same status to all his childs 2335 // and set the same status to all his childs 2684 void G4OpenGLQtViewer::setCheckComponent(QTre 2336 void G4OpenGLQtViewer::setCheckComponent(QTreeWidgetItem* item,bool check) 2685 { 2337 { 2686 if (item) { << 2687 << 2688 const PVPath& fullPath = fTreeItemModels[ << 2689 // If a physical volume << 2690 if (fullPath.size() > 0) { << 2691 SetTouchable(fullPath); << 2692 TouchableSetVisibility(fullPath, check) << 2693 fMouseOnSceneTree = true; << 2694 } << 2695 } << 2696 << 2697 if (item != NULL) { 2338 if (item != NULL) { 2698 if (check) { 2339 if (check) { 2699 item->setCheckState(0,Qt::Checked); 2340 item->setCheckState(0,Qt::Checked); 2700 } else { 2341 } else { 2701 item->setCheckState(0,Qt::Unchecked); 2342 item->setCheckState(0,Qt::Unchecked); 2702 } 2343 } 2703 updatePositivePoIndexSceneTreeWidgetQuick << 2344 updatePositivePoIndexSceneTreeWidgetQuickMap(item->data(0,Qt::UserRole).toInt(),item); 2704 int nChildCount = item->childCount(); 2345 int nChildCount = item->childCount(); 2705 for (int i = 0; i < nChildCount; i++) { 2346 for (int i = 0; i < nChildCount; i++) { 2706 setCheckComponent(item->child(i),check) 2347 setCheckComponent(item->child(i),check); 2707 } 2348 } 2708 } 2349 } 2709 } 2350 } 2710 2351 2711 #if QT_VERSION < 0x060000 << 2712 #else << 2713 //G.Barrand : from stackoverflow "How to rend << 2714 static void transform_point(GLdouble out[4], << 2715 { << 2716 #define M(row,col) m[col*4+row] << 2717 out[0] = << 2718 M(0, 0) * in[0] + M(0, 1) * in[1] + M << 2719 out[1] = << 2720 M(1, 0) * in[0] + M(1, 1) * in[1] + M << 2721 out[2] = << 2722 M(2, 0) * in[0] + M(2, 1) * in[1] + M << 2723 out[3] = << 2724 M(3, 0) * in[0] + M(3, 1) * in[1] + M << 2725 #undef M << 2726 } << 2727 inline GLint project_point(GLdouble objx, GLd << 2728 const GLdouble model[16], const GLdouble << 2729 const GLint viewport[4], << 2730 GLdouble * winx, GLdouble * winy, GLdoubl << 2731 { << 2732 GLdouble in[4], out[4]; << 2733 << 2734 in[0] = objx; << 2735 in[1] = objy; << 2736 in[2] = objz; << 2737 in[3] = 1.0; << 2738 transform_point(out, model, in); << 2739 transform_point(in, proj, out); << 2740 << 2741 if (in[3] == 0.0) << 2742 return GL_FALSE; << 2743 << 2744 in[0] /= in[3]; << 2745 in[1] /= in[3]; << 2746 in[2] /= in[3]; << 2747 << 2748 *winx = viewport[0] + (1 + in[0]) * viewp << 2749 *winy = viewport[1] + (1 + in[1]) * viewp << 2750 << 2751 *winz = (1 + in[2]) / 2; << 2752 return GL_TRUE; << 2753 } << 2754 static void render_text(QOpenGLWidget& widget << 2755 double world_x, double world << 2756 double offset_x, double offs << 2757 const QFont& font, << 2758 const QColor& color, << 2759 const char* text) << 2760 { << 2761 GLdouble model[4][4]; << 2762 glGetDoublev(GL_MODELVIEW_MATRIX, &model[ << 2763 GLdouble proj[4][4]; << 2764 glGetDoublev(GL_PROJECTION_MATRIX, &proj[ << 2765 GLint view[4]; << 2766 glGetIntegerv(GL_VIEWPORT, &view[0]); << 2767 << 2768 GLdouble textPosX = 0, textPosY = 0, text << 2769 project_point(world_x, world_y, world_z, << 2770 &model[0][0], &proj[0][0], << 2771 &textPosX, &textPosY, &text << 2772 << 2773 textPosX /= GLdouble(widget.devicePixelRa << 2774 textPosY /= GLdouble(widget.devicePixelRa << 2775 << 2776 textPosY = GLdouble(widget.height()) - te << 2777 << 2778 textPosX += offset_x; << 2779 textPosY += offset_y; << 2780 << 2781 GLboolean GL_BLEND_enabled = glIsEnabled( << 2782 << 2783 QPainter painter(&widget); << 2784 painter.setPen(color); << 2785 painter.setFont(font); << 2786 painter.setRenderHints(QPainter::Antialia << 2787 painter.drawText(textPosX, textPosY, text << 2788 painter.end(); << 2789 << 2790 if(GL_BLEND_enabled==GL_TRUE) { << 2791 ::glEnable(GL_BLEND); << 2792 ::glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINU << 2793 } << 2794 } << 2795 #endif << 2796 2352 2797 void G4OpenGLQtViewer::DrawText(const G4Text& 2353 void G4OpenGLQtViewer::DrawText(const G4Text& g4text) 2798 { 2354 { 2799 auto* qGLW = dynamic_cast<G4QGLWidgetType*> << 2800 if (! qGLW) { << 2801 return; << 2802 } << 2803 if (isGl2psWriting()) { 2355 if (isGl2psWriting()) { 2804 2356 2805 G4OpenGLViewer::DrawText(g4text); 2357 G4OpenGLViewer::DrawText(g4text); 2806 2358 2807 } else { 2359 } else { 2808 2360 2809 if (!fGLWidget) return; << 2361 if (!fWindow) return; 2810 << 2811 if (!G4Threading::IsMasterThread()) retur << 2812 2362 2813 G4VSceneHandler::MarkerSizeType sizeType; 2363 G4VSceneHandler::MarkerSizeType sizeType; 2814 G4double size = fSceneHandler.GetMarkerSi 2364 G4double size = fSceneHandler.GetMarkerSize(g4text,sizeType); 2815 2365 2816 QFont font = QFont(); 2366 QFont font = QFont(); 2817 font.setPointSizeF(size); 2367 font.setPointSizeF(size); 2818 2368 2819 const G4Colour& c = fSceneHandler.GetText << 2820 << 2821 G4Point3D position = g4text.GetPosition() 2369 G4Point3D position = g4text.GetPosition(); 2822 2370 2823 const G4String& textString = g4text.GetTe 2371 const G4String& textString = g4text.GetText(); 2824 const char* textCString = textString.c_st 2372 const char* textCString = textString.c_str(); >> 2373 >> 2374 glRasterPos3d(position.x(),position.y(),position.z()); 2825 2375 2826 // Calculate move for centre and right ad 2376 // Calculate move for centre and right adjustment 2827 QFontMetrics f(font); << 2377 QFontMetrics* f = new QFontMetrics (font); 2828 G4double span = f.boundingRect(textCStrin << 2378 G4double span = f->width(textCString); 2829 << 2379 G4double xmove = 0., ymove = 0.; 2830 G4double xmove = 0.; << 2831 G4double ymove = 0.; << 2832 << 2833 switch (g4text.GetLayout()) { 2380 switch (g4text.GetLayout()) { 2834 case G4Text::left: break; 2381 case G4Text::left: break; 2835 case G4Text::centre: xmove -= span / 2.; 2382 case G4Text::centre: xmove -= span / 2.; break; 2836 case G4Text::right: xmove -= span; 2383 case G4Text::right: xmove -= span; 2837 } 2384 } 2838 << 2385 2839 //Add offsets 2386 //Add offsets 2840 xmove += g4text.GetXOffset(); 2387 xmove += g4text.GetXOffset(); 2841 ymove += g4text.GetYOffset(); 2388 ymove += g4text.GetYOffset(); 2842 2389 2843 #if QT_VERSION < 0x060000 << 2390 fWindow->renderText 2844 glColor4d(c.GetRed(),c.GetGreen(),c.GetBl << 2845 glRasterPos3d(position.x(),position.y(),p << 2846 // xmove, ymove in pixels - or are they? << 2847 #ifdef __APPLE__ << 2848 const G4double fudgeFactor = 2.; << 2849 #else << 2850 const G4double fudgeFactor = 1.; << 2851 #endif << 2852 xmove *= fudgeFactor; << 2853 ymove *= fudgeFactor; << 2854 qGLW->renderText << 2855 ((position.x()+(2*xmove)/getWinWidth()) 2391 ((position.x()+(2*xmove)/getWinWidth()), 2856 (position.y()+(2*ymove)/getWinHeight() 2392 (position.y()+(2*ymove)/getWinHeight()), 2857 position.z(), 2393 position.z(), 2858 textCString, 2394 textCString, 2859 font); 2395 font); 2860 #else << 2396 2861 QColor color((int)(c.GetRed()*255), << 2862 (int)(c.GetGreen()*255), << 2863 (int)(c.GetBlue()*255), << 2864 (int)(c.GetAlpha()*255)); << 2865 render_text(*qGLW, << 2866 position.x(),position.y(),pos << 2867 xmove,ymove, << 2868 font,color,textCString); << 2869 #endif << 2870 } 2397 } 2871 } 2398 } 2872 2399 2873 2400 2874 void G4OpenGLQtViewer::ResetView () { 2401 void G4OpenGLQtViewer::ResetView () { 2875 G4OpenGLViewer::ResetView(); 2402 G4OpenGLViewer::ResetView(); 2876 fDeltaDepth = 0.01; 2403 fDeltaDepth = 0.01; 2877 fDeltaZoom = 0.05; 2404 fDeltaZoom = 0.05; 2878 } 2405 } 2879 2406 2880 2407 2881 2408 2882 2409 2883 void G4OpenGLQtViewer::addPVSceneTreeElement( 2410 void G4OpenGLQtViewer::addPVSceneTreeElement(const G4String& model, G4PhysicalVolumeModel* pPVModel, int currentPOIndex) { 2884 2411 2885 const QString& modelShortName = getModelSho 2412 const QString& modelShortName = getModelShortName(model); 2886 2413 2887 if (modelShortName == "") { 2414 if (modelShortName == "") { 2888 return ; 2415 return ; 2889 } 2416 } 2890 // try to init it 2417 // try to init it 2891 if (fSceneTreeComponentTreeWidget == NULL) 2418 if (fSceneTreeComponentTreeWidget == NULL) { 2892 createSceneTreeComponent(); << 2419 initSceneTreeComponent(); 2893 } 2420 } 2894 2421 2895 // if no UI 2422 // if no UI 2896 if (fSceneTreeComponentTreeWidget == NULL) 2423 if (fSceneTreeComponentTreeWidget == NULL) { 2897 return; 2424 return; 2898 } 2425 } 2899 2426 2900 fSceneTreeComponentTreeWidget->blockSignals 2427 fSceneTreeComponentTreeWidget->blockSignals(true); 2901 2428 2902 // Create the "volume" node if not 2429 // Create the "volume" node if not 2903 // if (fSceneTreeComponentTreeWidget->topL 2430 // if (fSceneTreeComponentTreeWidget->topLevelItemCount () == 0) { 2904 if (!fPVRootNodeCreate) { 2431 if (!fPVRootNodeCreate) { 2905 const G4Colour& color = fSceneHandler.Get << 2432 const G4VisAttributes* visAttr = GetApplicableVisAttributes(pPVModel->GetFullPVPath().at(0).GetPhysicalVolume()->GetLogicalVolume()->GetVisAttributes()); 2906 << 2433 const G4Colour& color = visAttr->GetColour(); >> 2434 2907 fModelShortNameItem = createTreeWidgetIte 2435 fModelShortNameItem = createTreeWidgetItem(pPVModel->GetFullPVPath(), 2908 2436 modelShortName, 2909 2437 0, // currentPVCopyNb 2910 2438 -1, // currentPVPOIndex 2911 2439 "", 2912 2440 Qt::Checked, 2913 2441 NULL, 2914 2442 color); 2915 fPVRootNodeCreate = true; 2443 fPVRootNodeCreate = true; 2916 } 2444 } 2917 2445 2918 bool added = parseAndInsertInSceneTree(fMod 2446 bool added = parseAndInsertInSceneTree(fModelShortNameItem,pPVModel,0,modelShortName,0,currentPOIndex); 2919 if (!added) { 2447 if (!added) { 2920 } 2448 } 2921 << 2449 2922 fSceneTreeComponentTreeWidget->blockSignals 2450 fSceneTreeComponentTreeWidget->blockSignals(false); 2923 << 2451 2924 } 2452 } 2925 2453 2926 2454 2927 /** 2455 /** 2928 if treeNode is NULL, then add this treeNod 2456 if treeNode is NULL, then add this treeNode to the TreeWidget 2929 @return the inserted item 2457 @return the inserted item 2930 */ 2458 */ 2931 QTreeWidgetItem* G4OpenGLQtViewer::createTree 2459 QTreeWidgetItem* G4OpenGLQtViewer::createTreeWidgetItem( 2932 const PVPath& fullPath 2460 const PVPath& fullPath 2933 ,const QString& name 2461 ,const QString& name 2934 ,int copyNb 2462 ,int copyNb 2935 ,int POIndex 2463 ,int POIndex 2936 ,const QString& logicalName 2464 ,const QString& logicalName 2937 ,Qt::CheckState state 2465 ,Qt::CheckState state 2938 ,QTreeWidgetItem * parentTreeNode 2466 ,QTreeWidgetItem * parentTreeNode 2939 ,const G4Colour& color 2467 ,const G4Colour& color 2940 ) { 2468 ) { 2941 2469 2942 // Set depth 2470 // Set depth 2943 if (fullPath.size() > fSceneTreeDepth) { 2471 if (fullPath.size() > fSceneTreeDepth) { 2944 fSceneTreeDepth = (unsigned int)fullPath. << 2472 fSceneTreeDepth = fullPath.size(); 2945 // Change slider value 2473 // Change slider value 2946 if (fSceneTreeDepthSlider) { 2474 if (fSceneTreeDepthSlider) { 2947 fSceneTreeDepthSlider->setTickInterval( 2475 fSceneTreeDepthSlider->setTickInterval(1000/(fSceneTreeDepth+1)); 2948 } 2476 } 2949 } 2477 } 2950 QTreeWidgetItem * newItem = NULL; 2478 QTreeWidgetItem * newItem = NULL; 2951 if (parentTreeNode == NULL) { 2479 if (parentTreeNode == NULL) { 2952 newItem = new QTreeWidgetItem(); 2480 newItem = new QTreeWidgetItem(); 2953 fSceneTreeComponentTreeWidget->addTopLeve 2481 fSceneTreeComponentTreeWidget->addTopLevelItem(newItem); 2954 } else { 2482 } else { 2955 newItem = new QTreeWidgetItem(parentTreeN 2483 newItem = new QTreeWidgetItem(parentTreeNode); 2956 fSceneTreeComponentTreeWidget->addTopLeve 2484 fSceneTreeComponentTreeWidget->addTopLevelItem(parentTreeNode); 2957 } 2485 } 2958 2486 2959 2487 2960 newItem->setText(0,name); 2488 newItem->setText(0,name); 2961 newItem->setData(1,Qt::UserRole,copyNb); 2489 newItem->setData(1,Qt::UserRole,copyNb); 2962 newItem->setText(2,QString::number(POIndex) 2490 newItem->setText(2,QString::number(POIndex)); 2963 newItem->setData(0, Qt::UserRole, POIndex); 2491 newItem->setData(0, Qt::UserRole, POIndex); 2964 newItem->setText(3,logicalName); 2492 newItem->setText(3,logicalName); 2965 newItem->setFlags(newItem->flags()|Qt::Item 2493 newItem->setFlags(newItem->flags()|Qt::ItemIsUserCheckable); 2966 newItem->setCheckState(0,state); 2494 newItem->setCheckState(0,state); 2967 newItem->setExpanded(true); << 2968 updatePositivePoIndexSceneTreeWidgetQuickMa 2495 updatePositivePoIndexSceneTreeWidgetQuickMap(POIndex,newItem); 2969 2496 2970 changeQColorForTreeWidgetItem(newItem,QColo 2497 changeQColorForTreeWidgetItem(newItem,QColor((int)(color.GetRed()*255), 2971 2498 (int)(color.GetGreen()*255), 2972 2499 (int)(color.GetBlue()*255), 2973 2500 (int)(color.GetAlpha()*255))); 2974 2501 2975 // If invisible 2502 // If invisible 2976 if ((state == Qt::Unchecked) && (POIndex == 2503 if ((state == Qt::Unchecked) && (POIndex == -1)) { 2977 newItem->setForeground (0, QBrush( Qt::gr 2504 newItem->setForeground (0, QBrush( Qt::gray) ); 2978 << 2505 2979 // Set a tootip 2506 // Set a tootip 2980 newItem->setToolTip (0,QString( 2507 newItem->setToolTip (0,QString( 2981 "This node 2508 "This node exists in the geometry but has not been\n")+ 2982 "drawn, perhaps beca 2509 "drawn, perhaps because it has been set invisible. It \n"+ 2983 "cannot be made visi 2510 "cannot be made visible with a click on the button.\n"+ 2984 "To see it, change t 2511 "To see it, change the visibility, for example, with \n"+ 2985 "/vis/geometry/set/v 2512 "/vis/geometry/set/visibility " + logicalName + " 0 true\n"+ 2986 "and rebuild the vie 2513 "and rebuild the view with /vis/viewer/rebuild.\n"+ 2987 "Click here will onl 2514 "Click here will only show/hide all child components"); 2988 } else { 2515 } else { 2989 // Set a tootip 2516 // Set a tootip 2990 newItem->setToolTip (0,QString("double-cl 2517 newItem->setToolTip (0,QString("double-click to change the color")); 2991 } 2518 } 2992 2519 2993 // special case: if alpha=0, it is a totall 2520 // special case: if alpha=0, it is a totally transparent objet, 2994 // then, do not redraw it 2521 // then, do not redraw it 2995 if (color.GetAlpha() == 0) { 2522 if (color.GetAlpha() == 0) { 2996 state = Qt::Unchecked; 2523 state = Qt::Unchecked; 2997 newItem->setCheckState(0,state); 2524 newItem->setCheckState(0,state); 2998 updatePositivePoIndexSceneTreeWidgetQuick 2525 updatePositivePoIndexSceneTreeWidgetQuickMap(POIndex,newItem); 2999 } 2526 } 3000 2527 3001 fTreeItemModels.insert(std::pair <int, PVPa 2528 fTreeItemModels.insert(std::pair <int, PVPath > (POIndex,fullPath) ); 3002 2529 3003 // Check last status of this item and chang << 2530 // Check last status of this item and change if necessary 3004 // open/close/hidden/visible/selected 2531 // open/close/hidden/visible/selected 3005 changeOpenCloseVisibleHiddenSelectedColorSc 2532 changeOpenCloseVisibleHiddenSelectedColorSceneTreeElement(newItem); 3006 return newItem; 2533 return newItem; 3007 } 2534 } 3008 2535 3009 2536 3010 // 2537 // 3011 // Recursive function. 2538 // Recursive function. 3012 // Try to insert the given item : 2539 // Try to insert the given item : 3013 // - If not present and last item of the pa 2540 // - If not present and last item of the path: insert it and mark it CHECK 3014 // - If not present and NOT last item of th 2541 // - If not present and NOT last item of the path: insert it and mark it UNCHECKED 3015 // - If already present and name/PO/Transfo 2542 // - If already present and name/PO/Transformation identical, then it is a transparent 3016 // object : Change the PO number and tran 2543 // object : Change the PO number and transparency 3017 // - If already present and PO different, t 2544 // - If already present and PO different, then it is an unvisible item : Have to 3018 // set it visible 2545 // set it visible 3019 // - else : Create a new element 2546 // - else : Create a new element 3020 // @return true if inserted, false if alrea 2547 // @return true if inserted, false if already present 3021 // 2548 // 3022 bool G4OpenGLQtViewer::parseAndInsertInSceneT 2549 bool G4OpenGLQtViewer::parseAndInsertInSceneTree( 3023 QTreeWidgetItem * parentItem 2550 QTreeWidgetItem * parentItem 3024 ,G4PhysicalVolumeModel* pPVModel 2551 ,G4PhysicalVolumeModel* pPVModel 3025 ,unsigned int fullPathIndex 2552 ,unsigned int fullPathIndex 3026 ,const QString& parentRoot 2553 ,const QString& parentRoot 3027 ,unsigned int currentIndexInTreeSceneHandler 2554 ,unsigned int currentIndexInTreeSceneHandler 3028 ,int currentPVPOIndex 2555 ,int currentPVPOIndex 3029 ) { 2556 ) { 3030 2557 3031 if (parentItem == NULL) { 2558 if (parentItem == NULL) { 3032 return false; 2559 return false; 3033 } 2560 } 3034 2561 3035 const PVPath& fullPath = pPVModel->GetFullP 2562 const PVPath& fullPath = pPVModel->GetFullPVPath(); 3036 2563 3037 std::ostringstream oss; 2564 std::ostringstream oss; 3038 oss << fullPath.at(fullPathIndex).GetCopyNo 2565 oss << fullPath.at(fullPathIndex).GetCopyNo(); 3039 std::string currentPVName = G4String(fullPa 2566 std::string currentPVName = G4String(fullPath.at(fullPathIndex).GetPhysicalVolume()->GetName()+" ["+oss.str()+"]").data(); 3040 2567 3041 int currentPVCopyNb = fullPath.at(fullPathI 2568 int currentPVCopyNb = fullPath.at(fullPathIndex).GetCopyNo(); 3042 2569 3043 const G4Colour& color = fSceneHandler.GetCo << 2570 const G4VisAttributes* visAttr = GetApplicableVisAttributes(fullPath.at(fullPathIndex).GetPhysicalVolume()->GetLogicalVolume()->GetVisAttributes()); >> 2571 const G4Colour& color = visAttr->GetColour(); 3044 2572 3045 // look in all children in order to get if 2573 // look in all children in order to get if their is already a 3046 // child corresponding: 2574 // child corresponding: 3047 // - if so, go into this child 2575 // - if so, go into this child 3048 // - if not : create it as invisible 2576 // - if not : create it as invisible 3049 2577 3050 // Realy quick check if the POindex is alre 2578 // Realy quick check if the POindex is already there 3051 QTreeWidgetItem* subItem = NULL; 2579 QTreeWidgetItem* subItem = NULL; 3052 QList<QTreeWidgetItem *> parentItemList; 2580 QList<QTreeWidgetItem *> parentItemList; 3053 << 2581 3054 << 2582 3055 // first of all, very quick check if it was 2583 // first of all, very quick check if it was not the same as last one 3056 2584 3057 // Check only if it is a transparent object 2585 // Check only if it is a transparent object 3058 // If it is the last item and it is not tra << 2586 // If it is the last item and it is not transparent -> nothing to look for, 3059 // simply add it. 2587 // simply add it. 3060 if ((currentIndexInTreeSceneHandler == (ful 2588 if ((currentIndexInTreeSceneHandler == (fullPath.size()-1)) && ((color.GetAlpha() == 1.))) { 3061 } else { 2589 } else { 3062 QString lookForString = QString(currentPV 2590 QString lookForString = QString(currentPVName.c_str()); 3063 for (int i = 0;i < parentItem->childCount 2591 for (int i = 0;i < parentItem->childCount(); i++ ) { 3064 if (parentItem->child(i)->text(0) == lo 2592 if (parentItem->child(i)->text(0) == lookForString) { 3065 parentItemList.push_back(parentItem-> 2593 parentItemList.push_back(parentItem->child(i)); 3066 } 2594 } 3067 } 2595 } 3068 } 2596 } 3069 << 2597 3070 for (int i = 0; i < parentItemList.size(); 2598 for (int i = 0; i < parentItemList.size(); ++i) { 3071 const std::string& parentItemName = paren 2599 const std::string& parentItemName = parentItemList.at(i)->text(0).toStdString(); 3072 int parentItemCopyNb = parentItemList.at( 2600 int parentItemCopyNb = parentItemList.at(i)->data(1,Qt::UserRole).toInt(); 3073 int parentItemPOIndex = parentItemList.at 2601 int parentItemPOIndex = parentItemList.at(i)->data(0,Qt::UserRole).toInt(); 3074 << 2602 3075 // if already inside 2603 // if already inside 3076 // -> return true 2604 // -> return true 3077 // special case, do not have to deal with 2605 // special case, do not have to deal with hierarchy except for PhysicalVolume 3078 2606 3079 << 2607 3080 /* Physical Volume AND copy number equal 2608 /* Physical Volume AND copy number equal AND name equal */ 3081 if (((parentRoot == fTouchableVolumes) && 2609 if (((parentRoot == fTouchableVolumes) && (currentPVCopyNb == parentItemCopyNb) 3082 && (currentPVName == parentItemName) 2610 && (currentPVName == parentItemName)) || 3083 /* NOT a Physical Volume AND copy nu 2611 /* NOT a Physical Volume AND copy number equal */ 3084 ((parentRoot != fTouchableVolumes) && << 2612 ((parentRoot != fTouchableVolumes) && (currentPVCopyNb == parentItemCopyNb) 3085 /*AND name equal AND PO index equa 2613 /*AND name equal AND PO index equal*/ 3086 && (currentPVName == parentItemName) 2614 && (currentPVName == parentItemName) && (currentPVPOIndex == parentItemPOIndex) )) { 3087 << 2615 3088 // then check for the Transform3D 2616 // then check for the Transform3D 3089 bool sameTransform = true; 2617 bool sameTransform = true; 3090 if (parentItemPOIndex >= 0) { 2618 if (parentItemPOIndex >= 0) { 3091 const PVPath& fullPathTmp = fTreeItem 2619 const PVPath& fullPathTmp = fTreeItemModels[parentItemPOIndex]; 3092 if (fullPathTmp.size() > 0) { 2620 if (fullPathTmp.size() > 0) { 3093 if (fullPathTmp.at(fullPathTmp.size 2621 if (fullPathTmp.at(fullPathTmp.size()-1).GetTransform () == pPVModel->GetTransformation ()) { 3094 sameTransform = true; 2622 sameTransform = true; 3095 } else { 2623 } else { 3096 sameTransform = false; 2624 sameTransform = false; 3097 } 2625 } 3098 } 2626 } 3099 } 2627 } 3100 2628 3101 // Same transformation, then try to cha 2629 // Same transformation, then try to change the PO index 3102 if (sameTransform == true) { 2630 if (sameTransform == true) { 3103 // already exist in the tree, is it a 2631 // already exist in the tree, is it a transparent object ? 3104 // If so, then have to change the PO 2632 // If so, then have to change the PO index ONLY if it is the last 3105 // and then change the state ONLY if 2633 // and then change the state ONLY if POIndex has change 3106 // If not, then go deaper 2634 // If not, then go deaper 3107 << 2635 3108 // last element 2636 // last element 3109 if (currentIndexInTreeSceneHandler == 2637 if (currentIndexInTreeSceneHandler == (fullPath.size()-1)) { 3110 << 2638 3111 parentItemList.at(i)->setText(2,QSt 2639 parentItemList.at(i)->setText(2,QString::number(currentPVPOIndex)); 3112 parentItemList.at(i)->setData(0, Qt 2640 parentItemList.at(i)->setData(0, Qt::UserRole,currentPVPOIndex); 3113 << 2641 3114 fTreeItemModels.insert(std::pair <i 2642 fTreeItemModels.insert(std::pair <int, PVPath >(currentPVPOIndex,fullPath) ); 3115 << 2643 3116 // Then remove tooltip and special 2644 // Then remove tooltip and special font 3117 QFont f = QFont(); 2645 QFont f = QFont(); 3118 parentItemList.at(i)->setFont (0,f) 2646 parentItemList.at(i)->setFont (0,f); 3119 << 2647 3120 // set foreground 2648 // set foreground 3121 parentItemList.at(i)->setForeground 2649 parentItemList.at(i)->setForeground (0,QBrush()); 3122 << 2650 3123 // Set a tootip 2651 // Set a tootip 3124 parentItemList.at(i)->setToolTip (0 2652 parentItemList.at(i)->setToolTip (0,""); 3125 << 2653 3126 changeQColorForTreeWidgetItem(paren 2654 changeQColorForTreeWidgetItem(parentItemList.at(i),QColor((int)(color.GetRed()*255), 3127 2655 (int)(color.GetGreen()*255), 3128 2656 (int)(color.GetBlue()*255), 3129 2657 (int)(color.GetAlpha()*255))); 3130 << 2658 3131 // set check only if there is somet 2659 // set check only if there is something to display 3132 if (color.GetAlpha() > 0) { 2660 if (color.GetAlpha() > 0) { 3133 parentItemList.at(i)->setCheckSta 2661 parentItemList.at(i)->setCheckState(0,Qt::Checked); 3134 updatePositivePoIndexSceneTreeWid 2662 updatePositivePoIndexSceneTreeWidgetQuickMap(currentPVPOIndex,parentItemList.at(i)); 3135 } 2663 } 3136 return false; 2664 return false; 3137 } else { 2665 } else { 3138 subItem = parentItemList.at(i); << 2666 subItem = parentItemList.at(i); 3139 } 2667 } 3140 << 2668 3141 // Exists but not the end of path, th 2669 // Exists but not the end of path, then forget get it 3142 } else if (currentIndexInTreeSceneHandl 2670 } else if (currentIndexInTreeSceneHandler < (fullPath.size()-1)) { 3143 subItem = parentItemList.at(i); 2671 subItem = parentItemList.at(i); 3144 } 2672 } 3145 } 2673 } 3146 2674 3147 } // end for 2675 } // end for 3148 << 2676 3149 // if it the last, then add it and set it c 2677 // if it the last, then add it and set it checked 3150 if (currentIndexInTreeSceneHandler == (full 2678 if (currentIndexInTreeSceneHandler == (fullPath.size()-1)) { 3151 /* subItem =*/ createTreeWidgetItem(fullP 2679 /* subItem =*/ createTreeWidgetItem(fullPath, 3152 QString(cu 2680 QString(currentPVName.c_str()), 3153 currentPVC 2681 currentPVCopyNb, 3154 currentPVP 2682 currentPVPOIndex, 3155 QString(fu 2683 QString(fullPath.at(fullPathIndex).GetPhysicalVolume()->GetLogicalVolume()->GetName().data()), 3156 Qt::Checke 2684 Qt::Checked, 3157 parentItem 2685 parentItem, 3158 color); 2686 color); 3159 2687 3160 if (currentPVPOIndex > fMaxPOindexInserte 2688 if (currentPVPOIndex > fMaxPOindexInserted) { 3161 fMaxPOindexInserted = currentPVPOIndex; 2689 fMaxPOindexInserted = currentPVPOIndex; 3162 } 2690 } 3163 2691 3164 } else { 2692 } else { 3165 << 2693 3166 // if no child found, then this child is 2694 // if no child found, then this child is create and marked as invisible, then go inside 3167 if (subItem == NULL) { 2695 if (subItem == NULL) { 3168 << 2696 3169 if (currentIndexInTreeSceneHandler < (f 2697 if (currentIndexInTreeSceneHandler < (fullPath.size()-1)) { 3170 subItem = createTreeWidgetItem(fullPa 2698 subItem = createTreeWidgetItem(fullPath, 3171 QStrin 2699 QString(currentPVName.c_str()), 3172 curren 2700 currentPVCopyNb, 3173 -1, 2701 -1, 3174 QStrin 2702 QString(fullPath.at(fullPathIndex).GetPhysicalVolume()->GetLogicalVolume()->GetName().data()), 3175 Qt::Un 2703 Qt::Unchecked, 3176 parent 2704 parentItem, 3177 color) 2705 color); 3178 } 2706 } 3179 } 2707 } 3180 << 2708 3181 return parseAndInsertInSceneTree(subItem, 2709 return parseAndInsertInSceneTree(subItem,pPVModel,fullPathIndex+1,parentRoot,currentIndexInTreeSceneHandler+1,currentPVPOIndex); 3182 } 2710 } 3183 return true; 2711 return true; 3184 } 2712 } 3185 2713 3186 2714 3187 void G4OpenGLQtViewer::changeOpenCloseVisible 2715 void G4OpenGLQtViewer::changeOpenCloseVisibleHiddenSelectedColorSceneTreeElement( 3188 QTreeWidgetItem* subItem 2716 QTreeWidgetItem* subItem 3189 ) 2717 ) 3190 { 2718 { 3191 // Check if object with the same POIndex is 2719 // Check if object with the same POIndex is the same in old tree 3192 QTreeWidgetItem* oldItem = NULL; 2720 QTreeWidgetItem* oldItem = NULL; 3193 2721 3194 QTreeWidgetItem* foundItem = getOldTreeWidg 2722 QTreeWidgetItem* foundItem = getOldTreeWidgetItem(subItem->data(0,Qt::UserRole).toInt()); 3195 2723 3196 if (foundItem != NULL) { 2724 if (foundItem != NULL) { 3197 if (isSameSceneTreeElement(foundItem,subI 2725 if (isSameSceneTreeElement(foundItem,subItem)) { 3198 oldItem = foundItem; 2726 oldItem = foundItem; 3199 } 2727 } 3200 } 2728 } 3201 if (foundItem == NULL) { // PO should have 2729 if (foundItem == NULL) { // PO should have change, parse all 3202 2730 3203 // POindex > 0 2731 // POindex > 0 3204 std::map <int, QTreeWidgetItem*>::const_i 2732 std::map <int, QTreeWidgetItem*>::const_iterator i; 3205 i = fOldPositivePoIndexSceneTreeWidgetQui << 2733 i = fOldPositivePoIndexSceneTreeWidgetQuickMap.begin(); 3206 while (i != fOldPositivePoIndexSceneTreeW << 2734 while (i != fOldPositivePoIndexSceneTreeWidgetQuickMap.end()) { 3207 if (isSameSceneTreeElement(i->second,su 2735 if (isSameSceneTreeElement(i->second,subItem)) { 3208 oldItem = i->second; 2736 oldItem = i->second; 3209 i = fOldPositivePoIndexSceneTreeWidge << 2737 i = fOldPositivePoIndexSceneTreeWidgetQuickMap.end(); 3210 } else { 2738 } else { 3211 ++i; << 2739 i++; 3212 } 2740 } 3213 } 2741 } 3214 // POindex == 0 ? 2742 // POindex == 0 ? 3215 if (oldItem == NULL) { 2743 if (oldItem == NULL) { 3216 std::size_t a = 0; << 2744 unsigned int a = 0; 3217 while (a < fOldNullPoIndexSceneTreeWidg 2745 while (a < fOldNullPoIndexSceneTreeWidgetQuickVector.size()) { 3218 if (isSameSceneTreeElement(fOldNullPo 2746 if (isSameSceneTreeElement(fOldNullPoIndexSceneTreeWidgetQuickVector[a],subItem)) { 3219 oldItem = fOldNullPoIndexSceneTreeW 2747 oldItem = fOldNullPoIndexSceneTreeWidgetQuickVector[a]; 3220 a = fOldNullPoIndexSceneTreeWidgetQ 2748 a = fOldNullPoIndexSceneTreeWidgetQuickVector.size(); 3221 } else { 2749 } else { 3222 ++a; << 2750 a++; 3223 } 2751 } 3224 } 2752 } 3225 } 2753 } 3226 } 2754 } 3227 2755 3228 // if found : retore old state 2756 // if found : retore old state 3229 if (oldItem != NULL) { 2757 if (oldItem != NULL) { 3230 subItem->setFlags(oldItem->flags()); // 2758 subItem->setFlags(oldItem->flags()); // flags 3231 subItem->setCheckState(0,oldItem->checkSt 2759 subItem->setCheckState(0,oldItem->checkState(0)); // check state 3232 subItem->setSelected(oldItem->isSelected( 2760 subItem->setSelected(oldItem->isSelected()); // selected 3233 subItem->setExpanded(oldItem->isExpanded 2761 subItem->setExpanded(oldItem->isExpanded ()); // expand 3234 2762 3235 // change color 2763 // change color 3236 // when we call this function, the color 2764 // when we call this function, the color in the item is the one of vis Attr 3237 2765 3238 std::map <int, QTreeWidgetItem* >::iterat 2766 std::map <int, QTreeWidgetItem* >::iterator it; 3239 << 2767 3240 // getOldPO 2768 // getOldPO 3241 int oldPOIndex = oldItem->data(0,Qt::User 2769 int oldPOIndex = oldItem->data(0,Qt::UserRole).toInt(); 3242 it = fOldPositivePoIndexSceneTreeWidgetQu 2770 it = fOldPositivePoIndexSceneTreeWidgetQuickMap.find(oldPOIndex); 3243 QColor color; 2771 QColor color; 3244 2772 3245 // get old Vis Attr Color 2773 // get old Vis Attr Color 3246 std::map <int, QColor >::iterator itVis; 2774 std::map <int, QColor >::iterator itVis; 3247 itVis = fOldVisAttrColorMap.find(oldPOInd 2775 itVis = fOldVisAttrColorMap.find(oldPOIndex); 3248 2776 3249 QColor oldVisAttrColor; 2777 QColor oldVisAttrColor; 3250 const QColor& newVisAttrColor = subItem-> 2778 const QColor& newVisAttrColor = subItem->data(2,Qt::UserRole).value<QColor>(); 3251 2779 3252 bool visAttrChange = false; 2780 bool visAttrChange = false; 3253 // if old vis attr color found 2781 // if old vis attr color found 3254 if (itVis != fOldVisAttrColorMap.end()) { 2782 if (itVis != fOldVisAttrColorMap.end()) { 3255 oldVisAttrColor = itVis->second; 2783 oldVisAttrColor = itVis->second; 3256 if (oldVisAttrColor != newVisAttrColor) 2784 if (oldVisAttrColor != newVisAttrColor) { 3257 visAttrChange = true; 2785 visAttrChange = true; 3258 } 2786 } 3259 } else { 2787 } else { 3260 visAttrChange = true; 2788 visAttrChange = true; 3261 } 2789 } 3262 << 2790 3263 if (visAttrChange) { 2791 if (visAttrChange) { 3264 fOldVisAttrColorMap.insert(std::pair <i 2792 fOldVisAttrColorMap.insert(std::pair <int, QColor > (subItem->data(0,Qt::UserRole).toInt(),newVisAttrColor) ); 3265 2793 3266 } else { // if no changes, get old PO val 2794 } else { // if no changes, get old PO value 3267 // if old PO found 2795 // if old PO found 3268 if (it != fOldPositivePoIndexSceneTreeW 2796 if (it != fOldPositivePoIndexSceneTreeWidgetQuickMap.end()) { 3269 color = (it->second)->data(2,Qt::User << 2797 color = (it->second)->data(2,Qt::UserRole).value<QColor>(); 3270 } else { 2798 } else { 3271 color = oldItem->data(2,Qt::UserRole) << 2799 color = oldItem->data(2,Qt::UserRole).value<QColor>(); 3272 } 2800 } >> 2801 #ifdef G4DEBUG_VIS_OGL >> 2802 printf("====color name:%s\n",color.name().toStdString().c_str()); >> 2803 #endif 3273 changeQColorForTreeWidgetItem(subItem,c 2804 changeQColorForTreeWidgetItem(subItem,color); 3274 } 2805 } 3275 } 2806 } 3276 2807 3277 return; 2808 return; 3278 } 2809 } 3279 2810 3280 2811 3281 2812 3282 // Check if both items are identical. 2813 // Check if both items are identical. 3283 // For that, check name, copy number, transfo 2814 // For that, check name, copy number, transformation 3284 // special case for "non Touchables", do not 2815 // special case for "non Touchables", do not check the PO index, check only the name 3285 bool G4OpenGLQtViewer::isSameSceneTreeElement 2816 bool G4OpenGLQtViewer::isSameSceneTreeElement( 3286 QTreeWidgetItem* parentOldItem 2817 QTreeWidgetItem* parentOldItem 3287 ,QTreeWidgetItem* parentNewItem 2818 ,QTreeWidgetItem* parentNewItem 3288 ) { 2819 ) { 3289 2820 3290 int newPO = -1; 2821 int newPO = -1; 3291 int oldPO = -1; 2822 int oldPO = -1; 3292 << 2823 3293 int newCpNumber = -1; 2824 int newCpNumber = -1; 3294 int oldCpNumber = -1; 2825 int oldCpNumber = -1; 3295 2826 3296 bool firstWhile = true; 2827 bool firstWhile = true; 3297 2828 3298 while ((parentOldItem != NULL) && (parentNe 2829 while ((parentOldItem != NULL) && (parentNewItem != NULL)) { 3299 2830 3300 // check transform, optimize getting data 2831 // check transform, optimize getting data(..,..) that consume lot of time 3301 if (!firstWhile) { 2832 if (!firstWhile) { 3302 oldPO = parentOldItem->data(0,Qt::UserR 2833 oldPO = parentOldItem->data(0,Qt::UserRole).toInt(); 3303 newPO = parentNewItem->data(0,Qt::UserR 2834 newPO = parentNewItem->data(0,Qt::UserRole).toInt(); 3304 } 2835 } 3305 firstWhile = false; 2836 firstWhile = false; 3306 << 2837 3307 if ((oldPO >= 0) && 2838 if ((oldPO >= 0) && 3308 (newPO >= 0)) { 2839 (newPO >= 0)) { 3309 const PVPath& oldFullPath = fOldTreeIte 2840 const PVPath& oldFullPath = fOldTreeItemModels[oldPO]; 3310 const PVPath& newFullPath = fTreeItemMo 2841 const PVPath& newFullPath = fTreeItemModels[newPO]; 3311 if ((oldFullPath.size() > 0) && 2842 if ((oldFullPath.size() > 0) && 3312 (newFullPath.size() > 0)) { 2843 (newFullPath.size() > 0)) { 3313 if (oldFullPath.size() != newFullPath 2844 if (oldFullPath.size() != newFullPath.size()) { 3314 return false; 2845 return false; 3315 } 2846 } 3316 if (oldFullPath.at(oldFullPath.size() 2847 if (oldFullPath.at(oldFullPath.size()-1).GetTransform () == newFullPath.at(newFullPath.size()-1).GetTransform ()) { 3317 newCpNumber = newFullPath.at(newFul 2848 newCpNumber = newFullPath.at(newFullPath.size()-1).GetCopyNo(); 3318 oldCpNumber = oldFullPath.at(oldFul 2849 oldCpNumber = oldFullPath.at(oldFullPath.size()-1).GetCopyNo(); 3319 // ok 2850 // ok 3320 } else { 2851 } else { 3321 return false; 2852 return false; 3322 } 2853 } 3323 } 2854 } 3324 } 2855 } 3325 << 2856 3326 // Check copy Number 2857 // Check copy Number 3327 if (oldCpNumber == -1) { 2858 if (oldCpNumber == -1) { 3328 oldCpNumber = parentOldItem->data(1,Qt: 2859 oldCpNumber = parentOldItem->data(1,Qt::UserRole).toInt(); 3329 } 2860 } 3330 if (newCpNumber == -1) { 2861 if (newCpNumber == -1) { 3331 newCpNumber = parentNewItem->data(1,Qt: 2862 newCpNumber = parentNewItem->data(1,Qt::UserRole).toInt(); 3332 } 2863 } 3333 if ((oldCpNumber != newCpNumber) || 2864 if ((oldCpNumber != newCpNumber) || 3334 // Check name 2865 // Check name 3335 (parentOldItem->text(0) != parentNewI << 2866 (parentOldItem->text(0) != parentNewItem->text(0)) ) { 3336 // try to optimize 2867 // try to optimize 3337 return false; << 2868 return false; 3338 } else if ((parentOldItem->text(0) != par 2869 } else if ((parentOldItem->text(0) != parentNewItem->text(0)) || // Logical Name 3339 (parentOldItem->text(3) != par 2870 (parentOldItem->text(3) != parentNewItem->text(3))) { // Check logical name 3340 return false; 2871 return false; 3341 } else { 2872 } else { 3342 parentOldItem = parentOldItem->parent() 2873 parentOldItem = parentOldItem->parent(); 3343 parentNewItem = parentNewItem->parent() 2874 parentNewItem = parentNewItem->parent(); 3344 } 2875 } 3345 } // end while 2876 } // end while 3346 2877 3347 return true; 2878 return true; 3348 } 2879 } 3349 2880 3350 2881 3351 void G4OpenGLQtViewer::addNonPVSceneTreeEleme 2882 void G4OpenGLQtViewer::addNonPVSceneTreeElement( 3352 const G4String& model 2883 const G4String& model 3353 ,int currentPOIndex 2884 ,int currentPOIndex 3354 ,const std::string& modelDescription 2885 ,const std::string& modelDescription 3355 ,const G4Visible& visible 2886 ,const G4Visible& visible 3356 ) { 2887 ) { 3357 2888 3358 QString modelShortName = getModelShortName( 2889 QString modelShortName = getModelShortName(model); 3359 G4Colour color; 2890 G4Colour color; 3360 2891 3361 // Special case for text 2892 // Special case for text 3362 try { 2893 try { 3363 const G4Text& g4Text = dynamic_cast<const 2894 const G4Text& g4Text = dynamic_cast<const G4Text&>(visible); 3364 color = fSceneHandler.GetTextColour(g4Tex 2895 color = fSceneHandler.GetTextColour(g4Text); 3365 } 2896 } 3366 catch (const std::bad_cast&) { << 2897 catch (std::bad_cast) { 3367 color = fSceneHandler.GetColour(); << 2898 color = fSceneHandler.GetColour(visible); 3368 } << 3369 << 3370 // Special case for marker << 3371 try { << 3372 const G4VMarker& g4Marker = dynamic_cast< << 3373 if (g4Marker.GetInfo() != "") { << 3374 modelShortName = g4Marker.GetInfo(); << 3375 } << 3376 } 2899 } 3377 catch (const std::bad_cast&) {} << 3378 << 3379 if (modelShortName == "") { 2900 if (modelShortName == "") { 3380 return ; 2901 return ; 3381 } 2902 } 3382 // try to init it 2903 // try to init it 3383 if (fSceneTreeComponentTreeWidget == NULL) 2904 if (fSceneTreeComponentTreeWidget == NULL) { 3384 createSceneTreeComponent(); << 2905 initSceneTreeComponent(); 3385 } 2906 } 3386 2907 3387 // if no UI 2908 // if no UI 3388 if (fSceneTreeComponentTreeWidget == NULL) 2909 if (fSceneTreeComponentTreeWidget == NULL) { 3389 return; 2910 return; 3390 } 2911 } 3391 2912 3392 fSceneTreeComponentTreeWidget->blockSignals 2913 fSceneTreeComponentTreeWidget->blockSignals(true); 3393 2914 3394 // Create the "Model" node if not 2915 // Create the "Model" node if not 3395 2916 3396 QList<QTreeWidgetItem *> resItem; 2917 QList<QTreeWidgetItem *> resItem; 3397 resItem = fSceneTreeComponentTreeWidget->f 2918 resItem = fSceneTreeComponentTreeWidget->findItems (modelShortName, Qt::MatchExactly, 0 ); 3398 QTreeWidgetItem * currentItem = NULL; 2919 QTreeWidgetItem * currentItem = NULL; 3399 const PVPath tmpFullPath; 2920 const PVPath tmpFullPath; 3400 2921 3401 if (resItem.empty()) { 2922 if (resItem.empty()) { 3402 currentItem = createTreeWidgetItem(tmpFul 2923 currentItem = createTreeWidgetItem(tmpFullPath, 3403 modelS 2924 modelShortName, 3404 0, // 2925 0, // currentPVCopyNb 3405 -1, // 2926 -1, // currentPVPOIndex 3406 "", 2927 "", 3407 Qt::Ch 2928 Qt::Checked, 3408 NULL, 2929 NULL, 3409 color) 2930 color); 3410 } else { 2931 } else { 3411 currentItem = resItem.first(); 2932 currentItem = resItem.first(); 3412 } 2933 } 3413 2934 3414 // Is this volume already in the tree AND P 2935 // Is this volume already in the tree AND PO is not the same? 3415 const QList<QTreeWidgetItem *>& 2936 const QList<QTreeWidgetItem *>& 3416 resItems = fSceneTreeComponentTreeWidget-> 2937 resItems = fSceneTreeComponentTreeWidget->findItems (QString(modelDescription.c_str()), Qt::MatchFixedString| Qt::MatchCaseSensitive|Qt::MatchRecursive, 0 ); 3417 << 2938 3418 bool alreadyPresent = false; 2939 bool alreadyPresent = false; 3419 for (int i = 0; i < resItems.size(); ++i) { 2940 for (int i = 0; i < resItems.size(); ++i) { 3420 if (currentPOIndex == resItems.at(i)->dat 2941 if (currentPOIndex == resItems.at(i)->data(0,Qt::UserRole).toInt()) { 3421 alreadyPresent = true; 2942 alreadyPresent = true; 3422 } 2943 } 3423 } 2944 } 3424 if (!alreadyPresent) { 2945 if (!alreadyPresent) { 3425 createTreeWidgetItem(tmpFullPath, 2946 createTreeWidgetItem(tmpFullPath, 3426 modelShortName, << 2947 QString(modelDescription.c_str()), 3427 0, // currentPVCopyN 2948 0, // currentPVCopyNb 3428 currentPOIndex, 2949 currentPOIndex, 3429 "", 2950 "", 3430 Qt::Checked, 2951 Qt::Checked, 3431 currentItem, 2952 currentItem, 3432 color); 2953 color); 3433 } 2954 } 3434 fSceneTreeComponentTreeWidget->blockSignals 2955 fSceneTreeComponentTreeWidget->blockSignals(false); 3435 << 2956 3436 } 2957 } 3437 2958 3438 2959 3439 /** 2960 /** 3440 Get the short name for a given label 2961 Get the short name for a given label 3441 */ 2962 */ 3442 QString G4OpenGLQtViewer::getModelShortName(c 2963 QString G4OpenGLQtViewer::getModelShortName(const G4String& model) { 3443 2964 3444 QString modelShortName = model.data(); 2965 QString modelShortName = model.data(); 3445 if (modelShortName.mid(0,modelShortName.ind 2966 if (modelShortName.mid(0,modelShortName.indexOf(" ")) == "G4PhysicalVolumeModel") { 3446 modelShortName = fTouchableVolumes; 2967 modelShortName = fTouchableVolumes; 3447 } else { 2968 } else { 3448 if (modelShortName.mid(0,2) == "G4") { 2969 if (modelShortName.mid(0,2) == "G4") { 3449 modelShortName = modelShortName.mid(2); 2970 modelShortName = modelShortName.mid(2); 3450 } 2971 } 3451 if (modelShortName.indexOf("Model") != -1 2972 if (modelShortName.indexOf("Model") != -1) { 3452 modelShortName = modelShortName.mid(0,m 2973 modelShortName = modelShortName.mid(0,modelShortName.indexOf("Model")); 3453 } 2974 } 3454 } 2975 } 3455 return modelShortName; 2976 return modelShortName; 3456 } 2977 } 3457 2978 3458 2979 3459 2980 3460 bool G4OpenGLQtViewer::isTouchableVisible(int 2981 bool G4OpenGLQtViewer::isTouchableVisible(int POindex){ 3461 2982 3462 // If no scene tree (Immediate viewer) 2983 // If no scene tree (Immediate viewer) 3463 if (fSceneTreeComponentTreeWidget == NULL) 2984 if (fSceneTreeComponentTreeWidget == NULL) { 3464 return false; 2985 return false; 3465 } 2986 } 3466 << 2987 3467 // should be the next one 2988 // should be the next one 3468 // Prevent to get out the std::map 2989 // Prevent to get out the std::map 3469 if (fLastSceneTreeWidgetAskForIterator != f 2990 if (fLastSceneTreeWidgetAskForIterator != fLastSceneTreeWidgetAskForIteratorEnd) { 3470 fLastSceneTreeWidgetAskForIterator++; 2991 fLastSceneTreeWidgetAskForIterator++; 3471 } 2992 } 3472 QTreeWidgetItem* item = getTreeWidgetItem(P 2993 QTreeWidgetItem* item = getTreeWidgetItem(POindex); 3473 << 2994 3474 if (item != NULL) { 2995 if (item != NULL) { 3475 if ( item->checkState(0) == Qt::Checked) 2996 if ( item->checkState(0) == Qt::Checked) { 3476 return true; 2997 return true; 3477 } 2998 } 3478 } << 2999 } 3479 return false; 3000 return false; 3480 } 3001 } 3481 3002 3482 3003 3483 bool G4OpenGLQtViewer::parseAndCheckVisibilit 3004 bool G4OpenGLQtViewer::parseAndCheckVisibility(QTreeWidgetItem * treeNode,int POindex){ 3484 bool isFound = false; 3005 bool isFound = false; 3485 for (int i = 0; i < treeNode->childCount() 3006 for (int i = 0; i < treeNode->childCount() ; ++i) { 3486 3007 3487 if (treeNode->child(i)->data(0,Qt::UserRo 3008 if (treeNode->child(i)->data(0,Qt::UserRole).toInt() == POindex) { 3488 if (treeNode->child(i)->checkState(0) = 3009 if (treeNode->child(i)->checkState(0) == Qt::Checked) { 3489 return true; 3010 return true; 3490 } 3011 } 3491 } 3012 } 3492 isFound = parseAndCheckVisibility(treeNod 3013 isFound = parseAndCheckVisibility(treeNode->child(i),POindex); 3493 if (isFound) { 3014 if (isFound) { 3494 return true; 3015 return true; 3495 } 3016 } 3496 } // end for 3017 } // end for 3497 return false; 3018 return false; 3498 } 3019 } 3499 3020 3500 3021 3501 std::string G4OpenGLQtViewer::parseSceneTreeA 3022 std::string G4OpenGLQtViewer::parseSceneTreeAndSaveState(){ 3502 std::string commandLine = ""; 3023 std::string commandLine = ""; 3503 for (int b=0;b<fSceneTreeComponentTreeWidge 3024 for (int b=0;b<fSceneTreeComponentTreeWidget->topLevelItemCount();b++) { 3504 commandLine += parseSceneTreeElementAndSa 3025 commandLine += parseSceneTreeElementAndSaveState(fSceneTreeComponentTreeWidget->topLevelItem(b),1)+"\n"; 3505 } 3026 } 3506 if (commandLine != "") { 3027 if (commandLine != "") { 3507 commandLine = std::string("# Disable auto 3028 commandLine = std::string("# Disable auto refresh and quieten vis messages whilst scene and\n") + 3508 "# trajectories are established:\n" + 3029 "# trajectories are established:\n" + 3509 "/vis/viewer/set/autoRefresh false\n" + 3030 "/vis/viewer/set/autoRefresh false\n" + 3510 "/vis/verbose errors" + 3031 "/vis/verbose errors" + 3511 commandLine + 3032 commandLine + 3512 "# Re-establish auto refreshing and verbo 3033 "# Re-establish auto refreshing and verbosity:\n" + 3513 "/vis/viewer/set/autoRefresh true\n" + 3034 "/vis/viewer/set/autoRefresh true\n" + 3514 "/vis/verbose confirmations\n"; 3035 "/vis/verbose confirmations\n"; 3515 } 3036 } 3516 return commandLine; 3037 return commandLine; 3517 } 3038 } 3518 3039 3519 3040 3520 std::string G4OpenGLQtViewer::parseSceneTreeE 3041 std::string G4OpenGLQtViewer::parseSceneTreeElementAndSaveState(QTreeWidgetItem* item, unsigned int level){ 3521 // parse current item 3042 // parse current item 3522 std::string str( level, ' ' ); 3043 std::string str( level, ' ' ); 3523 std::string commandLine = "\n#"+ str + "PV 3044 std::string commandLine = "\n#"+ str + "PV Name: " + item->text(0).toStdString(); 3524 3045 3525 if (item->text(3) != "") { 3046 if (item->text(3) != "") { 3526 commandLine += " LV Name: "+item->text(3) 3047 commandLine += " LV Name: "+item->text(3).toStdString()+"\n"; 3527 // save check state 3048 // save check state 3528 commandLine += "/vis/geometry/set/visibil 3049 commandLine += "/vis/geometry/set/visibility " + item->text(3).toStdString() + " ! "; // let default value for depth 3529 if (item->checkState(0) == Qt::Checked) { 3050 if (item->checkState(0) == Qt::Checked) { 3530 commandLine += "1"; 3051 commandLine += "1"; 3531 } 3052 } 3532 if (item->checkState(0) == Qt::Unchecked) 3053 if (item->checkState(0) == Qt::Unchecked) { 3533 commandLine += "0"; 3054 commandLine += "0"; 3534 } 3055 } 3535 commandLine +="\n"; 3056 commandLine +="\n"; 3536 << 3057 3537 // save color 3058 // save color 3538 const QColor& c = item->data(2,Qt::UserRo 3059 const QColor& c = item->data(2,Qt::UserRole).value<QColor>(); 3539 std::stringstream red; 3060 std::stringstream red; 3540 red << ((double)c.red())/255; 3061 red << ((double)c.red())/255; 3541 std::stringstream green; 3062 std::stringstream green; 3542 green << (double)c.green()/255; 3063 green << (double)c.green()/255; 3543 std::stringstream blue; 3064 std::stringstream blue; 3544 blue << ((double)c.blue())/255; 3065 blue << ((double)c.blue())/255; 3545 std::stringstream alpha; 3066 std::stringstream alpha; 3546 alpha << ((double)c.alpha())/255; 3067 alpha << ((double)c.alpha())/255; 3547 << 3068 3548 commandLine += "/vis/geometry/set/colour 3069 commandLine += "/vis/geometry/set/colour " + item->text(3).toStdString() + " ! " + red.str() + " " + green.str() + " " + blue.str() + " " + alpha.str()+"\n"; 3549 3070 3550 } else { 3071 } else { 3551 commandLine += "\n"; 3072 commandLine += "\n"; 3552 } 3073 } 3553 3074 3554 // parse childs 3075 // parse childs 3555 for (int b=0;b< item->childCount();b++) { 3076 for (int b=0;b< item->childCount();b++) { 3556 commandLine += parseSceneTreeElementAndSa 3077 commandLine += parseSceneTreeElementAndSaveState(item->child(b),level+1); 3557 } 3078 } 3558 << 3079 3559 return commandLine; 3080 return commandLine; 3560 } 3081 } 3561 3082 3562 3083 3563 void G4OpenGLQtViewer::sceneTreeComponentItem 3084 void G4OpenGLQtViewer::sceneTreeComponentItemChanged(QTreeWidgetItem* item, int) { 3564 3085 3565 if (fCheckSceneTreeComponentSignalLock == f 3086 if (fCheckSceneTreeComponentSignalLock == false) { 3566 fCheckSceneTreeComponentSignalLock = true 3087 fCheckSceneTreeComponentSignalLock = true; 3567 G4bool checked = false; 3088 G4bool checked = false; 3568 if (item->checkState(0) == Qt::Checked) { 3089 if (item->checkState(0) == Qt::Checked) { 3569 checked = true; 3090 checked = true; 3570 } 3091 } 3571 setCheckComponent(item,checked); 3092 setCheckComponent(item,checked); 3572 updateQWidget(); 3093 updateQWidget(); 3573 3094 3574 fCheckSceneTreeComponentSignalLock = fals 3095 fCheckSceneTreeComponentSignalLock = false; 3575 } 3096 } 3576 } 3097 } 3577 3098 3578 3099 3579 void G4OpenGLQtViewer::sceneTreeComponentSele 3100 void G4OpenGLQtViewer::sceneTreeComponentSelected() { >> 3101 /* >> 3102 if (fSceneTreeComponentTreeWidget) { >> 3103 if (! fSceneTreeComponentTreeWidget->selectedItems().isEmpty ()) { >> 3104 QTreeWidgetItem* item = fSceneTreeComponentTreeWidget->selectedItems ().first(); >> 3105 if (item) { >> 3106 >> 3107 const PVPath& fullPath = fTreeItemModels[item->data(0,Qt::UserRole).toInt()]; >> 3108 if (fullPath.size() > 0) { >> 3109 const G4VisAttributes* visAttr2 = GetApplicableVisAttributes(fullPath.at(fullPath.size()-1).GetPhysicalVolume()->GetLogicalVolume()->GetVisAttributes()); >> 3110 } >> 3111 } >> 3112 } >> 3113 } >> 3114 */ 3580 } 3115 } 3581 3116 >> 3117 3582 void G4OpenGLQtViewer::changeDepthInSceneTree 3118 void G4OpenGLQtViewer::changeDepthInSceneTree (int val){ 3583 3119 3584 // If no scene tree (Immediate viewer) 3120 // If no scene tree (Immediate viewer) 3585 if (fSceneTreeComponentTreeWidget == NULL) 3121 if (fSceneTreeComponentTreeWidget == NULL) { 3586 return; 3122 return; 3587 } 3123 } 3588 3124 3589 // max depth : fSceneTreeDepth 3125 // max depth : fSceneTreeDepth 3590 // val is between 0 and 1 3126 // val is between 0 and 1 3591 // 0 .1 .2 .3 .4 .5 .6 .7 .8 .9 1 3127 // 0 .1 .2 .3 .4 .5 .6 .7 .8 .9 1 3592 // 1 1.4 2 << 3128 // 1 1.4 2 3593 // 1 2 3 4 3129 // 1 2 3 4 3594 3130 3595 // Get the depth : 3131 // Get the depth : 3596 double depth = 1 + ((double)val)/1000 * ((d 3132 double depth = 1 + ((double)val)/1000 * ((double)fSceneTreeDepth+1); 3597 << 3133 3598 // lock update on scene tree items 3134 // lock update on scene tree items 3599 fCheckSceneTreeComponentSignalLock = true; 3135 fCheckSceneTreeComponentSignalLock = true; 3600 << 3136 3601 // Disable redraw each time ! 3137 // Disable redraw each time ! 3602 G4bool currentAutoRefresh = fVP.IsAutoRefre 3138 G4bool currentAutoRefresh = fVP.IsAutoRefresh(); 3603 fVP.SetAutoRefresh(false); 3139 fVP.SetAutoRefresh(false); 3604 3140 3605 for (int b=0;b<fSceneTreeComponentTreeWidge 3141 for (int b=0;b<fSceneTreeComponentTreeWidget->topLevelItemCount();b++) { 3606 changeDepthOnSceneTreeItem(depth,1.,fScen 3142 changeDepthOnSceneTreeItem(depth,1.,fSceneTreeComponentTreeWidget->topLevelItem(b)); 3607 } 3143 } 3608 3144 3609 // Enable redraw ! 3145 // Enable redraw ! 3610 fVP.SetAutoRefresh(currentAutoRefresh); 3146 fVP.SetAutoRefresh(currentAutoRefresh); 3611 updateQWidget(); 3147 updateQWidget(); 3612 3148 3613 // unlock update on scene tree items 3149 // unlock update on scene tree items 3614 fCheckSceneTreeComponentSignalLock = false; 3150 fCheckSceneTreeComponentSignalLock = false; 3615 3151 3616 } 3152 } 3617 3153 3618 3154 3619 void G4OpenGLQtViewer::changeColorAndTranspar 3155 void G4OpenGLQtViewer::changeColorAndTransparency(QTreeWidgetItem* item,int) { 3620 3156 3621 if (item == NULL) { 3157 if (item == NULL) { 3622 return; 3158 return; 3623 } 3159 } 3624 const QColor& old = QColor(item->data(2,Qt: 3160 const QColor& old = QColor(item->data(2,Qt::UserRole).value<QColor>()); 3625 3161 >> 3162 #if QT_VERSION < 0x040500 >> 3163 bool a; >> 3164 const QColor& color = QColor(QColorDialog::getRgba (old.rgba(),&a,fSceneTreeComponentTreeWidget)); >> 3165 #else 3626 const QColor& color = QColorDialog::getColo 3166 const QColor& color = QColorDialog::getColor(old, 3627 fScen 3167 fSceneTreeComponentTreeWidget, 3628 " Get 3168 " Get color and transparency", 3629 QColo 3169 QColorDialog::ShowAlphaChannel); 3630 << 3170 #endif >> 3171 3631 if (color.isValid()) { 3172 if (color.isValid()) { 3632 3173 3633 changeColorAndTransparency(item->data(0,Q << 3174 // change vis attributes to set new colour 3634 G4Colour (((G4 << 3175 G4int iPO = item->data(0,Qt::UserRole).toInt(); 3635 ((G4 << 3176 if (iPO >= 0 && fTreeItemModels.find(iPO) != fTreeItemModels.end()) { 3636 ((G4 << 3177 const PVPath& fullPath = fTreeItemModels[iPO]; 3637 ((G4 << 3178 // If a physical volume 3638 << 3179 if (fullPath.size()) { >> 3180 >> 3181 // Instantiate a working copy of a G4VisAttributes object... >> 3182 G4VisAttributes workingVisAtts; >> 3183 // and set the colour. >> 3184 G4Colour g4c(((G4double)color.red())/255, >> 3185 ((G4double)color.green())/255, >> 3186 ((G4double)color.blue())/255, >> 3187 ((G4double)color.alpha())/255); >> 3188 workingVisAtts.SetColour(g4c); >> 3189 >> 3190 // Add a vis atts modifier to the view parameters... >> 3191 fVP.AddVisAttributesModifier >> 3192 (G4ModelingParameters::VisAttributesModifier >> 3193 (workingVisAtts, >> 3194 G4ModelingParameters::VASColour, >> 3195 fullPath)); >> 3196 // G4ModelingParameters::VASColour tells G4PhysicalVolumeModel that it is >> 3197 // the colour that should be picked out and merged with the touchable's >> 3198 // normal vis attributes. >> 3199 } >> 3200 } >> 3201 3639 // set scene tree parameters 3202 // set scene tree parameters 3640 changeQColorForTreeWidgetItem(item,color) 3203 changeQColorForTreeWidgetItem(item,color); 3641 } 3204 } 3642 } 3205 } 3643 3206 3644 3207 3645 void G4OpenGLQtViewer::changeColorAndTranspar << 3646 << 3647 // change vis attributes to set new colour << 3648 G4int iPO = index; << 3649 if (iPO >= 0 && fTreeItemModels.find(iPO) ! << 3650 const PVPath& fullPath = fTreeItemModels[ << 3651 // If a physical volume << 3652 if (fullPath.size()) { << 3653 SetTouchable(fullPath); << 3654 TouchableSetColour(fullPath, color); << 3655 fMouseOnSceneTree = true; << 3656 } << 3657 } << 3658 } << 3659 << 3660 << 3661 G4Colour G4OpenGLQtViewer::getColorForPoIndex 3208 G4Colour G4OpenGLQtViewer::getColorForPoIndex(int poIndex) { 3662 // FIXME 09/2014 : Could be optimize by sea << 3209 3663 QTreeWidgetItem* item = getTreeWidgetItem(p 3210 QTreeWidgetItem* item = getTreeWidgetItem(poIndex); 3664 3211 3665 if (item != NULL) { 3212 if (item != NULL) { 3666 << 3213 3667 const QColor& color = item->data(2,Qt::Us 3214 const QColor& color = item->data(2,Qt::UserRole).value<QColor>(); 3668 G4Colour g4c(((G4double)color.red())/255, 3215 G4Colour g4c(((G4double)color.red())/255, 3669 ((G4double)color.green())/25 3216 ((G4double)color.green())/255, 3670 ((G4double)color.blue())/255 3217 ((G4double)color.blue())/255, 3671 ((G4double)color.alpha())/25 3218 ((G4double)color.alpha())/255); 3672 3219 3673 return g4c; 3220 return g4c; 3674 } 3221 } 3675 return G4Colour(); 3222 return G4Colour(); 3676 } 3223 } 3677 3224 3678 3225 3679 const std::vector<G4ModelingParameters::VisAt 3226 const std::vector<G4ModelingParameters::VisAttributesModifier>* 3680 G4OpenGLQtViewer::GetPrivateVisAttributesModi 3227 G4OpenGLQtViewer::GetPrivateVisAttributesModifiers() const 3681 { 3228 { 3682 static std::vector<G4ModelingParameters::Vi 3229 static std::vector<G4ModelingParameters::VisAttributesModifier> 3683 privateVisAttributesModifiers; 3230 privateVisAttributesModifiers; 3684 3231 3685 privateVisAttributesModifiers.clear(); 3232 privateVisAttributesModifiers.clear(); 3686 3233 3687 // I don't think we need this. (JA Sep 2016) << 3688 // // For each modified touchable... 3234 // // For each modified touchable... 3689 // std::map<int,PVPath>::const_iterator i; 3235 // std::map<int,PVPath>::const_iterator i; 3690 // for (i = fTreeItemModels.begin(); 3236 // for (i = fTreeItemModels.begin(); 3691 // i != fTreeItemModels.end(); 3237 // i != fTreeItemModels.end(); 3692 // ++i) { 3238 // ++i) { 3693 // 3239 // 3694 // // How do I know if it's been modified 3240 // // How do I know if it's been modified or not? 3695 // 3241 // 3696 // int iPO = i->first; 3242 // int iPO = i->first; 3697 // const PVPath& fullPath = i->second; 3243 // const PVPath& fullPath = i->second; 3698 // 3244 // 3699 // // If a physical volume 3245 // // If a physical volume 3700 // if (fullPath.size()) { 3246 // if (fullPath.size()) { 3701 // 3247 // 3702 // // const G4bool& visibilityChanged 3248 // // const G4bool& visibilityChanged = ??? 3703 // // const G4bool& visibility = ??? 3249 // // const G4bool& visibility = ??? 3704 // // const G4bool& colourChanged = ? 3250 // // const G4bool& colourChanged = ??? 3705 // // const QColor& colour = ??? 3251 // // const QColor& colour = ??? 3706 // // G4Colour g4colour(((G4double)co 3252 // // G4Colour g4colour(((G4double)colour.red())/255, 3707 // // ((G4double)co 3253 // // ((G4double)colour.green())/255, 3708 // // ((G4double)co 3254 // // ((G4double)colour.blue())/255, 3709 // // ((G4double)co 3255 // // ((G4double)colour.alpha())/255); 3710 // // Next 4 lines are for testing, to b 3256 // // Next 4 lines are for testing, to be replaced by the above... 3711 // G4bool visibilityChanged = true; 3257 // G4bool visibilityChanged = true; 3712 // G4bool visibility = true; 3258 // G4bool visibility = true; 3713 // G4bool colourChanged = true; 3259 // G4bool colourChanged = true; 3714 // G4Colour g4colour(G4Colour::Red()); 3260 // G4Colour g4colour(G4Colour::Red()); 3715 // 3261 // 3716 // // Instantiate a working copy of a G4 3262 // // Instantiate a working copy of a G4VisAttributes object... 3717 // G4VisAttributes workingVisAtts; 3263 // G4VisAttributes workingVisAtts; 3718 // // ...and use it to create vis attrib 3264 // // ...and use it to create vis attribute modifiers... 3719 // if (visibilityChanged) { 3265 // if (visibilityChanged) { 3720 // workingVisAtts.SetVisibility(visibi 3266 // workingVisAtts.SetVisibility(visibility); 3721 // privateVisAttributesModifiers.push_ 3267 // privateVisAttributesModifiers.push_back 3722 // (G4ModelingParameters::VisAttribute 3268 // (G4ModelingParameters::VisAttributesModifier 3723 // (workingVisAtts, 3269 // (workingVisAtts, 3724 // G4ModelingParameters::VASVisibili 3270 // G4ModelingParameters::VASVisibility, 3725 // fullPath)); 3271 // fullPath)); 3726 // } 3272 // } 3727 // if (colourChanged) { 3273 // if (colourChanged) { 3728 // workingVisAtts.SetColour(g4colour); 3274 // workingVisAtts.SetColour(g4colour); 3729 // privateVisAttributesModifiers.push_ 3275 // privateVisAttributesModifiers.push_back 3730 // (G4ModelingParameters::VisAttribute 3276 // (G4ModelingParameters::VisAttributesModifier 3731 // (workingVisAtts, 3277 // (workingVisAtts, 3732 // G4ModelingParameters::VASColour, 3278 // G4ModelingParameters::VASColour, 3733 // fullPath)); 3279 // fullPath)); 3734 // } 3280 // } 3735 // } 3281 // } 3736 // } 3282 // } 3737 3283 3738 return &privateVisAttributesModifiers; 3284 return &privateVisAttributesModifiers; 3739 } 3285 } 3740 3286 3741 3287 3742 void G4OpenGLQtViewer::changeSearchSelection( 3288 void G4OpenGLQtViewer::changeSearchSelection() 3743 { 3289 { 3744 const QString& searchText = fFilterOutput-> << 3290 const QString& searchText = fHelpLine->text(); 3745 if (fSceneTreeComponentTreeWidget == NULL) 3291 if (fSceneTreeComponentTreeWidget == NULL) { 3746 return; 3292 return; 3747 } 3293 } 3748 3294 3749 // unselect all 3295 // unselect all 3750 for (int a=0; a<fSceneTreeComponentTreeWidg 3296 for (int a=0; a<fSceneTreeComponentTreeWidget->topLevelItemCount(); a++) { 3751 fSceneTreeComponentTreeWidget->topLevelIt 3297 fSceneTreeComponentTreeWidget->topLevelItem(a)->setExpanded(false); 3752 fSceneTreeComponentTreeWidget->topLevelIt 3298 fSceneTreeComponentTreeWidget->topLevelItem(a)->setSelected(false); 3753 clearSceneTreeSelection(fSceneTreeCompone 3299 clearSceneTreeSelection(fSceneTreeComponentTreeWidget->topLevelItem(a)); 3754 } 3300 } 3755 3301 3756 QList<QTreeWidgetItem *> itemList = fSceneT 3302 QList<QTreeWidgetItem *> itemList = fSceneTreeComponentTreeWidget->findItems (searchText,Qt::MatchContains | Qt::MatchRecursive,0); 3757 3303 3758 for (int i = 0; i < itemList.size(); ++i) { 3304 for (int i = 0; i < itemList.size(); ++i) { 3759 QTreeWidgetItem* expandParentItem = itemL 3305 QTreeWidgetItem* expandParentItem = itemList.at(i); 3760 while (expandParentItem->parent() != NULL 3306 while (expandParentItem->parent() != NULL) { 3761 expandParentItem->parent()->setExpanded 3307 expandParentItem->parent()->setExpanded(true); 3762 expandParentItem = expandParentItem->pa 3308 expandParentItem = expandParentItem->parent(); 3763 } 3309 } 3764 itemList.at(i)->setSelected(true); 3310 itemList.at(i)->setSelected(true); 3765 } << 3311 } 3766 3312 3767 } 3313 } 3768 3314 3769 3315 3770 void G4OpenGLQtViewer::clearSceneTreeSelectio 3316 void G4OpenGLQtViewer::clearSceneTreeSelection(QTreeWidgetItem* item) { 3771 for (int a=0; a<item->childCount(); a++) { 3317 for (int a=0; a<item->childCount(); a++) { 3772 item->child(a)->setSelected(false); 3318 item->child(a)->setSelected(false); 3773 item->child(a)->setExpanded(false); 3319 item->child(a)->setExpanded(false); 3774 clearSceneTreeSelection(item->child(a)); 3320 clearSceneTreeSelection(item->child(a)); 3775 } 3321 } 3776 3322 3777 } 3323 } 3778 3324 3779 3325 3780 bool G4OpenGLQtViewer::isPVVolume(QTreeWidget 3326 bool G4OpenGLQtViewer::isPVVolume(QTreeWidgetItem* item) { 3781 QTreeWidgetItem* sParent = item; 3327 QTreeWidgetItem* sParent = item; 3782 while (sParent->parent() != NULL) { 3328 while (sParent->parent() != NULL) { 3783 sParent = sParent->parent(); 3329 sParent = sParent->parent(); 3784 } 3330 } 3785 if (sParent->text(0) != fTouchableVolumes) 3331 if (sParent->text(0) != fTouchableVolumes) { 3786 return false; 3332 return false; 3787 } 3333 } 3788 // item is the "Touchable" node 3334 // item is the "Touchable" node 3789 if (item->text(0) == fTouchableVolumes) { 3335 if (item->text(0) == fTouchableVolumes) { 3790 return false; 3336 return false; 3791 } 3337 } 3792 return true; 3338 return true; 3793 } 3339 } 3794 3340 3795 3341 3796 void G4OpenGLQtViewer::changeDepthOnSceneTree 3342 void G4OpenGLQtViewer::changeDepthOnSceneTreeItem( 3797 double lookForDepth 3343 double lookForDepth 3798 ,double currentDepth 3344 ,double currentDepth 3799 ,QTreeWidgetItem* item 3345 ,QTreeWidgetItem* item 3800 ) { 3346 ) { 3801 double transparencyLevel = 0.; 3347 double transparencyLevel = 0.; 3802 << 3348 3803 // look for a 2.2 depth and we are at level << 3349 // look for a 2.2 depth and we are at level 3 3804 // -> Set all theses items to Opaque 3350 // -> Set all theses items to Opaque 3805 // ONLY if it is a PV volume ! 3351 // ONLY if it is a PV volume ! 3806 if (isPVVolume(item)) { 3352 if (isPVVolume(item)) { 3807 if ((lookForDepth-currentDepth) < 0) { 3353 if ((lookForDepth-currentDepth) < 0) { 3808 item->setCheckState(0,Qt::Checked); 3354 item->setCheckState(0,Qt::Checked); 3809 updatePositivePoIndexSceneTreeWidgetQui 3355 updatePositivePoIndexSceneTreeWidgetQuickMap(item->data(0,Qt::UserRole).toInt(),item); 3810 transparencyLevel = 1; 3356 transparencyLevel = 1; 3811 } else if ((lookForDepth-currentDepth) > 3357 } else if ((lookForDepth-currentDepth) > 1 ){ 3812 item->setCheckState(0,Qt::Unchecked); 3358 item->setCheckState(0,Qt::Unchecked); 3813 updatePositivePoIndexSceneTreeWidgetQui 3359 updatePositivePoIndexSceneTreeWidgetQuickMap(item->data(0,Qt::UserRole).toInt(),item); 3814 transparencyLevel = 0; 3360 transparencyLevel = 0; 3815 } else { 3361 } else { 3816 item->setCheckState(0,Qt::Checked); 3362 item->setCheckState(0,Qt::Checked); 3817 updatePositivePoIndexSceneTreeWidgetQui 3363 updatePositivePoIndexSceneTreeWidgetQuickMap(item->data(0,Qt::UserRole).toInt(),item); 3818 transparencyLevel = 1-(lookForDepth-cur 3364 transparencyLevel = 1-(lookForDepth-currentDepth); 3819 } 3365 } 3820 } 3366 } 3821 << 3367 3822 if (item->data(0,Qt::UserRole).toInt() >= 0 3368 if (item->data(0,Qt::UserRole).toInt() >= 0) { 3823 const G4Colour& color = getColorForPoInde 3369 const G4Colour& color = getColorForPoIndex(item->data(0,Qt::UserRole).toInt()); 3824 << 3370 3825 // We are less depper (ex:tree depth:2) t 3371 // We are less depper (ex:tree depth:2) than lookForDepth (ex:3.1) 3826 // -> Have to hide this level ONLY if it 3372 // -> Have to hide this level ONLY if it was not hidden before 3827 << 3373 3828 // Not on a top level item case 3374 // Not on a top level item case 3829 // Do not set if it was already set 3375 // Do not set if it was already set 3830 3376 3831 // Should add them all the time in case o 3377 // Should add them all the time in case of an older command has change transparency 3832 // before. Should be checked in changeDep 3378 // before. Should be checked in changeDepthInSceneTree for duplicated commands 3833 // Do not change transparency if not visi 3379 // Do not change transparency if not visible by humain (and avoid precision value 3834 // problems..) 3380 // problems..) 3835 if (((color.GetAlpha()-transparencyLevel) 3381 if (((color.GetAlpha()-transparencyLevel) > 0.000001) || 3836 ((color.GetAlpha()-transparencyLevel) 3382 ((color.GetAlpha()-transparencyLevel) < -0.000001)) { 3837 if ((item->text(3) != "")) { 3383 if ((item->text(3) != "")) { 3838 // FIXME : Should not test this here 3384 // FIXME : Should not test this here because of transparent 3839 // volume that will came after and wi 3385 // volume that will came after and with a different alpha level 3840 // Good thing to do is to check and s 3386 // Good thing to do is to check and suppress doubles in changeDepthInSceneTree 3841 // and then check if last (transparen 3387 // and then check if last (transparents volumes) has to change alpha 3842 3388 3843 changeQColorForTreeWidgetItem(item,QC 3389 changeQColorForTreeWidgetItem(item,QColor((int)(color.GetRed()*255), 3844 3390 (int)(color.GetGreen()*255), 3845 3391 (int)(color.GetBlue()*255), 3846 3392 (int)(transparencyLevel*255))); 3847 } 3393 } 3848 } 3394 } 3849 } 3395 } 3850 3396 3851 for (int b=0;b< item->childCount();b++) { 3397 for (int b=0;b< item->childCount();b++) { 3852 changeDepthOnSceneTreeItem(lookForDepth,c 3398 changeDepthOnSceneTreeItem(lookForDepth,currentDepth+1,item->child(b)); 3853 } 3399 } 3854 } 3400 } 3855 3401 3856 3402 3857 void G4OpenGLQtViewer::clearTreeWidget(){ 3403 void G4OpenGLQtViewer::clearTreeWidget(){ 3858 // be careful about calling this twice 3404 // be careful about calling this twice 3859 3405 3860 if (fSceneTreeComponentTreeWidget) { 3406 if (fSceneTreeComponentTreeWidget) { 3861 3407 >> 3408 if (fOldSceneTreeComponentTreeWidget == NULL) { >> 3409 fOldSceneTreeComponentTreeWidget = new QTreeWidget(); >> 3410 } >> 3411 // clear old scene tree >> 3412 int tmp = fOldSceneTreeComponentTreeWidget->topLevelItemCount(); >> 3413 while (tmp > 0) { >> 3414 delete fOldSceneTreeComponentTreeWidget->takeTopLevelItem (0); >> 3415 tmp = fOldSceneTreeComponentTreeWidget->topLevelItemCount(); >> 3416 } >> 3417 3862 if (fSceneTreeComponentTreeWidget->topLev 3418 if (fSceneTreeComponentTreeWidget->topLevelItemCount () > 0) { 3863 3419 3864 fPVRootNodeCreate = false; 3420 fPVRootNodeCreate = false; 3865 3421 3866 // reset all old 3422 // reset all old 3867 fOldPositivePoIndexSceneTreeWidgetQuick 3423 fOldPositivePoIndexSceneTreeWidgetQuickMap.clear(); 3868 fOldNullPoIndexSceneTreeWidgetQuickVect 3424 fOldNullPoIndexSceneTreeWidgetQuickVector.clear(); 3869 fOldTreeItemModels.clear(); 3425 fOldTreeItemModels.clear(); 3870 3426 3871 // Clone everything << 3427 // Clone everything 3872 for (int b =0; b <fSceneTreeComponentTr 3428 for (int b =0; b <fSceneTreeComponentTreeWidget->topLevelItemCount();b++) { 3873 // All tree widgets are in : 3429 // All tree widgets are in : 3874 // then we could get the old POindex << 3430 // then we could get the old POindex and get 3875 // .visible/Hidden 3431 // .visible/Hidden 3876 // .Check/Uncheck 3432 // .Check/Uncheck 3877 // .selected 3433 // .selected 3878 // .colour status from std::map 3434 // .colour status from std::map 3879 3435 3880 // clone top level items 3436 // clone top level items 3881 int poIndex = fSceneTreeComponentTree 3437 int poIndex = fSceneTreeComponentTreeWidget->topLevelItem(b)->data(0,Qt::UserRole).toInt(); 3882 if (poIndex != -1) { 3438 if (poIndex != -1) { 3883 fOldPositivePoIndexSceneTreeWidgetQ 3439 fOldPositivePoIndexSceneTreeWidgetQuickMap.insert(std::pair <int, QTreeWidgetItem*> (poIndex,cloneWidgetItem(fSceneTreeComponentTreeWidget->topLevelItem(b)))); 3884 } else { 3440 } else { 3885 fOldNullPoIndexSceneTreeWidgetQuick 3441 fOldNullPoIndexSceneTreeWidgetQuickVector.push_back(cloneWidgetItem(fSceneTreeComponentTreeWidget->topLevelItem(b))); 3886 } 3442 } 3887 3443 3888 // clone leaves 3444 // clone leaves 3889 cloneSceneTree(fSceneTreeComponentTre 3445 cloneSceneTree(fSceneTreeComponentTreeWidget->topLevelItem(b)); 3890 } 3446 } 3891 // delete all elements 3447 // delete all elements 3892 3448 3893 fOldTreeItemModels.insert(fTreeItemMode << 3449 fOldTreeItemModels.insert(fTreeItemModels.begin(), fTreeItemModels.end()); 3894 3450 3895 // all is copy, then clear scene tree 3451 // all is copy, then clear scene tree 3896 int tmp2 = fSceneTreeComponentTreeWidge 3452 int tmp2 = fSceneTreeComponentTreeWidget->topLevelItemCount(); 3897 while (tmp2 > 0) { 3453 while (tmp2 > 0) { 3898 delete fSceneTreeComponentTreeWidget- 3454 delete fSceneTreeComponentTreeWidget->takeTopLevelItem (0); 3899 tmp2 = fSceneTreeComponentTreeWidget- 3455 tmp2 = fSceneTreeComponentTreeWidget->topLevelItemCount(); 3900 } 3456 } 3901 fPositivePoIndexSceneTreeWidgetQuickMap 3457 fPositivePoIndexSceneTreeWidgetQuickMap.clear(); 3902 3458 3903 // put correct value in paramaters 3459 // put correct value in paramaters 3904 fOldLastSceneTreeWidgetAskForIterator = 3460 fOldLastSceneTreeWidgetAskForIterator = fOldPositivePoIndexSceneTreeWidgetQuickMap.begin(); 3905 fOldLastSceneTreeWidgetAskForIteratorEn 3461 fOldLastSceneTreeWidgetAskForIteratorEnd = fOldPositivePoIndexSceneTreeWidgetQuickMap.end(); 3906 fSceneTreeDepth = 1; 3462 fSceneTreeDepth = 1; 3907 fModelShortNameItem = NULL; 3463 fModelShortNameItem = NULL; 3908 fMaxPOindexInserted = -1; 3464 fMaxPOindexInserted = -1; 3909 3465 3910 } 3466 } 3911 } 3467 } 3912 } 3468 } 3913 3469 3914 3470 3915 /** 3471 /** 3916 Clone : << 3472 Clone : 3917 - Open/close 3473 - Open/close 3918 - Visible/hidden 3474 - Visible/hidden 3919 - Selected 3475 - Selected 3920 */ 3476 */ 3921 QTreeWidgetItem * G4OpenGLQtViewer::cloneWidg 3477 QTreeWidgetItem * G4OpenGLQtViewer::cloneWidgetItem(QTreeWidgetItem* item) { 3922 3478 3923 QTreeWidgetItem* cloneItem = new QTreeWidge 3479 QTreeWidgetItem* cloneItem = new QTreeWidgetItem(); 3924 3480 3925 // Clone what is create createTreeWidgetIte 3481 // Clone what is create createTreeWidgetItem step 3926 3482 3927 cloneItem->setText(0,item->text(0)); 3483 cloneItem->setText(0,item->text(0)); 3928 cloneItem->setData(1,Qt::UserRole,item->dat 3484 cloneItem->setData(1,Qt::UserRole,item->data(1,Qt::UserRole).toInt()); 3929 cloneItem->setText(2,item->text(2)); 3485 cloneItem->setText(2,item->text(2)); 3930 cloneItem->setData(0, Qt::UserRole,item->da 3486 cloneItem->setData(0, Qt::UserRole,item->data(0,Qt::UserRole).toInt()); 3931 cloneItem->setText(3,item->text(3)); 3487 cloneItem->setText(3,item->text(3)); 3932 cloneItem->setFlags(item->flags()); 3488 cloneItem->setFlags(item->flags()); 3933 cloneItem->setToolTip(0,item->toolTip(0)); << 3489 cloneItem->setToolTip(0,item->toolTip(0)); 3934 cloneItem->setCheckState(0,item->checkState 3490 cloneItem->setCheckState(0,item->checkState(0)); 3935 cloneItem->setSelected(item->isSelected()); << 3491 cloneItem->setSelected(item->isSelected()); 3936 cloneItem->setExpanded(item->isExpanded ()) 3492 cloneItem->setExpanded(item->isExpanded ()); 3937 3493 3938 cloneItem->setData(2,Qt::UserRole,item->dat 3494 cloneItem->setData(2,Qt::UserRole,item->data(2,Qt::UserRole).value<QColor>()); 3939 3495 3940 return cloneItem; 3496 return cloneItem; 3941 } 3497 } 3942 3498 3943 3499 3944 /** 3500 /** 3945 Clone the current tree in order to get a s 3501 Clone the current tree in order to get a snapshot of old version 3946 */ 3502 */ 3947 void G4OpenGLQtViewer::cloneSceneTree( 3503 void G4OpenGLQtViewer::cloneSceneTree( 3948 QTreeWidgetItem* rootItem 3504 QTreeWidgetItem* rootItem 3949 ) { 3505 ) { 3950 << 3506 3951 for (int b=0;b< rootItem->childCount();b++) 3507 for (int b=0;b< rootItem->childCount();b++) { 3952 3508 3953 QTreeWidgetItem *child = rootItem->child( 3509 QTreeWidgetItem *child = rootItem->child(b); 3954 3510 3955 // clone top level items 3511 // clone top level items 3956 int poIndex = child->data(0,Qt::UserRole) 3512 int poIndex = child->data(0,Qt::UserRole).toInt(); 3957 if (poIndex != -1) { 3513 if (poIndex != -1) { 3958 fOldPositivePoIndexSceneTreeWidgetQuick 3514 fOldPositivePoIndexSceneTreeWidgetQuickMap.insert(std::pair <int, QTreeWidgetItem*> (poIndex,cloneWidgetItem(child))); 3959 } else { 3515 } else { 3960 fOldNullPoIndexSceneTreeWidgetQuickVect 3516 fOldNullPoIndexSceneTreeWidgetQuickVector.push_back(cloneWidgetItem(child)); 3961 } 3517 } 3962 cloneSceneTree(child); 3518 cloneSceneTree(child); 3963 } 3519 } 3964 } 3520 } 3965 3521 3966 3522 3967 /** 3523 /** 3968 Update the quick scene tree visibility map 3524 Update the quick scene tree visibility map (used by parseAndCheckVisibility) 3969 */ 3525 */ 3970 void G4OpenGLQtViewer::updatePositivePoIndex 3526 void G4OpenGLQtViewer::updatePositivePoIndexSceneTreeWidgetQuickMap(int POindex,QTreeWidgetItem* item) { 3971 3527 3972 // Check state 3528 // Check state 3973 std::map <int, QTreeWidgetItem*>::iterator 3529 std::map <int, QTreeWidgetItem*>::iterator i; 3974 i = fPositivePoIndexSceneTreeWidgetQuickMa 3530 i = fPositivePoIndexSceneTreeWidgetQuickMap.find(POindex); 3975 3531 3976 if (i == fPositivePoIndexSceneTreeWidgetQu 3532 if (i == fPositivePoIndexSceneTreeWidgetQuickMap.end()) { 3977 fPositivePoIndexSceneTreeWidgetQuickMap. 3533 fPositivePoIndexSceneTreeWidgetQuickMap.insert(std::pair <int, QTreeWidgetItem*> (POindex,item) ); 3978 fLastSceneTreeWidgetAskForIterator = fPo 3534 fLastSceneTreeWidgetAskForIterator = fPositivePoIndexSceneTreeWidgetQuickMap.end(); 3979 fLastSceneTreeWidgetAskForIteratorEnd = 3535 fLastSceneTreeWidgetAskForIteratorEnd = fPositivePoIndexSceneTreeWidgetQuickMap.end(); 3980 } else { 3536 } else { 3981 i->second = item; 3537 i->second = item; 3982 } 3538 } 3983 } 3539 } 3984 3540 3985 3541 3986 3542 3987 void G4OpenGLQtViewer::changeQColorForTreeWid 3543 void G4OpenGLQtViewer::changeQColorForTreeWidgetItem(QTreeWidgetItem* item,const QColor& qc) { 3988 3544 3989 int POIndex = item->data(0,Qt::UserRole).to 3545 int POIndex = item->data(0,Qt::UserRole).toInt(); 3990 updatePositivePoIndexSceneTreeWidgetQuickMa 3546 updatePositivePoIndexSceneTreeWidgetQuickMap(POIndex,item ); 3991 3547 3992 QPixmap pixmap = QPixmap(QSize(16, 16)); 3548 QPixmap pixmap = QPixmap(QSize(16, 16)); 3993 if (item->data(0,Qt::UserRole).toInt() != - 3549 if (item->data(0,Qt::UserRole).toInt() != -1) { 3994 pixmap.fill (qc); 3550 pixmap.fill (qc); 3995 } else { 3551 } else { 3996 pixmap.fill (QColor(255,255,255,255)); 3552 pixmap.fill (QColor(255,255,255,255)); 3997 } 3553 } 3998 QPainter painter(&pixmap); 3554 QPainter painter(&pixmap); 3999 painter.setPen(Qt::black); 3555 painter.setPen(Qt::black); 4000 painter.drawRect(0,0,15,15); // Draw contou 3556 painter.drawRect(0,0,15,15); // Draw contour 4001 3557 4002 item->setIcon(0,pixmap); 3558 item->setIcon(0,pixmap); 4003 item->setData(2,Qt::UserRole,qc); 3559 item->setData(2,Qt::UserRole,qc); 4004 } 3560 } 4005 3561 4006 3562 4007 3563 4008 /** 3564 /** 4009 @return the corresponding item if existing 3565 @return the corresponding item if existing. 4010 Look into fPositivePoIndexSceneTreeWidgetQ 3566 Look into fPositivePoIndexSceneTreeWidgetQuickMap 4011 */ 3567 */ 4012 QTreeWidgetItem* G4OpenGLQtViewer::getTreeWid 3568 QTreeWidgetItem* G4OpenGLQtViewer::getTreeWidgetItem(int POindex){ 4013 3569 4014 // -1 is not a visible item 3570 // -1 is not a visible item 4015 if (POindex == -1) { 3571 if (POindex == -1) { 4016 return NULL; 3572 return NULL; 4017 } 3573 } 4018 3574 4019 if (fPositivePoIndexSceneTreeWidgetQuickMap 3575 if (fPositivePoIndexSceneTreeWidgetQuickMap.size() == 0){ 4020 return NULL; 3576 return NULL; 4021 } 3577 } 4022 3578 4023 if (fLastSceneTreeWidgetAskForIterator != f 3579 if (fLastSceneTreeWidgetAskForIterator != fLastSceneTreeWidgetAskForIteratorEnd) { 4024 if (POindex == fLastSceneTreeWidgetAskFor 3580 if (POindex == fLastSceneTreeWidgetAskForIterator->first) { 4025 if (fLastSceneTreeWidgetAskForIterator- 3581 if (fLastSceneTreeWidgetAskForIterator->second != NULL) { 4026 return fLastSceneTreeWidgetAskForIter 3582 return fLastSceneTreeWidgetAskForIterator->second; 4027 } 3583 } 4028 } 3584 } 4029 } 3585 } 4030 << 3586 4031 // if not, use the "find" algorithm 3587 // if not, use the "find" algorithm 4032 fLastSceneTreeWidgetAskForIterator = fPosit 3588 fLastSceneTreeWidgetAskForIterator = fPositivePoIndexSceneTreeWidgetQuickMap.find(POindex); 4033 fLastSceneTreeWidgetAskForIteratorEnd = fPo 3589 fLastSceneTreeWidgetAskForIteratorEnd = fPositivePoIndexSceneTreeWidgetQuickMap.end(); 4034 << 3590 4035 if (fLastSceneTreeWidgetAskForIterator != f 3591 if (fLastSceneTreeWidgetAskForIterator != fPositivePoIndexSceneTreeWidgetQuickMap.end()) { 4036 return fLastSceneTreeWidgetAskForIterator 3592 return fLastSceneTreeWidgetAskForIterator->second; 4037 } 3593 } 4038 return NULL; 3594 return NULL; 4039 } 3595 } 4040 3596 4041 /** 3597 /** 4042 @return the corresponding item if existing 3598 @return the corresponding item if existing in the old tree 4043 Look into fOldPositivePoIndexSceneTreeWidg 3599 Look into fOldPositivePoIndexSceneTreeWidgetQuickMap 4044 */ 3600 */ 4045 QTreeWidgetItem* G4OpenGLQtViewer::getOldTree 3601 QTreeWidgetItem* G4OpenGLQtViewer::getOldTreeWidgetItem(int POindex){ 4046 3602 4047 3603 4048 // -1 is not a visible item 3604 // -1 is not a visible item 4049 if (POindex == -1) { 3605 if (POindex == -1) { 4050 return NULL; 3606 return NULL; 4051 } 3607 } 4052 3608 4053 if (fOldPositivePoIndexSceneTreeWidgetQuick 3609 if (fOldPositivePoIndexSceneTreeWidgetQuickMap.size() == 0){ 4054 return NULL; 3610 return NULL; 4055 } 3611 } 4056 3612 4057 // Should be call only once by item additio 3613 // Should be call only once by item addition 4058 // Prevent to get out the std::map 3614 // Prevent to get out the std::map 4059 if (fOldLastSceneTreeWidgetAskForIterator ! 3615 if (fOldLastSceneTreeWidgetAskForIterator != fOldLastSceneTreeWidgetAskForIteratorEnd) { 4060 fOldLastSceneTreeWidgetAskForIterator++; 3616 fOldLastSceneTreeWidgetAskForIterator++; 4061 } 3617 } 4062 << 3618 4063 if (fOldLastSceneTreeWidgetAskForIterator ! 3619 if (fOldLastSceneTreeWidgetAskForIterator != fOldPositivePoIndexSceneTreeWidgetQuickMap.end()) { 4064 if (POindex == fOldLastSceneTreeWidgetAsk 3620 if (POindex == fOldLastSceneTreeWidgetAskForIterator->first) { 4065 if (fOldLastSceneTreeWidgetAskForIterat 3621 if (fOldLastSceneTreeWidgetAskForIterator->second != NULL) { 4066 return fOldLastSceneTreeWidgetAskForI 3622 return fOldLastSceneTreeWidgetAskForIterator->second; 4067 } 3623 } 4068 } 3624 } 4069 } 3625 } 4070 << 3626 4071 // if not, use the "find" algorithm 3627 // if not, use the "find" algorithm 4072 fOldLastSceneTreeWidgetAskForIterator = fOl 3628 fOldLastSceneTreeWidgetAskForIterator = fOldPositivePoIndexSceneTreeWidgetQuickMap.find(POindex); 4073 fOldLastSceneTreeWidgetAskForIteratorEnd = 3629 fOldLastSceneTreeWidgetAskForIteratorEnd = fOldPositivePoIndexSceneTreeWidgetQuickMap.end(); 4074 << 3630 4075 if (fOldLastSceneTreeWidgetAskForIterator ! 3631 if (fOldLastSceneTreeWidgetAskForIterator != fOldPositivePoIndexSceneTreeWidgetQuickMap.end()) { 4076 return fOldLastSceneTreeWidgetAskForItera 3632 return fOldLastSceneTreeWidgetAskForIterator->second; 4077 } 3633 } 4078 return NULL; 3634 return NULL; 4079 } 3635 } 4080 3636 4081 3637 4082 3638 4083 /** 3639 /** 4084 Should replace actual tree by the one in t 3640 Should replace actual tree by the one in this class 4085 and update tree 3641 and update tree 4086 */ 3642 */ 4087 void G4OpenGLQtViewer::displaySceneTreeCompon 3643 void G4OpenGLQtViewer::displaySceneTreeComponent() { 4088 // no UI 3644 // no UI 4089 if (fUISceneTreeWidget == NULL) { << 3645 if (fUISceneTreeComponentsTBWidget == NULL) { 4090 return; << 3646 return; 4091 } 3647 } 4092 if (fSceneTreeComponentTreeWidget == NULL) 3648 if (fSceneTreeComponentTreeWidget == NULL) { 4093 return; << 3649 return; 4094 } 3650 } 4095 3651 4096 // sort tree items 3652 // sort tree items 4097 fSceneTreeComponentTreeWidget->sortItems (0 3653 fSceneTreeComponentTreeWidget->sortItems (0, Qt::AscendingOrder ); 4098 3654 4099 return; 3655 return; 4100 } 3656 } 4101 3657 4102 3658 4103 /** 3659 /** 4104 Update the toolbar Icons/Mouse context men 3660 Update the toolbar Icons/Mouse context menu 4105 - Change ortho/perspective 3661 - Change ortho/perspective 4106 - Change surface style 3662 - Change surface style 4107 - Change cursor style 3663 - Change cursor style 4108 */ 3664 */ 4109 void G4OpenGLQtViewer::updateToolbarAndMouseC 3665 void G4OpenGLQtViewer::updateToolbarAndMouseContextMenu(){ 4110 if (fBatchMode) { 3666 if (fBatchMode) { 4111 return; 3667 return; 4112 } 3668 } 4113 3669 4114 G4ViewParameters::DrawingStyle 3670 G4ViewParameters::DrawingStyle 4115 d_style = fVP.GetDrawingStyle(); 3671 d_style = fVP.GetDrawingStyle(); 4116 << 3672 4117 // Surface style 3673 // Surface style 4118 if (d_style == G4ViewParameters::wireframe) 3674 if (d_style == G4ViewParameters::wireframe) { 4119 if (fUiQt) fUiQt->SetIconWireframeSelecte 3675 if (fUiQt) fUiQt->SetIconWireframeSelected(); 4120 if (fContextMenu) { 3676 if (fContextMenu) { 4121 fDrawingWireframe->setChecked(true); 3677 fDrawingWireframe->setChecked(true); 4122 fDrawingLineRemoval->setChecked(false); 3678 fDrawingLineRemoval->setChecked(false); 4123 fDrawingSurfaceRemoval->setChecked(fals 3679 fDrawingSurfaceRemoval->setChecked(false); 4124 fDrawingLineSurfaceRemoval->setChecked( 3680 fDrawingLineSurfaceRemoval->setChecked(false); 4125 } << 3681 } 4126 } else if (d_style == G4ViewParameters::hlr 3682 } else if (d_style == G4ViewParameters::hlr) { 4127 if (fUiQt) fUiQt->SetIconHLRSelected(); 3683 if (fUiQt) fUiQt->SetIconHLRSelected(); 4128 if (fContextMenu) { 3684 if (fContextMenu) { 4129 fDrawingLineRemoval->setChecked(true); 3685 fDrawingLineRemoval->setChecked(true); 4130 fDrawingWireframe->setChecked(false); 3686 fDrawingWireframe->setChecked(false); 4131 fDrawingSurfaceRemoval->setChecked(fals 3687 fDrawingSurfaceRemoval->setChecked(false); 4132 fDrawingLineSurfaceRemoval->setChecked( 3688 fDrawingLineSurfaceRemoval->setChecked(false); 4133 } << 3689 } 4134 } else if (d_style == G4ViewParameters::hsr 3690 } else if (d_style == G4ViewParameters::hsr) { 4135 if (fUiQt) fUiQt->SetIconSolidSelected(); 3691 if (fUiQt) fUiQt->SetIconSolidSelected(); 4136 if (fContextMenu) { 3692 if (fContextMenu) { 4137 fDrawingSurfaceRemoval->setChecked(true 3693 fDrawingSurfaceRemoval->setChecked(true); 4138 fDrawingWireframe->setChecked(false); 3694 fDrawingWireframe->setChecked(false); 4139 fDrawingLineRemoval->setChecked(false); 3695 fDrawingLineRemoval->setChecked(false); 4140 fDrawingLineSurfaceRemoval->setChecked( 3696 fDrawingLineSurfaceRemoval->setChecked(false); 4141 } 3697 } 4142 } else if (d_style == G4ViewParameters::hlh 3698 } else if (d_style == G4ViewParameters::hlhsr) { 4143 if (fUiQt) fUiQt->SetIconHLHSRSelected(); 3699 if (fUiQt) fUiQt->SetIconHLHSRSelected(); 4144 if (fContextMenu) { 3700 if (fContextMenu) { 4145 fDrawingLineSurfaceRemoval->setChecked( 3701 fDrawingLineSurfaceRemoval->setChecked(true); 4146 fDrawingWireframe->setChecked(false); 3702 fDrawingWireframe->setChecked(false); 4147 fDrawingLineRemoval->setChecked(false); 3703 fDrawingLineRemoval->setChecked(false); 4148 fDrawingSurfaceRemoval->setChecked(fals 3704 fDrawingSurfaceRemoval->setChecked(false); 4149 fDrawingLineSurfaceRemoval->setChecked( 3705 fDrawingLineSurfaceRemoval->setChecked(false); 4150 } 3706 } 4151 } 3707 } 4152 << 3708 4153 << 3709 4154 // projection style 3710 // projection style 4155 G4double d_proj = fVP.GetFieldHalfAngle () 3711 G4double d_proj = fVP.GetFieldHalfAngle () ; 4156 if (d_proj == 0.) { // ortho 3712 if (d_proj == 0.) { // ortho 4157 if (fUiQt) fUiQt->SetIconOrthoSelected(); 3713 if (fUiQt) fUiQt->SetIconOrthoSelected(); 4158 if (fContextMenu) { 3714 if (fContextMenu) { 4159 fProjectionOrtho->setChecked(true); 3715 fProjectionOrtho->setChecked(true); 4160 fProjectionPerspective->setChecked(fals 3716 fProjectionPerspective->setChecked(false); 4161 } << 3717 } 4162 } else { 3718 } else { 4163 if (fUiQt) fUiQt->SetIconPerspectiveSelec 3719 if (fUiQt) fUiQt->SetIconPerspectiveSelected(); 4164 if (fContextMenu) { 3720 if (fContextMenu) { 4165 fProjectionPerspective->setChecked(tr 3721 fProjectionPerspective->setChecked(true); 4166 fProjectionOrtho->setChecked(false); 3722 fProjectionOrtho->setChecked(false); 4167 } 3723 } 4168 } 3724 } 4169 << 3725 4170 << 3726 4171 // mouse style : They are controlled by UI 3727 // mouse style : They are controlled by UI ! 4172 if (fUiQt && fContextMenu) { 3728 if (fUiQt && fContextMenu) { 4173 if (fUiQt->IsIconPickSelected()) { 3729 if (fUiQt->IsIconPickSelected()) { 4174 fMousePickAction->setChecked(true); 3730 fMousePickAction->setChecked(true); 4175 fMouseZoomOutAction->setChecked(false); 3731 fMouseZoomOutAction->setChecked(false); 4176 fMouseZoomInAction->setChecked(false); 3732 fMouseZoomInAction->setChecked(false); 4177 fMouseRotateAction->setChecked(false); 3733 fMouseRotateAction->setChecked(false); 4178 fMouseMoveAction->setChecked(false); 3734 fMouseMoveAction->setChecked(false); 4179 } else if (fUiQt->IsIconZoomOutSelected() 3735 } else if (fUiQt->IsIconZoomOutSelected()) { 4180 fMouseZoomOutAction->setChecked(true); 3736 fMouseZoomOutAction->setChecked(true); 4181 fMousePickAction->setChecked(false); 3737 fMousePickAction->setChecked(false); 4182 fMouseZoomInAction->setChecked(false); 3738 fMouseZoomInAction->setChecked(false); 4183 fMouseRotateAction->setChecked(false); 3739 fMouseRotateAction->setChecked(false); 4184 fMouseMoveAction->setChecked(false); 3740 fMouseMoveAction->setChecked(false); 4185 } else if (fUiQt->IsIconZoomInSelected()) 3741 } else if (fUiQt->IsIconZoomInSelected()) { 4186 fMouseZoomInAction->setChecked(true); 3742 fMouseZoomInAction->setChecked(true); 4187 fMousePickAction->setChecked(false); 3743 fMousePickAction->setChecked(false); 4188 fMouseZoomOutAction->setChecked(false); 3744 fMouseZoomOutAction->setChecked(false); 4189 fMouseRotateAction->setChecked(false); 3745 fMouseRotateAction->setChecked(false); 4190 fMouseMoveAction->setChecked(false); 3746 fMouseMoveAction->setChecked(false); 4191 } else if (fUiQt->IsIconRotateSelected()) 3747 } else if (fUiQt->IsIconRotateSelected()) { 4192 fMouseRotateAction->setChecked(true); 3748 fMouseRotateAction->setChecked(true); 4193 fMousePickAction->setChecked(false); 3749 fMousePickAction->setChecked(false); 4194 fMouseZoomOutAction->setChecked(false); 3750 fMouseZoomOutAction->setChecked(false); 4195 fMouseZoomInAction->setChecked(false); 3751 fMouseZoomInAction->setChecked(false); 4196 fMouseMoveAction->setChecked(false); 3752 fMouseMoveAction->setChecked(false); 4197 } else if (fUiQt->IsIconMoveSelected()) { 3753 } else if (fUiQt->IsIconMoveSelected()) { 4198 fMouseMoveAction->setChecked(true); 3754 fMouseMoveAction->setChecked(true); 4199 fMousePickAction->setChecked(false); 3755 fMousePickAction->setChecked(false); 4200 fMouseZoomOutAction->setChecked(false); 3756 fMouseZoomOutAction->setChecked(false); 4201 fMouseZoomInAction->setChecked(false); 3757 fMouseZoomInAction->setChecked(false); 4202 fMouseRotateAction->setChecked(false); 3758 fMouseRotateAction->setChecked(false); 4203 } 3759 } 4204 } 3760 } 4205 } 3761 } 4206 3762 4207 3763 4208 /** << 4209 Update the scene tree widget << 4210 */ << 4211 void G4OpenGLQtViewer::updateSceneTreeWidget( << 4212 // Ensure case where closing a UI tab close << 4213 if (!fSceneTreeWidget) { << 4214 createSceneTreeWidget(); << 4215 } << 4216 } << 4217 << 4218 << 4219 /** << 4220 Update the viewer properties component widge << 4221 Clear it only if the number of command is le << 4222 */ << 4223 void G4OpenGLQtViewer::updateViewerProperties << 4224 << 4225 if (!isCurrentWidget()) { << 4226 return; << 4227 } << 4228 << 4229 // Ensure case where closing a UI tab close << 4230 if (!fViewerPropertiesTableWidget) { << 4231 createViewerPropertiesWidget(); << 4232 } << 4233 int treeWidgetInfosIgnoredCommands = 0; << 4234 G4UImanager* UI = G4UImanager::GetUIpointer << 4235 G4UIcommandTree * commandTreeTop = UI->GetT << 4236 G4UIcommandTree* path = commandTreeTop->Fin << 4237 << 4238 if (!path) { << 4239 return; << 4240 } << 4241 << 4242 // clear old table << 4243 if ((path->GetCommandEntry()-fTreeWidgetInf << 4244 fViewerPropertiesTableWidget->clear(); << 4245 } << 4246 << 4247 fViewerPropertiesTableWidget->blockSignals( << 4248 // TODO : Could be optimized by comparing c << 4249 << 4250 fViewerPropertiesTableWidget->setColumnCoun << 4251 fViewerPropertiesTableWidget->setRowCount ( << 4252 fViewerPropertiesTableWidget->setHorizontal << 4253 << 4254 fViewerPropertiesTableWidget->verticalHeade << 4255 fViewerPropertiesTableWidget->setAlternatin << 4256 << 4257 // For the moment, we do only command that << 4258 << 4259 for (int a=0;a<path->GetCommandEntry();a++) << 4260 G4UIcommand* commandTmp = path->GetComman << 4261 << 4262 // get current parameters << 4263 QString params = ""; << 4264 << 4265 if(commandTmp->GetCommandName() == "autoR << 4266 if (fVP.IsAutoRefresh()) { << 4267 params = "True"; << 4268 } else { << 4269 params = "False"; << 4270 } << 4271 } else if(commandTmp->GetCommandName() == << 4272 if (fVP.IsAuxEdgeVisible()) { << 4273 params = "True"; << 4274 } else { << 4275 params = "False"; << 4276 } << 4277 } else if(commandTmp->GetCommandName() == << 4278 params = QString().number(fVP.GetBackgr << 4279 QString().number(fVP.GetBackgroundColou << 4280 QString().number(fVP.GetBackgroundColou << 4281 QString().number(fVP.GetBackgroundColou << 4282 << 4283 } else if(commandTmp->GetCommandName() == << 4284 params = QString().number(fVP. IsCullin << 4285 } else if(commandTmp->GetCommandName() == << 4286 if (fVP.GetCutawayMode() == G4ViewParam << 4287 params = "union"; << 4288 } else { << 4289 params = "intersection"; << 4290 } << 4291 << 4292 } else if(commandTmp->GetCommandName() == << 4293 params = QString().number(fVP.GetDefaul << 4294 QString().number(fVP.GetDefaultVisAttri << 4295 QString().number(fVP.GetDefaultVisAttri << 4296 QString().number(fVP.GetDefaultVisAttri << 4297 << 4298 } else if(commandTmp->GetCommandName() == << 4299 params = QString().number(fVP.GetDefaul << 4300 QString().number(fVP.GetDefaultTextVisA << 4301 QString().number(fVP.GetDefaultTextVisA << 4302 QString().number(fVP.GetDefaultTextVisA << 4303 << 4304 } else if(commandTmp->GetCommandName() == << 4305 G4ViewParameters::DrawingStyle existing << 4306 params = "False"; << 4307 if (existingStyle == G4ViewParameters:: << 4308 params = "True"; << 4309 } << 4310 << 4311 } else if(commandTmp->GetCommandName() == << 4312 params = QString().number(fVP.GetExplod << 4313 << 4314 } else if(commandTmp->GetCommandName() == << 4315 params = QString().number(fVP.GetGlobal << 4316 << 4317 } else if(commandTmp->GetCommandName() == << 4318 params = QString().number(fVP.GetGlobal << 4319 << 4320 } else if(commandTmp->GetCommandName() == << 4321 G4ViewParameters::DrawingStyle style = << 4322 if ((style == G4ViewParameters::hlr) || << 4323 (style == G4ViewParameters::hlhsr)) << 4324 params = "True"; << 4325 } else { << 4326 params = "False"; << 4327 } << 4328 << 4329 } else if(commandTmp->GetCommandName() == << 4330 if (fVP.IsMarkerNotHidden()) { << 4331 params = "False"; << 4332 } else { << 4333 params = "True"; << 4334 } << 4335 << 4336 } else if(commandTmp->GetCommandName() == << 4337 if (fVP.GetLightsMoveWithCamera()) { << 4338 params = "camera"; << 4339 } else { << 4340 params = "object"; << 4341 } << 4342 } else if(commandTmp->GetCommandName() == << 4343 G4Vector3D direction = fVP.GetLightpoin << 4344 // degree << 4345 params = QString().number(direction.the << 4346 if (commandTmp->GetParameterEntries() = << 4347 if (commandTmp->GetParameter(2)->GetD << 4348 params = QString().number(direction << 4349 } << 4350 } << 4351 } else if(commandTmp->GetCommandName() == << 4352 params = QString().number(fVP.GetLightpo << 4353 QString().number(fVP.GetLightpointDirec << 4354 QString().number(fVP.GetLightpointDirec << 4355 << 4356 } else if(commandTmp->GetCommandName() == << 4357 params = QString().number(fVP.GetNoOfSi << 4358 << 4359 } else if(commandTmp->GetCommandName() == << 4360 if (fVP.IsPicking()) { << 4361 params = "True"; << 4362 } else { << 4363 params = "False"; << 4364 } << 4365 << 4366 } else if(commandTmp->GetCommandName() == << 4367 if (fVP.GetFieldHalfAngle() == 0.) { << 4368 params = "orthogonal"; << 4369 } else { << 4370 params = QString("perspective ") + QS << 4371 } << 4372 << 4373 } else if(commandTmp->GetCommandName() == << 4374 if (fVP.GetRotationStyle() == G4ViewPar << 4375 params = "constrainUpDirection"; << 4376 } else { << 4377 params = "freeRotation"; << 4378 } << 4379 << 4380 } else if(commandTmp->GetCommandName() == << 4381 if (fVP.IsSection()) { << 4382 params = QString("on ") + << 4383 G4String(G4BestUnit(fVP.GetSectionPla << 4384 QString().number(fVP.GetSectionPlane( << 4385 + " " + QString().number(fVP.GetSecti << 4386 + " " + QString().number(fVP.GetSecti << 4387 } else { << 4388 params = "off"; << 4389 } << 4390 << 4391 } else if(commandTmp->GetCommandName() == << 4392 if (fVP.GetDrawingStyle() == G4ViewPara << 4393 params = "wireframe"; << 4394 } else { << 4395 params = "surface"; << 4396 } << 4397 << 4398 << 4399 } else if(commandTmp->GetCommandName() == << 4400 G4Point3D point = fVP.GetCurrentTargetP << 4401 if (fSceneHandler.GetScene()) { << 4402 G4String b = G4BestUnit(fSceneHandler << 4403 params = b.data(); << 4404 } << 4405 } else if(commandTmp->GetCommandName() == << 4406 G4Vector3D up = fVP.GetUpVector(); << 4407 // degree << 4408 params = QString().number(up.theta()/CL << 4409 if (commandTmp->GetParameterEntries() = << 4410 if (commandTmp->GetParameter(2)->GetD << 4411 params = QString().number(up.theta( << 4412 } << 4413 } << 4414 } else if(commandTmp->GetCommandName() == << 4415 G4Vector3D up = fVP.GetUpVector(); << 4416 params = QString().number(up.x())+ " " << 4417 << 4418 } else if(commandTmp->GetCommandName() == << 4419 G4Vector3D direction = fVP.GetViewpoint << 4420 // degree << 4421 params = QString().number(direction.the << 4422 if (commandTmp->GetParameterEntries() = << 4423 if (commandTmp->GetParameter(2)->GetD << 4424 params = QString().number(direction << 4425 } << 4426 } << 4427 } else if(commandTmp->GetCommandName() == << 4428 G4Vector3D direction = fVP.GetViewpoint << 4429 params = QString().number(direction.x() << 4430 } else { << 4431 // No help << 4432 } << 4433 << 4434 /* DO NOT DISPLAY COMMANDS WITHOUT ANY PA << 4435 if (params == "") { << 4436 // TODO : display default parameters // << 4437 << 4438 for( G4int i_thParameter=0; i_thParamet << 4439 commandParam = commandTmp->GetParamet << 4440 << 4441 if (QString(QChar(commandParam->GetPa << 4442 if (commandParam->GetDefaultValue() << 4443 params += "True"; << 4444 } else { << 4445 params += "False"; << 4446 } << 4447 } else { << 4448 params += QString((char*)(commandPa << 4449 } << 4450 if (i_thParameter<commandTmp->GetPara << 4451 params += " "; << 4452 } << 4453 } << 4454 } << 4455 */ << 4456 << 4457 if (params != "") { << 4458 << 4459 QTableWidgetItem *nameItem; << 4460 QTableWidgetItem *paramItem; << 4461 << 4462 // already present ? << 4463 QList<QTableWidgetItem *> list = fViewe << 4464 if (list.size() == 1) { << 4465 nameItem = list.first(); << 4466 paramItem = fViewerPropertiesTableWid << 4467 << 4468 } else { << 4469 nameItem = new QTableWidgetItem(); << 4470 paramItem = new QTableWidgetItem(); << 4471 fViewerPropertiesTableWidget->setItem << 4472 fViewerPropertiesTableWidget->setItem << 4473 << 4474 // Set Guidance << 4475 QString guidance; << 4476 G4int n_guidanceEntry = (G4int)comman << 4477 for( G4int i_thGuidance=0; i_thGuidan << 4478 guidance += QString((char*)(command << 4479 } << 4480 << 4481 nameItem->setToolTip(guidance); << 4482 paramItem->setToolTip(GetCommandParam << 4483 << 4484 fViewerPropertiesTableWidget->setRowH << 4485 } << 4486 << 4487 // set current name and parameters << 4488 nameItem->setText(commandTmp->GetComman << 4489 paramItem->setText(params); << 4490 << 4491 nameItem->setFlags(Qt::NoItemFlags); << 4492 nameItem->setForeground(QBrush()); << 4493 << 4494 } else { << 4495 treeWidgetInfosIgnoredCommands++; << 4496 } << 4497 } << 4498 // remove empty content row << 4499 for (int i=0; i<treeWidgetInfosIgnoredComma << 4500 fViewerPropertiesTableWidget->removeRow ( << 4501 } << 4502 << 4503 // The resize should done only at creation << 4504 if (!fViewerPropertiesTableWidgetIsInit) { << 4505 fViewerPropertiesTableWidgetIsInit = true << 4506 << 4507 fViewerPropertiesTableWidget->resizeColum << 4508 << 4509 int x = fViewerPropertiesTableWidget->hor << 4510 int y = fViewerPropertiesTableWidget->ver << 4511 << 4512 // fViewerPropertiesTableWidget->vertica << 4513 // fViewerPropertiesTableWidget->horizon << 4514 << 4515 // resize to fit content << 4516 QDialog* dial = static_cast<QDialog*> (fU << 4517 if (dial) { << 4518 dial->resize(x+56,y+46); // more or les << 4519 } << 4520 } << 4521 fViewerPropertiesTableWidget->blockSignals( << 4522 << 4523 fTreeWidgetInfosIgnoredCommands = treeWidge << 4524 } << 4525 << 4526 << 4527 /** << 4528 Update the pick infos component widget << 4529 */ << 4530 void G4OpenGLQtViewer::updatePickInfosWidget( << 4531 fLastPickPoint = QPoint(aX,aY); << 4532 << 4533 if (!isCurrentWidget()) { << 4534 return; << 4535 } << 4536 // Ensure case where closing a UI tab close << 4537 if (!fPickInfosWidget) { << 4538 createPickInfosWidget(); << 4539 } << 4540 << 4541 #if QT_VERSION < 0x060000 << 4542 #else << 4543 {auto* qGLW = dynamic_cast<G4QGLWidgetType*> << 4544 if (qGLW) qGLW->makeCurrent();} << 4545 ResizeGLView(); << 4546 #endif << 4547 const std::vector < G4OpenGLViewerPickMap* << 4548 << 4549 // remove all previous widgets << 4550 if (fPickInfosWidget) { << 4551 QLayoutItem * wItem; << 4552 if (fPickInfosWidget->layout()->count()) << 4553 while ((wItem = fPickInfosWidget->layou << 4554 delete wItem->widget(); << 4555 delete wItem; << 4556 } << 4557 } << 4558 } else { << 4559 // Ensure case where closing a UI tab clo << 4560 if (!fPickInfosWidget) { << 4561 createPickInfosWidget(); << 4562 } << 4563 } << 4564 << 4565 // parse all pick results << 4566 G4int nPickedObjectsWithAttributes = 0; << 4567 for (unsigned int a=0; a< pickMapVector.siz << 4568 const auto& pickMap = pickMapVector[a]; << 4569 // Add a box inside the pick viewer box << 4570 std::ostringstream label; << 4571 std::ostringstream content; << 4572 std::string txt = pickMap->getAttributes( << 4573 if (pickMapVector[a]->getAttributes().siz << 4574 ++nPickedObjectsWithAttributes; << 4575 << 4576 std::size_t pos1 = txt.find(':'); << 4577 std::string storeKey = txt.substr(0,pos << 4578 << 4579 if (storeKey == "G4PhysicalVolumeModel" << 4580 << 4581 label << "Volume:"; << 4582 std::size_t pos2 = txt.find(':',pos1+ << 4583 std::size_t pos3 = txt.find('\n',pos2 << 4584 label << txt.substr(pos2+1,pos3-pos2- << 4585 << 4586 } else if (storeKey == "G4TrajectoriesM << 4587 << 4588 label << "Trajectory:"; << 4589 std::size_t pos2 = txt.find(':',pos1+ << 4590 std::size_t pos3 = txt.find('\n',pos2 << 4591 label << " Run:" << txt.substr(pos2+1 << 4592 std::size_t pos4 = txt.find(':',pos3+ << 4593 std::size_t pos5 = txt.find('\n',pos4 << 4594 label << ", Event:" << txt.substr(pos << 4595 << 4596 } else { << 4597 << 4598 label << "Hit number:" << a << ", Pic << 4599 << 4600 } << 4601 << 4602 // Accumulate all content with the same << 4603 content << pickMap->print().data(); << 4604 G4int thisPickName = pickMap->getPickNa << 4605 while (++a < pickMapVector.size()) { << 4606 const auto& a_pickMap = pickMapVector << 4607 if (a_pickMap->getPickName() == thisP << 4608 content << a_pickMap->print().data( << 4609 } else { << 4610 a--; << 4611 break; << 4612 } << 4613 } << 4614 << 4615 QPushButton* pickCoutButton = new QPush << 4616 pickCoutButton->setStyleSheet ("text-al << 4617 pickCoutButton->setIcon(*fTreeIconClose << 4618 fPickInfosWidget->layout()->addWidget(p << 4619 << 4620 QStringList newStr; << 4621 << 4622 // Add to stringList << 4623 newStr = QStringList(QString(content.st << 4624 << 4625 QTextEdit* ed = new QTextEdit(); << 4626 ed->setReadOnly(true); << 4627 fPickInfosWidget->layout()->addWidget(e << 4628 ed->setVisible((false)); << 4629 ed->append(newStr.join("")); << 4630 << 4631 std::cout << pickCoutButton->text().toS << 4632 int tmp = fPickInfosWidget->layout()->c << 4633 connect(pickCoutButton, &QPushButton::c << 4634 } << 4635 } << 4636 << 4637 // add a label to push everything up! << 4638 QLabel * pushUp = new QLabel(""); << 4639 QSizePolicy vPolicy = QSizePolicy(QSizePoli << 4640 vPolicy.setVerticalStretch(10); << 4641 pushUp->setSizePolicy(vPolicy); << 4642 fPickInfosWidget->layout()->addWidget(pushU << 4643 << 4644 // highlight the first one : << 4645 << 4646 // first un-highlight the last selected << 4647 changeColorAndTransparency(fLastHighlightNa << 4648 << 4649 if (pickMapVector.size() > 0 ) { << 4650 // get the new one << 4651 fLastHighlightName = pickMapVector[0]->ge << 4652 fLastHighlightColor = getColorForPoIndex( << 4653 // set the new one << 4654 changeColorAndTransparency(fLastHighlight << 4655 << 4656 updateQWidget(); << 4657 } << 4658 QDialog* dial = static_cast<QDialog*> (fUIP << 4659 if (dial) { << 4660 // change name << 4661 std::ostringstream oss; << 4662 if (nPickedObjectsWithAttributes == 0) { << 4663 oss << "No object"; << 4664 } else if (nPickedObjectsWithAttributes = << 4665 oss << "1 object"; << 4666 } else { << 4667 oss << nPickedObjectsWithAttributes << << 4668 } << 4669 oss << " selected - " << GetName(); << 4670 dial->setWindowTitle(oss.str().c_str()); << 4671 } << 4672 // set picking cout visible << 4673 fPickInfosScrollArea->setVisible(true); << 4674 } << 4675 << 4676 << 4677 void G4OpenGLQtViewer::toggleSceneTreeCompone << 4678 << 4679 QWidget* w; << 4680 // close other items, it could take too muc << 4681 << 4682 for (int a=0; a<fPickInfosWidget->layout()- << 4683 w = fPickInfosWidget->layout()->itemAt(a) << 4684 QTextEdit* ed = dynamic_cast<QTextEdit*>( << 4685 QPushButton* button; << 4686 if (ed) { << 4687 if (a == pickItem) { << 4688 w->setVisible(!w->isVisible()); << 4689 } else { << 4690 w->setVisible(false); << 4691 } << 4692 if (a >= 1) { << 4693 button = dynamic_cast<QPushButton*>(f << 4694 if (button) { << 4695 if (button->isVisible()) { << 4696 button->setIcon(*fTreeIconOpen); << 4697 } else { << 4698 button->setIcon(*fTreeIconClosed) << 4699 } << 4700 } << 4701 } << 4702 } << 4703 } << 4704 } << 4705 << 4706 << 4707 void G4OpenGLQtViewer::currentTabActivated(in << 4708 if (fUiQt->GetViewerTabWidget()->tabText(cu << 4709 createViewerPropertiesWidget(); << 4710 // createPickInfosWidget(); // Causes a / << 4711 // createSceneTreeWidget(); // ...this ol << 4712 } << 4713 } << 4714 << 4715 << 4716 void G4OpenGLQtViewer::tableWidgetViewerSetIt << 4717 G4UImanager* UI = G4UImanager::GetUIpointer << 4718 if(UI != NULL) { << 4719 QTableWidgetItem* previous = fViewerPrope << 4720 if (previous) { << 4721 fViewerPropertiesTableWidget->blockSign << 4722 UI->ApplyCommand((std::string("/vis/vie << 4723 + previous->text().to << 4724 + " " << 4725 + item->text().toStdS << 4726 fViewerPropertiesTableWidget->blockSign << 4727 } << 4728 } << 4729 } << 4730 << 4731 bool G4OpenGLQtViewer::isCurrentWidget(){ << 4732 G4Qt* interactorManager = G4Qt::getInstance << 4733 if (!interactorManager->IsExternalApp()) { << 4734 << 4735 // Prevent from repainting a hidden tab ( << 4736 if ( GetName() != fUiQt->GetViewerTabWidg << 4737 return false; << 4738 } << 4739 } << 4740 return true; << 4741 } << 4742 << 4743 /** Build the parameter list parameters in << 4744 Reimplement partialy the G4UIparameter.cc << 4745 @param aCommand : command to list parameters << 4746 @see G4UIparameter::List() << 4747 @see G4UIcommand::List() << 4748 @return the command list parameters, or "" i << 4749 */ << 4750 QString G4OpenGLQtViewer::GetCommandParameter << 4751 const G4UIc << 4752 ) << 4753 { << 4754 G4int n_parameterEntry = (G4int)aCommand->G << 4755 QString txt; << 4756 << 4757 if( n_parameterEntry > 0 ) { << 4758 G4UIparameter *param; << 4759 << 4760 // Re-implementation of G4UIparameter.cc << 4761 << 4762 for( G4int i_thParameter=0; i_thParameter << 4763 param = aCommand->GetParameter(i_thPara << 4764 txt += "\nParameter : " + QString((char << 4765 if( ! param->GetParameterGuidance().emp << 4766 txt += QString((char*)(param->GetPara << 4767 txt += " Parameter type : " + QString( << 4768 if(param->IsOmittable()){ << 4769 txt += " Omittable : True\n"; << 4770 } else { << 4771 txt += " Omittable : False\n"; << 4772 } << 4773 if( param->GetCurrentAsDefault() ) { << 4774 txt += " Default value : taken from << 4775 } else if( ! param->GetDefaultValue().e << 4776 txt += " Default value : " + QStrin << 4777 } << 4778 if( ! param->GetParameterRange().empty( << 4779 txt += " Parameter range : " + QStrin << 4780 } << 4781 if( ! param->GetParameterCandidates().e << 4782 txt += " Candidates : " + QStrin << 4783 } << 4784 } << 4785 } << 4786 return txt; << 4787 } << 4788 << 4789 #ifdef G4MULTITHREADED << 4790 << 4791 namespace { << 4792 G4Mutex visSubThreadMutex = G4MUTEX_INITIAL << 4793 G4Condition waitForVisSubThreadInitialized << 4794 G4bool visSubThreadEstablished = false; << 4795 G4bool qObjectsSwitched = false; << 4796 G4QGLWidgetType* qGLWidget = nullptr; << 4797 } << 4798 << 4799 void G4OpenGLQtViewer::DoneWithMasterThread() << 4800 { << 4801 // Called by Main Thread ! << 4802 << 4803 // Initialise and check qGLWidget - no need << 4804 qGLWidget = dynamic_cast<G4QGLWidgetType*>( << 4805 if (qGLWidget == nullptr) return; << 4806 << 4807 // Done with master thread << 4808 qGLWidget->doneCurrent(); << 4809 << 4810 // Set current QThread for the way back << 4811 fQGLContextMainThread = QThread::currentThr << 4812 } << 4813 << 4814 void G4OpenGLQtViewer::MovingToVisSubThread() << 4815 { << 4816 // Still on master thread but vis thread ha << 4817 << 4818 if (qGLWidget == nullptr) return; << 4819 << 4820 // Wait until SwitchToVisSubThread has foun << 4821 { << 4822 G4AutoLock lock(&visSubThreadMutex); << 4823 G4CONDITIONWAITLAMBDA(&waitForVisSubThreadI << 4824 } << 4825 << 4826 // Move stuff to sub-thread << 4827 if(qGLWidget->context()) qGLWidget->context << 4828 << 4829 // Inform sub-thread << 4830 G4AutoLock lock(&visSubThreadMutex); << 4831 qObjectsSwitched = true; << 4832 lock.unlock(); << 4833 G4CONDITIONBROADCAST(&waitForVisSubThreadIn << 4834 } << 4835 << 4836 void G4OpenGLQtViewer::SwitchToVisSubThread() << 4837 { << 4838 // Called by VisSub Thread ! << 4839 << 4840 if (qGLWidget == nullptr) return; << 4841 << 4842 // Set the current QThread to its static va << 4843 fQGLContextVisSubThread = QThread::currentT << 4844 << 4845 // Let MovingToVisSubThread know we have th << 4846 { << 4847 G4AutoLock lock(&visSubThreadMutex); << 4848 visSubThreadEstablished = true; << 4849 G4CONDITIONBROADCAST(&waitForVisSubThreadIn << 4850 } << 4851 << 4852 // Wait until MovingToVisSubThread has move << 4853 { << 4854 G4AutoLock lock(&visSubThreadMutex); << 4855 G4CONDITIONWAITLAMBDA(&waitForVisSubThreadI << 4856 } << 4857 << 4858 // make context current << 4859 qGLWidget->makeCurrent(); << 4860 } << 4861 << 4862 void G4OpenGLQtViewer::DoneWithVisSubThread() << 4863 { << 4864 // Called by vis sub thread << 4865 << 4866 if (qGLWidget == nullptr) return; << 4867 << 4868 // finish with this vis sub thread context << 4869 qGLWidget->doneCurrent(); << 4870 << 4871 // and move stuff back to the main thread << 4872 if(qGLWidget->context()) qGLWidget->context << 4873 } << 4874 << 4875 void G4OpenGLQtViewer::SwitchToMasterThread() << 4876 { << 4877 // Called by master Thread ! << 4878 << 4879 if (qGLWidget == nullptr) return; << 4880 << 4881 qGLWidget->makeCurrent(); << 4882 << 4883 visSubThreadEstablished = false; << 4884 qObjectsSwitched = false; << 4885 } << 4886 << 4887 #endif << 4888 << 4889 << 4890 /* 3764 /* 4891 << 3765 4892 void MultiLayer::exportToSVG(const QString& f 3766 void MultiLayer::exportToSVG(const QString& fname) 4893 { 3767 { 4894 QPicture picture; 3768 QPicture picture; 4895 QPainter p(&picture); 3769 QPainter p(&picture); 4896 for (int i=0;i<(int)graphsList->count();i++) 3770 for (int i=0;i<(int)graphsList->count();i++) 4897 { 3771 { 4898 Graph *gr=(Graph *)graphsList->at(i); 3772 Graph *gr=(Graph *)graphsList->at(i); 4899 Plot *myPlot= (Plot *)gr->plotWidget(); 3773 Plot *myPlot= (Plot *)gr->plotWidget(); 4900 << 3774 4901 QPoint pos=gr->pos(); 3775 QPoint pos=gr->pos(); 4902 << 3776 4903 int width=int(myPlot->frameGeometry().width() 3777 int width=int(myPlot->frameGeometry().width()); 4904 int height=int(myPlot->frameGeometry().height 3778 int height=int(myPlot->frameGeometry().height()); 4905 << 3779 4906 myPlot->print(&p, QRect(pos,QSize(width,heigh 3780 myPlot->print(&p, QRect(pos,QSize(width,height))); 4907 } 3781 } 4908 << 3782 4909 p.end(); 3783 p.end(); 4910 picture.save(fname, "svg"); 3784 picture.save(fname, "svg"); 4911 } 3785 } 4912 */ 3786 */ >> 3787 #endif 4913 3788