Geant4 Cross Reference

Cross-Referencing   Geant4
Geant4/visualization/OpenGL/src/G4OpenGLQtViewer.cc

Version: [ ReleaseNotes ] [ 1.0 ] [ 1.1 ] [ 2.0 ] [ 3.0 ] [ 3.1 ] [ 3.2 ] [ 4.0 ] [ 4.0.p1 ] [ 4.0.p2 ] [ 4.1 ] [ 4.1.p1 ] [ 5.0 ] [ 5.0.p1 ] [ 5.1 ] [ 5.1.p1 ] [ 5.2 ] [ 5.2.p1 ] [ 5.2.p2 ] [ 6.0 ] [ 6.0.p1 ] [ 6.1 ] [ 6.2 ] [ 6.2.p1 ] [ 6.2.p2 ] [ 7.0 ] [ 7.0.p1 ] [ 7.1 ] [ 7.1.p1 ] [ 8.0 ] [ 8.0.p1 ] [ 8.1 ] [ 8.1.p1 ] [ 8.1.p2 ] [ 8.2 ] [ 8.2.p1 ] [ 8.3 ] [ 8.3.p1 ] [ 8.3.p2 ] [ 9.0 ] [ 9.0.p1 ] [ 9.0.p2 ] [ 9.1 ] [ 9.1.p1 ] [ 9.1.p2 ] [ 9.1.p3 ] [ 9.2 ] [ 9.2.p1 ] [ 9.2.p2 ] [ 9.2.p3 ] [ 9.2.p4 ] [ 9.3 ] [ 9.3.p1 ] [ 9.3.p2 ] [ 9.4 ] [ 9.4.p1 ] [ 9.4.p2 ] [ 9.4.p3 ] [ 9.4.p4 ] [ 9.5 ] [ 9.5.p1 ] [ 9.5.p2 ] [ 9.6 ] [ 9.6.p1 ] [ 9.6.p2 ] [ 9.6.p3 ] [ 9.6.p4 ] [ 10.0 ] [ 10.0.p1 ] [ 10.0.p2 ] [ 10.0.p3 ] [ 10.0.p4 ] [ 10.1 ] [ 10.1.p1 ] [ 10.1.p2 ] [ 10.1.p3 ] [ 10.2 ] [ 10.2.p1 ] [ 10.2.p2 ] [ 10.2.p3 ] [ 10.3 ] [ 10.3.p1 ] [ 10.3.p2 ] [ 10.3.p3 ] [ 10.4 ] [ 10.4.p1 ] [ 10.4.p2 ] [ 10.4.p3 ] [ 10.5 ] [ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

Diff markup

Differences between /visualization/OpenGL/src/G4OpenGLQtViewer.cc (Version 11.3.0) and /visualization/OpenGL/src/G4OpenGLQtViewer.cc (Version 10.7.p3)


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