58#include <qpushbutton.h>
61#include <qimagewriter.h>
64#include <qtreewidget.h>
65#include <qapplication.h>
66#include <qmessagebox.h>
67#include <qfiledialog.h>
69#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
70 #include <qelapsedtimer.h>
72#if (QT_VERSION < QT_VERSION_CHECK(5, 10, 0))
73 #include "qdesktopwidget.h"
77#include <qcolordialog.h>
84#include <qmainwindow.h>
85#include <qtablewidget.h>
86#include <qheaderview.h>
87#include <qscrollarea.h>
93#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
96#include <QOpenGLContext>
100#include "moc_G4OpenGLQtViewer.cpp"
108#ifdef G4MULTITHREADED
142 if (UI == NULL)
return;
151 bool isTabbedView =
false;
161 SIGNAL(currentChanged(
int)),
163 SLOT(currentTabActivated(
int)));
167 createSceneTreeWidget();
174 QWidget *glDialogWidget = getParentWidget();
175 if (glDialogWidget == NULL) {
178 glWidget->setParent(glDialogWidget);
179 QHBoxLayout *mainLayout =
new QHBoxLayout();
181 mainLayout->setContentsMargins(0,0,0,0);
182 mainLayout->setSpacing(0);
184 if (
fGLWidget->inherits(
"QMainWindow")) {
187 glDialogWidget->setLayout(mainLayout);
191#if (QT_VERSION >= QT_VERSION_CHECK(5, 10, 0))
192 G4int offset = QGuiApplication::primaryScreen()->availableGeometry().height()
193 - QGuiApplication::screenAt(QPoint(20,20))->availableGeometry().height();
195 G4int offset = QApplication::desktop()->height()
196 - QApplication::desktop()->availableGeometry().height();
205 glDialogWidget->show();
224 ,fRecordFrameNumber(0)
225 ,fMouseOnSceneTree(false)
227 ,fLastPickPoint(-1,-1)
230 ,fHoldKeyEvent(false)
231 ,fHoldMoveEvent(false)
232 ,fHoldRotateEvent(false)
236 ,fMovieTempFolderPath(
"")
238 ,fParameterFileName(
"ppmtompeg_encode_parameter_file.par")
239 ,fMovieParametersDialog(NULL)
240 ,fRecordingStep(WAIT)
242 ,fNbMaxFramesPerSec(100)
243 ,fNbMaxAnglePerSec(360)
244 ,fLaunchSpinDelay(100)
245 ,fUISceneTreeWidget(NULL)
246 ,fUIViewerPropertiesWidget(NULL)
247 ,fUIPickInfosWidget(NULL)
250 ,fControlKeyPress(false)
251 ,fShiftKeyPress(false)
253 ,fCheckSceneTreeComponentSignalLock(false)
254 ,fViewerPropertiesTableWidgetIsInit(false)
255 ,fSceneTreeComponentTreeWidget(NULL)
256 ,fSceneTreeWidget(NULL)
257 ,fPVRootNodeCreate(false)
261 ,fTouchableVolumes(
"Touchables")
262 ,fShortcutsDialog(NULL)
263 ,fViewerPropertiesTableWidget(NULL)
264 ,fPickInfosWidget(NULL)
265 ,fPickInfosScrollArea(NULL)
266 ,fTreeWidgetInfosIgnoredCommands(0)
267 ,fSceneTreeDepthSlider(NULL)
269 ,fModelShortNameItem(NULL)
270 ,fMaxPOindexInserted(-1)
272 ,fTreeIconClosed(NULL)
273 ,fLastExportSliderValue(80)
274 ,fLastHighlightColor(
G4Color(0,0,0,0))
275 ,fLastHighlightName(0)
278 lWaitForVisSubThreadQtOpenGLContextInitialized
279 =
new G4AutoLock(mWaitForVisSubThreadQtOpenGLContextInitialized,
281 lWaitForVisSubThreadQtOpenGLContextMoved
282 =
new G4AutoLock(mWaitForVisSubThreadQtOpenGLContextMoved,
286 if (QCoreApplication::instance () == NULL) {
291 fLastPos3 = QPoint(-1,-1);
292 fLastPos2 = QPoint(-1,-1);
293 fLastPos1 = QPoint(-1,-1);
295 initMovieParameters();
297#if (QT_VERSION < QT_VERSION_CHECK(5, 14, 0))
298 fLastEventTime =
new QTime();
300 fLastEventTime =
new QElapsedTimer();
303 fFileSavePath = QDir::currentPath();
306 QList<QByteArray> formats = QImageWriter::supportedImageFormats ();
307 for (
int i = 0; i < formats.size(); ++i) {
311 const char *
const icon1[]={
369 const char *
const icon2[]={
462 const char *
const search[] = {
474 "OOOOOOOOOOOOOOOOOOO",
475 "OOOOOOOOOOOOOOOOOOO",
476 "OOOOOOOo. .oOOOOOO",
479 "OOOOO. XOOOOX .OOOO",
482 "OOOOO. XOOOOo .OOOO",
486 "OOOOOOOOOOOOO. XOO",
487 "OOOOOOOOOOOOOO. XOO",
488 "OOOOOOOOOOOOOOOoOOO",
489 "OOOOOOOOOOOOOOOOOOO",
490 "OOOOOOOOOOOOOOOOOOO",
491 "OOOOOOOOOOOOOOOOOOO",
492 "OOOOOOOOOOOOOOOOOOO"
495 fSearchIcon =
new QPixmap(search);
496 fTreeIconOpen =
new QPixmap(icon1);
497 fTreeIconClosed =
new QPixmap(icon2);
512 if (fSceneTreeWidget != NULL) {
513 if (fSceneTreeWidget->layout() != NULL) {
514 while ((wItem = fSceneTreeWidget->layout()->takeAt(0)) != 0) {
515 delete wItem->widget();
522 delete fTreeIconOpen;
523 delete fTreeIconClosed;
525 G4cout <<removeTempFolder().toStdString().c_str() <<
G4endl;
527 delete lWaitForVisSubThreadQtOpenGLContextInitialized;
528 delete lWaitForVisSubThreadQtOpenGLContextMoved;
536void G4OpenGLQtViewer::createPopupMenu() {
538 fContextMenu =
new QMenu(
"All");
540 QMenu *mMouseAction = fContextMenu->addMenu(
"&Mouse actions");
541 fMouseRotateAction = mMouseAction->addAction(
"Rotate",
this, [
this](){ this->toggleMouseAction(1); });
542 fMouseMoveAction = mMouseAction->addAction(
"Move",
this, [
this](){ this->toggleMouseAction(2); });
543 fMousePickAction = mMouseAction->addAction(
"Pick",
this, [
this](){ this->toggleMouseAction(3); });
544 fMouseZoomOutAction = mMouseAction->addAction(
"Zoom out",
this, [
this](){ this->toggleMouseAction(4); });
545 fMouseZoomInAction = mMouseAction->addAction(
"Zoom in",
this, [
this](){ this->toggleMouseAction(5); });
546 QAction *shortcutsAction = mMouseAction->addAction(
"Show shortcuts");
548 fMouseRotateAction->setCheckable(
true);
549 fMouseMoveAction->setCheckable(
true);
550 fMousePickAction->setCheckable(
true);
551 fMouseZoomOutAction->setCheckable(
true);
552 fMouseZoomInAction->setCheckable(
true);
553 shortcutsAction->setCheckable(
false);
555 QObject::connect(shortcutsAction,
556 SIGNAL(triggered(
bool)),
558 SLOT(showShortcuts()));
561 QMenu *mStyle = fContextMenu->addMenu(
"&Style");
563 QMenu *mProjection = mStyle->addMenu(
"&Projection");
566 fProjectionOrtho = mProjection->addAction(
"Orthographic",
this, [
this](){ this->toggleProjection(
true); });
567 fProjectionPerspective = mProjection->addAction(
"Perspective",
this, [
this](){ this->toggleProjection(
false); });
569 QMenu *mDrawing = mStyle->addMenu(
"&Drawing");
570 fDrawingWireframe = mDrawing->addAction(
"Wireframe",
this, [
this](){ this->toggleSurfaceAction(1); });
571 fDrawingLineRemoval = mDrawing->addAction(
"Hidden line removal",
this, [
this](){ this->toggleSurfaceAction(2); });
572 fDrawingSurfaceRemoval = mDrawing->addAction(
"Hidden Surface removal",
this, [
this](){ this->toggleSurfaceAction(3); });
573 fDrawingLineSurfaceRemoval = mDrawing->addAction(
"Hidden line and surface removal",
this, [
this](){ this->toggleSurfaceAction(4); });
575 fDrawingWireframe->setCheckable(
true);
576 fDrawingLineRemoval->setCheckable(
true);
577 fDrawingSurfaceRemoval->setCheckable(
true);
578 fDrawingLineSurfaceRemoval->setCheckable(
true);
582 QAction *backgroundColorChooser ;
584 backgroundColorChooser = mStyle->addAction(
"Background color");
585 QObject ::connect(backgroundColorChooser,
588 SLOT(actionChangeBackgroundColor()));
592 QAction *textColorChooser ;
594 textColorChooser = mStyle->addAction(
"Text color");
595 QObject ::connect(textColorChooser,
598 SLOT(actionChangeTextColor()));
602 QAction *defaultColorChooser ;
604 defaultColorChooser = mStyle->addAction(
"Default color");
605 QObject ::connect(defaultColorChooser,
608 SLOT(actionChangeDefaultColor()));
612 QMenu *mActions = fContextMenu->addMenu(
"&Actions");
613 QAction *createEPS = mActions->addAction(
"Save as ...");
614 QObject ::connect(createEPS,
617 SLOT(actionSaveImage()));
620 QAction *movieParameters = mActions->addAction(
"Save as movie...");
621 QObject ::connect(movieParameters,
624 SLOT(actionMovieParameters()));
630 QMenu *mSpecial = fContextMenu->addMenu(
"S&pecial");
631 QMenu *mTransparency = mSpecial->addMenu(
"Transparency");
632 QAction *transparencyOn = mTransparency->addAction(
"On");
633 QAction *transparencyOff = mTransparency->addAction(
"Off");
636 createRadioAction(transparencyOn,transparencyOff,SLOT(toggleTransparency(
bool)),2);
638 createRadioAction(transparencyOn,transparencyOff,SLOT(toggleTransparency(
bool)),1);
644 QMenu *mAntialiasing = mSpecial->addMenu(
"Antialiasing");
645 QAction *antialiasingOn = mAntialiasing->addAction(
"On");
646 QAction *antialiasingOff = mAntialiasing->addAction(
"Off");
649 createRadioAction(antialiasingOn,antialiasingOff,SLOT(toggleAntialiasing(
bool)),2);
651 createRadioAction(antialiasingOn,antialiasingOff,SLOT(toggleAntialiasing(
bool)),1);
653 mAntialiasing->clear();
656 QMenu *mHaloing = mSpecial->addMenu(
"Haloing");
657 QAction *haloingOn = mHaloing->addAction(
"On");
658 QAction *haloingOff = mHaloing->addAction(
"Off");
660 createRadioAction(haloingOn,haloingOff,SLOT(toggleHaloing(
bool)),2);
662 createRadioAction(haloingOn,haloingOff,SLOT(toggleHaloing(
bool)),1);
667 QMenu *mAux = mSpecial->addMenu(
"Auxiliary edges");
668 QAction *auxOn = mAux->addAction(
"On");
669 QAction *auxOff = mAux->addAction(
"Off");
671 createRadioAction(auxOn,auxOff,SLOT(toggleAux(
bool)),2);
673 createRadioAction(auxOn,auxOff,SLOT(toggleAux(
bool)),1);
677 QMenu *mHiddenMarkers = mSpecial->addMenu(
"Hidden markers");
678 QAction *hiddenMarkersOn = mHiddenMarkers->addAction(
"On");
679 QAction *hiddenMarkersOff = mHiddenMarkers->addAction(
"Off");
681 createRadioAction(hiddenMarkersOn,hiddenMarkersOff,SLOT(toggleHiddenMarkers(
bool)),2);
683 createRadioAction(hiddenMarkersOn,hiddenMarkersOff,SLOT(toggleHiddenMarkers(
bool)),1);
688 QMenu *mFullScreen = mSpecial->addMenu(
"&Full screen");
689 fFullScreenOn = mFullScreen->addAction(
"On");
690 fFullScreenOff = mFullScreen->addAction(
"Off");
691 createRadioAction(fFullScreenOn,fFullScreenOff,SLOT(toggleFullScreen(
bool)),2);
700 G4cerr <<
"Visualization window not defined, please choose one before" <<
G4endl;
707 if ( fContextMenu ) {
708 fContextMenu->exec( e->globalPos() );
724void G4OpenGLQtViewer::createRadioAction(QAction *action1,QAction *action2,
const std::string& method,
unsigned int nCheck) {
726 action1->setCheckable(
true);
727 action2->setCheckable(
true);
730 action1->setChecked (
true);
732 action2->setChecked (
true);
734 QObject ::connect(action1, SIGNAL(triggered(
bool)),action2, SLOT(toggle()));
735 QObject ::connect(action2, SIGNAL(triggered(
bool)),action1, SLOT(toggle()));
737 QObject ::connect(action1, SIGNAL(toggled(
bool)),
this, method.c_str());
746void G4OpenGLQtViewer::showShortcuts() {
749 text =
"========= Mouse Shortcuts =========\n";
752 text +=
"Click and move mouse to rotate volume \n";
753 text +=
"ALT + Click and move mouse to rotate volume (Toggle View/Theta-Phi Direction) \n";
754 text +=
"CTRL + Click and move mouse to zoom in/out \n";
755 text +=
"SHIFT + Click and move mouse to change camera point of view \n";
757 text +=
"Move camera point of view with mouse \n";
759 text +=
"Click and pick \n";
762 text +=
"Click and move mouse to rotate volume \n";
763 text +=
"ALT + Click and move mouse to rotate volume (Toggle View/Theta-Phi Direction) \n";
764 text +=
"CTRL + Click and zoom mouse to zoom in/out \n";
765 text +=
"SHIFT + Click and zoommove camera point of view \n";
767 text +=
"========= Move Shortcuts ========= \n";
768 text +=
"Press left/right arrows to move volume left/right \n";
769 text +=
"Press up/down arrows to move volume up/down \n";
770 text +=
"Press '+'/'-' to move volume toward/forward \n";
772 text +=
"========= Rotation (Theta/Phi) Shortcuts ========= \n";
773 text +=
"Press SHIFT + left/right arrows to rotate volume left/right \n";
774 text +=
"Press SHIFT + up/down arrows to rotate volume up/down \n";
776 text +=
"========= Rotation (View Direction) Shortcuts ========= \n";
777 text +=
"Press ALT + left/right to rotate volume around vertical direction \n";
778 text +=
"Press ALT + up/down to rotate volume around horizontal direction \n";
780 text +=
"========= Zoom View ========= \n";
781 text +=
"Press CTRL + '+'/'-' to zoom into volume \n";
783 text +=
"========= Misc ========= \n";
784 text +=
"Press ALT +/- to slow/speed rotation/move \n";
785 text +=
"Press H to reset view \n";
786 text +=
"Press Esc to exit FullScreen \n";
788 text +=
"========= Video ========= \n";
789 text +=
"In video mode : \n";
790 text +=
" Press SPACE to Start/Pause video recording \n";
791 text +=
" Press RETURN to Stop video recording \n";
796 if ( fShortcutsDialog == NULL) {
797 fShortcutsDialog =
new QDialog();
798 fShortcutsDialogInfos =
new QTextEdit() ;
799 QVBoxLayout *mainLayout =
new QVBoxLayout;
800 mainLayout->addWidget(fShortcutsDialogInfos);
801 fShortcutsDialog->setLayout(mainLayout);
802 fShortcutsDialog->setWindowTitle(tr(
"Shortcuts"));
805 fShortcutsDialogInfos->setPlainText(text.data());
806 fShortcutsDialog->show();
817void G4OpenGLQtViewer::toggleMouseAction(
int aAction) {
821 }
else if (aAction == 2) {
823 }
else if (aAction == 3) {
825 }
else if (aAction == 4) {
827 }
else if (aAction == 5) {
846void G4OpenGLQtViewer::toggleSurfaceAction(
int aAction) {
853 }
else if (aAction ==2) {
856 }
else if (aAction ==3) {
859 }
else if (aAction ==4) {
879void G4OpenGLQtViewer::toggleProjection(
bool check) {
895void G4OpenGLQtViewer::toggleTransparency(
bool check) {
911void G4OpenGLQtViewer::toggleAntialiasing(
bool check) {
915 glDisable (GL_LINE_SMOOTH);
916 glDisable (GL_POLYGON_SMOOTH);
919 glEnable (GL_LINE_SMOOTH);
920 glHint (GL_LINE_SMOOTH_HINT, GL_NICEST);
921 glEnable (GL_POLYGON_SMOOTH);
922 glHint (GL_POLYGON_SMOOTH_HINT, GL_NICEST);
934void G4OpenGLQtViewer::toggleHaloing(
bool check) {
950void G4OpenGLQtViewer::toggleAux(
bool check) {
962void G4OpenGLQtViewer::togglePicking() {
975 UI->
ApplyCommand(std::string(
"/vis/viewer/set/picking true"));
977 UI->
ApplyCommand(std::string(
"/vis/viewer/set/picking false"));
988void G4OpenGLQtViewer::toggleHiddenMarkers(
bool check) {
1002void G4OpenGLQtViewer::toggleFullScreen(
bool check) {
1003 if (check !=
fGLWidget->isFullScreen()) {
1010 if (fMovieTempFolderPath ==
"") {
1018 QString filePath =fMovieTempFolderPath+fileName;
1021#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
1022 image = qGLW->grabFrameBuffer();
1024 image = qGLW->grabFramebuffer();
1028 res = image.save(filePath,0);
1031 setRecordingInfos(
"Can't save tmp file "+filePath);
1035 setRecordingInfos(
"File "+fileName+
" saved");
1041void G4OpenGLQtViewer::actionSaveImage() {
1049 qFilename = QFileDialog::getSaveFileName (
fGLWidget,
1056 std::string
name = qFilename.toStdString().c_str();
1063 fFileSavePath = QFileInfo(qFilename).path();
1065 std::string format = selectedFormat->toLower().toStdString().c_str();
1070 std::string filename =
name;
1071 std::string extension =
"";
1072 if (
name.find_last_of(
".") != std::string::npos) {
1073 filename =
name.substr(0,
name.find_last_of(
".") + 1);
1074 extension =
name.substr(
name.find_last_of(
".") + 1);
1079 filename+=
"."+ extension;
1086 if( exportDialog->exec()) {
1111void G4OpenGLQtViewer::actionChangeBackgroundColor() {
1118 const QColor color =
1119 QColorDialog::getColor(Qt::black,
1121 " Get background color and transparency",
1122 QColorDialog::ShowAlphaChannel);
1123 if (color.isValid()) {
1135void G4OpenGLQtViewer::actionChangeTextColor() {
1136 const QColor& color =
1137 QColorDialog::getColor(Qt::yellow,
1139 " Get text color and transparency",
1140 QColorDialog::ShowAlphaChannel);
1141 if (color.isValid()) {
1154void G4OpenGLQtViewer::actionChangeDefaultColor() {
1155 const QColor& color =
1156 QColorDialog::getColor(Qt::white,
1158 " Get default color and transparency",
1159 QColorDialog::ShowAlphaChannel);
1160 if (color.isValid()) {
1174void G4OpenGLQtViewer::actionMovieParameters() {
1175 showMovieParametersDialog();
1179void G4OpenGLQtViewer::showMovieParametersDialog() {
1180 if (!fMovieParametersDialog) {
1187 setRecordingInfos(
"ppmtompeg is needed to encode in video format. It is available here: http://netpbm.sourceforge.net ");
1190 fMovieParametersDialog->show();
1213 if (evnt->button() == Qt::RightButton) {
1216 if ((evnt->button() & Qt::LeftButton) && (! (evnt->modifiers() & Qt::ControlModifier ))){
1219 fLastPos1 = evnt->pos();
1220 fLastPos2 = fLastPos1;
1221 fLastPos3 = fLastPos2;
1222 fLastEventTime->start();
1223 if (
fUiQt != NULL) {
1228 float deltaX = ((float)
getWinWidth()/2-evnt->pos().x());
1229 float deltaY = ((float)
getWinHeight()/2-evnt->pos().y());
1250 if (fShiftKeyPress) {
1251 fGLWidget->setCursor(QCursor(Qt::SizeAllCursor));
1254 fGLWidget->setCursor(QCursor(Qt::ClosedHandCursor));
1257 fGLWidget->setCursor(QCursor(Qt::SizeAllCursor));
1259 fGLWidget->setCursor(QCursor(Qt::PointingHandCursor));
1270 glGetIntegerv(GL_VIEWPORT, viewport);
1273 double factorX = ((double)viewport[2]/
fGLWidget->width());
1274 double factorY = ((double)viewport[3]/
fGLWidget->height());
1275 fSpinningDelay = (int)fLastEventTime->elapsed();
1276 QPoint delta = (fLastPos3-fLastPos1)*factorX;
1279 fGLWidget->setCursor(QCursor(Qt::ArrowCursor));
1282 if ((delta.x() != 0) || (delta.y() != 0)) {
1287 }
else if (fSpinningDelay < fLaunchSpinDelay ) {
1288 if ((delta.x() == 0) && (delta.y() == 0)) {
1293#if (QT_VERSION < QT_VERSION_CHECK(5, 14, 0))
1296 QElapsedTimer lastMoveTime;
1298 lastMoveTime.start();
1300 float correctionFactor = 5;
1302 if ( lastMoveTime.elapsed() >= (
int)(1000/fNbMaxFramesPerSec)) {
1303 float lTime = 1000.0f/lastMoveTime.elapsed();
1304 if (((((
float)delta.x())/correctionFactor)*lTime > fNbMaxAnglePerSec) ||
1305 ((((
float)delta.x())/correctionFactor)*lTime < -fNbMaxAnglePerSec) ) {
1306 correctionFactor = (float)delta.x()*(lTime/fNbMaxAnglePerSec);
1307 if (delta.x() <0 ) {
1308 correctionFactor = -correctionFactor;
1311 if (((((
float)delta.y())/correctionFactor)*lTime > fNbMaxAnglePerSec) ||
1312 ((((
float)delta.y())/correctionFactor)*lTime < -fNbMaxAnglePerSec) ) {
1313 correctionFactor = (float)delta.y()*(lTime/fNbMaxAnglePerSec);
1314 if (delta.y() <0 ) {
1315 correctionFactor = -correctionFactor;
1326 lastMoveTime.start();
1328 bool rotate =
false;
1331 if (
fUiQt != NULL) {
1347 rotateQtScene(((
float)delta.x())/correctionFactor,((
float)delta.y())/correctionFactor);
1348 }
else if (fAltKeyPress) {
1349 rotateQtSceneToggle(((
float)delta.x())/correctionFactor,((
float)delta.y())/correctionFactor);
1353 moveScene(-((
float)delta.x())/correctionFactor,-((
float)delta.y())/correctionFactor,0,
true);
1380 Qt::MouseButtons mButtons = evnt->buttons();
1388 fLastPos3 = fLastPos2;
1389 fLastPos2 = fLastPos1;
1391#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
1392 fLastPos1 = QPoint(evnt->x(), evnt->y());
1394 fLastPos1 = QPoint(evnt->position().x(), evnt->position().y());
1397 int deltaX = fLastPos2.x()-fLastPos1.x();
1398 int deltaY = fLastPos2.y()-fLastPos1.y();
1401 if (
fUiQt != NULL) {
1407 if (mButtons & Qt::LeftButton) {
1410 }
else if (fAltKeyPress) {
1412 }
else if (fShiftKeyPress) {
1413 unsigned int sizeWin;
1420 float factor = ((float)100/(float)sizeWin) ;
1421 moveScene(-(
float)deltaX*factor,-(
float)deltaY*factor,0,
false);
1422 }
else if (fControlKeyPress) {
1427 if (mButtons & Qt::LeftButton) {
1428 moveScene(-(
float)deltaX,-(
float)deltaY,0,
true);
1432 fLastEventTime->start();
1447 fHoldMoveEvent =
true;
1450 GLdouble coefDepth = 0;
1466 fHoldMoveEvent =
false;
1477 if (fHoldRotateEvent)
1479 fHoldRotateEvent =
true;
1485 fHoldRotateEvent =
false;
1495 if (fHoldRotateEvent)
1497 fHoldRotateEvent =
true;
1503 fHoldRotateEvent =
false;
1514void G4OpenGLQtViewer::rescaleImage(
1536#if (QT_VERSION < QT_VERSION_CHECK(5, 15, 0))
1550 fHoldKeyEvent =
true;
1555 if ((fNoKeyPress) || (evnt->modifiers() == Qt::KeypadModifier )) {
1556 if (evnt->key() == Qt::Key_Down) {
1559 else if (evnt->key() == Qt::Key_Up) {
1562 if (evnt->key() == Qt::Key_Left) {
1565 else if (evnt->key() == Qt::Key_Right) {
1568 if (evnt->key() == Qt::Key_Minus) {
1571 else if (evnt->key() == Qt::Key_Plus) {
1575 if (evnt->key() == Qt::Key_Escape) {
1576 toggleFullScreen(
false);
1585 if ((evnt->key() == Qt::Key_Return) || (evnt->key() == Qt::Key_Enter)){
1588 if (evnt->key() == Qt::Key_Space){
1593 if (evnt->key() == Qt::Key_H){
1600 if (fShiftKeyPress) {
1601 fGLWidget->setCursor(QCursor(Qt::SizeAllCursor));
1603 if (evnt->key() == Qt::Key_Down) {
1606 else if (evnt->key() == Qt::Key_Up) {
1609 if (evnt->key() == Qt::Key_Left) {
1612 else if (evnt->key() == Qt::Key_Right) {
1615 if (evnt->key() == Qt::Key_Plus) {
1622 if ((fAltKeyPress)) {
1623 fGLWidget->setCursor(QCursor(Qt::ClosedHandCursor));
1625 if (evnt->key() == Qt::Key_Down) {
1628 else if (evnt->key() == Qt::Key_Up) {
1631 if (evnt->key() == Qt::Key_Left) {
1634 else if (evnt->key() == Qt::Key_Right) {
1639 if (evnt->key() == Qt::Key_Plus) {
1643 else if (evnt->key() == Qt::Key_Minus) {
1650 if ((fControlKeyPress)) {
1651 if (evnt->key() == Qt::Key_Plus) {
1655 else if (evnt->key() == Qt::Key_Minus) {
1661 fHoldKeyEvent =
false;
1667 fGLWidget->setCursor(QCursor(Qt::ArrowCursor));
1675 fAltKeyPress =
false;
1676 fShiftKeyPress =
false;
1677 fControlKeyPress =
false;
1679 if (modifier & Qt::AltModifier ) {
1680 fAltKeyPress =
true;
1681 fNoKeyPress =
false;
1683 if (modifier & Qt::ShiftModifier ) {
1684 fShiftKeyPress =
true;
1685 fNoKeyPress =
false;
1687 if (modifier & Qt::ControlModifier ) {
1688 fControlKeyPress =
true;
1689 fNoKeyPress =
false;
1699 if (!fMovieParametersDialog) {
1700 showMovieParametersDialog();
1702 setRecordingStatus(STOP);
1707 setRecordingStatus(BAD_ENCODER);
1709 setRecordingStatus(BAD_OUTPUT);
1713 setRecordingInfos(
"No frame to encode.");
1722 if (!fMovieParametersDialog) {
1723 showMovieParametersDialog();
1729 if (fRecordingStep == STOP) {
1730 setRecordingStatus(SAVE);
1743 if ( fRecordingStep == WAIT) {
1746 showMovieParametersDialog();
1747 setRecordingInfos(
"You should specified the temp folder in order to make movie");
1751 QString tmp = removeTempFolder();
1753 setRecordingInfos(tmp);
1756 tmp = createTempFolder();
1758 setRecordingInfos(
"Can't create temp folder."+tmp);
1764 if (fRecordingStep == WAIT) {
1765 setRecordingStatus(START);
1766 }
else if (fRecordingStep == START) {
1767 setRecordingStatus(PAUSE);
1768 }
else if (fRecordingStep == PAUSE) {
1769 setRecordingStatus(CONTINUE);
1770 }
else if (fRecordingStep == CONTINUE) {
1771 setRecordingStatus(PAUSE);
1775void G4OpenGLQtViewer::setRecordingStatus(RECORDING_STEP step) {
1777 fRecordingStep = step;
1784 QString txtStatus =
"";
1785 if (fRecordingStep == WAIT) {
1786 txtStatus =
"Waiting to start...";
1788 }
else if (fRecordingStep == START) {
1789 txtStatus =
"Start Recording...";
1790 }
else if (fRecordingStep == PAUSE) {
1791 txtStatus =
"Pause Recording...";
1792 }
else if (fRecordingStep == CONTINUE) {
1793 txtStatus =
"Continue Recording...";
1794 }
else if (fRecordingStep == STOP) {
1795 txtStatus =
"Stop Recording...";
1796 }
else if (fRecordingStep == READY_TO_ENCODE) {
1797 txtStatus =
"Ready to Encode...";
1798 }
else if (fRecordingStep ==
ENCODING) {
1799 txtStatus =
"Encoding...";
1800 }
else if (fRecordingStep == FAILED) {
1801 txtStatus =
"Failed to encode...";
1802 }
else if ((fRecordingStep == BAD_ENCODER)
1803 || (fRecordingStep == BAD_OUTPUT)
1804 || (fRecordingStep == BAD_TMP)) {
1805 txtStatus =
"Correct above errors first";
1806 }
else if (fRecordingStep == SUCCESS) {
1807 txtStatus =
"File encoded successfully";
1811 if (fMovieParametersDialog) {
1816 setRecordingInfos(
"");
1820void G4OpenGLQtViewer::setRecordingInfos(
const QString& txt) {
1821 if (fMovieParametersDialog) {
1830void G4OpenGLQtViewer::initMovieParameters() {
1834 fProcess =
new QProcess();
1836 QObject ::connect(fProcess,SIGNAL(finished (
int)),
1837 this,SLOT(processLookForFinished()));
1838 fProcess->setProcessChannelMode(QProcess::MergedChannels);
1839#if (QT_VERSION < QT_VERSION_CHECK(5, 15, 0))
1840 fProcess->start (
"which ppmtompeg");
1842 fProcess->start (
"which ppmtompeg", QStringList());
1849 return fEncoderPath;
1859 return "ppmtompeg is needed to encode in video format. It is available here: http://netpbm.sourceforge.net ";
1862 path = QDir::cleanPath(path);
1863 QFileInfo *f =
new QFileInfo(path);
1865 return "File does not exist";
1866 }
else if (f->isDir()) {
1867 return "This is a directory";
1868 }
else if (!f->isExecutable()) {
1869 return "File exist but is not executable";
1870 }
else if (!f->isFile()) {
1871 return "This is not a file";
1873 fEncoderPath = path;
1875 if (fRecordingStep == BAD_ENCODER) {
1876 setRecordingStatus(STOP);
1883 if ((fRecordingStep == START) || (fRecordingStep == CONTINUE)) {
1890 if (fRecordingStep == PAUSE) {
1904 if (fRecordingStep == WAIT) {
1911 if (fRecordingStep == STOP) {
1918 if (fRecordingStep == FAILED) {
1925 if (fRecordingStep == SUCCESS) {
1932 if (fRecordingStep == BAD_ENCODER) {
1938 if (fRecordingStep == BAD_TMP) {
1944 if (fRecordingStep == BAD_OUTPUT) {
1951 fRecordingStep = BAD_ENCODER;
1955 fRecordingStep = BAD_TMP;
1959 fRecordingStep = BAD_OUTPUT;
1964 fRecordingStep = WAIT;
1970 if (fRecordingStep == READY_TO_ENCODE) {
1977 setRecordingStatus(WAIT);
1987 return "Path does not exist";
1989 path = QDir::cleanPath(path);
1990 QFileInfo *d =
new QFileInfo(path);
1992 return "Path does not exist";
1993 }
else if (!d->isDir()) {
1994 return "This is not a directory";
1995 }
else if (!d->isReadable()) {
1996 return path +
" is read protected";
1997 }
else if (!d->isWritable()) {
1998 return path +
" is write protected";
2001 if (fRecordingStep == BAD_TMP) {
2002 setRecordingStatus(WAIT);
2004 fTempFolderPath = path;
2011 return fTempFolderPath;
2021 return "Path does not exist";
2024 QFileInfo *file =
new QFileInfo(path);
2025 QDir dir = file->dir();
2026 path = QDir::cleanPath(path);
2027 if (file->exists()) {
2028 return "File already exist, please choose a new one";
2029 }
else if (!dir.exists()) {
2030 return "Dir does not exist";
2031 }
else if (!dir.isReadable()) {
2032 return path +
" is read protected";
2035 if (fRecordingStep == BAD_OUTPUT) {
2036 setRecordingStatus(STOP);
2038 fSaveFileName = path;
2045 return fSaveFileName ;
2052QString G4OpenGLQtViewer::createTempFolder() {
2053 fMovieTempFolderPath =
"";
2059 QString sep = QString(QDir::separator());
2060 QString path = sep+
"QtMovie_"+QDateTime::currentDateTime ().toString(
"dd-MM-yyyy_hh-mm-ss")+sep;
2061 QDir *d =
new QDir(QDir::cleanPath(fTempFolderPath));
2063 if (d->exists(path)) {
2064 return "Folder "+path+
" already exists.Please remove it first";
2066 if (d->mkdir(fTempFolderPath+path)) {
2067 fMovieTempFolderPath = fTempFolderPath+path;
2070 return "Can't create "+fTempFolderPath+path;
2075QString G4OpenGLQtViewer::removeTempFolder() {
2077 if (fMovieTempFolderPath ==
"") {
2080 QDir *d =
new QDir(QDir::cleanPath(fMovieTempFolderPath));
2085 d->setFilter( QDir::Files );
2086 QStringList subDirList = d->entryList();
2089 for (QStringList::ConstIterator it = subDirList.begin() ;(it != subDirList.end()) ; it++) {
2090 const QString currentFile = *it;
2091 if (!d->remove(currentFile)) {
2093 QString file = fMovieTempFolderPath+currentFile;
2094 error +=
"Removing file failed : "+file;
2099 if (d->rmdir(fMovieTempFolderPath)) {
2100 fMovieTempFolderPath =
"";
2103 return "Dir "+fMovieTempFolderPath+
" should be empty, but could not remove it";
2107 return "Could not remove "+fMovieTempFolderPath+
" because of the following errors :"+error;
2124 bool increaseFileNumber =
true;
2126 if (name.size() != name.substr(name.find_last_of(
".") + 1).size()) {
2127 increaseFileNumber =
false;
2132 if ((width !=-1) && (height != -1)) {
2142#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
2143 image = qGLW->grabFrameBuffer();
2145 image = qGLW->grabFramebuffer();
2165 fp = fopen (QString(fMovieTempFolderPath+fParameterFileName).toStdString().c_str(),
"w");
2168 setRecordingInfos(
"Generation of parameter file failed");
2172 fprintf (fp,
"# Pattern affects speed, quality and compression. See the User's Guide\n");
2173 fprintf (fp,
"# for more info.\n");
2175 fprintf (fp,
"PATTERN I\n");
2178 fprintf (fp,
"# You must specify the type of the input files. The choices are:\n");
2179 fprintf (fp,
"# YUV, PPM, JMOVIE, Y, JPEG, PNM\n");
2180 fprintf (fp,
"# (must be upper case)\n");
2182 fprintf (fp,
"BASE_FILE_FORMAT PPM\n");
2185 fprintf (fp,
"# If you are using YUV, there are different supported file formats.\n");
2186 fprintf (fp,
"# EYUV or UCB are the same as previous versions of this encoder.\n");
2187 fprintf (fp,
"# (All the Y's, then U's then V's, in 4:2:0 subsampling.)\n");
2188 fprintf (fp,
"# Other formats, such as Abekas, Phillips, or a general format are\n");
2189 fprintf (fp,
"# permissible, the general format is a string of Y's, U's, and V's\n");
2190 fprintf (fp,
"# to specify the file order.\n");
2192 fprintf (fp,
"INPUT_FORMAT UCB\n");
2194 fprintf (fp,
"# the conversion statement\n");
2196 fprintf (fp,
"# Each occurrence of '*' will be replaced by the input file\n");
2198 fprintf (fp,
"# e.g., if you have a bunch of GIF files, then this might be:\n");
2199 fprintf (fp,
"# INPUT_CONVERT giftoppm *\n");
2201 fprintf (fp,
"# e.g., if you have a bunch of files like a.Y a.U a.V, etc., then:\n");
2202 fprintf (fp,
"# INPUT_CONVERT cat *.Y *.U *.V\n");
2204 fprintf (fp,
"# e.g., if you are grabbing from laser disc you might have something like\n");
2205 fprintf (fp,
"# INPUT_CONVERT goto frame *; grabppm\n");
2206 fprintf (fp,
"# 'INPUT_CONVERT *' means the files are already in the base file format\n");
2208 fprintf (fp,
"INPUT_CONVERT * \n");
2210 fprintf (fp,
"# number of frames in a GOP.\n");
2212 fprintf (fp,
"# since each GOP must have at least one I-frame, the encoder will find the\n");
2213 fprintf (fp,
"# the first I-frame after GOP_SIZE frames to start the next GOP\n");
2215 fprintf (fp,
"# later, will add more flexible GOP signalling\n");
2217 fprintf (fp,
"GOP_SIZE 1\n");
2219 fprintf (fp,
"# number of slices in a frame\n");
2221 fprintf (fp,
"# 1 is a good number. another possibility is the number of macroblock rows\n");
2222 fprintf (fp,
"# (which is the height divided by 16)\n");
2224 fprintf (fp,
"SLICES_PER_FRAME 1\n");
2225 fprintf (fp,
"PIXEL HALF");
2227 fprintf (fp,
"# directory to get all input files from (makes this file easier to read)\n");
2228 fprintf (fp,
"INPUT_DIR %s\n",fMovieTempFolderPath.toStdString().c_str());
2230 fprintf (fp,
"# There are a bunch of ways to specify the input files.\n");
2231 fprintf (fp,
"# from a simple one-per-line listing, to the following \n");
2232 fprintf (fp,
"# way of numbering them. See the manual for more information.\n");
2233 fprintf (fp,
"INPUT\n");
2234 fprintf (fp,
"# '*' is replaced by the numbers 01, 02, 03, 04\n");
2235 fprintf (fp,
"# if I instead do [01-11], it would be 01, 02, ..., 09, 10, 11\n");
2236 fprintf (fp,
"# if I instead do [1-11], it would be 1, 2, 3, ..., 9, 10, 11\n");
2237 fprintf (fp,
"# if I instead do [1-11+3], it would be 1, 4, 7, 10\n");
2238 fprintf (fp,
"# the program assumes none of your input files has a name ending in ']'\n");
2239 fprintf (fp,
"# if you do, too bad!!!\n");
2243 fprintf (fp,
"# can have more files here if you want...there is no limit on the number\n");
2244 fprintf (fp,
"# of files\n");
2245 fprintf (fp,
"END_INPUT\n");
2249 fprintf (fp,
"# Many of the remaining options have to do with the motion search and qscale\n");
2251 fprintf (fp,
"# FULL or HALF -- must be upper case\n");
2252 fprintf (fp,
"# Should be FULL for computer generated images\n");
2253 fprintf (fp,
"PIXEL FULL\n");
2255 fprintf (fp,
"# means +/- this many pixels for both P and B frame searches\n");
2256 fprintf (fp,
"# specify two numbers if you wish to serc different ranges in the two.\n");
2257 fprintf (fp,
"RANGE 10\n");
2259 fprintf (fp,
"# The two search algorithm parameters below mostly affect speed,\n");
2260 fprintf (fp,
"# with some affect on compression and almost none on quality.\n");
2262 fprintf (fp,
"# this must be one of {EXHAUSTIVE, SUBSAMPLE, LOGARITHMIC}\n");
2263 fprintf (fp,
"PSEARCH_ALG LOGARITHMIC\n");
2265 fprintf (fp,
"# this must be one of {SIMPLE, CROSS2, EXHAUSTIVE}\n");
2267 fprintf (fp,
"# note that EXHAUSTIVE is really, really, really slow\n");
2269 fprintf (fp,
"BSEARCH_ALG SIMPLE\n");
2272 fprintf (fp,
"# these specify the q-scale for I, P, and B frames\n");
2273 fprintf (fp,
"# (values must be between 1 and 31)\n");
2274 fprintf (fp,
"# These are the Qscale values for the entire frame in variable bit-rate\n");
2275 fprintf (fp,
"# mode, and starting points (but not important) for constant bit rate\n");
2278 fprintf (fp,
"# Qscale (Quantization scale) affects quality and compression,\n");
2279 fprintf (fp,
"# but has very little effect on speed.\n");
2281 fprintf (fp,
"IQSCALE 4\n");
2282 fprintf (fp,
"PQSCALE 5\n");
2283 fprintf (fp,
"BQSCALE 12\n");
2285 fprintf (fp,
"# this must be ORIGINAL or DECODED\n");
2286 fprintf (fp,
"REFERENCE_FRAME ORIGINAL\n");
2288 fprintf (fp,
"# for parallel parameters see parallel.param in the examples subdirectory\n");
2290 fprintf (fp,
"# if you want constant bit-rate mode, specify it as follows (number is bits/sec):\n");
2291 fprintf (fp,
"#BIT_RATE 1000000\n");
2293 fprintf (fp,
"# To specify the buffer size (327680 is default, measused in bits, for 16bit words)\n");
2294 fprintf (fp,
"BUFFER_SIZE 327680\n");
2296 fprintf (fp,
"# The frame rate is the number of frames/second (legal values:\n");
2297 fprintf (fp,
"# 23.976, 24, 25, 29.97, 30, 50 ,59.94, 60\n");
2298 fprintf (fp,
"FRAME_RATE 30\n");
2300 fprintf (fp,
"# There are many more options, see the users manual for examples....\n");
2301 fprintf (fp,
"# ASPECT_RATIO, USER_DATA, GAMMA, IQTABLE, etc.\n");
2306 setRecordingInfos(
"Parameter file "+fParameterFileName+
" generated in "+fMovieTempFolderPath);
2307 setRecordingStatus(READY_TO_ENCODE);
2316 fProcess =
new QProcess();
2317 QObject ::connect(fProcess,SIGNAL(finished (
int,QProcess::ExitStatus)),
2318 this,SLOT(processEncodeFinished()));
2319 QObject ::connect(fProcess,SIGNAL(readyReadStandardOutput ()),
2320 this,SLOT(processEncodeStdout()));
2321#if (QT_VERSION < QT_VERSION_CHECK(5, 10, 0))
2322 fProcess->setReadChannelMode(QProcess::MergedChannels);
2324 fProcess->setProcessChannelMode(QProcess::MergedChannels);
2326 fProcess->start (fEncoderPath, QStringList(fMovieTempFolderPath+fParameterFileName));
2332void G4OpenGLQtViewer::processEncodeStdout()
2334 QString tmp = fProcess->readAllStandardOutput ().data();
2335 auto start = tmp.lastIndexOf(
"ESTIMATED TIME");
2336 tmp = tmp.mid(start,tmp.indexOf(
"\n",start)-start);
2337 setRecordingInfos(tmp);
2341void G4OpenGLQtViewer::processEncodeFinished()
2345 txt = getProcessErrorMsg();
2347 setRecordingStatus(SUCCESS);
2349 setRecordingStatus(FAILED);
2355void G4OpenGLQtViewer::processLookForFinished()
2358 QString txt = getProcessErrorMsg();
2362 fEncoderPath = QString(fProcess->readAllStandardOutput ().data()).trimmed();
2364 if (fEncoderPath.contains(
" ")) {
2366 }
else if (!fEncoderPath.contains(
"ppmtompeg")) {
2376QString G4OpenGLQtViewer::getProcessErrorMsg()
2379 if (fProcess->exitCode() != 0) {
2380 switch (fProcess->error()) {
2381 case QProcess::FailedToStart:
2382 txt =
"The process failed to start. Either the invoked program is missing, or you may have insufficient permissions to invoke the program.\n";
2384 case QProcess::Crashed:
2385 txt =
"The process crashed some time after starting successfully.\n";
2387 case QProcess::Timedout:
2388 txt =
"The last waitFor...() function timed out. The state of QProcess is unchanged, and you can try calling waitFor...() again.\n";
2390 case QProcess::WriteError:
2391 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";
2393 case QProcess::ReadError:
2394 txt =
"An error occurred when attempting to read from the process. For example, the process may not be running.\n";
2396 case QProcess::UnknownError:
2397 txt =
"An unknown error occurred. This is the default return value of error().\n";
2407QWidget *G4OpenGLQtViewer::getParentWidget()
2415 QDialog* dialog = NULL;
2419 QWidgetList wl = QApplication::allWidgets();
2420 QWidget *widget = NULL;
2421 for (
int i=0; i < wl.size(); i++) {
2423 if ((found==
false) && (widget->inherits(
"QMainWindow"))) {
2424 dialog =
new QDialog(widget,Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowMinMaxButtonsHint);
2430 dialog =
new QDialog();
2433 dialog=
new QDialog();
2443void G4OpenGLQtViewer::createSceneTreeWidget() {
2446 if (!fUISceneTreeWidget) {
2451 QLayoutItem * wItem;
2453 if (fUISceneTreeWidget->layout()->count() ) {
2454 for(
int idx = 0; idx < fUISceneTreeWidget->layout()->count(); idx++){
2455 wItem = fUISceneTreeWidget->layout()->itemAt(idx);
2456 if (fSceneTreeWidget) {
2457 if(
dynamic_cast<QWidget *
>(wItem->widget())) {
2458 if (wItem->widget()->windowTitle() == fSceneTreeWidget->windowTitle()) {
2459 wItem->widget()->show();
2462 wItem->widget()->hide();
2473 fSceneTreeWidget =
new QWidget();
2474 QVBoxLayout* layoutSceneTree =
new QVBoxLayout();
2475 fSceneTreeWidget->setStyleSheet (
"padding: 0px ");
2477 fSceneTreeWidget->setLayout(layoutSceneTree);
2478 fSceneTreeWidget->layout()->setContentsMargins(5,5,5,5);
2479 fSceneTreeWidget->setWindowTitle(QString(
GetName().data()));
2481 if (fUISceneTreeWidget != NULL) {
2487 createSceneTreeComponent();
2493void G4OpenGLQtViewer::createSceneTreeComponent(){
2495 QLayout* vLayout = fSceneTreeWidget->layout();
2498 QWidget* coutButtonWidget =
new QWidget();
2499 QHBoxLayout* layoutCoutTBButtons =
new QHBoxLayout();
2501 fFilterOutput =
new QLineEdit();
2502 fFilterOutput->setToolTip(
"Filter output by...");
2503 fFilterOutput->setStyleSheet (
"padding: 0px ");
2506 fFilterOutput->addAction(*searchIcon,QLineEdit::TrailingPosition);
2507 fFilterOutput->setStyleSheet (
"border-radius:7px;");
2508 layoutCoutTBButtons->addWidget(fFilterOutput);
2510 coutButtonWidget->setLayout(layoutCoutTBButtons);
2511 vLayout->addWidget(coutButtonWidget);
2514 vLayout->setContentsMargins(0,0,0,0);
2517 fSceneTreeComponentTreeWidget =
new QTreeWidget();
2518 fSceneTreeComponentTreeWidget->setSelectionMode(QAbstractItemView::SingleSelection);
2519 fSceneTreeComponentTreeWidget->setHeaderLabel (
"Scene tree : "+QString(
GetName().data()));
2520 fSceneTreeComponentTreeWidget->setColumnHidden (1,
true);
2521 fSceneTreeComponentTreeWidget->setColumnHidden (2,
true);
2522 fSceneTreeComponentTreeWidget->setColumnHidden (3,
true);
2527 vLayout->addWidget(fSceneTreeComponentTreeWidget);
2529 connect(fSceneTreeComponentTreeWidget,SIGNAL(itemChanged(QTreeWidgetItem*,
int)),SLOT(sceneTreeComponentItemChanged(QTreeWidgetItem*,
int)));
2530 connect(fSceneTreeComponentTreeWidget,SIGNAL(itemSelectionChanged ()),SLOT(sceneTreeComponentSelected()));
2531 connect(fSceneTreeComponentTreeWidget,SIGNAL(itemDoubleClicked ( QTreeWidgetItem*,
int)),SLOT(changeColorAndTransparency( QTreeWidgetItem*,
int)));
2535 QWidget *helpWidget =
new QWidget();
2536 QHBoxLayout *helpLayout =
new QHBoxLayout();
2538 QWidget* depthWidget =
new QWidget();
2539 QWidget *showBox =
new QWidget(depthWidget);
2540 QHBoxLayout *showBoxLayout =
new QHBoxLayout();
2543 showBoxLayout->setContentsMargins(5,5,5,5);
2545 QLabel *zero =
new QLabel();
2546 zero->setText(
"Show all");
2547 QLabel *one =
new QLabel();
2548 one->setText(
"Hide all");
2549 fSceneTreeDepthSlider =
new QSlider ( Qt::Horizontal);
2550 fSceneTreeDepthSlider->setMaximum (1000);
2551 fSceneTreeDepthSlider->setMinimum (0);
2552 fSceneTreeDepthSlider->setTickPosition(QSlider::TicksAbove);
2554 fSceneTreeDepthSlider->setMinimumWidth (40);
2556 showBoxLayout->addWidget(zero);
2557 showBoxLayout->addWidget(fSceneTreeDepthSlider);
2558 showBoxLayout->addWidget(one);
2560 showBox->setLayout(showBoxLayout);
2562 helpLayout->addWidget(showBox);
2563 helpWidget->setLayout(helpLayout);
2564 helpLayout->setContentsMargins(0,0,0,0);
2566 vLayout->addWidget(helpWidget);
2568 connect( fSceneTreeDepthSlider, SIGNAL( valueChanged(
int) ),
this, SLOT( changeDepthInSceneTree(
int) ) );
2569 connect( fFilterOutput, SIGNAL( textEdited (
const QString &) ),
this, SLOT(changeSearchSelection()));
2570 fTreeItemModels.clear();
2572 fPVRootNodeCreate =
false;
2574 fMaxPOindexInserted = -1;
2580void G4OpenGLQtViewer::createViewerPropertiesWidget() {
2585 if (!fUIViewerPropertiesWidget) {
2590 QLayoutItem * wItem;
2591 if (fUIViewerPropertiesWidget->layout()->count()) {
2592 while ((wItem = fUIViewerPropertiesWidget->layout()->takeAt(0)) != 0) {
2593 delete wItem->widget();
2599 QGroupBox *groupBox =
new QGroupBox();
2600 groupBox->setTitle(
GetName().data());
2601 QVBoxLayout *vbox =
new QVBoxLayout;
2604 fViewerPropertiesTableWidget =
new QTableWidget();
2606 QSizePolicy vPolicy = fViewerPropertiesTableWidget->sizePolicy();
2607 vPolicy.setVerticalStretch(4);
2609 vbox->addWidget(fViewerPropertiesTableWidget);
2610 groupBox->setLayout(vbox);
2611 fUIViewerPropertiesWidget->layout()->addWidget(groupBox);
2613 connect(fViewerPropertiesTableWidget, SIGNAL(itemChanged(QTableWidgetItem*)),
this, SLOT(tableWidgetViewerSetItemChanged(QTableWidgetItem *)));
2617 QDialog* dial =
static_cast<QDialog*
> (fUIViewerPropertiesWidget->parent());
2620 dial->setWindowTitle(QString(
"Viewer properties - ")+
GetName());
2625void G4OpenGLQtViewer::createPickInfosWidget(){
2630 if (!fUIPickInfosWidget) {
2635 QLayoutItem * wItem;
2636 if (fUIPickInfosWidget->layout()->count()) {
2637 while ((wItem = fUIPickInfosWidget->layout()->takeAt(0)) != 0) {
2638 delete wItem->widget();
2643 QGroupBox *groupBox =
new QGroupBox(
"");
2644 QVBoxLayout *vbox =
new QVBoxLayout;
2647 QWidget *pickingInfoWidget =
new QWidget();
2648 QHBoxLayout *pickingInfoLayout =
new QHBoxLayout();
2650 pickingInfoWidget->setStyleSheet (
"padding-left: 0px; border:0px;");
2651 pickingInfoWidget->setLayout(pickingInfoLayout);
2653 vbox->addWidget(pickingInfoWidget);
2656 fPickInfosScrollArea =
new QScrollArea();
2657 fPickInfosScrollArea->setWidgetResizable(
true);
2660 fPickInfosWidget =
new QWidget();
2661 fPickInfosWidget->setStyleSheet (
"padding: 0px ");
2663 QVBoxLayout* vLayout =
new QVBoxLayout();
2664 fPickInfosWidget->setLayout (vLayout);
2665 fPickInfosScrollArea->setWidget(fPickInfosWidget);
2667 QSizePolicy vPolicy = fPickInfosWidget->sizePolicy();
2668 vPolicy.setVerticalStretch(4);
2669 vbox->addWidget(fPickInfosScrollArea);
2670 pickingInfoLayout->setContentsMargins(0,0,0,0);
2671 vLayout->setContentsMargins(0,0,0,0);
2672 vbox->setContentsMargins(1,1,1,1);
2674 groupBox->setLayout(vbox);
2675 fUIPickInfosWidget->layout()->addWidget(groupBox);
2683void G4OpenGLQtViewer::setCheckComponent(QTreeWidgetItem* item,
bool check)
2687 const PVPath& fullPath = fTreeItemModels[item->data(0,Qt::UserRole).toInt()];
2689 if (fullPath.size() > 0) {
2698 item->setCheckState(0,Qt::Checked);
2700 item->setCheckState(0,Qt::Unchecked);
2702 updatePositivePoIndexSceneTreeWidgetQuickMap(item->data(0,Qt::UserRole).toInt(),item);
2703 int nChildCount = item->childCount();
2704 for (
int i = 0; i < nChildCount; i++) {
2705 setCheckComponent(item->child(i),check);
2725#ifdef G4MULTITHREADED
2732 QFont font = QFont();
2733 font.setPointSizeF(size);
2741 const char* textCString = textString.c_str();
2746 QFontMetrics* f =
new QFontMetrics (font);
2747 G4double span = f->boundingRect(textCString).width();
2750 [[maybe_unused]]
G4double xmove = 0.;
2751 [[maybe_unused]]
G4double ymove = 0.;
2769 xmove *= fudgeFactor;
2770 ymove *= fudgeFactor;
2772#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
2797 const QString& modelShortName = getModelShortName(model);
2799 if (modelShortName ==
"") {
2803 if (fSceneTreeComponentTreeWidget == NULL) {
2804 createSceneTreeComponent();
2808 if (fSceneTreeComponentTreeWidget == NULL) {
2812 fSceneTreeComponentTreeWidget->blockSignals(
true);
2816 if (!fPVRootNodeCreate) {
2819 fModelShortNameItem = createTreeWidgetItem(pPVModel->
GetFullPVPath(),
2827 fPVRootNodeCreate =
true;
2830 bool added = parseAndInsertInSceneTree(fModelShortNameItem,pPVModel,0,modelShortName,0,currentPOIndex);
2834 fSceneTreeComponentTreeWidget->blockSignals(
false);
2843QTreeWidgetItem* G4OpenGLQtViewer::createTreeWidgetItem(
2844 const PVPath& fullPath
2845 ,
const QString& name
2848 ,
const QString& logicalName
2849 ,Qt::CheckState state
2850 ,QTreeWidgetItem * parentTreeNode
2855 if (fullPath.size() > fSceneTreeDepth) {
2856 fSceneTreeDepth = (
unsigned int)fullPath.size();
2858 if (fSceneTreeDepthSlider) {
2859 fSceneTreeDepthSlider->setTickInterval(1000/(fSceneTreeDepth+1));
2862 QTreeWidgetItem * newItem = NULL;
2863 if (parentTreeNode == NULL) {
2864 newItem =
new QTreeWidgetItem();
2865 fSceneTreeComponentTreeWidget->addTopLevelItem(newItem);
2867 newItem =
new QTreeWidgetItem(parentTreeNode);
2868 fSceneTreeComponentTreeWidget->addTopLevelItem(parentTreeNode);
2872 newItem->setText(0,name);
2873 newItem->setData(1,Qt::UserRole,copyNb);
2874 newItem->setText(2,QString::number(POIndex));
2875 newItem->setData(0, Qt::UserRole, POIndex);
2876 newItem->setText(3,logicalName);
2877 newItem->setFlags(newItem->flags()|Qt::ItemIsUserCheckable);
2878 newItem->setCheckState(0,state);
2879 newItem->setExpanded(
true);
2880 updatePositivePoIndexSceneTreeWidgetQuickMap(POIndex,newItem);
2882 changeQColorForTreeWidgetItem(newItem,QColor((
int)(color.
GetRed()*255),
2888 if ((state == Qt::Unchecked) && (POIndex == -1)) {
2889 newItem->setForeground (0, QBrush( Qt::gray) );
2892 newItem->setToolTip (0,QString(
2893 "This node exists in the geometry but has not been\n")+
2894 "drawn, perhaps because it has been set invisible. It \n"+
2895 "cannot be made visible with a click on the button.\n"+
2896 "To see it, change the visibility, for example, with \n"+
2897 "/vis/geometry/set/visibility " + logicalName +
" 0 true\n"+
2898 "and rebuild the view with /vis/viewer/rebuild.\n"+
2899 "Click here will only show/hide all child components");
2902 newItem->setToolTip (0,QString(
"double-click to change the color"));
2908 state = Qt::Unchecked;
2909 newItem->setCheckState(0,state);
2910 updatePositivePoIndexSceneTreeWidgetQuickMap(POIndex,newItem);
2913 fTreeItemModels.insert(std::pair <int, PVPath > (POIndex,fullPath) );
2917 changeOpenCloseVisibleHiddenSelectedColorSceneTreeElement(newItem);
2934bool G4OpenGLQtViewer::parseAndInsertInSceneTree(
2935 QTreeWidgetItem * parentItem
2937 ,
unsigned int fullPathIndex
2938 ,
const QString& parentRoot
2939 ,
unsigned int currentIndexInTreeSceneHandler
2940 ,
int currentPVPOIndex
2943 if (parentItem == NULL) {
2949 std::ostringstream oss;
2950 oss << fullPath.at(fullPathIndex).GetCopyNo();
2951 std::string currentPVName =
G4String(fullPath.at(fullPathIndex).GetPhysicalVolume()->GetName()+
" ["+oss.str()+
"]").data();
2953 int currentPVCopyNb = fullPath.at(fullPathIndex).GetCopyNo();
2963 QTreeWidgetItem* subItem = NULL;
2964 QList<QTreeWidgetItem *> parentItemList;
2972 if ((currentIndexInTreeSceneHandler == (fullPath.size()-1)) && ((color.
GetAlpha() == 1.))) {
2974 QString lookForString = QString(currentPVName.c_str());
2975 for (
int i = 0;i < parentItem->childCount(); i++ ) {
2976 if (parentItem->child(i)->text(0) == lookForString) {
2977 parentItemList.push_back(parentItem->child(i));
2982 for (
int i = 0; i < parentItemList.size(); ++i) {
2983 const std::string& parentItemName = parentItemList.at(i)->text(0).toStdString();
2984 int parentItemCopyNb = parentItemList.at(i)->data(1,Qt::UserRole).toInt();
2985 int parentItemPOIndex = parentItemList.at(i)->data(0,Qt::UserRole).toInt();
2993 if (((parentRoot == fTouchableVolumes) && (currentPVCopyNb == parentItemCopyNb)
2994 && (currentPVName == parentItemName)) ||
2996 ((parentRoot != fTouchableVolumes) && (currentPVCopyNb == parentItemCopyNb)
2998 && (currentPVName == parentItemName) && (currentPVPOIndex == parentItemPOIndex) )) {
3001 bool sameTransform =
true;
3002 if (parentItemPOIndex >= 0) {
3003 const PVPath& fullPathTmp = fTreeItemModels[parentItemPOIndex];
3004 if (fullPathTmp.size() > 0) {
3005 if (fullPathTmp.at(fullPathTmp.size()-1).GetTransform () == pPVModel->
GetTransformation ()) {
3006 sameTransform =
true;
3008 sameTransform =
false;
3014 if (sameTransform ==
true) {
3021 if (currentIndexInTreeSceneHandler == (fullPath.size()-1)) {
3023 parentItemList.at(i)->setText(2,QString::number(currentPVPOIndex));
3024 parentItemList.at(i)->setData(0, Qt::UserRole,currentPVPOIndex);
3026 fTreeItemModels.insert(std::pair <int, PVPath >(currentPVPOIndex,fullPath) );
3030 parentItemList.at(i)->setFont (0,f);
3033 parentItemList.at(i)->setForeground (0,QBrush());
3036 parentItemList.at(i)->setToolTip (0,
"");
3038 changeQColorForTreeWidgetItem(parentItemList.at(i),QColor((
int)(color.
GetRed()*255),
3045 parentItemList.at(i)->setCheckState(0,Qt::Checked);
3046 updatePositivePoIndexSceneTreeWidgetQuickMap(currentPVPOIndex,parentItemList.at(i));
3050 subItem = parentItemList.at(i);
3054 }
else if (currentIndexInTreeSceneHandler < (fullPath.size()-1)) {
3055 subItem = parentItemList.at(i);
3062 if (currentIndexInTreeSceneHandler == (fullPath.size()-1)) {
3063 createTreeWidgetItem(fullPath,
3064 QString(currentPVName.c_str()),
3067 QString(fullPath.at(fullPathIndex).GetPhysicalVolume()->GetLogicalVolume()->GetName().data()),
3072 if (currentPVPOIndex > fMaxPOindexInserted) {
3073 fMaxPOindexInserted = currentPVPOIndex;
3079 if (subItem == NULL) {
3081 if (currentIndexInTreeSceneHandler < (fullPath.size()-1)) {
3082 subItem = createTreeWidgetItem(fullPath,
3083 QString(currentPVName.c_str()),
3086 QString(fullPath.at(fullPathIndex).GetPhysicalVolume()->GetLogicalVolume()->GetName().data()),
3093 return parseAndInsertInSceneTree(subItem,pPVModel,fullPathIndex+1,parentRoot,currentIndexInTreeSceneHandler+1,currentPVPOIndex);
3099void G4OpenGLQtViewer::changeOpenCloseVisibleHiddenSelectedColorSceneTreeElement(
3100 QTreeWidgetItem* subItem
3104 QTreeWidgetItem* oldItem = NULL;
3106 QTreeWidgetItem* foundItem = getOldTreeWidgetItem(subItem->data(0,Qt::UserRole).toInt());
3108 if (foundItem != NULL) {
3109 if (isSameSceneTreeElement(foundItem,subItem)) {
3110 oldItem = foundItem;
3113 if (foundItem == NULL) {
3116 std::map <int, QTreeWidgetItem*>::const_iterator i;
3117 i = fOldPositivePoIndexSceneTreeWidgetQuickMap.cbegin();
3118 while (i != fOldPositivePoIndexSceneTreeWidgetQuickMap.cend()) {
3119 if (isSameSceneTreeElement(i->second,subItem)) {
3120 oldItem = i->second;
3121 i = fOldPositivePoIndexSceneTreeWidgetQuickMap.cend();
3127 if (oldItem == NULL) {
3129 while (a < fOldNullPoIndexSceneTreeWidgetQuickVector.size()) {
3130 if (isSameSceneTreeElement(fOldNullPoIndexSceneTreeWidgetQuickVector[a],subItem)) {
3131 oldItem = fOldNullPoIndexSceneTreeWidgetQuickVector[a];
3132 a = fOldNullPoIndexSceneTreeWidgetQuickVector.size();
3141 if (oldItem != NULL) {
3142 subItem->setFlags(oldItem->flags());
3143 subItem->setCheckState(0,oldItem->checkState(0));
3144 subItem->setSelected(oldItem->isSelected());
3145 subItem->setExpanded(oldItem->isExpanded ());
3150 std::map <int, QTreeWidgetItem* >::iterator it;
3153 int oldPOIndex = oldItem->data(0,Qt::UserRole).toInt();
3154 it = fOldPositivePoIndexSceneTreeWidgetQuickMap.find(oldPOIndex);
3158 std::map <int, QColor >::iterator itVis;
3159 itVis = fOldVisAttrColorMap.find(oldPOIndex);
3161 QColor oldVisAttrColor;
3162 const QColor& newVisAttrColor = subItem->data(2,Qt::UserRole).value<QColor>();
3164 bool visAttrChange =
false;
3166 if (itVis != fOldVisAttrColorMap.end()) {
3167 oldVisAttrColor = itVis->second;
3168 if (oldVisAttrColor != newVisAttrColor) {
3169 visAttrChange =
true;
3172 visAttrChange =
true;
3175 if (visAttrChange) {
3176 fOldVisAttrColorMap.insert(std::pair <int, QColor > (subItem->data(0,Qt::UserRole).toInt(),newVisAttrColor) );
3180 if (it != fOldPositivePoIndexSceneTreeWidgetQuickMap.end()) {
3181 color = (it->second)->data(2,Qt::UserRole).value<QColor>();
3183 color = oldItem->data(2,Qt::UserRole).value<QColor>();
3185 changeQColorForTreeWidgetItem(subItem,color);
3197bool G4OpenGLQtViewer::isSameSceneTreeElement(
3198 QTreeWidgetItem* parentOldItem
3199 ,QTreeWidgetItem* parentNewItem
3205 int newCpNumber = -1;
3206 int oldCpNumber = -1;
3208 bool firstWhile =
true;
3210 while ((parentOldItem != NULL) && (parentNewItem != NULL)) {
3214 oldPO = parentOldItem->data(0,Qt::UserRole).toInt();
3215 newPO = parentNewItem->data(0,Qt::UserRole).toInt();
3221 const PVPath& oldFullPath = fOldTreeItemModels[oldPO];
3222 const PVPath& newFullPath = fTreeItemModels[newPO];
3223 if ((oldFullPath.size() > 0) &&
3224 (newFullPath.size() > 0)) {
3225 if (oldFullPath.size() != newFullPath.size()) {
3228 if (oldFullPath.at(oldFullPath.size()-1).GetTransform () == newFullPath.at(newFullPath.size()-1).GetTransform ()) {
3229 newCpNumber = newFullPath.at(newFullPath.size()-1).GetCopyNo();
3230 oldCpNumber = oldFullPath.at(oldFullPath.size()-1).GetCopyNo();
3239 if (oldCpNumber == -1) {
3240 oldCpNumber = parentOldItem->data(1,Qt::UserRole).toInt();
3242 if (newCpNumber == -1) {
3243 newCpNumber = parentNewItem->data(1,Qt::UserRole).toInt();
3245 if ((oldCpNumber != newCpNumber) ||
3247 (parentOldItem->text(0) != parentNewItem->text(0)) ) {
3250 }
else if ((parentOldItem->text(0) != parentNewItem->text(0)) ||
3251 (parentOldItem->text(3) != parentNewItem->text(3))) {
3254 parentOldItem = parentOldItem->parent();
3255 parentNewItem = parentNewItem->parent();
3266 ,
const std::string& modelDescription
3270 QString modelShortName = getModelShortName(model);
3275 const G4Text& g4Text =
dynamic_cast<const G4Text&
>(visible);
3278 catch (
const std::bad_cast&) {
3285 if (g4Marker.
GetInfo() !=
"") {
3286 modelShortName = g4Marker.
GetInfo();
3289 catch (
const std::bad_cast&) {}
3291 if (modelShortName ==
"") {
3295 if (fSceneTreeComponentTreeWidget == NULL) {
3296 createSceneTreeComponent();
3300 if (fSceneTreeComponentTreeWidget == NULL) {
3304 fSceneTreeComponentTreeWidget->blockSignals(
true);
3308 QList<QTreeWidgetItem *> resItem;
3309 resItem = fSceneTreeComponentTreeWidget->findItems (modelShortName, Qt::MatchExactly, 0 );
3310 QTreeWidgetItem * currentItem = NULL;
3311 const PVPath tmpFullPath;
3313 if (resItem.empty()) {
3314 currentItem = createTreeWidgetItem(tmpFullPath,
3323 currentItem = resItem.first();
3327 const QList<QTreeWidgetItem *>&
3328 resItems = fSceneTreeComponentTreeWidget->findItems (QString(modelDescription.c_str()), Qt::MatchFixedString| Qt::MatchCaseSensitive|Qt::MatchRecursive, 0 );
3330 bool alreadyPresent =
false;
3331 for (
int i = 0; i < resItems.size(); ++i) {
3332 if (currentPOIndex == resItems.at(i)->data(0,Qt::UserRole).toInt()) {
3333 alreadyPresent =
true;
3336 if (!alreadyPresent) {
3337 createTreeWidgetItem(tmpFullPath,
3346 fSceneTreeComponentTreeWidget->blockSignals(
false);
3354QString G4OpenGLQtViewer::getModelShortName(
const G4String& model) {
3356 QString modelShortName = model.data();
3357 if (modelShortName.mid(0,modelShortName.indexOf(
" ")) ==
"G4PhysicalVolumeModel") {
3358 modelShortName = fTouchableVolumes;
3360 if (modelShortName.mid(0,2) ==
"G4") {
3361 modelShortName = modelShortName.mid(2);
3363 if (modelShortName.indexOf(
"Model") != -1) {
3364 modelShortName = modelShortName.mid(0,modelShortName.indexOf(
"Model"));
3367 return modelShortName;
3375 if (fSceneTreeComponentTreeWidget == NULL) {
3381 if (fLastSceneTreeWidgetAskForIterator != fLastSceneTreeWidgetAskForIteratorEnd) {
3382 fLastSceneTreeWidgetAskForIterator++;
3384 QTreeWidgetItem* item = getTreeWidgetItem(POindex);
3387 if ( item->checkState(0) == Qt::Checked) {
3395bool G4OpenGLQtViewer::parseAndCheckVisibility(QTreeWidgetItem * treeNode,
int POindex){
3396 bool isFound =
false;
3397 for (
int i = 0; i < treeNode->childCount() ; ++i) {
3399 if (treeNode->child(i)->data(0,Qt::UserRole).toInt() == POindex) {
3400 if (treeNode->child(i)->checkState(0) == Qt::Checked) {
3404 isFound = parseAndCheckVisibility(treeNode->child(i),POindex);
3413std::string G4OpenGLQtViewer::parseSceneTreeAndSaveState(){
3414 std::string commandLine =
"";
3415 for (
int b=0;b<fSceneTreeComponentTreeWidget->topLevelItemCount();b++) {
3416 commandLine += parseSceneTreeElementAndSaveState(fSceneTreeComponentTreeWidget->topLevelItem(b),1)+
"\n";
3418 if (commandLine !=
"") {
3419 commandLine = std::string(
"# Disable auto refresh and quieten vis messages whilst scene and\n") +
3420 "# trajectories are established:\n" +
3421 "/vis/viewer/set/autoRefresh false\n" +
3422 "/vis/verbose errors" +
3424 "# Re-establish auto refreshing and verbosity:\n" +
3425 "/vis/viewer/set/autoRefresh true\n" +
3426 "/vis/verbose confirmations\n";
3432std::string G4OpenGLQtViewer::parseSceneTreeElementAndSaveState(QTreeWidgetItem* item,
unsigned int level){
3434 std::string str( level,
' ' );
3435 std::string commandLine =
"\n#"+ str +
"PV Name: " + item->text(0).toStdString();
3437 if (item->text(3) !=
"") {
3438 commandLine +=
" LV Name: "+item->text(3).toStdString()+
"\n";
3440 commandLine +=
"/vis/geometry/set/visibility " + item->text(3).toStdString() +
" ! ";
3441 if (item->checkState(0) == Qt::Checked) {
3444 if (item->checkState(0) == Qt::Unchecked) {
3450 const QColor& c = item->data(2,Qt::UserRole).value<QColor>();
3451 std::stringstream red;
3452 red << ((double)c.red())/255;
3453 std::stringstream green;
3454 green << (double)c.green()/255;
3455 std::stringstream blue;
3456 blue << ((double)c.blue())/255;
3457 std::stringstream
alpha;
3458 alpha << ((double)c.alpha())/255;
3460 commandLine +=
"/vis/geometry/set/colour " + item->text(3).toStdString() +
" ! " + red.str() +
" " + green.str() +
" " + blue.str() +
" " +
alpha.str()+
"\n";
3463 commandLine +=
"\n";
3467 for (
int b=0;b< item->childCount();b++) {
3468 commandLine += parseSceneTreeElementAndSaveState(item->child(b),level+1);
3475void G4OpenGLQtViewer::sceneTreeComponentItemChanged(QTreeWidgetItem* item,
int) {
3477 if (fCheckSceneTreeComponentSignalLock ==
false) {
3478 fCheckSceneTreeComponentSignalLock =
true;
3480 if (item->checkState(0) == Qt::Checked) {
3483 setCheckComponent(item,checked);
3486 fCheckSceneTreeComponentSignalLock =
false;
3491void G4OpenGLQtViewer::sceneTreeComponentSelected() {
3494void G4OpenGLQtViewer::changeDepthInSceneTree (
int val){
3497 if (fSceneTreeComponentTreeWidget == NULL) {
3508 double depth = 1 + ((double)val)/1000 * ((
double)fSceneTreeDepth+1);
3511 fCheckSceneTreeComponentSignalLock =
true;
3517 for (
int b=0;b<fSceneTreeComponentTreeWidget->topLevelItemCount();b++) {
3518 changeDepthOnSceneTreeItem(depth,1.,fSceneTreeComponentTreeWidget->topLevelItem(b));
3526 fCheckSceneTreeComponentSignalLock =
false;
3531void G4OpenGLQtViewer::changeColorAndTransparency(QTreeWidgetItem* item,
int) {
3536 const QColor& old = QColor(item->data(2,Qt::UserRole).value<QColor>());
3538 const QColor& color = QColorDialog::getColor(old,
3539 fSceneTreeComponentTreeWidget,
3540 " Get color and transparency",
3541 QColorDialog::ShowAlphaChannel);
3543 if (color.isValid()) {
3545 changeColorAndTransparency(item->data(0,Qt::UserRole).toInt(),
3552 changeQColorForTreeWidgetItem(item,color);
3557void G4OpenGLQtViewer::changeColorAndTransparency(GLuint index,
G4Color color) {
3561 if (iPO >= 0 && fTreeItemModels.find(iPO) != fTreeItemModels.end()) {
3562 const PVPath& fullPath = fTreeItemModels[iPO];
3564 if (fullPath.size()) {
3575 QTreeWidgetItem* item = getTreeWidgetItem(poIndex);
3579 const QColor& color = item->data(2,Qt::UserRole).value<QColor>();
3591const std::vector<G4ModelingParameters::VisAttributesModifier>*
3594 static std::vector<G4ModelingParameters::VisAttributesModifier>
3595 privateVisAttributesModifiers;
3597 privateVisAttributesModifiers.clear();
3650 return &privateVisAttributesModifiers;
3654void G4OpenGLQtViewer::changeSearchSelection()
3656 const QString& searchText = fFilterOutput->text();
3657 if (fSceneTreeComponentTreeWidget == NULL) {
3662 for (
int a=0; a<fSceneTreeComponentTreeWidget->topLevelItemCount(); a++) {
3663 fSceneTreeComponentTreeWidget->topLevelItem(a)->setExpanded(
false);
3664 fSceneTreeComponentTreeWidget->topLevelItem(a)->setSelected(
false);
3665 clearSceneTreeSelection(fSceneTreeComponentTreeWidget->topLevelItem(a));
3668 QList<QTreeWidgetItem *> itemList = fSceneTreeComponentTreeWidget->findItems (searchText,Qt::MatchContains | Qt::MatchRecursive,0);
3670 for (
int i = 0; i < itemList.size(); ++i) {
3671 QTreeWidgetItem* expandParentItem = itemList.at(i);
3672 while (expandParentItem->parent() != NULL) {
3673 expandParentItem->parent()->setExpanded(
true);
3674 expandParentItem = expandParentItem->parent();
3676 itemList.at(i)->setSelected(
true);
3682void G4OpenGLQtViewer::clearSceneTreeSelection(QTreeWidgetItem* item) {
3683 for (
int a=0; a<item->childCount(); a++) {
3684 item->child(a)->setSelected(
false);
3685 item->child(a)->setExpanded(
false);
3686 clearSceneTreeSelection(item->child(a));
3692bool G4OpenGLQtViewer::isPVVolume(QTreeWidgetItem* item) {
3693 QTreeWidgetItem* sParent = item;
3694 while (sParent->parent() != NULL) {
3695 sParent = sParent->parent();
3697 if (sParent->text(0) != fTouchableVolumes) {
3701 if (item->text(0) == fTouchableVolumes) {
3708void G4OpenGLQtViewer::changeDepthOnSceneTreeItem(
3710 ,
double currentDepth
3711 ,QTreeWidgetItem* item
3713 double transparencyLevel = 0.;
3718 if (isPVVolume(item)) {
3719 if ((lookForDepth-currentDepth) < 0) {
3720 item->setCheckState(0,Qt::Checked);
3721 updatePositivePoIndexSceneTreeWidgetQuickMap(item->data(0,Qt::UserRole).toInt(),item);
3722 transparencyLevel = 1;
3723 }
else if ((lookForDepth-currentDepth) > 1 ){
3724 item->setCheckState(0,Qt::Unchecked);
3725 updatePositivePoIndexSceneTreeWidgetQuickMap(item->data(0,Qt::UserRole).toInt(),item);
3726 transparencyLevel = 0;
3728 item->setCheckState(0,Qt::Checked);
3729 updatePositivePoIndexSceneTreeWidgetQuickMap(item->data(0,Qt::UserRole).toInt(),item);
3730 transparencyLevel = 1-(lookForDepth-currentDepth);
3734 if (item->data(0,Qt::UserRole).toInt() >= 0) {
3747 if (((color.
GetAlpha()-transparencyLevel) > 0.000001) ||
3748 ((color.
GetAlpha()-transparencyLevel) < -0.000001)) {
3749 if ((item->text(3) !=
"")) {
3755 changeQColorForTreeWidgetItem(item,QColor((
int)(color.
GetRed()*255),
3758 (
int)(transparencyLevel*255)));
3763 for (
int b=0;b< item->childCount();b++) {
3764 changeDepthOnSceneTreeItem(lookForDepth,currentDepth+1,item->child(b));
3772 if (fSceneTreeComponentTreeWidget) {
3774 if (fSceneTreeComponentTreeWidget->topLevelItemCount () > 0) {
3776 fPVRootNodeCreate =
false;
3779 fOldPositivePoIndexSceneTreeWidgetQuickMap.clear();
3780 fOldNullPoIndexSceneTreeWidgetQuickVector.clear();
3781 fOldTreeItemModels.clear();
3784 for (
int b =0; b <fSceneTreeComponentTreeWidget->topLevelItemCount();b++) {
3793 int poIndex = fSceneTreeComponentTreeWidget->topLevelItem(b)->data(0,Qt::UserRole).toInt();
3794 if (poIndex != -1) {
3795 fOldPositivePoIndexSceneTreeWidgetQuickMap.insert(std::pair <int, QTreeWidgetItem*> (poIndex,cloneWidgetItem(fSceneTreeComponentTreeWidget->topLevelItem(b))));
3797 fOldNullPoIndexSceneTreeWidgetQuickVector.push_back(cloneWidgetItem(fSceneTreeComponentTreeWidget->topLevelItem(b)));
3801 cloneSceneTree(fSceneTreeComponentTreeWidget->topLevelItem(b));
3805 fOldTreeItemModels.insert(fTreeItemModels.begin(), fTreeItemModels.end());
3808 int tmp2 = fSceneTreeComponentTreeWidget->topLevelItemCount();
3810 delete fSceneTreeComponentTreeWidget->takeTopLevelItem (0);
3811 tmp2 = fSceneTreeComponentTreeWidget->topLevelItemCount();
3813 fPositivePoIndexSceneTreeWidgetQuickMap.clear();
3816 fOldLastSceneTreeWidgetAskForIterator = fOldPositivePoIndexSceneTreeWidgetQuickMap.begin();
3817 fOldLastSceneTreeWidgetAskForIteratorEnd = fOldPositivePoIndexSceneTreeWidgetQuickMap.end();
3818 fSceneTreeDepth = 1;
3819 fModelShortNameItem = NULL;
3820 fMaxPOindexInserted = -1;
3833QTreeWidgetItem * G4OpenGLQtViewer::cloneWidgetItem(QTreeWidgetItem* item) {
3835 QTreeWidgetItem* cloneItem =
new QTreeWidgetItem();
3839 cloneItem->setText(0,item->text(0));
3840 cloneItem->setData(1,Qt::UserRole,item->data(1,Qt::UserRole).toInt());
3841 cloneItem->setText(2,item->text(2));
3842 cloneItem->setData(0, Qt::UserRole,item->data(0,Qt::UserRole).toInt());
3843 cloneItem->setText(3,item->text(3));
3844 cloneItem->setFlags(item->flags());
3845 cloneItem->setToolTip(0,item->toolTip(0));
3846 cloneItem->setCheckState(0,item->checkState(0));
3847 cloneItem->setSelected(item->isSelected());
3848 cloneItem->setExpanded(item->isExpanded ());
3850 cloneItem->setData(2,Qt::UserRole,item->data(2,Qt::UserRole).value<QColor>());
3859void G4OpenGLQtViewer::cloneSceneTree(
3860 QTreeWidgetItem* rootItem
3863 for (
int b=0;b< rootItem->childCount();b++) {
3865 QTreeWidgetItem *child = rootItem->child(b);
3868 int poIndex = child->data(0,Qt::UserRole).toInt();
3869 if (poIndex != -1) {
3870 fOldPositivePoIndexSceneTreeWidgetQuickMap.insert(std::pair <int, QTreeWidgetItem*> (poIndex,cloneWidgetItem(child)));
3872 fOldNullPoIndexSceneTreeWidgetQuickVector.push_back(cloneWidgetItem(child));
3874 cloneSceneTree(child);
3882 void G4OpenGLQtViewer::updatePositivePoIndexSceneTreeWidgetQuickMap(
int POindex,QTreeWidgetItem* item) {
3885 std::map <int, QTreeWidgetItem*>::iterator i;
3886 i = fPositivePoIndexSceneTreeWidgetQuickMap.find(POindex);
3888 if (i == fPositivePoIndexSceneTreeWidgetQuickMap.end()) {
3889 fPositivePoIndexSceneTreeWidgetQuickMap.insert(std::pair <int, QTreeWidgetItem*> (POindex,item) );
3890 fLastSceneTreeWidgetAskForIterator = fPositivePoIndexSceneTreeWidgetQuickMap.end();
3891 fLastSceneTreeWidgetAskForIteratorEnd = fPositivePoIndexSceneTreeWidgetQuickMap.end();
3899void G4OpenGLQtViewer::changeQColorForTreeWidgetItem(QTreeWidgetItem* item,
const QColor& qc) {
3901 int POIndex = item->data(0,Qt::UserRole).toInt();
3902 updatePositivePoIndexSceneTreeWidgetQuickMap(POIndex,item );
3904 QPixmap pixmap = QPixmap(QSize(16, 16));
3905 if (item->data(0,Qt::UserRole).toInt() != -1) {
3908 pixmap.fill (QColor(255,255,255,255));
3910 QPainter painter(&pixmap);
3911 painter.setPen(Qt::black);
3912 painter.drawRect(0,0,15,15);
3914 item->setIcon(0,pixmap);
3915 item->setData(2,Qt::UserRole,qc);
3924QTreeWidgetItem* G4OpenGLQtViewer::getTreeWidgetItem(
int POindex){
3927 if (POindex == -1) {
3931 if (fPositivePoIndexSceneTreeWidgetQuickMap.size() == 0){
3935 if (fLastSceneTreeWidgetAskForIterator != fLastSceneTreeWidgetAskForIteratorEnd) {
3936 if (POindex == fLastSceneTreeWidgetAskForIterator->first) {
3937 if (fLastSceneTreeWidgetAskForIterator->second != NULL) {
3938 return fLastSceneTreeWidgetAskForIterator->second;
3944 fLastSceneTreeWidgetAskForIterator = fPositivePoIndexSceneTreeWidgetQuickMap.find(POindex);
3945 fLastSceneTreeWidgetAskForIteratorEnd = fPositivePoIndexSceneTreeWidgetQuickMap.end();
3947 if (fLastSceneTreeWidgetAskForIterator != fPositivePoIndexSceneTreeWidgetQuickMap.end()) {
3948 return fLastSceneTreeWidgetAskForIterator->second;
3957QTreeWidgetItem* G4OpenGLQtViewer::getOldTreeWidgetItem(
int POindex){
3961 if (POindex == -1) {
3965 if (fOldPositivePoIndexSceneTreeWidgetQuickMap.size() == 0){
3971 if (fOldLastSceneTreeWidgetAskForIterator != fOldLastSceneTreeWidgetAskForIteratorEnd) {
3972 fOldLastSceneTreeWidgetAskForIterator++;
3975 if (fOldLastSceneTreeWidgetAskForIterator != fOldPositivePoIndexSceneTreeWidgetQuickMap.end()) {
3976 if (POindex == fOldLastSceneTreeWidgetAskForIterator->first) {
3977 if (fOldLastSceneTreeWidgetAskForIterator->second != NULL) {
3978 return fOldLastSceneTreeWidgetAskForIterator->second;
3984 fOldLastSceneTreeWidgetAskForIterator = fOldPositivePoIndexSceneTreeWidgetQuickMap.find(POindex);
3985 fOldLastSceneTreeWidgetAskForIteratorEnd = fOldPositivePoIndexSceneTreeWidgetQuickMap.end();
3987 if (fOldLastSceneTreeWidgetAskForIterator != fOldPositivePoIndexSceneTreeWidgetQuickMap.end()) {
3988 return fOldLastSceneTreeWidgetAskForIterator->second;
4001 if (fUISceneTreeWidget == NULL) {
4004 if (fSceneTreeComponentTreeWidget == NULL) {
4009 fSceneTreeComponentTreeWidget->sortItems (0, Qt::AscendingOrder );
4033 fDrawingWireframe->setChecked(
true);
4034 fDrawingLineRemoval->setChecked(
false);
4035 fDrawingSurfaceRemoval->setChecked(
false);
4036 fDrawingLineSurfaceRemoval->setChecked(
false);
4041 fDrawingLineRemoval->setChecked(
true);
4042 fDrawingWireframe->setChecked(
false);
4043 fDrawingSurfaceRemoval->setChecked(
false);
4044 fDrawingLineSurfaceRemoval->setChecked(
false);
4049 fDrawingSurfaceRemoval->setChecked(
true);
4050 fDrawingWireframe->setChecked(
false);
4051 fDrawingLineRemoval->setChecked(
false);
4052 fDrawingLineSurfaceRemoval->setChecked(
false);
4057 fDrawingLineSurfaceRemoval->setChecked(
true);
4058 fDrawingWireframe->setChecked(
false);
4059 fDrawingLineRemoval->setChecked(
false);
4060 fDrawingSurfaceRemoval->setChecked(
false);
4061 fDrawingLineSurfaceRemoval->setChecked(
false);
4071 fProjectionOrtho->setChecked(
true);
4072 fProjectionPerspective->setChecked(
false);
4077 fProjectionPerspective->setChecked(
true);
4078 fProjectionOrtho->setChecked(
false);
4084 if (
fUiQt && fContextMenu) {
4086 fMousePickAction->setChecked(
true);
4087 fMouseZoomOutAction->setChecked(
false);
4088 fMouseZoomInAction->setChecked(
false);
4089 fMouseRotateAction->setChecked(
false);
4090 fMouseMoveAction->setChecked(
false);
4092 fMouseZoomOutAction->setChecked(
true);
4093 fMousePickAction->setChecked(
false);
4094 fMouseZoomInAction->setChecked(
false);
4095 fMouseRotateAction->setChecked(
false);
4096 fMouseMoveAction->setChecked(
false);
4098 fMouseZoomInAction->setChecked(
true);
4099 fMousePickAction->setChecked(
false);
4100 fMouseZoomOutAction->setChecked(
false);
4101 fMouseRotateAction->setChecked(
false);
4102 fMouseMoveAction->setChecked(
false);
4104 fMouseRotateAction->setChecked(
true);
4105 fMousePickAction->setChecked(
false);
4106 fMouseZoomOutAction->setChecked(
false);
4107 fMouseZoomInAction->setChecked(
false);
4108 fMouseMoveAction->setChecked(
false);
4110 fMouseMoveAction->setChecked(
true);
4111 fMousePickAction->setChecked(
false);
4112 fMouseZoomOutAction->setChecked(
false);
4113 fMouseZoomInAction->setChecked(
false);
4114 fMouseRotateAction->setChecked(
false);
4125 if (!fSceneTreeWidget) {
4126 createSceneTreeWidget();
4142 if (!fViewerPropertiesTableWidget) {
4143 createViewerPropertiesWidget();
4145 int treeWidgetInfosIgnoredCommands = 0;
4155 if ((path->
GetCommandEntry()-fTreeWidgetInfosIgnoredCommands) != fViewerPropertiesTableWidget->rowCount()) {
4156 fViewerPropertiesTableWidget->clear();
4159 fViewerPropertiesTableWidget->blockSignals(
true);
4162 fViewerPropertiesTableWidget->setColumnCount (2);
4163 fViewerPropertiesTableWidget->setRowCount (path->
GetCommandEntry()-fTreeWidgetInfosIgnoredCommands);
4164 fViewerPropertiesTableWidget->setHorizontalHeaderLabels(QStringList() << tr(
"Property")
4166 fViewerPropertiesTableWidget->verticalHeader()->setVisible(
false);
4167 fViewerPropertiesTableWidget->setAlternatingRowColors (
true);
4175 QString params =
"";
4196 params = QString().number(
fVP. IsCulling ());
4201 params =
"intersection";
4226 }
else if(commandTmp->
GetCommandName() ==
"globalLineWidthScale") {
4257 params = QString().number(direction.
theta()/CLHEP::degree)+
" "+ QString().number(direction.
phi()/CLHEP::degree)+
" deg";
4268 }
else if(commandTmp->
GetCommandName() ==
"lineSegmentsPerCircle") {
4280 params =
"orthogonal";
4282 params = QString(
"perspective ") + QString().number(
fVP.
GetFieldHalfAngle()/CLHEP::degree) +
" deg";
4287 params =
"constrainUpDirection";
4289 params =
"freeRotation";
4294 params = QString(
"on ") +
4305 params =
"wireframe";
4320 params = QString().number(up.
theta()/CLHEP::degree)+
" "+ QString().number(up.
phi()/CLHEP::degree)+
" deg";
4328 params = QString().number(up.
x())+
" "+ QString().number(up.
y())+
" "+QString().number(up.
z())+
" ";
4333 params = QString().number(direction.
theta()/CLHEP::degree)+
" "+ QString().number(direction.
phi()/CLHEP::degree)+
" deg";
4341 params = QString().number(direction.
x())+
" "+ QString().number(direction.
y())+
" "+QString().number(direction.
z());
4371 QTableWidgetItem *nameItem;
4372 QTableWidgetItem *paramItem;
4375 QList<QTableWidgetItem *> list = fViewerPropertiesTableWidget->findItems (commandTmp->
GetCommandName().data(),Qt::MatchExactly);
4376 if (list.size() == 1) {
4377 nameItem = list.first();
4378 paramItem = fViewerPropertiesTableWidget->item(nameItem->row(),1);
4381 nameItem =
new QTableWidgetItem();
4382 paramItem =
new QTableWidgetItem();
4383 fViewerPropertiesTableWidget->setItem(a-treeWidgetInfosIgnoredCommands, 0, nameItem);
4384 fViewerPropertiesTableWidget->setItem(a-treeWidgetInfosIgnoredCommands, 1, paramItem);
4389 for(
G4int i_thGuidance=0; i_thGuidance < n_guidanceEntry; i_thGuidance++ ) {
4390 guidance += QString((
char*)(commandTmp->
GetGuidanceLine(i_thGuidance)).data()) +
"\n";
4393 nameItem->setToolTip(guidance);
4394 paramItem->setToolTip(GetCommandParameterList(commandTmp));
4396 fViewerPropertiesTableWidget->setRowHeight(a-treeWidgetInfosIgnoredCommands,15);
4401 paramItem->setText(params);
4403 nameItem->setFlags(Qt::NoItemFlags);
4404 nameItem->setForeground(QBrush());
4407 treeWidgetInfosIgnoredCommands++;
4411 for (
int i=0; i<treeWidgetInfosIgnoredCommands; i++) {
4412 fViewerPropertiesTableWidget->removeRow (fViewerPropertiesTableWidget->rowCount() - 1);
4416 if (!fViewerPropertiesTableWidgetIsInit) {
4417 fViewerPropertiesTableWidgetIsInit =
true;
4419 fViewerPropertiesTableWidget->resizeColumnsToContents();
4421 int x = fViewerPropertiesTableWidget->horizontalHeader()->length();
4422 int y = fViewerPropertiesTableWidget->verticalHeader()->length()+ fViewerPropertiesTableWidget->horizontalHeader()->sizeHint().height() + 2;
4428 QDialog* dial =
static_cast<QDialog*
> (fUIViewerPropertiesWidget->parent());
4430 dial->resize(x+56,y+46);
4433 fViewerPropertiesTableWidget->blockSignals(
false);
4435 fTreeWidgetInfosIgnoredCommands = treeWidgetInfosIgnoredCommands;
4443 fLastPickPoint = QPoint(aX,aY);
4449 if (!fPickInfosWidget) {
4450 createPickInfosWidget();
4453 const std::vector < G4OpenGLViewerPickMap* > & pickMapVector =
GetPickDetails(aX,aY);
4456 if (fPickInfosWidget) {
4457 QLayoutItem * wItem;
4458 if (fPickInfosWidget->layout()->count()) {
4459 while ((wItem = fPickInfosWidget->layout()->takeAt(0)) != 0) {
4460 delete wItem->widget();
4466 if (!fPickInfosWidget) {
4467 createPickInfosWidget();
4472 G4int nPickedObjectsWithAttributes = 0;
4473 for (
unsigned int a=0; a< pickMapVector.size(); a++) {
4474 const auto& pickMap = pickMapVector[a];
4476 std::ostringstream label;
4477 std::ostringstream content;
4478 std::string txt = pickMap->getAttributes()[0].data();
4479 if (pickMapVector[a]->getAttributes().size()) {
4480 ++nPickedObjectsWithAttributes;
4482 std::size_t pos1 = txt.find(
':');
4483 std::string storeKey = txt.substr(0,pos1);
4485 if (storeKey ==
"G4PhysicalVolumeModel") {
4488 std::size_t pos2 = txt.find(
':',pos1+1);
4489 std::size_t pos3 = txt.find(
'\n',pos2+1);
4490 label << txt.substr(pos2+1,pos3-pos2-1);
4492 }
else if (storeKey ==
"G4TrajectoriesModel") {
4494 label <<
"Trajectory:";
4495 std::size_t pos2 = txt.find(
':',pos1+1);
4496 std::size_t pos3 = txt.find(
'\n',pos2+1);
4497 label <<
" Run:" << txt.substr(pos2+1,pos3-pos2-1);
4498 std::size_t pos4 = txt.find(
':',pos3+1);
4499 std::size_t pos5 = txt.find(
'\n',pos4+1);
4500 label <<
", Event:" << txt.substr(pos4+1,pos5-pos4-1);
4504 label <<
"Hit number:" << a <<
", PickName: " << pickMap->getPickName();
4509 content << pickMap->print().data();
4510 G4int thisPickName = pickMap->getPickName();
4511 while (++a < pickMapVector.size()) {
4512 const auto& a_pickMap = pickMapVector[a];
4513 if (a_pickMap->getPickName() == thisPickName) {
4514 content << a_pickMap->print().data();
4521 QPushButton* pickCoutButton =
new QPushButton(label.str().c_str());
4522 pickCoutButton->setStyleSheet (
"text-align: left; padding: 1px; border: 0px;");
4523 pickCoutButton->setIcon(*fTreeIconClosed);
4524 fPickInfosWidget->layout()->addWidget(pickCoutButton);
4529 newStr = QStringList(QString(content.str().c_str()).trimmed());
4531 QTextEdit* ed =
new QTextEdit();
4532 ed->setReadOnly(
true);
4533 fPickInfosWidget->layout()->addWidget(ed);
4534 ed->setVisible((
false));
4535 ed->append(newStr.join(
""));
4537 std::cout << pickCoutButton->text().toStdString() <<
" "<< fPickInfosWidget->layout()->count()-1<< std::endl;
4538 int tmp = fPickInfosWidget->layout()->count()-1;
4539 connect(pickCoutButton, &QPushButton::clicked , [
this, tmp](){ this->toggleSceneTreeComponentPickingCout(tmp);});
4544 QLabel * pushUp =
new QLabel(
"");
4545 QSizePolicy vPolicy = QSizePolicy(QSizePolicy::Minimum,QSizePolicy::Minimum);
4546 vPolicy.setVerticalStretch(10);
4547 pushUp->setSizePolicy(vPolicy);
4548 fPickInfosWidget->layout()->addWidget(pushUp);
4553 changeColorAndTransparency(fLastHighlightName,fLastHighlightColor);
4555 if (pickMapVector.size() > 0 ) {
4557 fLastHighlightName = pickMapVector[0]->getPickName();
4560 changeColorAndTransparency(fLastHighlightName,
G4Color(1,1,1,1));
4564 QDialog* dial =
static_cast<QDialog*
> (fUIPickInfosWidget->parent());
4567 std::ostringstream oss;
4568 if (nPickedObjectsWithAttributes == 0) {
4570 }
else if (nPickedObjectsWithAttributes == 1) {
4573 oss << nPickedObjectsWithAttributes <<
" objects";
4575 oss <<
" selected - " <<
GetName();
4576 dial->setWindowTitle(oss.str().c_str());
4579 fPickInfosScrollArea->setVisible(
true);
4583void G4OpenGLQtViewer::toggleSceneTreeComponentPickingCout(
int pickItem) {
4588 for (
int a=0; a<fPickInfosWidget->layout()->count(); a++) {
4589 w = fPickInfosWidget->layout()->itemAt(a)->widget();
4590 QTextEdit* ed =
dynamic_cast<QTextEdit*
>(w);
4591 QPushButton* button;
4593 if (a == pickItem) {
4594 w->setVisible(!w->isVisible());
4596 w->setVisible(
false);
4599 button =
dynamic_cast<QPushButton*
>(fPickInfosWidget->layout()->itemAt(a-1)->widget());
4601 if (button->isVisible()) {
4602 button->setIcon(*fTreeIconOpen);
4604 button->setIcon(*fTreeIconClosed);
4613void G4OpenGLQtViewer::currentTabActivated(
int currentTab) {
4615 createViewerPropertiesWidget();
4616 createPickInfosWidget();
4617 createSceneTreeWidget();
4622void G4OpenGLQtViewer::tableWidgetViewerSetItemChanged(QTableWidgetItem * item) {
4625 QTableWidgetItem* previous = fViewerPropertiesTableWidget->item(fViewerPropertiesTableWidget->row(item),0);
4627 fViewerPropertiesTableWidget->blockSignals(
true);
4629 + previous->text().toStdString()
4631 + item->text().toStdString()).c_str());
4632 fViewerPropertiesTableWidget->blockSignals(
false);
4656QString G4OpenGLQtViewer::GetCommandParameterList (
4663 if( n_parameterEntry > 0 ) {
4668 for(
G4int i_thParameter=0; i_thParameter<n_parameterEntry; i_thParameter++ ) {
4670 txt +=
"\nParameter : " + QString((
char*)(param->
GetParameterName()).data()) +
"\n";
4673 txt +=
" Parameter type : " + QString(QChar(param->
GetParameterType())) +
"\n";
4675 txt +=
" Omittable : True\n";
4677 txt +=
" Omittable : False\n";
4680 txt +=
" Default value : taken from the current value\n";
4682 txt +=
" Default value : " + QString((
char*)(param->
GetDefaultValue()).data())+
"\n";
4685 txt +=
" Parameter range : " + QString((
char*)(param->
GetParameterRange()).data())+
"\n";
4695#ifdef G4MULTITHREADED
4697void G4OpenGLQtViewer::DoneWithMasterThread()
4703 if(!lWaitForVisSubThreadQtOpenGLContextInitialized->
owns_lock())
4704 lWaitForVisSubThreadQtOpenGLContextInitialized->
lock();
4707void G4OpenGLQtViewer::SwitchToVisSubThread()
4717 SetQGLContextVisSubThread(QThread::currentThread());
4723 if(!lWaitForVisSubThreadQtOpenGLContextMoved->
owns_lock())
4724 lWaitForVisSubThreadQtOpenGLContextMoved->
lock();
4728 lWaitForVisSubThreadQtOpenGLContextMoved);
4731 qGLW->makeCurrent();
4734void G4OpenGLQtViewer::DoneWithVisSubThread()
4743 qGLW->doneCurrent();
4746 qGLW->context()->moveToThread(fQGLContextMainThread);
4749void G4OpenGLQtViewer::SwitchToMasterThread()
4760 if(lWaitForVisSubThreadQtOpenGLContextInitialized->
owns_lock())
4761 lWaitForVisSubThreadQtOpenGLContextInitialized->
unlock();
4763 qGLW->makeCurrent();
4767void G4OpenGLQtViewer::MovingToVisSubThread(){
4777 if(!lWaitForVisSubThreadQtOpenGLContextInitialized->
owns_lock())
4778 lWaitForVisSubThreadQtOpenGLContextInitialized->
lock();
4782 lWaitForVisSubThreadQtOpenGLContextInitialized);
4785 SetQGLContextMainThread(QThread::currentThread());
4788 qGLW->doneCurrent();
4789 qGLW->context()->moveToThread(fQGLContextVisSubThread);
G4TemplateAutoLock< G4Mutex > G4AutoLock
QOpenGLWidget G4QGLWidgetType
#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)
virtual void CreateMainWindow(G4QGLWidgetType *, const QString &)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
G4Colour getColorForPoIndex(int poIndex)
void updatePickInfosWidget(int, int)
virtual ~G4OpenGLQtViewer()
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
void DrawText(const G4Text &)
QString setEncoderPath(QString path)
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)