58#include <qpushbutton.h>
60#include <qdesktopwidget.h>
63#include <qimagewriter.h>
66#include <qtreewidget.h>
67#include <qapplication.h>
68#include <qmessagebox.h>
69#include <qfiledialog.h>
72#if QT_VERSION >= 0x050e00
73 #include <qelapsedtimer.h>
78#include <qcolordialog.h>
84#if QT_VERSION < 0x050600
85#include <qsignalmapper.h>
89#include <qmainwindow.h>
90#include <qtablewidget.h>
91#include <qheaderview.h>
92#include <qscrollarea.h>
99#include "moc_G4OpenGLQtViewer.cpp"
107#ifdef G4MULTITHREADED
141 if (UI == NULL)
return;
150 bool isTabbedView =
false;
160 SIGNAL(currentChanged(
int)),
162 SLOT(currentTabActivated(
int)));
166 createSceneTreeWidget();
173 QWidget *glDialogWidget = getParentWidget();
174 if (glDialogWidget == NULL) {
177 glWidget->setParent(glDialogWidget);
178 QHBoxLayout *mainLayout =
new QHBoxLayout();
180 mainLayout->setMargin(0);
181 mainLayout->setSpacing(0);
183 if (
fGLWidget->inherits(
"QMainWindow")) {
186 glDialogWidget->setLayout(mainLayout);
190#if QT_VERSION >= 0x050a00
191 G4int offset = QApplication::desktop()->height()
192 - QGuiApplication::screenAt(QPoint(20,20))->availableGeometry().height();
194 G4int offset = QApplication::desktop()->height()
195 - QApplication::desktop()->availableGeometry().height();
204 glDialogWidget->show();
222 ,fRecordFrameNumber(0)
223 ,fMouseOnSceneTree(false)
225 ,fLastPickPoint(-1,-1)
228 ,fHoldKeyEvent(false)
229 ,fHoldMoveEvent(false)
230 ,fHoldRotateEvent(false)
234 ,fMovieTempFolderPath(
"")
236 ,fParameterFileName(
"ppmtompeg_encode_parameter_file.par")
237 ,fMovieParametersDialog(NULL)
238 ,fRecordingStep(WAIT)
240 ,fNbMaxFramesPerSec(100)
241 ,fNbMaxAnglePerSec(360)
242 ,fLaunchSpinDelay(100)
243 ,fUISceneTreeWidget(NULL)
244 ,fUIViewerPropertiesWidget(NULL)
245 ,fUIPickInfosWidget(NULL)
248 ,fControlKeyPress(false)
249 ,fShiftKeyPress(false)
251 ,fCheckSceneTreeComponentSignalLock(false)
252 ,fViewerPropertiesTableWidgetIsInit(false)
253 ,fSceneTreeComponentTreeWidget(NULL)
254 ,fSceneTreeWidget(NULL)
255 ,fPVRootNodeCreate(false)
259 ,fTouchableVolumes(
"Touchables")
260 ,fShortcutsDialog(NULL)
261 ,fViewerPropertiesTableWidget(NULL)
262 ,fPickInfosWidget(NULL)
263 ,fPickInfosScrollArea(NULL)
264 ,fTreeWidgetInfosIgnoredCommands(0)
265 ,fSceneTreeDepthSlider(NULL)
267 ,fModelShortNameItem(NULL)
268 ,fMaxPOindexInserted(-1)
270#if QT_VERSION < 0x050600
271 ,fSignalMapperMouse(NULL)
272 ,fSignalMapperSurface(NULL)
273 ,fSignalMapperPicking(NULL)
276 ,fTreeIconClosed(NULL)
277 ,fLastExportSliderValue(80)
278 ,fLastHighlightColor(
G4Color(0,0,0,0))
279 ,fLastHighlightName(0)
282 lWaitForVisSubThreadQtOpenGLContextInitialized
283 =
new G4AutoLock(mWaitForVisSubThreadQtOpenGLContextInitialized,
285 lWaitForVisSubThreadQtOpenGLContextMoved
286 =
new G4AutoLock(mWaitForVisSubThreadQtOpenGLContextMoved,
290 if (QCoreApplication::instance () == NULL) {
295 fLastPos3 = QPoint(-1,-1);
296 fLastPos2 = QPoint(-1,-1);
297 fLastPos1 = QPoint(-1,-1);
299 initMovieParameters();
301#if QT_VERSION < 0x050e00
302 fLastEventTime =
new QTime();
304 fLastEventTime =
new QElapsedTimer();
306#if QT_VERSION < 0x050600
307 fSignalMapperMouse =
new QSignalMapper(
this);
308 fSignalMapperSurface =
new QSignalMapper(
this);
311 fFileSavePath = QDir::currentPath();
314 QList<QByteArray> formats = QImageWriter::supportedImageFormats ();
315 for (
int i = 0; i < formats.size(); ++i) {
319 const char *
const icon1[]={
377 const char *
const icon2[]={
470 const char *
const search[] = {
482 "OOOOOOOOOOOOOOOOOOO",
483 "OOOOOOOOOOOOOOOOOOO",
484 "OOOOOOOo. .oOOOOOO",
487 "OOOOO. XOOOOX .OOOO",
490 "OOOOO. XOOOOo .OOOO",
494 "OOOOOOOOOOOOO. XOO",
495 "OOOOOOOOOOOOOO. XOO",
496 "OOOOOOOOOOOOOOOoOOO",
497 "OOOOOOOOOOOOOOOOOOO",
498 "OOOOOOOOOOOOOOOOOOO",
499 "OOOOOOOOOOOOOOOOOOO",
500 "OOOOOOOOOOOOOOOOOOO"
503 fSearchIcon =
new QPixmap(search);
504 fTreeIconOpen =
new QPixmap(icon1);
505 fTreeIconClosed =
new QPixmap(icon2);
520 if (fSceneTreeWidget != NULL) {
521 if (fSceneTreeWidget->layout() != NULL) {
522 while ((wItem = fSceneTreeWidget->layout()->takeAt(0)) != 0) {
523 delete wItem->widget();
530 delete fTreeIconOpen;
531 delete fTreeIconClosed;
533 G4cout <<removeTempFolder().toStdString().c_str() <<
G4endl;
535 delete lWaitForVisSubThreadQtOpenGLContextInitialized;
536 delete lWaitForVisSubThreadQtOpenGLContextMoved;
544void G4OpenGLQtViewer::createPopupMenu() {
546 fContextMenu =
new QMenu(
"All");
548 QMenu *mMouseAction = fContextMenu->addMenu(
"&Mouse actions");
550#if QT_VERSION < 0x050600
551 fMouseRotateAction = mMouseAction->addAction(
"Rotate", fSignalMapperMouse, SLOT(map()));
552 fMouseMoveAction = mMouseAction->addAction(
"Move", fSignalMapperMouse, SLOT(map()));
553 fMousePickAction = mMouseAction->addAction(
"Pick", fSignalMapperMouse, SLOT(map()));
554 fMouseZoomOutAction = mMouseAction->addAction(
"Zoom out", fSignalMapperMouse, SLOT(map()));
555 fMouseZoomInAction = mMouseAction->addAction(
"Zoom in", fSignalMapperMouse, SLOT(map()));
557 fMouseRotateAction = mMouseAction->addAction(
"Rotate",
this, [
this](){ this->toggleMouseAction(1); });
558 fMouseMoveAction = mMouseAction->addAction(
"Move",
this, [
this](){ this->toggleMouseAction(2); });
559 fMousePickAction = mMouseAction->addAction(
"Pick",
this, [
this](){ this->toggleMouseAction(3); });
560 fMouseZoomOutAction = mMouseAction->addAction(
"Zoom out",
this, [
this](){ this->toggleMouseAction(4); });
561 fMouseZoomInAction = mMouseAction->addAction(
"Zoom in",
this, [
this](){ this->toggleMouseAction(5); });
563 QAction *shortcutsAction = mMouseAction->addAction(
"Show shortcuts");
565 fMouseRotateAction->setCheckable(
true);
566 fMouseMoveAction->setCheckable(
true);
567 fMousePickAction->setCheckable(
true);
568 fMouseZoomOutAction->setCheckable(
true);
569 fMouseZoomInAction->setCheckable(
true);
570 shortcutsAction->setCheckable(
false);
572#if QT_VERSION < 0x050600
573 connect(fSignalMapperMouse, SIGNAL(mapped(
int)),
this, SLOT(toggleMouseAction(
int)));
574 fSignalMapperMouse->setMapping(fMouseRotateAction,1);
575 fSignalMapperMouse->setMapping(fMouseMoveAction,2);
576 fSignalMapperMouse->setMapping(fMousePickAction,3);
577 fSignalMapperMouse->setMapping(fMouseZoomOutAction,4);
578 fSignalMapperMouse->setMapping(fMouseZoomInAction,5);
581 QObject::connect(shortcutsAction,
582 SIGNAL(triggered(
bool)),
584 SLOT(showShortcuts()));
587 QMenu *mStyle = fContextMenu->addMenu(
"&Style");
589 QMenu *mProjection = mStyle->addMenu(
"&Projection");
591#if QT_VERSION < 0x050600
592 fProjectionOrtho = mProjection->addAction(
"Orthographic", fSignalMapperSurface, SLOT(map()));
593 fProjectionPerspective = mProjection->addAction(
"Perspective", fSignalMapperSurface, SLOT(map()));
597 createRadioAction(fProjectionOrtho, fProjectionPerspective,SLOT(toggleProjection(
bool)),1);
599 createRadioAction(fProjectionOrtho, fProjectionPerspective,SLOT(toggleProjection(
bool)),2);
603 fProjectionOrtho = mProjection->addAction(
"Orthographic",
this, [
this](){ this->toggleProjection(
true); });
604 fProjectionPerspective = mProjection->addAction(
"Perspective",
this, [
this](){ this->toggleProjection(
false); });
607 QMenu *mDrawing = mStyle->addMenu(
"&Drawing");
609#if QT_VERSION < 0x050600
610 fDrawingWireframe = mDrawing->addAction(
"Wireframe", fSignalMapperSurface, SLOT(map()));
612 fDrawingLineRemoval = mDrawing->addAction(
"Hidden line removal", fSignalMapperSurface, SLOT(map()));
614 fDrawingSurfaceRemoval = mDrawing->addAction(
"Hidden Surface removal", fSignalMapperSurface, SLOT(map()));
616 fDrawingLineSurfaceRemoval = mDrawing->addAction(
"Hidden line and surface removal", fSignalMapperSurface, SLOT(map()));
619#if QT_VERSION < 0x050600
620 connect(fSignalMapperSurface, SIGNAL(mapped(
int)),
this, SLOT(toggleSurfaceAction(
int)));
621 fSignalMapperSurface->setMapping(fDrawingWireframe,1);
622 fSignalMapperSurface->setMapping(fDrawingLineRemoval,2);
623 fSignalMapperSurface->setMapping(fDrawingSurfaceRemoval,3);
624 fSignalMapperSurface->setMapping(fDrawingLineSurfaceRemoval,4);
626 fDrawingWireframe = mDrawing->addAction(
"Wireframe",
this, [
this](){ this->toggleSurfaceAction(1); });
627 fDrawingLineRemoval = mDrawing->addAction(
"Hidden line removal",
this, [
this](){ this->toggleSurfaceAction(2); });
628 fDrawingSurfaceRemoval = mDrawing->addAction(
"Hidden Surface removal",
this, [
this](){ this->toggleSurfaceAction(3); });
629 fDrawingLineSurfaceRemoval = mDrawing->addAction(
"Hidden line and surface removal",
this, [
this](){ this->toggleSurfaceAction(4); });
632 fDrawingWireframe->setCheckable(
true);
633 fDrawingLineRemoval->setCheckable(
true);
634 fDrawingSurfaceRemoval->setCheckable(
true);
635 fDrawingLineSurfaceRemoval->setCheckable(
true);
639 QAction *backgroundColorChooser ;
641 backgroundColorChooser = mStyle->addAction(
"Background color");
642 QObject ::connect(backgroundColorChooser,
645 SLOT(actionChangeBackgroundColor()));
649 QAction *textColorChooser ;
651 textColorChooser = mStyle->addAction(
"Text color");
652 QObject ::connect(textColorChooser,
655 SLOT(actionChangeTextColor()));
659 QAction *defaultColorChooser ;
661 defaultColorChooser = mStyle->addAction(
"Default color");
662 QObject ::connect(defaultColorChooser,
665 SLOT(actionChangeDefaultColor()));
669 QMenu *mActions = fContextMenu->addMenu(
"&Actions");
670 QAction *createEPS = mActions->addAction(
"Save as ...");
671 QObject ::connect(createEPS,
674 SLOT(actionSaveImage()));
677 QAction *movieParameters = mActions->addAction(
"Save as movie...");
678 QObject ::connect(movieParameters,
681 SLOT(actionMovieParameters()));
687 QMenu *mSpecial = fContextMenu->addMenu(
"S&pecial");
688 QMenu *mTransparency = mSpecial->addMenu(
"Transparency");
689 QAction *transparencyOn = mTransparency->addAction(
"On");
690 QAction *transparencyOff = mTransparency->addAction(
"Off");
693 createRadioAction(transparencyOn,transparencyOff,SLOT(toggleTransparency(
bool)),2);
695 createRadioAction(transparencyOn,transparencyOff,SLOT(toggleTransparency(
bool)),1);
701 QMenu *mAntialiasing = mSpecial->addMenu(
"Antialiasing");
702 QAction *antialiasingOn = mAntialiasing->addAction(
"On");
703 QAction *antialiasingOff = mAntialiasing->addAction(
"Off");
706 createRadioAction(antialiasingOn,antialiasingOff,SLOT(toggleAntialiasing(
bool)),2);
708 createRadioAction(antialiasingOn,antialiasingOff,SLOT(toggleAntialiasing(
bool)),1);
710 mAntialiasing->clear();
713 QMenu *mHaloing = mSpecial->addMenu(
"Haloing");
714 QAction *haloingOn = mHaloing->addAction(
"On");
715 QAction *haloingOff = mHaloing->addAction(
"Off");
717 createRadioAction(haloingOn,haloingOff,SLOT(toggleHaloing(
bool)),2);
719 createRadioAction(haloingOn,haloingOff,SLOT(toggleHaloing(
bool)),1);
724 QMenu *mAux = mSpecial->addMenu(
"Auxiliary edges");
725 QAction *auxOn = mAux->addAction(
"On");
726 QAction *auxOff = mAux->addAction(
"Off");
728 createRadioAction(auxOn,auxOff,SLOT(toggleAux(
bool)),2);
730 createRadioAction(auxOn,auxOff,SLOT(toggleAux(
bool)),1);
734 QMenu *mHiddenMarkers = mSpecial->addMenu(
"Hidden markers");
735 QAction *hiddenMarkersOn = mHiddenMarkers->addAction(
"On");
736 QAction *hiddenMarkersOff = mHiddenMarkers->addAction(
"Off");
738 createRadioAction(hiddenMarkersOn,hiddenMarkersOff,SLOT(toggleHiddenMarkers(
bool)),2);
740 createRadioAction(hiddenMarkersOn,hiddenMarkersOff,SLOT(toggleHiddenMarkers(
bool)),1);
745 QMenu *mFullScreen = mSpecial->addMenu(
"&Full screen");
746 fFullScreenOn = mFullScreen->addAction(
"On");
747 fFullScreenOff = mFullScreen->addAction(
"Off");
748 createRadioAction(fFullScreenOn,fFullScreenOff,SLOT(toggleFullScreen(
bool)),2);
757 G4cerr <<
"Visualization window not defined, please choose one before" <<
G4endl;
764 if ( fContextMenu ) {
765 fContextMenu->exec( e->globalPos() );
781void G4OpenGLQtViewer::createRadioAction(QAction *action1,QAction *action2,
const std::string& method,
unsigned int nCheck) {
783 action1->setCheckable(
true);
784 action2->setCheckable(
true);
787 action1->setChecked (
true);
789 action2->setChecked (
true);
791 QObject ::connect(action1, SIGNAL(triggered(
bool)),action2, SLOT(toggle()));
792 QObject ::connect(action2, SIGNAL(triggered(
bool)),action1, SLOT(toggle()));
794 QObject ::connect(action1, SIGNAL(toggled(
bool)),
this, method.c_str());
803void G4OpenGLQtViewer::showShortcuts() {
806 text =
"========= Mouse Shortcuts =========\n";
809 text +=
"Click and move mouse to rotate volume \n";
810 text +=
"ALT + Click and move mouse to rotate volume (Toggle View/Theta-Phi Direction) \n";
811 text +=
"CTRL + Click and move mouse to zoom in/out \n";
812 text +=
"SHIFT + Click and move mouse to change camera point of view \n";
814 text +=
"Move camera point of view with mouse \n";
816 text +=
"Click and pick \n";
819 text +=
"Click and move mouse to rotate volume \n";
820 text +=
"ALT + Click and move mouse to rotate volume (Toggle View/Theta-Phi Direction) \n";
821 text +=
"CTRL + Click and zoom mouse to zoom in/out \n";
822 text +=
"SHIFT + Click and zoommove camera point of view \n";
824 text +=
"========= Move Shortcuts ========= \n";
825 text +=
"Press left/right arrows to move volume left/right \n";
826 text +=
"Press up/down arrows to move volume up/down \n";
827 text +=
"Press '+'/'-' to move volume toward/forward \n";
829 text +=
"========= Rotation (Theta/Phi) Shortcuts ========= \n";
830 text +=
"Press SHIFT + left/right arrows to rotate volume left/right \n";
831 text +=
"Press SHIFT + up/down arrows to rotate volume up/down \n";
833 text +=
"========= Rotation (View Direction) Shortcuts ========= \n";
834 text +=
"Press ALT + left/right to rotate volume around vertical direction \n";
835 text +=
"Press ALT + up/down to rotate volume around horizontal direction \n";
837 text +=
"========= Zoom View ========= \n";
838 text +=
"Press CTRL + '+'/'-' to zoom into volume \n";
840 text +=
"========= Misc ========= \n";
841 text +=
"Press ALT +/- to slow/speed rotation/move \n";
842 text +=
"Press H to reset view \n";
843 text +=
"Press Esc to exit FullScreen \n";
845 text +=
"========= Video ========= \n";
846 text +=
"In video mode : \n";
847 text +=
" Press SPACE to Start/Pause video recording \n";
848 text +=
" Press RETURN to Stop video recording \n";
853 if ( fShortcutsDialog == NULL) {
854 fShortcutsDialog =
new QDialog();
855 fShortcutsDialogInfos =
new QTextEdit() ;
856 QVBoxLayout *mainLayout =
new QVBoxLayout;
857 mainLayout->addWidget(fShortcutsDialogInfos);
858 fShortcutsDialog->setLayout(mainLayout);
859 fShortcutsDialog->setWindowTitle(tr(
"Shortcuts"));
862 fShortcutsDialogInfos->setPlainText(text.data());
863 fShortcutsDialog->show();
874void G4OpenGLQtViewer::toggleMouseAction(
int aAction) {
878 }
else if (aAction == 2) {
880 }
else if (aAction == 3) {
882 }
else if (aAction == 4) {
884 }
else if (aAction == 5) {
903void G4OpenGLQtViewer::toggleSurfaceAction(
int aAction) {
910 }
else if (aAction ==2) {
913 }
else if (aAction ==3) {
916 }
else if (aAction ==4) {
936void G4OpenGLQtViewer::toggleProjection(
bool check) {
952void G4OpenGLQtViewer::toggleTransparency(
bool check) {
968void G4OpenGLQtViewer::toggleAntialiasing(
bool check) {
972 glDisable (GL_LINE_SMOOTH);
973 glDisable (GL_POLYGON_SMOOTH);
976 glEnable (GL_LINE_SMOOTH);
977 glHint (GL_LINE_SMOOTH_HINT, GL_NICEST);
978 glEnable (GL_POLYGON_SMOOTH);
979 glHint (GL_POLYGON_SMOOTH_HINT, GL_NICEST);
991void G4OpenGLQtViewer::toggleHaloing(
bool check) {
1007void G4OpenGLQtViewer::toggleAux(
bool check) {
1019void G4OpenGLQtViewer::togglePicking() {
1032 UI->
ApplyCommand(std::string(
"/vis/viewer/set/picking true"));
1034 UI->
ApplyCommand(std::string(
"/vis/viewer/set/picking false"));
1045void G4OpenGLQtViewer::toggleHiddenMarkers(
bool check) {
1059void G4OpenGLQtViewer::toggleFullScreen(
bool check) {
1060 if (check !=
fGLWidget->isFullScreen()) {
1067 if (fMovieTempFolderPath ==
"") {
1070 QGLWidget* qGLW =
dynamic_cast<QGLWidget*
> (
fGLWidget) ;
1075 QString filePath =fMovieTempFolderPath+fileName;
1078 image = qGLW->grabFrameBuffer();
1081 res = image.save(filePath,0);
1084 setRecordingInfos(
"Can't save tmp file "+filePath);
1088 setRecordingInfos(
"File "+fileName+
" saved");
1094void G4OpenGLQtViewer::actionSaveImage() {
1102 qFilename = QFileDialog::getSaveFileName (
fGLWidget,
1109 std::string
name = qFilename.toStdString().c_str();
1116 fFileSavePath = QFileInfo(qFilename).path();
1118 std::string format = selectedFormat->toLower().toStdString().c_str();
1123 std::string filename =
name;
1124 std::string extension =
"";
1125 if (
name.find_last_of(
".") != std::string::npos) {
1126 filename =
name.substr(0,
name.find_last_of(
".") + 1);
1127 extension =
name.substr(
name.find_last_of(
".") + 1);
1132 filename+=
"."+ extension;
1139 if( exportDialog->exec()) {
1164void G4OpenGLQtViewer::actionChangeBackgroundColor() {
1172#if QT_VERSION < 0x040500
1174 const QColor color = QColor(QColorDialog::getRgba (QColor(Qt::black).rgba(),&a,
fGLWidget));
1176 const QColor color =
1177 QColorDialog::getColor(Qt::black,
1179 " Get background color and transparency",
1180 QColorDialog::ShowAlphaChannel);
1182 if (color.isValid()) {
1194void G4OpenGLQtViewer::actionChangeTextColor() {
1196#if QT_VERSION < 0x040500
1198 const QColor color = QColor(QColorDialog::getRgba (QColor(Qt::yellow).rgba(),&a,
fGLWidget));
1200 const QColor& color =
1201 QColorDialog::getColor(Qt::yellow,
1203 " Get text color and transparency",
1204 QColorDialog::ShowAlphaChannel);
1206 if (color.isValid()) {
1219void G4OpenGLQtViewer::actionChangeDefaultColor() {
1221#if QT_VERSION < 0x040500
1223 const QColor color = QColor(QColorDialog::getRgba (QColor(Qt::white).rgba(),&a,
fGLWidget));
1225 const QColor& color =
1226 QColorDialog::getColor(Qt::white,
1228 " Get default color and transparency",
1229 QColorDialog::ShowAlphaChannel);
1231 if (color.isValid()) {
1245void G4OpenGLQtViewer::actionMovieParameters() {
1246 showMovieParametersDialog();
1250void G4OpenGLQtViewer::showMovieParametersDialog() {
1251 if (!fMovieParametersDialog) {
1258 setRecordingInfos(
"ppmtompeg is needed to encode in video format. It is available here: http://netpbm.sourceforge.net ");
1261 fMovieParametersDialog->show();
1284 if (evnt->button() == Qt::RightButton) {
1287 if ((evnt->button() & Qt::LeftButton) && (! (evnt->modifiers() & Qt::ControlModifier ))){
1290 fLastPos1 = evnt->pos();
1291 fLastPos2 = fLastPos1;
1292 fLastPos3 = fLastPos2;
1293 fLastEventTime->start();
1294 if (fUiQt != NULL) {
1299 float deltaX = ((float)
getWinWidth()/2-evnt->pos().x());
1300 float deltaY = ((float)
getWinHeight()/2-evnt->pos().y());
1321 if (fShiftKeyPress) {
1322 fGLWidget->setCursor(QCursor(Qt::SizeAllCursor));
1325 fGLWidget->setCursor(QCursor(Qt::ClosedHandCursor));
1328 fGLWidget->setCursor(QCursor(Qt::SizeAllCursor));
1330 fGLWidget->setCursor(QCursor(Qt::PointingHandCursor));
1341 glGetIntegerv(GL_VIEWPORT, viewport);
1344 double factorX = ((double)viewport[2]/
fGLWidget->width());
1345 double factorY = ((double)viewport[3]/
fGLWidget->height());
1346 fSpinningDelay = (int)fLastEventTime->elapsed();
1347 QPoint delta = (fLastPos3-fLastPos1)*factorX;
1350 fGLWidget->setCursor(QCursor(Qt::ArrowCursor));
1353 if ((delta.x() != 0) || (delta.y() != 0)) {
1358 }
else if (fSpinningDelay < fLaunchSpinDelay ) {
1359 if ((delta.x() == 0) && (delta.y() == 0)) {
1364#if QT_VERSION < 0x050e00
1367 QElapsedTimer lastMoveTime;
1369 lastMoveTime.start();
1371 float correctionFactor = 5;
1373 if ( lastMoveTime.elapsed() >= (
int)(1000/fNbMaxFramesPerSec)) {
1374 float lTime = 1000/lastMoveTime.elapsed();
1375 if (((((
float)delta.x())/correctionFactor)*lTime > fNbMaxAnglePerSec) ||
1376 ((((
float)delta.x())/correctionFactor)*lTime < -fNbMaxAnglePerSec) ) {
1377 correctionFactor = (float)delta.x()*(lTime/fNbMaxAnglePerSec);
1378 if (delta.x() <0 ) {
1379 correctionFactor = -correctionFactor;
1382 if (((((
float)delta.y())/correctionFactor)*lTime > fNbMaxAnglePerSec) ||
1383 ((((
float)delta.y())/correctionFactor)*lTime < -fNbMaxAnglePerSec) ) {
1384 correctionFactor = (float)delta.y()*(lTime/fNbMaxAnglePerSec);
1385 if (delta.y() <0 ) {
1386 correctionFactor = -correctionFactor;
1397 lastMoveTime.start();
1399 bool rotate =
false;
1402 if (fUiQt != NULL) {
1418 rotateQtScene(((
float)delta.x())/correctionFactor,((
float)delta.y())/correctionFactor);
1419 }
else if (fAltKeyPress) {
1420 rotateQtSceneToggle(((
float)delta.x())/correctionFactor,((
float)delta.y())/correctionFactor);
1424 moveScene(-((
float)delta.x())/correctionFactor,-((
float)delta.y())/correctionFactor,0,
true);
1451 Qt::MouseButtons mButtons = evnt->buttons();
1459 fLastPos3 = fLastPos2;
1460 fLastPos2 = fLastPos1;
1461 fLastPos1 = QPoint(evnt->x(), evnt->y());
1463 int deltaX = fLastPos2.x()-fLastPos1.x();
1464 int deltaY = fLastPos2.y()-fLastPos1.y();
1467 if (fUiQt != NULL) {
1473 if (mButtons & Qt::LeftButton) {
1476 }
else if (fAltKeyPress) {
1478 }
else if (fShiftKeyPress) {
1479 unsigned int sizeWin;
1486 float factor = ((float)100/(
float)sizeWin) ;
1487 moveScene(-(
float)deltaX*factor,-(
float)deltaY*factor,0,
false);
1488 }
else if (fControlKeyPress) {
1493 if (mButtons & Qt::LeftButton) {
1494 moveScene(-(
float)deltaX,-(
float)deltaY,0,
true);
1498 fLastEventTime->start();
1513 fHoldMoveEvent =
true;
1516 GLdouble coefDepth = 0;
1532 fHoldMoveEvent =
false;
1543 if (fHoldRotateEvent)
1545 fHoldRotateEvent =
true;
1551 fHoldRotateEvent =
false;
1561 if (fHoldRotateEvent)
1563 fHoldRotateEvent =
true;
1569 fHoldRotateEvent =
false;
1580void G4OpenGLQtViewer::rescaleImage(
1602#if QT_VERSION < 0x050F00
1618 fHoldKeyEvent =
true;
1623 if ((fNoKeyPress) || (evnt->modifiers() == Qt::KeypadModifier )) {
1624 if (evnt->key() == Qt::Key_Down) {
1627 else if (evnt->key() == Qt::Key_Up) {
1630 if (evnt->key() == Qt::Key_Left) {
1633 else if (evnt->key() == Qt::Key_Right) {
1636 if (evnt->key() == Qt::Key_Minus) {
1639 else if (evnt->key() == Qt::Key_Plus) {
1643 if (evnt->key() == Qt::Key_Escape) {
1644 toggleFullScreen(
false);
1653 if ((evnt->key() == Qt::Key_Return) || (evnt->key() == Qt::Key_Enter)){
1656 if (evnt->key() == Qt::Key_Space){
1661 if (evnt->key() == Qt::Key_H){
1668 if (fShiftKeyPress) {
1669 fGLWidget->setCursor(QCursor(Qt::SizeAllCursor));
1671 if (evnt->key() == Qt::Key_Down) {
1674 else if (evnt->key() == Qt::Key_Up) {
1677 if (evnt->key() == Qt::Key_Left) {
1680 else if (evnt->key() == Qt::Key_Right) {
1683 if (evnt->key() == Qt::Key_Plus) {
1690 if ((fAltKeyPress)) {
1691 fGLWidget->setCursor(QCursor(Qt::ClosedHandCursor));
1693 if (evnt->key() == Qt::Key_Down) {
1696 else if (evnt->key() == Qt::Key_Up) {
1699 if (evnt->key() == Qt::Key_Left) {
1702 else if (evnt->key() == Qt::Key_Right) {
1707 if (evnt->key() == Qt::Key_Plus) {
1711 else if (evnt->key() == Qt::Key_Minus) {
1718 if ((fControlKeyPress)) {
1719 if (evnt->key() == Qt::Key_Plus) {
1723 else if (evnt->key() == Qt::Key_Minus) {
1729 fHoldKeyEvent =
false;
1735 fGLWidget->setCursor(QCursor(Qt::ArrowCursor));
1743 fAltKeyPress =
false;
1744 fShiftKeyPress =
false;
1745 fControlKeyPress =
false;
1747 if (modifier & Qt::AltModifier ) {
1748 fAltKeyPress =
true;
1749 fNoKeyPress =
false;
1751 if (modifier & Qt::ShiftModifier ) {
1752 fShiftKeyPress =
true;
1753 fNoKeyPress =
false;
1755 if (modifier & Qt::ControlModifier ) {
1756 fControlKeyPress =
true;
1757 fNoKeyPress =
false;
1767 if (!fMovieParametersDialog) {
1768 showMovieParametersDialog();
1770 setRecordingStatus(STOP);
1775 setRecordingStatus(BAD_ENCODER);
1777 setRecordingStatus(BAD_OUTPUT);
1781 setRecordingInfos(
"No frame to encode.");
1790 if (!fMovieParametersDialog) {
1791 showMovieParametersDialog();
1797 if (fRecordingStep == STOP) {
1798 setRecordingStatus(SAVE);
1811 if ( fRecordingStep == WAIT) {
1814 showMovieParametersDialog();
1815 setRecordingInfos(
"You should specified the temp folder in order to make movie");
1819 QString tmp = removeTempFolder();
1821 setRecordingInfos(tmp);
1824 tmp = createTempFolder();
1826 setRecordingInfos(
"Can't create temp folder."+tmp);
1832 if (fRecordingStep == WAIT) {
1833 setRecordingStatus(START);
1834 }
else if (fRecordingStep == START) {
1835 setRecordingStatus(PAUSE);
1836 }
else if (fRecordingStep == PAUSE) {
1837 setRecordingStatus(CONTINUE);
1838 }
else if (fRecordingStep == CONTINUE) {
1839 setRecordingStatus(PAUSE);
1843void G4OpenGLQtViewer::setRecordingStatus(RECORDING_STEP step) {
1845 fRecordingStep = step;
1852 QString txtStatus =
"";
1853 if (fRecordingStep == WAIT) {
1854 txtStatus =
"Waiting to start...";
1856 }
else if (fRecordingStep == START) {
1857 txtStatus =
"Start Recording...";
1858 }
else if (fRecordingStep == PAUSE) {
1859 txtStatus =
"Pause Recording...";
1860 }
else if (fRecordingStep == CONTINUE) {
1861 txtStatus =
"Continue Recording...";
1862 }
else if (fRecordingStep == STOP) {
1863 txtStatus =
"Stop Recording...";
1864 }
else if (fRecordingStep == READY_TO_ENCODE) {
1865 txtStatus =
"Ready to Encode...";
1866 }
else if (fRecordingStep ==
ENCODING) {
1867 txtStatus =
"Encoding...";
1868 }
else if (fRecordingStep == FAILED) {
1869 txtStatus =
"Failed to encode...";
1870 }
else if ((fRecordingStep == BAD_ENCODER)
1871 || (fRecordingStep == BAD_OUTPUT)
1872 || (fRecordingStep == BAD_TMP)) {
1873 txtStatus =
"Correct above errors first";
1874 }
else if (fRecordingStep == SUCCESS) {
1875 txtStatus =
"File encoded successfully";
1879 if (fMovieParametersDialog) {
1884 setRecordingInfos(
"");
1888void G4OpenGLQtViewer::setRecordingInfos(
const QString& txt) {
1889 if (fMovieParametersDialog) {
1898void G4OpenGLQtViewer::initMovieParameters() {
1902 fProcess =
new QProcess();
1904 QObject ::connect(fProcess,SIGNAL(finished (
int)),
1905 this,SLOT(processLookForFinished()));
1906 fProcess->setProcessChannelMode(QProcess::MergedChannels);
1907#if QT_VERSION < 0x050F00
1909 fProcess->start (
"which ppmtompeg");
1912 fProcess->start (
"which ppmtompeg", QStringList());
1919 return fEncoderPath;
1929 return "ppmtompeg is needed to encode in video format. It is available here: http://netpbm.sourceforge.net ";
1932 path = QDir::cleanPath(path);
1933 QFileInfo *f =
new QFileInfo(path);
1935 return "File does not exist";
1936 }
else if (f->isDir()) {
1937 return "This is a directory";
1938 }
else if (!f->isExecutable()) {
1939 return "File exist but is not executable";
1940 }
else if (!f->isFile()) {
1941 return "This is not a file";
1943 fEncoderPath = path;
1945 if (fRecordingStep == BAD_ENCODER) {
1946 setRecordingStatus(STOP);
1953 if ((fRecordingStep == START) || (fRecordingStep == CONTINUE)) {
1960 if (fRecordingStep == PAUSE) {
1974 if (fRecordingStep == WAIT) {
1981 if (fRecordingStep == STOP) {
1988 if (fRecordingStep == FAILED) {
1995 if (fRecordingStep == SUCCESS) {
2002 if (fRecordingStep == BAD_ENCODER) {
2008 if (fRecordingStep == BAD_TMP) {
2014 if (fRecordingStep == BAD_OUTPUT) {
2021 fRecordingStep = BAD_ENCODER;
2025 fRecordingStep = BAD_TMP;
2029 fRecordingStep = BAD_OUTPUT;
2034 fRecordingStep = WAIT;
2040 if (fRecordingStep == READY_TO_ENCODE) {
2047 setRecordingStatus(WAIT);
2057 return "Path does not exist";
2059 path = QDir::cleanPath(path);
2060 QFileInfo *d =
new QFileInfo(path);
2062 return "Path does not exist";
2063 }
else if (!d->isDir()) {
2064 return "This is not a directory";
2065 }
else if (!d->isReadable()) {
2066 return path +
" is read protected";
2067 }
else if (!d->isWritable()) {
2068 return path +
" is write protected";
2071 if (fRecordingStep == BAD_TMP) {
2072 setRecordingStatus(WAIT);
2074 fTempFolderPath = path;
2081 return fTempFolderPath;
2091 return "Path does not exist";
2094 QFileInfo *file =
new QFileInfo(path);
2095 QDir dir = file->dir();
2096 path = QDir::cleanPath(path);
2097 if (file->exists()) {
2098 return "File already exist, please choose a new one";
2099 }
else if (!dir.exists()) {
2100 return "Dir does not exist";
2101 }
else if (!dir.isReadable()) {
2102 return path +
" is read protected";
2105 if (fRecordingStep == BAD_OUTPUT) {
2106 setRecordingStatus(STOP);
2108 fSaveFileName = path;
2115 return fSaveFileName ;
2122QString G4OpenGLQtViewer::createTempFolder() {
2123 fMovieTempFolderPath =
"";
2129 QString sep = QString(QDir::separator());
2130 QString path = sep+
"QtMovie_"+QDateTime::currentDateTime ().toString(
"dd-MM-yyyy_hh-mm-ss")+sep;
2131 QDir *d =
new QDir(QDir::cleanPath(fTempFolderPath));
2133 if (d->exists(path)) {
2134 return "Folder "+path+
" already exists.Please remove it first";
2136 if (d->mkdir(fTempFolderPath+path)) {
2137 fMovieTempFolderPath = fTempFolderPath+path;
2140 return "Can't create "+fTempFolderPath+path;
2145QString G4OpenGLQtViewer::removeTempFolder() {
2147 if (fMovieTempFolderPath ==
"") {
2150 QDir *d =
new QDir(QDir::cleanPath(fMovieTempFolderPath));
2155 d->setFilter( QDir::Files );
2156 QStringList subDirList = d->entryList();
2159 for (QStringList::ConstIterator it = subDirList.begin() ;(it != subDirList.end()) ; it++) {
2160 const QString currentFile = *it;
2161 if (!d->remove(currentFile)) {
2163 QString file = fMovieTempFolderPath+currentFile;
2164 error +=
"Removing file failed : "+file;
2169 if (d->rmdir(fMovieTempFolderPath)) {
2170 fMovieTempFolderPath =
"";
2173 return "Dir "+fMovieTempFolderPath+
" should be empty, but could not remove it";
2177 return "Could not remove "+fMovieTempFolderPath+
" because of the following errors :"+error;
2189 QGLWidget* qGLW =
dynamic_cast<QGLWidget*
> (
fGLWidget) ;
2194 bool increaseFileNumber =
true;
2196 if (name.size() != name.substr(name.find_last_of(
".") + 1).size()) {
2197 increaseFileNumber =
false;
2202 if ((width !=-1) && (height != -1)) {
2212 image = qGLW->grabFrameBuffer();
2231 fp = fopen (QString(fMovieTempFolderPath+fParameterFileName).toStdString().c_str(),
"w");
2234 setRecordingInfos(
"Generation of parameter file failed");
2238 fprintf (fp,
"# Pattern affects speed, quality and compression. See the User's Guide\n");
2239 fprintf (fp,
"# for more info.\n");
2241 fprintf (fp,
"PATTERN I\n");
2244 fprintf (fp,
"# You must specify the type of the input files. The choices are:\n");
2245 fprintf (fp,
"# YUV, PPM, JMOVIE, Y, JPEG, PNM\n");
2246 fprintf (fp,
"# (must be upper case)\n");
2248 fprintf (fp,
"BASE_FILE_FORMAT PPM\n");
2251 fprintf (fp,
"# If you are using YUV, there are different supported file formats.\n");
2252 fprintf (fp,
"# EYUV or UCB are the same as previous versions of this encoder.\n");
2253 fprintf (fp,
"# (All the Y's, then U's then V's, in 4:2:0 subsampling.)\n");
2254 fprintf (fp,
"# Other formats, such as Abekas, Phillips, or a general format are\n");
2255 fprintf (fp,
"# permissible, the general format is a string of Y's, U's, and V's\n");
2256 fprintf (fp,
"# to specify the file order.\n");
2258 fprintf (fp,
"INPUT_FORMAT UCB\n");
2260 fprintf (fp,
"# the conversion statement\n");
2262 fprintf (fp,
"# Each occurrence of '*' will be replaced by the input file\n");
2264 fprintf (fp,
"# e.g., if you have a bunch of GIF files, then this might be:\n");
2265 fprintf (fp,
"# INPUT_CONVERT giftoppm *\n");
2267 fprintf (fp,
"# e.g., if you have a bunch of files like a.Y a.U a.V, etc., then:\n");
2268 fprintf (fp,
"# INPUT_CONVERT cat *.Y *.U *.V\n");
2270 fprintf (fp,
"# e.g., if you are grabbing from laser disc you might have something like\n");
2271 fprintf (fp,
"# INPUT_CONVERT goto frame *; grabppm\n");
2272 fprintf (fp,
"# 'INPUT_CONVERT *' means the files are already in the base file format\n");
2274 fprintf (fp,
"INPUT_CONVERT * \n");
2276 fprintf (fp,
"# number of frames in a GOP.\n");
2278 fprintf (fp,
"# since each GOP must have at least one I-frame, the encoder will find the\n");
2279 fprintf (fp,
"# the first I-frame after GOP_SIZE frames to start the next GOP\n");
2281 fprintf (fp,
"# later, will add more flexible GOP signalling\n");
2283 fprintf (fp,
"GOP_SIZE 1\n");
2285 fprintf (fp,
"# number of slices in a frame\n");
2287 fprintf (fp,
"# 1 is a good number. another possibility is the number of macroblock rows\n");
2288 fprintf (fp,
"# (which is the height divided by 16)\n");
2290 fprintf (fp,
"SLICES_PER_FRAME 1\n");
2291 fprintf (fp,
"PIXEL HALF");
2293 fprintf (fp,
"# directory to get all input files from (makes this file easier to read)\n");
2294 fprintf (fp,
"INPUT_DIR %s\n",fMovieTempFolderPath.toStdString().c_str());
2296 fprintf (fp,
"# There are a bunch of ways to specify the input files.\n");
2297 fprintf (fp,
"# from a simple one-per-line listing, to the following \n");
2298 fprintf (fp,
"# way of numbering them. See the manual for more information.\n");
2299 fprintf (fp,
"INPUT\n");
2300 fprintf (fp,
"# '*' is replaced by the numbers 01, 02, 03, 04\n");
2301 fprintf (fp,
"# if I instead do [01-11], it would be 01, 02, ..., 09, 10, 11\n");
2302 fprintf (fp,
"# if I instead do [1-11], it would be 1, 2, 3, ..., 9, 10, 11\n");
2303 fprintf (fp,
"# if I instead do [1-11+3], it would be 1, 4, 7, 10\n");
2304 fprintf (fp,
"# the program assumes none of your input files has a name ending in ']'\n");
2305 fprintf (fp,
"# if you do, too bad!!!\n");
2309 fprintf (fp,
"# can have more files here if you want...there is no limit on the number\n");
2310 fprintf (fp,
"# of files\n");
2311 fprintf (fp,
"END_INPUT\n");
2315 fprintf (fp,
"# Many of the remaining options have to do with the motion search and qscale\n");
2317 fprintf (fp,
"# FULL or HALF -- must be upper case\n");
2318 fprintf (fp,
"# Should be FULL for computer generated images\n");
2319 fprintf (fp,
"PIXEL FULL\n");
2321 fprintf (fp,
"# means +/- this many pixels for both P and B frame searches\n");
2322 fprintf (fp,
"# specify two numbers if you wish to serc different ranges in the two.\n");
2323 fprintf (fp,
"RANGE 10\n");
2325 fprintf (fp,
"# The two search algorithm parameters below mostly affect speed,\n");
2326 fprintf (fp,
"# with some affect on compression and almost none on quality.\n");
2328 fprintf (fp,
"# this must be one of {EXHAUSTIVE, SUBSAMPLE, LOGARITHMIC}\n");
2329 fprintf (fp,
"PSEARCH_ALG LOGARITHMIC\n");
2331 fprintf (fp,
"# this must be one of {SIMPLE, CROSS2, EXHAUSTIVE}\n");
2333 fprintf (fp,
"# note that EXHAUSTIVE is really, really, really slow\n");
2335 fprintf (fp,
"BSEARCH_ALG SIMPLE\n");
2338 fprintf (fp,
"# these specify the q-scale for I, P, and B frames\n");
2339 fprintf (fp,
"# (values must be between 1 and 31)\n");
2340 fprintf (fp,
"# These are the Qscale values for the entire frame in variable bit-rate\n");
2341 fprintf (fp,
"# mode, and starting points (but not important) for constant bit rate\n");
2344 fprintf (fp,
"# Qscale (Quantization scale) affects quality and compression,\n");
2345 fprintf (fp,
"# but has very little effect on speed.\n");
2347 fprintf (fp,
"IQSCALE 4\n");
2348 fprintf (fp,
"PQSCALE 5\n");
2349 fprintf (fp,
"BQSCALE 12\n");
2351 fprintf (fp,
"# this must be ORIGINAL or DECODED\n");
2352 fprintf (fp,
"REFERENCE_FRAME ORIGINAL\n");
2354 fprintf (fp,
"# for parallel parameters see parallel.param in the examples subdirectory\n");
2356 fprintf (fp,
"# if you want constant bit-rate mode, specify it as follows (number is bits/sec):\n");
2357 fprintf (fp,
"#BIT_RATE 1000000\n");
2359 fprintf (fp,
"# To specify the buffer size (327680 is default, measused in bits, for 16bit words)\n");
2360 fprintf (fp,
"BUFFER_SIZE 327680\n");
2362 fprintf (fp,
"# The frame rate is the number of frames/second (legal values:\n");
2363 fprintf (fp,
"# 23.976, 24, 25, 29.97, 30, 50 ,59.94, 60\n");
2364 fprintf (fp,
"FRAME_RATE 30\n");
2366 fprintf (fp,
"# There are many more options, see the users manual for examples....\n");
2367 fprintf (fp,
"# ASPECT_RATIO, USER_DATA, GAMMA, IQTABLE, etc.\n");
2372 setRecordingInfos(
"Parameter file "+fParameterFileName+
" generated in "+fMovieTempFolderPath);
2373 setRecordingStatus(READY_TO_ENCODE);
2382 fProcess =
new QProcess();
2383#if QT_VERSION > 0x040100
2384 QObject ::connect(fProcess,SIGNAL(finished (
int,QProcess::ExitStatus)),
2385 this,SLOT(processEncodeFinished()));
2386 QObject ::connect(fProcess,SIGNAL(readyReadStandardOutput ()),
2387 this,SLOT(processEncodeStdout()));
2389 QObject ::connect(fProcess,SIGNAL(finished (
int)),
2390 this,SLOT(processEncodeFinished()));
2391 QObject ::connect(fProcess,SIGNAL(readyReadStandardOutput ()),
2392 this,SLOT(processEncodeStdout()));
2394#if QT_VERSION < 0x050a00
2395 fProcess->setReadChannelMode(QProcess::MergedChannels);
2397 fProcess->setProcessChannelMode(QProcess::MergedChannels);
2399 fProcess->start (fEncoderPath, QStringList(fMovieTempFolderPath+fParameterFileName));
2405void G4OpenGLQtViewer::processEncodeStdout()
2407 QString tmp = fProcess->readAllStandardOutput ().data();
2408 int start = tmp.lastIndexOf(
"ESTIMATED TIME");
2409 tmp = tmp.mid(start,tmp.indexOf(
"\n",start)-start);
2410 setRecordingInfos(tmp);
2414void G4OpenGLQtViewer::processEncodeFinished()
2418 txt = getProcessErrorMsg();
2420 setRecordingStatus(SUCCESS);
2422 setRecordingStatus(FAILED);
2428void G4OpenGLQtViewer::processLookForFinished()
2431 QString txt = getProcessErrorMsg();
2435 fEncoderPath = QString(fProcess->readAllStandardOutput ().data()).trimmed();
2437 if (fEncoderPath.contains(
" ")) {
2439 }
else if (!fEncoderPath.contains(
"ppmtompeg")) {
2449QString G4OpenGLQtViewer::getProcessErrorMsg()
2452 if (fProcess->exitCode() != 0) {
2453 switch (fProcess->error()) {
2454 case QProcess::FailedToStart:
2455 txt =
"The process failed to start. Either the invoked program is missing, or you may have insufficient permissions to invoke the program.\n";
2457 case QProcess::Crashed:
2458 txt =
"The process crashed some time after starting successfully.\n";
2460 case QProcess::Timedout:
2461 txt =
"The last waitFor...() function timed out. The state of QProcess is unchanged, and you can try calling waitFor...() again.\n";
2463 case QProcess::WriteError:
2464 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";
2466 case QProcess::ReadError:
2467 txt =
"An error occurred when attempting to read from the process. For example, the process may not be running.\n";
2469 case QProcess::UnknownError:
2470 txt =
"An unknown error occurred. This is the default return value of error().\n";
2480QWidget *G4OpenGLQtViewer::getParentWidget()
2488 QDialog* dialog = NULL;
2492 QWidgetList wl = QApplication::allWidgets();
2493 QWidget *widget = NULL;
2494 for (
int i=0; i < wl.size(); i++) {
2496 if ((found==
false) && (widget->inherits(
"QMainWindow"))) {
2497 dialog =
new QDialog(widget,Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowMinMaxButtonsHint);
2503 dialog =
new QDialog();
2506 dialog=
new QDialog();
2516void G4OpenGLQtViewer::createSceneTreeWidget() {
2519 if (!fUISceneTreeWidget) {
2524 QLayoutItem * wItem;
2526 if (fUISceneTreeWidget->layout()->count() ) {
2527 for(
int idx = 0; idx < fUISceneTreeWidget->layout()->count(); idx++){
2528 wItem = fUISceneTreeWidget->layout()->itemAt(idx);
2529 if (fSceneTreeWidget) {
2530 if(
dynamic_cast<QWidget *
>(wItem->widget())) {
2531 if (wItem->widget()->windowTitle() == fSceneTreeWidget->windowTitle()) {
2532 wItem->widget()->show();
2535 wItem->widget()->hide();
2539 wItem->widget()->hide();
2546 fSceneTreeWidget =
new QWidget();
2547 QVBoxLayout* layoutSceneTree =
new QVBoxLayout();
2548 fSceneTreeWidget->setStyleSheet (
"padding: 0px ");
2550 fSceneTreeWidget->setLayout(layoutSceneTree);
2551 fSceneTreeWidget->layout()->setContentsMargins(5,5,5,5);
2552 fSceneTreeWidget->setWindowTitle(QString(
GetName().data()));
2554 if (fUISceneTreeWidget != NULL) {
2555 fUISceneTreeWidget->layout()->addWidget(fSceneTreeWidget);
2560 createSceneTreeComponent();
2566void G4OpenGLQtViewer::createSceneTreeComponent(){
2568 QLayout* vLayout = fSceneTreeWidget->layout();
2571 QWidget* coutButtonWidget =
new QWidget();
2572 QHBoxLayout* layoutCoutTBButtons =
new QHBoxLayout();
2574 fFilterOutput =
new QLineEdit();
2575 fFilterOutput->setToolTip(
"Filter output by...");
2576 fFilterOutput->setStyleSheet (
"padding: 0px ");
2579#if QT_VERSION > 0x050100
2580 fFilterOutput->addAction(*searchIcon,QLineEdit::TrailingPosition);
2581 fFilterOutput->setStyleSheet (
"border-radius:7px;");
2583 QPushButton *coutTBFilterButton =
new QPushButton();
2584 coutTBFilterButton->setIcon(*searchIcon);
2585 coutTBFilterButton->setStyleSheet (
"padding-left: 0px; border:0px;");
2586 fFilterOutput->setStyleSheet (
"padding-right: 0px;");
2588 layoutCoutTBButtons->addWidget(fFilterOutput);
2590#if QT_VERSION <= 0x050100
2591 layoutCoutTBButtons->addWidget(coutTBFilterButton);
2594 coutButtonWidget->setLayout(layoutCoutTBButtons);
2595 vLayout->addWidget(coutButtonWidget);
2598 vLayout->setContentsMargins(0,0,0,0);
2601 fSceneTreeComponentTreeWidget =
new QTreeWidget();
2602 fSceneTreeComponentTreeWidget->setSelectionMode(QAbstractItemView::SingleSelection);
2603 fSceneTreeComponentTreeWidget->setHeaderLabel (
"Scene tree : "+QString(
GetName().data()));
2604 fSceneTreeComponentTreeWidget->setColumnHidden (1,
true);
2605 fSceneTreeComponentTreeWidget->setColumnHidden (2,
true);
2606 fSceneTreeComponentTreeWidget->setColumnHidden (3,
true);
2611 vLayout->addWidget(fSceneTreeComponentTreeWidget);
2613 connect(fSceneTreeComponentTreeWidget,SIGNAL(itemChanged(QTreeWidgetItem*,
int)),SLOT(sceneTreeComponentItemChanged(QTreeWidgetItem*,
int)));
2614 connect(fSceneTreeComponentTreeWidget,SIGNAL(itemSelectionChanged ()),SLOT(sceneTreeComponentSelected()));
2615 connect(fSceneTreeComponentTreeWidget,SIGNAL(itemDoubleClicked ( QTreeWidgetItem*,
int)),SLOT(changeColorAndTransparency( QTreeWidgetItem*,
int)));
2619 QWidget *helpWidget =
new QWidget();
2620 QHBoxLayout *helpLayout =
new QHBoxLayout();
2622 QWidget* depthWidget =
new QWidget();
2623 QWidget *showBox =
new QWidget(depthWidget);
2624 QHBoxLayout *showBoxLayout =
new QHBoxLayout();
2627 showBoxLayout->setContentsMargins(5,5,5,5);
2629 QLabel *zero =
new QLabel();
2630 zero->setText(
"Show all");
2631 QLabel *one =
new QLabel();
2632 one->setText(
"Hide all");
2633 fSceneTreeDepthSlider =
new QSlider ( Qt::Horizontal);
2634 fSceneTreeDepthSlider->setMaximum (1000);
2635 fSceneTreeDepthSlider->setMinimum (0);
2636 fSceneTreeDepthSlider->setTickPosition(QSlider::TicksAbove);
2638 fSceneTreeDepthSlider->setMinimumWidth (40);
2640 showBoxLayout->addWidget(zero);
2641 showBoxLayout->addWidget(fSceneTreeDepthSlider);
2642 showBoxLayout->addWidget(one);
2644 showBox->setLayout(showBoxLayout);
2646 helpLayout->addWidget(showBox);
2647 helpWidget->setLayout(helpLayout);
2648 helpLayout->setContentsMargins(0,0,0,0);
2650 vLayout->addWidget(helpWidget);
2652 connect( fSceneTreeDepthSlider, SIGNAL( valueChanged(
int) ),
this, SLOT( changeDepthInSceneTree(
int) ) );
2653 connect( fFilterOutput, SIGNAL( textEdited (
const QString &) ),
this, SLOT(changeSearchSelection()));
2654 fTreeItemModels.clear();
2656 fPVRootNodeCreate =
false;
2658 fMaxPOindexInserted = -1;
2664void G4OpenGLQtViewer::createViewerPropertiesWidget() {
2669 if (!fUIViewerPropertiesWidget) {
2674 QLayoutItem * wItem;
2675 if (fUIViewerPropertiesWidget->layout()->count()) {
2676 while ((wItem = fUIViewerPropertiesWidget->layout()->takeAt(0)) != 0) {
2677 delete wItem->widget();
2683 QGroupBox *groupBox =
new QGroupBox();
2684 groupBox->setTitle(
GetName().data());
2685 QVBoxLayout *vbox =
new QVBoxLayout;
2688 fViewerPropertiesTableWidget =
new QTableWidget();
2690 QSizePolicy vPolicy = fViewerPropertiesTableWidget->sizePolicy();
2691 vPolicy.setVerticalStretch(4);
2693 vbox->addWidget(fViewerPropertiesTableWidget);
2694 groupBox->setLayout(vbox);
2695 fUIViewerPropertiesWidget->layout()->addWidget(groupBox);
2697 connect(fViewerPropertiesTableWidget, SIGNAL(itemChanged(QTableWidgetItem*)),
this, SLOT(tableWidgetViewerSetItemChanged(QTableWidgetItem *)));
2701 QDialog* dial =
static_cast<QDialog*
> (fUIViewerPropertiesWidget->parent());
2704 dial->setWindowTitle(QString(
"Viewer properties - ")+
GetName());
2709void G4OpenGLQtViewer::createPickInfosWidget(){
2714 if (!fUIPickInfosWidget) {
2719 QLayoutItem * wItem;
2720 if (fUIPickInfosWidget->layout()->count()) {
2721 while ((wItem = fUIPickInfosWidget->layout()->takeAt(0)) != 0) {
2722 delete wItem->widget();
2727 QGroupBox *groupBox =
new QGroupBox(
"");
2728 QVBoxLayout *vbox =
new QVBoxLayout;
2731 QWidget *pickingInfoWidget =
new QWidget();
2732 QHBoxLayout *pickingInfoLayout =
new QHBoxLayout();
2734 pickingInfoWidget->setStyleSheet (
"padding-left: 0px; border:0px;");
2735 pickingInfoWidget->setLayout(pickingInfoLayout);
2737 vbox->addWidget(pickingInfoWidget);
2740 fPickInfosScrollArea =
new QScrollArea();
2741 fPickInfosScrollArea->setWidgetResizable(
true);
2744 fPickInfosWidget =
new QWidget();
2745 fPickInfosWidget->setStyleSheet (
"padding: 0px ");
2747 QVBoxLayout* vLayout =
new QVBoxLayout();
2748 fPickInfosWidget->setLayout (vLayout);
2749 fPickInfosScrollArea->setWidget(fPickInfosWidget);
2751 QSizePolicy vPolicy = fPickInfosWidget->sizePolicy();
2752 vPolicy.setVerticalStretch(4);
2753 vbox->addWidget(fPickInfosScrollArea);
2754 pickingInfoLayout->setContentsMargins(0,0,0,0);
2755 vLayout->setContentsMargins(0,0,0,0);
2756 vbox->setContentsMargins(1,1,1,1);
2758 groupBox->setLayout(vbox);
2759 fUIPickInfosWidget->layout()->addWidget(groupBox);
2767void G4OpenGLQtViewer::setCheckComponent(QTreeWidgetItem* item,
bool check)
2771 const PVPath& fullPath = fTreeItemModels[item->data(0,Qt::UserRole).toInt()];
2773 if (fullPath.size() > 0) {
2782 item->setCheckState(0,Qt::Checked);
2784 item->setCheckState(0,Qt::Unchecked);
2786 updatePositivePoIndexSceneTreeWidgetQuickMap(item->data(0,Qt::UserRole).toInt(),item);
2787 int nChildCount = item->childCount();
2788 for (
int i = 0; i < nChildCount; i++) {
2789 setCheckComponent(item->child(i),check);
2797 QGLWidget* qGLW =
dynamic_cast<QGLWidget*
> (
fGLWidget) ;
2809#ifdef G4MULTITHREADED
2816 QFont font = QFont();
2817 font.setPointSizeF(size);
2825 const char* textCString = textString.c_str();
2830 QFontMetrics* f =
new QFontMetrics (font);
2831#if QT_VERSION > 0x050110
2832 G4double span = f->boundingRect(textCString).width();
2834 G4double span = f->width(textCString);
2853 xmove *= fudgeFactor;
2854 ymove *= fudgeFactor;
2878 const QString& modelShortName = getModelShortName(model);
2880 if (modelShortName ==
"") {
2884 if (fSceneTreeComponentTreeWidget == NULL) {
2885 createSceneTreeComponent();
2889 if (fSceneTreeComponentTreeWidget == NULL) {
2893 fSceneTreeComponentTreeWidget->blockSignals(
true);
2897 if (!fPVRootNodeCreate) {
2900 fModelShortNameItem = createTreeWidgetItem(pPVModel->
GetFullPVPath(),
2908 fPVRootNodeCreate =
true;
2911 bool added = parseAndInsertInSceneTree(fModelShortNameItem,pPVModel,0,modelShortName,0,currentPOIndex);
2915 fSceneTreeComponentTreeWidget->blockSignals(
false);
2924QTreeWidgetItem* G4OpenGLQtViewer::createTreeWidgetItem(
2925 const PVPath& fullPath
2926 ,
const QString& name
2929 ,
const QString& logicalName
2930 ,Qt::CheckState state
2931 ,QTreeWidgetItem * parentTreeNode
2936 if (fullPath.size() > fSceneTreeDepth) {
2937 fSceneTreeDepth = (
unsigned int)fullPath.size();
2939 if (fSceneTreeDepthSlider) {
2940 fSceneTreeDepthSlider->setTickInterval(1000/(fSceneTreeDepth+1));
2943 QTreeWidgetItem * newItem = NULL;
2944 if (parentTreeNode == NULL) {
2945 newItem =
new QTreeWidgetItem();
2946 fSceneTreeComponentTreeWidget->addTopLevelItem(newItem);
2948 newItem =
new QTreeWidgetItem(parentTreeNode);
2949 fSceneTreeComponentTreeWidget->addTopLevelItem(parentTreeNode);
2953 newItem->setText(0,name);
2954 newItem->setData(1,Qt::UserRole,copyNb);
2955 newItem->setText(2,QString::number(POIndex));
2956 newItem->setData(0, Qt::UserRole, POIndex);
2957 newItem->setText(3,logicalName);
2958 newItem->setFlags(newItem->flags()|Qt::ItemIsUserCheckable);
2959 newItem->setCheckState(0,state);
2960 newItem->setExpanded(
true);
2961 updatePositivePoIndexSceneTreeWidgetQuickMap(POIndex,newItem);
2963 changeQColorForTreeWidgetItem(newItem,QColor((
int)(color.
GetRed()*255),
2969 if ((state == Qt::Unchecked) && (POIndex == -1)) {
2970 newItem->setForeground (0, QBrush( Qt::gray) );
2973 newItem->setToolTip (0,QString(
2974 "This node exists in the geometry but has not been\n")+
2975 "drawn, perhaps because it has been set invisible. It \n"+
2976 "cannot be made visible with a click on the button.\n"+
2977 "To see it, change the visibility, for example, with \n"+
2978 "/vis/geometry/set/visibility " + logicalName +
" 0 true\n"+
2979 "and rebuild the view with /vis/viewer/rebuild.\n"+
2980 "Click here will only show/hide all child components");
2983 newItem->setToolTip (0,QString(
"double-click to change the color"));
2989 state = Qt::Unchecked;
2990 newItem->setCheckState(0,state);
2991 updatePositivePoIndexSceneTreeWidgetQuickMap(POIndex,newItem);
2994 fTreeItemModels.insert(std::pair <int, PVPath > (POIndex,fullPath) );
2998 changeOpenCloseVisibleHiddenSelectedColorSceneTreeElement(newItem);
3015bool G4OpenGLQtViewer::parseAndInsertInSceneTree(
3016 QTreeWidgetItem * parentItem
3018 ,
unsigned int fullPathIndex
3019 ,
const QString& parentRoot
3020 ,
unsigned int currentIndexInTreeSceneHandler
3021 ,
int currentPVPOIndex
3024 if (parentItem == NULL) {
3030 std::ostringstream oss;
3031 oss << fullPath.at(fullPathIndex).GetCopyNo();
3032 std::string currentPVName =
G4String(fullPath.at(fullPathIndex).GetPhysicalVolume()->GetName()+
" ["+oss.str()+
"]").data();
3034 int currentPVCopyNb = fullPath.at(fullPathIndex).GetCopyNo();
3044 QTreeWidgetItem* subItem = NULL;
3045 QList<QTreeWidgetItem *> parentItemList;
3053 if ((currentIndexInTreeSceneHandler == (fullPath.size()-1)) && ((color.
GetAlpha() == 1.))) {
3055 QString lookForString = QString(currentPVName.c_str());
3056 for (
int i = 0;i < parentItem->childCount(); i++ ) {
3057 if (parentItem->child(i)->text(0) == lookForString) {
3058 parentItemList.push_back(parentItem->child(i));
3063 for (
int i = 0; i < parentItemList.size(); ++i) {
3064 const std::string& parentItemName = parentItemList.at(i)->text(0).toStdString();
3065 int parentItemCopyNb = parentItemList.at(i)->data(1,Qt::UserRole).toInt();
3066 int parentItemPOIndex = parentItemList.at(i)->data(0,Qt::UserRole).toInt();
3074 if (((parentRoot == fTouchableVolumes) && (currentPVCopyNb == parentItemCopyNb)
3075 && (currentPVName == parentItemName)) ||
3077 ((parentRoot != fTouchableVolumes) && (currentPVCopyNb == parentItemCopyNb)
3079 && (currentPVName == parentItemName) && (currentPVPOIndex == parentItemPOIndex) )) {
3082 bool sameTransform =
true;
3083 if (parentItemPOIndex >= 0) {
3084 const PVPath& fullPathTmp = fTreeItemModels[parentItemPOIndex];
3085 if (fullPathTmp.size() > 0) {
3086 if (fullPathTmp.at(fullPathTmp.size()-1).GetTransform () == pPVModel->
GetTransformation ()) {
3087 sameTransform =
true;
3089 sameTransform =
false;
3095 if (sameTransform ==
true) {
3102 if (currentIndexInTreeSceneHandler == (fullPath.size()-1)) {
3104 parentItemList.at(i)->setText(2,QString::number(currentPVPOIndex));
3105 parentItemList.at(i)->setData(0, Qt::UserRole,currentPVPOIndex);
3107 fTreeItemModels.insert(std::pair <int, PVPath >(currentPVPOIndex,fullPath) );
3111 parentItemList.at(i)->setFont (0,f);
3114 parentItemList.at(i)->setForeground (0,QBrush());
3117 parentItemList.at(i)->setToolTip (0,
"");
3119 changeQColorForTreeWidgetItem(parentItemList.at(i),QColor((
int)(color.
GetRed()*255),
3126 parentItemList.at(i)->setCheckState(0,Qt::Checked);
3127 updatePositivePoIndexSceneTreeWidgetQuickMap(currentPVPOIndex,parentItemList.at(i));
3131 subItem = parentItemList.at(i);
3135 }
else if (currentIndexInTreeSceneHandler < (fullPath.size()-1)) {
3136 subItem = parentItemList.at(i);
3143 if (currentIndexInTreeSceneHandler == (fullPath.size()-1)) {
3144 createTreeWidgetItem(fullPath,
3145 QString(currentPVName.c_str()),
3148 QString(fullPath.at(fullPathIndex).GetPhysicalVolume()->GetLogicalVolume()->GetName().data()),
3153 if (currentPVPOIndex > fMaxPOindexInserted) {
3154 fMaxPOindexInserted = currentPVPOIndex;
3160 if (subItem == NULL) {
3162 if (currentIndexInTreeSceneHandler < (fullPath.size()-1)) {
3163 subItem = createTreeWidgetItem(fullPath,
3164 QString(currentPVName.c_str()),
3167 QString(fullPath.at(fullPathIndex).GetPhysicalVolume()->GetLogicalVolume()->GetName().data()),
3174 return parseAndInsertInSceneTree(subItem,pPVModel,fullPathIndex+1,parentRoot,currentIndexInTreeSceneHandler+1,currentPVPOIndex);
3180void G4OpenGLQtViewer::changeOpenCloseVisibleHiddenSelectedColorSceneTreeElement(
3181 QTreeWidgetItem* subItem
3185 QTreeWidgetItem* oldItem = NULL;
3187 QTreeWidgetItem* foundItem = getOldTreeWidgetItem(subItem->data(0,Qt::UserRole).toInt());
3189 if (foundItem != NULL) {
3190 if (isSameSceneTreeElement(foundItem,subItem)) {
3191 oldItem = foundItem;
3194 if (foundItem == NULL) {
3197 std::map <int, QTreeWidgetItem*>::const_iterator i;
3198 i = fOldPositivePoIndexSceneTreeWidgetQuickMap.cbegin();
3199 while (i != fOldPositivePoIndexSceneTreeWidgetQuickMap.cend()) {
3200 if (isSameSceneTreeElement(i->second,subItem)) {
3201 oldItem = i->second;
3202 i = fOldPositivePoIndexSceneTreeWidgetQuickMap.cend();
3208 if (oldItem == NULL) {
3210 while (a < fOldNullPoIndexSceneTreeWidgetQuickVector.size()) {
3211 if (isSameSceneTreeElement(fOldNullPoIndexSceneTreeWidgetQuickVector[a],subItem)) {
3212 oldItem = fOldNullPoIndexSceneTreeWidgetQuickVector[a];
3213 a = fOldNullPoIndexSceneTreeWidgetQuickVector.size();
3222 if (oldItem != NULL) {
3223 subItem->setFlags(oldItem->flags());
3224 subItem->setCheckState(0,oldItem->checkState(0));
3225 subItem->setSelected(oldItem->isSelected());
3226 subItem->setExpanded(oldItem->isExpanded ());
3231 std::map <int, QTreeWidgetItem* >::iterator it;
3234 int oldPOIndex = oldItem->data(0,Qt::UserRole).toInt();
3235 it = fOldPositivePoIndexSceneTreeWidgetQuickMap.find(oldPOIndex);
3239 std::map <int, QColor >::iterator itVis;
3240 itVis = fOldVisAttrColorMap.find(oldPOIndex);
3242 QColor oldVisAttrColor;
3243 const QColor& newVisAttrColor = subItem->data(2,Qt::UserRole).value<QColor>();
3245 bool visAttrChange =
false;
3247 if (itVis != fOldVisAttrColorMap.end()) {
3248 oldVisAttrColor = itVis->second;
3249 if (oldVisAttrColor != newVisAttrColor) {
3250 visAttrChange =
true;
3253 visAttrChange =
true;
3256 if (visAttrChange) {
3257 fOldVisAttrColorMap.insert(std::pair <int, QColor > (subItem->data(0,Qt::UserRole).toInt(),newVisAttrColor) );
3261 if (it != fOldPositivePoIndexSceneTreeWidgetQuickMap.end()) {
3262 color = (it->second)->data(2,Qt::UserRole).value<QColor>();
3264 color = oldItem->data(2,Qt::UserRole).value<QColor>();
3266 changeQColorForTreeWidgetItem(subItem,color);
3278bool G4OpenGLQtViewer::isSameSceneTreeElement(
3279 QTreeWidgetItem* parentOldItem
3280 ,QTreeWidgetItem* parentNewItem
3286 int newCpNumber = -1;
3287 int oldCpNumber = -1;
3289 bool firstWhile =
true;
3291 while ((parentOldItem != NULL) && (parentNewItem != NULL)) {
3295 oldPO = parentOldItem->data(0,Qt::UserRole).toInt();
3296 newPO = parentNewItem->data(0,Qt::UserRole).toInt();
3302 const PVPath& oldFullPath = fOldTreeItemModels[oldPO];
3303 const PVPath& newFullPath = fTreeItemModels[newPO];
3304 if ((oldFullPath.size() > 0) &&
3305 (newFullPath.size() > 0)) {
3306 if (oldFullPath.size() != newFullPath.size()) {
3309 if (oldFullPath.at(oldFullPath.size()-1).GetTransform () == newFullPath.at(newFullPath.size()-1).GetTransform ()) {
3310 newCpNumber = newFullPath.at(newFullPath.size()-1).GetCopyNo();
3311 oldCpNumber = oldFullPath.at(oldFullPath.size()-1).GetCopyNo();
3320 if (oldCpNumber == -1) {
3321 oldCpNumber = parentOldItem->data(1,Qt::UserRole).toInt();
3323 if (newCpNumber == -1) {
3324 newCpNumber = parentNewItem->data(1,Qt::UserRole).toInt();
3326 if ((oldCpNumber != newCpNumber) ||
3328 (parentOldItem->text(0) != parentNewItem->text(0)) ) {
3331 }
else if ((parentOldItem->text(0) != parentNewItem->text(0)) ||
3332 (parentOldItem->text(3) != parentNewItem->text(3))) {
3335 parentOldItem = parentOldItem->parent();
3336 parentNewItem = parentNewItem->parent();
3347 ,
const std::string& modelDescription
3351 QString modelShortName = getModelShortName(model);
3356 const G4Text& g4Text =
dynamic_cast<const G4Text&
>(visible);
3359 catch (
const std::bad_cast&) {
3366 if (g4Marker.
GetInfo() !=
"") {
3367 modelShortName = g4Marker.
GetInfo();
3370 catch (
const std::bad_cast&) {}
3372 if (modelShortName ==
"") {
3376 if (fSceneTreeComponentTreeWidget == NULL) {
3377 createSceneTreeComponent();
3381 if (fSceneTreeComponentTreeWidget == NULL) {
3385 fSceneTreeComponentTreeWidget->blockSignals(
true);
3389 QList<QTreeWidgetItem *> resItem;
3390 resItem = fSceneTreeComponentTreeWidget->findItems (modelShortName, Qt::MatchExactly, 0 );
3391 QTreeWidgetItem * currentItem = NULL;
3392 const PVPath tmpFullPath;
3394 if (resItem.empty()) {
3395 currentItem = createTreeWidgetItem(tmpFullPath,
3404 currentItem = resItem.first();
3408 const QList<QTreeWidgetItem *>&
3409 resItems = fSceneTreeComponentTreeWidget->findItems (QString(modelDescription.c_str()), Qt::MatchFixedString| Qt::MatchCaseSensitive|Qt::MatchRecursive, 0 );
3411 bool alreadyPresent =
false;
3412 for (
int i = 0; i < resItems.size(); ++i) {
3413 if (currentPOIndex == resItems.at(i)->data(0,Qt::UserRole).toInt()) {
3414 alreadyPresent =
true;
3417 if (!alreadyPresent) {
3418 createTreeWidgetItem(tmpFullPath,
3427 fSceneTreeComponentTreeWidget->blockSignals(
false);
3435QString G4OpenGLQtViewer::getModelShortName(
const G4String& model) {
3437 QString modelShortName = model.data();
3438 if (modelShortName.mid(0,modelShortName.indexOf(
" ")) ==
"G4PhysicalVolumeModel") {
3439 modelShortName = fTouchableVolumes;
3441 if (modelShortName.mid(0,2) ==
"G4") {
3442 modelShortName = modelShortName.mid(2);
3444 if (modelShortName.indexOf(
"Model") != -1) {
3445 modelShortName = modelShortName.mid(0,modelShortName.indexOf(
"Model"));
3448 return modelShortName;
3456 if (fSceneTreeComponentTreeWidget == NULL) {
3462 if (fLastSceneTreeWidgetAskForIterator != fLastSceneTreeWidgetAskForIteratorEnd) {
3463 fLastSceneTreeWidgetAskForIterator++;
3465 QTreeWidgetItem* item = getTreeWidgetItem(POindex);
3468 if ( item->checkState(0) == Qt::Checked) {
3476bool G4OpenGLQtViewer::parseAndCheckVisibility(QTreeWidgetItem * treeNode,
int POindex){
3477 bool isFound =
false;
3478 for (
int i = 0; i < treeNode->childCount() ; ++i) {
3480 if (treeNode->child(i)->data(0,Qt::UserRole).toInt() == POindex) {
3481 if (treeNode->child(i)->checkState(0) == Qt::Checked) {
3485 isFound = parseAndCheckVisibility(treeNode->child(i),POindex);
3494std::string G4OpenGLQtViewer::parseSceneTreeAndSaveState(){
3495 std::string commandLine =
"";
3496 for (
int b=0;b<fSceneTreeComponentTreeWidget->topLevelItemCount();b++) {
3497 commandLine += parseSceneTreeElementAndSaveState(fSceneTreeComponentTreeWidget->topLevelItem(b),1)+
"\n";
3499 if (commandLine !=
"") {
3500 commandLine = std::string(
"# Disable auto refresh and quieten vis messages whilst scene and\n") +
3501 "# trajectories are established:\n" +
3502 "/vis/viewer/set/autoRefresh false\n" +
3503 "/vis/verbose errors" +
3505 "# Re-establish auto refreshing and verbosity:\n" +
3506 "/vis/viewer/set/autoRefresh true\n" +
3507 "/vis/verbose confirmations\n";
3513std::string G4OpenGLQtViewer::parseSceneTreeElementAndSaveState(QTreeWidgetItem* item,
unsigned int level){
3515 std::string str( level,
' ' );
3516 std::string commandLine =
"\n#"+ str +
"PV Name: " + item->text(0).toStdString();
3518 if (item->text(3) !=
"") {
3519 commandLine +=
" LV Name: "+item->text(3).toStdString()+
"\n";
3521 commandLine +=
"/vis/geometry/set/visibility " + item->text(3).toStdString() +
" ! ";
3522 if (item->checkState(0) == Qt::Checked) {
3525 if (item->checkState(0) == Qt::Unchecked) {
3531 const QColor& c = item->data(2,Qt::UserRole).value<QColor>();
3532 std::stringstream red;
3533 red << ((double)c.red())/255;
3534 std::stringstream green;
3535 green << (double)c.green()/255;
3536 std::stringstream blue;
3537 blue << ((double)c.blue())/255;
3538 std::stringstream
alpha;
3539 alpha << ((double)c.alpha())/255;
3541 commandLine +=
"/vis/geometry/set/colour " + item->text(3).toStdString() +
" ! " + red.str() +
" " + green.str() +
" " + blue.str() +
" " +
alpha.str()+
"\n";
3544 commandLine +=
"\n";
3548 for (
int b=0;b< item->childCount();b++) {
3549 commandLine += parseSceneTreeElementAndSaveState(item->child(b),level+1);
3556void G4OpenGLQtViewer::sceneTreeComponentItemChanged(QTreeWidgetItem* item,
int) {
3558 if (fCheckSceneTreeComponentSignalLock ==
false) {
3559 fCheckSceneTreeComponentSignalLock =
true;
3561 if (item->checkState(0) == Qt::Checked) {
3564 setCheckComponent(item,checked);
3567 fCheckSceneTreeComponentSignalLock =
false;
3572void G4OpenGLQtViewer::sceneTreeComponentSelected() {
3575void G4OpenGLQtViewer::changeDepthInSceneTree (
int val){
3578 if (fSceneTreeComponentTreeWidget == NULL) {
3589 double depth = 1 + ((double)val)/1000 * ((double)fSceneTreeDepth+1);
3592 fCheckSceneTreeComponentSignalLock =
true;
3598 for (
int b=0;b<fSceneTreeComponentTreeWidget->topLevelItemCount();b++) {
3599 changeDepthOnSceneTreeItem(depth,1.,fSceneTreeComponentTreeWidget->topLevelItem(b));
3607 fCheckSceneTreeComponentSignalLock =
false;
3612void G4OpenGLQtViewer::changeColorAndTransparency(QTreeWidgetItem* item,
int) {
3617 const QColor& old = QColor(item->data(2,Qt::UserRole).value<QColor>());
3619#if QT_VERSION < 0x040500
3621 const QColor& color = QColor(QColorDialog::getRgba (old.rgba(),&a,fSceneTreeComponentTreeWidget));
3623 const QColor& color = QColorDialog::getColor(old,
3624 fSceneTreeComponentTreeWidget,
3625 " Get color and transparency",
3626 QColorDialog::ShowAlphaChannel);
3629 if (color.isValid()) {
3631 changeColorAndTransparency(item->data(0,Qt::UserRole).toInt(),
3638 changeQColorForTreeWidgetItem(item,color);
3643void G4OpenGLQtViewer::changeColorAndTransparency(GLuint index,
G4Color color) {
3647 if (iPO >= 0 && fTreeItemModels.find(iPO) != fTreeItemModels.end()) {
3648 const PVPath& fullPath = fTreeItemModels[iPO];
3650 if (fullPath.size()) {
3661 QTreeWidgetItem* item = getTreeWidgetItem(poIndex);
3665 const QColor& color = item->data(2,Qt::UserRole).value<QColor>();
3677const std::vector<G4ModelingParameters::VisAttributesModifier>*
3680 static std::vector<G4ModelingParameters::VisAttributesModifier>
3681 privateVisAttributesModifiers;
3683 privateVisAttributesModifiers.clear();
3736 return &privateVisAttributesModifiers;
3740void G4OpenGLQtViewer::changeSearchSelection()
3742 const QString& searchText = fFilterOutput->text();
3743 if (fSceneTreeComponentTreeWidget == NULL) {
3748 for (
int a=0; a<fSceneTreeComponentTreeWidget->topLevelItemCount(); a++) {
3749 fSceneTreeComponentTreeWidget->topLevelItem(a)->setExpanded(
false);
3750 fSceneTreeComponentTreeWidget->topLevelItem(a)->setSelected(
false);
3751 clearSceneTreeSelection(fSceneTreeComponentTreeWidget->topLevelItem(a));
3754 QList<QTreeWidgetItem *> itemList = fSceneTreeComponentTreeWidget->findItems (searchText,Qt::MatchContains | Qt::MatchRecursive,0);
3756 for (
int i = 0; i < itemList.size(); ++i) {
3757 QTreeWidgetItem* expandParentItem = itemList.at(i);
3758 while (expandParentItem->parent() != NULL) {
3759 expandParentItem->parent()->setExpanded(
true);
3760 expandParentItem = expandParentItem->parent();
3762 itemList.at(i)->setSelected(
true);
3768void G4OpenGLQtViewer::clearSceneTreeSelection(QTreeWidgetItem* item) {
3769 for (
int a=0; a<item->childCount(); a++) {
3770 item->child(a)->setSelected(
false);
3771 item->child(a)->setExpanded(
false);
3772 clearSceneTreeSelection(item->child(a));
3778bool G4OpenGLQtViewer::isPVVolume(QTreeWidgetItem* item) {
3779 QTreeWidgetItem* sParent = item;
3780 while (sParent->parent() != NULL) {
3781 sParent = sParent->parent();
3783 if (sParent->text(0) != fTouchableVolumes) {
3787 if (item->text(0) == fTouchableVolumes) {
3794void G4OpenGLQtViewer::changeDepthOnSceneTreeItem(
3796 ,
double currentDepth
3797 ,QTreeWidgetItem* item
3799 double transparencyLevel = 0.;
3804 if (isPVVolume(item)) {
3805 if ((lookForDepth-currentDepth) < 0) {
3806 item->setCheckState(0,Qt::Checked);
3807 updatePositivePoIndexSceneTreeWidgetQuickMap(item->data(0,Qt::UserRole).toInt(),item);
3808 transparencyLevel = 1;
3809 }
else if ((lookForDepth-currentDepth) > 1 ){
3810 item->setCheckState(0,Qt::Unchecked);
3811 updatePositivePoIndexSceneTreeWidgetQuickMap(item->data(0,Qt::UserRole).toInt(),item);
3812 transparencyLevel = 0;
3814 item->setCheckState(0,Qt::Checked);
3815 updatePositivePoIndexSceneTreeWidgetQuickMap(item->data(0,Qt::UserRole).toInt(),item);
3816 transparencyLevel = 1-(lookForDepth-currentDepth);
3820 if (item->data(0,Qt::UserRole).toInt() >= 0) {
3833 if (((color.
GetAlpha()-transparencyLevel) > 0.000001) ||
3834 ((color.
GetAlpha()-transparencyLevel) < -0.000001)) {
3835 if ((item->text(3) !=
"")) {
3841 changeQColorForTreeWidgetItem(item,QColor((
int)(color.
GetRed()*255),
3844 (
int)(transparencyLevel*255)));
3849 for (
int b=0;b< item->childCount();b++) {
3850 changeDepthOnSceneTreeItem(lookForDepth,currentDepth+1,item->child(b));
3858 if (fSceneTreeComponentTreeWidget) {
3860 if (fSceneTreeComponentTreeWidget->topLevelItemCount () > 0) {
3862 fPVRootNodeCreate =
false;
3865 fOldPositivePoIndexSceneTreeWidgetQuickMap.clear();
3866 fOldNullPoIndexSceneTreeWidgetQuickVector.clear();
3867 fOldTreeItemModels.clear();
3870 for (
int b =0; b <fSceneTreeComponentTreeWidget->topLevelItemCount();b++) {
3879 int poIndex = fSceneTreeComponentTreeWidget->topLevelItem(b)->data(0,Qt::UserRole).toInt();
3880 if (poIndex != -1) {
3881 fOldPositivePoIndexSceneTreeWidgetQuickMap.insert(std::pair <int, QTreeWidgetItem*> (poIndex,cloneWidgetItem(fSceneTreeComponentTreeWidget->topLevelItem(b))));
3883 fOldNullPoIndexSceneTreeWidgetQuickVector.push_back(cloneWidgetItem(fSceneTreeComponentTreeWidget->topLevelItem(b)));
3887 cloneSceneTree(fSceneTreeComponentTreeWidget->topLevelItem(b));
3891 fOldTreeItemModels.insert(fTreeItemModels.begin(), fTreeItemModels.end());
3894 int tmp2 = fSceneTreeComponentTreeWidget->topLevelItemCount();
3896 delete fSceneTreeComponentTreeWidget->takeTopLevelItem (0);
3897 tmp2 = fSceneTreeComponentTreeWidget->topLevelItemCount();
3899 fPositivePoIndexSceneTreeWidgetQuickMap.clear();
3902 fOldLastSceneTreeWidgetAskForIterator = fOldPositivePoIndexSceneTreeWidgetQuickMap.begin();
3903 fOldLastSceneTreeWidgetAskForIteratorEnd = fOldPositivePoIndexSceneTreeWidgetQuickMap.end();
3904 fSceneTreeDepth = 1;
3905 fModelShortNameItem = NULL;
3906 fMaxPOindexInserted = -1;
3919QTreeWidgetItem * G4OpenGLQtViewer::cloneWidgetItem(QTreeWidgetItem* item) {
3921 QTreeWidgetItem* cloneItem =
new QTreeWidgetItem();
3925 cloneItem->setText(0,item->text(0));
3926 cloneItem->setData(1,Qt::UserRole,item->data(1,Qt::UserRole).toInt());
3927 cloneItem->setText(2,item->text(2));
3928 cloneItem->setData(0, Qt::UserRole,item->data(0,Qt::UserRole).toInt());
3929 cloneItem->setText(3,item->text(3));
3930 cloneItem->setFlags(item->flags());
3931 cloneItem->setToolTip(0,item->toolTip(0));
3932 cloneItem->setCheckState(0,item->checkState(0));
3933 cloneItem->setSelected(item->isSelected());
3934 cloneItem->setExpanded(item->isExpanded ());
3936 cloneItem->setData(2,Qt::UserRole,item->data(2,Qt::UserRole).value<QColor>());
3945void G4OpenGLQtViewer::cloneSceneTree(
3946 QTreeWidgetItem* rootItem
3949 for (
int b=0;b< rootItem->childCount();b++) {
3951 QTreeWidgetItem *child = rootItem->child(b);
3954 int poIndex = child->data(0,Qt::UserRole).toInt();
3955 if (poIndex != -1) {
3956 fOldPositivePoIndexSceneTreeWidgetQuickMap.insert(std::pair <int, QTreeWidgetItem*> (poIndex,cloneWidgetItem(child)));
3958 fOldNullPoIndexSceneTreeWidgetQuickVector.push_back(cloneWidgetItem(child));
3960 cloneSceneTree(child);
3968 void G4OpenGLQtViewer::updatePositivePoIndexSceneTreeWidgetQuickMap(
int POindex,QTreeWidgetItem* item) {
3971 std::map <int, QTreeWidgetItem*>::iterator i;
3972 i = fPositivePoIndexSceneTreeWidgetQuickMap.find(POindex);
3974 if (i == fPositivePoIndexSceneTreeWidgetQuickMap.end()) {
3975 fPositivePoIndexSceneTreeWidgetQuickMap.insert(std::pair <int, QTreeWidgetItem*> (POindex,item) );
3976 fLastSceneTreeWidgetAskForIterator = fPositivePoIndexSceneTreeWidgetQuickMap.end();
3977 fLastSceneTreeWidgetAskForIteratorEnd = fPositivePoIndexSceneTreeWidgetQuickMap.end();
3985void G4OpenGLQtViewer::changeQColorForTreeWidgetItem(QTreeWidgetItem* item,
const QColor& qc) {
3987 int POIndex = item->data(0,Qt::UserRole).toInt();
3988 updatePositivePoIndexSceneTreeWidgetQuickMap(POIndex,item );
3990 QPixmap pixmap = QPixmap(QSize(16, 16));
3991 if (item->data(0,Qt::UserRole).toInt() != -1) {
3994 pixmap.fill (QColor(255,255,255,255));
3996 QPainter painter(&pixmap);
3997 painter.setPen(Qt::black);
3998 painter.drawRect(0,0,15,15);
4000 item->setIcon(0,pixmap);
4001 item->setData(2,Qt::UserRole,qc);
4010QTreeWidgetItem* G4OpenGLQtViewer::getTreeWidgetItem(
int POindex){
4013 if (POindex == -1) {
4017 if (fPositivePoIndexSceneTreeWidgetQuickMap.size() == 0){
4021 if (fLastSceneTreeWidgetAskForIterator != fLastSceneTreeWidgetAskForIteratorEnd) {
4022 if (POindex == fLastSceneTreeWidgetAskForIterator->first) {
4023 if (fLastSceneTreeWidgetAskForIterator->second != NULL) {
4024 return fLastSceneTreeWidgetAskForIterator->second;
4030 fLastSceneTreeWidgetAskForIterator = fPositivePoIndexSceneTreeWidgetQuickMap.find(POindex);
4031 fLastSceneTreeWidgetAskForIteratorEnd = fPositivePoIndexSceneTreeWidgetQuickMap.end();
4033 if (fLastSceneTreeWidgetAskForIterator != fPositivePoIndexSceneTreeWidgetQuickMap.end()) {
4034 return fLastSceneTreeWidgetAskForIterator->second;
4043QTreeWidgetItem* G4OpenGLQtViewer::getOldTreeWidgetItem(
int POindex){
4047 if (POindex == -1) {
4051 if (fOldPositivePoIndexSceneTreeWidgetQuickMap.size() == 0){
4057 if (fOldLastSceneTreeWidgetAskForIterator != fOldLastSceneTreeWidgetAskForIteratorEnd) {
4058 fOldLastSceneTreeWidgetAskForIterator++;
4061 if (fOldLastSceneTreeWidgetAskForIterator != fOldPositivePoIndexSceneTreeWidgetQuickMap.end()) {
4062 if (POindex == fOldLastSceneTreeWidgetAskForIterator->first) {
4063 if (fOldLastSceneTreeWidgetAskForIterator->second != NULL) {
4064 return fOldLastSceneTreeWidgetAskForIterator->second;
4070 fOldLastSceneTreeWidgetAskForIterator = fOldPositivePoIndexSceneTreeWidgetQuickMap.find(POindex);
4071 fOldLastSceneTreeWidgetAskForIteratorEnd = fOldPositivePoIndexSceneTreeWidgetQuickMap.end();
4073 if (fOldLastSceneTreeWidgetAskForIterator != fOldPositivePoIndexSceneTreeWidgetQuickMap.end()) {
4074 return fOldLastSceneTreeWidgetAskForIterator->second;
4087 if (fUISceneTreeWidget == NULL) {
4090 if (fSceneTreeComponentTreeWidget == NULL) {
4095 fSceneTreeComponentTreeWidget->sortItems (0, Qt::AscendingOrder );
4119 fDrawingWireframe->setChecked(
true);
4120 fDrawingLineRemoval->setChecked(
false);
4121 fDrawingSurfaceRemoval->setChecked(
false);
4122 fDrawingLineSurfaceRemoval->setChecked(
false);
4127 fDrawingLineRemoval->setChecked(
true);
4128 fDrawingWireframe->setChecked(
false);
4129 fDrawingSurfaceRemoval->setChecked(
false);
4130 fDrawingLineSurfaceRemoval->setChecked(
false);
4135 fDrawingSurfaceRemoval->setChecked(
true);
4136 fDrawingWireframe->setChecked(
false);
4137 fDrawingLineRemoval->setChecked(
false);
4138 fDrawingLineSurfaceRemoval->setChecked(
false);
4143 fDrawingLineSurfaceRemoval->setChecked(
true);
4144 fDrawingWireframe->setChecked(
false);
4145 fDrawingLineRemoval->setChecked(
false);
4146 fDrawingSurfaceRemoval->setChecked(
false);
4147 fDrawingLineSurfaceRemoval->setChecked(
false);
4157 fProjectionOrtho->setChecked(
true);
4158 fProjectionPerspective->setChecked(
false);
4163 fProjectionPerspective->setChecked(
true);
4164 fProjectionOrtho->setChecked(
false);
4170 if (fUiQt && fContextMenu) {
4172 fMousePickAction->setChecked(
true);
4173 fMouseZoomOutAction->setChecked(
false);
4174 fMouseZoomInAction->setChecked(
false);
4175 fMouseRotateAction->setChecked(
false);
4176 fMouseMoveAction->setChecked(
false);
4178 fMouseZoomOutAction->setChecked(
true);
4179 fMousePickAction->setChecked(
false);
4180 fMouseZoomInAction->setChecked(
false);
4181 fMouseRotateAction->setChecked(
false);
4182 fMouseMoveAction->setChecked(
false);
4184 fMouseZoomInAction->setChecked(
true);
4185 fMousePickAction->setChecked(
false);
4186 fMouseZoomOutAction->setChecked(
false);
4187 fMouseRotateAction->setChecked(
false);
4188 fMouseMoveAction->setChecked(
false);
4190 fMouseRotateAction->setChecked(
true);
4191 fMousePickAction->setChecked(
false);
4192 fMouseZoomOutAction->setChecked(
false);
4193 fMouseZoomInAction->setChecked(
false);
4194 fMouseMoveAction->setChecked(
false);
4196 fMouseMoveAction->setChecked(
true);
4197 fMousePickAction->setChecked(
false);
4198 fMouseZoomOutAction->setChecked(
false);
4199 fMouseZoomInAction->setChecked(
false);
4200 fMouseRotateAction->setChecked(
false);
4210 if (!fSceneTreeWidget) {
4211 createSceneTreeWidget();
4227 if (!fViewerPropertiesTableWidget) {
4228 createViewerPropertiesWidget();
4230 int treeWidgetInfosIgnoredCommands = 0;
4240 if ((path->
GetCommandEntry()-fTreeWidgetInfosIgnoredCommands) != fViewerPropertiesTableWidget->rowCount()) {
4241 fViewerPropertiesTableWidget->clear();
4244 fViewerPropertiesTableWidget->blockSignals(
true);
4247 fViewerPropertiesTableWidget->setColumnCount (2);
4248 fViewerPropertiesTableWidget->setRowCount (path->
GetCommandEntry()-fTreeWidgetInfosIgnoredCommands);
4249 fViewerPropertiesTableWidget->setHorizontalHeaderLabels(QStringList() << tr(
"Property")
4251 fViewerPropertiesTableWidget->verticalHeader()->setVisible(
false);
4252 fViewerPropertiesTableWidget->setAlternatingRowColors (
true);
4260 QString params =
"";
4281 params = QString().number(
fVP. IsCulling ());
4286 params =
"intersection";
4311 }
else if(commandTmp->
GetCommandName() ==
"globalLineWidthScale") {
4342 params = QString().number(direction.
theta()/CLHEP::degree)+
" "+ QString().number(direction.
phi()/CLHEP::degree)+
" deg";
4353 }
else if(commandTmp->
GetCommandName() ==
"lineSegmentsPerCircle") {
4365 params =
"orthogonal";
4367 params = QString(
"perspective ") + QString().number(
fVP.
GetFieldHalfAngle()/CLHEP::degree) +
" deg";
4372 params =
"constrainUpDirection";
4374 params =
"freeRotation";
4379 params = QString(
"on ") +
4390 params =
"wireframe";
4405 params = QString().number(up.
theta()/CLHEP::degree)+
" "+ QString().number(up.
phi()/CLHEP::degree)+
" deg";
4413 params = QString().number(up.
x())+
" "+ QString().number(up.
y())+
" "+QString().number(up.
z())+
" ";
4418 params = QString().number(direction.
theta()/CLHEP::degree)+
" "+ QString().number(direction.
phi()/CLHEP::degree)+
" deg";
4426 params = QString().number(direction.
x())+
" "+ QString().number(direction.
y())+
" "+QString().number(direction.
z());
4456 QTableWidgetItem *nameItem;
4457 QTableWidgetItem *paramItem;
4460 QList<QTableWidgetItem *> list = fViewerPropertiesTableWidget->findItems (commandTmp->
GetCommandName().data(),Qt::MatchExactly);
4461 if (list.size() == 1) {
4462 nameItem = list.first();
4463 paramItem = fViewerPropertiesTableWidget->item(nameItem->row(),1);
4466 nameItem =
new QTableWidgetItem();
4467 paramItem =
new QTableWidgetItem();
4468 fViewerPropertiesTableWidget->setItem(a-treeWidgetInfosIgnoredCommands, 0, nameItem);
4469 fViewerPropertiesTableWidget->setItem(a-treeWidgetInfosIgnoredCommands, 1, paramItem);
4474 for(
G4int i_thGuidance=0; i_thGuidance < n_guidanceEntry; i_thGuidance++ ) {
4475 guidance += QString((
char*)(commandTmp->
GetGuidanceLine(i_thGuidance)).data()) +
"\n";
4478 nameItem->setToolTip(guidance);
4479 paramItem->setToolTip(GetCommandParameterList(commandTmp));
4481 fViewerPropertiesTableWidget->setRowHeight(a-treeWidgetInfosIgnoredCommands,15);
4486 paramItem->setText(params);
4488 nameItem->setFlags(Qt::NoItemFlags);
4489 nameItem->setForeground(QBrush());
4492 treeWidgetInfosIgnoredCommands++;
4496 for (
int i=0; i<treeWidgetInfosIgnoredCommands; i++) {
4497 fViewerPropertiesTableWidget->removeRow (fViewerPropertiesTableWidget->rowCount() - 1);
4501 if (!fViewerPropertiesTableWidgetIsInit) {
4502 fViewerPropertiesTableWidgetIsInit =
true;
4504 fViewerPropertiesTableWidget->resizeColumnsToContents();
4506 int x = fViewerPropertiesTableWidget->horizontalHeader()->length();
4507 int y = fViewerPropertiesTableWidget->verticalHeader()->length()+ fViewerPropertiesTableWidget->horizontalHeader()->sizeHint().height() + 2;
4513 QDialog* dial =
static_cast<QDialog*
> (fUIViewerPropertiesWidget->parent());
4515 dial->resize(x+56,y+46);
4518 fViewerPropertiesTableWidget->blockSignals(
false);
4520 fTreeWidgetInfosIgnoredCommands = treeWidgetInfosIgnoredCommands;
4528 fLastPickPoint = QPoint(aX,aY);
4534 if (!fPickInfosWidget) {
4535 createPickInfosWidget();
4538 const std::vector < G4OpenGLViewerPickMap* > & pickMapVector =
GetPickDetails(aX,aY);
4541 if (fPickInfosWidget) {
4542 QLayoutItem * wItem;
4543 if (fPickInfosWidget->layout()->count()) {
4544 while ((wItem = fPickInfosWidget->layout()->takeAt(0)) != 0) {
4545 delete wItem->widget();
4551 if (!fPickInfosWidget) {
4552 createPickInfosWidget();
4557#if QT_VERSION < 0x050600
4558 delete fSignalMapperPicking;
4559 fSignalMapperPicking =
new QSignalMapper(
this);
4563 G4int nPickedObjectsWithAttributes = 0;
4564 for (
unsigned int a=0; a< pickMapVector.size(); a++) {
4565 const auto& pickMap = pickMapVector[a];
4567 std::ostringstream label;
4568 std::ostringstream content;
4569 std::string txt = pickMap->getAttributes()[0].data();
4570 if (pickMapVector[a]->getAttributes().size()) {
4571 ++nPickedObjectsWithAttributes;
4573 std::size_t pos1 = txt.find(
':');
4574 std::string storeKey = txt.substr(0,pos1);
4576 if (storeKey ==
"G4PhysicalVolumeModel") {
4579 std::size_t pos2 = txt.find(
':',pos1+1);
4580 std::size_t pos3 = txt.find(
'\n',pos2+1);
4581 label << txt.substr(pos2+1,pos3-pos2-1);
4583 }
else if (storeKey ==
"G4TrajectoriesModel") {
4585 label <<
"Trajectory:";
4586 std::size_t pos2 = txt.find(
':',pos1+1);
4587 std::size_t pos3 = txt.find(
'\n',pos2+1);
4588 label <<
" Run:" << txt.substr(pos2+1,pos3-pos2-1);
4589 std::size_t pos4 = txt.find(
':',pos3+1);
4590 std::size_t pos5 = txt.find(
'\n',pos4+1);
4591 label <<
", Event:" << txt.substr(pos4+1,pos5-pos4-1);
4595 label <<
"Hit number:" << a <<
", PickName: " << pickMap->getPickName();
4600 content << pickMap->print().data();
4601 G4int thisPickName = pickMap->getPickName();
4602 while (++a < pickMapVector.size()) {
4603 const auto& a_pickMap = pickMapVector[a];
4604 if (a_pickMap->getPickName() == thisPickName) {
4605 content << a_pickMap->print().data();
4612 QPushButton* pickCoutButton =
new QPushButton(label.str().c_str());
4613 pickCoutButton->setStyleSheet (
"text-align: left; padding: 1px; border: 0px;");
4614 pickCoutButton->setIcon(*fTreeIconClosed);
4615 fPickInfosWidget->layout()->addWidget(pickCoutButton);
4620 newStr = QStringList(QString(content.str().c_str()).trimmed());
4622 QTextEdit* ed =
new QTextEdit();
4623 ed->setReadOnly(
true);
4624 fPickInfosWidget->layout()->addWidget(ed);
4625 ed->setVisible((
false));
4626 ed->append(newStr.join(
""));
4628#if QT_VERSION < 0x050600
4629 connect(pickCoutButton, SIGNAL(clicked()), fSignalMapperPicking, SLOT(map()));
4630 fSignalMapperPicking->setMapping(pickCoutButton,fPickInfosWidget->layout()->count()-1);
4632 std::cout << pickCoutButton->text().toStdString() <<
" "<< fPickInfosWidget->layout()->count()-1<< std::endl;
4633 int tmp = fPickInfosWidget->layout()->count()-1;
4634 connect(pickCoutButton, &QPushButton::clicked , [
this, tmp](){ this->toggleSceneTreeComponentPickingCout(tmp);});
4638#if QT_VERSION < 0x050600
4639 connect(fSignalMapperPicking, SIGNAL(mapped(
int)),
this, SLOT(toggleSceneTreeComponentPickingCout(
int)));
4643 QLabel * pushUp =
new QLabel(
"");
4644 QSizePolicy vPolicy = QSizePolicy(QSizePolicy::Minimum,QSizePolicy::Minimum);
4645 vPolicy.setVerticalStretch(10);
4646 pushUp->setSizePolicy(vPolicy);
4647 fPickInfosWidget->layout()->addWidget(pushUp);
4652 changeColorAndTransparency(fLastHighlightName,fLastHighlightColor);
4654 if (pickMapVector.size() > 0 ) {
4656 fLastHighlightName = pickMapVector[0]->getPickName();
4659 changeColorAndTransparency(fLastHighlightName,
G4Color(1,1,1,1));
4663 QDialog* dial =
static_cast<QDialog*
> (fUIPickInfosWidget->parent());
4666 std::ostringstream oss;
4667 if (nPickedObjectsWithAttributes == 0) {
4669 }
else if (nPickedObjectsWithAttributes == 1) {
4672 oss << nPickedObjectsWithAttributes <<
" objects";
4674 oss <<
" selected - " <<
GetName();
4675 dial->setWindowTitle(oss.str().c_str());
4678 fPickInfosScrollArea->setVisible(
true);
4682void G4OpenGLQtViewer::toggleSceneTreeComponentPickingCout(
int pickItem) {
4687 for (
int a=0; a<fPickInfosWidget->layout()->count(); a++) {
4688 w = fPickInfosWidget->layout()->itemAt(a)->widget();
4689 QTextEdit* ed =
dynamic_cast<QTextEdit*
>(w);
4690 QPushButton* button;
4692 if (a == pickItem) {
4693 w->setVisible(!w->isVisible());
4695 w->setVisible(
false);
4698 button =
dynamic_cast<QPushButton*
>(fPickInfosWidget->layout()->itemAt(a-1)->widget());
4700 if (button->isVisible()) {
4701 button->setIcon(*fTreeIconOpen);
4703 button->setIcon(*fTreeIconClosed);
4712void G4OpenGLQtViewer::currentTabActivated(
int currentTab) {
4714 createViewerPropertiesWidget();
4715 createPickInfosWidget();
4716 createSceneTreeWidget();
4721void G4OpenGLQtViewer::tableWidgetViewerSetItemChanged(QTableWidgetItem * item) {
4724 QTableWidgetItem* previous = fViewerPropertiesTableWidget->item(fViewerPropertiesTableWidget->row(item),0);
4726 fViewerPropertiesTableWidget->blockSignals(
true);
4728 + previous->text().toStdString()
4730 + item->text().toStdString()).c_str());
4731 fViewerPropertiesTableWidget->blockSignals(
false);
4755QString G4OpenGLQtViewer::GetCommandParameterList (
4762 if( n_parameterEntry > 0 ) {
4767 for(
G4int i_thParameter=0; i_thParameter<n_parameterEntry; i_thParameter++ ) {
4769 txt +=
"\nParameter : " + QString((
char*)(param->
GetParameterName()).data()) +
"\n";
4772 txt +=
" Parameter type : " + QString(QChar(param->
GetParameterType())) +
"\n";
4774 txt +=
" Omittable : True\n";
4776 txt +=
" Omittable : False\n";
4779 txt +=
" Default value : taken from the current value\n";
4781 txt +=
" Default value : " + QString((
char*)(param->
GetDefaultValue()).data())+
"\n";
4784 txt +=
" Parameter range : " + QString((
char*)(param->
GetParameterRange()).data())+
"\n";
4794#ifdef G4MULTITHREADED
4796void G4OpenGLQtViewer::DoneWithMasterThread()
4802 if(!lWaitForVisSubThreadQtOpenGLContextInitialized->
owns_lock())
4803 lWaitForVisSubThreadQtOpenGLContextInitialized->
lock();
4806void G4OpenGLQtViewer::SwitchToVisSubThread()
4810 QGLWidget* qGLW =
dynamic_cast<QGLWidget*
> (
fGLWidget) ;
4816 SetQGLContextVisSubThread(QThread::currentThread());
4822 if(!lWaitForVisSubThreadQtOpenGLContextMoved->
owns_lock())
4823 lWaitForVisSubThreadQtOpenGLContextMoved->
lock();
4827 lWaitForVisSubThreadQtOpenGLContextMoved);
4830 qGLW->makeCurrent();
4833void G4OpenGLQtViewer::DoneWithVisSubThread()
4836 QGLWidget* qGLW =
dynamic_cast<QGLWidget*
> (
fGLWidget) ;
4842 qGLW->doneCurrent();
4844#if QT_VERSION > 0x050000
4846 qGLW->context()->moveToThread(fQGLContextMainThread);
4850void G4OpenGLQtViewer::SwitchToMasterThread()
4854 QGLWidget* qGLW =
dynamic_cast<QGLWidget*
> (
fGLWidget) ;
4861 if(lWaitForVisSubThreadQtOpenGLContextInitialized->
owns_lock())
4862 lWaitForVisSubThreadQtOpenGLContextInitialized->
unlock();
4864 qGLW->makeCurrent();
4868void G4OpenGLQtViewer::MovingToVisSubThread(){
4871 QGLWidget* qGLW =
dynamic_cast<QGLWidget*
> (
fGLWidget) ;
4878 if(!lWaitForVisSubThreadQtOpenGLContextInitialized->
owns_lock())
4879 lWaitForVisSubThreadQtOpenGLContextInitialized->
lock();
4883 lWaitForVisSubThreadQtOpenGLContextInitialized);
4886 SetQGLContextMainThread(QThread::currentThread());
4889 qGLW->doneCurrent();
4890#if QT_VERSION > 0x050000
4891 qGLW->context()->moveToThread(fQGLContextVisSubThread);
G4TemplateAutoLock< G4Mutex > G4AutoLock
#define G4CONDITION_INITIALIZER
#define G4MUTEX_INITIALIZER
#define G4CONDITIONWAIT(cond, mutex)
#define G4CONDITIONBROADCAST(cond)
G4GLOB_DLL std::ostream G4cerr
G4GLOB_DLL std::ostream G4cout
G4double GetAlpha() const
G4double GetGreen() const
bool checkSaveFileNameParameters()
void setRecordingInfos(QString)
void setRecordingStatus(QString)
bool checkTempFolderParameters()
bool checkEncoderSwParameters()
void G4MouseReleaseEvent(QMouseEvent *evnt)
void rotateQtSceneToggle(float, float)
void G4MouseMoveEvent(QMouseEvent *event)
void G4keyPressEvent(QKeyEvent *event)
void updateViewerPropertiesTableWidget()
void addNonPVSceneTreeElement(const G4String &model, int currentPVPOIndex, const std::string &modelDescription, const G4Visible &visible)
void displayRecordingStatus()
QString getSaveFileName()
void G4MousePressEvent(QMouseEvent *event)
void G4wheelEvent(QWheelEvent *event)
void G4MouseDoubleClickEvent()
void updateSceneTreeWidget()
G4OpenGLQtViewer(G4OpenGLSceneHandler &scene)
bool isTouchableVisible(int POindex)
void moveScene(float, float, float, bool)
void G4manageContextMenuEvent(QContextMenuEvent *e)
QString getTempFolderPath()
void rotateQtScene(float, float)
bool exportImage(std::string name="", int width=-1, int height=-1)
void updateToolbarAndMouseContextMenu()
void updateKeyModifierState(const Qt::KeyboardModifiers &)
void G4keyReleaseEvent(QKeyEvent *event)
G4Colour getColorForPoIndex(int poIndex)
void updatePickInfosWidget(int, int)
virtual ~G4OpenGLQtViewer()
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
void DrawText(const G4Text &)
QString setEncoderPath(QString path)
virtual void CreateMainWindow(QGLWidget *, const QString &)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
bool generateMpegEncoderParameters()
virtual void updateQWidget()=0
QString setSaveFileName(QString path)
void addPVSceneTreeElement(const G4String &model, G4PhysicalVolumeModel *pPVModel, int currentPVPOIndex)
const std::vector< G4ModelingParameters::VisAttributesModifier > * GetPrivateVisAttributesModifiers() const
QString setTempFolderPath(QString path)
void displaySceneTreeComponent()
std::vector< std::string > fExportImageFormatVector
void rotateSceneToggle(G4double dx, G4double dy)
unsigned int getWinHeight() const
std::string fExportImageFormat
void ResizeWindow(unsigned int, unsigned int)
unsigned int getWinWidth() const
std::string fDefaultExportImageFormat
bool setExportFilename(G4String name, G4bool inc=true)
void addExportImageFormat(std::string format)
G4bool antialiasing_enabled
virtual void DrawText(const G4Text &)
void setExportSize(G4int, G4int)
void rotateScene(G4double dx, G4double dy)
G4bool transparency_enabled
virtual bool exportImage(std::string name="", int width=-1, int height=-1)
std::string getRealPrintFilename()
GLdouble getSceneNearWidth()
const std::vector< G4OpenGLViewerPickMap * > & GetPickDetails(GLdouble x, GLdouble y)
const G4Transform3D & GetTransformation() const
const std::vector< G4PhysicalVolumeNodeID > & GetFullPVPath() const
static G4Qt * getInstance()
const G4Point3D & GetStandardTargetPoint() const
bool owns_lock() const noexcept
G4double GetYOffset() const
G4double GetXOffset() const
void SetIconPickSelected()
G4bool AddTabWidget(QWidget *, QString)
QWidget * GetViewerPropertiesWidget()
void SetIconOrthoSelected()
G4bool IsIconRotateSelected()
G4bool IsIconZoomInSelected()
G4bool IsIconMoveSelected()
void SetIconZoomInSelected()
QPixmap * getSearchIcon()
G4bool IsIconZoomOutSelected()
QWidget * GetSceneTreeWidget()
void SetIconZoomOutSelected()
void SetIconHLRSelected()
void SetIconPerspectiveSelected()
QTabWidget * GetViewerTabWidget()
QWidget * GetPickInfosWidget()
void SetIconSolidSelected()
void SetIconRotateSelected()
G4bool IsIconPickSelected()
void SetIconWireframeSelected()
void SetIconMoveSelected()
void SetIconHLHSRSelected()
G4int GetCommandEntry() const
G4UIcommand * GetCommand(G4int i)
G4UIcommandTree * FindCommandTree(const char *commandPath)
std::size_t GetParameterEntries() const
const G4String & GetGuidanceLine(G4int i) const
G4UIparameter * GetParameter(G4int i) const
std::size_t GetGuidanceEntries() const
const G4String & GetCommandName() const
G4UIcommandTree * GetTree() const
G4int ApplyCommand(const char *aCommand)
G4UIsession * GetG4UIWindow() const
static G4UImanager * GetUIpointer()
const G4String & GetParameterCandidates() const
const G4String & GetParameterGuidance() const
G4bool IsOmittable() const
const G4String & GetParameterRange() const
G4bool GetCurrentAsDefault() const
char GetParameterType() const
const G4String & GetParameterName() const
const G4String & GetDefaultValue() const
G4Interactor GetMainInteractor()
G4Point3D GetPosition() const
const G4Colour & GetTextColour(const G4Text &)
const G4Colour & GetColour()
G4Scene * GetScene() const
G4double GetMarkerSize(const G4VMarker &, MarkerSizeType &)
void SetTouchable(const std::vector< G4PhysicalVolumeModel::G4PhysicalVolumeNodeID > &fullPath)
const G4String & GetName() const
G4VSceneHandler & fSceneHandler
void SetNeedKernelVisit(G4bool need)
void TouchableSetVisibility(const std::vector< G4PhysicalVolumeModel::G4PhysicalVolumeNodeID > &fullPath, G4bool visibility)
void TouchableSetColour(const std::vector< G4PhysicalVolumeModel::G4PhysicalVolumeNodeID > &fullPath, const G4Colour &)
void SetAutoRefresh(G4bool)
void SetBackgroundColour(const G4Colour &)
G4int GetNoOfSides() const
G4int GetWindowAbsoluteLocationHintY(G4int) const
CutawayMode GetCutawayMode() const
G4double GetExplodeFactor() const
G4bool IsMarkerNotHidden() const
unsigned int GetWindowSizeHintX() const
G4double GetGlobalLineWidthScale() const
void SetPerspectiveProjection(G4double fieldHalfAngle=30. *CLHEP::deg)
void SetDefaultColour(const G4Colour &)
void SetDrawingStyle(G4ViewParameters::DrawingStyle style)
const G4Colour & GetBackgroundColour() const
const G4Vector3D & GetLightpointDirection() const
void SetDefaultTextColour(const G4Colour &)
const G4Vector3D & GetViewpointDirection() const
const G4Point3D & GetCurrentTargetPoint() const
G4double GetFieldHalfAngle() const
const G4VisAttributes * GetDefaultTextVisAttributes() const
G4double GetZoomFactor() const
void SetOrthogonalProjection()
G4int GetWindowAbsoluteLocationHintX(G4int) const
void IncrementPan(G4double right, G4double up)
const G4Vector3D & GetUpVector() const
void SetMarkerNotHidden()
G4double GetGlobalMarkerScale() const
void SetZoomFactor(G4double zoomFactor)
const G4VisAttributes * GetDefaultVisAttributes() const
RotationStyle GetRotationStyle() const
G4bool IsAutoRefresh() const
unsigned int GetWindowSizeHintY() const
G4bool GetLightsMoveWithCamera() const
void SetAuxEdgeVisible(G4bool)
const G4Plane3D & GetSectionPlane() const
DrawingStyle GetDrawingStyle() const
G4bool IsAuxEdgeVisible() const
const G4Color & GetColor() const
virtual const G4String & GetInfo() const
Point3D< T > point(const Point3D< T > &p) const
Normal3D< T > normal() const
const char * name(G4int ptype)