36 #ifdef G4VIS_BUILD_OPENGLQT_DRIVER    64 #include <qpushbutton.h>    66 #include <qdesktopwidget.h>    69 #include <qimagewriter.h>    71 #include <qtextedit.h>    72 #include <qtreewidget.h>    73 #include <qapplication.h>    74 #include <qmessagebox.h>    75 #include <qfiledialog.h>    77 #include <qdatetime.h>    81 #include <qcolordialog.h>    84 #include <qgroupbox.h>    85 #include <qcombobox.h>    86 #include <qlineedit.h>    87 #include <qsignalmapper.h>    88 #include <qmainwindow.h>    89 #include <qtablewidget.h>    90 #include <qheaderview.h>    91 #include <qscrollarea.h>    92 #include <qsplitter.h>    93 #include <qcheckbox.h>    97 #ifdef G4MULTITHREADED   103 #ifdef G4MULTITHREADED   112 void G4OpenGLQtViewer::CreateMainWindow (
   120   if(fGLWidget) 
return; 
   122   fGLWidget = glWidget ;
   125   G4Qt* interactorManager = G4Qt::getInstance ();
   127   ResizeWindow(fVP.GetWindowSizeHintX(),fVP.GetWindowSizeHintY());
   139   if (UI == NULL) 
return;
   141   if (! static_cast<G4UIQt*> (UI->GetG4UIWindow())) {
   146   fUiQt = 
static_cast<G4UIQt*
> (UI->GetG4UIWindow());
   148   bool isTabbedView = 
false;
   151       if (!interactorManager->IsExternalApp()) {
   153         fWinSize_x = fVP.GetWindowSizeHintX();
   154         fWinSize_y = fVP.GetWindowSizeHintY();
   156         isTabbedView = fUiQt->AddTabWidget((QWidget*)fGLWidget,name);
   158       fUISceneTreeComponentsTBWidget = fUiQt->GetSceneTreeComponentsTBWidget();
   161       fUiQt->GetViewersWidget()->setCurrentWidget(fUISceneTreeComponentsTBWidget);
   164       fSceneTreeWidget = 
new QWidget();
   165       QVBoxLayout* layoutSceneTree = 
new QVBoxLayout();
   166       fSceneTreeWidget->setStyleSheet (
"padding: 0px ");
   168       fSceneTreeWidget->setLayout(layoutSceneTree);
   169       fSceneTreeWidget->layout()->setContentsMargins(5,5,5,5);
   171       if (fUISceneTreeComponentsTBWidget != NULL) {
   172         fUISceneTreeComponentsTBWidget->addTab(fSceneTreeWidget,QString(GetName().data()));
   176       if (dynamic_cast<G4OpenGLStoredQtViewer*> (
this)) {
   177         createSceneTreeComponent();
   180       createViewerPropertiesComponent();
   181       createPickingComponent();
   189     QWidget *glDialogWidget = getParentWidget();
   190     if (glDialogWidget != NULL) {
   191       glWidget->setParent(glDialogWidget);
   193     QHBoxLayout *mainLayout = 
new QHBoxLayout();
   195     mainLayout->setMargin(0);
   196     mainLayout->setSpacing(0);   
   197     mainLayout->addWidget(fGLWidget);
   198     if (fGLWidget->inherits(
"QMainWindow")) {
   199       fGLWidget->setWindowTitle( name);
   201     glDialogWidget->setLayout(mainLayout);
   205     int offset = QApplication::desktop()->height() 
   206       - QApplication::desktop()->availableGeometry().height();
   208     G4int YPos= fVP.GetWindowAbsoluteLocationHintY(QApplication::desktop()->height());
   209     if (fVP.GetWindowAbsoluteLocationHintY(QApplication::desktop()->height())< offset) {
   212     glDialogWidget->resize(getWinWidth(), getWinHeight());
   213     glDialogWidget->move(fVP.GetWindowAbsoluteLocationHintX(QApplication::desktop()->width()),YPos);
   214     glDialogWidget->show();
   217   if(!fGLWidget) 
return;
   226 G4OpenGLQtViewer::G4OpenGLQtViewer (
   227  G4OpenGLSceneHandler& scene
   230   ,G4OpenGLViewer (scene)
   232   ,fRecordFrameNumber(0)
   236   ,fHoldKeyEvent(false)
   237   ,fHoldMoveEvent(false)
   238   ,fHoldRotateEvent(false)
   242   ,fMovieTempFolderPath(
"")
   244   ,fParameterFileName(
"ppmtompeg_encode_parameter_file.par")
   245   ,fMovieParametersDialog(NULL)
   246   ,fRecordingStep(WAIT)
   248   ,fNbMaxFramesPerSec(100)
   249   ,fNbMaxAnglePerSec(360)
   250   ,fLaunchSpinDelay(100)
   251   ,fUISceneTreeComponentsTBWidget(NULL)
   254   ,fControlKeyPress(false)
   255   ,fShiftKeyPress(false)
   257   ,fCheckSceneTreeComponentSignalLock(false)
   258   ,fSceneTreeComponentTreeWidget(NULL)
   259   ,fOldSceneTreeComponentTreeWidget(NULL)
   260   ,fSceneTreeWidget(NULL)
   261   ,fPVRootNodeCreate(false)
   263   ,fViewerPropertiesButton(NULL)
   266   ,fTouchableVolumes(
"Touchables")
   267   ,fShortcutsDialog(NULL)
   268   ,fSceneTreeComponentTreeWidgetInfos(NULL)
   269   ,fSceneTreeComponentPickingInfos(NULL)
   270   ,fSceneTreeComponentPickingScrollArea(NULL)
   271   ,fTreeWidgetInfosIgnoredCommands(0)
   272   ,fSceneTreeDepthSlider(NULL)
   274   ,fModelShortNameItem(NULL)
   275   ,fMaxPOindexInserted(-1)
   277   ,fSignalMapperMouse(NULL)
   278   ,fSignalMapperSurface(NULL)
   279   ,fSignalMapperPicking(NULL)
   281   ,fTreeIconClosed(NULL)
   282   ,fLastExportSliderValue(80)
   283   ,fLastHighlightColor(
G4Color(0,0,0,0))
   284   ,fLastHighlightName(0)
   292   G4Qt::getInstance ();
   294   fLastPos3 = QPoint(-1,-1);    
   295   fLastPos2 = QPoint(-1,-1);    
   296   fLastPos1 = QPoint(-1,-1);    
   298   initMovieParameters();
   300   fLastEventTime = 
new QTime();
   301   fSignalMapperMouse = 
new QSignalMapper(
this);
   302   fSignalMapperSurface = 
new QSignalMapper(
this);
   305   fFileSavePath = QDir::currentPath();
   308   QList<QByteArray> formats =  QImageWriter::supportedImageFormats ();
   309   for (
int i = 0; i < formats.size(); ++i) {
   310     addExportImageFormat(formats.at(i).data());
   313   const char * 
const icon1[]={
   371   const char * 
const icon2[]={
   464   const char * 
const search[]  = {
   476     "OOOOOOOOOOOOOOOOOOO",
   477     "OOOOOOOOOOOOOOOOOOO",
   478     "OOOOOOOo.  .oOOOOOO",
   481     "OOOOO. XOOOOX .OOOO",
   484     "OOOOO. XOOOOo .OOOO",
   488     "OOOOOOOOOOOOO.  XOO",
   489     "OOOOOOOOOOOOOO. XOO",
   490     "OOOOOOOOOOOOOOOoOOO",
   491     "OOOOOOOOOOOOOOOOOOO",
   492     "OOOOOOOOOOOOOOOOOOO",
   493     "OOOOOOOOOOOOOOOOOOO",
   494     "OOOOOOOOOOOOOOOOOOO"   497   fSearchIcon = 
new QPixmap(search);
   498   fTreeIconOpen = 
new QPixmap(icon1);
   499   fTreeIconClosed = 
new QPixmap(icon2);
   504 G4OpenGLQtViewer::~G4OpenGLQtViewer (
   514   if (fSceneTreeWidget != NULL) {
   515     if (fSceneTreeWidget->layout() != NULL) {
   516       while ((wItem = fSceneTreeWidget->layout()->takeAt(0)) != 0) {
   517     delete wItem->widget();
   521     if (fUISceneTreeComponentsTBWidget != NULL) {
   522       fUISceneTreeComponentsTBWidget->removeTab(fUISceneTreeComponentsTBWidget->indexOf(fSceneTreeWidget));
   527   delete fTreeIconOpen;
   528   delete fTreeIconClosed;
   530   G4cout <<removeTempFolder().toStdString().c_str() <<
G4endl;
   537 void G4OpenGLQtViewer::createPopupMenu()    {
   539   fContextMenu = 
new QMenu(
"All");
   541   QMenu *mMouseAction = fContextMenu->addMenu(
"&Mouse actions");
   543   fMouseRotateAction = mMouseAction->addAction(
"Rotate", fSignalMapperMouse, SLOT(map()));
   544   fMouseMoveAction = mMouseAction->addAction(
"Move", fSignalMapperMouse, SLOT(map()));
   545   fMousePickAction = mMouseAction->addAction(
"Pick", fSignalMapperMouse, SLOT(map()));
   546   fMouseZoomOutAction = mMouseAction->addAction(
"Zoom out", fSignalMapperMouse, SLOT(map()));
   547   fMouseZoomInAction = mMouseAction->addAction(
"Zoom in", fSignalMapperMouse, SLOT(map()));
   548   QAction *shortcutsAction = mMouseAction->addAction(
"Show shortcuts");
   550   fMouseRotateAction->setCheckable(
true);
   551   fMouseMoveAction->setCheckable(
true);
   552   fMousePickAction->setCheckable(
true);
   553   fMouseZoomOutAction->setCheckable(
true);
   554   fMouseZoomInAction->setCheckable(
true);
   555   shortcutsAction->setCheckable(
false);
   557   connect(fSignalMapperMouse, SIGNAL(mapped(
int)),
this, SLOT(toggleMouseAction(
int)));
   558   fSignalMapperMouse->setMapping(fMouseRotateAction,1);
   559   fSignalMapperMouse->setMapping(fMouseMoveAction,2);
   560   fSignalMapperMouse->setMapping(fMousePickAction,3);
   561   fSignalMapperMouse->setMapping(fMouseZoomOutAction,4);
   562   fSignalMapperMouse->setMapping(fMouseZoomInAction,5);
   564   QObject::connect(shortcutsAction, 
   565                     SIGNAL(triggered(
bool)),
   567                     SLOT(showShortcuts()));
   570   QMenu *mStyle = fContextMenu->addMenu(
"&Style");
   572   QMenu *mProjection = mStyle->addMenu(
"&Projection");
   574   fProjectionOrtho = mProjection->addAction(
"Orthographic", fSignalMapperSurface, SLOT(map()));
   575   fProjectionPerspective = mProjection->addAction(
"Persepective", fSignalMapperSurface, SLOT(map()));
   578   if (fVP.GetFieldHalfAngle() == 0) {
   579     createRadioAction(fProjectionOrtho, fProjectionPerspective,SLOT(toggleProjection(
bool)),1);
   581     createRadioAction(fProjectionOrtho, fProjectionPerspective,SLOT(toggleProjection(
bool)),2);
   585   QMenu *mDrawing = mStyle->addMenu(
"&Drawing");
   587   fDrawingWireframe = mDrawing->addAction(
"Wireframe", fSignalMapperSurface, SLOT(map()));
   589   fDrawingLineRemoval = mDrawing->addAction(
"Hidden line removal", fSignalMapperSurface, SLOT(map()));
   591   fDrawingSurfaceRemoval = mDrawing->addAction(
"Hidden Surface removal", fSignalMapperSurface, SLOT(map()));
   593   fDrawingLineSurfaceRemoval = mDrawing->addAction(
"Hidden line and surface removal", fSignalMapperSurface, SLOT(map()));
   595   fDrawingWireframe->setCheckable(
true);
   596   fDrawingLineRemoval->setCheckable(
true);
   597   fDrawingSurfaceRemoval->setCheckable(
true);
   598   fDrawingLineSurfaceRemoval->setCheckable(
true);
   600   connect(fSignalMapperSurface, SIGNAL(mapped(
int)),
this, SLOT(toggleSurfaceAction(
int)));
   601   fSignalMapperSurface->setMapping(fDrawingWireframe,1);
   602   fSignalMapperSurface->setMapping(fDrawingLineRemoval,2);
   603   fSignalMapperSurface->setMapping(fDrawingSurfaceRemoval,3);
   604   fSignalMapperSurface->setMapping(fDrawingLineSurfaceRemoval,4);
   609   QAction *backgroundColorChooser ;
   611   backgroundColorChooser = mStyle->addAction(
"Background color");
   612   QObject ::connect(backgroundColorChooser, 
   615                     SLOT(actionChangeBackgroundColor()));
   619   QAction *textColorChooser ;
   621   textColorChooser = mStyle->addAction(
"Text color");
   622   QObject ::connect(textColorChooser, 
   625                     SLOT(actionChangeTextColor()));
   629   QAction *defaultColorChooser ;
   631   defaultColorChooser = mStyle->addAction(
"Default color");
   632   QObject ::connect(defaultColorChooser, 
   635                     SLOT(actionChangeDefaultColor()));
   639   QMenu *mActions = fContextMenu->addMenu(
"&Actions");
   640   QAction *createEPS = mActions->addAction(
"Save as ...");
   641   QObject ::connect(createEPS, 
   644                     SLOT(actionSaveImage()));
   647   QAction *movieParameters = mActions->addAction(
"Save as movie...");
   648   QObject ::connect(movieParameters, 
   651                     SLOT(actionMovieParameters()));
   657   QMenu *mSpecial = fContextMenu->addMenu(
"S&pecial");
   658   QMenu *mTransparency = mSpecial->addMenu(
"Transparency");
   659   QAction *transparencyOn = mTransparency->addAction(
"On");
   660   QAction *transparencyOff = mTransparency->addAction(
"Off");
   662   if (transparency_enabled == 
false) {
   663     createRadioAction(transparencyOn,transparencyOff,SLOT(toggleTransparency(
bool)),2);
   664   } 
else if (transparency_enabled == 
true) {
   665     createRadioAction(transparencyOn,transparencyOff,SLOT(toggleTransparency(
bool)),1);
   671   QMenu *mAntialiasing = mSpecial->addMenu(
"Antialiasing");
   672   QAction *antialiasingOn = mAntialiasing->addAction(
"On");
   673   QAction *antialiasingOff = mAntialiasing->addAction(
"Off");
   675   if (antialiasing_enabled == 
false) {
   676     createRadioAction(antialiasingOn,antialiasingOff,SLOT(toggleAntialiasing(
bool)),2);
   677   } 
else if (antialiasing_enabled == 
true) {
   678     createRadioAction(antialiasingOn,antialiasingOff,SLOT(toggleAntialiasing(
bool)),1);
   680     mAntialiasing->clear();
   683   QMenu *mHaloing = mSpecial->addMenu(
"Haloing");
   684   QAction *haloingOn = mHaloing->addAction(
"On");
   685   QAction *haloingOff = mHaloing->addAction(
"Off");
   686   if (haloing_enabled == 
false) {
   687     createRadioAction(haloingOn,haloingOff,SLOT(toggleHaloing(
bool)),2);
   688   } 
else if (haloing_enabled == 
true) {
   689     createRadioAction(haloingOn,haloingOff,SLOT(toggleHaloing(
bool)),1);
   694   QMenu *mAux = mSpecial->addMenu(
"Auxiliary edges");
   695   QAction *auxOn = mAux->addAction(
"On");
   696   QAction *auxOff = mAux->addAction(
"Off");
   697   if (!fVP.IsAuxEdgeVisible()) {
   698     createRadioAction(auxOn,auxOff,SLOT(toggleAux(
bool)),2);
   700     createRadioAction(auxOn,auxOff,SLOT(toggleAux(
bool)),1);
   704   QMenu *mHiddenMarkers = mSpecial->addMenu(
"Hidden markers");
   705   QAction *hiddenMarkersOn = mHiddenMarkers->addAction(
"On");
   706   QAction *hiddenMarkersOff = mHiddenMarkers->addAction(
"Off");
   707   if (fVP.IsMarkerNotHidden()) {
   708     createRadioAction(hiddenMarkersOn,hiddenMarkersOff,SLOT(toggleHiddenMarkers(
bool)),2);
   710     createRadioAction(hiddenMarkersOn,hiddenMarkersOff,SLOT(toggleHiddenMarkers(
bool)),1);
   715   QMenu *mFullScreen = mSpecial->addMenu(
"&Full screen");
   716   fFullScreenOn = mFullScreen->addAction(
"On");
   717   fFullScreenOff = mFullScreen->addAction(
"Off");
   718   createRadioAction(fFullScreenOn,fFullScreenOff,SLOT(toggleFullScreen(
bool)),2);
   721   updateToolbarAndMouseContextMenu();
   724 void G4OpenGLQtViewer::G4manageContextMenuEvent(QContextMenuEvent *
e)
   727     G4cerr << 
"Visualization window not defined, please choose one before" << 
G4endl;
   734     if ( fContextMenu ) {
   735       fContextMenu->exec( e->globalPos() );
   751 void G4OpenGLQtViewer::createRadioAction(QAction *action1,QAction *action2, 
const std::string& method,
unsigned int nCheck) {
   753   action1->setCheckable(
true);
   754   action2->setCheckable(
true);
   757     action1->setChecked (
true);
   759     action2->setChecked (
true);
   761   QObject ::connect(action1, SIGNAL(triggered(
bool)),action2, SLOT(toggle()));
   762   QObject ::connect(action2, SIGNAL(triggered(
bool)),action1, SLOT(toggle()));
   764   QObject ::connect(action1, SIGNAL(toggled(
bool)),
this, method.c_str());
   773 void G4OpenGLQtViewer::showShortcuts() {
   776   text = 
"========= Mouse Shortcuts =========\n";
   778     if (fUiQt->IsIconRotateSelected()) {  
   779       text += 
"Click and move mouse to rotate volume \n";
   780       text += 
"ALT + Click and move mouse to rotate volume (Toggle View/Theta-Phi Direction) \n";
   781       text += 
"CTRL + Click and move mouse to zoom in/out \n";
   782       text += 
"SHIFT + Click and move mouse to change camera point of view \n";
   783     } 
else  if (fUiQt->IsIconMoveSelected()) { 
   784       text += 
"Move camera point of view with mouse \n";
   785     } 
else  if (fUiQt->IsIconPickSelected()) { 
   786       text += 
"Click and pick \n";
   789     text += 
"Click and move mouse to rotate volume \n";
   790     text += 
"ALT + Click and move mouse to rotate volume (Toggle View/Theta-Phi Direction) \n";
   791     text += 
"CTRL + Click and zoom mouse to zoom in/out \n";
   792     text += 
"SHIFT + Click and zoommove camera point of view \n";
   794   text += 
"========= Move Shortcuts ========= \n";
   795   text += 
"Press left/right arrows to move volume left/right \n";
   796   text += 
"Press up/down arrows to move volume up/down \n";
   797   text += 
"Press '+'/'-' to move volume toward/forward \n";
   799   text += 
"========= Rotation (Theta/Phi) Shortcuts ========= \n";
   800   text += 
"Press SHIFT + left/right arrows to rotate volume left/right \n";
   801   text += 
"Press SHIFT + up/down arrows to rotate volume up/down \n";
   803   text += 
"========= Rotation (View Direction) Shortcuts ========= \n";
   804   text += 
"Press ALT + left/right to rotate volume around vertical direction \n";
   805   text += 
"Press ALT + up/down to rotate volume around horizontal direction \n";
   807   text += 
"========= Zoom View ========= \n";
   808   text += 
"Press CTRL + '+'/'-' to zoom into volume \n";
   810   text += 
"========= Misc ========= \n";
   811   text += 
"Press ALT +/- to slow/speed rotation/move \n";
   812   text += 
"Press H to reset view \n";
   813   text += 
"Press Esc to exit FullScreen \n";
   815   text += 
"========= Video ========= \n";
   816   text += 
"In video mode : \n";
   817   text += 
" Press SPACE to Start/Pause video recording \n";
   818   text += 
" Press RETURN to Stop video recording \n";
   823   if (  fShortcutsDialog == NULL) {
   824     fShortcutsDialog = 
new QDialog();
   825     fShortcutsDialogInfos = 
new QTextEdit() ;
   826     QVBoxLayout *mainLayout = 
new QVBoxLayout;
   827     mainLayout->addWidget(fShortcutsDialogInfos);
   828     fShortcutsDialog->setLayout(mainLayout);
   829     fShortcutsDialog->setWindowTitle(tr(
"Shortcuts"));
   832   fShortcutsDialogInfos->setPlainText(text.data());
   833   fShortcutsDialog->show();      
   844 void G4OpenGLQtViewer::toggleMouseAction(
int aAction) {
   847     fUiQt->SetIconRotateSelected();
   848   } 
else  if (aAction == 2) {
   849     fUiQt->SetIconMoveSelected();
   850   } 
else  if (aAction == 3) {
   852   } 
else  if (aAction == 4) {
   853     fUiQt->SetIconZoomOutSelected();
   854   } 
else  if (aAction == 5) {
   855     fUiQt->SetIconZoomInSelected();
   859   updateToolbarAndMouseContextMenu();
   873 void G4OpenGLQtViewer::toggleSurfaceAction(
int aAction) {
   880   } 
else  if (aAction ==2) {
   883   } 
else  if (aAction ==3) {
   886   } 
else  if (aAction ==4) {
   889   fVP.SetDrawingStyle(d_style);
   891   updateToolbarAndMouseContextMenu();
   906 void G4OpenGLQtViewer::toggleProjection(
bool check) {
   909     fVP.SetOrthogonalProjection ();
   911     fVP.SetPerspectiveProjection();
   913   updateToolbarAndMouseContextMenu();
   922 void G4OpenGLQtViewer::toggleTransparency(
bool check) {
   925     transparency_enabled = 
true;
   927     transparency_enabled = 
false;
   929   SetNeedKernelVisit (
true);
   930   updateToolbarAndMouseContextMenu();
   938 void G4OpenGLQtViewer::toggleAntialiasing(
bool check) {
   941     antialiasing_enabled = 
false;
   942     glDisable (GL_LINE_SMOOTH);
   943     glDisable (GL_POLYGON_SMOOTH);
   945     antialiasing_enabled = 
true;
   946     glEnable (GL_LINE_SMOOTH);
   947     glHint (GL_LINE_SMOOTH_HINT, GL_NICEST);
   948     glEnable (GL_POLYGON_SMOOTH);
   949     glHint (GL_POLYGON_SMOOTH_HINT, GL_NICEST);
   952   updateToolbarAndMouseContextMenu();
   961 void G4OpenGLQtViewer::toggleHaloing(
bool check) {
   963     haloing_enabled = 
false;
   965     haloing_enabled = 
true;
   968   updateToolbarAndMouseContextMenu();
   977 void G4OpenGLQtViewer::toggleAux(
bool check) {
   979     fVP.SetAuxEdgeVisible(
true);
   981     fVP.SetAuxEdgeVisible(
false);
   983   SetNeedKernelVisit (
true);
   984   updateToolbarAndMouseContextMenu();
   989 void G4OpenGLQtViewer::togglePicking() {
   992     if (!fVP.IsPicking()) {
   993       fUiQt->SetIconPickSelected();
   995       fUiQt->SetIconRotateSelected();
  1001     if (!fVP.IsPicking()) {
  1002       UI->
ApplyCommand(std::string(
"/vis/viewer/set/picking true"));
  1004       UI->
ApplyCommand(std::string(
"/vis/viewer/set/picking false"));
  1015 void G4OpenGLQtViewer::toggleHiddenMarkers(
bool check) {
  1017     fVP.SetMarkerHidden();
  1019     fVP.SetMarkerNotHidden();
  1022   updateToolbarAndMouseContextMenu();
  1029 void G4OpenGLQtViewer::toggleFullScreen(
bool check) {
  1030   if (check != fGLWidget->isFullScreen()) { 
  1031     fGLWidget->setWindowState(fGLWidget->windowState() ^ Qt::WindowFullScreen);
  1036 void G4OpenGLQtViewer::savePPMToTemp() {
  1037   if (fMovieTempFolderPath == 
"") {
  1040   QGLWidget* qGLW = 
dynamic_cast<QGLWidget*
> (fGLWidget) ;
  1044   QString fileName =
"Test"+QString::number(fRecordFrameNumber)+
".ppm";
  1045   QString filePath =fMovieTempFolderPath+fileName;
  1048   image = qGLW->grabFrameBuffer();
  1051   res = image.save(filePath,0);
  1054     setRecordingInfos(
"Can't save tmp file "+filePath);
  1058   setRecordingInfos(
"File "+fileName+
" saved");
  1059   fRecordFrameNumber++;
  1064 void G4OpenGLQtViewer::actionSaveImage() {
  1066   for (
unsigned int i = 0; i < fExportImageFormatVector.size(); ++i) {
  1067     filters += QString(
"*.") + fExportImageFormatVector.at(i).c_str() + 
";;";
  1070   QString* selectedFormat = 
new QString(fDefaultExportImageFormat.c_str());
  1072   qFilename =  QFileDialog::getSaveFileName ( fGLWidget,
  1079   std::string name = qFilename.toStdString().c_str();
  1086   fFileSavePath = QFileInfo(qFilename).path();
  1088   std::string format = selectedFormat->toLower().toStdString().c_str();
  1091   fExportImageFormat = format.substr(format.find_last_of(
".") + 1);
  1093   std::string filename = 
name;
  1094   std::string extension = 
"";
  1095   if (name.find_last_of(
".") != std::string::npos) {
  1096     filename = name.substr(0,name.find_last_of(
".") + 1);
  1097     extension = name.substr(name.find_last_of(
".") + 1);
  1099     extension = fExportImageFormat;
  1102   filename+= 
"."+ extension;
  1104   if (!setExportFilename(filename.c_str(),0)) {
  1108   G4OpenGLQtExportDialog* exportDialog= 
new G4OpenGLQtExportDialog(fGLWidget,format.c_str(),fGLWidget->height(),fGLWidget->width());
  1109   if(  exportDialog->exec()) {
  1111     if ((exportDialog->getWidth() !=fGLWidget->width()) ||
  1112         (exportDialog->getHeight() !=fGLWidget->height())) {
  1113       setExportSize(exportDialog->getWidth(),exportDialog->getHeight());
  1116     if (fExportImageFormat == 
"eps") {
  1117       fVectoredPs = exportDialog->getVectorEPS();
  1118     } 
else if (fExportImageFormat == 
"ps") {
  1121     fLastExportSliderValue = exportDialog->getSliderValue();
  1123     if (exportImage(filename)) {
  1125       fDefaultExportImageFormat = format;
  1134 void G4OpenGLQtViewer::actionChangeBackgroundColor() {
  1142 #if QT_VERSION < 0x040500  1144   const QColor color = QColor(QColorDialog::getRgba (QColor(Qt::black).rgba(),&a,fGLWidget));
  1146   const QColor color =
  1147     QColorDialog::getColor(Qt::black,
  1149                            " Get background color and transparency",
  1150                            QColorDialog::ShowAlphaChannel);
  1152   if (color.isValid()) {
  1157     fVP.SetBackgroundColour(colour);
  1159     updateToolbarAndMouseContextMenu();
  1164 void G4OpenGLQtViewer::actionChangeTextColor() {
  1166 #if QT_VERSION < 0x040500  1168   const QColor color = QColor(QColorDialog::getRgba (QColor(
Qt::yellow).rgba(),&a,fGLWidget));
  1170   const QColor& color =
  1173                            " Get text color and transparency",
  1174                            QColorDialog::ShowAlphaChannel);
  1176   if (color.isValid()) {
  1182     fVP.SetDefaultTextColour(colour);
  1184     updateToolbarAndMouseContextMenu();
  1189 void G4OpenGLQtViewer::actionChangeDefaultColor() {
  1191 #if QT_VERSION < 0x040500  1193   const QColor color = QColor(QColorDialog::getRgba (QColor(Qt::white).rgba(),&a,fGLWidget));
  1195   const QColor& color =
  1196     QColorDialog::getColor(Qt::white,
  1198                            " Get default color and transparency",
  1199                            QColorDialog::ShowAlphaChannel);
  1201   if (color.isValid()) {
  1207     fVP.SetDefaultColour(colour);
  1209     updateToolbarAndMouseContextMenu();
  1215 void G4OpenGLQtViewer::actionMovieParameters() {
  1216   showMovieParametersDialog();
  1220 void G4OpenGLQtViewer::showMovieParametersDialog() {
  1221   if (!fMovieParametersDialog) {
  1222     fMovieParametersDialog= 
new G4OpenGLQtMovieDialog(
this,fGLWidget);
  1223     displayRecordingStatus();
  1224     fMovieParametersDialog->checkEncoderSwParameters();
  1225     fMovieParametersDialog->checkSaveFileNameParameters();
  1226     fMovieParametersDialog->checkTempFolderParameters();
  1227     if (getEncoderPath() == 
"") {
  1228       setRecordingInfos(
"ppmtompeg is needed to encode in video format. It is available here: http://netpbm.sourceforge.net ");
  1231   fMovieParametersDialog->show();
  1236 void G4OpenGLQtViewer::FinishView()
  1252 void G4OpenGLQtViewer::G4MousePressEvent(QMouseEvent *evnt)
  1254   if (evnt->button() == Qt::RightButton) {
  1257   if ((evnt->button() & Qt::LeftButton) && (! (evnt->modifiers() & Qt::ControlModifier ))){
  1258     fGLWidget->setMouseTracking(
true);
  1260     fLastPos1 = evnt->pos();
  1261     fLastPos2 = fLastPos1;
  1262     fLastPos3 = fLastPos2;
  1263     fLastEventTime->start();
  1264     if (fUiQt != NULL) {
  1266       if (fUiQt->IsIconZoomInSelected()) {  
  1269         float deltaX = ((float)getWinWidth()/2-evnt->pos().x());
  1270         float deltaY = ((float)getWinHeight()/2-evnt->pos().y());
  1274         if (getWinHeight() <getWinWidth()) {
  1277         fVP.IncrementPan(-deltaX*coefTrans,deltaY*coefTrans,0);
  1278         fVP.SetZoomFactor(1.5 * fVP.GetZoomFactor());
  1282       } 
else if (fUiQt->IsIconZoomOutSelected()) {  
  1284         moveScene(((
float)getWinWidth()/2-evnt->pos().x()),((
float)getWinHeight()/2-evnt->pos().y()),0,
true);
  1286         fVP.SetZoomFactor(0.75 * fVP.GetZoomFactor());
  1289       } 
else if (fUiQt->IsIconRotateSelected() ) {
  1291         if (fShiftKeyPress) { 
  1292           fGLWidget->setCursor(QCursor(Qt::SizeAllCursor));
  1295           fGLWidget->setCursor(QCursor(Qt::ClosedHandCursor));
  1297       } 
else if (fUiQt->IsIconMoveSelected()) {
  1298         fGLWidget->setCursor(QCursor(Qt::SizeAllCursor));
  1299       } 
else if (fUiQt->IsIconPickSelected()) {
  1300         fGLWidget->setCursor(QCursor(Qt::PointingHandCursor));
  1308 void G4OpenGLQtViewer::G4MouseReleaseEvent(QMouseEvent *evnt)
  1310   fSpinningDelay = fLastEventTime->elapsed();
  1311   QPoint delta = (fLastPos3-fLastPos1);
  1314   fGLWidget->setCursor(QCursor(Qt::ArrowCursor));
  1316   if (fVP.IsPicking()){  
  1317     if ((delta.x() != 0) || (delta.y() != 0)) {
  1320     std::vector < G4OpenGLViewerPickMap* >  pickMap = GetPickDetails(evnt->pos().x(),evnt->pos().y());
  1323     QLayoutItem * wItem;
  1324     while ((wItem = fSceneTreeComponentPickingInfos->layout()->takeAt(0)) != 0) {
  1325       delete wItem->widget();
  1330     delete fSignalMapperPicking;
  1331     fSignalMapperPicking = 
new QSignalMapper(
this);
  1334     for (
unsigned int a=0; a< pickMap.size(); a++) {
  1336       std::ostringstream label;
  1337       label << 
"Hit number:" << a << 
", PickName: " << pickMap[
a]->getPickName();
  1339       QPushButton* pickCoutButton = 
new QPushButton(label.str().c_str());
  1340       pickCoutButton->setStyleSheet (
"text-align: left; padding: 1px; border: 0px;");
  1341       pickCoutButton->setIcon(*fTreeIconClosed);
  1342       fSceneTreeComponentPickingInfos->layout()->addWidget(pickCoutButton);
  1347       newStr = QStringList(QString(pickMap[a]->
print().data()).trimmed());
  1349       QTextEdit* ed = 
new QTextEdit();
  1350       ed->setFontFamily(
"Courier");
  1351       ed->setFontPointSize(12);
  1352       ed->setReadOnly(
true);
  1353       fSceneTreeComponentPickingInfos->layout()->addWidget(ed);
  1354       ed->setVisible((
false));
  1355       ed->append(newStr.join(
""));
  1357       connect(pickCoutButton, SIGNAL(clicked()), fSignalMapperPicking, SLOT(map()));
  1358       fSignalMapperPicking->setMapping(pickCoutButton,fSceneTreeComponentPickingInfos->layout()->count()-1);
  1361     connect(fSignalMapperPicking, SIGNAL(mapped(
int)),
this, SLOT(toggleSceneTreeComponentPickingCout(
int)));
  1364     QLabel * pushUp = 
new QLabel(
"");
  1365     QSizePolicy vPolicy = QSizePolicy(QSizePolicy::Minimum,QSizePolicy::Minimum);
  1366     vPolicy.setVerticalStretch(10);
  1367     pushUp->setSizePolicy(vPolicy);
  1368     fSceneTreeComponentPickingInfos->layout()->addWidget(pushUp);
  1373     changeColorAndTransparency(fLastHighlightName,fLastHighlightColor);
  1375     if (pickMap.size() > 0 ) {
  1377       fLastHighlightName = pickMap[0]->getPickName();
  1378       fLastHighlightColor = getColorForPoIndex(fLastHighlightName);
  1380       changeColorAndTransparency(fLastHighlightName,
G4Color(1,1,1,1));
  1384     fSceneTreeComponentPickingScrollArea->setVisible(
true);
  1386   } 
else if (fSpinningDelay < fLaunchSpinDelay ) {
  1387     if ((delta.x() == 0) && (delta.y() == 0)) {
  1393     lastMoveTime.start();
  1395     float correctionFactor = 5;
  1397       if ( lastMoveTime.elapsed() >= (int)(1000/fNbMaxFramesPerSec)) {
  1398         float lTime = 1000/lastMoveTime.elapsed();
  1399         if (((((
float)delta.x())/correctionFactor)*lTime > fNbMaxAnglePerSec) ||
  1400             ((((
float)delta.x())/correctionFactor)*lTime < -fNbMaxAnglePerSec) ) {
  1401           correctionFactor = (float)delta.x()*(lTime/fNbMaxAnglePerSec);
  1402           if (delta.x() <0 ) {
  1403             correctionFactor = -correctionFactor;
  1406         if (((((
float)delta.y())/correctionFactor)*lTime > fNbMaxAnglePerSec) ||
  1407             ((((
float)delta.y())/correctionFactor)*lTime < -fNbMaxAnglePerSec) ) {
  1408           correctionFactor = (float)delta.y()*(lTime/fNbMaxAnglePerSec);
  1409           if (delta.y() <0 ) {
  1410             correctionFactor = -correctionFactor;
  1421         lastMoveTime.start();
  1423         bool rotate = 
false;
  1426         if (fUiQt != NULL) {
  1427           if (fUiQt->IsIconRotateSelected()) {  
  1429           } 
else if (fUiQt->IsIconMoveSelected()) {  
  1442             rotateQtScene(((
float)delta.x())/correctionFactor,((
float)delta.y())/correctionFactor);
  1443           } 
else if (fAltKeyPress) {
  1444             rotateQtSceneToggle(((
float)delta.x())/correctionFactor,((
float)delta.y())/correctionFactor);
  1448           moveScene(-((
float)delta.x())/correctionFactor,-((
float)delta.y())/correctionFactor,0,
true);
  1451       ((QApplication*)G4Qt::getInstance ())->processEvents();
  1454   fGLWidget->setMouseTracking(
false);
  1459 void G4OpenGLQtViewer::G4MouseDoubleClickEvent()
  1461   fGLWidget->setMouseTracking(
true);
  1472 void G4OpenGLQtViewer::G4MouseMoveEvent(QMouseEvent *evnt)
  1475   Qt::MouseButtons mButtons = evnt->buttons();
  1477   updateKeyModifierState(evnt->modifiers());
  1483   fLastPos3 = fLastPos2;
  1484   fLastPos2 = fLastPos1;
  1485   fLastPos1 = QPoint(evnt->x(), evnt->y());
  1487   int deltaX = fLastPos2.x()-fLastPos1.x();
  1488   int deltaY = fLastPos2.y()-fLastPos1.y();
  1491   if (fUiQt != NULL) {
  1492     if (fUiQt->IsIconMoveSelected()) {  
  1497     if (mButtons & Qt::LeftButton) {
  1499         rotateQtScene(((
float)deltaX),((
float)deltaY));
  1500       } 
else if (fAltKeyPress) {
  1501         rotateQtSceneToggle(((
float)deltaX),((
float)deltaY));
  1502       } 
else if (fShiftKeyPress) {
  1503         unsigned int sizeWin;
  1504         sizeWin = getWinWidth();
  1505         if (getWinHeight() < getWinWidth()) {
  1506           sizeWin = getWinHeight();
  1510         float factor = ((float)100/(
float)sizeWin) ;
  1511         moveScene(-(
float)deltaX*factor,-(
float)deltaY*factor,0,
false);
  1512       } 
else if (fControlKeyPress) {
  1513         fVP.SetZoomFactor(fVP.GetZoomFactor()*(1+((float)deltaY))); 
  1517     if (mButtons & Qt::LeftButton) {
  1518       moveScene(-(
float)deltaX,-(
float)deltaY,0,
true);
  1522   fLastEventTime->start();
  1533 void G4OpenGLQtViewer::moveScene(
float dx,
float dy, 
float dz,
bool mouseMove)
  1537   fHoldMoveEvent = 
true;
  1540   GLdouble coefDepth = 0;
  1543     if (getWinHeight() <getWinWidth()) {
  1547     coefTrans = getSceneNearWidth()*fPan_sens;
  1548     coefDepth = getSceneDepth()*fDeltaDepth;
  1550   fVP.IncrementPan(-dx*coefTrans,dy*coefTrans,dz*coefDepth);
  1554     ((QApplication*)G4Qt::getInstance ())->processEvents();
  1556   fHoldMoveEvent = 
false;
  1565 void G4OpenGLQtViewer::rotateQtScene(
float dx, 
float dy)
  1567   if (fHoldRotateEvent)
  1569   fHoldRotateEvent = 
true;
  1575   fHoldRotateEvent = 
false;
  1583 void G4OpenGLQtViewer::rotateQtSceneToggle(
float dx, 
float dy)
  1585   if (fHoldRotateEvent)
  1587   fHoldRotateEvent = 
true;
  1589   rotateSceneToggle(dx,dy);
  1593   fHoldRotateEvent = 
false;
  1604 void G4OpenGLQtViewer::rescaleImage(
  1624 void G4OpenGLQtViewer::G4wheelEvent (QWheelEvent * evnt) 
  1626   fVP.SetZoomFactor(fVP.GetZoomFactor()+(fVP.GetZoomFactor()*(evnt->delta())/1200)); 
  1631 void G4OpenGLQtViewer::G4keyPressEvent (QKeyEvent * evnt) 
  1636   fHoldKeyEvent = 
true;
  1640   updateKeyModifierState(evnt->modifiers());
  1641   if ((fNoKeyPress) || (evnt->modifiers() == Qt::KeypadModifier )) {
  1642     if (evnt->key() == Qt::Key_Down) { 
  1643       moveScene(0,1,0,
false);
  1645     else if (evnt->key() == Qt::Key_Up) {  
  1646       moveScene(0,-1,0,
false);
  1648     if (evnt->key() == Qt::Key_Left) { 
  1649       moveScene(-1,0,0,
false);
  1651     else if (evnt->key() == Qt::Key_Right) { 
  1652       moveScene(1,0,0,
false);
  1654     if (evnt->key() == Qt::Key_Minus) { 
  1655       moveScene(0,0,1,
false);
  1657     else if (evnt->key() == Qt::Key_Plus) { 
  1658       moveScene(0,0,-1,
false);
  1662     if (evnt->key() == Qt::Key_Escape) {
  1663       toggleFullScreen(
false);
  1672   if ((evnt->key() == Qt::Key_Return) || (evnt->key() == Qt::Key_Enter)){ 
  1675   if (evnt->key() == Qt::Key_Space){ 
  1680   if (evnt->key() == Qt::Key_H){ 
  1687   if (fShiftKeyPress) {
  1688     fGLWidget->setCursor(QCursor(Qt::SizeAllCursor));
  1690     if (evnt->key() == Qt::Key_Down) { 
  1691       rotateQtScene(0,-fRot_sens);
  1693     else if (evnt->key() == Qt::Key_Up) { 
  1694       rotateQtScene(0,fRot_sens);
  1696     if (evnt->key() == Qt::Key_Left) { 
  1697       rotateQtScene(fRot_sens,0);
  1699     else if (evnt->key() == Qt::Key_Right) { 
  1700       rotateQtScene(-fRot_sens,0);
  1702     if (evnt->key() == Qt::Key_Plus) { 
  1704       moveScene(0,0,-1,
false);
  1709   if ((fAltKeyPress)) {
  1710     fGLWidget->setCursor(QCursor(Qt::ClosedHandCursor));
  1712     if (evnt->key() == Qt::Key_Down) { 
  1713       rotateQtSceneToggle(0,-fRot_sens);
  1715     else if (evnt->key() == Qt::Key_Up) { 
  1716       rotateQtSceneToggle(0,fRot_sens);
  1718     if (evnt->key() == Qt::Key_Left) { 
  1719       rotateQtSceneToggle(fRot_sens,0);
  1721     else if (evnt->key() == Qt::Key_Right) { 
  1722       rotateQtSceneToggle(-fRot_sens,0);
  1726     if (evnt->key() == Qt::Key_Plus) {
  1727       fRot_sens = fRot_sens/0.7;
  1728       G4cout << 
"Auto-rotation set to : " << fRot_sens << 
G4endl;
  1730     else if (evnt->key() == Qt::Key_Minus) {
  1731       fRot_sens = fRot_sens*0.7;
  1732       G4cout << 
"Auto-rotation set to : " << fRot_sens << 
G4endl;
  1737   if ((fControlKeyPress)) {
  1738     if (evnt->key() == Qt::Key_Plus) {
  1739       fVP.SetZoomFactor(fVP.GetZoomFactor()*(1+fDeltaZoom)); 
  1742     else if (evnt->key() == Qt::Key_Minus) {
  1743       fVP.SetZoomFactor(fVP.GetZoomFactor()*(1-fDeltaZoom)); 
  1748   fHoldKeyEvent = 
false;
  1752 void G4OpenGLQtViewer::G4keyReleaseEvent (QKeyEvent *)
  1754   fGLWidget->setCursor(QCursor(Qt::ArrowCursor));
  1758 void  G4OpenGLQtViewer::updateKeyModifierState(
const Qt::KeyboardModifiers& modifier) {
  1762   fAltKeyPress = 
false;
  1763   fShiftKeyPress = 
false;
  1764   fControlKeyPress = 
false;
  1766   if (modifier & Qt::AltModifier ) {
  1767     fAltKeyPress = 
true;
  1768     fNoKeyPress = 
false;
  1770   if (modifier & Qt::ShiftModifier ) {
  1771     fShiftKeyPress = 
true;
  1772     fNoKeyPress = 
false;
  1774   if (modifier & Qt::ControlModifier ) {
  1775     fControlKeyPress = 
true;
  1776     fNoKeyPress = 
false;
  1783 void G4OpenGLQtViewer::stopVideo() {
  1786   if (!fMovieParametersDialog) {
  1787     showMovieParametersDialog();
  1789   setRecordingStatus(STOP);
  1791   if (fRecordFrameNumber >0) {
  1793     if (!(fMovieParametersDialog->checkEncoderSwParameters())) {
  1794       setRecordingStatus(BAD_ENCODER);
  1795     }  
else if (!(fMovieParametersDialog->checkSaveFileNameParameters())) {
  1796       setRecordingStatus(BAD_OUTPUT);
  1800     setRecordingInfos(
"No frame to encode.");
  1806 void G4OpenGLQtViewer::saveVideo() {
  1809   if (!fMovieParametersDialog) {
  1810     showMovieParametersDialog();
  1813   fMovieParametersDialog->checkEncoderSwParameters();
  1814   fMovieParametersDialog->checkSaveFileNameParameters();
  1816   if (fRecordingStep == STOP) {
  1817     setRecordingStatus(SAVE);
  1818     generateMpegEncoderParameters();
  1826 void G4OpenGLQtViewer::startPauseVideo() {
  1830   if ( fRecordingStep == WAIT) {
  1831     if ( fRecordFrameNumber == 0) {
  1832       if (getTempFolderPath() == 
"") { 
  1833         showMovieParametersDialog();
  1834         setRecordingInfos(
"You should specified the temp folder in order to make movie");
  1838         QString 
tmp = removeTempFolder();
  1840           setRecordingInfos(tmp);
  1843         tmp = createTempFolder();
  1845           setRecordingInfos(
"Can't create temp folder."+tmp);
  1851   if (fRecordingStep == WAIT) {
  1852     setRecordingStatus(
START); 
  1853   } 
else if (fRecordingStep == 
START) {
  1854     setRecordingStatus(PAUSE);
  1855   } 
else if (fRecordingStep == PAUSE) {
  1856     setRecordingStatus(CONTINUE);
  1857   } 
else if (fRecordingStep == CONTINUE) {
  1858     setRecordingStatus(PAUSE);
  1862 void G4OpenGLQtViewer::setRecordingStatus(RECORDING_STEP step) {
  1864   fRecordingStep = step;
  1865   displayRecordingStatus();
  1869 void G4OpenGLQtViewer::displayRecordingStatus() {
  1871   QString txtStatus = 
"";
  1872   if (fRecordingStep == WAIT) {
  1873     txtStatus  = 
"Waiting to start...";
  1874     fRecordFrameNumber = 0; 
  1875   } 
else if (fRecordingStep == 
START) {
  1876     txtStatus  = 
"Start Recording...";
  1877   } 
else if (fRecordingStep == PAUSE) {
  1878     txtStatus  = 
"Pause Recording...";
  1879   } 
else if (fRecordingStep == CONTINUE) {
  1880     txtStatus  = 
"Continue Recording...";
  1881   } 
else if (fRecordingStep == STOP) {
  1882     txtStatus  = 
"Stop Recording...";
  1883   } 
else if (fRecordingStep == READY_TO_ENCODE) {
  1884     txtStatus  = 
"Ready to Encode...";
  1885   } 
else if (fRecordingStep == 
ENCODING) {
  1886     txtStatus  = 
"Encoding...";
  1887   } 
else if (fRecordingStep == FAILED) {
  1888     txtStatus  = 
"Failed to encode...";
  1889   } 
else if ((fRecordingStep == BAD_ENCODER)
  1890              || (fRecordingStep == BAD_OUTPUT)
  1891              || (fRecordingStep == BAD_TMP)) {
  1892     txtStatus  = 
"Correct above errors first";
  1893   } 
else if (fRecordingStep == SUCCESS) {
  1894     txtStatus  = 
"File encoded successfully";
  1898   if (fMovieParametersDialog) {
  1899     fMovieParametersDialog->setRecordingStatus(txtStatus);
  1903   setRecordingInfos(
"");
  1907 void G4OpenGLQtViewer::setRecordingInfos(
const QString& txt) {
  1908   if (fMovieParametersDialog) {
  1909     fMovieParametersDialog->setRecordingInfos(txt);
  1917 void G4OpenGLQtViewer::initMovieParameters() {
  1921   fProcess = 
new QProcess();
  1923   QObject ::connect(fProcess,SIGNAL(finished ( 
int)),
  1924                     this,SLOT(processLookForFinished()));
  1925   fProcess->setReadChannelMode(QProcess::MergedChannels);
  1926   fProcess->start (
"which ppmtompeg");
  1932 QString G4OpenGLQtViewer::getEncoderPath() {
  1933   return fEncoderPath;
  1941 QString G4OpenGLQtViewer::setEncoderPath(QString path) {
  1943     return "ppmtompeg is needed to encode in video format. It is available here: http://netpbm.sourceforge.net ";
  1946   path =  QDir::cleanPath(path);
  1947   QFileInfo *
f = 
new QFileInfo(path);
  1949     return "File does not exist";
  1950   } 
else if (f->isDir()) {
  1951     return "This is a directory";
  1952   } 
else if (!f->isExecutable()) {
  1953     return "File exist but is not executable";
  1954   } 
else if (!f->isFile()) {
  1955     return "This is not a file";
  1957   fEncoderPath = path;
  1959   if (fRecordingStep == BAD_ENCODER) {
  1960     setRecordingStatus(STOP);
  1966 bool G4OpenGLQtViewer::isRecording(){
  1967   if ((fRecordingStep == 
START) || (fRecordingStep == CONTINUE)) {
  1973 bool G4OpenGLQtViewer::isPaused(){
  1974   if (fRecordingStep == PAUSE) {
  1980 bool G4OpenGLQtViewer::isEncoding(){
  1987 bool G4OpenGLQtViewer::isWaiting(){
  1988   if (fRecordingStep == WAIT) {
  1994 bool G4OpenGLQtViewer::isStopped(){
  1995   if (fRecordingStep == STOP) {
  2001 bool G4OpenGLQtViewer::isFailed(){
  2002   if (fRecordingStep == FAILED) {
  2008 bool G4OpenGLQtViewer::isSuccess(){
  2009   if (fRecordingStep == SUCCESS) {
  2015 bool G4OpenGLQtViewer::isBadEncoder(){
  2016   if (fRecordingStep == BAD_ENCODER) {
  2021 bool G4OpenGLQtViewer::isBadTmp(){
  2022   if (fRecordingStep == BAD_TMP) {
  2027 bool G4OpenGLQtViewer::isBadOutput(){
  2028   if (fRecordingStep == BAD_OUTPUT) {
  2034 void G4OpenGLQtViewer::setBadEncoder(){
  2035   fRecordingStep = BAD_ENCODER;
  2036   displayRecordingStatus();
  2038 void G4OpenGLQtViewer::setBadTmp(){
  2039   fRecordingStep = BAD_TMP;
  2040   displayRecordingStatus();
  2042 void G4OpenGLQtViewer::setBadOutput(){
  2043   fRecordingStep = BAD_OUTPUT;
  2044   displayRecordingStatus();
  2047 void G4OpenGLQtViewer::setWaiting(){
  2048   fRecordingStep = WAIT;
  2049   displayRecordingStatus();
  2053 bool G4OpenGLQtViewer::isReadyToEncode(){
  2054   if (fRecordingStep == READY_TO_ENCODE) {
  2060 void G4OpenGLQtViewer::resetRecording() {
  2061   setRecordingStatus(WAIT);
  2068 QString G4OpenGLQtViewer::setTempFolderPath(QString path) {
  2071     return "Path does not exist";
  2073   path =  QDir::cleanPath(path);
  2074   QFileInfo *
d = 
new QFileInfo(path);
  2076     return "Path does not exist";
  2077   } 
else if (!d->isDir()) {
  2078     return "This is not a directory";
  2079   } 
else if (!d->isReadable()) {
  2080     return path +
" is read protected";
  2081   } 
else if (!d->isWritable()) {
  2082     return path +
" is write protected";
  2085   if (fRecordingStep == BAD_TMP) {
  2086     setRecordingStatus(WAIT); 
  2088   fTempFolderPath = path;
  2094 QString G4OpenGLQtViewer::getTempFolderPath() {
  2095   return fTempFolderPath;
  2102 QString G4OpenGLQtViewer::setSaveFileName(QString path) {
  2105     return "Path does not exist";
  2108   QFileInfo *
file = 
new QFileInfo(path);
  2109   QDir 
dir = file->dir();
  2110   path =  QDir::cleanPath(path);
  2111   if (file->exists()) {
  2112     return "File already exist, please choose a new one";
  2113   } 
else if (!dir.exists()) {
  2114     return "Dir does not exist";
  2115   } 
else if (!dir.isReadable()) {
  2116     return path +
" is read protected";
  2119   if (fRecordingStep == BAD_OUTPUT) {
  2120     setRecordingStatus(STOP); 
  2122   fSaveFileName = path;
  2128 QString G4OpenGLQtViewer::getSaveFileName() {
  2129   return fSaveFileName ;
  2136 QString G4OpenGLQtViewer::createTempFolder() {
  2137   fMovieTempFolderPath = 
"";
  2139   QString 
tmp = setTempFolderPath(fTempFolderPath);
  2143   QString sep = QString(QDir::separator());
  2144   QString path = sep+
"QtMovie_"+QDateTime::currentDateTime ().toString(
"dd-MM-yyyy_hh-mm-ss")+sep; 
  2145   QDir *d = 
new QDir(QDir::cleanPath(fTempFolderPath));
  2147   if (d->exists(path)) {
  2148     return "Folder "+path+
" already exists.Please remove it first";
  2150   if (d->mkdir(fTempFolderPath+path)) {
  2151     fMovieTempFolderPath = fTempFolderPath+path;
  2154   return "Can't create "+fTempFolderPath+path;
  2159 QString G4OpenGLQtViewer::removeTempFolder() {
  2161   if (fMovieTempFolderPath == 
"") {
  2164   QDir *d = 
new QDir(QDir::cleanPath(fMovieTempFolderPath));
  2169   d->setFilter( QDir::Files );
  2170   QStringList subDirList = d->entryList();
  2173   for (QStringList::ConstIterator it = subDirList.begin() ;(it != subDirList.end()) ; it++) {
  2174     const QString currentFile = *it;
  2175     if (!d->remove(currentFile)) {
  2177       QString file = fMovieTempFolderPath+currentFile;
  2178       error +=
"Removing file failed : "+
file;
  2183     if (d->rmdir(fMovieTempFolderPath)) {
  2184       fMovieTempFolderPath = 
"";
  2187       return "Dir "+fMovieTempFolderPath+
" should be empty, but could not remove it";
  2191   return "Could not remove "+fMovieTempFolderPath+
" because of the following errors :"+
error;
  2201 bool G4OpenGLQtViewer::exportImage(std::string name, 
int width, 
int height) {
  2203   QGLWidget* qGLW = 
dynamic_cast<QGLWidget*
> (fGLWidget) ;
  2208   bool increaseFileNumber = 
true;
  2210   if (name.size() != name.substr(name.find_last_of(
".") + 1).size()) {
  2211     increaseFileNumber = 
false;
  2213   if (! setExportFilename(name,increaseFileNumber)) {
  2216   if ((width !=-1) && (height != -1)) {
  2217     setExportSize(width, height);
  2220   if (G4OpenGLViewer::exportImage()) {
  2226     image = qGLW->grabFrameBuffer();
  2228     bool res = image.save(QString(getRealPrintFilename().c_str()),0,fLastExportSliderValue);
  2231       G4cerr << 
"Error saving file... " << getRealPrintFilename().c_str() << 
G4endl;
  2234       G4cout << 
"File " << getRealPrintFilename().c_str() << 
" size: " << fGLWidget->width() << 
"x" << fGLWidget->height() << 
" has been saved " << 
G4endl;
  2235       fExportFilenameIndex++;
  2243 bool G4OpenGLQtViewer::hasPendingEvents () {
  2244   return ((QApplication*)G4Qt::getInstance ())->hasPendingEvents ();
  2247 bool G4OpenGLQtViewer::generateMpegEncoderParameters () {
  2251   fp = fopen (QString(fMovieTempFolderPath+fParameterFileName).toStdString().c_str(), 
"w");
  2254     setRecordingInfos(
"Generation of parameter file failed");
  2258   fprintf (fp,
"# Pattern affects speed, quality and compression. See the User's Guide\n");
  2259   fprintf (fp,
"# for more info.\n");
  2261   fprintf (fp,
"PATTERN      IBBPBBPBBPBBPBBP\n");
  2262   fprintf (fp,
"OUTPUT       %s\n",getSaveFileName().toStdString().c_str());
  2264   fprintf (fp,
"# You must specify the type of the input files.  The choices are:\n");
  2265   fprintf (fp,
"#    YUV, PPM, JMOVIE, Y, JPEG, PNM\n");
  2266   fprintf (fp,
"#    (must be upper case)\n");
  2268   fprintf (fp,
"BASE_FILE_FORMAT PPM\n");
  2271   fprintf (fp,
"# if YUV format (or using parallel version), must provide width and height\n");
  2272   fprintf (fp,
"# YUV_SIZE   widthxheight\n");
  2273   fprintf (fp,
"# this option is ignored if BASE_FILE_FORMAT is not YUV and you're running\n");
  2274   fprintf (fp,
"# on just one machine\n");
  2276   fprintf (fp,
"YUV_SIZE 352x240\n");
  2278   fprintf (fp,
"# If you are using YUV, there are different supported file formats.\n");
  2279   fprintf (fp,
"# EYUV or UCB are the same as previous versions of this encoder.\n");
  2280   fprintf (fp,
"# (All the Y's, then U's then V's, in 4:2:0 subsampling.)\n");
  2281   fprintf (fp,
"# Other formats, such as Abekas, Phillips, or a general format are\n");
  2282   fprintf (fp,
"# permissible, the general format is a string of Y's, U's, and V's\n");
  2283   fprintf (fp,
"# to specify the file order.\n");
  2285   fprintf (fp,
"INPUT_FORMAT UCB\n");
  2287   fprintf (fp,
"# the conversion statement\n");
  2289   fprintf (fp,
"# Each occurrence of '*' will be replaced by the input file\n");
  2291   fprintf (fp,
"# e.g., if you have a bunch of GIF files, then this might be:\n");
  2292   fprintf (fp,
"#    INPUT_CONVERT   giftoppm *\n");
  2294   fprintf (fp,
"# e.g., if you have a bunch of files like a.Y a.U a.V, etc., then:\n");
  2295   fprintf (fp,
"#    INPUT_CONVERT   cat *.Y *.U *.V\n");
  2297   fprintf (fp,
"# e.g., if you are grabbing from laser disc you might have something like\n");
  2298   fprintf (fp,
"#    INPUT_CONVERT   goto frame *; grabppm\n");
  2299   fprintf (fp,
"# 'INPUT_CONVERT *' means the files are already in the base file format\n");
  2301   fprintf (fp,
"INPUT_CONVERT    * \n");
  2303   fprintf (fp,
"# number of frames in a GOP.\n");
  2305   fprintf (fp,
"# since each GOP must have at least one I-frame, the encoder will find the\n");
  2306   fprintf (fp,
"# the first I-frame after GOP_SIZE frames to start the next GOP\n");
  2308   fprintf (fp,
"# later, will add more flexible GOP signalling\n");
  2310   fprintf (fp,
"GOP_SIZE 16\n");
  2312   fprintf (fp,
"# number of slices in a frame\n");
  2314   fprintf (fp,
"# 1 is a good number.  another possibility is the number of macroblock rows\n");
  2315   fprintf (fp,
"# (which is the height divided by 16)\n");
  2317   fprintf (fp,
"SLICES_PER_FRAME 1\n");
  2319   fprintf (fp,
"# directory to get all input files from (makes this file easier to read)\n");
  2320   fprintf (fp,
"INPUT_DIR    %s\n",fMovieTempFolderPath.toStdString().c_str());
  2322   fprintf (fp,
"# There are a bunch of ways to specify the input files.\n");
  2323   fprintf (fp,
"# from a simple one-per-line listing, to the following \n");
  2324   fprintf (fp,
"# way of numbering them.  See the manual for more information.\n");
  2325   fprintf (fp,
"INPUT\n");
  2326   fprintf (fp,
"# '*' is replaced by the numbers 01, 02, 03, 04\n");
  2327   fprintf (fp,
"# if I instead do [01-11], it would be 01, 02, ..., 09, 10, 11\n");
  2328   fprintf (fp,
"# if I instead do [1-11], it would be 1, 2, 3, ..., 9, 10, 11\n");
  2329   fprintf (fp,
"# if I instead do [1-11+3], it would be 1, 4, 7, 10\n");
  2330   fprintf (fp,
"# the program assumes none of your input files has a name ending in ']'\n");
  2331   fprintf (fp,
"# if you do, too bad!!!\n");
  2334   fprintf (fp,
"Test*.ppm    [0-%d]\n",fRecordFrameNumber-1);
  2335   fprintf (fp,
"# can have more files here if you want...there is no limit on the number\n");
  2336   fprintf (fp,
"# of files\n");
  2337   fprintf (fp,
"END_INPUT\n");
  2341   fprintf (fp,
"# Many of the remaining options have to do with the motion search and qscale\n");
  2343   fprintf (fp,
"# FULL or HALF -- must be upper case\n");
  2344   fprintf (fp,
"# Should be FULL for computer generated images\n");
  2345   fprintf (fp,
"PIXEL        FULL\n");
  2347   fprintf (fp,
"# means +/- this many pixels for both P and B frame searches\n");
  2348   fprintf (fp,
"# specify two numbers if you wish to serc different ranges in the two.\n");
  2349   fprintf (fp,
"RANGE        10\n");
  2351   fprintf (fp,
"# The two search algorithm parameters below mostly affect speed,\n");
  2352   fprintf (fp,
"# with some affect on compression and almost none on quality.\n");
  2354   fprintf (fp,
"# this must be one of {EXHAUSTIVE, SUBSAMPLE, LOGARITHMIC}\n");
  2355   fprintf (fp,
"PSEARCH_ALG  LOGARITHMIC\n");
  2357   fprintf (fp,
"# this must be one of {SIMPLE, CROSS2, EXHAUSTIVE}\n");
  2359   fprintf (fp,
"# note that EXHAUSTIVE is really, really, really slow\n");
  2361   fprintf (fp,
"BSEARCH_ALG  SIMPLE\n");
  2364   fprintf (fp,
"# these specify the q-scale for I, P, and B frames\n");
  2365   fprintf (fp,
"# (values must be between 1 and 31)\n");
  2366   fprintf (fp,
"# These are the Qscale values for the entire frame in variable bit-rate\n");
  2367   fprintf (fp,
"# mode, and starting points (but not important) for constant bit rate\n");
  2370   fprintf (fp,
"# Qscale (Quantization scale) affects quality and compression,\n");
  2371   fprintf (fp,
"# but has very little effect on speed.\n");
  2373   fprintf (fp,
"IQSCALE      4\n");
  2374   fprintf (fp,
"PQSCALE      5\n");
  2375   fprintf (fp,
"BQSCALE      12\n");
  2377   fprintf (fp,
"# this must be ORIGINAL or DECODED\n");
  2378   fprintf (fp,
"REFERENCE_FRAME  ORIGINAL\n");
  2380   fprintf (fp,
"# for parallel parameters see parallel.param in the exmaples subdirectory\n");
  2382   fprintf (fp,
"# if you want constant bit-rate mode, specify it as follows (number is bits/sec):\n");
  2383   fprintf (fp,
"#BIT_RATE  1000000\n");
  2385   fprintf (fp,
"# To specify the buffer size (327680 is default, measused in bits, for 16bit words)\n");
  2386   fprintf (fp,
"BUFFER_SIZE 327680\n");
  2388   fprintf (fp,
"# The frame rate is the number of frames/second (legal values:\n");
  2389   fprintf (fp,
"# 23.976, 24, 25, 29.97, 30, 50 ,59.94, 60\n");
  2390   fprintf (fp,
"FRAME_RATE 30\n");
  2392   fprintf (fp,
"# There are many more options, see the users manual for examples....\n");
  2393   fprintf (fp,
"# ASPECT_RATIO, USER_DATA, GAMMA, IQTABLE, etc.\n");
  2398   setRecordingInfos(
"Parameter file "+fParameterFileName+
" generated in "+fMovieTempFolderPath);
  2399   setRecordingStatus(READY_TO_ENCODE);
  2403 void G4OpenGLQtViewer::encodeVideo()
  2405   if ((getEncoderPath() != 
"") && (getSaveFileName() != 
"")) {
  2408     fProcess = 
new QProcess();
  2409 #if QT_VERSION > 0x040100  2410     QObject ::connect(fProcess,SIGNAL(finished ( 
int,QProcess::ExitStatus)),
  2411                       this,SLOT(processEncodeFinished()));
  2412     QObject ::connect(fProcess,SIGNAL(readyReadStandardOutput ()),
  2413                       this,SLOT(processEncodeStdout()));
  2415     QObject ::connect(fProcess,SIGNAL(finished ( 
int)),
  2416                       this,SLOT(processEncodeFinished()));
  2417     QObject ::connect(fProcess,SIGNAL(readyReadStandardOutput ()),
  2418                       this,SLOT(processEncodeStdout()));
  2420     fProcess->setReadChannelMode(QProcess::MergedChannels);
  2421     fProcess->start (fEncoderPath, QStringList(fMovieTempFolderPath+fParameterFileName));
  2427 void G4OpenGLQtViewer::processEncodeStdout()
  2429   QString tmp = fProcess->readAllStandardOutput ().data();
  2430   int start = tmp.lastIndexOf(
"ESTIMATED TIME");
  2431   tmp = tmp.mid(start,tmp.indexOf(
"\n",start)-start);
  2432   setRecordingInfos(tmp);
  2436 void G4OpenGLQtViewer::processEncodeFinished()
  2440   txt = getProcessErrorMsg();
  2442     setRecordingStatus(SUCCESS);
  2444     setRecordingStatus(FAILED);
  2450 void G4OpenGLQtViewer::processLookForFinished() 
  2453   QString txt = getProcessErrorMsg();
  2457     fEncoderPath = QString(fProcess->readAllStandardOutput ().data()).trimmed();
  2459     if (fEncoderPath.contains(
" ")) {
  2461     } 
else if (!fEncoderPath.contains(
"ppmtompeg")) {
  2464     setEncoderPath(fEncoderPath);
  2467   setTempFolderPath(QDir::temp ().absolutePath ());
  2471 QString G4OpenGLQtViewer::getProcessErrorMsg()
  2474   if (fProcess->exitCode() != 0) {
  2475     switch (fProcess->error()) {
  2476     case QProcess::FailedToStart:
  2477       txt = 
"The process failed to start. Either the invoked program is missing, or you may have insufficient permissions to invoke the program.\n";
  2479     case QProcess::Crashed:
  2480       txt = 
"The process crashed some time after starting successfully.\n";
  2482     case QProcess::Timedout:
  2483       txt = 
"The last waitFor...() function timed out. The state of QProcess is unchanged, and you can try calling waitFor...() again.\n";
  2485     case QProcess::WriteError:
  2486       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";
  2488     case QProcess::ReadError:
  2489       txt = 
"An error occurred when attempting to read from the process. For example, the process may not be running.\n";
  2491     case QProcess::UnknownError:
  2492       txt = 
"An unknown error occurred. This is the default return value of error().\n";
  2502 QWidget *G4OpenGLQtViewer::getParentWidget() 
  2505   G4Qt* interactorManager = G4Qt::getInstance ();
  2510   QDialog* dialog = NULL;
  2512   if (((QApplication*)interactorManager->GetMainInteractor())) {
  2514     QWidgetList wl = QApplication::allWidgets();
  2515     QWidget *widget = NULL;
  2516     for (
int i=0; i < wl.size(); i++) {
  2518       if ((found== 
false) && (widget->inherits(
"QMainWindow"))) {
  2519         dialog = 
new QDialog(widget,Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowMinMaxButtonsHint);
  2525       dialog = 
new QDialog();
  2528     dialog= 
new QDialog();
  2538 void G4OpenGLQtViewer::createSceneTreeComponent(){
  2540   QGroupBox *groupBox = 
new QGroupBox(
"");
  2541   QVBoxLayout *vbox = 
new QVBoxLayout;
  2543   fSceneTreeViewerButton = 
new QPushButton(
"Scene tree");
  2544   fSceneTreeViewerButton->setStyleSheet (
"text-align: left; padding: 2px; border:0px; background:#e0e5ef;");
  2545   fSceneTreeViewerButton->setIcon(*fTreeIconOpen);
  2547   vbox->addWidget(fSceneTreeViewerButton);
  2548   connect(fSceneTreeViewerButton,SIGNAL(clicked()),
this, SLOT(toggleSceneTreeViewerInfos()));
  2550   fSceneTreeViewerInfos = 
new QWidget();
  2551   fSceneTreeViewerInfos->setStyleSheet (
"padding: 0px ");
  2552   fSceneTreeViewerInfos->setSizePolicy(QSizePolicy::Minimum,QSizePolicy::Minimum);
  2554   QVBoxLayout* vLayout = 
new QVBoxLayout();
  2555   fSceneTreeViewerInfos->setLayout (vLayout);
  2558   QWidget* coutButtonWidget = 
new QWidget();
  2559   QHBoxLayout* layoutCoutTBButtons = 
new QHBoxLayout();
  2561   fFilterOutput = 
new QLineEdit();
  2562   fFilterOutput->setToolTip(
"Filter output by...");
  2563   fFilterOutput->setStyleSheet (
"padding: 0px ");
  2565   QPixmap* searchIcon = fUiQt->getSearchIcon();
  2566 #if QT_VERSION > 0x050100  2567   fFilterOutput->addAction(*searchIcon,QLineEdit::TrailingPosition);
  2568   fFilterOutput->setStyleSheet (
"border-radius:7px;");
  2570   QPushButton *coutTBFilterButton = 
new QPushButton();
  2571   coutTBFilterButton->setIcon(*searchIcon);
  2572   coutTBFilterButton->setStyleSheet (
"padding-left: 0px; border:0px;");
  2573   fFilterOutput->setStyleSheet (
"padding-right: 0px;");
  2575   layoutCoutTBButtons->addWidget(fFilterOutput);
  2577 #if QT_VERSION <= 0x050100  2578   layoutCoutTBButtons->addWidget(coutTBFilterButton);
  2581   coutButtonWidget->setLayout(layoutCoutTBButtons);
  2582   vLayout->addWidget(coutButtonWidget);
  2585   vLayout->setContentsMargins(0,0,0,0);
  2586   vbox->setContentsMargins(1,1,1,1);
  2589   fSceneTreeComponentTreeWidget = 
new QTreeWidget();
  2590   fSceneTreeComponentTreeWidget->setSelectionMode(QAbstractItemView::SingleSelection);
  2591   fSceneTreeComponentTreeWidget->setHeaderLabel (
"Scene tree : "+QString(
GetName().data()));
  2592   fSceneTreeComponentTreeWidget->setColumnHidden (1,
true);  
  2593   fSceneTreeComponentTreeWidget->setColumnHidden (2,
true);  
  2594   fSceneTreeComponentTreeWidget->setColumnHidden (3,
true);  
  2599   vLayout->addWidget(fSceneTreeComponentTreeWidget);
  2601   connect(fSceneTreeComponentTreeWidget,SIGNAL(itemChanged(QTreeWidgetItem*, 
int)),SLOT(sceneTreeComponentItemChanged(QTreeWidgetItem*, 
int)));
  2602   connect(fSceneTreeComponentTreeWidget,SIGNAL(itemSelectionChanged ()),SLOT(sceneTreeComponentSelected()));
  2603   connect(fSceneTreeComponentTreeWidget,SIGNAL(itemDoubleClicked ( QTreeWidgetItem*, 
int)),SLOT(changeColorAndTransparency( QTreeWidgetItem*, 
int)));
  2607   QWidget *helpWidget = 
new QWidget();
  2608   QHBoxLayout *helpLayout = 
new QHBoxLayout();
  2610   QWidget* depthWidget = 
new QWidget();
  2611   QWidget *showBox = 
new QWidget(depthWidget);
  2612   QHBoxLayout *showBoxLayout = 
new QHBoxLayout();
  2615   showBoxLayout->setContentsMargins(5,5,5,5);
  2617   QLabel *zero = 
new QLabel();
  2618   zero->setText(
"Show all");          
  2619   QLabel *one = 
new QLabel();
  2620   one->setText(
"Hide all");
  2621   fSceneTreeDepthSlider = 
new QSlider ( Qt::Horizontal);
  2622   fSceneTreeDepthSlider->setMaximum (1000);
  2623   fSceneTreeDepthSlider->setMinimum (0);
  2624   fSceneTreeDepthSlider->setTickPosition(QSlider::TicksAbove);
  2626   fSceneTreeDepthSlider->setMinimumWidth (40);
  2628   showBoxLayout->addWidget(zero);
  2629   showBoxLayout->addWidget(fSceneTreeDepthSlider);
  2630   showBoxLayout->addWidget(one);
  2632   showBox->setLayout(showBoxLayout);
  2634   helpLayout->addWidget(showBox);
  2635   helpWidget->setLayout(helpLayout);
  2636   helpLayout->setContentsMargins(0,0,0,0);
  2638   vLayout->addWidget(helpWidget);
  2639   QSizePolicy vPolicy = fSceneTreeViewerInfos->sizePolicy();
  2640   vPolicy.setVerticalStretch(4);
  2642   vbox->addWidget(fSceneTreeViewerInfos);
  2644   groupBox->setLayout(vbox);
  2645   fSceneTreeWidget->layout()->addWidget(groupBox);
  2647   connect( fSceneTreeDepthSlider, SIGNAL( valueChanged(
int) ), 
this, SLOT( changeDepthInSceneTree(
int) ) );
  2648   fTreeItemModels.clear();
  2650   fPVRootNodeCreate = 
false;
  2652   fMaxPOindexInserted = -1;
  2658 void G4OpenGLQtViewer::createViewerPropertiesComponent() {
  2661   QGroupBox *groupBox = 
new QGroupBox(
"");
  2662   QVBoxLayout *vbox = 
new QVBoxLayout;
  2663   fViewerPropertiesButton = 
new QPushButton(
"Viewer properties");
  2664   fViewerPropertiesButton->setStyleSheet (
"text-align: left; padding: 2px; border:0px; background:#e0e5ef;");
  2666   fViewerPropertiesButton->setIcon(*fTreeIconOpen);
  2668   vbox->addWidget(fViewerPropertiesButton);
  2669   connect(fViewerPropertiesButton,SIGNAL(clicked()),
this, SLOT(toggleSceneTreeComponentTreeWidgetInfos()));
  2672   fSceneTreeComponentTreeWidgetInfos = 
new QTableWidget();
  2673   fSceneTreeComponentTreeWidgetInfos->setStyleSheet (
"padding: 0px ");
  2674   vbox->addWidget(fSceneTreeComponentTreeWidgetInfos);
  2675   vbox->setContentsMargins(1,1,1,1);
  2677   groupBox->setLayout(vbox);
  2678   fSceneTreeWidget->layout()->addWidget(groupBox);
  2679   QSizePolicy vPolicy = fSceneTreeComponentTreeWidgetInfos->sizePolicy();
  2680   vPolicy.setVerticalStretch(4);
  2682   connect(fSceneTreeComponentTreeWidgetInfos, SIGNAL(itemChanged(QTableWidgetItem*)),
this, SLOT(tableWidgetViewerSetItemChanged(QTableWidgetItem *)));
  2684   updateSceneTreeComponentTreeWidgetInfos();
  2688 void G4OpenGLQtViewer::createPickingComponent(){
  2690   QGroupBox *groupBox = 
new QGroupBox(
"");
  2691   QVBoxLayout *vbox = 
new QVBoxLayout;
  2694   QWidget *pickingInfoWidget = 
new QWidget();
  2695   QHBoxLayout *pickingInfoLayout = 
new QHBoxLayout();
  2697   fViewerPickingButton = 
new QPushButton(
"Picking informations");
  2698   fViewerPickingButton->setStyleSheet (
"text-align: left; padding: 2px; border:0px; background:#e0e5ef;");
  2699   fViewerPickingButton->setIcon(*fTreeIconOpen);
  2703   QCheckBox * activatePicking = 
new QCheckBox(
"Picking mode active");
  2704   if (fVP.IsPicking()) {
  2705     activatePicking->setCheckState(Qt::Checked);
  2707     activatePicking->setCheckState(Qt::Unchecked);
  2709   activatePicking->setToolTip(
"Enable picking allow you to display properties of a selected object on the scene");
  2710   connect(activatePicking, SIGNAL(clicked()), 
this, SLOT(togglePicking()));
  2712   pickingInfoLayout->addWidget(fViewerPickingButton);
  2713   pickingInfoLayout->addWidget(activatePicking);
  2715   pickingInfoWidget->setStyleSheet (
"padding-left: 0px; border:0px;");
  2716   pickingInfoWidget->setLayout(pickingInfoLayout);
  2718   vbox->addWidget(pickingInfoWidget);
  2719   connect(fViewerPickingButton,SIGNAL(clicked()),
this, SLOT(toggleSceneTreeComponentPickingInfos()));
  2723   fSceneTreeComponentPickingScrollArea = 
new QScrollArea();
  2724   fSceneTreeComponentPickingScrollArea->setWidgetResizable(
true);
  2727   fSceneTreeComponentPickingInfos = 
new QWidget();
  2728   fSceneTreeComponentPickingInfos->setStyleSheet (
"padding: 0px ");
  2730   QVBoxLayout* vLayout = 
new QVBoxLayout();
  2731   fSceneTreeComponentPickingInfos->setLayout (vLayout);
  2732   fSceneTreeComponentPickingScrollArea->setWidget(fSceneTreeComponentPickingInfos);
  2734   QSizePolicy vPolicy = fSceneTreeComponentPickingInfos->sizePolicy();
  2735   vPolicy.setVerticalStretch(4);
  2736   vbox->addWidget(fSceneTreeComponentPickingScrollArea);
  2737   pickingInfoLayout->setContentsMargins(0,0,0,0);
  2738   vLayout->setContentsMargins(0,0,0,0);
  2739   vbox->setContentsMargins(1,1,1,1);
  2741   groupBox->setLayout(vbox);
  2742   fSceneTreeWidget->layout()->addWidget(groupBox);
  2743   connect( fFilterOutput, SIGNAL( textEdited ( 
const QString &) ), 
this, SLOT(changeSearchSelection()));
  2750 void G4OpenGLQtViewer::setCheckComponent(QTreeWidgetItem* item,
bool check)
  2754       item->setCheckState(0,Qt::Checked);
  2756       item->setCheckState(0,Qt::Unchecked);
  2758       updatePositivePoIndexSceneTreeWidgetQuickMap(item->data(0,Qt::UserRole).toInt(),item);
  2759     int nChildCount = item->childCount();
  2760     for (
int i = 0; i < nChildCount; i++) {
  2761       setCheckComponent(item->child(i),check);
  2767 void G4OpenGLQtViewer::DrawText(
const G4Text& g4text)
  2769   QGLWidget* qGLW = 
dynamic_cast<QGLWidget*
> (fGLWidget) ;
  2773   if (isGl2psWriting()) {
  2775     G4OpenGLViewer::DrawText(g4text);
  2779     if (!fGLWidget) 
return;
  2781 #ifdef G4MULTITHREADED  2786     G4double size = fSceneHandler.GetMarkerSize(g4text,sizeType);
  2788     QFont font = QFont();
  2789     font.setPointSizeF(size);
  2791     const G4Colour& 
c = fSceneHandler.GetTextColour(g4text);
  2797     const char* textCString = textString.c_str();
  2799     glRasterPos3d(position.x(),position.y(),position.z());
  2802     QFontMetrics* f = 
new QFontMetrics (font);
  2803     G4double span = f->width(textCString);
  2816       ((position.x()+(2*xmove)/getWinWidth()),
  2817        (position.y()+(2*ymove)/getWinHeight()),
  2826 void G4OpenGLQtViewer::ResetView () {
  2827   G4OpenGLViewer::ResetView();
  2837   const QString& modelShortName = getModelShortName(model);
  2839   if (modelShortName == 
"") {
  2843   if (fSceneTreeComponentTreeWidget == NULL) {
  2844     createSceneTreeComponent();
  2848   if (fSceneTreeComponentTreeWidget == NULL) {
  2852   fSceneTreeComponentTreeWidget->blockSignals(
true);
  2856   if (!fPVRootNodeCreate) {
  2857     const G4VisAttributes* visAttr = GetApplicableVisAttributes(pPVModel->
GetFullPVPath().at(0).GetPhysicalVolume()->GetLogicalVolume()->GetVisAttributes());
  2860     fModelShortNameItem = createTreeWidgetItem(pPVModel->
GetFullPVPath(),
  2868     fPVRootNodeCreate = 
true;
  2871   bool added = parseAndInsertInSceneTree(fModelShortNameItem,pPVModel,0,modelShortName,0,currentPOIndex);
  2875   fSceneTreeComponentTreeWidget->blockSignals(
false);
  2884 QTreeWidgetItem* G4OpenGLQtViewer::createTreeWidgetItem(
  2886  ,
const QString& name
  2889  ,
const QString& logicalName
  2890  ,Qt::CheckState state
  2891  ,QTreeWidgetItem * parentTreeNode
  2896   if (fullPath.size() > fSceneTreeDepth) {
  2897     fSceneTreeDepth = fullPath.size();
  2899     if (fSceneTreeDepthSlider) {
  2900       fSceneTreeDepthSlider->setTickInterval(1000/(fSceneTreeDepth+1));
  2903   QTreeWidgetItem * newItem = NULL;
  2904   if (parentTreeNode == NULL) {
  2905     newItem = 
new QTreeWidgetItem();
  2906     fSceneTreeComponentTreeWidget->addTopLevelItem(newItem);
  2908     newItem = 
new QTreeWidgetItem(parentTreeNode);
  2909     fSceneTreeComponentTreeWidget->addTopLevelItem(parentTreeNode);
  2913   newItem->setText(0,name);
  2914   newItem->setData(1,Qt::UserRole,copyNb);
  2915   newItem->setText(2,QString::number(POIndex));
  2916   newItem->setData(0, Qt::UserRole, POIndex);
  2917   newItem->setText(3,logicalName);
  2918   newItem->setFlags(newItem->flags()|Qt::ItemIsUserCheckable);
  2919   newItem->setCheckState(0,state);
  2920   newItem->setExpanded(
true);
  2921   updatePositivePoIndexSceneTreeWidgetQuickMap(POIndex,newItem);
  2923   changeQColorForTreeWidgetItem(newItem,QColor((
int)(color.
GetRed()*255),
  2929   if ((state == Qt::Unchecked) && (POIndex == -1)) {
  2930     newItem->setForeground (0, QBrush( 
Qt::gray) );
  2933     newItem->setToolTip (0,QString(
  2934                                    "This node exists in the geometry but has not been\n")+
  2935                          "drawn, perhaps because it has been set invisible. It \n"+
  2936                          "cannot be made visible with a click on the button.\n"+
  2937                          "To see it, change the visibility, for example, with \n"+
  2938                          "/vis/geometry/set/visibility " + logicalName + 
" 0 true\n"+
  2939                          "and rebuild the view with /vis/viewer/rebuild.\n"+
  2940                          "Click here will only show/hide all child components");
  2943     newItem->setToolTip (0,QString(
"double-click to change the color"));
  2949     state = Qt::Unchecked;
  2950     newItem->setCheckState(0,state);
  2951     updatePositivePoIndexSceneTreeWidgetQuickMap(POIndex,newItem);
  2954   fTreeItemModels.insert(std::pair <int, PVPath > (POIndex,fullPath) );
  2958   changeOpenCloseVisibleHiddenSelectedColorSceneTreeElement(newItem);
  2975 bool G4OpenGLQtViewer::parseAndInsertInSceneTree(
  2976  QTreeWidgetItem * parentItem
  2978  ,
unsigned int fullPathIndex
  2979  ,
const QString& parentRoot
  2980  ,
unsigned int currentIndexInTreeSceneHandler
  2981  ,
int currentPVPOIndex
  2984   if (parentItem == NULL) {
  2990   std::ostringstream oss;
  2991   oss << fullPath.at(fullPathIndex).GetCopyNo();
  2992   std::string currentPVName = 
G4String(fullPath.at(fullPathIndex).GetPhysicalVolume()->GetName()+
" ["+oss.str()+
"]").data();
  2994   int currentPVCopyNb = fullPath.at(fullPathIndex).GetCopyNo();
  2996   const G4VisAttributes* visAttr = GetApplicableVisAttributes(fullPath.at(fullPathIndex).GetPhysicalVolume()->GetLogicalVolume()->GetVisAttributes());
  3005   QTreeWidgetItem* subItem = NULL;
  3006   QList<QTreeWidgetItem *> parentItemList;
  3014   if ((currentIndexInTreeSceneHandler == (fullPath.size()-1)) && ((color.GetAlpha() == 1.))) {
  3016     QString lookForString = QString(currentPVName.c_str());
  3017     for (
int i = 0;i < parentItem->childCount(); i++ ) {
  3018       if (parentItem->child(i)->text(0) == lookForString) {
  3019         parentItemList.push_back(parentItem->child(i));
  3024   for (
int i = 0; i < parentItemList.size(); ++i) {
  3025     const std::string& parentItemName = parentItemList.at(i)->text(0).toStdString();
  3026     int parentItemCopyNb = parentItemList.at(i)->data(1,Qt::UserRole).toInt();
  3027     int parentItemPOIndex = parentItemList.at(i)->data(0,Qt::UserRole).toInt();
  3035     if (((parentRoot == fTouchableVolumes) &&  (currentPVCopyNb == parentItemCopyNb)
  3036          && (currentPVName == parentItemName))        ||
  3038         ((parentRoot != fTouchableVolumes) && (currentPVCopyNb == parentItemCopyNb) 
  3040          && (currentPVName == parentItemName) && (currentPVPOIndex == parentItemPOIndex) )) {
  3043       bool sameTransform = 
true;
  3044       if (parentItemPOIndex >= 0) {
  3045         const PVPath& fullPathTmp = fTreeItemModels[parentItemPOIndex];
  3046         if (fullPathTmp.size() > 0) {
  3047           if (fullPathTmp.at(fullPathTmp.size()-1).GetTransform () == pPVModel->
GetTransformation ()) {
  3048             sameTransform = 
true;
  3050             sameTransform = 
false;
  3056       if (sameTransform == 
true) {
  3063         if (currentIndexInTreeSceneHandler == (fullPath.size()-1)) {
  3065           parentItemList.at(i)->setText(2,QString::number(currentPVPOIndex));
  3066           parentItemList.at(i)->setData(0, Qt::UserRole,currentPVPOIndex);
  3068           fTreeItemModels.insert(std::pair <int, PVPath >(currentPVPOIndex,fullPath) );
  3072           parentItemList.at(i)->setFont (0,f);
  3075           parentItemList.at(i)->setForeground (0,QBrush());
  3078           parentItemList.at(i)->setToolTip (0,
"");
  3080           changeQColorForTreeWidgetItem(parentItemList.at(i),QColor((
int)(color.GetRed()*255),
  3081                                                                     (
int)(color.GetGreen()*255),
  3082                                                                     (
int)(color.GetBlue()*255),
  3083                                                                     (
int)(color.GetAlpha()*255)));
  3086           if (color.GetAlpha() > 0) {
  3087             parentItemList.at(i)->setCheckState(0,Qt::Checked);
  3088             updatePositivePoIndexSceneTreeWidgetQuickMap(currentPVPOIndex,parentItemList.at(i));
  3092           subItem = parentItemList.at(i);        
  3096       } 
else if (currentIndexInTreeSceneHandler < (fullPath.size()-1))  {
  3097         subItem = parentItemList.at(i);
  3104   if (currentIndexInTreeSceneHandler == (fullPath.size()-1)) {
  3105      createTreeWidgetItem(fullPath,
  3106                                    QString(currentPVName.c_str()),
  3109                                    QString(fullPath.at(fullPathIndex).GetPhysicalVolume()->GetLogicalVolume()->GetName().data()),
  3114     if (currentPVPOIndex > fMaxPOindexInserted) {
  3115       fMaxPOindexInserted = currentPVPOIndex;
  3121     if (subItem == NULL) {
  3123       if (currentIndexInTreeSceneHandler < (fullPath.size()-1))  {
  3124         subItem = createTreeWidgetItem(fullPath,
  3125                                        QString(currentPVName.c_str()),
  3128                                        QString(fullPath.at(fullPathIndex).GetPhysicalVolume()->GetLogicalVolume()->GetName().data()),
  3135     return parseAndInsertInSceneTree(subItem,pPVModel,fullPathIndex+1,parentRoot,currentIndexInTreeSceneHandler+1,currentPVPOIndex);
  3141 void G4OpenGLQtViewer::changeOpenCloseVisibleHiddenSelectedColorSceneTreeElement(
  3142  QTreeWidgetItem* subItem
  3146   QTreeWidgetItem* oldItem = NULL;
  3148   QTreeWidgetItem* foundItem = getOldTreeWidgetItem(subItem->data(0,Qt::UserRole).toInt());
  3150   if (foundItem != NULL) {
  3151     if (isSameSceneTreeElement(foundItem,subItem)) {
  3152       oldItem = foundItem;
  3155   if (foundItem == NULL) {  
  3158     std::map <int, QTreeWidgetItem*>::const_iterator i;
  3159     i = fOldPositivePoIndexSceneTreeWidgetQuickMap.begin();
  3160     while (i != fOldPositivePoIndexSceneTreeWidgetQuickMap.end()) {
  3161       if (isSameSceneTreeElement(i->second,subItem)) {
  3162         oldItem = i->second;
  3163         i = fOldPositivePoIndexSceneTreeWidgetQuickMap.end();
  3169     if (oldItem == NULL) {
  3171       while (a < fOldNullPoIndexSceneTreeWidgetQuickVector.size()) {
  3172         if (isSameSceneTreeElement(fOldNullPoIndexSceneTreeWidgetQuickVector[a],subItem)) {
  3173           oldItem = fOldNullPoIndexSceneTreeWidgetQuickVector[
a];
  3174           a = fOldNullPoIndexSceneTreeWidgetQuickVector.size();
  3183   if (oldItem != NULL) {
  3184     subItem->setFlags(oldItem->flags());   
  3185     subItem->setCheckState(0,oldItem->checkState(0)); 
  3186     subItem->setSelected(oldItem->isSelected());  
  3187     subItem->setExpanded(oldItem->isExpanded ());  
  3192     std::map <int, QTreeWidgetItem* >::iterator it;
  3195     int oldPOIndex = oldItem->data(0,Qt::UserRole).toInt();
  3196     it = fOldPositivePoIndexSceneTreeWidgetQuickMap.find(oldPOIndex);
  3200     std::map <int, QColor >::iterator itVis;
  3201     itVis = fOldVisAttrColorMap.find(oldPOIndex);
  3203     QColor oldVisAttrColor;
  3204     const QColor& newVisAttrColor = subItem->data(2,Qt::UserRole).value<QColor>();
  3206     bool visAttrChange = 
false;
  3208     if (itVis != fOldVisAttrColorMap.end()) {
  3209       oldVisAttrColor = itVis->second;
  3210       if (oldVisAttrColor != newVisAttrColor) {
  3211         visAttrChange = 
true;
  3214       visAttrChange = 
true;
  3217     if (visAttrChange) {
  3218       fOldVisAttrColorMap.insert(std::pair <int, QColor > (subItem->data(0,Qt::UserRole).toInt(),newVisAttrColor) );
  3222       if (it != fOldPositivePoIndexSceneTreeWidgetQuickMap.end()) {
  3223         color = (it->second)->data(2,Qt::UserRole).value<QColor>(); 
  3225         color = oldItem->data(2,Qt::UserRole).value<QColor>(); 
  3227       changeQColorForTreeWidgetItem(subItem,color);
  3239 bool G4OpenGLQtViewer::isSameSceneTreeElement(
  3240  QTreeWidgetItem* parentOldItem
  3241  ,QTreeWidgetItem* parentNewItem
  3247   int newCpNumber = -1;
  3248   int oldCpNumber = -1;
  3250   bool firstWhile = 
true;
  3252   while ((parentOldItem != NULL) && (parentNewItem != NULL)) {
  3256       oldPO = parentOldItem->data(0,Qt::UserRole).toInt();
  3257       newPO = parentNewItem->data(0,Qt::UserRole).toInt();
  3263       const PVPath& oldFullPath = fOldTreeItemModels[oldPO];
  3264       const PVPath& newFullPath = fTreeItemModels[newPO];
  3265       if ((oldFullPath.size() > 0) &&
  3266           (newFullPath.size() > 0)) {
  3267         if (oldFullPath.size() != newFullPath.size()) {
  3270         if (oldFullPath.at(oldFullPath.size()-1).GetTransform () == newFullPath.at(newFullPath.size()-1).GetTransform ()) {
  3271           newCpNumber = newFullPath.at(newFullPath.size()-1).GetCopyNo();
  3272           oldCpNumber = oldFullPath.at(oldFullPath.size()-1).GetCopyNo();
  3281     if (oldCpNumber == -1) {
  3282       oldCpNumber = parentOldItem->data(1,Qt::UserRole).toInt();
  3284     if (newCpNumber == -1) {
  3285       newCpNumber = parentNewItem->data(1,Qt::UserRole).toInt();
  3287     if ((oldCpNumber != newCpNumber) ||
  3289         (parentOldItem->text(0) != parentNewItem->text(0)) ) { 
  3292     } 
else if ((parentOldItem->text(0) != parentNewItem->text(0)) || 
  3293                (parentOldItem->text(3) != parentNewItem->text(3))) {   
  3296       parentOldItem = parentOldItem->parent();
  3297       parentNewItem = parentNewItem->parent();
  3305 void G4OpenGLQtViewer::addNonPVSceneTreeElement(
  3308  ,
const std::string& modelDescription
  3312   QString modelShortName = getModelShortName(model);
  3317     const G4Text& g4Text = 
dynamic_cast<const G4Text&
>(visible);
  3318     color = fSceneHandler.GetTextColour(g4Text);
  3320   catch (std::bad_cast) {
  3321     color = fSceneHandler.
GetColour(visible);
  3323   if (modelShortName == 
"") {
  3327   if (fSceneTreeComponentTreeWidget == NULL) {
  3328     createSceneTreeComponent();
  3332   if (fSceneTreeComponentTreeWidget == NULL) {
  3336   fSceneTreeComponentTreeWidget->blockSignals(
true);
  3340   QList<QTreeWidgetItem *> resItem;
  3341   resItem =  fSceneTreeComponentTreeWidget->findItems (modelShortName, Qt::MatchExactly, 0 );
  3342   QTreeWidgetItem * currentItem = NULL;
  3343   const PVPath tmpFullPath;
  3345   if (resItem.empty()) {
  3346     currentItem = createTreeWidgetItem(tmpFullPath,
  3355     currentItem = resItem.first();
  3359   const QList<QTreeWidgetItem *>&
  3360   resItems =  fSceneTreeComponentTreeWidget->findItems (QString(modelDescription.c_str()), Qt::MatchFixedString| Qt::MatchCaseSensitive|Qt::MatchRecursive, 0 );
  3362   bool alreadyPresent = 
false;
  3363   for (
int i = 0; i < resItems.size(); ++i) {
  3364     if (currentPOIndex == resItems.at(i)->data(0,Qt::UserRole).toInt()) {
  3365       alreadyPresent = 
true;
  3368   if (!alreadyPresent) {
  3369     createTreeWidgetItem(tmpFullPath,
  3370                          QString(modelDescription.c_str()),
  3378   fSceneTreeComponentTreeWidget->blockSignals(
false);
  3386 QString G4OpenGLQtViewer::getModelShortName(
const G4String& model) {
  3388   QString modelShortName = model.
data();
  3389   if (modelShortName.mid(0,modelShortName.indexOf(
" ")) == 
"G4PhysicalVolumeModel") {
  3390     modelShortName = fTouchableVolumes;
  3392     if (modelShortName.mid(0,2) == 
"G4") {
  3393       modelShortName = modelShortName.mid(2);
  3395     if (modelShortName.indexOf(
"Model") != -1) {
  3396       modelShortName = modelShortName.mid(0,modelShortName.indexOf(
"Model"));
  3399   return modelShortName;
  3404 bool G4OpenGLQtViewer::isTouchableVisible(
int POindex){
  3407   if (fSceneTreeComponentTreeWidget == NULL) {
  3413   if (fLastSceneTreeWidgetAskForIterator != fLastSceneTreeWidgetAskForIteratorEnd) {
  3414     fLastSceneTreeWidgetAskForIterator++;
  3416   QTreeWidgetItem* item = getTreeWidgetItem(POindex);
  3419     if ( item->checkState(0) == Qt::Checked) {
  3427 bool G4OpenGLQtViewer::parseAndCheckVisibility(QTreeWidgetItem * treeNode,
int POindex){
  3428   bool isFound = 
false;
  3429   for (
int i = 0; i < treeNode->childCount() ; ++i) {
  3431     if (treeNode->child(i)->data(0,Qt::UserRole).toInt() == POindex) {
  3432       if (treeNode->child(i)->checkState(0) == Qt::Checked) {
  3436     isFound = parseAndCheckVisibility(treeNode->child(i),POindex);
  3445 std::string G4OpenGLQtViewer::parseSceneTreeAndSaveState(){
  3446   std::string commandLine = 
"";
  3447   for (
int b=0;
b<fSceneTreeComponentTreeWidget->topLevelItemCount();
b++) {
  3448     commandLine += parseSceneTreeElementAndSaveState(fSceneTreeComponentTreeWidget->topLevelItem(
b),1)+
"\n";
  3450   if (commandLine != 
"") {
  3451     commandLine = std::string(
"# Disable auto refresh and quieten vis messages whilst scene and\n") +
  3452     "# trajectories are established:\n" +
  3453     "/vis/viewer/set/autoRefresh false\n" +
  3454     "/vis/verbose errors" +
  3456     "# Re-establish auto refreshing and verbosity:\n" +
  3457     "/vis/viewer/set/autoRefresh true\n" +
  3458     "/vis/verbose confirmations\n";
  3464 std::string G4OpenGLQtViewer::parseSceneTreeElementAndSaveState(QTreeWidgetItem* item, 
unsigned int level){
  3466   std::string str( level, 
' ' );
  3467   std::string commandLine = 
"\n#"+ str + 
"PV Name: " + item->text(0).toStdString();
  3469   if (item->text(3) != 
"") {
  3470     commandLine += 
" LV Name: "+item->text(3).toStdString()+
"\n";
  3472     commandLine += 
"/vis/geometry/set/visibility " + item->text(3).toStdString() + 
" ! "; 
  3473     if (item->checkState(0) == Qt::Checked) {
  3476     if (item->checkState(0) == Qt::Unchecked) {
  3482     const QColor& c = item->data(2,Qt::UserRole).value<QColor>();
  3483     std::stringstream 
red;
  3484     red << ((double)c.red())/255;
  3485     std::stringstream green;
  3486     green << (double)c.green()/255;
  3487     std::stringstream 
blue;
  3488     blue << ((double)c.blue())/255;
  3489     std::stringstream 
alpha;
  3490     alpha << ((double)c.alpha())/255;
  3492     commandLine += 
"/vis/geometry/set/colour " + item->text(3).toStdString() + 
" ! " + red.str() + 
" " + green.str() + 
" " + blue.str() + 
" " + alpha.str()+
"\n";
  3495     commandLine += 
"\n";
  3499   for (
int b=0;
b< item->childCount();
b++) {
  3500     commandLine += parseSceneTreeElementAndSaveState(item->child(
b),level+1);
  3507 void G4OpenGLQtViewer::sceneTreeComponentItemChanged(QTreeWidgetItem* item, 
int) {
  3509   if (fCheckSceneTreeComponentSignalLock == 
false) {
  3510     fCheckSceneTreeComponentSignalLock = 
true;
  3512     if (item->checkState(0) == Qt::Checked) {
  3515     setCheckComponent(item,checked);
  3518     fCheckSceneTreeComponentSignalLock = 
false;
  3523 void G4OpenGLQtViewer::sceneTreeComponentSelected() {
  3541 void G4OpenGLQtViewer::changeDepthInSceneTree (
int val){
  3544   if (fSceneTreeComponentTreeWidget == NULL) {
  3555   double depth = 1 + ((double)val)/1000 * ((double)fSceneTreeDepth+1);
  3558   fCheckSceneTreeComponentSignalLock = 
true;
  3561   G4bool currentAutoRefresh = fVP.IsAutoRefresh();
  3562   fVP.SetAutoRefresh(
false);
  3564   for (
int b=0;
b<fSceneTreeComponentTreeWidget->topLevelItemCount();
b++) {
  3565     changeDepthOnSceneTreeItem(depth,1.,fSceneTreeComponentTreeWidget->topLevelItem(
b));
  3569   fVP.SetAutoRefresh(currentAutoRefresh);
  3573   fCheckSceneTreeComponentSignalLock = 
false;
  3578 void G4OpenGLQtViewer::changeColorAndTransparency(QTreeWidgetItem* item,
int) {
  3583   const QColor& old = QColor(item->data(2,Qt::UserRole).value<QColor>());
  3585 #if QT_VERSION < 0x040500  3587   const QColor& color = QColor(QColorDialog::getRgba (old.rgba(),&
a,fSceneTreeComponentTreeWidget));
  3589   const QColor& color = QColorDialog::getColor(old,
  3590                                         fSceneTreeComponentTreeWidget,
  3591                                         " Get color and transparency",
  3592                                         QColorDialog::ShowAlphaChannel);
  3595   if (color.isValid()) {
  3597     changeColorAndTransparency(item->data(0,Qt::UserRole).toInt(),
  3604     changeQColorForTreeWidgetItem(item,color);
  3609 void G4OpenGLQtViewer::changeColorAndTransparency(GLuint 
index, 
G4Color color) {
  3613   if (iPO >= 0 && fTreeItemModels.find(iPO) != fTreeItemModels.end()) {
  3614     const PVPath& fullPath = fTreeItemModels[iPO];
  3616     if (fullPath.size()) {
  3624       fVP.AddVisAttributesModifier
  3637 G4Colour G4OpenGLQtViewer::getColorForPoIndex(
int poIndex) {
  3639   QTreeWidgetItem* item = getTreeWidgetItem(poIndex);
  3643     const QColor& color = item->data(2,Qt::UserRole).value<QColor>();
  3655 const std::vector<G4ModelingParameters::VisAttributesModifier>*
  3656 G4OpenGLQtViewer::GetPrivateVisAttributesModifiers()
 const  3658   static std::vector<G4ModelingParameters::VisAttributesModifier>
  3659   privateVisAttributesModifiers;
  3661   privateVisAttributesModifiers.clear();
  3713   return &privateVisAttributesModifiers;
  3717 void G4OpenGLQtViewer::changeSearchSelection()
  3719   const QString& searchText = fFilterOutput->text();
  3720   if (fSceneTreeComponentTreeWidget == NULL) {
  3725   for (
int a=0; a<fSceneTreeComponentTreeWidget->topLevelItemCount(); a++) {
  3726     fSceneTreeComponentTreeWidget->topLevelItem(a)->setExpanded(
false);
  3727     fSceneTreeComponentTreeWidget->topLevelItem(a)->setSelected(
false);
  3728     clearSceneTreeSelection(fSceneTreeComponentTreeWidget->topLevelItem(a));
  3731   QList<QTreeWidgetItem *> itemList = fSceneTreeComponentTreeWidget->findItems (searchText,Qt::MatchContains | Qt::MatchRecursive,0);
  3733   for (
int i = 0; i < itemList.size(); ++i) {
  3734     QTreeWidgetItem* expandParentItem = itemList.at(i);
  3735     while (expandParentItem->parent() != NULL) {
  3736       expandParentItem->parent()->setExpanded(
true);
  3737       expandParentItem = expandParentItem->parent();
  3739     itemList.at(i)->setSelected(
true);
  3745 void G4OpenGLQtViewer::clearSceneTreeSelection(QTreeWidgetItem* item) {
  3746   for (
int a=0; a<item->childCount(); a++) {
  3747     item->child(a)->setSelected(
false);
  3748     item->child(a)->setExpanded(
false);
  3749     clearSceneTreeSelection(item->child(a));
  3755 bool G4OpenGLQtViewer::isPVVolume(QTreeWidgetItem* item) {
  3756   QTreeWidgetItem* sParent = item;
  3757   while (sParent->parent() != NULL) {
  3758     sParent = sParent->parent();
  3760   if (sParent->text(0) != fTouchableVolumes) {
  3764   if (item->text(0) == fTouchableVolumes) {
  3771 void G4OpenGLQtViewer::changeDepthOnSceneTreeItem(
  3773  ,
double currentDepth
  3774  ,QTreeWidgetItem* item
  3776   double transparencyLevel = 0.;
  3781   if (isPVVolume(item)) {
  3782     if ((lookForDepth-currentDepth) < 0) {
  3783       item->setCheckState(0,Qt::Checked);
  3784       updatePositivePoIndexSceneTreeWidgetQuickMap(item->data(0,Qt::UserRole).toInt(),item);
  3785       transparencyLevel = 1;
  3786     } 
else if ((lookForDepth-currentDepth) > 1 ){
  3787       item->setCheckState(0,Qt::Unchecked);
  3788       updatePositivePoIndexSceneTreeWidgetQuickMap(item->data(0,Qt::UserRole).toInt(),item);
  3789       transparencyLevel = 0;
  3791       item->setCheckState(0,Qt::Checked);
  3792       updatePositivePoIndexSceneTreeWidgetQuickMap(item->data(0,Qt::UserRole).toInt(),item);
  3793       transparencyLevel = 1-(lookForDepth-currentDepth);
  3797   if (item->data(0,Qt::UserRole).toInt() >= 0) {
  3798     const G4Colour& color = getColorForPoIndex(item->data(0,Qt::UserRole).toInt());
  3810     if (((color.
GetAlpha()-transparencyLevel) >  0.000001) ||
  3811         ((color.
GetAlpha()-transparencyLevel) < -0.000001))  {
  3812       if ((item->text(3) != 
"")) {
  3818         changeQColorForTreeWidgetItem(item,QColor((
int)(color.
GetRed()*255),
  3821                                                   (
int)(transparencyLevel*255)));
  3826   for (
int b=0;
b< item->childCount();
b++) {
  3827     changeDepthOnSceneTreeItem(lookForDepth,currentDepth+1,item->child(
b));
  3832 void G4OpenGLQtViewer::clearTreeWidget(){
  3835   if (fSceneTreeComponentTreeWidget) {
  3837     if (fOldSceneTreeComponentTreeWidget == NULL) {
  3838       fOldSceneTreeComponentTreeWidget = 
new QTreeWidget();
  3841     int tmp = fOldSceneTreeComponentTreeWidget->topLevelItemCount();
  3843       delete fOldSceneTreeComponentTreeWidget->takeTopLevelItem (0);
  3844       tmp = fOldSceneTreeComponentTreeWidget->topLevelItemCount();
  3847     if (fSceneTreeComponentTreeWidget->topLevelItemCount () > 0) {
  3849       fPVRootNodeCreate = 
false;
  3852       fOldPositivePoIndexSceneTreeWidgetQuickMap.clear();
  3853       fOldNullPoIndexSceneTreeWidgetQuickVector.clear();
  3854       fOldTreeItemModels.clear();
  3857       for (
int b =0; 
b <fSceneTreeComponentTreeWidget->topLevelItemCount();
b++) {
  3866         int poIndex = fSceneTreeComponentTreeWidget->topLevelItem(
b)->data(0,Qt::UserRole).toInt();
  3867         if (poIndex != -1) {
  3868           fOldPositivePoIndexSceneTreeWidgetQuickMap.insert(std::pair <int, QTreeWidgetItem*> (poIndex,cloneWidgetItem(fSceneTreeComponentTreeWidget->topLevelItem(
b))));
  3870           fOldNullPoIndexSceneTreeWidgetQuickVector.push_back(cloneWidgetItem(fSceneTreeComponentTreeWidget->topLevelItem(
b)));
  3874         cloneSceneTree(fSceneTreeComponentTreeWidget->topLevelItem(
b));
  3878       fOldTreeItemModels.insert(fTreeItemModels.begin(), fTreeItemModels.end());  
  3881       int tmp2 = fSceneTreeComponentTreeWidget->topLevelItemCount();
  3883         delete fSceneTreeComponentTreeWidget->takeTopLevelItem (0);
  3884         tmp2 = fSceneTreeComponentTreeWidget->topLevelItemCount();
  3886       fPositivePoIndexSceneTreeWidgetQuickMap.clear();
  3889       fOldLastSceneTreeWidgetAskForIterator = fOldPositivePoIndexSceneTreeWidgetQuickMap.begin();
  3890       fOldLastSceneTreeWidgetAskForIteratorEnd = fOldPositivePoIndexSceneTreeWidgetQuickMap.end();
  3891       fSceneTreeDepth = 1;
  3892       fModelShortNameItem = NULL;
  3893       fMaxPOindexInserted = -1;
  3906 QTreeWidgetItem * G4OpenGLQtViewer::cloneWidgetItem(QTreeWidgetItem* item) {
  3908   QTreeWidgetItem* cloneItem = 
new QTreeWidgetItem();
  3912   cloneItem->setText(0,item->text(0));
  3913   cloneItem->setData(1,Qt::UserRole,item->data(1,Qt::UserRole).toInt());
  3914   cloneItem->setText(2,item->text(2));
  3915   cloneItem->setData(0, Qt::UserRole,item->data(0,Qt::UserRole).toInt());
  3916   cloneItem->setText(3,item->text(3));
  3917   cloneItem->setFlags(item->flags());
  3918   cloneItem->setToolTip(0,item->toolTip(0));        
  3919   cloneItem->setCheckState(0,item->checkState(0));
  3920   cloneItem->setSelected(item->isSelected()); 
  3921   cloneItem->setExpanded(item->isExpanded ());
  3923   cloneItem->setData(2,Qt::UserRole,item->data(2,Qt::UserRole).value<QColor>());
  3932 void G4OpenGLQtViewer::cloneSceneTree(
  3933  QTreeWidgetItem* rootItem
  3936   for (
int b=0;
b< rootItem->childCount();
b++) {
  3938     QTreeWidgetItem *child = rootItem->child(
b);
  3941     int poIndex = child->data(0,Qt::UserRole).toInt();
  3942     if (poIndex != -1) {
  3943       fOldPositivePoIndexSceneTreeWidgetQuickMap.insert(std::pair <int, QTreeWidgetItem*> (poIndex,cloneWidgetItem(child)));
  3945       fOldNullPoIndexSceneTreeWidgetQuickVector.push_back(cloneWidgetItem(child));
  3947     cloneSceneTree(child);
  3955  void G4OpenGLQtViewer::updatePositivePoIndexSceneTreeWidgetQuickMap(
int POindex,QTreeWidgetItem* item) {
  3958    std::map <int, QTreeWidgetItem*>::iterator i;
  3959    i = fPositivePoIndexSceneTreeWidgetQuickMap.find(POindex);
  3961    if (i == fPositivePoIndexSceneTreeWidgetQuickMap.end()) {
  3962      fPositivePoIndexSceneTreeWidgetQuickMap.insert(std::pair <int, QTreeWidgetItem*> (POindex,item) );
  3963      fLastSceneTreeWidgetAskForIterator = fPositivePoIndexSceneTreeWidgetQuickMap.end();
  3964      fLastSceneTreeWidgetAskForIteratorEnd = fPositivePoIndexSceneTreeWidgetQuickMap.end();
  3972 void G4OpenGLQtViewer::changeQColorForTreeWidgetItem(QTreeWidgetItem* item,
const QColor& qc) {
  3974   int POIndex = item->data(0,Qt::UserRole).toInt();
  3975   updatePositivePoIndexSceneTreeWidgetQuickMap(POIndex,item );
  3977   QPixmap pixmap = QPixmap(QSize(16, 16));
  3978   if (item->data(0,Qt::UserRole).toInt() != -1) {
  3981     pixmap.fill (QColor(255,255,255,255));
  3983   QPainter painter(&pixmap);
  3984   painter.setPen(Qt::black);
  3985   painter.drawRect(0,0,15,15); 
  3987   item->setIcon(0,pixmap);
  3988   item->setData(2,Qt::UserRole,qc);
  3997 QTreeWidgetItem* G4OpenGLQtViewer::getTreeWidgetItem(
int POindex){
  4000   if (POindex == -1) {
  4004   if (fPositivePoIndexSceneTreeWidgetQuickMap.size() == 0){
  4008   if (fLastSceneTreeWidgetAskForIterator != fLastSceneTreeWidgetAskForIteratorEnd) {
  4009     if (POindex == fLastSceneTreeWidgetAskForIterator->first) {
  4010       if (fLastSceneTreeWidgetAskForIterator->second != NULL) {
  4011         return fLastSceneTreeWidgetAskForIterator->second;
  4017   fLastSceneTreeWidgetAskForIterator = fPositivePoIndexSceneTreeWidgetQuickMap.find(POindex);
  4018   fLastSceneTreeWidgetAskForIteratorEnd = fPositivePoIndexSceneTreeWidgetQuickMap.end();
  4020   if (fLastSceneTreeWidgetAskForIterator != fPositivePoIndexSceneTreeWidgetQuickMap.end()) {
  4021     return fLastSceneTreeWidgetAskForIterator->second;
  4030 QTreeWidgetItem* G4OpenGLQtViewer::getOldTreeWidgetItem(
int POindex){
  4034   if (POindex == -1) {
  4038   if (fOldPositivePoIndexSceneTreeWidgetQuickMap.size() == 0){
  4044   if (fOldLastSceneTreeWidgetAskForIterator != fOldLastSceneTreeWidgetAskForIteratorEnd) {
  4045     fOldLastSceneTreeWidgetAskForIterator++;
  4048   if (fOldLastSceneTreeWidgetAskForIterator != fOldPositivePoIndexSceneTreeWidgetQuickMap.end()) {
  4049     if (POindex == fOldLastSceneTreeWidgetAskForIterator->first) {
  4050       if (fOldLastSceneTreeWidgetAskForIterator->second != NULL) {
  4051         return fOldLastSceneTreeWidgetAskForIterator->second;
  4057   fOldLastSceneTreeWidgetAskForIterator = fOldPositivePoIndexSceneTreeWidgetQuickMap.find(POindex);
  4058   fOldLastSceneTreeWidgetAskForIteratorEnd = fOldPositivePoIndexSceneTreeWidgetQuickMap.end();
  4060   if (fOldLastSceneTreeWidgetAskForIterator != fOldPositivePoIndexSceneTreeWidgetQuickMap.end()) {
  4061     return fOldLastSceneTreeWidgetAskForIterator->second;
  4072 void G4OpenGLQtViewer::displaySceneTreeComponent() {
  4074   if (fUISceneTreeComponentsTBWidget == NULL) {
  4077   if (fSceneTreeComponentTreeWidget == NULL) {
  4082   fSceneTreeComponentTreeWidget->sortItems (0, Qt::AscendingOrder );
  4094 void G4OpenGLQtViewer::updateToolbarAndMouseContextMenu(){
  4100   d_style = fVP.GetDrawingStyle();
  4104     if (fUiQt) fUiQt->SetIconWireframeSelected();
  4106       fDrawingWireframe->setChecked(
true);
  4107       fDrawingLineRemoval->setChecked(
false);
  4108       fDrawingSurfaceRemoval->setChecked(
false);
  4109       fDrawingLineSurfaceRemoval->setChecked(
false);
  4112     if (fUiQt) fUiQt->SetIconHLRSelected();
  4114       fDrawingLineRemoval->setChecked(
true);
  4115       fDrawingWireframe->setChecked(
false);
  4116       fDrawingSurfaceRemoval->setChecked(
false);
  4117       fDrawingLineSurfaceRemoval->setChecked(
false);
  4120     if (fUiQt) fUiQt->SetIconSolidSelected();
  4122       fDrawingSurfaceRemoval->setChecked(
true);
  4123       fDrawingWireframe->setChecked(
false);
  4124       fDrawingLineRemoval->setChecked(
false);
  4125       fDrawingLineSurfaceRemoval->setChecked(
false);
  4128     if (fUiQt) fUiQt->SetIconHLHSRSelected();
  4130       fDrawingLineSurfaceRemoval->setChecked(
true);
  4131       fDrawingWireframe->setChecked(
false);
  4132       fDrawingLineRemoval->setChecked(
false);
  4133       fDrawingSurfaceRemoval->setChecked(
false);
  4134       fDrawingLineSurfaceRemoval->setChecked(
false);
  4140   G4double d_proj = fVP.GetFieldHalfAngle () ;
  4142     if (fUiQt) fUiQt->SetIconOrthoSelected();
  4144       fProjectionOrtho->setChecked(
true);
  4145       fProjectionPerspective->setChecked(
false);
  4148     if (fUiQt) fUiQt->SetIconPerspectiveSelected();
  4150         fProjectionPerspective->setChecked(
true);
  4151         fProjectionOrtho->setChecked(
false);
  4157   if (fUiQt && fContextMenu) {
  4158     if (fUiQt->IsIconPickSelected()) {
  4159       fMousePickAction->setChecked(
true);
  4160       fMouseZoomOutAction->setChecked(
false);
  4161       fMouseZoomInAction->setChecked(
false);
  4162       fMouseRotateAction->setChecked(
false);
  4163       fMouseMoveAction->setChecked(
false);
  4164     } 
else if (fUiQt->IsIconZoomOutSelected()) {
  4165       fMouseZoomOutAction->setChecked(
true);
  4166       fMousePickAction->setChecked(
false);
  4167       fMouseZoomInAction->setChecked(
false);
  4168       fMouseRotateAction->setChecked(
false);
  4169       fMouseMoveAction->setChecked(
false);
  4170     } 
else if (fUiQt->IsIconZoomInSelected()) {
  4171       fMouseZoomInAction->setChecked(
true);
  4172       fMousePickAction->setChecked(
false);
  4173       fMouseZoomOutAction->setChecked(
false);
  4174       fMouseRotateAction->setChecked(
false);
  4175       fMouseMoveAction->setChecked(
false);
  4176     } 
else if (fUiQt->IsIconRotateSelected()) {
  4177       fMouseRotateAction->setChecked(
true);
  4178       fMousePickAction->setChecked(
false);
  4179       fMouseZoomOutAction->setChecked(
false);
  4180       fMouseZoomInAction->setChecked(
false);
  4181       fMouseMoveAction->setChecked(
false);
  4182     } 
else if (fUiQt->IsIconMoveSelected()) {
  4183       fMouseMoveAction->setChecked(
true);
  4184       fMousePickAction->setChecked(
false);
  4185       fMouseZoomOutAction->setChecked(
false);
  4186       fMouseZoomInAction->setChecked(
false);
  4187       fMouseRotateAction->setChecked(
false);
  4196 void G4OpenGLQtViewer::updateSceneTreeComponentTreeWidgetInfos() {
  4198   if (!fSceneTreeComponentTreeWidgetInfos) {
  4201   int treeWidgetInfosIgnoredCommands = 0;
  4211   if ((path->
GetCommandEntry()-fTreeWidgetInfosIgnoredCommands) != fSceneTreeComponentTreeWidgetInfos->rowCount()) {
  4212     fSceneTreeComponentTreeWidgetInfos->clear();
  4215   fSceneTreeComponentTreeWidgetInfos->blockSignals(
true);
  4218   fSceneTreeComponentTreeWidgetInfos->setColumnCount (2);
  4219   fSceneTreeComponentTreeWidgetInfos->setRowCount (path->
GetCommandEntry()-fTreeWidgetInfosIgnoredCommands);
  4220   fSceneTreeComponentTreeWidgetInfos->setHorizontalHeaderLabels(QStringList() << tr(
"Property")
  4222   fSceneTreeComponentTreeWidgetInfos->verticalHeader()->setVisible(
false);
  4223   fSceneTreeComponentTreeWidgetInfos->setAlternatingRowColors (
true);
  4231     QString params = 
"";
  4234       if (fVP.IsAutoRefresh()) {
  4240       if (fVP.IsAuxEdgeVisible()) {
  4246       params = QString().number(fVP.GetBackgroundColour().GetRed()) + 
"  "+
  4247       QString().number(fVP.GetBackgroundColour().GetGreen()) + 
"  "+
  4248       QString().number(fVP.GetBackgroundColour().GetBlue()) + 
"  "+
  4249       QString().number(fVP.GetBackgroundColour().GetAlpha());
  4252       params = QString().number(fVP. IsCulling ());
  4257         params = 
"intersection";
  4261       params = QString().number(fVP.GetDefaultVisAttributes()->GetColor().GetRed()) + 
"  "+
  4262       QString().number(fVP.GetDefaultVisAttributes()->GetColor().GetGreen()) + 
"  "+
  4263       QString().number(fVP.GetDefaultVisAttributes()->GetColor().GetBlue()) + 
"  "+
  4264       QString().number(fVP.GetDefaultVisAttributes()->GetColor().GetAlpha());
  4267       params = QString().number(fVP.GetDefaultTextVisAttributes()->GetColor().GetRed()) + 
"  "+
  4268       QString().number(fVP.GetDefaultTextVisAttributes()->GetColor().GetGreen()) + 
"  "+
  4269       QString().number(fVP.GetDefaultTextVisAttributes()->GetColor().GetBlue()) + 
"  "+
  4270       QString().number(fVP.GetDefaultTextVisAttributes()->GetColor().GetAlpha());
  4280       params = QString().number(fVP.GetExplodeFactor()) +  
"  " + QString(
G4String(
G4BestUnit(fVP.GetExplodeFactor(),
"Length")).
data());
  4282     } 
else if(commandTmp->
GetCommandName() == 
"globalLineWidthScale") {
  4283       params = QString().number(fVP.GetGlobalLineWidthScale());
  4286       params = QString().number(fVP.GetGlobalMarkerScale());
  4298       if (fVP.IsMarkerNotHidden()) {
  4305       if (fVP.GetLightsMoveWithCamera()) {
  4311       G4Vector3D direction = fVP.GetLightpointDirection();
  4320      params = QString().number(fVP.GetLightpointDirection().x()) + 
"  "+
  4321       QString().number(fVP.GetLightpointDirection().y()) + 
"  "+
  4322       QString().number(fVP.GetLightpointDirection().z());
  4324     } 
else if(commandTmp->
GetCommandName() == 
"lineSegmentsPerCircle") {
  4325       params = QString().number(fVP.GetNoOfSides());
  4328       if (fVP.IsPicking()) {
  4335       if (fVP.GetFieldHalfAngle() == 0.) {
  4336         params = 
"orthogonal";
  4338         params = QString(
"perspective ") + QString().number(fVP.GetFieldHalfAngle()/
CLHEP::degree) + 
" deg";
  4343         params = 
"constrainUpDirection";
  4345         params = 
"freeRotation";
  4349       if (fVP.IsSection()) {
  4350         params =  QString(
"on ") +
  4352         QString().number(fVP.GetSectionPlane().normal().x())
  4353         + 
" " + QString().number(fVP.GetSectionPlane().normal().y())
  4354         + 
" " + QString().number(fVP.GetSectionPlane().normal().z());
  4361          params = 
"wireframe";
  4368       G4Point3D point = fVP.GetCurrentTargetPoint();
  4369       if (fSceneHandler.GetScene()) {
  4370         G4String b = 
G4BestUnit(fSceneHandler.GetScene()->GetStandardTargetPoint() + fVP.GetCurrentTargetPoint(),
"Length");
  4384       params = QString().number(up.
x())+ 
"  "+ QString().number(up.
y())+
"  "+QString().number(up.
z())+ 
"  ";
  4387       G4Vector3D direction = fVP.GetViewpointDirection();
  4396       G4Vector3D direction = fVP.GetViewpointDirection();
  4397       params = QString().number(direction.
x())+ 
"  "+ QString().number(direction.
y())+
" "+QString().number(direction.
z());
  4427       QTableWidgetItem *nameItem;
  4428       QTableWidgetItem *paramItem;
  4431       QList<QTableWidgetItem *> list = fSceneTreeComponentTreeWidgetInfos->findItems (commandTmp->
GetCommandName().
data(),Qt::MatchExactly);
  4432       if (list.size() == 1) {
  4433         nameItem = list.first();
  4434         paramItem = fSceneTreeComponentTreeWidgetInfos->item(nameItem->row(),1);
  4437         nameItem = 
new QTableWidgetItem();
  4438         paramItem = 
new QTableWidgetItem();
  4439         fSceneTreeComponentTreeWidgetInfos->setItem(a-treeWidgetInfosIgnoredCommands, 0, nameItem);
  4440         fSceneTreeComponentTreeWidgetInfos->setItem(a-treeWidgetInfosIgnoredCommands, 1, paramItem);
  4445         for( 
G4int i_thGuidance=0; i_thGuidance < n_guidanceEntry; i_thGuidance++ ) {
  4446           guidance += QString((
char*)(commandTmp->
GetGuidanceLine(i_thGuidance)).data()) + 
"\n";
  4449         nameItem->setToolTip(guidance);
  4450         paramItem->setToolTip(GetCommandParameterList(commandTmp));
  4452         fSceneTreeComponentTreeWidgetInfos->setRowHeight(a-treeWidgetInfosIgnoredCommands,15);
  4457       paramItem->setText(params);
  4459       nameItem->setFlags(Qt::NoItemFlags);
  4460       nameItem->setForeground(QBrush());
  4463       treeWidgetInfosIgnoredCommands++;
  4467   for (
int i=0; i<treeWidgetInfosIgnoredCommands; i++) {
  4468     fSceneTreeComponentTreeWidgetInfos->removeRow (fSceneTreeComponentTreeWidgetInfos->rowCount() - 1);
  4471   fSceneTreeComponentTreeWidgetInfos->resizeColumnToContents(0);
  4472   fSceneTreeComponentTreeWidgetInfos->horizontalHeader()->setStretchLastSection(
true);
  4473   fSceneTreeComponentTreeWidgetInfos->blockSignals(
false);
  4475   fTreeWidgetInfosIgnoredCommands = treeWidgetInfosIgnoredCommands;
  4480 void G4OpenGLQtViewer::toggleSceneTreeViewerInfos() {
  4481   if (! fSceneTreeViewerButton) {
  4484   fSceneTreeViewerInfos->setVisible(!fSceneTreeViewerInfos->isVisible());
  4485   if (fSceneTreeViewerInfos->isVisible()) {
  4486     fSceneTreeViewerButton->setIcon(*fTreeIconOpen);
  4488     fSceneTreeViewerButton->setIcon(*fTreeIconClosed);
  4493 void G4OpenGLQtViewer::toggleSceneTreeComponentTreeWidgetInfos() {
  4494   fSceneTreeComponentTreeWidgetInfos->setVisible(!fSceneTreeComponentTreeWidgetInfos->isVisible());
  4495   if (fSceneTreeComponentTreeWidgetInfos->isVisible()) {
  4496     fViewerPropertiesButton->setIcon(*fTreeIconOpen);
  4498     fViewerPropertiesButton->setIcon(*fTreeIconClosed);
  4503 void G4OpenGLQtViewer::toggleSceneTreeComponentPickingInfos() {
  4504   fSceneTreeComponentPickingScrollArea->setVisible(!fSceneTreeComponentPickingScrollArea->isVisible());
  4505   if (fViewerPickingButton->isVisible()) {
  4506     fViewerPickingButton->setIcon(*fTreeIconOpen);
  4508     fViewerPickingButton->setIcon(*fTreeIconClosed);
  4513 void G4OpenGLQtViewer::toggleSceneTreeComponentPickingCout(
int pickItem) {
  4518   for (
int a=0; a<fSceneTreeComponentPickingInfos->layout()->count(); a++) {
  4519     w = fSceneTreeComponentPickingInfos->layout()->itemAt(a)->widget();
  4520     QTextEdit* ed = 
dynamic_cast<QTextEdit*
>(
w);
  4521     QPushButton* button;
  4523       if (a == pickItem) {
  4524         w->setVisible(!w->isVisible());
  4526         w->setVisible(
false);
  4529         button = 
dynamic_cast<QPushButton*
>(fSceneTreeComponentPickingInfos->layout()->itemAt(a-1)->widget());
  4531           if (button->isVisible()) {
  4532             button->setIcon(*fTreeIconOpen);
  4534             button->setIcon(*fTreeIconClosed);
  4543 void G4OpenGLQtViewer::tableWidgetViewerSetItemChanged(QTableWidgetItem * item) {
  4546     QTableWidgetItem* previous = fSceneTreeComponentTreeWidgetInfos->item(fSceneTreeComponentTreeWidgetInfos->row(item),0);
  4548       fSceneTreeComponentTreeWidgetInfos->blockSignals(
true);
  4550                         + previous->text().toStdString()
  4552                         + item->text().toStdString()).c_str());
  4553       fSceneTreeComponentTreeWidgetInfos->blockSignals(
false);
  4566 QString G4OpenGLQtViewer::GetCommandParameterList (
  4573   if( n_parameterEntry > 0 ) {
  4578     for( 
G4int i_thParameter=0; i_thParameter<n_parameterEntry; i_thParameter++ ) {
  4580       txt += 
"\nParameter : " + QString((
char*)(param->
GetParameterName()).data()) + 
"\n";
  4583       txt += 
" Parameter type  : " + QString(QChar(param->
GetParameterType())) + 
"\n";
  4585         txt += 
" Omittable       : True\n";
  4587         txt += 
" Omittable       : False\n";
  4590         txt += 
" Default value   : taken from the current value\n";
  4592         txt += 
" Default value   : " + QString((
char*)(param->
GetDefaultValue()).data())+ 
"\n";
  4595         txt += 
" Parameter range : " + QString((
char*)(param->
GetParameterRange()).data())+ 
"\n";
  4605 #ifdef G4MULTITHREADED  4607 void G4OpenGLQtViewer::DoneWithMasterThread()
  4612   G4MUTEXLOCK(&mWaitForVisSubThreadQtOpenGLContextInitialized);
  4615 void G4OpenGLQtViewer::SwitchToVisSubThread()
  4619   QGLWidget* qGLW = 
dynamic_cast<QGLWidget*
> (fGLWidget) ;
  4625   SetQGLContextVisSubThread(QThread::currentThread());
  4631   G4CONDITIONWAIT(&c2_VisSubThreadQtOpenGLContextMoved, &mWaitForVisSubThreadQtOpenGLContextMoved);
  4634   qGLW->makeCurrent();
  4637 void G4OpenGLQtViewer::DoneWithVisSubThread()
  4640   QGLWidget* qGLW = 
dynamic_cast<QGLWidget*
> (fGLWidget) ;
  4646   qGLW->doneCurrent();
  4648 #if QT_VERSION > 0x050000  4650   qGLW->context()->moveToThread(fQGLContextMainThread);
  4654 void G4OpenGLQtViewer::SwitchToMasterThread()
  4658   QGLWidget* qGLW = 
dynamic_cast<QGLWidget*
> (fGLWidget) ;
  4664   G4MUTEXUNLOCK(&mWaitForVisSubThreadQtOpenGLContextInitialized);
  4665   qGLW->makeCurrent();
  4669 void G4OpenGLQtViewer::MovingToVisSubThread(){
  4672   QGLWidget* qGLW = 
dynamic_cast<QGLWidget*
> (fGLWidget) ;
  4678   G4CONDITIONWAIT( &c1_VisSubThreadQtOpenGLContextInitialized, &mWaitForVisSubThreadQtOpenGLContextInitialized);
  4682   SetQGLContextMainThread(QThread::currentThread());
  4685   qGLW->doneCurrent();
  4686 #if QT_VERSION > 0x050000  4687   qGLW->context()->moveToThread(fQGLContextVisSubThread);
 
G4int GetGuidanceEntries() const
 
G4String GetDefaultValue() const
 
G4UIcommandTree * FindCommandTree(const char *commandPath)
 
void SetColour(const G4Colour &)
 
const G4String & GetCommandName() const
 
G4String GetParameterRange() const
 
const char * data() const
 
G4bool GetCurrentAsDefault() const
 
#define G4CONDTIONBROADCAST(cond)
 
G4Point3D GetPosition() const
 
G4UIcommand * GetCommand(G4int i)
 
G4double GetAlpha() const
 
const G4String GetParameterGuidance() const
 
const G4String & GetGuidanceLine(G4int i) const
 
static G4bool GetColour(const G4String &key, G4Colour &result)
 
G4bool IsOmittable() const
 
char GetParameterType() const
 
G4double GetXOffset() const
 
G4UIparameter * GetParameter(G4int i) const
 
const G4Transform3D & GetTransformation() const
 
#define G4BestUnit(a, b)
#define G4_USE_G4BESTUNIT_FOR_VERBOSE 1 
 
G4double GetGreen() const
 
#define G4CONDITIONWAIT(cond, mutex)
 
static const double degree
 
#define G4MUTEX_INITIALIZER
 
G4int GetCommandEntry() const
 
static G4UImanager * GetUIpointer()
 
const std::vector< G4PhysicalVolumeNodeID > & GetFullPVPath() const
 
G4GLOB_DLL std::ostream G4cout
 
G4double GetYOffset() const
 
G4String GetParameterName() const
 
std::vector< PVNodeID > PVPath
 
G4UIcommandTree * GetTree() const
 
void print(G4double elem)
 
G4String GetParameterCandidates() const
 
static const G4double factor
 
const G4String & GetName() const
 
G4int GetParameterEntries() const
 
static MCTruthManager * instance
 
static PROLOG_HANDLER error
 
static const G4double alpha
 
G4int ApplyCommand(const char *aCommand)
 
std::vector< G4PolyconeSideRZ > g4c
 
G4GLOB_DLL std::ostream G4cerr
 
#define G4CONDITION_INITIALIZER
 
const G4Colour & GetColour() const