32#ifdef G4VIS_BUILD_OPENGLQT_DRIVER
60#include <qpushbutton.h>
62#include <qdesktopwidget.h>
65#include <qimagewriter.h>
68#include <qtreewidget.h>
69#include <qapplication.h>
70#include <qmessagebox.h>
71#include <qfiledialog.h>
74#if QT_VERSION >= 0x050e00
75 #include <qelapsedtimer.h>
80#include <qcolordialog.h>
86#if QT_VERSION < 0x050600
87#include <qsignalmapper.h>
91#include <qmainwindow.h>
92#include <qtablewidget.h>
93#include <qheaderview.h>
94#include <qscrollarea.h>
101#include "moc_G4OpenGLQtViewer.cpp"
109#ifdef G4MULTITHREADED
116void G4OpenGLQtViewer::CreateMainWindow (
124 if(fGLWidget)
return;
126 fGLWidget = glWidget ;
129 G4Qt* interactorManager = G4Qt::getInstance ();
131 ResizeWindow(fVP.GetWindowSizeHintX(),fVP.GetWindowSizeHintY());
143 if (UI == NULL)
return;
152 bool isTabbedView =
false;
155 if (!interactorManager->IsExternalApp()) {
157 fWinSize_x = fVP.GetWindowSizeHintX();
158 fWinSize_y = fVP.GetWindowSizeHintY();
160 isTabbedView = fUiQt->AddTabWidget((QWidget*)fGLWidget,
name);
161 QObject::connect(fUiQt->GetViewerTabWidget(),
162 SIGNAL(currentChanged(
int)),
164 SLOT(currentTabActivated(
int)));
168 createSceneTreeWidget();
175 QWidget *glDialogWidget = getParentWidget();
176 if (glDialogWidget == NULL) {
179 glWidget->setParent(glDialogWidget);
180 QHBoxLayout *mainLayout =
new QHBoxLayout();
182 mainLayout->setMargin(0);
183 mainLayout->setSpacing(0);
184 mainLayout->addWidget(fGLWidget);
185 if (fGLWidget->inherits(
"QMainWindow")) {
186 fGLWidget->setWindowTitle( name);
188 glDialogWidget->setLayout(mainLayout);
192#if QT_VERSION >= 0x050a00
193 G4int offset = QApplication::desktop()->height()
194 - QGuiApplication::screenAt(QPoint(20,20))->availableGeometry().height();
196 G4int offset = QApplication::desktop()->height()
197 - QApplication::desktop()->availableGeometry().height();
200 G4int YPos= fVP.GetWindowAbsoluteLocationHintY(QApplication::desktop()->height());
201 if (fVP.GetWindowAbsoluteLocationHintY(QApplication::desktop()->height())< offset) {
204 glDialogWidget->resize(getWinWidth(), getWinHeight());
205 glDialogWidget->move(fVP.GetWindowAbsoluteLocationHintX(QApplication::desktop()->width()),YPos);
206 glDialogWidget->show();
209 if(!fGLWidget)
return;
218G4OpenGLQtViewer::G4OpenGLQtViewer (
219 G4OpenGLSceneHandler& scene
222 ,G4OpenGLViewer (scene)
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#if QT_VERSION < 0x050600
273 ,fSignalMapperMouse(NULL)
274 ,fSignalMapperSurface(NULL)
275 ,fSignalMapperPicking(NULL)
278 ,fTreeIconClosed(NULL)
279 ,fLastExportSliderValue(80)
280 ,fLastHighlightColor(
G4Color(0,0,0,0))
281 ,fLastHighlightName(0)
284 lWaitForVisSubThreadQtOpenGLContextInitialized
285 =
new G4AutoLock(mWaitForVisSubThreadQtOpenGLContextInitialized,
287 lWaitForVisSubThreadQtOpenGLContextMoved
288 =
new G4AutoLock(mWaitForVisSubThreadQtOpenGLContextMoved,
292 if (QCoreApplication::instance () == NULL) {
295 G4Qt::getInstance ();
297 fLastPos3 = QPoint(-1,-1);
298 fLastPos2 = QPoint(-1,-1);
299 fLastPos1 = QPoint(-1,-1);
301 initMovieParameters();
303#if QT_VERSION < 0x050e00
304 fLastEventTime =
new QTime();
306 fLastEventTime =
new QElapsedTimer();
308#if QT_VERSION < 0x050600
309 fSignalMapperMouse =
new QSignalMapper(
this);
310 fSignalMapperSurface =
new QSignalMapper(
this);
313 fFileSavePath = QDir::currentPath();
316 QList<QByteArray> formats = QImageWriter::supportedImageFormats ();
317 for (
int i = 0; i < formats.size(); ++i) {
318 addExportImageFormat(formats.at(i).data());
321 const char *
const icon1[]={
379 const char *
const icon2[]={
472 const char *
const search[] = {
484 "OOOOOOOOOOOOOOOOOOO",
485 "OOOOOOOOOOOOOOOOOOO",
486 "OOOOOOOo. .oOOOOOO",
489 "OOOOO. XOOOOX .OOOO",
492 "OOOOO. XOOOOo .OOOO",
496 "OOOOOOOOOOOOO. XOO",
497 "OOOOOOOOOOOOOO. XOO",
498 "OOOOOOOOOOOOOOOoOOO",
499 "OOOOOOOOOOOOOOOOOOO",
500 "OOOOOOOOOOOOOOOOOOO",
501 "OOOOOOOOOOOOOOOOOOO",
502 "OOOOOOOOOOOOOOOOOOO"
505 fSearchIcon =
new QPixmap(search);
506 fTreeIconOpen =
new QPixmap(icon1);
507 fTreeIconClosed =
new QPixmap(icon2);
512G4OpenGLQtViewer::~G4OpenGLQtViewer (
522 if (fSceneTreeWidget != NULL) {
523 if (fSceneTreeWidget->layout() != NULL) {
524 while ((wItem = fSceneTreeWidget->layout()->takeAt(0)) != 0) {
525 delete wItem->widget();
532 delete fTreeIconOpen;
533 delete fTreeIconClosed;
535 G4cout <<removeTempFolder().toStdString().c_str() <<
G4endl;
537 delete lWaitForVisSubThreadQtOpenGLContextInitialized;
538 delete lWaitForVisSubThreadQtOpenGLContextMoved;
546void G4OpenGLQtViewer::createPopupMenu() {
548 fContextMenu =
new QMenu(
"All");
550 QMenu *mMouseAction = fContextMenu->addMenu(
"&Mouse actions");
552#if QT_VERSION < 0x050600
553 fMouseRotateAction = mMouseAction->addAction(
"Rotate", fSignalMapperMouse, SLOT(map()));
554 fMouseMoveAction = mMouseAction->addAction(
"Move", fSignalMapperMouse, SLOT(map()));
555 fMousePickAction = mMouseAction->addAction(
"Pick", fSignalMapperMouse, SLOT(map()));
556 fMouseZoomOutAction = mMouseAction->addAction(
"Zoom out", fSignalMapperMouse, SLOT(map()));
557 fMouseZoomInAction = mMouseAction->addAction(
"Zoom in", fSignalMapperMouse, SLOT(map()));
559 fMouseRotateAction = mMouseAction->addAction(
"Rotate",
this, [=](){ this->toggleMouseAction(1); });
560 fMouseMoveAction = mMouseAction->addAction(
"Move",
this, [=](){ this->toggleMouseAction(2); });
561 fMousePickAction = mMouseAction->addAction(
"Pick",
this, [=](){ this->toggleMouseAction(3); });
562 fMouseZoomOutAction = mMouseAction->addAction(
"Zoom out",
this, [=](){ this->toggleMouseAction(4); });
563 fMouseZoomInAction = mMouseAction->addAction(
"Zoom in",
this, [=](){ this->toggleMouseAction(5); });
565 QAction *shortcutsAction = mMouseAction->addAction(
"Show shortcuts");
567 fMouseRotateAction->setCheckable(
true);
568 fMouseMoveAction->setCheckable(
true);
569 fMousePickAction->setCheckable(
true);
570 fMouseZoomOutAction->setCheckable(
true);
571 fMouseZoomInAction->setCheckable(
true);
572 shortcutsAction->setCheckable(
false);
574#if QT_VERSION < 0x050600
575 connect(fSignalMapperMouse, SIGNAL(mapped(
int)),
this, SLOT(toggleMouseAction(
int)));
576 fSignalMapperMouse->setMapping(fMouseRotateAction,1);
577 fSignalMapperMouse->setMapping(fMouseMoveAction,2);
578 fSignalMapperMouse->setMapping(fMousePickAction,3);
579 fSignalMapperMouse->setMapping(fMouseZoomOutAction,4);
580 fSignalMapperMouse->setMapping(fMouseZoomInAction,5);
583 QObject::connect(shortcutsAction,
584 SIGNAL(triggered(
bool)),
586 SLOT(showShortcuts()));
589 QMenu *mStyle = fContextMenu->addMenu(
"&Style");
591 QMenu *mProjection = mStyle->addMenu(
"&Projection");
593#if QT_VERSION < 0x050600
594 fProjectionOrtho = mProjection->addAction(
"Orthographic", fSignalMapperSurface, SLOT(map()));
595 fProjectionPerspective = mProjection->addAction(
"Perspective", fSignalMapperSurface, SLOT(map()));
598 if (fVP.GetFieldHalfAngle() == 0) {
599 createRadioAction(fProjectionOrtho, fProjectionPerspective,SLOT(toggleProjection(
bool)),1);
601 createRadioAction(fProjectionOrtho, fProjectionPerspective,SLOT(toggleProjection(
bool)),2);
605 fProjectionOrtho = mProjection->addAction(
"Orthographic",
this, [=](){ this->toggleProjection(1); });
606 fProjectionPerspective = mProjection->addAction(
"Perspective",
this, [=](){ this->toggleProjection(2); });
609 QMenu *mDrawing = mStyle->addMenu(
"&Drawing");
611#if QT_VERSION < 0x050600
612 fDrawingWireframe = mDrawing->addAction(
"Wireframe", fSignalMapperSurface, SLOT(map()));
614 fDrawingLineRemoval = mDrawing->addAction(
"Hidden line removal", fSignalMapperSurface, SLOT(map()));
616 fDrawingSurfaceRemoval = mDrawing->addAction(
"Hidden Surface removal", fSignalMapperSurface, SLOT(map()));
618 fDrawingLineSurfaceRemoval = mDrawing->addAction(
"Hidden line and surface removal", fSignalMapperSurface, SLOT(map()));
621#if QT_VERSION < 0x050600
622 connect(fSignalMapperSurface, SIGNAL(mapped(
int)),
this, SLOT(toggleSurfaceAction(
int)));
623 fSignalMapperSurface->setMapping(fDrawingWireframe,1);
624 fSignalMapperSurface->setMapping(fDrawingLineRemoval,2);
625 fSignalMapperSurface->setMapping(fDrawingSurfaceRemoval,3);
626 fSignalMapperSurface->setMapping(fDrawingLineSurfaceRemoval,4);
628 fDrawingWireframe = mDrawing->addAction(
"Wireframe",
this, [=](){ this->toggleSurfaceAction(1); });
629 fDrawingLineRemoval = mDrawing->addAction(
"Hidden line removal",
this, [=](){ this->toggleSurfaceAction(2); });
630 fDrawingSurfaceRemoval = mDrawing->addAction(
"Hidden Surface removal",
this, [=](){ this->toggleSurfaceAction(3); });
631 fDrawingLineSurfaceRemoval = mDrawing->addAction(
"Hidden line and surface removal",
this, [=](){ this->toggleSurfaceAction(4); });
634 fDrawingWireframe->setCheckable(
true);
635 fDrawingLineRemoval->setCheckable(
true);
636 fDrawingSurfaceRemoval->setCheckable(
true);
637 fDrawingLineSurfaceRemoval->setCheckable(
true);
641 QAction *backgroundColorChooser ;
643 backgroundColorChooser = mStyle->addAction(
"Background color");
644 QObject ::connect(backgroundColorChooser,
647 SLOT(actionChangeBackgroundColor()));
651 QAction *textColorChooser ;
653 textColorChooser = mStyle->addAction(
"Text color");
654 QObject ::connect(textColorChooser,
657 SLOT(actionChangeTextColor()));
661 QAction *defaultColorChooser ;
663 defaultColorChooser = mStyle->addAction(
"Default color");
664 QObject ::connect(defaultColorChooser,
667 SLOT(actionChangeDefaultColor()));
671 QMenu *mActions = fContextMenu->addMenu(
"&Actions");
672 QAction *createEPS = mActions->addAction(
"Save as ...");
673 QObject ::connect(createEPS,
676 SLOT(actionSaveImage()));
679 QAction *movieParameters = mActions->addAction(
"Save as movie...");
680 QObject ::connect(movieParameters,
683 SLOT(actionMovieParameters()));
689 QMenu *mSpecial = fContextMenu->addMenu(
"S&pecial");
690 QMenu *mTransparency = mSpecial->addMenu(
"Transparency");
691 QAction *transparencyOn = mTransparency->addAction(
"On");
692 QAction *transparencyOff = mTransparency->addAction(
"Off");
694 if (transparency_enabled ==
false) {
695 createRadioAction(transparencyOn,transparencyOff,SLOT(toggleTransparency(
bool)),2);
696 }
else if (transparency_enabled ==
true) {
697 createRadioAction(transparencyOn,transparencyOff,SLOT(toggleTransparency(
bool)),1);
703 QMenu *mAntialiasing = mSpecial->addMenu(
"Antialiasing");
704 QAction *antialiasingOn = mAntialiasing->addAction(
"On");
705 QAction *antialiasingOff = mAntialiasing->addAction(
"Off");
707 if (antialiasing_enabled ==
false) {
708 createRadioAction(antialiasingOn,antialiasingOff,SLOT(toggleAntialiasing(
bool)),2);
709 }
else if (antialiasing_enabled ==
true) {
710 createRadioAction(antialiasingOn,antialiasingOff,SLOT(toggleAntialiasing(
bool)),1);
712 mAntialiasing->clear();
715 QMenu *mHaloing = mSpecial->addMenu(
"Haloing");
716 QAction *haloingOn = mHaloing->addAction(
"On");
717 QAction *haloingOff = mHaloing->addAction(
"Off");
718 if (haloing_enabled ==
false) {
719 createRadioAction(haloingOn,haloingOff,SLOT(toggleHaloing(
bool)),2);
720 }
else if (haloing_enabled ==
true) {
721 createRadioAction(haloingOn,haloingOff,SLOT(toggleHaloing(
bool)),1);
726 QMenu *mAux = mSpecial->addMenu(
"Auxiliary edges");
727 QAction *auxOn = mAux->addAction(
"On");
728 QAction *auxOff = mAux->addAction(
"Off");
729 if (!fVP.IsAuxEdgeVisible()) {
730 createRadioAction(auxOn,auxOff,SLOT(toggleAux(
bool)),2);
732 createRadioAction(auxOn,auxOff,SLOT(toggleAux(
bool)),1);
736 QMenu *mHiddenMarkers = mSpecial->addMenu(
"Hidden markers");
737 QAction *hiddenMarkersOn = mHiddenMarkers->addAction(
"On");
738 QAction *hiddenMarkersOff = mHiddenMarkers->addAction(
"Off");
739 if (fVP.IsMarkerNotHidden()) {
740 createRadioAction(hiddenMarkersOn,hiddenMarkersOff,SLOT(toggleHiddenMarkers(
bool)),2);
742 createRadioAction(hiddenMarkersOn,hiddenMarkersOff,SLOT(toggleHiddenMarkers(
bool)),1);
747 QMenu *mFullScreen = mSpecial->addMenu(
"&Full screen");
748 fFullScreenOn = mFullScreen->addAction(
"On");
749 fFullScreenOff = mFullScreen->addAction(
"Off");
750 createRadioAction(fFullScreenOn,fFullScreenOff,SLOT(toggleFullScreen(
bool)),2);
753 updateToolbarAndMouseContextMenu();
756void G4OpenGLQtViewer::G4manageContextMenuEvent(QContextMenuEvent *e)
759 G4cerr <<
"Visualization window not defined, please choose one before" <<
G4endl;
766 if ( fContextMenu ) {
767 fContextMenu->exec( e->globalPos() );
783void G4OpenGLQtViewer::createRadioAction(QAction *action1,QAction *action2,
const std::string& method,
unsigned int nCheck) {
785 action1->setCheckable(
true);
786 action2->setCheckable(
true);
789 action1->setChecked (
true);
791 action2->setChecked (
true);
793 QObject ::connect(action1, SIGNAL(triggered(
bool)),action2, SLOT(toggle()));
794 QObject ::connect(action2, SIGNAL(triggered(
bool)),action1, SLOT(toggle()));
796 QObject ::connect(action1, SIGNAL(toggled(
bool)),
this, method.c_str());
805void G4OpenGLQtViewer::showShortcuts() {
808 text =
"========= Mouse Shortcuts =========\n";
810 if (fUiQt->IsIconRotateSelected()) {
811 text +=
"Click and move mouse to rotate volume \n";
812 text +=
"ALT + Click and move mouse to rotate volume (Toggle View/Theta-Phi Direction) \n";
813 text +=
"CTRL + Click and move mouse to zoom in/out \n";
814 text +=
"SHIFT + Click and move mouse to change camera point of view \n";
815 }
else if (fUiQt->IsIconMoveSelected()) {
816 text +=
"Move camera point of view with mouse \n";
817 }
else if (fUiQt->IsIconPickSelected()) {
818 text +=
"Click and pick \n";
821 text +=
"Click and move mouse to rotate volume \n";
822 text +=
"ALT + Click and move mouse to rotate volume (Toggle View/Theta-Phi Direction) \n";
823 text +=
"CTRL + Click and zoom mouse to zoom in/out \n";
824 text +=
"SHIFT + Click and zoommove camera point of view \n";
826 text +=
"========= Move Shortcuts ========= \n";
827 text +=
"Press left/right arrows to move volume left/right \n";
828 text +=
"Press up/down arrows to move volume up/down \n";
829 text +=
"Press '+'/'-' to move volume toward/forward \n";
831 text +=
"========= Rotation (Theta/Phi) Shortcuts ========= \n";
832 text +=
"Press SHIFT + left/right arrows to rotate volume left/right \n";
833 text +=
"Press SHIFT + up/down arrows to rotate volume up/down \n";
835 text +=
"========= Rotation (View Direction) Shortcuts ========= \n";
836 text +=
"Press ALT + left/right to rotate volume around vertical direction \n";
837 text +=
"Press ALT + up/down to rotate volume around horizontal direction \n";
839 text +=
"========= Zoom View ========= \n";
840 text +=
"Press CTRL + '+'/'-' to zoom into volume \n";
842 text +=
"========= Misc ========= \n";
843 text +=
"Press ALT +/- to slow/speed rotation/move \n";
844 text +=
"Press H to reset view \n";
845 text +=
"Press Esc to exit FullScreen \n";
847 text +=
"========= Video ========= \n";
848 text +=
"In video mode : \n";
849 text +=
" Press SPACE to Start/Pause video recording \n";
850 text +=
" Press RETURN to Stop video recording \n";
855 if ( fShortcutsDialog == NULL) {
856 fShortcutsDialog =
new QDialog();
857 fShortcutsDialogInfos =
new QTextEdit() ;
858 QVBoxLayout *mainLayout =
new QVBoxLayout;
859 mainLayout->addWidget(fShortcutsDialogInfos);
860 fShortcutsDialog->setLayout(mainLayout);
861 fShortcutsDialog->setWindowTitle(tr(
"Shortcuts"));
864 fShortcutsDialogInfos->setPlainText(text.data());
865 fShortcutsDialog->show();
876void G4OpenGLQtViewer::toggleMouseAction(
int aAction) {
879 fUiQt->SetIconRotateSelected();
880 }
else if (aAction == 2) {
881 fUiQt->SetIconMoveSelected();
882 }
else if (aAction == 3) {
884 }
else if (aAction == 4) {
885 fUiQt->SetIconZoomOutSelected();
886 }
else if (aAction == 5) {
887 fUiQt->SetIconZoomInSelected();
891 updateToolbarAndMouseContextMenu();
905void G4OpenGLQtViewer::toggleSurfaceAction(
int aAction) {
912 }
else if (aAction ==2) {
915 }
else if (aAction ==3) {
918 }
else if (aAction ==4) {
921 fVP.SetDrawingStyle(d_style);
923 updateToolbarAndMouseContextMenu();
938void G4OpenGLQtViewer::toggleProjection(
bool check) {
941 fVP.SetOrthogonalProjection ();
943 fVP.SetPerspectiveProjection();
945 updateToolbarAndMouseContextMenu();
954void G4OpenGLQtViewer::toggleTransparency(
bool check) {
957 transparency_enabled =
true;
959 transparency_enabled =
false;
961 SetNeedKernelVisit (
true);
962 updateToolbarAndMouseContextMenu();
970void G4OpenGLQtViewer::toggleAntialiasing(
bool check) {
973 antialiasing_enabled =
false;
974 glDisable (GL_LINE_SMOOTH);
975 glDisable (GL_POLYGON_SMOOTH);
977 antialiasing_enabled =
true;
978 glEnable (GL_LINE_SMOOTH);
979 glHint (GL_LINE_SMOOTH_HINT, GL_NICEST);
980 glEnable (GL_POLYGON_SMOOTH);
981 glHint (GL_POLYGON_SMOOTH_HINT, GL_NICEST);
984 updateToolbarAndMouseContextMenu();
993void G4OpenGLQtViewer::toggleHaloing(
bool check) {
995 haloing_enabled =
false;
997 haloing_enabled =
true;
1000 updateToolbarAndMouseContextMenu();
1009void G4OpenGLQtViewer::toggleAux(
bool check) {
1011 fVP.SetAuxEdgeVisible(
true);
1013 fVP.SetAuxEdgeVisible(
false);
1015 SetNeedKernelVisit (
true);
1016 updateToolbarAndMouseContextMenu();
1021void G4OpenGLQtViewer::togglePicking() {
1024 if (!fVP.IsPicking()) {
1025 fUiQt->SetIconPickSelected();
1027 fUiQt->SetIconRotateSelected();
1033 if (!fVP.IsPicking()) {
1034 UI->
ApplyCommand(std::string(
"/vis/viewer/set/picking true"));
1036 UI->
ApplyCommand(std::string(
"/vis/viewer/set/picking false"));
1047void G4OpenGLQtViewer::toggleHiddenMarkers(
bool check) {
1049 fVP.SetMarkerHidden();
1051 fVP.SetMarkerNotHidden();
1054 updateToolbarAndMouseContextMenu();
1061void G4OpenGLQtViewer::toggleFullScreen(
bool check) {
1062 if (check != fGLWidget->isFullScreen()) {
1063 fGLWidget->setWindowState(fGLWidget->windowState() ^ Qt::WindowFullScreen);
1068void G4OpenGLQtViewer::savePPMToTemp() {
1069 if (fMovieTempFolderPath ==
"") {
1072 QGLWidget* qGLW =
dynamic_cast<QGLWidget*
> (fGLWidget) ;
1076 QString fileName =
"Test"+QString::number(fRecordFrameNumber)+
".ppm";
1077 QString filePath =fMovieTempFolderPath+fileName;
1080 image = qGLW->grabFrameBuffer();
1083 res = image.save(filePath,0);
1086 setRecordingInfos(
"Can't save tmp file "+filePath);
1090 setRecordingInfos(
"File "+fileName+
" saved");
1091 fRecordFrameNumber++;
1096void G4OpenGLQtViewer::actionSaveImage() {
1098 for (
unsigned int i = 0; i < fExportImageFormatVector.size(); ++i) {
1099 filters += QString(
"*.") + fExportImageFormatVector.at(i).c_str() +
";;";
1102 QString* selectedFormat =
new QString(fDefaultExportImageFormat.c_str());
1104 qFilename = QFileDialog::getSaveFileName ( fGLWidget,
1111 std::string
name = qFilename.toStdString().c_str();
1118 fFileSavePath = QFileInfo(qFilename).path();
1120 std::string format = selectedFormat->toLower().toStdString().c_str();
1123 fExportImageFormat = format.substr(format.find_last_of(
".") + 1);
1125 std::string filename =
name;
1126 std::string extension =
"";
1127 if (
name.find_last_of(
".") != std::string::npos) {
1128 filename =
name.substr(0,
name.find_last_of(
".") + 1);
1129 extension =
name.substr(
name.find_last_of(
".") + 1);
1131 extension = fExportImageFormat;
1134 filename+=
"."+ extension;
1136 if (!setExportFilename(filename.c_str(),0)) {
1140 G4OpenGLQtExportDialog* exportDialog=
new G4OpenGLQtExportDialog(fGLWidget,format.c_str(),fGLWidget->height(),fGLWidget->width());
1141 if( exportDialog->exec()) {
1143 if ((exportDialog->getWidth() !=fGLWidget->width()) ||
1144 (exportDialog->getHeight() !=fGLWidget->height())) {
1145 setExportSize(exportDialog->getWidth(),exportDialog->getHeight());
1148 if (fExportImageFormat ==
"eps") {
1149 fVectoredPs = exportDialog->getVectorEPS();
1150 }
else if (fExportImageFormat ==
"ps") {
1153 fLastExportSliderValue = exportDialog->getSliderValue();
1155 if (exportImage(filename)) {
1157 fDefaultExportImageFormat = format;
1166void G4OpenGLQtViewer::actionChangeBackgroundColor() {
1174#if QT_VERSION < 0x040500
1176 const QColor color = QColor(QColorDialog::getRgba (QColor(Qt::black).rgba(),&a,fGLWidget));
1178 const QColor color =
1179 QColorDialog::getColor(Qt::black,
1181 " Get background color and transparency",
1182 QColorDialog::ShowAlphaChannel);
1184 if (color.isValid()) {
1189 fVP.SetBackgroundColour(colour);
1191 updateToolbarAndMouseContextMenu();
1196void G4OpenGLQtViewer::actionChangeTextColor() {
1198#if QT_VERSION < 0x040500
1200 const QColor color = QColor(QColorDialog::getRgba (QColor(Qt::yellow).rgba(),&a,fGLWidget));
1202 const QColor& color =
1203 QColorDialog::getColor(Qt::yellow,
1205 " Get text color and transparency",
1206 QColorDialog::ShowAlphaChannel);
1208 if (color.isValid()) {
1214 fVP.SetDefaultTextColour(colour);
1216 updateToolbarAndMouseContextMenu();
1221void G4OpenGLQtViewer::actionChangeDefaultColor() {
1223#if QT_VERSION < 0x040500
1225 const QColor color = QColor(QColorDialog::getRgba (QColor(Qt::white).rgba(),&a,fGLWidget));
1227 const QColor& color =
1228 QColorDialog::getColor(Qt::white,
1230 " Get default color and transparency",
1231 QColorDialog::ShowAlphaChannel);
1233 if (color.isValid()) {
1239 fVP.SetDefaultColour(colour);
1241 updateToolbarAndMouseContextMenu();
1247void G4OpenGLQtViewer::actionMovieParameters() {
1248 showMovieParametersDialog();
1252void G4OpenGLQtViewer::showMovieParametersDialog() {
1253 if (!fMovieParametersDialog) {
1254 fMovieParametersDialog=
new G4OpenGLQtMovieDialog(
this,fGLWidget);
1255 displayRecordingStatus();
1256 fMovieParametersDialog->checkEncoderSwParameters();
1257 fMovieParametersDialog->checkSaveFileNameParameters();
1258 fMovieParametersDialog->checkTempFolderParameters();
1259 if (getEncoderPath() ==
"") {
1260 setRecordingInfos(
"ppmtompeg is needed to encode in video format. It is available here: http://netpbm.sourceforge.net ");
1263 fMovieParametersDialog->show();
1268void G4OpenGLQtViewer::FinishView()
1284void G4OpenGLQtViewer::G4MousePressEvent(QMouseEvent *evnt)
1286 if (evnt->button() == Qt::RightButton) {
1289 if ((evnt->button() & Qt::LeftButton) && (! (evnt->modifiers() & Qt::ControlModifier ))){
1290 fGLWidget->setMouseTracking(
true);
1292 fLastPos1 = evnt->pos();
1293 fLastPos2 = fLastPos1;
1294 fLastPos3 = fLastPos2;
1295 fLastEventTime->start();
1296 if (fUiQt != NULL) {
1298 if (fUiQt->IsIconZoomInSelected()) {
1301 float deltaX = ((float)getWinWidth()/2-evnt->pos().x());
1302 float deltaY = ((float)getWinHeight()/2-evnt->pos().y());
1306 if (getWinHeight() <getWinWidth()) {
1309 fVP.IncrementPan(-deltaX*coefTrans,deltaY*coefTrans,0);
1310 fVP.SetZoomFactor(1.5 * fVP.GetZoomFactor());
1314 }
else if (fUiQt->IsIconZoomOutSelected()) {
1316 moveScene(((
float)getWinWidth()/2-evnt->pos().x()),((
float)getWinHeight()/2-evnt->pos().y()),0,
true);
1318 fVP.SetZoomFactor(0.75 * fVP.GetZoomFactor());
1321 }
else if (fUiQt->IsIconRotateSelected() ) {
1323 if (fShiftKeyPress) {
1324 fGLWidget->setCursor(QCursor(Qt::SizeAllCursor));
1327 fGLWidget->setCursor(QCursor(Qt::ClosedHandCursor));
1329 }
else if (fUiQt->IsIconMoveSelected()) {
1330 fGLWidget->setCursor(QCursor(Qt::SizeAllCursor));
1331 }
else if (fUiQt->IsIconPickSelected()) {
1332 fGLWidget->setCursor(QCursor(Qt::PointingHandCursor));
1340void G4OpenGLQtViewer::G4MouseReleaseEvent(QMouseEvent *evnt)
1343 glGetIntegerv(GL_VIEWPORT, viewport);
1346 double factorX = ((double)viewport[2]/fGLWidget->width());
1347 double factorY = ((double)viewport[3]/fGLWidget->height());
1348 fSpinningDelay = fLastEventTime->elapsed();
1349 QPoint delta = (fLastPos3-fLastPos1)*factorX;
1352 fGLWidget->setCursor(QCursor(Qt::ArrowCursor));
1354 if (fVP.IsPicking()){
1355 if ((delta.x() != 0) || (delta.y() != 0)) {
1358 updatePickInfosWidget(evnt->pos().x()*factorX,evnt->pos().y()*factorY);
1360 }
else if (fSpinningDelay < fLaunchSpinDelay ) {
1361 if ((delta.x() == 0) && (delta.y() == 0)) {
1366#if QT_VERSION < 0x050e00
1369 QElapsedTimer lastMoveTime;
1371 lastMoveTime.start();
1373 float correctionFactor = 5;
1375 if ( lastMoveTime.elapsed() >= (
int)(1000/fNbMaxFramesPerSec)) {
1376 float lTime = 1000/lastMoveTime.elapsed();
1377 if (((((
float)delta.x())/correctionFactor)*lTime > fNbMaxAnglePerSec) ||
1378 ((((
float)delta.x())/correctionFactor)*lTime < -fNbMaxAnglePerSec) ) {
1379 correctionFactor = (float)delta.x()*(lTime/fNbMaxAnglePerSec);
1380 if (delta.x() <0 ) {
1381 correctionFactor = -correctionFactor;
1384 if (((((
float)delta.y())/correctionFactor)*lTime > fNbMaxAnglePerSec) ||
1385 ((((
float)delta.y())/correctionFactor)*lTime < -fNbMaxAnglePerSec) ) {
1386 correctionFactor = (float)delta.y()*(lTime/fNbMaxAnglePerSec);
1387 if (delta.y() <0 ) {
1388 correctionFactor = -correctionFactor;
1399 lastMoveTime.start();
1401 bool rotate =
false;
1404 if (fUiQt != NULL) {
1405 if (fUiQt->IsIconRotateSelected()) {
1407 }
else if (fUiQt->IsIconMoveSelected()) {
1420 rotateQtScene(((
float)delta.x())/correctionFactor,((
float)delta.y())/correctionFactor);
1421 }
else if (fAltKeyPress) {
1422 rotateQtSceneToggle(((
float)delta.x())/correctionFactor,((
float)delta.y())/correctionFactor);
1426 moveScene(-((
float)delta.x())/correctionFactor,-((
float)delta.y())/correctionFactor,0,
true);
1429 ((QApplication*)G4Qt::getInstance ())->processEvents();
1432 fGLWidget->setMouseTracking(
false);
1437void G4OpenGLQtViewer::G4MouseDoubleClickEvent()
1439 fGLWidget->setMouseTracking(
true);
1450void G4OpenGLQtViewer::G4MouseMoveEvent(QMouseEvent *evnt)
1453 Qt::MouseButtons mButtons = evnt->buttons();
1455 updateKeyModifierState(evnt->modifiers());
1461 fLastPos3 = fLastPos2;
1462 fLastPos2 = fLastPos1;
1463 fLastPos1 = QPoint(evnt->x(), evnt->y());
1465 int deltaX = fLastPos2.x()-fLastPos1.x();
1466 int deltaY = fLastPos2.y()-fLastPos1.y();
1469 if (fUiQt != NULL) {
1470 if (fUiQt->IsIconMoveSelected()) {
1475 if (mButtons & Qt::LeftButton) {
1477 rotateQtScene(((
float)deltaX),((
float)deltaY));
1478 }
else if (fAltKeyPress) {
1479 rotateQtSceneToggle(((
float)deltaX),((
float)deltaY));
1480 }
else if (fShiftKeyPress) {
1481 unsigned int sizeWin;
1482 sizeWin = getWinWidth();
1483 if (getWinHeight() < getWinWidth()) {
1484 sizeWin = getWinHeight();
1488 float factor = ((float)100/(
float)sizeWin) ;
1489 moveScene(-(
float)deltaX*factor,-(
float)deltaY*factor,0,
false);
1490 }
else if (fControlKeyPress) {
1491 fVP.SetZoomFactor(fVP.GetZoomFactor()*(1+((
float)deltaY)));
1495 if (mButtons & Qt::LeftButton) {
1496 moveScene(-(
float)deltaX,-(
float)deltaY,0,
true);
1500 fLastEventTime->start();
1511void G4OpenGLQtViewer::moveScene(
float dx,
float dy,
float dz,
bool mouseMove)
1515 fHoldMoveEvent =
true;
1518 GLdouble coefDepth = 0;
1521 if (getWinHeight() <getWinWidth()) {
1525 coefTrans = getSceneNearWidth()*fPan_sens;
1526 coefDepth = getSceneDepth()*fDeltaDepth;
1528 fVP.IncrementPan(-dx*coefTrans,dy*coefTrans,dz*coefDepth);
1532 ((QApplication*)G4Qt::getInstance ())->processEvents();
1534 fHoldMoveEvent =
false;
1543void G4OpenGLQtViewer::rotateQtScene(
float dx,
float dy)
1545 if (fHoldRotateEvent)
1547 fHoldRotateEvent =
true;
1553 fHoldRotateEvent =
false;
1561void G4OpenGLQtViewer::rotateQtSceneToggle(
float dx,
float dy)
1563 if (fHoldRotateEvent)
1565 fHoldRotateEvent =
true;
1567 rotateSceneToggle(dx,dy);
1571 fHoldRotateEvent =
false;
1582void G4OpenGLQtViewer::rescaleImage(
1602void G4OpenGLQtViewer::G4wheelEvent (QWheelEvent * evnt)
1604#if QT_VERSION < 0x050F00
1606 fVP.SetZoomFactor(fVP.GetZoomFactor()+(fVP.GetZoomFactor()*(evnt->delta())/1200));
1609 fVP.SetZoomFactor(fVP.GetZoomFactor()+(fVP.GetZoomFactor()*(evnt->angleDelta().y())/1200));
1615void G4OpenGLQtViewer::G4keyPressEvent (QKeyEvent * evnt)
1620 fHoldKeyEvent =
true;
1624 updateKeyModifierState(evnt->modifiers());
1625 if ((fNoKeyPress) || (evnt->modifiers() == Qt::KeypadModifier )) {
1626 if (evnt->key() == Qt::Key_Down) {
1627 moveScene(0,1,0,
false);
1629 else if (evnt->key() == Qt::Key_Up) {
1630 moveScene(0,-1,0,
false);
1632 if (evnt->key() == Qt::Key_Left) {
1633 moveScene(-1,0,0,
false);
1635 else if (evnt->key() == Qt::Key_Right) {
1636 moveScene(1,0,0,
false);
1638 if (evnt->key() == Qt::Key_Minus) {
1639 moveScene(0,0,1,
false);
1641 else if (evnt->key() == Qt::Key_Plus) {
1642 moveScene(0,0,-1,
false);
1645 if (evnt->key() == Qt::Key_Escape) {
1646 toggleFullScreen(
false);
1655 if ((evnt->key() == Qt::Key_Return) || (evnt->key() == Qt::Key_Enter)){
1658 if (evnt->key() == Qt::Key_Space){
1663 if (evnt->key() == Qt::Key_H){
1670 if (fShiftKeyPress) {
1671 fGLWidget->setCursor(QCursor(Qt::SizeAllCursor));
1673 if (evnt->key() == Qt::Key_Down) {
1674 rotateQtScene(0,-fRot_sens);
1676 else if (evnt->key() == Qt::Key_Up) {
1677 rotateQtScene(0,fRot_sens);
1679 if (evnt->key() == Qt::Key_Left) {
1680 rotateQtScene(fRot_sens,0);
1682 else if (evnt->key() == Qt::Key_Right) {
1683 rotateQtScene(-fRot_sens,0);
1685 if (evnt->key() == Qt::Key_Plus) {
1687 moveScene(0,0,-1,
false);
1692 if ((fAltKeyPress)) {
1693 fGLWidget->setCursor(QCursor(Qt::ClosedHandCursor));
1695 if (evnt->key() == Qt::Key_Down) {
1696 rotateQtSceneToggle(0,-fRot_sens);
1698 else if (evnt->key() == Qt::Key_Up) {
1699 rotateQtSceneToggle(0,fRot_sens);
1701 if (evnt->key() == Qt::Key_Left) {
1702 rotateQtSceneToggle(fRot_sens,0);
1704 else if (evnt->key() == Qt::Key_Right) {
1705 rotateQtSceneToggle(-fRot_sens,0);
1709 if (evnt->key() == Qt::Key_Plus) {
1710 fRot_sens = fRot_sens/0.7;
1711 G4cout <<
"Auto-rotation set to : " << fRot_sens <<
G4endl;
1713 else if (evnt->key() == Qt::Key_Minus) {
1714 fRot_sens = fRot_sens*0.7;
1715 G4cout <<
"Auto-rotation set to : " << fRot_sens <<
G4endl;
1720 if ((fControlKeyPress)) {
1721 if (evnt->key() == Qt::Key_Plus) {
1722 fVP.SetZoomFactor(fVP.GetZoomFactor()*(1+fDeltaZoom));
1725 else if (evnt->key() == Qt::Key_Minus) {
1726 fVP.SetZoomFactor(fVP.GetZoomFactor()*(1-fDeltaZoom));
1731 fHoldKeyEvent =
false;
1735void G4OpenGLQtViewer::G4keyReleaseEvent (QKeyEvent *)
1737 fGLWidget->setCursor(QCursor(Qt::ArrowCursor));
1741void G4OpenGLQtViewer::updateKeyModifierState(
const Qt::KeyboardModifiers& modifier) {
1745 fAltKeyPress =
false;
1746 fShiftKeyPress =
false;
1747 fControlKeyPress =
false;
1749 if (modifier & Qt::AltModifier ) {
1750 fAltKeyPress =
true;
1751 fNoKeyPress =
false;
1753 if (modifier & Qt::ShiftModifier ) {
1754 fShiftKeyPress =
true;
1755 fNoKeyPress =
false;
1757 if (modifier & Qt::ControlModifier ) {
1758 fControlKeyPress =
true;
1759 fNoKeyPress =
false;
1766void G4OpenGLQtViewer::stopVideo() {
1769 if (!fMovieParametersDialog) {
1770 showMovieParametersDialog();
1772 setRecordingStatus(STOP);
1774 if (fRecordFrameNumber >0) {
1776 if (!(fMovieParametersDialog->checkEncoderSwParameters())) {
1777 setRecordingStatus(BAD_ENCODER);
1778 }
else if (!(fMovieParametersDialog->checkSaveFileNameParameters())) {
1779 setRecordingStatus(BAD_OUTPUT);
1783 setRecordingInfos(
"No frame to encode.");
1789void G4OpenGLQtViewer::saveVideo() {
1792 if (!fMovieParametersDialog) {
1793 showMovieParametersDialog();
1796 fMovieParametersDialog->checkEncoderSwParameters();
1797 fMovieParametersDialog->checkSaveFileNameParameters();
1799 if (fRecordingStep == STOP) {
1800 setRecordingStatus(SAVE);
1801 generateMpegEncoderParameters();
1809void G4OpenGLQtViewer::startPauseVideo() {
1813 if ( fRecordingStep == WAIT) {
1814 if ( fRecordFrameNumber == 0) {
1815 if (getTempFolderPath() ==
"") {
1816 showMovieParametersDialog();
1817 setRecordingInfos(
"You should specified the temp folder in order to make movie");
1821 QString tmp = removeTempFolder();
1823 setRecordingInfos(tmp);
1826 tmp = createTempFolder();
1828 setRecordingInfos(
"Can't create temp folder."+tmp);
1834 if (fRecordingStep == WAIT) {
1835 setRecordingStatus(
START);
1836 }
else if (fRecordingStep ==
START) {
1837 setRecordingStatus(PAUSE);
1838 }
else if (fRecordingStep == PAUSE) {
1839 setRecordingStatus(CONTINUE);
1840 }
else if (fRecordingStep == CONTINUE) {
1841 setRecordingStatus(PAUSE);
1845void G4OpenGLQtViewer::setRecordingStatus(RECORDING_STEP step) {
1847 fRecordingStep = step;
1848 displayRecordingStatus();
1852void G4OpenGLQtViewer::displayRecordingStatus() {
1854 QString txtStatus =
"";
1855 if (fRecordingStep == WAIT) {
1856 txtStatus =
"Waiting to start...";
1857 fRecordFrameNumber = 0;
1858 }
else if (fRecordingStep ==
START) {
1859 txtStatus =
"Start Recording...";
1860 }
else if (fRecordingStep == PAUSE) {
1861 txtStatus =
"Pause Recording...";
1862 }
else if (fRecordingStep == CONTINUE) {
1863 txtStatus =
"Continue Recording...";
1864 }
else if (fRecordingStep == STOP) {
1865 txtStatus =
"Stop Recording...";
1866 }
else if (fRecordingStep == READY_TO_ENCODE) {
1867 txtStatus =
"Ready to Encode...";
1868 }
else if (fRecordingStep ==
ENCODING) {
1869 txtStatus =
"Encoding...";
1870 }
else if (fRecordingStep == FAILED) {
1871 txtStatus =
"Failed to encode...";
1872 }
else if ((fRecordingStep == BAD_ENCODER)
1873 || (fRecordingStep == BAD_OUTPUT)
1874 || (fRecordingStep == BAD_TMP)) {
1875 txtStatus =
"Correct above errors first";
1876 }
else if (fRecordingStep == SUCCESS) {
1877 txtStatus =
"File encoded successfully";
1881 if (fMovieParametersDialog) {
1882 fMovieParametersDialog->setRecordingStatus(txtStatus);
1886 setRecordingInfos(
"");
1890void G4OpenGLQtViewer::setRecordingInfos(
const QString& txt) {
1891 if (fMovieParametersDialog) {
1892 fMovieParametersDialog->setRecordingInfos(txt);
1900void G4OpenGLQtViewer::initMovieParameters() {
1904 fProcess =
new QProcess();
1906 QObject ::connect(fProcess,SIGNAL(finished (
int)),
1907 this,SLOT(processLookForFinished()));
1908 fProcess->setProcessChannelMode(QProcess::MergedChannels);
1909#if QT_VERSION < 0x050F00
1911 fProcess->start (
"which ppmtompeg");
1914 fProcess->start (
"which ppmtompeg", QStringList());
1920QString G4OpenGLQtViewer::getEncoderPath() {
1921 return fEncoderPath;
1929QString G4OpenGLQtViewer::setEncoderPath(QString path) {
1931 return "ppmtompeg is needed to encode in video format. It is available here: http://netpbm.sourceforge.net ";
1934 path = QDir::cleanPath(path);
1935 QFileInfo *f =
new QFileInfo(path);
1937 return "File does not exist";
1938 }
else if (f->isDir()) {
1939 return "This is a directory";
1940 }
else if (!f->isExecutable()) {
1941 return "File exist but is not executable";
1942 }
else if (!f->isFile()) {
1943 return "This is not a file";
1945 fEncoderPath = path;
1947 if (fRecordingStep == BAD_ENCODER) {
1948 setRecordingStatus(STOP);
1954bool G4OpenGLQtViewer::isRecording(){
1955 if ((fRecordingStep ==
START) || (fRecordingStep == CONTINUE)) {
1961bool G4OpenGLQtViewer::isPaused(){
1962 if (fRecordingStep == PAUSE) {
1968bool G4OpenGLQtViewer::isEncoding(){
1975bool G4OpenGLQtViewer::isWaiting(){
1976 if (fRecordingStep == WAIT) {
1982bool G4OpenGLQtViewer::isStopped(){
1983 if (fRecordingStep == STOP) {
1989bool G4OpenGLQtViewer::isFailed(){
1990 if (fRecordingStep == FAILED) {
1996bool G4OpenGLQtViewer::isSuccess(){
1997 if (fRecordingStep == SUCCESS) {
2003bool G4OpenGLQtViewer::isBadEncoder(){
2004 if (fRecordingStep == BAD_ENCODER) {
2009bool G4OpenGLQtViewer::isBadTmp(){
2010 if (fRecordingStep == BAD_TMP) {
2015bool G4OpenGLQtViewer::isBadOutput(){
2016 if (fRecordingStep == BAD_OUTPUT) {
2022void G4OpenGLQtViewer::setBadEncoder(){
2023 fRecordingStep = BAD_ENCODER;
2024 displayRecordingStatus();
2026void G4OpenGLQtViewer::setBadTmp(){
2027 fRecordingStep = BAD_TMP;
2028 displayRecordingStatus();
2030void G4OpenGLQtViewer::setBadOutput(){
2031 fRecordingStep = BAD_OUTPUT;
2032 displayRecordingStatus();
2035void G4OpenGLQtViewer::setWaiting(){
2036 fRecordingStep = WAIT;
2037 displayRecordingStatus();
2041bool G4OpenGLQtViewer::isReadyToEncode(){
2042 if (fRecordingStep == READY_TO_ENCODE) {
2048void G4OpenGLQtViewer::resetRecording() {
2049 setRecordingStatus(WAIT);
2056QString G4OpenGLQtViewer::setTempFolderPath(QString path) {
2059 return "Path does not exist";
2061 path = QDir::cleanPath(path);
2062 QFileInfo *d =
new QFileInfo(path);
2064 return "Path does not exist";
2065 }
else if (!d->isDir()) {
2066 return "This is not a directory";
2067 }
else if (!d->isReadable()) {
2068 return path +
" is read protected";
2069 }
else if (!d->isWritable()) {
2070 return path +
" is write protected";
2073 if (fRecordingStep == BAD_TMP) {
2074 setRecordingStatus(WAIT);
2076 fTempFolderPath = path;
2082QString G4OpenGLQtViewer::getTempFolderPath() {
2083 return fTempFolderPath;
2090QString G4OpenGLQtViewer::setSaveFileName(QString path) {
2093 return "Path does not exist";
2096 QFileInfo *file =
new QFileInfo(path);
2097 QDir dir = file->dir();
2098 path = QDir::cleanPath(path);
2099 if (file->exists()) {
2100 return "File already exist, please choose a new one";
2101 }
else if (!dir.exists()) {
2102 return "Dir does not exist";
2103 }
else if (!dir.isReadable()) {
2104 return path +
" is read protected";
2107 if (fRecordingStep == BAD_OUTPUT) {
2108 setRecordingStatus(STOP);
2110 fSaveFileName = path;
2116QString G4OpenGLQtViewer::getSaveFileName() {
2117 return fSaveFileName ;
2124QString G4OpenGLQtViewer::createTempFolder() {
2125 fMovieTempFolderPath =
"";
2127 QString tmp = setTempFolderPath(fTempFolderPath);
2131 QString sep = QString(QDir::separator());
2132 QString path = sep+
"QtMovie_"+QDateTime::currentDateTime ().toString(
"dd-MM-yyyy_hh-mm-ss")+sep;
2133 QDir *d =
new QDir(QDir::cleanPath(fTempFolderPath));
2135 if (d->exists(path)) {
2136 return "Folder "+path+
" already exists.Please remove it first";
2138 if (d->mkdir(fTempFolderPath+path)) {
2139 fMovieTempFolderPath = fTempFolderPath+path;
2142 return "Can't create "+fTempFolderPath+path;
2147QString G4OpenGLQtViewer::removeTempFolder() {
2149 if (fMovieTempFolderPath ==
"") {
2152 QDir *d =
new QDir(QDir::cleanPath(fMovieTempFolderPath));
2157 d->setFilter( QDir::Files );
2158 QStringList subDirList = d->entryList();
2161 for (QStringList::ConstIterator it = subDirList.begin() ;(it != subDirList.end()) ; it++) {
2162 const QString currentFile = *it;
2163 if (!d->remove(currentFile)) {
2165 QString file = fMovieTempFolderPath+currentFile;
2166 error +=
"Removing file failed : "+file;
2171 if (d->rmdir(fMovieTempFolderPath)) {
2172 fMovieTempFolderPath =
"";
2175 return "Dir "+fMovieTempFolderPath+
" should be empty, but could not remove it";
2179 return "Could not remove "+fMovieTempFolderPath+
" because of the following errors :"+error;
2189bool G4OpenGLQtViewer::exportImage(std::string name,
int width,
int height) {
2191 QGLWidget* qGLW =
dynamic_cast<QGLWidget*
> (fGLWidget) ;
2196 bool increaseFileNumber =
true;
2198 if (
name.size() !=
name.substr(
name.find_last_of(
".") + 1).size()) {
2199 increaseFileNumber =
false;
2201 if (! setExportFilename(name,increaseFileNumber)) {
2204 if ((width !=-1) && (height != -1)) {
2205 setExportSize(width, height);
2208 if (G4OpenGLViewer::exportImage(name, width, height)) {
2214 image = qGLW->grabFrameBuffer();
2216 bool res = image.save(QString(getRealPrintFilename().c_str()),0,fLastExportSliderValue);
2219 G4cerr <<
"Error saving file... " << getRealPrintFilename().c_str() <<
G4endl;
2222 G4cout <<
"File " << getRealPrintFilename().c_str() <<
" size: " << fGLWidget->width() <<
"x" << fGLWidget->height() <<
" has been saved " <<
G4endl;
2223 fExportFilenameIndex++;
2229bool G4OpenGLQtViewer::generateMpegEncoderParameters () {
2233 fp = fopen (QString(fMovieTempFolderPath+fParameterFileName).toStdString().c_str(),
"w");
2236 setRecordingInfos(
"Generation of parameter file failed");
2240 fprintf (fp,
"# Pattern affects speed, quality and compression. See the User's Guide\n");
2241 fprintf (fp,
"# for more info.\n");
2243 fprintf (fp,
"PATTERN I\n");
2244 fprintf (fp,
"OUTPUT %s\n",getSaveFileName().toStdString().c_str());
2246 fprintf (fp,
"# You must specify the type of the input files. The choices are:\n");
2247 fprintf (fp,
"# YUV, PPM, JMOVIE, Y, JPEG, PNM\n");
2248 fprintf (fp,
"# (must be upper case)\n");
2250 fprintf (fp,
"BASE_FILE_FORMAT PPM\n");
2253 fprintf (fp,
"# If you are using YUV, there are different supported file formats.\n");
2254 fprintf (fp,
"# EYUV or UCB are the same as previous versions of this encoder.\n");
2255 fprintf (fp,
"# (All the Y's, then U's then V's, in 4:2:0 subsampling.)\n");
2256 fprintf (fp,
"# Other formats, such as Abekas, Phillips, or a general format are\n");
2257 fprintf (fp,
"# permissible, the general format is a string of Y's, U's, and V's\n");
2258 fprintf (fp,
"# to specify the file order.\n");
2260 fprintf (fp,
"INPUT_FORMAT UCB\n");
2262 fprintf (fp,
"# the conversion statement\n");
2264 fprintf (fp,
"# Each occurrence of '*' will be replaced by the input file\n");
2266 fprintf (fp,
"# e.g., if you have a bunch of GIF files, then this might be:\n");
2267 fprintf (fp,
"# INPUT_CONVERT giftoppm *\n");
2269 fprintf (fp,
"# e.g., if you have a bunch of files like a.Y a.U a.V, etc., then:\n");
2270 fprintf (fp,
"# INPUT_CONVERT cat *.Y *.U *.V\n");
2272 fprintf (fp,
"# e.g., if you are grabbing from laser disc you might have something like\n");
2273 fprintf (fp,
"# INPUT_CONVERT goto frame *; grabppm\n");
2274 fprintf (fp,
"# 'INPUT_CONVERT *' means the files are already in the base file format\n");
2276 fprintf (fp,
"INPUT_CONVERT * \n");
2278 fprintf (fp,
"# number of frames in a GOP.\n");
2280 fprintf (fp,
"# since each GOP must have at least one I-frame, the encoder will find the\n");
2281 fprintf (fp,
"# the first I-frame after GOP_SIZE frames to start the next GOP\n");
2283 fprintf (fp,
"# later, will add more flexible GOP signalling\n");
2285 fprintf (fp,
"GOP_SIZE 1\n");
2287 fprintf (fp,
"# number of slices in a frame\n");
2289 fprintf (fp,
"# 1 is a good number. another possibility is the number of macroblock rows\n");
2290 fprintf (fp,
"# (which is the height divided by 16)\n");
2292 fprintf (fp,
"SLICES_PER_FRAME 1\n");
2293 fprintf (fp,
"PIXEL HALF");
2295 fprintf (fp,
"# directory to get all input files from (makes this file easier to read)\n");
2296 fprintf (fp,
"INPUT_DIR %s\n",fMovieTempFolderPath.toStdString().c_str());
2298 fprintf (fp,
"# There are a bunch of ways to specify the input files.\n");
2299 fprintf (fp,
"# from a simple one-per-line listing, to the following \n");
2300 fprintf (fp,
"# way of numbering them. See the manual for more information.\n");
2301 fprintf (fp,
"INPUT\n");
2302 fprintf (fp,
"# '*' is replaced by the numbers 01, 02, 03, 04\n");
2303 fprintf (fp,
"# if I instead do [01-11], it would be 01, 02, ..., 09, 10, 11\n");
2304 fprintf (fp,
"# if I instead do [1-11], it would be 1, 2, 3, ..., 9, 10, 11\n");
2305 fprintf (fp,
"# if I instead do [1-11+3], it would be 1, 4, 7, 10\n");
2306 fprintf (fp,
"# the program assumes none of your input files has a name ending in ']'\n");
2307 fprintf (fp,
"# if you do, too bad!!!\n");
2310 fprintf (fp,
"Test*.ppm [0-%d]\n",fRecordFrameNumber-1);
2311 fprintf (fp,
"# can have more files here if you want...there is no limit on the number\n");
2312 fprintf (fp,
"# of files\n");
2313 fprintf (fp,
"END_INPUT\n");
2317 fprintf (fp,
"# Many of the remaining options have to do with the motion search and qscale\n");
2319 fprintf (fp,
"# FULL or HALF -- must be upper case\n");
2320 fprintf (fp,
"# Should be FULL for computer generated images\n");
2321 fprintf (fp,
"PIXEL FULL\n");
2323 fprintf (fp,
"# means +/- this many pixels for both P and B frame searches\n");
2324 fprintf (fp,
"# specify two numbers if you wish to serc different ranges in the two.\n");
2325 fprintf (fp,
"RANGE 10\n");
2327 fprintf (fp,
"# The two search algorithm parameters below mostly affect speed,\n");
2328 fprintf (fp,
"# with some affect on compression and almost none on quality.\n");
2330 fprintf (fp,
"# this must be one of {EXHAUSTIVE, SUBSAMPLE, LOGARITHMIC}\n");
2331 fprintf (fp,
"PSEARCH_ALG LOGARITHMIC\n");
2333 fprintf (fp,
"# this must be one of {SIMPLE, CROSS2, EXHAUSTIVE}\n");
2335 fprintf (fp,
"# note that EXHAUSTIVE is really, really, really slow\n");
2337 fprintf (fp,
"BSEARCH_ALG SIMPLE\n");
2340 fprintf (fp,
"# these specify the q-scale for I, P, and B frames\n");
2341 fprintf (fp,
"# (values must be between 1 and 31)\n");
2342 fprintf (fp,
"# These are the Qscale values for the entire frame in variable bit-rate\n");
2343 fprintf (fp,
"# mode, and starting points (but not important) for constant bit rate\n");
2346 fprintf (fp,
"# Qscale (Quantization scale) affects quality and compression,\n");
2347 fprintf (fp,
"# but has very little effect on speed.\n");
2349 fprintf (fp,
"IQSCALE 4\n");
2350 fprintf (fp,
"PQSCALE 5\n");
2351 fprintf (fp,
"BQSCALE 12\n");
2353 fprintf (fp,
"# this must be ORIGINAL or DECODED\n");
2354 fprintf (fp,
"REFERENCE_FRAME ORIGINAL\n");
2356 fprintf (fp,
"# for parallel parameters see parallel.param in the examples subdirectory\n");
2358 fprintf (fp,
"# if you want constant bit-rate mode, specify it as follows (number is bits/sec):\n");
2359 fprintf (fp,
"#BIT_RATE 1000000\n");
2361 fprintf (fp,
"# To specify the buffer size (327680 is default, measused in bits, for 16bit words)\n");
2362 fprintf (fp,
"BUFFER_SIZE 327680\n");
2364 fprintf (fp,
"# The frame rate is the number of frames/second (legal values:\n");
2365 fprintf (fp,
"# 23.976, 24, 25, 29.97, 30, 50 ,59.94, 60\n");
2366 fprintf (fp,
"FRAME_RATE 30\n");
2368 fprintf (fp,
"# There are many more options, see the users manual for examples....\n");
2369 fprintf (fp,
"# ASPECT_RATIO, USER_DATA, GAMMA, IQTABLE, etc.\n");
2374 setRecordingInfos(
"Parameter file "+fParameterFileName+
" generated in "+fMovieTempFolderPath);
2375 setRecordingStatus(READY_TO_ENCODE);
2379void G4OpenGLQtViewer::encodeVideo()
2381 if ((getEncoderPath() !=
"") && (getSaveFileName() !=
"")) {
2384 fProcess =
new QProcess();
2385#if QT_VERSION > 0x040100
2386 QObject ::connect(fProcess,SIGNAL(finished (
int,QProcess::ExitStatus)),
2387 this,SLOT(processEncodeFinished()));
2388 QObject ::connect(fProcess,SIGNAL(readyReadStandardOutput ()),
2389 this,SLOT(processEncodeStdout()));
2391 QObject ::connect(fProcess,SIGNAL(finished (
int)),
2392 this,SLOT(processEncodeFinished()));
2393 QObject ::connect(fProcess,SIGNAL(readyReadStandardOutput ()),
2394 this,SLOT(processEncodeStdout()));
2396#if QT_VERSION < 0x050a00
2397 fProcess->setReadChannelMode(QProcess::MergedChannels);
2399 fProcess->setProcessChannelMode(QProcess::MergedChannels);
2401 fProcess->start (fEncoderPath, QStringList(fMovieTempFolderPath+fParameterFileName));
2407void G4OpenGLQtViewer::processEncodeStdout()
2409 QString tmp = fProcess->readAllStandardOutput ().data();
2410 int start = tmp.lastIndexOf(
"ESTIMATED TIME");
2411 tmp = tmp.mid(start,tmp.indexOf(
"\n",start)-start);
2412 setRecordingInfos(tmp);
2416void G4OpenGLQtViewer::processEncodeFinished()
2420 txt = getProcessErrorMsg();
2422 setRecordingStatus(SUCCESS);
2424 setRecordingStatus(FAILED);
2430void G4OpenGLQtViewer::processLookForFinished()
2433 QString txt = getProcessErrorMsg();
2437 fEncoderPath = QString(fProcess->readAllStandardOutput ().data()).trimmed();
2439 if (fEncoderPath.contains(
" ")) {
2441 }
else if (!fEncoderPath.contains(
"ppmtompeg")) {
2444 setEncoderPath(fEncoderPath);
2447 setTempFolderPath(QDir::temp ().absolutePath ());
2451QString G4OpenGLQtViewer::getProcessErrorMsg()
2454 if (fProcess->exitCode() != 0) {
2455 switch (fProcess->error()) {
2456 case QProcess::FailedToStart:
2457 txt =
"The process failed to start. Either the invoked program is missing, or you may have insufficient permissions to invoke the program.\n";
2459 case QProcess::Crashed:
2460 txt =
"The process crashed some time after starting successfully.\n";
2462 case QProcess::Timedout:
2463 txt =
"The last waitFor...() function timed out. The state of QProcess is unchanged, and you can try calling waitFor...() again.\n";
2465 case QProcess::WriteError:
2466 txt =
"An error occurred when attempting to write to the process. For example, the process may not be running, or it may have closed its input channel.\n";
2468 case QProcess::ReadError:
2469 txt =
"An error occurred when attempting to read from the process. For example, the process may not be running.\n";
2471 case QProcess::UnknownError:
2472 txt =
"An unknown error occurred. This is the default return value of error().\n";
2482QWidget *G4OpenGLQtViewer::getParentWidget()
2485 G4Qt* interactorManager = G4Qt::getInstance ();
2490 QDialog* dialog = NULL;
2492 if (((QApplication*)interactorManager->GetMainInteractor())) {
2494 QWidgetList wl = QApplication::allWidgets();
2495 QWidget *widget = NULL;
2496 for (
int i=0; i < wl.size(); i++) {
2498 if ((found==
false) && (widget->inherits(
"QMainWindow"))) {
2499 dialog =
new QDialog(widget,Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowMinMaxButtonsHint);
2505 dialog =
new QDialog();
2508 dialog=
new QDialog();
2518void G4OpenGLQtViewer::createSceneTreeWidget() {
2519 fUISceneTreeWidget = fUiQt->GetSceneTreeWidget();
2521 if (!fUISceneTreeWidget) {
2526 QLayoutItem * wItem;
2528 if (fUISceneTreeWidget->layout()->count() ) {
2529 for(
int idx = 0; idx < fUISceneTreeWidget->layout()->count(); idx++){
2530 wItem = fUISceneTreeWidget->layout()->itemAt(idx);
2531 if (fSceneTreeWidget) {
2532 if(
dynamic_cast<QWidget *
>(wItem->widget())) {
2533 if (wItem->widget()->windowTitle() == fSceneTreeWidget->windowTitle()) {
2534 wItem->widget()->show();
2537 wItem->widget()->hide();
2541 wItem->widget()->hide();
2548 fSceneTreeWidget =
new QWidget();
2549 QVBoxLayout* layoutSceneTree =
new QVBoxLayout();
2550 fSceneTreeWidget->setStyleSheet (
"padding: 0px ");
2552 fSceneTreeWidget->setLayout(layoutSceneTree);
2553 fSceneTreeWidget->layout()->setContentsMargins(5,5,5,5);
2554 fSceneTreeWidget->setWindowTitle(QString(GetName().data()));
2556 if (fUISceneTreeWidget != NULL) {
2557 fUISceneTreeWidget->layout()->addWidget(fSceneTreeWidget);
2561 if (
dynamic_cast<G4OpenGLStoredQtViewer*
> (
this)) {
2562 createSceneTreeComponent();
2568void G4OpenGLQtViewer::createSceneTreeComponent(){
2570 QLayout* vLayout = fSceneTreeWidget->layout();
2573 QWidget* coutButtonWidget =
new QWidget();
2574 QHBoxLayout* layoutCoutTBButtons =
new QHBoxLayout();
2576 fFilterOutput =
new QLineEdit();
2577 fFilterOutput->setToolTip(
"Filter output by...");
2578 fFilterOutput->setStyleSheet (
"padding: 0px ");
2580 QPixmap* searchIcon = fUiQt->getSearchIcon();
2581#if QT_VERSION > 0x050100
2582 fFilterOutput->addAction(*searchIcon,QLineEdit::TrailingPosition);
2583 fFilterOutput->setStyleSheet (
"border-radius:7px;");
2585 QPushButton *coutTBFilterButton =
new QPushButton();
2586 coutTBFilterButton->setIcon(*searchIcon);
2587 coutTBFilterButton->setStyleSheet (
"padding-left: 0px; border:0px;");
2588 fFilterOutput->setStyleSheet (
"padding-right: 0px;");
2590 layoutCoutTBButtons->addWidget(fFilterOutput);
2592#if QT_VERSION <= 0x050100
2593 layoutCoutTBButtons->addWidget(coutTBFilterButton);
2596 coutButtonWidget->setLayout(layoutCoutTBButtons);
2597 vLayout->addWidget(coutButtonWidget);
2600 vLayout->setContentsMargins(0,0,0,0);
2603 fSceneTreeComponentTreeWidget =
new QTreeWidget();
2604 fSceneTreeComponentTreeWidget->setSelectionMode(QAbstractItemView::SingleSelection);
2605 fSceneTreeComponentTreeWidget->setHeaderLabel (
"Scene tree : "+QString(GetName().data()));
2606 fSceneTreeComponentTreeWidget->setColumnHidden (1,
true);
2607 fSceneTreeComponentTreeWidget->setColumnHidden (2,
true);
2608 fSceneTreeComponentTreeWidget->setColumnHidden (3,
true);
2613 vLayout->addWidget(fSceneTreeComponentTreeWidget);
2615 connect(fSceneTreeComponentTreeWidget,SIGNAL(itemChanged(QTreeWidgetItem*,
int)),SLOT(sceneTreeComponentItemChanged(QTreeWidgetItem*,
int)));
2616 connect(fSceneTreeComponentTreeWidget,SIGNAL(itemSelectionChanged ()),SLOT(sceneTreeComponentSelected()));
2617 connect(fSceneTreeComponentTreeWidget,SIGNAL(itemDoubleClicked ( QTreeWidgetItem*,
int)),SLOT(changeColorAndTransparency( QTreeWidgetItem*,
int)));
2621 QWidget *helpWidget =
new QWidget();
2622 QHBoxLayout *helpLayout =
new QHBoxLayout();
2624 QWidget* depthWidget =
new QWidget();
2625 QWidget *showBox =
new QWidget(depthWidget);
2626 QHBoxLayout *showBoxLayout =
new QHBoxLayout();
2629 showBoxLayout->setContentsMargins(5,5,5,5);
2631 QLabel *zero =
new QLabel();
2632 zero->setText(
"Show all");
2633 QLabel *one =
new QLabel();
2634 one->setText(
"Hide all");
2635 fSceneTreeDepthSlider =
new QSlider ( Qt::Horizontal);
2636 fSceneTreeDepthSlider->setMaximum (1000);
2637 fSceneTreeDepthSlider->setMinimum (0);
2638 fSceneTreeDepthSlider->setTickPosition(QSlider::TicksAbove);
2640 fSceneTreeDepthSlider->setMinimumWidth (40);
2642 showBoxLayout->addWidget(zero);
2643 showBoxLayout->addWidget(fSceneTreeDepthSlider);
2644 showBoxLayout->addWidget(one);
2646 showBox->setLayout(showBoxLayout);
2648 helpLayout->addWidget(showBox);
2649 helpWidget->setLayout(helpLayout);
2650 helpLayout->setContentsMargins(0,0,0,0);
2652 vLayout->addWidget(helpWidget);
2654 connect( fSceneTreeDepthSlider, SIGNAL( valueChanged(
int) ),
this, SLOT( changeDepthInSceneTree(
int) ) );
2655 connect( fFilterOutput, SIGNAL( textEdited (
const QString &) ),
this, SLOT(changeSearchSelection()));
2656 fTreeItemModels.clear();
2658 fPVRootNodeCreate =
false;
2660 fMaxPOindexInserted = -1;
2666void G4OpenGLQtViewer::createViewerPropertiesWidget() {
2669 fUIViewerPropertiesWidget = fUiQt->GetViewerPropertiesWidget();
2671 if (!fUIViewerPropertiesWidget) {
2676 QLayoutItem * wItem;
2677 if (fUIViewerPropertiesWidget->layout()->count()) {
2678 while ((wItem = fUIViewerPropertiesWidget->layout()->takeAt(0)) != 0) {
2679 delete wItem->widget();
2685 QGroupBox *groupBox =
new QGroupBox();
2686 groupBox->setTitle(GetName().data());
2687 QVBoxLayout *vbox =
new QVBoxLayout;
2690 fViewerPropertiesTableWidget =
new QTableWidget();
2692 QSizePolicy vPolicy = fViewerPropertiesTableWidget->sizePolicy();
2693 vPolicy.setVerticalStretch(4);
2695 vbox->addWidget(fViewerPropertiesTableWidget);
2696 groupBox->setLayout(vbox);
2697 fUIViewerPropertiesWidget->layout()->addWidget(groupBox);
2699 connect(fViewerPropertiesTableWidget, SIGNAL(itemChanged(QTableWidgetItem*)),
this, SLOT(tableWidgetViewerSetItemChanged(QTableWidgetItem *)));
2701 updateViewerPropertiesTableWidget();
2703 QDialog* dial =
static_cast<QDialog*
> (fUIViewerPropertiesWidget->parent());
2706 dial->setWindowTitle(QString(
"Viewer properties - ")+GetName());
2711void G4OpenGLQtViewer::createPickInfosWidget(){
2714 fUIPickInfosWidget = fUiQt->GetPickInfosWidget();
2716 if (!fUIPickInfosWidget) {
2721 QLayoutItem * wItem;
2722 if (fUIPickInfosWidget->layout()->count()) {
2723 while ((wItem = fUIPickInfosWidget->layout()->takeAt(0)) != 0) {
2724 delete wItem->widget();
2729 QGroupBox *groupBox =
new QGroupBox(
"");
2730 QVBoxLayout *vbox =
new QVBoxLayout;
2733 QWidget *pickingInfoWidget =
new QWidget();
2734 QHBoxLayout *pickingInfoLayout =
new QHBoxLayout();
2736 pickingInfoWidget->setStyleSheet (
"padding-left: 0px; border:0px;");
2737 pickingInfoWidget->setLayout(pickingInfoLayout);
2739 vbox->addWidget(pickingInfoWidget);
2742 fPickInfosScrollArea =
new QScrollArea();
2743 fPickInfosScrollArea->setWidgetResizable(
true);
2746 fPickInfosWidget =
new QWidget();
2747 fPickInfosWidget->setStyleSheet (
"padding: 0px ");
2749 QVBoxLayout* vLayout =
new QVBoxLayout();
2750 fPickInfosWidget->setLayout (vLayout);
2751 fPickInfosScrollArea->setWidget(fPickInfosWidget);
2753 QSizePolicy vPolicy = fPickInfosWidget->sizePolicy();
2754 vPolicy.setVerticalStretch(4);
2755 vbox->addWidget(fPickInfosScrollArea);
2756 pickingInfoLayout->setContentsMargins(0,0,0,0);
2757 vLayout->setContentsMargins(0,0,0,0);
2758 vbox->setContentsMargins(1,1,1,1);
2760 groupBox->setLayout(vbox);
2761 fUIPickInfosWidget->layout()->addWidget(groupBox);
2763 updatePickInfosWidget(fLastPickPoint.x(),fLastPickPoint.y());
2769void G4OpenGLQtViewer::setCheckComponent(QTreeWidgetItem* item,
bool check)
2773 const PVPath& fullPath = fTreeItemModels[item->data(0,Qt::UserRole).toInt()];
2775 if (fullPath.size() > 0) {
2776 SetTouchable(fullPath);
2777 TouchableSetVisibility(fullPath, check);
2778 fMouseOnSceneTree =
true;
2784 item->setCheckState(0,Qt::Checked);
2786 item->setCheckState(0,Qt::Unchecked);
2788 updatePositivePoIndexSceneTreeWidgetQuickMap(item->data(0,Qt::UserRole).toInt(),item);
2789 int nChildCount = item->childCount();
2790 for (
int i = 0; i < nChildCount; i++) {
2791 setCheckComponent(item->child(i),check);
2797void G4OpenGLQtViewer::DrawText(
const G4Text& g4text)
2799 QGLWidget* qGLW =
dynamic_cast<QGLWidget*
> (fGLWidget) ;
2803 if (isGl2psWriting()) {
2805 G4OpenGLViewer::DrawText(g4text);
2809 if (!fGLWidget)
return;
2811#ifdef G4MULTITHREADED
2816 G4double size = fSceneHandler.GetMarkerSize(g4text,sizeType);
2818 QFont font = QFont();
2819 font.setPointSizeF(size);
2821 const G4Colour& c = fSceneHandler.GetTextColour(g4text);
2827 const char* textCString = textString.c_str();
2832 QFontMetrics* f =
new QFontMetrics (font);
2833#if QT_VERSION > 0x050110
2834 G4double span = f->boundingRect(textCString[0]).width();
2836 G4double span = f->width(textCString);
2850 ((
position.x()+(2*xmove)/getWinWidth()),
2851 (
position.y()+(2*ymove)/getWinHeight()),
2860void G4OpenGLQtViewer::ResetView () {
2861 G4OpenGLViewer::ResetView();
2871 const QString& modelShortName = getModelShortName(model);
2873 if (modelShortName ==
"") {
2877 if (fSceneTreeComponentTreeWidget == NULL) {
2878 createSceneTreeComponent();
2882 if (fSceneTreeComponentTreeWidget == NULL) {
2886 fSceneTreeComponentTreeWidget->blockSignals(
true);
2890 if (!fPVRootNodeCreate) {
2893 fModelShortNameItem = createTreeWidgetItem(pPVModel->
GetFullPVPath(),
2901 fPVRootNodeCreate =
true;
2904 bool added = parseAndInsertInSceneTree(fModelShortNameItem,pPVModel,0,modelShortName,0,currentPOIndex);
2908 fSceneTreeComponentTreeWidget->blockSignals(
false);
2917QTreeWidgetItem* G4OpenGLQtViewer::createTreeWidgetItem(
2918 const PVPath& fullPath
2919 ,
const QString& name
2922 ,
const QString& logicalName
2923 ,Qt::CheckState state
2924 ,QTreeWidgetItem * parentTreeNode
2929 if (fullPath.size() > fSceneTreeDepth) {
2930 fSceneTreeDepth = fullPath.size();
2932 if (fSceneTreeDepthSlider) {
2933 fSceneTreeDepthSlider->setTickInterval(1000/(fSceneTreeDepth+1));
2936 QTreeWidgetItem * newItem = NULL;
2937 if (parentTreeNode == NULL) {
2938 newItem =
new QTreeWidgetItem();
2939 fSceneTreeComponentTreeWidget->addTopLevelItem(newItem);
2941 newItem =
new QTreeWidgetItem(parentTreeNode);
2942 fSceneTreeComponentTreeWidget->addTopLevelItem(parentTreeNode);
2946 newItem->setText(0,name);
2947 newItem->setData(1,Qt::UserRole,copyNb);
2948 newItem->setText(2,QString::number(POIndex));
2949 newItem->setData(0, Qt::UserRole, POIndex);
2950 newItem->setText(3,logicalName);
2951 newItem->setFlags(newItem->flags()|Qt::ItemIsUserCheckable);
2952 newItem->setCheckState(0,state);
2953 newItem->setExpanded(
true);
2954 updatePositivePoIndexSceneTreeWidgetQuickMap(POIndex,newItem);
2956 changeQColorForTreeWidgetItem(newItem,QColor((
int)(color.
GetRed()*255),
2962 if ((state == Qt::Unchecked) && (POIndex == -1)) {
2963 newItem->setForeground (0, QBrush( Qt::gray) );
2966 newItem->setToolTip (0,QString(
2967 "This node exists in the geometry but has not been\n")+
2968 "drawn, perhaps because it has been set invisible. It \n"+
2969 "cannot be made visible with a click on the button.\n"+
2970 "To see it, change the visibility, for example, with \n"+
2971 "/vis/geometry/set/visibility " + logicalName +
" 0 true\n"+
2972 "and rebuild the view with /vis/viewer/rebuild.\n"+
2973 "Click here will only show/hide all child components");
2976 newItem->setToolTip (0,QString(
"double-click to change the color"));
2982 state = Qt::Unchecked;
2983 newItem->setCheckState(0,state);
2984 updatePositivePoIndexSceneTreeWidgetQuickMap(POIndex,newItem);
2987 fTreeItemModels.insert(std::pair <int, PVPath > (POIndex,fullPath) );
2991 changeOpenCloseVisibleHiddenSelectedColorSceneTreeElement(newItem);
3008bool G4OpenGLQtViewer::parseAndInsertInSceneTree(
3009 QTreeWidgetItem * parentItem
3011 ,
unsigned int fullPathIndex
3012 ,
const QString& parentRoot
3013 ,
unsigned int currentIndexInTreeSceneHandler
3014 ,
int currentPVPOIndex
3017 if (parentItem == NULL) {
3023 std::ostringstream oss;
3024 oss << fullPath.at(fullPathIndex).GetCopyNo();
3025 std::string currentPVName =
G4String(fullPath.at(fullPathIndex).GetPhysicalVolume()->GetName()+
" ["+oss.str()+
"]").
data();
3027 int currentPVCopyNb = fullPath.at(fullPathIndex).GetCopyNo();
3037 QTreeWidgetItem* subItem = NULL;
3038 QList<QTreeWidgetItem *> parentItemList;
3046 if ((currentIndexInTreeSceneHandler == (fullPath.size()-1)) && ((color.
GetAlpha() == 1.))) {
3048 QString lookForString = QString(currentPVName.c_str());
3049 for (
int i = 0;i < parentItem->childCount(); i++ ) {
3050 if (parentItem->child(i)->text(0) == lookForString) {
3051 parentItemList.push_back(parentItem->child(i));
3056 for (
int i = 0; i < parentItemList.size(); ++i) {
3057 const std::string& parentItemName = parentItemList.at(i)->text(0).toStdString();
3058 int parentItemCopyNb = parentItemList.at(i)->data(1,Qt::UserRole).toInt();
3059 int parentItemPOIndex = parentItemList.at(i)->data(0,Qt::UserRole).toInt();
3067 if (((parentRoot == fTouchableVolumes) && (currentPVCopyNb == parentItemCopyNb)
3068 && (currentPVName == parentItemName)) ||
3070 ((parentRoot != fTouchableVolumes) && (currentPVCopyNb == parentItemCopyNb)
3072 && (currentPVName == parentItemName) && (currentPVPOIndex == parentItemPOIndex) )) {
3075 bool sameTransform =
true;
3076 if (parentItemPOIndex >= 0) {
3077 const PVPath& fullPathTmp = fTreeItemModels[parentItemPOIndex];
3078 if (fullPathTmp.size() > 0) {
3079 if (fullPathTmp.at(fullPathTmp.size()-1).GetTransform () == pPVModel->
GetTransformation ()) {
3080 sameTransform =
true;
3082 sameTransform =
false;
3088 if (sameTransform ==
true) {
3095 if (currentIndexInTreeSceneHandler == (fullPath.size()-1)) {
3097 parentItemList.at(i)->setText(2,QString::number(currentPVPOIndex));
3098 parentItemList.at(i)->setData(0, Qt::UserRole,currentPVPOIndex);
3100 fTreeItemModels.insert(std::pair <int, PVPath >(currentPVPOIndex,fullPath) );
3104 parentItemList.at(i)->setFont (0,f);
3107 parentItemList.at(i)->setForeground (0,QBrush());
3110 parentItemList.at(i)->setToolTip (0,
"");
3112 changeQColorForTreeWidgetItem(parentItemList.at(i),QColor((
int)(color.
GetRed()*255),
3119 parentItemList.at(i)->setCheckState(0,Qt::Checked);
3120 updatePositivePoIndexSceneTreeWidgetQuickMap(currentPVPOIndex,parentItemList.at(i));
3124 subItem = parentItemList.at(i);
3128 }
else if (currentIndexInTreeSceneHandler < (fullPath.size()-1)) {
3129 subItem = parentItemList.at(i);
3136 if (currentIndexInTreeSceneHandler == (fullPath.size()-1)) {
3137 createTreeWidgetItem(fullPath,
3138 QString(currentPVName.c_str()),
3141 QString(fullPath.at(fullPathIndex).GetPhysicalVolume()->GetLogicalVolume()->GetName().data()),
3146 if (currentPVPOIndex > fMaxPOindexInserted) {
3147 fMaxPOindexInserted = currentPVPOIndex;
3153 if (subItem == NULL) {
3155 if (currentIndexInTreeSceneHandler < (fullPath.size()-1)) {
3156 subItem = createTreeWidgetItem(fullPath,
3157 QString(currentPVName.c_str()),
3160 QString(fullPath.at(fullPathIndex).GetPhysicalVolume()->GetLogicalVolume()->GetName().data()),
3167 return parseAndInsertInSceneTree(subItem,pPVModel,fullPathIndex+1,parentRoot,currentIndexInTreeSceneHandler+1,currentPVPOIndex);
3173void G4OpenGLQtViewer::changeOpenCloseVisibleHiddenSelectedColorSceneTreeElement(
3174 QTreeWidgetItem* subItem
3178 QTreeWidgetItem* oldItem = NULL;
3180 QTreeWidgetItem* foundItem = getOldTreeWidgetItem(subItem->data(0,Qt::UserRole).toInt());
3182 if (foundItem != NULL) {
3183 if (isSameSceneTreeElement(foundItem,subItem)) {
3184 oldItem = foundItem;
3187 if (foundItem == NULL) {
3190 std::map <int, QTreeWidgetItem*>::const_iterator i;
3191 i = fOldPositivePoIndexSceneTreeWidgetQuickMap.begin();
3192 while (i != fOldPositivePoIndexSceneTreeWidgetQuickMap.end()) {
3193 if (isSameSceneTreeElement(i->second,subItem)) {
3194 oldItem = i->second;
3195 i = fOldPositivePoIndexSceneTreeWidgetQuickMap.end();
3201 if (oldItem == NULL) {
3203 while (a < fOldNullPoIndexSceneTreeWidgetQuickVector.size()) {
3204 if (isSameSceneTreeElement(fOldNullPoIndexSceneTreeWidgetQuickVector[a],subItem)) {
3205 oldItem = fOldNullPoIndexSceneTreeWidgetQuickVector[a];
3206 a = fOldNullPoIndexSceneTreeWidgetQuickVector.size();
3215 if (oldItem != NULL) {
3216 subItem->setFlags(oldItem->flags());
3217 subItem->setCheckState(0,oldItem->checkState(0));
3218 subItem->setSelected(oldItem->isSelected());
3219 subItem->setExpanded(oldItem->isExpanded ());
3224 std::map <int, QTreeWidgetItem* >::iterator it;
3227 int oldPOIndex = oldItem->data(0,Qt::UserRole).toInt();
3228 it = fOldPositivePoIndexSceneTreeWidgetQuickMap.find(oldPOIndex);
3232 std::map <int, QColor >::iterator itVis;
3233 itVis = fOldVisAttrColorMap.find(oldPOIndex);
3235 QColor oldVisAttrColor;
3236 const QColor& newVisAttrColor = subItem->data(2,Qt::UserRole).value<QColor>();
3238 bool visAttrChange =
false;
3240 if (itVis != fOldVisAttrColorMap.end()) {
3241 oldVisAttrColor = itVis->second;
3242 if (oldVisAttrColor != newVisAttrColor) {
3243 visAttrChange =
true;
3246 visAttrChange =
true;
3249 if (visAttrChange) {
3250 fOldVisAttrColorMap.insert(std::pair <int, QColor > (subItem->data(0,Qt::UserRole).toInt(),newVisAttrColor) );
3254 if (it != fOldPositivePoIndexSceneTreeWidgetQuickMap.end()) {
3255 color = (it->second)->data(2,Qt::UserRole).value<QColor>();
3257 color = oldItem->data(2,Qt::UserRole).value<QColor>();
3259 changeQColorForTreeWidgetItem(subItem,color);
3271bool G4OpenGLQtViewer::isSameSceneTreeElement(
3272 QTreeWidgetItem* parentOldItem
3273 ,QTreeWidgetItem* parentNewItem
3279 int newCpNumber = -1;
3280 int oldCpNumber = -1;
3282 bool firstWhile =
true;
3284 while ((parentOldItem != NULL) && (parentNewItem != NULL)) {
3288 oldPO = parentOldItem->data(0,Qt::UserRole).toInt();
3289 newPO = parentNewItem->data(0,Qt::UserRole).toInt();
3295 const PVPath& oldFullPath = fOldTreeItemModels[oldPO];
3296 const PVPath& newFullPath = fTreeItemModels[newPO];
3297 if ((oldFullPath.size() > 0) &&
3298 (newFullPath.size() > 0)) {
3299 if (oldFullPath.size() != newFullPath.size()) {
3302 if (oldFullPath.at(oldFullPath.size()-1).GetTransform () == newFullPath.at(newFullPath.size()-1).GetTransform ()) {
3303 newCpNumber = newFullPath.at(newFullPath.size()-1).GetCopyNo();
3304 oldCpNumber = oldFullPath.at(oldFullPath.size()-1).GetCopyNo();
3313 if (oldCpNumber == -1) {
3314 oldCpNumber = parentOldItem->data(1,Qt::UserRole).toInt();
3316 if (newCpNumber == -1) {
3317 newCpNumber = parentNewItem->data(1,Qt::UserRole).toInt();
3319 if ((oldCpNumber != newCpNumber) ||
3321 (parentOldItem->text(0) != parentNewItem->text(0)) ) {
3324 }
else if ((parentOldItem->text(0) != parentNewItem->text(0)) ||
3325 (parentOldItem->text(3) != parentNewItem->text(3))) {
3328 parentOldItem = parentOldItem->parent();
3329 parentNewItem = parentNewItem->parent();
3337void G4OpenGLQtViewer::addNonPVSceneTreeElement(
3340 ,
const std::string& modelDescription
3344 QString modelShortName = getModelShortName(model);
3349 const G4Text& g4Text =
dynamic_cast<const G4Text&
>(visible);
3350 color = fSceneHandler.GetTextColour(g4Text);
3352 catch (
const std::bad_cast&) {
3355 if (modelShortName ==
"") {
3359 if (fSceneTreeComponentTreeWidget == NULL) {
3360 createSceneTreeComponent();
3364 if (fSceneTreeComponentTreeWidget == NULL) {
3368 fSceneTreeComponentTreeWidget->blockSignals(
true);
3372 QList<QTreeWidgetItem *> resItem;
3373 resItem = fSceneTreeComponentTreeWidget->findItems (modelShortName, Qt::MatchExactly, 0 );
3374 QTreeWidgetItem * currentItem = NULL;
3375 const PVPath tmpFullPath;
3377 if (resItem.empty()) {
3378 currentItem = createTreeWidgetItem(tmpFullPath,
3387 currentItem = resItem.first();
3391 const QList<QTreeWidgetItem *>&
3392 resItems = fSceneTreeComponentTreeWidget->findItems (QString(modelDescription.c_str()), Qt::MatchFixedString| Qt::MatchCaseSensitive|Qt::MatchRecursive, 0 );
3394 bool alreadyPresent =
false;
3395 for (
int i = 0; i < resItems.size(); ++i) {
3396 if (currentPOIndex == resItems.at(i)->data(0,Qt::UserRole).toInt()) {
3397 alreadyPresent =
true;
3400 if (!alreadyPresent) {
3401 createTreeWidgetItem(tmpFullPath,
3402 QString(modelDescription.c_str()),
3410 fSceneTreeComponentTreeWidget->blockSignals(
false);
3418QString G4OpenGLQtViewer::getModelShortName(
const G4String& model) {
3420 QString modelShortName = model.
data();
3421 if (modelShortName.mid(0,modelShortName.indexOf(
" ")) ==
"G4PhysicalVolumeModel") {
3422 modelShortName = fTouchableVolumes;
3424 if (modelShortName.mid(0,2) ==
"G4") {
3425 modelShortName = modelShortName.mid(2);
3427 if (modelShortName.indexOf(
"Model") != -1) {
3428 modelShortName = modelShortName.mid(0,modelShortName.indexOf(
"Model"));
3431 return modelShortName;
3436bool G4OpenGLQtViewer::isTouchableVisible(
int POindex){
3439 if (fSceneTreeComponentTreeWidget == NULL) {
3445 if (fLastSceneTreeWidgetAskForIterator != fLastSceneTreeWidgetAskForIteratorEnd) {
3446 fLastSceneTreeWidgetAskForIterator++;
3448 QTreeWidgetItem* item = getTreeWidgetItem(POindex);
3451 if ( item->checkState(0) == Qt::Checked) {
3459bool G4OpenGLQtViewer::parseAndCheckVisibility(QTreeWidgetItem * treeNode,
int POindex){
3460 bool isFound =
false;
3461 for (
int i = 0; i < treeNode->childCount() ; ++i) {
3463 if (treeNode->child(i)->data(0,Qt::UserRole).toInt() == POindex) {
3464 if (treeNode->child(i)->checkState(0) == Qt::Checked) {
3468 isFound = parseAndCheckVisibility(treeNode->child(i),POindex);
3477std::string G4OpenGLQtViewer::parseSceneTreeAndSaveState(){
3478 std::string commandLine =
"";
3479 for (
int b=0;b<fSceneTreeComponentTreeWidget->topLevelItemCount();b++) {
3480 commandLine += parseSceneTreeElementAndSaveState(fSceneTreeComponentTreeWidget->topLevelItem(b),1)+
"\n";
3482 if (commandLine !=
"") {
3483 commandLine = std::string(
"# Disable auto refresh and quieten vis messages whilst scene and\n") +
3484 "# trajectories are established:\n" +
3485 "/vis/viewer/set/autoRefresh false\n" +
3486 "/vis/verbose errors" +
3488 "# Re-establish auto refreshing and verbosity:\n" +
3489 "/vis/viewer/set/autoRefresh true\n" +
3490 "/vis/verbose confirmations\n";
3496std::string G4OpenGLQtViewer::parseSceneTreeElementAndSaveState(QTreeWidgetItem* item,
unsigned int level){
3498 std::string str( level,
' ' );
3499 std::string commandLine =
"\n#"+ str +
"PV Name: " + item->text(0).toStdString();
3501 if (item->text(3) !=
"") {
3502 commandLine +=
" LV Name: "+item->text(3).toStdString()+
"\n";
3504 commandLine +=
"/vis/geometry/set/visibility " + item->text(3).toStdString() +
" ! ";
3505 if (item->checkState(0) == Qt::Checked) {
3508 if (item->checkState(0) == Qt::Unchecked) {
3514 const QColor& c = item->data(2,Qt::UserRole).value<QColor>();
3515 std::stringstream red;
3516 red << ((double)c.red())/255;
3517 std::stringstream green;
3518 green << (double)c.green()/255;
3519 std::stringstream blue;
3520 blue << ((double)c.blue())/255;
3521 std::stringstream
alpha;
3522 alpha << ((double)c.alpha())/255;
3524 commandLine +=
"/vis/geometry/set/colour " + item->text(3).toStdString() +
" ! " + red.str() +
" " + green.str() +
" " + blue.str() +
" " +
alpha.str()+
"\n";
3527 commandLine +=
"\n";
3531 for (
int b=0;b< item->childCount();b++) {
3532 commandLine += parseSceneTreeElementAndSaveState(item->child(b),level+1);
3539void G4OpenGLQtViewer::sceneTreeComponentItemChanged(QTreeWidgetItem* item,
int) {
3541 if (fCheckSceneTreeComponentSignalLock ==
false) {
3542 fCheckSceneTreeComponentSignalLock =
true;
3544 if (item->checkState(0) == Qt::Checked) {
3547 setCheckComponent(item,checked);
3550 fCheckSceneTreeComponentSignalLock =
false;
3555void G4OpenGLQtViewer::sceneTreeComponentSelected() {
3558void G4OpenGLQtViewer::changeDepthInSceneTree (
int val){
3561 if (fSceneTreeComponentTreeWidget == NULL) {
3572 double depth = 1 + ((double)val)/1000 * ((double)fSceneTreeDepth+1);
3575 fCheckSceneTreeComponentSignalLock =
true;
3578 G4bool currentAutoRefresh = fVP.IsAutoRefresh();
3579 fVP.SetAutoRefresh(
false);
3581 for (
int b=0;b<fSceneTreeComponentTreeWidget->topLevelItemCount();b++) {
3582 changeDepthOnSceneTreeItem(depth,1.,fSceneTreeComponentTreeWidget->topLevelItem(b));
3586 fVP.SetAutoRefresh(currentAutoRefresh);
3590 fCheckSceneTreeComponentSignalLock =
false;
3595void G4OpenGLQtViewer::changeColorAndTransparency(QTreeWidgetItem* item,
int) {
3600 const QColor& old = QColor(item->data(2,Qt::UserRole).value<QColor>());
3602#if QT_VERSION < 0x040500
3604 const QColor& color = QColor(QColorDialog::getRgba (old.rgba(),&a,fSceneTreeComponentTreeWidget));
3606 const QColor& color = QColorDialog::getColor(old,
3607 fSceneTreeComponentTreeWidget,
3608 " Get color and transparency",
3609 QColorDialog::ShowAlphaChannel);
3612 if (color.isValid()) {
3614 changeColorAndTransparency(item->data(0,Qt::UserRole).toInt(),
3621 changeQColorForTreeWidgetItem(item,color);
3626void G4OpenGLQtViewer::changeColorAndTransparency(GLuint index,
G4Color color) {
3630 if (iPO >= 0 && fTreeItemModels.find(iPO) != fTreeItemModels.end()) {
3631 const PVPath& fullPath = fTreeItemModels[iPO];
3633 if (fullPath.size()) {
3634 SetTouchable(fullPath);
3635 TouchableSetColour(fullPath, color);
3636 fMouseOnSceneTree =
true;
3642G4Colour G4OpenGLQtViewer::getColorForPoIndex(
int poIndex) {
3644 QTreeWidgetItem* item = getTreeWidgetItem(poIndex);
3648 const QColor& color = item->data(2,Qt::UserRole).value<QColor>();
3660const std::vector<G4ModelingParameters::VisAttributesModifier>*
3661G4OpenGLQtViewer::GetPrivateVisAttributesModifiers()
const
3663 static std::vector<G4ModelingParameters::VisAttributesModifier>
3664 privateVisAttributesModifiers;
3666 privateVisAttributesModifiers.clear();
3719 return &privateVisAttributesModifiers;
3723void G4OpenGLQtViewer::changeSearchSelection()
3725 const QString& searchText = fFilterOutput->text();
3726 if (fSceneTreeComponentTreeWidget == NULL) {
3731 for (
int a=0; a<fSceneTreeComponentTreeWidget->topLevelItemCount(); a++) {
3732 fSceneTreeComponentTreeWidget->topLevelItem(a)->setExpanded(
false);
3733 fSceneTreeComponentTreeWidget->topLevelItem(a)->setSelected(
false);
3734 clearSceneTreeSelection(fSceneTreeComponentTreeWidget->topLevelItem(a));
3737 QList<QTreeWidgetItem *> itemList = fSceneTreeComponentTreeWidget->findItems (searchText,Qt::MatchContains | Qt::MatchRecursive,0);
3739 for (
int i = 0; i < itemList.size(); ++i) {
3740 QTreeWidgetItem* expandParentItem = itemList.at(i);
3741 while (expandParentItem->parent() != NULL) {
3742 expandParentItem->parent()->setExpanded(
true);
3743 expandParentItem = expandParentItem->parent();
3745 itemList.at(i)->setSelected(
true);
3751void G4OpenGLQtViewer::clearSceneTreeSelection(QTreeWidgetItem* item) {
3752 for (
int a=0; a<item->childCount(); a++) {
3753 item->child(a)->setSelected(
false);
3754 item->child(a)->setExpanded(
false);
3755 clearSceneTreeSelection(item->child(a));
3761bool G4OpenGLQtViewer::isPVVolume(QTreeWidgetItem* item) {
3762 QTreeWidgetItem* sParent = item;
3763 while (sParent->parent() != NULL) {
3764 sParent = sParent->parent();
3766 if (sParent->text(0) != fTouchableVolumes) {
3770 if (item->text(0) == fTouchableVolumes) {
3777void G4OpenGLQtViewer::changeDepthOnSceneTreeItem(
3779 ,
double currentDepth
3780 ,QTreeWidgetItem* item
3782 double transparencyLevel = 0.;
3787 if (isPVVolume(item)) {
3788 if ((lookForDepth-currentDepth) < 0) {
3789 item->setCheckState(0,Qt::Checked);
3790 updatePositivePoIndexSceneTreeWidgetQuickMap(item->data(0,Qt::UserRole).toInt(),item);
3791 transparencyLevel = 1;
3792 }
else if ((lookForDepth-currentDepth) > 1 ){
3793 item->setCheckState(0,Qt::Unchecked);
3794 updatePositivePoIndexSceneTreeWidgetQuickMap(item->data(0,Qt::UserRole).toInt(),item);
3795 transparencyLevel = 0;
3797 item->setCheckState(0,Qt::Checked);
3798 updatePositivePoIndexSceneTreeWidgetQuickMap(item->data(0,Qt::UserRole).toInt(),item);
3799 transparencyLevel = 1-(lookForDepth-currentDepth);
3803 if (item->data(0,Qt::UserRole).toInt() >= 0) {
3804 const G4Colour& color = getColorForPoIndex(item->data(0,Qt::UserRole).toInt());
3816 if (((color.
GetAlpha()-transparencyLevel) > 0.000001) ||
3817 ((color.
GetAlpha()-transparencyLevel) < -0.000001)) {
3818 if ((item->text(3) !=
"")) {
3824 changeQColorForTreeWidgetItem(item,QColor((
int)(color.
GetRed()*255),
3827 (
int)(transparencyLevel*255)));
3832 for (
int b=0;b< item->childCount();b++) {
3833 changeDepthOnSceneTreeItem(lookForDepth,currentDepth+1,item->child(b));
3838void G4OpenGLQtViewer::clearTreeWidget(){
3841 if (fSceneTreeComponentTreeWidget) {
3843 if (fSceneTreeComponentTreeWidget->topLevelItemCount () > 0) {
3845 fPVRootNodeCreate =
false;
3848 fOldPositivePoIndexSceneTreeWidgetQuickMap.clear();
3849 fOldNullPoIndexSceneTreeWidgetQuickVector.clear();
3850 fOldTreeItemModels.clear();
3853 for (
int b =0; b <fSceneTreeComponentTreeWidget->topLevelItemCount();b++) {
3862 int poIndex = fSceneTreeComponentTreeWidget->topLevelItem(b)->data(0,Qt::UserRole).toInt();
3863 if (poIndex != -1) {
3864 fOldPositivePoIndexSceneTreeWidgetQuickMap.insert(std::pair <int, QTreeWidgetItem*> (poIndex,cloneWidgetItem(fSceneTreeComponentTreeWidget->topLevelItem(b))));
3866 fOldNullPoIndexSceneTreeWidgetQuickVector.push_back(cloneWidgetItem(fSceneTreeComponentTreeWidget->topLevelItem(b)));
3870 cloneSceneTree(fSceneTreeComponentTreeWidget->topLevelItem(b));
3874 fOldTreeItemModels.insert(fTreeItemModels.begin(), fTreeItemModels.end());
3877 int tmp2 = fSceneTreeComponentTreeWidget->topLevelItemCount();
3879 delete fSceneTreeComponentTreeWidget->takeTopLevelItem (0);
3880 tmp2 = fSceneTreeComponentTreeWidget->topLevelItemCount();
3882 fPositivePoIndexSceneTreeWidgetQuickMap.clear();
3885 fOldLastSceneTreeWidgetAskForIterator = fOldPositivePoIndexSceneTreeWidgetQuickMap.begin();
3886 fOldLastSceneTreeWidgetAskForIteratorEnd = fOldPositivePoIndexSceneTreeWidgetQuickMap.end();
3887 fSceneTreeDepth = 1;
3888 fModelShortNameItem = NULL;
3889 fMaxPOindexInserted = -1;
3902QTreeWidgetItem * G4OpenGLQtViewer::cloneWidgetItem(QTreeWidgetItem* item) {
3904 QTreeWidgetItem* cloneItem =
new QTreeWidgetItem();
3908 cloneItem->setText(0,item->text(0));
3909 cloneItem->setData(1,Qt::UserRole,item->data(1,Qt::UserRole).toInt());
3910 cloneItem->setText(2,item->text(2));
3911 cloneItem->setData(0, Qt::UserRole,item->data(0,Qt::UserRole).toInt());
3912 cloneItem->setText(3,item->text(3));
3913 cloneItem->setFlags(item->flags());
3914 cloneItem->setToolTip(0,item->toolTip(0));
3915 cloneItem->setCheckState(0,item->checkState(0));
3916 cloneItem->setSelected(item->isSelected());
3917 cloneItem->setExpanded(item->isExpanded ());
3919 cloneItem->setData(2,Qt::UserRole,item->data(2,Qt::UserRole).value<QColor>());
3928void G4OpenGLQtViewer::cloneSceneTree(
3929 QTreeWidgetItem* rootItem
3932 for (
int b=0;b< rootItem->childCount();b++) {
3934 QTreeWidgetItem *child = rootItem->child(b);
3937 int poIndex = child->data(0,Qt::UserRole).toInt();
3938 if (poIndex != -1) {
3939 fOldPositivePoIndexSceneTreeWidgetQuickMap.insert(std::pair <int, QTreeWidgetItem*> (poIndex,cloneWidgetItem(child)));
3941 fOldNullPoIndexSceneTreeWidgetQuickVector.push_back(cloneWidgetItem(child));
3943 cloneSceneTree(child);
3951 void G4OpenGLQtViewer::updatePositivePoIndexSceneTreeWidgetQuickMap(
int POindex,QTreeWidgetItem* item) {
3954 std::map <int, QTreeWidgetItem*>::iterator i;
3955 i = fPositivePoIndexSceneTreeWidgetQuickMap.find(POindex);
3957 if (i == fPositivePoIndexSceneTreeWidgetQuickMap.end()) {
3958 fPositivePoIndexSceneTreeWidgetQuickMap.insert(std::pair <int, QTreeWidgetItem*> (POindex,item) );
3959 fLastSceneTreeWidgetAskForIterator = fPositivePoIndexSceneTreeWidgetQuickMap.end();
3960 fLastSceneTreeWidgetAskForIteratorEnd = fPositivePoIndexSceneTreeWidgetQuickMap.end();
3968void G4OpenGLQtViewer::changeQColorForTreeWidgetItem(QTreeWidgetItem* item,
const QColor& qc) {
3970 int POIndex = item->data(0,Qt::UserRole).toInt();
3971 updatePositivePoIndexSceneTreeWidgetQuickMap(POIndex,item );
3973 QPixmap pixmap = QPixmap(QSize(16, 16));
3974 if (item->data(0,Qt::UserRole).toInt() != -1) {
3977 pixmap.fill (QColor(255,255,255,255));
3979 QPainter painter(&pixmap);
3980 painter.setPen(Qt::black);
3981 painter.drawRect(0,0,15,15);
3983 item->setIcon(0,pixmap);
3984 item->setData(2,Qt::UserRole,qc);
3993QTreeWidgetItem* G4OpenGLQtViewer::getTreeWidgetItem(
int POindex){
3996 if (POindex == -1) {
4000 if (fPositivePoIndexSceneTreeWidgetQuickMap.size() == 0){
4004 if (fLastSceneTreeWidgetAskForIterator != fLastSceneTreeWidgetAskForIteratorEnd) {
4005 if (POindex == fLastSceneTreeWidgetAskForIterator->first) {
4006 if (fLastSceneTreeWidgetAskForIterator->second != NULL) {
4007 return fLastSceneTreeWidgetAskForIterator->second;
4013 fLastSceneTreeWidgetAskForIterator = fPositivePoIndexSceneTreeWidgetQuickMap.find(POindex);
4014 fLastSceneTreeWidgetAskForIteratorEnd = fPositivePoIndexSceneTreeWidgetQuickMap.end();
4016 if (fLastSceneTreeWidgetAskForIterator != fPositivePoIndexSceneTreeWidgetQuickMap.end()) {
4017 return fLastSceneTreeWidgetAskForIterator->second;
4026QTreeWidgetItem* G4OpenGLQtViewer::getOldTreeWidgetItem(
int POindex){
4030 if (POindex == -1) {
4034 if (fOldPositivePoIndexSceneTreeWidgetQuickMap.size() == 0){
4040 if (fOldLastSceneTreeWidgetAskForIterator != fOldLastSceneTreeWidgetAskForIteratorEnd) {
4041 fOldLastSceneTreeWidgetAskForIterator++;
4044 if (fOldLastSceneTreeWidgetAskForIterator != fOldPositivePoIndexSceneTreeWidgetQuickMap.end()) {
4045 if (POindex == fOldLastSceneTreeWidgetAskForIterator->first) {
4046 if (fOldLastSceneTreeWidgetAskForIterator->second != NULL) {
4047 return fOldLastSceneTreeWidgetAskForIterator->second;
4053 fOldLastSceneTreeWidgetAskForIterator = fOldPositivePoIndexSceneTreeWidgetQuickMap.find(POindex);
4054 fOldLastSceneTreeWidgetAskForIteratorEnd = fOldPositivePoIndexSceneTreeWidgetQuickMap.end();
4056 if (fOldLastSceneTreeWidgetAskForIterator != fOldPositivePoIndexSceneTreeWidgetQuickMap.end()) {
4057 return fOldLastSceneTreeWidgetAskForIterator->second;
4068void G4OpenGLQtViewer::displaySceneTreeComponent() {
4070 if (fUISceneTreeWidget == NULL) {
4073 if (fSceneTreeComponentTreeWidget == NULL) {
4078 fSceneTreeComponentTreeWidget->sortItems (0, Qt::AscendingOrder );
4090void G4OpenGLQtViewer::updateToolbarAndMouseContextMenu(){
4096 d_style = fVP.GetDrawingStyle();
4100 if (fUiQt) fUiQt->SetIconWireframeSelected();
4102 fDrawingWireframe->setChecked(
true);
4103 fDrawingLineRemoval->setChecked(
false);
4104 fDrawingSurfaceRemoval->setChecked(
false);
4105 fDrawingLineSurfaceRemoval->setChecked(
false);
4108 if (fUiQt) fUiQt->SetIconHLRSelected();
4110 fDrawingLineRemoval->setChecked(
true);
4111 fDrawingWireframe->setChecked(
false);
4112 fDrawingSurfaceRemoval->setChecked(
false);
4113 fDrawingLineSurfaceRemoval->setChecked(
false);
4116 if (fUiQt) fUiQt->SetIconSolidSelected();
4118 fDrawingSurfaceRemoval->setChecked(
true);
4119 fDrawingWireframe->setChecked(
false);
4120 fDrawingLineRemoval->setChecked(
false);
4121 fDrawingLineSurfaceRemoval->setChecked(
false);
4124 if (fUiQt) fUiQt->SetIconHLHSRSelected();
4126 fDrawingLineSurfaceRemoval->setChecked(
true);
4127 fDrawingWireframe->setChecked(
false);
4128 fDrawingLineRemoval->setChecked(
false);
4129 fDrawingSurfaceRemoval->setChecked(
false);
4130 fDrawingLineSurfaceRemoval->setChecked(
false);
4136 G4double d_proj = fVP.GetFieldHalfAngle () ;
4138 if (fUiQt) fUiQt->SetIconOrthoSelected();
4140 fProjectionOrtho->setChecked(
true);
4141 fProjectionPerspective->setChecked(
false);
4144 if (fUiQt) fUiQt->SetIconPerspectiveSelected();
4146 fProjectionPerspective->setChecked(
true);
4147 fProjectionOrtho->setChecked(
false);
4153 if (fUiQt && fContextMenu) {
4154 if (fUiQt->IsIconPickSelected()) {
4155 fMousePickAction->setChecked(
true);
4156 fMouseZoomOutAction->setChecked(
false);
4157 fMouseZoomInAction->setChecked(
false);
4158 fMouseRotateAction->setChecked(
false);
4159 fMouseMoveAction->setChecked(
false);
4160 }
else if (fUiQt->IsIconZoomOutSelected()) {
4161 fMouseZoomOutAction->setChecked(
true);
4162 fMousePickAction->setChecked(
false);
4163 fMouseZoomInAction->setChecked(
false);
4164 fMouseRotateAction->setChecked(
false);
4165 fMouseMoveAction->setChecked(
false);
4166 }
else if (fUiQt->IsIconZoomInSelected()) {
4167 fMouseZoomInAction->setChecked(
true);
4168 fMousePickAction->setChecked(
false);
4169 fMouseZoomOutAction->setChecked(
false);
4170 fMouseRotateAction->setChecked(
false);
4171 fMouseMoveAction->setChecked(
false);
4172 }
else if (fUiQt->IsIconRotateSelected()) {
4173 fMouseRotateAction->setChecked(
true);
4174 fMousePickAction->setChecked(
false);
4175 fMouseZoomOutAction->setChecked(
false);
4176 fMouseZoomInAction->setChecked(
false);
4177 fMouseMoveAction->setChecked(
false);
4178 }
else if (fUiQt->IsIconMoveSelected()) {
4179 fMouseMoveAction->setChecked(
true);
4180 fMousePickAction->setChecked(
false);
4181 fMouseZoomOutAction->setChecked(
false);
4182 fMouseZoomInAction->setChecked(
false);
4183 fMouseRotateAction->setChecked(
false);
4191void G4OpenGLQtViewer::updateSceneTreeWidget() {
4193 if (!fSceneTreeWidget) {
4194 createSceneTreeWidget();
4203void G4OpenGLQtViewer::updateViewerPropertiesTableWidget() {
4205 if (!isCurrentWidget()) {
4210 if (!fViewerPropertiesTableWidget) {
4211 createViewerPropertiesWidget();
4213 int treeWidgetInfosIgnoredCommands = 0;
4223 if ((path->
GetCommandEntry()-fTreeWidgetInfosIgnoredCommands) != fViewerPropertiesTableWidget->rowCount()) {
4224 fViewerPropertiesTableWidget->clear();
4227 fViewerPropertiesTableWidget->blockSignals(
true);
4230 fViewerPropertiesTableWidget->setColumnCount (2);
4231 fViewerPropertiesTableWidget->setRowCount (path->
GetCommandEntry()-fTreeWidgetInfosIgnoredCommands);
4232 fViewerPropertiesTableWidget->setHorizontalHeaderLabels(QStringList() << tr(
"Property")
4234 fViewerPropertiesTableWidget->verticalHeader()->setVisible(
false);
4235 fViewerPropertiesTableWidget->setAlternatingRowColors (
true);
4243 QString params =
"";
4246 if (fVP.IsAutoRefresh()) {
4252 if (fVP.IsAuxEdgeVisible()) {
4258 params = QString().number(fVP.GetBackgroundColour().GetRed()) +
" "+
4259 QString().number(fVP.GetBackgroundColour().GetGreen()) +
" "+
4260 QString().number(fVP.GetBackgroundColour().GetBlue()) +
" "+
4261 QString().number(fVP.GetBackgroundColour().GetAlpha());
4264 params = QString().number(fVP. IsCulling ());
4269 params =
"intersection";
4273 params = QString().number(fVP.GetDefaultVisAttributes()->GetColor().GetRed()) +
" "+
4274 QString().number(fVP.GetDefaultVisAttributes()->GetColor().GetGreen()) +
" "+
4275 QString().number(fVP.GetDefaultVisAttributes()->GetColor().GetBlue()) +
" "+
4276 QString().number(fVP.GetDefaultVisAttributes()->GetColor().GetAlpha());
4279 params = QString().number(fVP.GetDefaultTextVisAttributes()->GetColor().GetRed()) +
" "+
4280 QString().number(fVP.GetDefaultTextVisAttributes()->GetColor().GetGreen()) +
" "+
4281 QString().number(fVP.GetDefaultTextVisAttributes()->GetColor().GetBlue()) +
" "+
4282 QString().number(fVP.GetDefaultTextVisAttributes()->GetColor().GetAlpha());
4292 params = QString().number(fVP.GetExplodeFactor()) +
" " + QString(
G4String(
G4BestUnit(fVP.GetExplodeFactor(),
"Length")).
data());
4294 }
else if(commandTmp->
GetCommandName() ==
"globalLineWidthScale") {
4295 params = QString().number(fVP.GetGlobalLineWidthScale());
4298 params = QString().number(fVP.GetGlobalMarkerScale());
4310 if (fVP.IsMarkerNotHidden()) {
4317 if (fVP.GetLightsMoveWithCamera()) {
4323 G4Vector3D direction = fVP.GetLightpointDirection();
4325 params = QString().number(direction.
theta()/CLHEP::degree)+
" "+ QString().number(direction.
phi()/CLHEP::degree)+
" deg";
4332 params = QString().number(fVP.GetLightpointDirection().x()) +
" "+
4333 QString().number(fVP.GetLightpointDirection().y()) +
" "+
4334 QString().number(fVP.GetLightpointDirection().z());
4336 }
else if(commandTmp->
GetCommandName() ==
"lineSegmentsPerCircle") {
4337 params = QString().number(fVP.GetNoOfSides());
4340 if (fVP.IsPicking()) {
4347 if (fVP.GetFieldHalfAngle() == 0.) {
4348 params =
"orthogonal";
4350 params = QString(
"perspective ") + QString().number(fVP.GetFieldHalfAngle()/CLHEP::degree) +
" deg";
4355 params =
"constrainUpDirection";
4357 params =
"freeRotation";
4361 if (fVP.IsSection()) {
4362 params = QString(
"on ") +
4364 QString().number(fVP.GetSectionPlane().normal().x())
4365 +
" " + QString().number(fVP.GetSectionPlane().normal().y())
4366 +
" " + QString().number(fVP.GetSectionPlane().normal().z());
4373 params =
"wireframe";
4380 G4Point3D point = fVP.GetCurrentTargetPoint();
4381 if (fSceneHandler.GetScene()) {
4382 G4String b =
G4BestUnit(fSceneHandler.GetScene()->GetStandardTargetPoint() + fVP.GetCurrentTargetPoint(),
"Length");
4388 params = QString().number(up.
theta()/CLHEP::degree)+
" "+ QString().number(up.
phi()/CLHEP::degree)+
" deg";
4396 params = QString().number(up.
x())+
" "+ QString().number(up.
y())+
" "+QString().number(up.
z())+
" ";
4399 G4Vector3D direction = fVP.GetViewpointDirection();
4401 params = QString().number(direction.
theta()/CLHEP::degree)+
" "+ QString().number(direction.
phi()/CLHEP::degree)+
" deg";
4408 G4Vector3D direction = fVP.GetViewpointDirection();
4409 params = QString().number(direction.
x())+
" "+ QString().number(direction.
y())+
" "+QString().number(direction.
z());
4439 QTableWidgetItem *nameItem;
4440 QTableWidgetItem *paramItem;
4443 QList<QTableWidgetItem *> list = fViewerPropertiesTableWidget->findItems (commandTmp->
GetCommandName().
data(),Qt::MatchExactly);
4444 if (list.size() == 1) {
4445 nameItem = list.first();
4446 paramItem = fViewerPropertiesTableWidget->item(nameItem->row(),1);
4449 nameItem =
new QTableWidgetItem();
4450 paramItem =
new QTableWidgetItem();
4451 fViewerPropertiesTableWidget->setItem(a-treeWidgetInfosIgnoredCommands, 0, nameItem);
4452 fViewerPropertiesTableWidget->setItem(a-treeWidgetInfosIgnoredCommands, 1, paramItem);
4457 for(
G4int i_thGuidance=0; i_thGuidance < n_guidanceEntry; i_thGuidance++ ) {
4458 guidance += QString((
char*)(commandTmp->
GetGuidanceLine(i_thGuidance)).data()) +
"\n";
4461 nameItem->setToolTip(guidance);
4462 paramItem->setToolTip(GetCommandParameterList(commandTmp));
4464 fViewerPropertiesTableWidget->setRowHeight(a-treeWidgetInfosIgnoredCommands,15);
4469 paramItem->setText(params);
4471 nameItem->setFlags(Qt::NoItemFlags);
4472 nameItem->setForeground(QBrush());
4475 treeWidgetInfosIgnoredCommands++;
4479 for (
int i=0; i<treeWidgetInfosIgnoredCommands; i++) {
4480 fViewerPropertiesTableWidget->removeRow (fViewerPropertiesTableWidget->rowCount() - 1);
4484 if (!fViewerPropertiesTableWidgetIsInit) {
4485 fViewerPropertiesTableWidgetIsInit =
true;
4487 fViewerPropertiesTableWidget->resizeColumnsToContents();
4489 int x = fViewerPropertiesTableWidget->horizontalHeader()->length();
4490 int y = fViewerPropertiesTableWidget->verticalHeader()->length()+ fViewerPropertiesTableWidget->horizontalHeader()->sizeHint().height() + 2;
4496 QDialog* dial =
static_cast<QDialog*
> (fUIViewerPropertiesWidget->parent());
4498 dial->resize(x+56,y+46);
4501 fViewerPropertiesTableWidget->blockSignals(
false);
4503 fTreeWidgetInfosIgnoredCommands = treeWidgetInfosIgnoredCommands;
4510void G4OpenGLQtViewer::updatePickInfosWidget(
int aX,
int aY) {
4511 fLastPickPoint = QPoint(aX,aY);
4513 if (!isCurrentWidget()) {
4517 if (!fPickInfosWidget) {
4518 createPickInfosWidget();
4521 const std::vector < G4OpenGLViewerPickMap* > & pickMapVector = GetPickDetails(aX,aY);
4524 if (fPickInfosWidget) {
4525 QLayoutItem * wItem;
4526 if (fPickInfosWidget->layout()->count()) {
4527 while ((wItem = fPickInfosWidget->layout()->takeAt(0)) != 0) {
4528 delete wItem->widget();
4534 if (!fPickInfosWidget) {
4535 createPickInfosWidget();
4540#if QT_VERSION < 0x050600
4541 delete fSignalMapperPicking;
4542 fSignalMapperPicking =
new QSignalMapper(
this);
4546 G4int nPickedObjectsWithAttributes = 0;
4547 for (
unsigned int a=0; a< pickMapVector.size(); a++) {
4548 const auto& pickMap = pickMapVector[a];
4550 std::ostringstream label;
4551 std::ostringstream content;
4552 std::string txt = pickMap->getAttributes()[0].data();
4553 if (pickMapVector[a]->getAttributes().size()) {
4554 ++nPickedObjectsWithAttributes;
4556 std::size_t pos1 = txt.find(
':');
4557 std::string storeKey = txt.substr(0,pos1);
4559 if (storeKey ==
"G4PhysicalVolumeModel") {
4562 std::size_t pos2 = txt.find(
':',pos1+1);
4563 std::size_t pos3 = txt.find(
'\n',pos2+1);
4564 label << txt.substr(pos2+1,pos3-pos2-1);
4566 }
else if (storeKey ==
"G4TrajectoriesModel") {
4568 label <<
"Trajectory:";
4569 std::size_t pos2 = txt.find(
':',pos1+1);
4570 std::size_t pos3 = txt.find(
'\n',pos2+1);
4571 label <<
" Run:" << txt.substr(pos2+1,pos3-pos2-1);
4572 std::size_t pos4 = txt.find(
':',pos3+1);
4573 std::size_t pos5 = txt.find(
'\n',pos4+1);
4574 label <<
", Event:" << txt.substr(pos4+1,pos5-pos4-1);
4578 label <<
"Hit number:" << a <<
", PickName: " << pickMap->getPickName();
4583 content << pickMap->print().data();
4584 G4int thisPickName = pickMap->getPickName();
4585 while (++a < pickMapVector.size()) {
4586 const auto& a_pickMap = pickMapVector[a];
4587 if (a_pickMap->getPickName() == thisPickName) {
4588 content << a_pickMap->print().data();
4595 QPushButton* pickCoutButton =
new QPushButton(label.str().c_str());
4596 pickCoutButton->setStyleSheet (
"text-align: left; padding: 1px; border: 0px;");
4597 pickCoutButton->setIcon(*fTreeIconClosed);
4598 fPickInfosWidget->layout()->addWidget(pickCoutButton);
4603 newStr = QStringList(QString(content.str().c_str()).trimmed());
4605 QTextEdit* ed =
new QTextEdit();
4606 ed->setReadOnly(
true);
4607 fPickInfosWidget->layout()->addWidget(ed);
4608 ed->setVisible((
false));
4609 ed->append(newStr.join(
""));
4611#if QT_VERSION < 0x050600
4612 connect(pickCoutButton, SIGNAL(clicked()), fSignalMapperPicking, SLOT(map()));
4613 fSignalMapperPicking->setMapping(pickCoutButton,fPickInfosWidget->layout()->count()-1);
4615 std::cout << pickCoutButton->text().toStdString() <<
" "<< fPickInfosWidget->layout()->count()-1<< std::endl;
4616 int tmp = fPickInfosWidget->layout()->count()-1;
4617 connect(pickCoutButton, &QPushButton::clicked , [=](){ this->toggleSceneTreeComponentPickingCout(tmp);});
4621#if QT_VERSION < 0x050600
4622 connect(fSignalMapperPicking, SIGNAL(mapped(
int)),
this, SLOT(toggleSceneTreeComponentPickingCout(
int)));
4626 QLabel * pushUp =
new QLabel(
"");
4627 QSizePolicy vPolicy = QSizePolicy(QSizePolicy::Minimum,QSizePolicy::Minimum);
4628 vPolicy.setVerticalStretch(10);
4629 pushUp->setSizePolicy(vPolicy);
4630 fPickInfosWidget->layout()->addWidget(pushUp);
4635 changeColorAndTransparency(fLastHighlightName,fLastHighlightColor);
4637 if (pickMapVector.size() > 0 ) {
4639 fLastHighlightName = pickMapVector[0]->getPickName();
4640 fLastHighlightColor = getColorForPoIndex(fLastHighlightName);
4642 changeColorAndTransparency(fLastHighlightName,
G4Color(1,1,1,1));
4646 QDialog* dial =
static_cast<QDialog*
> (fUIPickInfosWidget->parent());
4649 std::ostringstream oss;
4650 if (nPickedObjectsWithAttributes == 0) {
4652 }
else if (nPickedObjectsWithAttributes == 1) {
4655 oss << nPickedObjectsWithAttributes <<
" objects";
4657 oss <<
" selected - " << GetName();
4658 dial->setWindowTitle(oss.str().c_str());
4661 fPickInfosScrollArea->setVisible(
true);
4665void G4OpenGLQtViewer::toggleSceneTreeComponentPickingCout(
int pickItem) {
4670 for (
int a=0; a<fPickInfosWidget->layout()->count(); a++) {
4671 w = fPickInfosWidget->layout()->itemAt(a)->widget();
4672 QTextEdit* ed =
dynamic_cast<QTextEdit*
>(w);
4673 QPushButton* button;
4675 if (a == pickItem) {
4676 w->setVisible(!w->isVisible());
4678 w->setVisible(
false);
4681 button =
dynamic_cast<QPushButton*
>(fPickInfosWidget->layout()->itemAt(a-1)->widget());
4683 if (button->isVisible()) {
4684 button->setIcon(*fTreeIconOpen);
4686 button->setIcon(*fTreeIconClosed);
4695void G4OpenGLQtViewer::currentTabActivated(
int currentTab) {
4696 if (fUiQt->GetViewerTabWidget()->tabText(currentTab) == GetName()) {
4697 createViewerPropertiesWidget();
4698 createPickInfosWidget();
4699 createSceneTreeWidget();
4704void G4OpenGLQtViewer::tableWidgetViewerSetItemChanged(QTableWidgetItem * item) {
4707 QTableWidgetItem* previous = fViewerPropertiesTableWidget->item(fViewerPropertiesTableWidget->row(item),0);
4709 fViewerPropertiesTableWidget->blockSignals(
true);
4711 + previous->text().toStdString()
4713 + item->text().toStdString()).c_str());
4714 fViewerPropertiesTableWidget->blockSignals(
false);
4719bool G4OpenGLQtViewer::isCurrentWidget(){
4720 G4Qt* interactorManager = G4Qt::getInstance ();
4721 if (!interactorManager->IsExternalApp()) {
4724 if ( GetName() != fUiQt->GetViewerTabWidget()->tabText(fUiQt->GetViewerTabWidget()->currentIndex()).toStdString().c_str()) {
4738QString G4OpenGLQtViewer::GetCommandParameterList (
4745 if( n_parameterEntry > 0 ) {
4750 for(
G4int i_thParameter=0; i_thParameter<n_parameterEntry; i_thParameter++ ) {
4752 txt +=
"\nParameter : " + QString((
char*)(param->
GetParameterName()).data()) +
"\n";
4755 txt +=
" Parameter type : " + QString(QChar(param->
GetParameterType())) +
"\n";
4757 txt +=
" Omittable : True\n";
4759 txt +=
" Omittable : False\n";
4762 txt +=
" Default value : taken from the current value\n";
4764 txt +=
" Default value : " + QString((
char*)(param->
GetDefaultValue()).data())+
"\n";
4767 txt +=
" Parameter range : " + QString((
char*)(param->
GetParameterRange()).data())+
"\n";
4777#ifdef G4MULTITHREADED
4779void G4OpenGLQtViewer::DoneWithMasterThread()
4785 if(!lWaitForVisSubThreadQtOpenGLContextInitialized->owns_lock())
4786 lWaitForVisSubThreadQtOpenGLContextInitialized->lock();
4789void G4OpenGLQtViewer::SwitchToVisSubThread()
4793 QGLWidget* qGLW =
dynamic_cast<QGLWidget*
> (fGLWidget) ;
4799 SetQGLContextVisSubThread(QThread::currentThread());
4805 if(!lWaitForVisSubThreadQtOpenGLContextMoved->owns_lock())
4806 lWaitForVisSubThreadQtOpenGLContextMoved->lock();
4810 lWaitForVisSubThreadQtOpenGLContextMoved);
4813 qGLW->makeCurrent();
4816void G4OpenGLQtViewer::DoneWithVisSubThread()
4819 QGLWidget* qGLW =
dynamic_cast<QGLWidget*
> (fGLWidget) ;
4825 qGLW->doneCurrent();
4827#if QT_VERSION > 0x050000
4829 qGLW->context()->moveToThread(fQGLContextMainThread);
4833void G4OpenGLQtViewer::SwitchToMasterThread()
4837 QGLWidget* qGLW =
dynamic_cast<QGLWidget*
> (fGLWidget) ;
4844 if(lWaitForVisSubThreadQtOpenGLContextInitialized->owns_lock())
4845 lWaitForVisSubThreadQtOpenGLContextInitialized->unlock();
4847 qGLW->makeCurrent();
4851void G4OpenGLQtViewer::MovingToVisSubThread(){
4854 QGLWidget* qGLW =
dynamic_cast<QGLWidget*
> (fGLWidget) ;
4861 if(!lWaitForVisSubThreadQtOpenGLContextInitialized->owns_lock())
4862 lWaitForVisSubThreadQtOpenGLContextInitialized->lock();
4866 lWaitForVisSubThreadQtOpenGLContextInitialized);
4869 SetQGLContextMainThread(QThread::currentThread());
4872 qGLW->doneCurrent();
4873#if QT_VERSION > 0x050000
4874 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
static G4bool GetColour(const G4String &key, G4Colour &result)
G4double GetAlpha() const
G4double GetGreen() const
const std::vector< G4PhysicalVolumeNodeID > & GetFullPVPath() const
const char * data() const
G4double GetYOffset() const
G4double GetXOffset() const
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
G4Point3D GetPosition() const
const G4Transform3D & GetTransformation() const
const char * name(G4int ptype)
std::vector< PVNodeID > PVPath