35 #ifdef G4VIS_BUILD_OPENGLQT_DRIVER
63 #include <qpushbutton.h>
65 #include <qdesktopwidget.h>
68 #include <qimagewriter.h>
70 #include <qtextedit.h>
71 #include <qtreewidget.h>
72 #include <qapplication.h>
73 #include <qmessagebox.h>
74 #include <qfiledialog.h>
76 #include <qdatetime.h>
80 #include <qcolordialog.h>
83 #include <qgroupbox.h>
84 #include <qcombobox.h>
85 #include <qlineedit.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>
95 #include <qsplitter.h>
96 #include <qcheckbox.h>
105 #ifdef G4MULTITHREADED
112 void G4OpenGLQtViewer::CreateMainWindow (
120 if(fGLWidget)
return;
122 fGLWidget = glWidget ;
125 G4Qt* interactorManager = G4Qt::getInstance ();
127 ResizeWindow(fVP.GetWindowSizeHintX(),fVP.GetWindowSizeHintY());
139 if (UI == NULL)
return;
141 if (! static_cast<G4UIQt*> (UI->GetG4UIWindow())) {
146 fUiQt =
static_cast<G4UIQt*
> (UI->GetG4UIWindow());
148 bool isTabbedView =
false;
151 if (!interactorManager->IsExternalApp()) {
153 fWinSize_x = fVP.GetWindowSizeHintX();
154 fWinSize_y = fVP.GetWindowSizeHintY();
156 isTabbedView = fUiQt->AddTabWidget((QWidget*)fGLWidget,name);
158 SIGNAL(currentChanged(
int)),
160 SLOT(currentTabActivated(
int)));
164 createSceneTreeWidget();
171 QWidget *glDialogWidget = getParentWidget();
172 if (glDialogWidget == NULL) {
175 glWidget->setParent(glDialogWidget);
176 QHBoxLayout *mainLayout =
new QHBoxLayout();
178 mainLayout->setMargin(0);
179 mainLayout->setSpacing(0);
180 mainLayout->addWidget(fGLWidget);
181 if (fGLWidget->inherits(
"QMainWindow")) {
182 fGLWidget->setWindowTitle( name);
184 glDialogWidget->setLayout(mainLayout);
188 #if QT_VERSION >= 0x050a00
190 - QGuiApplication::screenAt(QPoint(20,20))->availableGeometry().height();
192 G4int offset = QApplication::desktop()->height()
193 - QApplication::desktop()->availableGeometry().height();
196 G4int YPos= fVP.GetWindowAbsoluteLocationHintY(QApplication::desktop()->height());
197 if (fVP.GetWindowAbsoluteLocationHintY(QApplication::desktop()->height())< offset) {
200 glDialogWidget->resize(getWinWidth(), getWinHeight());
201 glDialogWidget->move(fVP.GetWindowAbsoluteLocationHintX(QApplication::desktop()->width()),YPos);
202 glDialogWidget->show();
205 if(!fGLWidget)
return;
214 G4OpenGLQtViewer::G4OpenGLQtViewer (
215 G4OpenGLSceneHandler& scene
218 ,G4OpenGLViewer (scene)
220 ,fRecordFrameNumber(0)
221 ,fMouseOnSceneTree(
false)
223 ,fLastPickPoint(-1,-1)
226 ,fHoldKeyEvent(
false)
227 ,fHoldMoveEvent(
false)
228 ,fHoldRotateEvent(
false)
232 ,fMovieTempFolderPath(
"")
234 ,fParameterFileName(
"ppmtompeg_encode_parameter_file.par")
235 ,fMovieParametersDialog(NULL)
236 ,fRecordingStep(WAIT)
238 ,fNbMaxFramesPerSec(100)
239 ,fNbMaxAnglePerSec(360)
240 ,fLaunchSpinDelay(100)
241 ,fUISceneTreeWidget(NULL)
242 ,fUIViewerPropertiesWidget(NULL)
243 ,fUIPickInfosWidget(NULL)
246 ,fControlKeyPress(
false)
247 ,fShiftKeyPress(
false)
249 ,fCheckSceneTreeComponentSignalLock(
false)
250 ,fViewerPropertiesTableWidgetIsInit(
false)
251 ,fSceneTreeComponentTreeWidget(NULL)
252 ,fSceneTreeWidget(NULL)
253 ,fPVRootNodeCreate(
false)
257 ,fTouchableVolumes(
"Touchables")
258 ,fShortcutsDialog(NULL)
259 ,fViewerPropertiesTableWidget(NULL)
260 ,fPickInfosWidget(NULL)
261 ,fPickInfosScrollArea(NULL)
262 ,fTreeWidgetInfosIgnoredCommands(0)
263 ,fSceneTreeDepthSlider(NULL)
265 ,fModelShortNameItem(NULL)
266 ,fMaxPOindexInserted(-1)
268 #
if QT_VERSION < 0x050600
269 ,fSignalMapperMouse(NULL)
270 ,fSignalMapperSurface(NULL)
271 ,fSignalMapperPicking(NULL)
274 ,fTreeIconClosed(NULL)
275 ,fLastExportSliderValue(80)
276 ,fLastHighlightColor(
G4Color(0,0,0,0))
277 ,fLastHighlightName(0)
280 lWaitForVisSubThreadQtOpenGLContextInitialized
281 =
new G4AutoLock(mWaitForVisSubThreadQtOpenGLContextInitialized,
283 lWaitForVisSubThreadQtOpenGLContextMoved
284 =
new G4AutoLock(mWaitForVisSubThreadQtOpenGLContextMoved,
291 G4Qt::getInstance ();
293 fLastPos3 = QPoint(-1,-1);
294 fLastPos2 = QPoint(-1,-1);
295 fLastPos1 = QPoint(-1,-1);
297 initMovieParameters();
299 fLastEventTime =
new QTime();
300 #if QT_VERSION < 0x050600
301 fSignalMapperMouse =
new QSignalMapper(
this);
302 fSignalMapperSurface =
new QSignalMapper(
this);
305 fFileSavePath = QDir::currentPath();
308 QList<QByteArray> formats = QImageWriter::supportedImageFormats ();
309 for (
int i = 0; i < formats.size(); ++i) {
310 addExportImageFormat(formats.at(i).data());
313 const char *
const icon1[]={
371 const char *
const icon2[]={
464 const char *
const search[] = {
476 "OOOOOOOOOOOOOOOOOOO",
477 "OOOOOOOOOOOOOOOOOOO",
478 "OOOOOOOo. .oOOOOOO",
481 "OOOOO. XOOOOX .OOOO",
484 "OOOOO. XOOOOo .OOOO",
488 "OOOOOOOOOOOOO. XOO",
489 "OOOOOOOOOOOOOO. XOO",
490 "OOOOOOOOOOOOOOOoOOO",
491 "OOOOOOOOOOOOOOOOOOO",
492 "OOOOOOOOOOOOOOOOOOO",
493 "OOOOOOOOOOOOOOOOOOO",
494 "OOOOOOOOOOOOOOOOOOO"
497 fSearchIcon =
new QPixmap(search);
498 fTreeIconOpen =
new QPixmap(icon1);
499 fTreeIconClosed =
new QPixmap(icon2);
504 G4OpenGLQtViewer::~G4OpenGLQtViewer (
514 if (fSceneTreeWidget != NULL) {
515 if (fSceneTreeWidget->layout() != NULL) {
516 while ((wItem = fSceneTreeWidget->layout()->takeAt(0)) != 0) {
517 delete wItem->widget();
524 delete fTreeIconOpen;
525 delete fTreeIconClosed;
527 G4cout <<removeTempFolder().toStdString().c_str() <<
G4endl;
529 delete lWaitForVisSubThreadQtOpenGLContextInitialized;
530 delete lWaitForVisSubThreadQtOpenGLContextMoved;
538 void G4OpenGLQtViewer::createPopupMenu() {
540 fContextMenu =
new QMenu(
"All");
542 QMenu *mMouseAction = fContextMenu->addMenu(
"&Mouse actions");
544 #if QT_VERSION < 0x050600
545 fMouseRotateAction = mMouseAction->addAction(
"Rotate", fSignalMapperMouse, SLOT(map()));
546 fMouseMoveAction = mMouseAction->addAction(
"Move", fSignalMapperMouse, SLOT(map()));
547 fMousePickAction = mMouseAction->addAction(
"Pick", fSignalMapperMouse, SLOT(map()));
548 fMouseZoomOutAction = mMouseAction->addAction(
"Zoom out", fSignalMapperMouse, SLOT(map()));
549 fMouseZoomInAction = mMouseAction->addAction(
"Zoom in", fSignalMapperMouse, SLOT(map()));
551 fMouseRotateAction = mMouseAction->addAction(
"Rotate",
this, [=](){ this->toggleMouseAction(1); });
552 fMouseMoveAction = mMouseAction->addAction(
"Move",
this, [=](){ this->toggleMouseAction(2); });
553 fMousePickAction = mMouseAction->addAction(
"Pick",
this, [=](){ this->toggleMouseAction(3); });
554 fMouseZoomOutAction = mMouseAction->addAction(
"Zoom out",
this, [=](){ this->toggleMouseAction(4); });
555 fMouseZoomInAction = mMouseAction->addAction(
"Zoom in",
this, [=](){ this->toggleMouseAction(5); });
557 QAction *shortcutsAction = mMouseAction->addAction(
"Show shortcuts");
559 fMouseRotateAction->setCheckable(
true);
560 fMouseMoveAction->setCheckable(
true);
561 fMousePickAction->setCheckable(
true);
562 fMouseZoomOutAction->setCheckable(
true);
563 fMouseZoomInAction->setCheckable(
true);
564 shortcutsAction->setCheckable(
false);
566 #if QT_VERSION < 0x050600
567 connect(fSignalMapperMouse, SIGNAL(mapped(
int)),
this, SLOT(toggleMouseAction(
int)));
568 fSignalMapperMouse->setMapping(fMouseRotateAction,1);
569 fSignalMapperMouse->setMapping(fMouseMoveAction,2);
570 fSignalMapperMouse->setMapping(fMousePickAction,3);
571 fSignalMapperMouse->setMapping(fMouseZoomOutAction,4);
572 fSignalMapperMouse->setMapping(fMouseZoomInAction,5);
576 SIGNAL(triggered(
bool)),
578 SLOT(showShortcuts()));
581 QMenu *mStyle = fContextMenu->addMenu(
"&Style");
583 QMenu *mProjection = mStyle->addMenu(
"&Projection");
585 #if QT_VERSION < 0x050600
586 fProjectionOrtho = mProjection->addAction(
"Orthographic", fSignalMapperSurface, SLOT(map()));
587 fProjectionPerspective = mProjection->addAction(
"Persepective", fSignalMapperSurface, SLOT(map()));
590 if (fVP.GetFieldHalfAngle() == 0) {
591 createRadioAction(fProjectionOrtho, fProjectionPerspective,SLOT(toggleProjection(
bool)),1);
593 createRadioAction(fProjectionOrtho, fProjectionPerspective,SLOT(toggleProjection(
bool)),2);
597 fProjectionOrtho = mProjection->addAction(
"Orthographic",
this, [=](){ this->toggleProjection(1); });
598 fProjectionPerspective = mProjection->addAction(
"Persepective",
this, [=](){ this->toggleProjection(2); });
601 QMenu *mDrawing = mStyle->addMenu(
"&Drawing");
603 #if QT_VERSION < 0x050600
604 fDrawingWireframe = mDrawing->addAction(
"Wireframe", fSignalMapperSurface, SLOT(map()));
606 fDrawingLineRemoval = mDrawing->addAction(
"Hidden line removal", fSignalMapperSurface, SLOT(map()));
608 fDrawingSurfaceRemoval = mDrawing->addAction(
"Hidden Surface removal", fSignalMapperSurface, SLOT(map()));
610 fDrawingLineSurfaceRemoval = mDrawing->addAction(
"Hidden line and surface removal", fSignalMapperSurface, SLOT(map()));
613 #if QT_VERSION < 0x050600
614 connect(fSignalMapperSurface, SIGNAL(mapped(
int)),
this, SLOT(toggleSurfaceAction(
int)));
615 fSignalMapperSurface->setMapping(fDrawingWireframe,1);
616 fSignalMapperSurface->setMapping(fDrawingLineRemoval,2);
617 fSignalMapperSurface->setMapping(fDrawingSurfaceRemoval,3);
618 fSignalMapperSurface->setMapping(fDrawingLineSurfaceRemoval,4);
620 fDrawingWireframe = mDrawing->addAction(
"Wireframe",
this, [=](){ this->toggleSurfaceAction(1); });
621 fDrawingLineRemoval = mDrawing->addAction(
"Hidden line removal",
this, [=](){ this->toggleSurfaceAction(2); });
622 fDrawingSurfaceRemoval = mDrawing->addAction(
"Hidden Surface removal",
this, [=](){ this->toggleSurfaceAction(3); });
623 fDrawingLineSurfaceRemoval = mDrawing->addAction(
"Hidden line and surface removal",
this, [=](){ this->toggleSurfaceAction(4); });
626 fDrawingWireframe->setCheckable(
true);
627 fDrawingLineRemoval->setCheckable(
true);
628 fDrawingSurfaceRemoval->setCheckable(
true);
629 fDrawingLineSurfaceRemoval->setCheckable(
true);
633 QAction *backgroundColorChooser ;
635 backgroundColorChooser = mStyle->addAction(
"Background color");
639 SLOT(actionChangeBackgroundColor()));
643 QAction *textColorChooser ;
645 textColorChooser = mStyle->addAction(
"Text color");
649 SLOT(actionChangeTextColor()));
653 QAction *defaultColorChooser ;
655 defaultColorChooser = mStyle->addAction(
"Default color");
659 SLOT(actionChangeDefaultColor()));
663 QMenu *mActions = fContextMenu->addMenu(
"&Actions");
664 QAction *createEPS = mActions->addAction(
"Save as ...");
668 SLOT(actionSaveImage()));
671 QAction *movieParameters = mActions->addAction(
"Save as movie...");
675 SLOT(actionMovieParameters()));
681 QMenu *mSpecial = fContextMenu->addMenu(
"S&pecial");
682 QMenu *mTransparency = mSpecial->addMenu(
"Transparency");
683 QAction *transparencyOn = mTransparency->addAction(
"On");
684 QAction *transparencyOff = mTransparency->addAction(
"Off");
686 if (transparency_enabled ==
false) {
687 createRadioAction(transparencyOn,transparencyOff,SLOT(toggleTransparency(
bool)),2);
688 }
else if (transparency_enabled ==
true) {
689 createRadioAction(transparencyOn,transparencyOff,SLOT(toggleTransparency(
bool)),1);
695 QMenu *mAntialiasing = mSpecial->addMenu(
"Antialiasing");
696 QAction *antialiasingOn = mAntialiasing->addAction(
"On");
697 QAction *antialiasingOff = mAntialiasing->addAction(
"Off");
699 if (antialiasing_enabled ==
false) {
700 createRadioAction(antialiasingOn,antialiasingOff,SLOT(toggleAntialiasing(
bool)),2);
701 }
else if (antialiasing_enabled ==
true) {
702 createRadioAction(antialiasingOn,antialiasingOff,SLOT(toggleAntialiasing(
bool)),1);
704 mAntialiasing->clear();
707 QMenu *mHaloing = mSpecial->addMenu(
"Haloing");
708 QAction *haloingOn = mHaloing->addAction(
"On");
709 QAction *haloingOff = mHaloing->addAction(
"Off");
710 if (haloing_enabled ==
false) {
711 createRadioAction(haloingOn,haloingOff,SLOT(toggleHaloing(
bool)),2);
712 }
else if (haloing_enabled ==
true) {
713 createRadioAction(haloingOn,haloingOff,SLOT(toggleHaloing(
bool)),1);
718 QMenu *mAux = mSpecial->addMenu(
"Auxiliary edges");
719 QAction *auxOn = mAux->addAction(
"On");
720 QAction *auxOff = mAux->addAction(
"Off");
721 if (!fVP.IsAuxEdgeVisible()) {
722 createRadioAction(auxOn,auxOff,SLOT(toggleAux(
bool)),2);
724 createRadioAction(auxOn,auxOff,SLOT(toggleAux(
bool)),1);
728 QMenu *mHiddenMarkers = mSpecial->addMenu(
"Hidden markers");
729 QAction *hiddenMarkersOn = mHiddenMarkers->addAction(
"On");
730 QAction *hiddenMarkersOff = mHiddenMarkers->addAction(
"Off");
731 if (fVP.IsMarkerNotHidden()) {
732 createRadioAction(hiddenMarkersOn,hiddenMarkersOff,SLOT(toggleHiddenMarkers(
bool)),2);
734 createRadioAction(hiddenMarkersOn,hiddenMarkersOff,SLOT(toggleHiddenMarkers(
bool)),1);
739 QMenu *mFullScreen = mSpecial->addMenu(
"&Full screen");
740 fFullScreenOn = mFullScreen->addAction(
"On");
741 fFullScreenOff = mFullScreen->addAction(
"Off");
742 createRadioAction(fFullScreenOn,fFullScreenOff,SLOT(toggleFullScreen(
bool)),2);
745 updateToolbarAndMouseContextMenu();
748 void G4OpenGLQtViewer::G4manageContextMenuEvent(QContextMenuEvent *
e)
751 G4cerr <<
"Visualization window not defined, please choose one before" <<
G4endl;
758 if ( fContextMenu ) {
759 fContextMenu->exec( e->globalPos() );
775 void G4OpenGLQtViewer::createRadioAction(QAction *action1,QAction *action2,
const std::string& method,
unsigned int nCheck) {
777 action1->setCheckable(
true);
778 action2->setCheckable(
true);
781 action1->setChecked (
true);
783 action2->setChecked (
true);
797 void G4OpenGLQtViewer::showShortcuts() {
800 text =
"========= Mouse Shortcuts =========\n";
802 if (fUiQt->IsIconRotateSelected()) {
803 text +=
"Click and move mouse to rotate volume \n";
804 text +=
"ALT + Click and move mouse to rotate volume (Toggle View/Theta-Phi Direction) \n";
805 text +=
"CTRL + Click and move mouse to zoom in/out \n";
806 text +=
"SHIFT + Click and move mouse to change camera point of view \n";
807 }
else if (fUiQt->IsIconMoveSelected()) {
808 text +=
"Move camera point of view with mouse \n";
809 }
else if (fUiQt->IsIconPickSelected()) {
810 text +=
"Click and pick \n";
813 text +=
"Click and move mouse to rotate volume \n";
814 text +=
"ALT + Click and move mouse to rotate volume (Toggle View/Theta-Phi Direction) \n";
815 text +=
"CTRL + Click and zoom mouse to zoom in/out \n";
816 text +=
"SHIFT + Click and zoommove camera point of view \n";
818 text +=
"========= Move Shortcuts ========= \n";
819 text +=
"Press left/right arrows to move volume left/right \n";
820 text +=
"Press up/down arrows to move volume up/down \n";
821 text +=
"Press '+'/'-' to move volume toward/forward \n";
823 text +=
"========= Rotation (Theta/Phi) Shortcuts ========= \n";
824 text +=
"Press SHIFT + left/right arrows to rotate volume left/right \n";
825 text +=
"Press SHIFT + up/down arrows to rotate volume up/down \n";
827 text +=
"========= Rotation (View Direction) Shortcuts ========= \n";
828 text +=
"Press ALT + left/right to rotate volume around vertical direction \n";
829 text +=
"Press ALT + up/down to rotate volume around horizontal direction \n";
831 text +=
"========= Zoom View ========= \n";
832 text +=
"Press CTRL + '+'/'-' to zoom into volume \n";
834 text +=
"========= Misc ========= \n";
835 text +=
"Press ALT +/- to slow/speed rotation/move \n";
836 text +=
"Press H to reset view \n";
837 text +=
"Press Esc to exit FullScreen \n";
839 text +=
"========= Video ========= \n";
840 text +=
"In video mode : \n";
841 text +=
" Press SPACE to Start/Pause video recording \n";
842 text +=
" Press RETURN to Stop video recording \n";
847 if ( fShortcutsDialog == NULL) {
848 fShortcutsDialog =
new QDialog();
849 fShortcutsDialogInfos =
new QTextEdit() ;
850 QVBoxLayout *mainLayout =
new QVBoxLayout;
851 mainLayout->addWidget(fShortcutsDialogInfos);
852 fShortcutsDialog->setLayout(mainLayout);
853 fShortcutsDialog->setWindowTitle(tr(
"Shortcuts"));
856 fShortcutsDialogInfos->setPlainText(text.data());
857 fShortcutsDialog->show();
868 void G4OpenGLQtViewer::toggleMouseAction(
int aAction) {
871 fUiQt->SetIconRotateSelected();
872 }
else if (aAction == 2) {
873 fUiQt->SetIconMoveSelected();
874 }
else if (aAction == 3) {
876 }
else if (aAction == 4) {
877 fUiQt->SetIconZoomOutSelected();
878 }
else if (aAction == 5) {
879 fUiQt->SetIconZoomInSelected();
883 updateToolbarAndMouseContextMenu();
897 void G4OpenGLQtViewer::toggleSurfaceAction(
int aAction) {
904 }
else if (aAction ==2) {
907 }
else if (aAction ==3) {
910 }
else if (aAction ==4) {
913 fVP.SetDrawingStyle(d_style);
915 updateToolbarAndMouseContextMenu();
930 void G4OpenGLQtViewer::toggleProjection(
bool check) {
933 fVP.SetOrthogonalProjection ();
935 fVP.SetPerspectiveProjection();
937 updateToolbarAndMouseContextMenu();
946 void G4OpenGLQtViewer::toggleTransparency(
bool check) {
949 transparency_enabled =
true;
951 transparency_enabled =
false;
953 SetNeedKernelVisit (
true);
954 updateToolbarAndMouseContextMenu();
962 void G4OpenGLQtViewer::toggleAntialiasing(
bool check) {
965 antialiasing_enabled =
false;
966 glDisable (GL_LINE_SMOOTH);
967 glDisable (GL_POLYGON_SMOOTH);
969 antialiasing_enabled =
true;
970 glEnable (GL_LINE_SMOOTH);
971 glHint (GL_LINE_SMOOTH_HINT, GL_NICEST);
972 glEnable (GL_POLYGON_SMOOTH);
973 glHint (GL_POLYGON_SMOOTH_HINT, GL_NICEST);
976 updateToolbarAndMouseContextMenu();
985 void G4OpenGLQtViewer::toggleHaloing(
bool check) {
987 haloing_enabled =
false;
989 haloing_enabled =
true;
992 updateToolbarAndMouseContextMenu();
1001 void G4OpenGLQtViewer::toggleAux(
bool check) {
1003 fVP.SetAuxEdgeVisible(
true);
1005 fVP.SetAuxEdgeVisible(
false);
1007 SetNeedKernelVisit (
true);
1008 updateToolbarAndMouseContextMenu();
1013 void G4OpenGLQtViewer::togglePicking() {
1016 if (!fVP.IsPicking()) {
1017 fUiQt->SetIconPickSelected();
1019 fUiQt->SetIconRotateSelected();
1025 if (!fVP.IsPicking()) {
1026 UI->
ApplyCommand(std::string(
"/vis/viewer/set/picking true"));
1028 UI->
ApplyCommand(std::string(
"/vis/viewer/set/picking false"));
1039 void G4OpenGLQtViewer::toggleHiddenMarkers(
bool check) {
1041 fVP.SetMarkerHidden();
1043 fVP.SetMarkerNotHidden();
1046 updateToolbarAndMouseContextMenu();
1053 void G4OpenGLQtViewer::toggleFullScreen(
bool check) {
1054 if (check != fGLWidget->isFullScreen()) {
1055 fGLWidget->setWindowState(fGLWidget->windowState() ^ Qt::WindowFullScreen);
1060 void G4OpenGLQtViewer::savePPMToTemp() {
1061 if (fMovieTempFolderPath ==
"") {
1064 QGLWidget* qGLW =
dynamic_cast<QGLWidget*
> (fGLWidget) ;
1068 QString fileName =
"Test"+QString::number(fRecordFrameNumber)+
".ppm";
1069 QString filePath =fMovieTempFolderPath+fileName;
1072 image = qGLW->grabFrameBuffer();
1075 res = image.save(filePath,0);
1078 setRecordingInfos(
"Can't save tmp file "+filePath);
1082 setRecordingInfos(
"File "+fileName+
" saved");
1083 fRecordFrameNumber++;
1088 void G4OpenGLQtViewer::actionSaveImage() {
1090 for (
unsigned int i = 0; i < fExportImageFormatVector.size(); ++i) {
1091 filters += QString(
"*.") + fExportImageFormatVector.at(i).c_str() +
";;";
1094 QString* selectedFormat =
new QString(fDefaultExportImageFormat.c_str());
1096 qFilename = QFileDialog::getSaveFileName ( fGLWidget,
1103 std::string name = qFilename.toStdString().c_str();
1110 fFileSavePath = QFileInfo(qFilename).path();
1112 std::string format = selectedFormat->toLower().toStdString().c_str();
1115 fExportImageFormat = format.substr(format.find_last_of(
".") + 1);
1118 std::string extension =
"";
1119 if (name.find_last_of(
".") != std::string::npos) {
1120 filename = name.substr(0,name.find_last_of(
".") + 1);
1121 extension = name.substr(name.find_last_of(
".") + 1);
1123 extension = fExportImageFormat;
1126 filename+=
"."+ extension;
1128 if (!setExportFilename(filename.c_str(),0)) {
1132 G4OpenGLQtExportDialog* exportDialog=
new G4OpenGLQtExportDialog(fGLWidget,format.c_str(),fGLWidget->height(),fGLWidget->width());
1133 if( exportDialog->exec()) {
1135 if ((exportDialog->getWidth() !=fGLWidget->width()) ||
1136 (exportDialog->getHeight() !=fGLWidget->height())) {
1137 setExportSize(exportDialog->getWidth(),exportDialog->getHeight());
1140 if (fExportImageFormat ==
"eps") {
1141 fVectoredPs = exportDialog->getVectorEPS();
1142 }
else if (fExportImageFormat ==
"ps") {
1145 fLastExportSliderValue = exportDialog->getSliderValue();
1147 if (exportImage(filename)) {
1149 fDefaultExportImageFormat = format;
1158 void G4OpenGLQtViewer::actionChangeBackgroundColor() {
1166 #if QT_VERSION < 0x040500
1168 const QColor
color = QColor(QColorDialog::getRgba (QColor(Qt::black).rgba(),&a,fGLWidget));
1170 const QColor color =
1171 QColorDialog::getColor(Qt::black,
1173 " Get background color and transparency",
1174 QColorDialog::ShowAlphaChannel);
1176 if (color.isValid()) {
1181 fVP.SetBackgroundColour(colour);
1183 updateToolbarAndMouseContextMenu();
1188 void G4OpenGLQtViewer::actionChangeTextColor() {
1190 #if QT_VERSION < 0x040500
1192 const QColor color = QColor(QColorDialog::getRgba (QColor(Qt::yellow).rgba(),&a,fGLWidget));
1194 const QColor& color =
1195 QColorDialog::getColor(Qt::yellow,
1197 " Get text color and transparency",
1198 QColorDialog::ShowAlphaChannel);
1200 if (color.isValid()) {
1206 fVP.SetDefaultTextColour(colour);
1208 updateToolbarAndMouseContextMenu();
1213 void G4OpenGLQtViewer::actionChangeDefaultColor() {
1215 #if QT_VERSION < 0x040500
1217 const QColor color = QColor(QColorDialog::getRgba (QColor(Qt::white).rgba(),&a,fGLWidget));
1219 const QColor& color =
1220 QColorDialog::getColor(Qt::white,
1222 " Get default color and transparency",
1223 QColorDialog::ShowAlphaChannel);
1225 if (color.isValid()) {
1231 fVP.SetDefaultColour(colour);
1233 updateToolbarAndMouseContextMenu();
1239 void G4OpenGLQtViewer::actionMovieParameters() {
1240 showMovieParametersDialog();
1244 void G4OpenGLQtViewer::showMovieParametersDialog() {
1245 if (!fMovieParametersDialog) {
1246 fMovieParametersDialog=
new G4OpenGLQtMovieDialog(
this,fGLWidget);
1247 displayRecordingStatus();
1248 fMovieParametersDialog->checkEncoderSwParameters();
1249 fMovieParametersDialog->checkSaveFileNameParameters();
1250 fMovieParametersDialog->checkTempFolderParameters();
1251 if (getEncoderPath() ==
"") {
1252 setRecordingInfos(
"ppmtompeg is needed to encode in video format. It is available here: http://netpbm.sourceforge.net ");
1255 fMovieParametersDialog->show();
1260 void G4OpenGLQtViewer::FinishView()
1276 void G4OpenGLQtViewer::G4MousePressEvent(QMouseEvent *evnt)
1278 if (evnt->button() == Qt::RightButton) {
1281 if ((evnt->button() & Qt::LeftButton) && (! (evnt->modifiers() & Qt::ControlModifier ))){
1282 fGLWidget->setMouseTracking(
true);
1284 fLastPos1 = evnt->pos();
1285 fLastPos2 = fLastPos1;
1286 fLastPos3 = fLastPos2;
1287 fLastEventTime->start();
1288 if (fUiQt != NULL) {
1290 if (fUiQt->IsIconZoomInSelected()) {
1293 float deltaX = ((float)getWinWidth()/2-evnt->pos().x());
1294 float deltaY = ((float)getWinHeight()/2-evnt->pos().y());
1298 if (getWinHeight() <getWinWidth()) {
1301 fVP.IncrementPan(-deltaX*coefTrans,deltaY*coefTrans,0);
1302 fVP.SetZoomFactor(1.5 * fVP.GetZoomFactor());
1306 }
else if (fUiQt->IsIconZoomOutSelected()) {
1308 moveScene(((
float)getWinWidth()/2-evnt->pos().x()),((
float)getWinHeight()/2-evnt->
pos().
y()),0,
true);
1310 fVP.SetZoomFactor(0.75 * fVP.GetZoomFactor());
1313 } else
if (fUiQt->IsIconRotateSelected() ) {
1315 if (fShiftKeyPress) {
1316 fGLWidget->setCursor(QCursor(Qt::SizeAllCursor));
1319 fGLWidget->setCursor(QCursor(Qt::ClosedHandCursor));
1321 }
else if (fUiQt->IsIconMoveSelected()) {
1322 fGLWidget->setCursor(QCursor(Qt::SizeAllCursor));
1323 }
else if (fUiQt->IsIconPickSelected()) {
1324 fGLWidget->setCursor(QCursor(Qt::PointingHandCursor));
1332 void G4OpenGLQtViewer::G4MouseReleaseEvent(QMouseEvent *evnt)
1335 glGetIntegerv(GL_VIEWPORT, viewport);
1338 double factorX = ((double)viewport[2]/fGLWidget->width());
1339 double factorY = ((double)viewport[3]/fGLWidget->height());
1340 fSpinningDelay = fLastEventTime->elapsed();
1341 QPoint
delta = (fLastPos3-fLastPos1)*factorX;
1344 fGLWidget->setCursor(QCursor(Qt::ArrowCursor));
1346 if (fVP.IsPicking()){
1347 if ((delta.x() != 0) || (delta.y() != 0)) {
1350 updatePickInfosWidget(evnt->pos().x()*factorX,evnt->pos().y()*factorY);
1352 }
else if (fSpinningDelay < fLaunchSpinDelay ) {
1353 if ((delta.x() == 0) && (delta.y() == 0)) {
1359 lastMoveTime.start();
1361 float correctionFactor = 5;
1363 if ( lastMoveTime.elapsed() >= (
int)(1000/fNbMaxFramesPerSec)) {
1364 float lTime = 1000/lastMoveTime.elapsed();
1365 if (((((
float)delta.x())/correctionFactor)*lTime > fNbMaxAnglePerSec) ||
1366 ((((
float)delta.x())/correctionFactor)*lTime < -fNbMaxAnglePerSec) ) {
1367 correctionFactor = (float)delta.x()*(lTime/fNbMaxAnglePerSec);
1368 if (delta.x() <0 ) {
1369 correctionFactor = -correctionFactor;
1372 if (((((
float)delta.y())/correctionFactor)*lTime > fNbMaxAnglePerSec) ||
1373 ((((
float)delta.y())/correctionFactor)*lTime < -fNbMaxAnglePerSec) ) {
1374 correctionFactor = (float)delta.y()*(lTime/fNbMaxAnglePerSec);
1375 if (delta.y() <0 ) {
1376 correctionFactor = -correctionFactor;
1387 lastMoveTime.start();
1389 bool rotate =
false;
1392 if (fUiQt != NULL) {
1393 if (fUiQt->IsIconRotateSelected()) {
1395 }
else if (fUiQt->IsIconMoveSelected()) {
1408 rotateQtScene(((
float)delta.x())/correctionFactor,((
float)delta.y())/correctionFactor);
1409 } else
if (fAltKeyPress) {
1410 rotateQtSceneToggle(((
float)delta.x())/correctionFactor,((
float)delta.y())/correctionFactor);
1414 moveScene(-((
float)delta.x())/correctionFactor,-((
float)delta.y())/correctionFactor,0,true);
1417 ((QApplication*)G4Qt::getInstance ())->processEvents();
1420 fGLWidget->setMouseTracking(
false);
1425 void G4OpenGLQtViewer::G4MouseDoubleClickEvent()
1427 fGLWidget->setMouseTracking(
true);
1438 void G4OpenGLQtViewer::G4MouseMoveEvent(QMouseEvent *evnt)
1441 Qt::MouseButtons mButtons = evnt->buttons();
1443 updateKeyModifierState(evnt->modifiers());
1449 fLastPos3 = fLastPos2;
1450 fLastPos2 = fLastPos1;
1451 fLastPos1 = QPoint(evnt->x(), evnt->y());
1453 int deltaX = fLastPos2.x()-fLastPos1.x();
1454 int deltaY = fLastPos2.y()-fLastPos1.y();
1457 if (fUiQt != NULL) {
1458 if (fUiQt->IsIconMoveSelected()) {
1463 if (mButtons & Qt::LeftButton) {
1465 rotateQtScene(((
float)deltaX),((
float)deltaY));
1466 }
else if (fAltKeyPress) {
1467 rotateQtSceneToggle(((
float)deltaX),((
float)deltaY));
1468 }
else if (fShiftKeyPress) {
1469 unsigned int sizeWin;
1470 sizeWin = getWinWidth();
1471 if (getWinHeight() < getWinWidth()) {
1472 sizeWin = getWinHeight();
1476 float factor = ((float)100/(
float)sizeWin) ;
1477 moveScene(-(
float)deltaX*factor,-(
float)deltaY*factor,0,
false);
1478 }
else if (fControlKeyPress) {
1479 fVP.SetZoomFactor(fVP.GetZoomFactor()*(1+((float)deltaY)));
1483 if (mButtons & Qt::LeftButton) {
1484 moveScene(-(
float)deltaX,-(
float)deltaY,0,
true);
1488 fLastEventTime->start();
1499 void G4OpenGLQtViewer::moveScene(
float dx,
float dy,
float dz,
bool mouseMove)
1503 fHoldMoveEvent =
true;
1506 GLdouble coefDepth = 0;
1509 if (getWinHeight() <getWinWidth()) {
1513 coefTrans = getSceneNearWidth()*fPan_sens;
1514 coefDepth = getSceneDepth()*fDeltaDepth;
1516 fVP.IncrementPan(-dx*coefTrans,dy*coefTrans,dz*coefDepth);
1520 ((QApplication*)G4Qt::getInstance ())->processEvents();
1522 fHoldMoveEvent =
false;
1531 void G4OpenGLQtViewer::rotateQtScene(
float dx,
float dy)
1533 if (fHoldRotateEvent)
1535 fHoldRotateEvent =
true;
1541 fHoldRotateEvent =
false;
1549 void G4OpenGLQtViewer::rotateQtSceneToggle(
float dx,
float dy)
1551 if (fHoldRotateEvent)
1553 fHoldRotateEvent =
true;
1555 rotateSceneToggle(dx,dy);
1559 fHoldRotateEvent =
false;
1570 void G4OpenGLQtViewer::rescaleImage(
1590 void G4OpenGLQtViewer::G4wheelEvent (QWheelEvent * evnt)
1592 fVP.SetZoomFactor(fVP.GetZoomFactor()+(fVP.GetZoomFactor()*(evnt->delta())/1200));
1597 void G4OpenGLQtViewer::G4keyPressEvent (QKeyEvent * evnt)
1602 fHoldKeyEvent =
true;
1606 updateKeyModifierState(evnt->modifiers());
1607 if ((fNoKeyPress) || (evnt->modifiers() == Qt::KeypadModifier )) {
1608 if (evnt->key() == Qt::Key_Down) {
1609 moveScene(0,1,0,
false);
1611 else if (evnt->key() == Qt::Key_Up) {
1612 moveScene(0,-1,0,
false);
1614 if (evnt->key() == Qt::Key_Left) {
1615 moveScene(-1,0,0,
false);
1617 else if (evnt->key() == Qt::Key_Right) {
1618 moveScene(1,0,0,
false);
1620 if (evnt->key() == Qt::Key_Minus) {
1621 moveScene(0,0,1,
false);
1623 else if (evnt->key() == Qt::Key_Plus) {
1624 moveScene(0,0,-1,
false);
1627 if (evnt->key() == Qt::Key_Escape) {
1628 toggleFullScreen(
false);
1637 if ((evnt->key() == Qt::Key_Return) || (evnt->key() == Qt::Key_Enter)){
1640 if (evnt->key() == Qt::Key_Space){
1645 if (evnt->key() == Qt::Key_H){
1652 if (fShiftKeyPress) {
1653 fGLWidget->setCursor(QCursor(Qt::SizeAllCursor));
1655 if (evnt->key() == Qt::Key_Down) {
1656 rotateQtScene(0,-fRot_sens);
1658 else if (evnt->key() == Qt::Key_Up) {
1659 rotateQtScene(0,fRot_sens);
1661 if (evnt->key() == Qt::Key_Left) {
1662 rotateQtScene(fRot_sens,0);
1664 else if (evnt->key() == Qt::Key_Right) {
1665 rotateQtScene(-fRot_sens,0);
1667 if (evnt->key() == Qt::Key_Plus) {
1669 moveScene(0,0,-1,
false);
1674 if ((fAltKeyPress)) {
1675 fGLWidget->setCursor(QCursor(Qt::ClosedHandCursor));
1677 if (evnt->key() == Qt::Key_Down) {
1678 rotateQtSceneToggle(0,-fRot_sens);
1680 else if (evnt->key() == Qt::Key_Up) {
1681 rotateQtSceneToggle(0,fRot_sens);
1683 if (evnt->key() == Qt::Key_Left) {
1684 rotateQtSceneToggle(fRot_sens,0);
1686 else if (evnt->key() == Qt::Key_Right) {
1687 rotateQtSceneToggle(-fRot_sens,0);
1691 if (evnt->key() == Qt::Key_Plus) {
1692 fRot_sens = fRot_sens/0.7;
1693 G4cout <<
"Auto-rotation set to : " << fRot_sens <<
G4endl;
1695 else if (evnt->key() == Qt::Key_Minus) {
1696 fRot_sens = fRot_sens*0.7;
1697 G4cout <<
"Auto-rotation set to : " << fRot_sens <<
G4endl;
1702 if ((fControlKeyPress)) {
1703 if (evnt->key() == Qt::Key_Plus) {
1704 fVP.SetZoomFactor(fVP.GetZoomFactor()*(1+fDeltaZoom));
1707 else if (evnt->key() == Qt::Key_Minus) {
1708 fVP.SetZoomFactor(fVP.GetZoomFactor()*(1-fDeltaZoom));
1713 fHoldKeyEvent =
false;
1717 void G4OpenGLQtViewer::G4keyReleaseEvent (QKeyEvent *)
1719 fGLWidget->setCursor(QCursor(Qt::ArrowCursor));
1723 void G4OpenGLQtViewer::updateKeyModifierState(
const Qt::KeyboardModifiers& modifier) {
1727 fAltKeyPress =
false;
1728 fShiftKeyPress =
false;
1729 fControlKeyPress =
false;
1731 if (modifier & Qt::AltModifier ) {
1732 fAltKeyPress =
true;
1733 fNoKeyPress =
false;
1735 if (modifier & Qt::ShiftModifier ) {
1736 fShiftKeyPress =
true;
1737 fNoKeyPress =
false;
1739 if (modifier & Qt::ControlModifier ) {
1740 fControlKeyPress =
true;
1741 fNoKeyPress =
false;
1748 void G4OpenGLQtViewer::stopVideo() {
1751 if (!fMovieParametersDialog) {
1752 showMovieParametersDialog();
1754 setRecordingStatus(STOP);
1756 if (fRecordFrameNumber >0) {
1758 if (!(fMovieParametersDialog->checkEncoderSwParameters())) {
1759 setRecordingStatus(BAD_ENCODER);
1760 }
else if (!(fMovieParametersDialog->checkSaveFileNameParameters())) {
1761 setRecordingStatus(BAD_OUTPUT);
1765 setRecordingInfos(
"No frame to encode.");
1771 void G4OpenGLQtViewer::saveVideo() {
1774 if (!fMovieParametersDialog) {
1775 showMovieParametersDialog();
1778 fMovieParametersDialog->checkEncoderSwParameters();
1779 fMovieParametersDialog->checkSaveFileNameParameters();
1781 if (fRecordingStep == STOP) {
1782 setRecordingStatus(SAVE);
1783 generateMpegEncoderParameters();
1791 void G4OpenGLQtViewer::startPauseVideo() {
1795 if ( fRecordingStep == WAIT) {
1796 if ( fRecordFrameNumber == 0) {
1797 if (getTempFolderPath() ==
"") {
1798 showMovieParametersDialog();
1799 setRecordingInfos(
"You should specified the temp folder in order to make movie");
1803 QString
tmp = removeTempFolder();
1805 setRecordingInfos(tmp);
1808 tmp = createTempFolder();
1810 setRecordingInfos(
"Can't create temp folder."+tmp);
1816 if (fRecordingStep == WAIT) {
1817 setRecordingStatus(
START);
1818 }
else if (fRecordingStep ==
START) {
1819 setRecordingStatus(PAUSE);
1820 }
else if (fRecordingStep == PAUSE) {
1821 setRecordingStatus(CONTINUE);
1822 }
else if (fRecordingStep == CONTINUE) {
1823 setRecordingStatus(PAUSE);
1827 void G4OpenGLQtViewer::setRecordingStatus(RECORDING_STEP
step) {
1829 fRecordingStep =
step;
1830 displayRecordingStatus();
1834 void G4OpenGLQtViewer::displayRecordingStatus() {
1836 QString txtStatus =
"";
1837 if (fRecordingStep == WAIT) {
1838 txtStatus =
"Waiting to start...";
1839 fRecordFrameNumber = 0;
1840 }
else if (fRecordingStep ==
START) {
1841 txtStatus =
"Start Recording...";
1842 }
else if (fRecordingStep == PAUSE) {
1843 txtStatus =
"Pause Recording...";
1844 }
else if (fRecordingStep == CONTINUE) {
1845 txtStatus =
"Continue Recording...";
1846 }
else if (fRecordingStep == STOP) {
1847 txtStatus =
"Stop Recording...";
1848 }
else if (fRecordingStep == READY_TO_ENCODE) {
1849 txtStatus =
"Ready to Encode...";
1850 }
else if (fRecordingStep ==
ENCODING) {
1851 txtStatus =
"Encoding...";
1852 }
else if (fRecordingStep == FAILED) {
1853 txtStatus =
"Failed to encode...";
1854 }
else if ((fRecordingStep == BAD_ENCODER)
1855 || (fRecordingStep == BAD_OUTPUT)
1856 || (fRecordingStep == BAD_TMP)) {
1857 txtStatus =
"Correct above errors first";
1858 }
else if (fRecordingStep ==
SUCCESS) {
1859 txtStatus =
"File encoded successfully";
1863 if (fMovieParametersDialog) {
1864 fMovieParametersDialog->setRecordingStatus(txtStatus);
1868 setRecordingInfos(
"");
1872 void G4OpenGLQtViewer::setRecordingInfos(
const QString& txt) {
1873 if (fMovieParametersDialog) {
1874 fMovieParametersDialog->setRecordingInfos(txt);
1882 void G4OpenGLQtViewer::initMovieParameters() {
1886 fProcess =
new QProcess();
1889 this,SLOT(processLookForFinished()));
1890 fProcess->setProcessChannelMode(QProcess::MergedChannels);
1891 fProcess->start (
"which ppmtompeg");
1897 QString G4OpenGLQtViewer::getEncoderPath() {
1898 return fEncoderPath;
1906 QString G4OpenGLQtViewer::setEncoderPath(QString path) {
1908 return "ppmtompeg is needed to encode in video format. It is available here: http://netpbm.sourceforge.net ";
1911 path = QDir::cleanPath(path);
1912 QFileInfo *
f =
new QFileInfo(path);
1914 return "File does not exist";
1915 }
else if (f->isDir()) {
1916 return "This is a directory";
1917 }
else if (!f->isExecutable()) {
1918 return "File exist but is not executable";
1919 }
else if (!f->isFile()) {
1920 return "This is not a file";
1922 fEncoderPath = path;
1924 if (fRecordingStep == BAD_ENCODER) {
1925 setRecordingStatus(STOP);
1931 bool G4OpenGLQtViewer::isRecording(){
1932 if ((fRecordingStep ==
START) || (fRecordingStep == CONTINUE)) {
1938 bool G4OpenGLQtViewer::isPaused(){
1939 if (fRecordingStep == PAUSE) {
1945 bool G4OpenGLQtViewer::isEncoding(){
1952 bool G4OpenGLQtViewer::isWaiting(){
1953 if (fRecordingStep == WAIT) {
1959 bool G4OpenGLQtViewer::isStopped(){
1960 if (fRecordingStep == STOP) {
1966 bool G4OpenGLQtViewer::isFailed(){
1967 if (fRecordingStep == FAILED) {
1973 bool G4OpenGLQtViewer::isSuccess(){
1974 if (fRecordingStep ==
SUCCESS) {
1980 bool G4OpenGLQtViewer::isBadEncoder(){
1981 if (fRecordingStep == BAD_ENCODER) {
1986 bool G4OpenGLQtViewer::isBadTmp(){
1987 if (fRecordingStep == BAD_TMP) {
1992 bool G4OpenGLQtViewer::isBadOutput(){
1993 if (fRecordingStep == BAD_OUTPUT) {
1999 void G4OpenGLQtViewer::setBadEncoder(){
2000 fRecordingStep = BAD_ENCODER;
2001 displayRecordingStatus();
2003 void G4OpenGLQtViewer::setBadTmp(){
2004 fRecordingStep = BAD_TMP;
2005 displayRecordingStatus();
2007 void G4OpenGLQtViewer::setBadOutput(){
2008 fRecordingStep = BAD_OUTPUT;
2009 displayRecordingStatus();
2012 void G4OpenGLQtViewer::setWaiting(){
2013 fRecordingStep = WAIT;
2014 displayRecordingStatus();
2018 bool G4OpenGLQtViewer::isReadyToEncode(){
2019 if (fRecordingStep == READY_TO_ENCODE) {
2025 void G4OpenGLQtViewer::resetRecording() {
2026 setRecordingStatus(WAIT);
2033 QString G4OpenGLQtViewer::setTempFolderPath(QString path) {
2036 return "Path does not exist";
2038 path = QDir::cleanPath(path);
2039 QFileInfo *
d =
new QFileInfo(path);
2041 return "Path does not exist";
2042 }
else if (!d->isDir()) {
2043 return "This is not a directory";
2044 }
else if (!d->isReadable()) {
2045 return path +
" is read protected";
2046 }
else if (!d->isWritable()) {
2047 return path +
" is write protected";
2050 if (fRecordingStep == BAD_TMP) {
2051 setRecordingStatus(WAIT);
2053 fTempFolderPath = path;
2059 QString G4OpenGLQtViewer::getTempFolderPath() {
2060 return fTempFolderPath;
2067 QString G4OpenGLQtViewer::setSaveFileName(QString path) {
2070 return "Path does not exist";
2073 QFileInfo *
file =
new QFileInfo(path);
2074 QDir
dir = file->dir();
2075 path = QDir::cleanPath(path);
2076 if (file->exists()) {
2077 return "File already exist, please choose a new one";
2078 }
else if (!dir.exists()) {
2079 return "Dir does not exist";
2080 }
else if (!dir.isReadable()) {
2081 return path +
" is read protected";
2084 if (fRecordingStep == BAD_OUTPUT) {
2085 setRecordingStatus(STOP);
2087 fSaveFileName = path;
2093 QString G4OpenGLQtViewer::getSaveFileName() {
2094 return fSaveFileName ;
2101 QString G4OpenGLQtViewer::createTempFolder() {
2102 fMovieTempFolderPath =
"";
2104 QString
tmp = setTempFolderPath(fTempFolderPath);
2109 QString path = sep+
"QtMovie_"+QDateTime::currentDateTime ().toString(
"dd-MM-yyyy_hh-mm-ss")+sep;
2110 QDir *d =
new QDir(QDir::cleanPath(fTempFolderPath));
2112 if (d->exists(path)) {
2113 return "Folder "+path+
" already exists.Please remove it first";
2115 if (d->mkdir(fTempFolderPath+path)) {
2116 fMovieTempFolderPath = fTempFolderPath+path;
2119 return "Can't create "+fTempFolderPath+path;
2124 QString G4OpenGLQtViewer::removeTempFolder() {
2126 if (fMovieTempFolderPath ==
"") {
2129 QDir *d =
new QDir(QDir::cleanPath(fMovieTempFolderPath));
2134 d->setFilter( QDir::Files );
2135 QStringList subDirList = d->entryList();
2138 for (QStringList::ConstIterator
it = subDirList.begin() ;(
it != subDirList.end()) ;
it++) {
2139 const QString currentFile = *
it;
2140 if (!d->remove(currentFile)) {
2142 QString file = fMovieTempFolderPath+currentFile;
2143 error +=
"Removing file failed : "+
file;
2148 if (d->rmdir(fMovieTempFolderPath)) {
2149 fMovieTempFolderPath =
"";
2152 return "Dir "+fMovieTempFolderPath+
" should be empty, but could not remove it";
2156 return "Could not remove "+fMovieTempFolderPath+
" because of the following errors :"+
error;
2166 bool G4OpenGLQtViewer::exportImage(std::string name,
int width,
int height) {
2168 QGLWidget* qGLW =
dynamic_cast<QGLWidget*
> (fGLWidget) ;
2173 bool increaseFileNumber =
true;
2175 if (name.size() != name.substr(name.find_last_of(
".") + 1).size()) {
2176 increaseFileNumber =
false;
2178 if (! setExportFilename(name,increaseFileNumber)) {
2181 if ((width !=-1) && (height != -1)) {
2182 setExportSize(width, height);
2185 if (G4OpenGLViewer::exportImage(name, width, height)) {
2191 image = qGLW->grabFrameBuffer();
2193 bool res = image.save(QString(getRealPrintFilename().c_str()),0,fLastExportSliderValue);
2196 G4cerr <<
"Error saving file... " << getRealPrintFilename().c_str() <<
G4endl;
2199 G4cout <<
"File " << getRealPrintFilename().c_str() <<
" size: " << fGLWidget->width() <<
"x" << fGLWidget->height() <<
" has been saved " <<
G4endl;
2200 fExportFilenameIndex++;
2206 bool G4OpenGLQtViewer::generateMpegEncoderParameters () {
2210 fp = fopen (QString(fMovieTempFolderPath+fParameterFileName).toStdString().c_str(),
"w");
2213 setRecordingInfos(
"Generation of parameter file failed");
2217 fprintf (fp,
"# Pattern affects speed, quality and compression. See the User's Guide\n");
2218 fprintf (fp,
"# for more info.\n");
2220 fprintf (fp,
"PATTERN I\n");
2221 fprintf (fp,
"OUTPUT %s\n",getSaveFileName().toStdString().c_str());
2223 fprintf (fp,
"# You must specify the type of the input files. The choices are:\n");
2224 fprintf (fp,
"# YUV, PPM, JMOVIE, Y, JPEG, PNM\n");
2225 fprintf (fp,
"# (must be upper case)\n");
2227 fprintf (fp,
"BASE_FILE_FORMAT PPM\n");
2230 fprintf (fp,
"# If you are using YUV, there are different supported file formats.\n");
2231 fprintf (fp,
"# EYUV or UCB are the same as previous versions of this encoder.\n");
2232 fprintf (fp,
"# (All the Y's, then U's then V's, in 4:2:0 subsampling.)\n");
2233 fprintf (fp,
"# Other formats, such as Abekas, Phillips, or a general format are\n");
2234 fprintf (fp,
"# permissible, the general format is a string of Y's, U's, and V's\n");
2235 fprintf (fp,
"# to specify the file order.\n");
2237 fprintf (fp,
"INPUT_FORMAT UCB\n");
2239 fprintf (fp,
"# the conversion statement\n");
2241 fprintf (fp,
"# Each occurrence of '*' will be replaced by the input file\n");
2243 fprintf (fp,
"# e.g., if you have a bunch of GIF files, then this might be:\n");
2244 fprintf (fp,
"# INPUT_CONVERT giftoppm *\n");
2246 fprintf (fp,
"# e.g., if you have a bunch of files like a.Y a.U a.V, etc., then:\n");
2247 fprintf (fp,
"# INPUT_CONVERT cat *.Y *.U *.V\n");
2249 fprintf (fp,
"# e.g., if you are grabbing from laser disc you might have something like\n");
2250 fprintf (fp,
"# INPUT_CONVERT goto frame *; grabppm\n");
2251 fprintf (fp,
"# 'INPUT_CONVERT *' means the files are already in the base file format\n");
2253 fprintf (fp,
"INPUT_CONVERT * \n");
2255 fprintf (fp,
"# number of frames in a GOP.\n");
2257 fprintf (fp,
"# since each GOP must have at least one I-frame, the encoder will find the\n");
2258 fprintf (fp,
"# the first I-frame after GOP_SIZE frames to start the next GOP\n");
2260 fprintf (fp,
"# later, will add more flexible GOP signalling\n");
2262 fprintf (fp,
"GOP_SIZE 1\n");
2264 fprintf (fp,
"# number of slices in a frame\n");
2266 fprintf (fp,
"# 1 is a good number. another possibility is the number of macroblock rows\n");
2267 fprintf (fp,
"# (which is the height divided by 16)\n");
2269 fprintf (fp,
"SLICES_PER_FRAME 1\n");
2270 fprintf (fp,
"PIXEL HALF");
2272 fprintf (fp,
"# directory to get all input files from (makes this file easier to read)\n");
2273 fprintf (fp,
"INPUT_DIR %s\n",fMovieTempFolderPath.toStdString().c_str());
2275 fprintf (fp,
"# There are a bunch of ways to specify the input files.\n");
2276 fprintf (fp,
"# from a simple one-per-line listing, to the following \n");
2277 fprintf (fp,
"# way of numbering them. See the manual for more information.\n");
2278 fprintf (fp,
"INPUT\n");
2279 fprintf (fp,
"# '*' is replaced by the numbers 01, 02, 03, 04\n");
2280 fprintf (fp,
"# if I instead do [01-11], it would be 01, 02, ..., 09, 10, 11\n");
2281 fprintf (fp,
"# if I instead do [1-11], it would be 1, 2, 3, ..., 9, 10, 11\n");
2282 fprintf (fp,
"# if I instead do [1-11+3], it would be 1, 4, 7, 10\n");
2283 fprintf (fp,
"# the program assumes none of your input files has a name ending in ']'\n");
2284 fprintf (fp,
"# if you do, too bad!!!\n");
2287 fprintf (fp,
"Test*.ppm [0-%d]\n",fRecordFrameNumber-1);
2288 fprintf (fp,
"# can have more files here if you want...there is no limit on the number\n");
2289 fprintf (fp,
"# of files\n");
2290 fprintf (fp,
"END_INPUT\n");
2294 fprintf (fp,
"# Many of the remaining options have to do with the motion search and qscale\n");
2296 fprintf (fp,
"# FULL or HALF -- must be upper case\n");
2297 fprintf (fp,
"# Should be FULL for computer generated images\n");
2298 fprintf (fp,
"PIXEL FULL\n");
2300 fprintf (fp,
"# means +/- this many pixels for both P and B frame searches\n");
2301 fprintf (fp,
"# specify two numbers if you wish to serc different ranges in the two.\n");
2302 fprintf (fp,
"RANGE 10\n");
2304 fprintf (fp,
"# The two search algorithm parameters below mostly affect speed,\n");
2305 fprintf (fp,
"# with some affect on compression and almost none on quality.\n");
2307 fprintf (fp,
"# this must be one of {EXHAUSTIVE, SUBSAMPLE, LOGARITHMIC}\n");
2308 fprintf (fp,
"PSEARCH_ALG LOGARITHMIC\n");
2310 fprintf (fp,
"# this must be one of {SIMPLE, CROSS2, EXHAUSTIVE}\n");
2312 fprintf (fp,
"# note that EXHAUSTIVE is really, really, really slow\n");
2314 fprintf (fp,
"BSEARCH_ALG SIMPLE\n");
2317 fprintf (fp,
"# these specify the q-scale for I, P, and B frames\n");
2318 fprintf (fp,
"# (values must be between 1 and 31)\n");
2319 fprintf (fp,
"# These are the Qscale values for the entire frame in variable bit-rate\n");
2320 fprintf (fp,
"# mode, and starting points (but not important) for constant bit rate\n");
2323 fprintf (fp,
"# Qscale (Quantization scale) affects quality and compression,\n");
2324 fprintf (fp,
"# but has very little effect on speed.\n");
2326 fprintf (fp,
"IQSCALE 4\n");
2327 fprintf (fp,
"PQSCALE 5\n");
2328 fprintf (fp,
"BQSCALE 12\n");
2330 fprintf (fp,
"# this must be ORIGINAL or DECODED\n");
2331 fprintf (fp,
"REFERENCE_FRAME ORIGINAL\n");
2333 fprintf (fp,
"# for parallel parameters see parallel.param in the exmaples subdirectory\n");
2335 fprintf (fp,
"# if you want constant bit-rate mode, specify it as follows (number is bits/sec):\n");
2336 fprintf (fp,
"#BIT_RATE 1000000\n");
2338 fprintf (fp,
"# To specify the buffer size (327680 is default, measused in bits, for 16bit words)\n");
2339 fprintf (fp,
"BUFFER_SIZE 327680\n");
2341 fprintf (fp,
"# The frame rate is the number of frames/second (legal values:\n");
2342 fprintf (fp,
"# 23.976, 24, 25, 29.97, 30, 50 ,59.94, 60\n");
2343 fprintf (fp,
"FRAME_RATE 30\n");
2345 fprintf (fp,
"# There are many more options, see the users manual for examples....\n");
2346 fprintf (fp,
"# ASPECT_RATIO, USER_DATA, GAMMA, IQTABLE, etc.\n");
2351 setRecordingInfos(
"Parameter file "+fParameterFileName+
" generated in "+fMovieTempFolderPath);
2352 setRecordingStatus(READY_TO_ENCODE);
2356 void G4OpenGLQtViewer::encodeVideo()
2358 if ((getEncoderPath() !=
"") && (getSaveFileName() !=
"")) {
2361 fProcess =
new QProcess();
2362 #if QT_VERSION > 0x040100
2364 this,SLOT(processEncodeFinished()));
2366 this,SLOT(processEncodeStdout()));
2369 this,SLOT(processEncodeFinished()));
2371 this,SLOT(processEncodeStdout()));
2373 #if QT_VERSION < 0x050a00
2374 fProcess->setReadChannelMode(QProcess::MergedChannels);
2376 fProcess->setProcessChannelMode(QProcess::MergedChannels);
2378 fProcess->start (fEncoderPath, QStringList(fMovieTempFolderPath+fParameterFileName));
2384 void G4OpenGLQtViewer::processEncodeStdout()
2386 QString tmp = fProcess->readAllStandardOutput ().data();
2387 int start = tmp.lastIndexOf(
"ESTIMATED TIME");
2388 tmp = tmp.mid(start,tmp.indexOf(
"\n",start)-
start);
2389 setRecordingInfos(tmp);
2393 void G4OpenGLQtViewer::processEncodeFinished()
2397 txt = getProcessErrorMsg();
2401 setRecordingStatus(FAILED);
2407 void G4OpenGLQtViewer::processLookForFinished()
2410 QString txt = getProcessErrorMsg();
2414 fEncoderPath = QString(fProcess->readAllStandardOutput ().data()).trimmed();
2416 if (fEncoderPath.contains(
" ")) {
2418 }
else if (!fEncoderPath.contains(
"ppmtompeg")) {
2421 setEncoderPath(fEncoderPath);
2424 setTempFolderPath(QDir::temp ().absolutePath ());
2428 QString G4OpenGLQtViewer::getProcessErrorMsg()
2431 if (fProcess->exitCode() != 0) {
2432 switch (fProcess->error()) {
2433 case QProcess::FailedToStart:
2434 txt =
"The process failed to start. Either the invoked program is missing, or you may have insufficient permissions to invoke the program.\n";
2436 case QProcess::Crashed:
2437 txt =
"The process crashed some time after starting successfully.\n";
2439 case QProcess::Timedout:
2440 txt =
"The last waitFor...() function timed out. The state of QProcess is unchanged, and you can try calling waitFor...() again.\n";
2442 case QProcess::WriteError:
2443 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";
2445 case QProcess::ReadError:
2446 txt =
"An error occurred when attempting to read from the process. For example, the process may not be running.\n";
2448 case QProcess::UnknownError:
2449 txt =
"An unknown error occurred. This is the default return value of error().\n";
2459 QWidget *G4OpenGLQtViewer::getParentWidget()
2462 G4Qt* interactorManager = G4Qt::getInstance ();
2467 QDialog* dialog = NULL;
2469 if (((QApplication*)interactorManager->GetMainInteractor())) {
2471 QWidgetList wl = QApplication::allWidgets();
2472 QWidget *widget = NULL;
2473 for (
int i=0; i < wl.size(); i++) {
2475 if ((found==
false) && (widget->inherits(
"QMainWindow"))) {
2476 dialog =
new QDialog(widget,Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowMinMaxButtonsHint);
2482 dialog =
new QDialog();
2485 dialog=
new QDialog();
2495 void G4OpenGLQtViewer::createSceneTreeWidget() {
2496 fUISceneTreeWidget = fUiQt->GetSceneTreeWidget();
2498 if (!fUISceneTreeWidget) {
2503 QLayoutItem * wItem;
2505 if (fUISceneTreeWidget->layout()->count() ) {
2506 for(
int idx = 0;
idx < fUISceneTreeWidget->layout()->count();
idx++){
2507 wItem = fUISceneTreeWidget->layout()->itemAt(
idx);
2508 if (fSceneTreeWidget) {
2509 if(dynamic_cast<QWidget *>(wItem->widget())) {
2510 if (wItem->widget()->windowTitle() == fSceneTreeWidget->windowTitle()) {
2511 wItem->widget()->show();
2514 wItem->widget()->hide();
2518 wItem->widget()->hide();
2525 fSceneTreeWidget =
new QWidget();
2526 QVBoxLayout* layoutSceneTree =
new QVBoxLayout();
2527 fSceneTreeWidget->setStyleSheet (
"padding: 0px ");
2529 fSceneTreeWidget->setLayout(layoutSceneTree);
2530 fSceneTreeWidget->layout()->setContentsMargins(5,5,5,5);
2531 fSceneTreeWidget->setWindowTitle(QString(GetName().
data()));
2533 if (fUISceneTreeWidget != NULL) {
2534 fUISceneTreeWidget->layout()->addWidget(fSceneTreeWidget);
2538 if (dynamic_cast<G4OpenGLStoredQtViewer*> (
this)) {
2539 createSceneTreeComponent();
2545 void G4OpenGLQtViewer::createSceneTreeComponent(){
2547 QLayout* vLayout = fSceneTreeWidget->layout();
2550 QWidget* coutButtonWidget =
new QWidget();
2551 QHBoxLayout* layoutCoutTBButtons =
new QHBoxLayout();
2553 fFilterOutput =
new QLineEdit();
2554 fFilterOutput->setToolTip(
"Filter output by...");
2555 fFilterOutput->setStyleSheet (
"padding: 0px ");
2557 QPixmap* searchIcon = fUiQt->getSearchIcon();
2558 #if QT_VERSION > 0x050100
2559 fFilterOutput->addAction(*searchIcon,QLineEdit::TrailingPosition);
2560 fFilterOutput->setStyleSheet (
"border-radius:7px;");
2562 QPushButton *coutTBFilterButton =
new QPushButton();
2563 coutTBFilterButton->setIcon(*searchIcon);
2564 coutTBFilterButton->setStyleSheet (
"padding-left: 0px; border:0px;");
2565 fFilterOutput->setStyleSheet (
"padding-right: 0px;");
2567 layoutCoutTBButtons->addWidget(fFilterOutput);
2569 #if QT_VERSION <= 0x050100
2570 layoutCoutTBButtons->addWidget(coutTBFilterButton);
2573 coutButtonWidget->setLayout(layoutCoutTBButtons);
2574 vLayout->addWidget(coutButtonWidget);
2577 vLayout->setContentsMargins(0,0,0,0);
2580 fSceneTreeComponentTreeWidget =
new QTreeWidget();
2581 fSceneTreeComponentTreeWidget->setSelectionMode(QAbstractItemView::SingleSelection);
2582 fSceneTreeComponentTreeWidget->setHeaderLabel (
"Scene tree : "+QString(GetName().
data()));
2583 fSceneTreeComponentTreeWidget->setColumnHidden (1,
true);
2584 fSceneTreeComponentTreeWidget->setColumnHidden (2,
true);
2585 fSceneTreeComponentTreeWidget->setColumnHidden (3,
true);
2590 vLayout->addWidget(fSceneTreeComponentTreeWidget);
2592 connect(fSceneTreeComponentTreeWidget,SIGNAL(itemChanged(QTreeWidgetItem*,
int)),SLOT(sceneTreeComponentItemChanged(QTreeWidgetItem*,
int)));
2593 connect(fSceneTreeComponentTreeWidget,SIGNAL(itemSelectionChanged ()),SLOT(sceneTreeComponentSelected()));
2594 connect(fSceneTreeComponentTreeWidget,SIGNAL(itemDoubleClicked ( QTreeWidgetItem*,
int)),SLOT(changeColorAndTransparency( QTreeWidgetItem*,
int)));
2598 QWidget *helpWidget =
new QWidget();
2599 QHBoxLayout *helpLayout =
new QHBoxLayout();
2601 QWidget* depthWidget =
new QWidget();
2602 QWidget *showBox =
new QWidget(depthWidget);
2603 QHBoxLayout *showBoxLayout =
new QHBoxLayout();
2606 showBoxLayout->setContentsMargins(5,5,5,5);
2608 QLabel *
zero =
new QLabel();
2609 zero->setText(
"Show all");
2610 QLabel *
one =
new QLabel();
2611 one->setText(
"Hide all");
2612 fSceneTreeDepthSlider =
new QSlider ( Qt::Horizontal);
2613 fSceneTreeDepthSlider->setMaximum (1000);
2614 fSceneTreeDepthSlider->setMinimum (0);
2615 fSceneTreeDepthSlider->setTickPosition(QSlider::TicksAbove);
2617 fSceneTreeDepthSlider->setMinimumWidth (40);
2619 showBoxLayout->addWidget(zero);
2620 showBoxLayout->addWidget(fSceneTreeDepthSlider);
2621 showBoxLayout->addWidget(one);
2623 showBox->setLayout(showBoxLayout);
2625 helpLayout->addWidget(showBox);
2626 helpWidget->setLayout(helpLayout);
2627 helpLayout->setContentsMargins(0,0,0,0);
2629 vLayout->addWidget(helpWidget);
2631 connect( fSceneTreeDepthSlider, SIGNAL( valueChanged(
int) ),
this, SLOT( changeDepthInSceneTree(
int) ) );
2632 connect( fFilterOutput, SIGNAL( textEdited (
const QString &) ),
this, SLOT(changeSearchSelection()));
2633 fTreeItemModels.clear();
2635 fPVRootNodeCreate =
false;
2637 fMaxPOindexInserted = -1;
2643 void G4OpenGLQtViewer::createViewerPropertiesWidget() {
2646 fUIViewerPropertiesWidget = fUiQt->GetViewerPropertiesWidget();
2648 if (!fUIViewerPropertiesWidget) {
2653 QLayoutItem * wItem;
2654 if (fUIViewerPropertiesWidget->layout()->count()) {
2655 while ((wItem = fUIViewerPropertiesWidget->layout()->takeAt(0)) != 0) {
2656 delete wItem->widget();
2662 QGroupBox *groupBox =
new QGroupBox();
2663 groupBox->setTitle(GetName().
data());
2664 QVBoxLayout *vbox =
new QVBoxLayout;
2667 fViewerPropertiesTableWidget =
new QTableWidget();
2669 QSizePolicy vPolicy = fViewerPropertiesTableWidget->sizePolicy();
2670 vPolicy.setVerticalStretch(4);
2672 vbox->addWidget(fViewerPropertiesTableWidget);
2673 groupBox->setLayout(vbox);
2674 fUIViewerPropertiesWidget->layout()->addWidget(groupBox);
2676 connect(fViewerPropertiesTableWidget, SIGNAL(itemChanged(QTableWidgetItem*)),
this, SLOT(tableWidgetViewerSetItemChanged(QTableWidgetItem *)));
2678 updateViewerPropertiesTableWidget();
2680 QDialog* dial =
static_cast<QDialog*
> (fUIViewerPropertiesWidget->parent());
2683 dial->setWindowTitle(QString(
"Viewer properties - ")+GetName());
2688 void G4OpenGLQtViewer::createPickInfosWidget(){
2691 fUIPickInfosWidget = fUiQt->GetPickInfosWidget();
2693 if (!fUIPickInfosWidget) {
2698 QLayoutItem * wItem;
2699 if (fUIPickInfosWidget->layout()->count()) {
2700 while ((wItem = fUIPickInfosWidget->layout()->takeAt(0)) != 0) {
2701 delete wItem->widget();
2706 QGroupBox *groupBox =
new QGroupBox(
"");
2707 QVBoxLayout *vbox =
new QVBoxLayout;
2710 QWidget *pickingInfoWidget =
new QWidget();
2711 QHBoxLayout *pickingInfoLayout =
new QHBoxLayout();
2713 pickingInfoWidget->setStyleSheet (
"padding-left: 0px; border:0px;");
2714 pickingInfoWidget->setLayout(pickingInfoLayout);
2716 vbox->addWidget(pickingInfoWidget);
2719 fPickInfosScrollArea =
new QScrollArea();
2720 fPickInfosScrollArea->setWidgetResizable(
true);
2723 fPickInfosWidget =
new QWidget();
2724 fPickInfosWidget->setStyleSheet (
"padding: 0px ");
2726 QVBoxLayout* vLayout =
new QVBoxLayout();
2727 fPickInfosWidget->setLayout (vLayout);
2728 fPickInfosScrollArea->setWidget(fPickInfosWidget);
2730 QSizePolicy vPolicy = fPickInfosWidget->sizePolicy();
2731 vPolicy.setVerticalStretch(4);
2732 vbox->addWidget(fPickInfosScrollArea);
2733 pickingInfoLayout->setContentsMargins(0,0,0,0);
2734 vLayout->setContentsMargins(0,0,0,0);
2735 vbox->setContentsMargins(1,1,1,1);
2737 groupBox->setLayout(vbox);
2738 fUIPickInfosWidget->layout()->addWidget(groupBox);
2740 updatePickInfosWidget(fLastPickPoint.x(),fLastPickPoint.y());
2746 void G4OpenGLQtViewer::setCheckComponent(QTreeWidgetItem* item,
bool check)
2750 const PVPath& fullPath = fTreeItemModels[item->data(0,Qt::UserRole).toInt()];
2752 if (fullPath.size() > 0) {
2753 SetTouchable(fullPath);
2754 TouchableSetVisibility(fullPath, check);
2755 fMouseOnSceneTree =
true;
2761 item->setCheckState(0,Qt::Checked);
2763 item->setCheckState(0,Qt::Unchecked);
2765 updatePositivePoIndexSceneTreeWidgetQuickMap(item->data(0,Qt::UserRole).toInt(),item);
2766 int nChildCount = item->childCount();
2767 for (
int i = 0; i < nChildCount; i++) {
2768 setCheckComponent(item->child(i),check);
2774 void G4OpenGLQtViewer::DrawText(
const G4Text& g4text)
2776 QGLWidget* qGLW =
dynamic_cast<QGLWidget*
> (fGLWidget) ;
2780 if (isGl2psWriting()) {
2782 G4OpenGLViewer::DrawText(g4text);
2786 if (!fGLWidget)
return;
2788 #ifdef G4MULTITHREADED
2793 G4double size = fSceneHandler.GetMarkerSize(g4text,sizeType);
2795 QFont font = QFont();
2796 font.setPointSizeF(size);
2798 const G4Colour&
c = fSceneHandler.GetTextColour(g4text);
2804 const char* textCString = textString.c_str();
2806 glRasterPos3d(position.x(),position.y(),position.z());
2809 QFontMetrics* f =
new QFontMetrics (font);
2810 #if QT_VERSION > 0x050110
2811 G4double span = f->boundingRect(textCString[0]).width();
2813 G4double span = f->width(textCString);
2827 ((position.x()+(2*xmove)/getWinWidth()),
2828 (position.y()+(2*ymove)/getWinHeight()),
2837 void G4OpenGLQtViewer::ResetView () {
2838 G4OpenGLViewer::ResetView();
2848 const QString& modelShortName = getModelShortName(model);
2850 if (modelShortName ==
"") {
2854 if (fSceneTreeComponentTreeWidget == NULL) {
2855 createSceneTreeComponent();
2859 if (fSceneTreeComponentTreeWidget == NULL) {
2863 fSceneTreeComponentTreeWidget->blockSignals(
true);
2867 if (!fPVRootNodeCreate) {
2870 fModelShortNameItem = createTreeWidgetItem(pPVModel->
GetFullPVPath(),
2878 fPVRootNodeCreate =
true;
2881 bool added = parseAndInsertInSceneTree(fModelShortNameItem,pPVModel,0,modelShortName,0,currentPOIndex);
2885 fSceneTreeComponentTreeWidget->blockSignals(
false);
2894 QTreeWidgetItem* G4OpenGLQtViewer::createTreeWidgetItem(
2896 ,
const QString& name
2899 ,
const QString& logicalName
2900 ,Qt::CheckState state
2901 ,QTreeWidgetItem * parentTreeNode
2906 if (fullPath.size() > fSceneTreeDepth) {
2907 fSceneTreeDepth = fullPath.size();
2909 if (fSceneTreeDepthSlider) {
2910 fSceneTreeDepthSlider->setTickInterval(1000/(fSceneTreeDepth+1));
2913 QTreeWidgetItem * newItem = NULL;
2914 if (parentTreeNode == NULL) {
2915 newItem =
new QTreeWidgetItem();
2916 fSceneTreeComponentTreeWidget->addTopLevelItem(newItem);
2918 newItem =
new QTreeWidgetItem(parentTreeNode);
2919 fSceneTreeComponentTreeWidget->addTopLevelItem(parentTreeNode);
2923 newItem->setText(0,name);
2924 newItem->setData(1,Qt::UserRole,copyNb);
2925 newItem->setText(2,QString::number(POIndex));
2926 newItem->setData(0, Qt::UserRole, POIndex);
2927 newItem->setText(3,logicalName);
2928 newItem->setFlags(newItem->flags()|Qt::ItemIsUserCheckable);
2929 newItem->setCheckState(0,state);
2930 newItem->setExpanded(
true);
2931 updatePositivePoIndexSceneTreeWidgetQuickMap(POIndex,newItem);
2933 changeQColorForTreeWidgetItem(newItem,QColor((
int)(color.
GetRed()*255),
2939 if ((state == Qt::Unchecked) && (POIndex == -1)) {
2940 newItem->setForeground (0, QBrush(
Qt::gray) );
2943 newItem->setToolTip (0,QString(
2944 "This node exists in the geometry but has not been\n")+
2945 "drawn, perhaps because it has been set invisible. It \n"+
2946 "cannot be made visible with a click on the button.\n"+
2947 "To see it, change the visibility, for example, with \n"+
2948 "/vis/geometry/set/visibility " + logicalName +
" 0 true\n"+
2949 "and rebuild the view with /vis/viewer/rebuild.\n"+
2950 "Click here will only show/hide all child components");
2953 newItem->setToolTip (0,QString(
"double-click to change the color"));
2959 state = Qt::Unchecked;
2960 newItem->setCheckState(0,state);
2961 updatePositivePoIndexSceneTreeWidgetQuickMap(POIndex,newItem);
2964 fTreeItemModels.insert(std::pair <int, PVPath > (POIndex,fullPath) );
2968 changeOpenCloseVisibleHiddenSelectedColorSceneTreeElement(newItem);
2985 bool G4OpenGLQtViewer::parseAndInsertInSceneTree(
2986 QTreeWidgetItem * parentItem
2988 ,
unsigned int fullPathIndex
2989 ,
const QString& parentRoot
2990 ,
unsigned int currentIndexInTreeSceneHandler
2991 ,
int currentPVPOIndex
2994 if (parentItem == NULL) {
3000 std::ostringstream oss;
3001 oss << fullPath.at(fullPathIndex).GetCopyNo();
3002 std::string currentPVName =
G4String(fullPath.at(fullPathIndex).GetPhysicalVolume()->GetName()+
" ["+oss.str()+
"]").
data();
3004 int currentPVCopyNb = fullPath.at(fullPathIndex).GetCopyNo();
3014 QTreeWidgetItem* subItem = NULL;
3015 QList<QTreeWidgetItem *> parentItemList;
3023 if ((currentIndexInTreeSceneHandler == (fullPath.size()-1)) && ((color.
GetAlpha() == 1.))) {
3025 QString lookForString = QString(currentPVName.c_str());
3026 for (
int i = 0;i < parentItem->childCount(); i++ ) {
3027 if (parentItem->child(i)->text(0) == lookForString) {
3028 parentItemList.push_back(parentItem->child(i));
3033 for (
int i = 0; i < parentItemList.size(); ++i) {
3034 const std::string& parentItemName = parentItemList.at(i)->text(0).toStdString();
3035 int parentItemCopyNb = parentItemList.at(i)->data(1,Qt::UserRole).toInt();
3036 int parentItemPOIndex = parentItemList.at(i)->data(0,Qt::UserRole).toInt();
3044 if (((parentRoot == fTouchableVolumes) && (currentPVCopyNb == parentItemCopyNb)
3045 && (currentPVName == parentItemName)) ||
3047 ((parentRoot != fTouchableVolumes) && (currentPVCopyNb == parentItemCopyNb)
3049 && (currentPVName == parentItemName) && (currentPVPOIndex == parentItemPOIndex) )) {
3052 bool sameTransform =
true;
3053 if (parentItemPOIndex >= 0) {
3054 const PVPath& fullPathTmp = fTreeItemModels[parentItemPOIndex];
3055 if (fullPathTmp.size() > 0) {
3056 if (fullPathTmp.at(fullPathTmp.size()-1).GetTransform () == pPVModel->
GetTransformation ()) {
3057 sameTransform =
true;
3059 sameTransform =
false;
3065 if (sameTransform ==
true) {
3072 if (currentIndexInTreeSceneHandler == (fullPath.size()-1)) {
3074 parentItemList.at(i)->setText(2,QString::number(currentPVPOIndex));
3075 parentItemList.at(i)->setData(0, Qt::UserRole,currentPVPOIndex);
3077 fTreeItemModels.insert(std::pair <int, PVPath >(currentPVPOIndex,fullPath) );
3081 parentItemList.at(i)->setFont (0,f);
3084 parentItemList.at(i)->setForeground (0,QBrush());
3087 parentItemList.at(i)->setToolTip (0,
"");
3089 changeQColorForTreeWidgetItem(parentItemList.at(i),QColor((
int)(color.
GetRed()*255),
3096 parentItemList.at(i)->setCheckState(0,Qt::Checked);
3097 updatePositivePoIndexSceneTreeWidgetQuickMap(currentPVPOIndex,parentItemList.at(i));
3101 subItem = parentItemList.at(i);
3105 }
else if (currentIndexInTreeSceneHandler < (fullPath.size()-1)) {
3106 subItem = parentItemList.at(i);
3113 if (currentIndexInTreeSceneHandler == (fullPath.size()-1)) {
3114 createTreeWidgetItem(fullPath,
3115 QString(currentPVName.c_str()),
3118 QString(fullPath.at(fullPathIndex).GetPhysicalVolume()->GetLogicalVolume()->GetName().data()),
3123 if (currentPVPOIndex > fMaxPOindexInserted) {
3124 fMaxPOindexInserted = currentPVPOIndex;
3130 if (subItem == NULL) {
3132 if (currentIndexInTreeSceneHandler < (fullPath.size()-1)) {
3133 subItem = createTreeWidgetItem(fullPath,
3134 QString(currentPVName.c_str()),
3137 QString(fullPath.at(fullPathIndex).GetPhysicalVolume()->GetLogicalVolume()->GetName().data()),
3144 return parseAndInsertInSceneTree(subItem,pPVModel,fullPathIndex+1,parentRoot,currentIndexInTreeSceneHandler+1,currentPVPOIndex);
3150 void G4OpenGLQtViewer::changeOpenCloseVisibleHiddenSelectedColorSceneTreeElement(
3151 QTreeWidgetItem* subItem
3155 QTreeWidgetItem* oldItem = NULL;
3157 QTreeWidgetItem* foundItem = getOldTreeWidgetItem(subItem->data(0,Qt::UserRole).toInt());
3159 if (foundItem != NULL) {
3160 if (isSameSceneTreeElement(foundItem,subItem)) {
3161 oldItem = foundItem;
3164 if (foundItem == NULL) {
3167 std::map <int, QTreeWidgetItem*>::const_iterator i;
3168 i = fOldPositivePoIndexSceneTreeWidgetQuickMap.begin();
3169 while (i != fOldPositivePoIndexSceneTreeWidgetQuickMap.end()) {
3170 if (isSameSceneTreeElement(i->second,subItem)) {
3171 oldItem = i->second;
3172 i = fOldPositivePoIndexSceneTreeWidgetQuickMap.end();
3178 if (oldItem == NULL) {
3180 while (a < fOldNullPoIndexSceneTreeWidgetQuickVector.size()) {
3181 if (isSameSceneTreeElement(fOldNullPoIndexSceneTreeWidgetQuickVector[a],subItem)) {
3182 oldItem = fOldNullPoIndexSceneTreeWidgetQuickVector[
a];
3183 a = fOldNullPoIndexSceneTreeWidgetQuickVector.size();
3192 if (oldItem != NULL) {
3193 subItem->setFlags(oldItem->flags());
3194 subItem->setCheckState(0,oldItem->checkState(0));
3195 subItem->setSelected(oldItem->isSelected());
3196 subItem->setExpanded(oldItem->isExpanded ());
3201 std::map <int, QTreeWidgetItem* >::iterator
it;
3204 int oldPOIndex = oldItem->data(0,Qt::UserRole).toInt();
3205 it = fOldPositivePoIndexSceneTreeWidgetQuickMap.find(oldPOIndex);
3209 std::map <int, QColor >::iterator itVis;
3210 itVis = fOldVisAttrColorMap.find(oldPOIndex);
3212 QColor oldVisAttrColor;
3213 const QColor& newVisAttrColor = subItem->data(2,Qt::UserRole).value<QColor>();
3215 bool visAttrChange =
false;
3217 if (itVis != fOldVisAttrColorMap.end()) {
3218 oldVisAttrColor = itVis->second;
3219 if (oldVisAttrColor != newVisAttrColor) {
3220 visAttrChange =
true;
3223 visAttrChange =
true;
3226 if (visAttrChange) {
3227 fOldVisAttrColorMap.insert(std::pair <int, QColor > (subItem->data(0,Qt::UserRole).toInt(),newVisAttrColor) );
3231 if (it != fOldPositivePoIndexSceneTreeWidgetQuickMap.end()) {
3232 color = (it->second)->
data(2,Qt::UserRole).value<QColor>();
3234 color = oldItem->data(2,Qt::UserRole).value<QColor>();
3236 changeQColorForTreeWidgetItem(subItem,color);
3248 bool G4OpenGLQtViewer::isSameSceneTreeElement(
3249 QTreeWidgetItem* parentOldItem
3250 ,QTreeWidgetItem* parentNewItem
3256 int newCpNumber = -1;
3257 int oldCpNumber = -1;
3259 bool firstWhile =
true;
3261 while ((parentOldItem != NULL) && (parentNewItem != NULL)) {
3265 oldPO = parentOldItem->data(0,Qt::UserRole).toInt();
3266 newPO = parentNewItem->data(0,Qt::UserRole).toInt();
3272 const PVPath& oldFullPath = fOldTreeItemModels[oldPO];
3273 const PVPath& newFullPath = fTreeItemModels[newPO];
3274 if ((oldFullPath.size() > 0) &&
3275 (newFullPath.size() > 0)) {
3276 if (oldFullPath.size() != newFullPath.size()) {
3279 if (oldFullPath.at(oldFullPath.size()-1).GetTransform () == newFullPath.at(newFullPath.size()-1).GetTransform ()) {
3280 newCpNumber = newFullPath.at(newFullPath.size()-1).GetCopyNo();
3281 oldCpNumber = oldFullPath.at(oldFullPath.size()-1).GetCopyNo();
3290 if (oldCpNumber == -1) {
3291 oldCpNumber = parentOldItem->data(1,Qt::UserRole).toInt();
3293 if (newCpNumber == -1) {
3294 newCpNumber = parentNewItem->data(1,Qt::UserRole).toInt();
3296 if ((oldCpNumber != newCpNumber) ||
3298 (parentOldItem->text(0) != parentNewItem->text(0)) ) {
3301 }
else if ((parentOldItem->text(0) != parentNewItem->text(0)) ||
3302 (parentOldItem->text(3) != parentNewItem->text(3))) {
3305 parentOldItem = parentOldItem->parent();
3306 parentNewItem = parentNewItem->parent();
3314 void G4OpenGLQtViewer::addNonPVSceneTreeElement(
3317 ,
const std::string& modelDescription
3321 QString modelShortName = getModelShortName(model);
3327 color = fSceneHandler.GetTextColour(g4Text);
3329 catch (
const std::bad_cast&) {
3332 if (modelShortName ==
"") {
3336 if (fSceneTreeComponentTreeWidget == NULL) {
3337 createSceneTreeComponent();
3341 if (fSceneTreeComponentTreeWidget == NULL) {
3345 fSceneTreeComponentTreeWidget->blockSignals(
true);
3349 QList<QTreeWidgetItem *> resItem;
3350 resItem = fSceneTreeComponentTreeWidget->findItems (modelShortName, Qt::MatchExactly, 0 );
3351 QTreeWidgetItem * currentItem = NULL;
3352 const PVPath tmpFullPath;
3354 if (resItem.empty()) {
3355 currentItem = createTreeWidgetItem(tmpFullPath,
3364 currentItem = resItem.first();
3368 const QList<QTreeWidgetItem *>&
3369 resItems = fSceneTreeComponentTreeWidget->findItems (QString(modelDescription.c_str()), Qt::MatchFixedString| Qt::MatchCaseSensitive|Qt::MatchRecursive, 0 );
3371 bool alreadyPresent =
false;
3372 for (
int i = 0; i < resItems.size(); ++i) {
3373 if (currentPOIndex == resItems.at(i)->data(0,Qt::UserRole).toInt()) {
3374 alreadyPresent =
true;
3377 if (!alreadyPresent) {
3378 createTreeWidgetItem(tmpFullPath,
3379 QString(modelDescription.c_str()),
3387 fSceneTreeComponentTreeWidget->blockSignals(
false);
3395 QString G4OpenGLQtViewer::getModelShortName(
const G4String& model) {
3397 QString modelShortName = model.
data();
3398 if (modelShortName.mid(0,modelShortName.indexOf(
" ")) ==
"G4PhysicalVolumeModel") {
3399 modelShortName = fTouchableVolumes;
3401 if (modelShortName.mid(0,2) ==
"G4") {
3402 modelShortName = modelShortName.mid(2);
3404 if (modelShortName.indexOf(
"Model") != -1) {
3405 modelShortName = modelShortName.mid(0,modelShortName.indexOf(
"Model"));
3408 return modelShortName;
3413 bool G4OpenGLQtViewer::isTouchableVisible(
int POindex){
3416 if (fSceneTreeComponentTreeWidget == NULL) {
3422 if (fLastSceneTreeWidgetAskForIterator != fLastSceneTreeWidgetAskForIteratorEnd) {
3423 fLastSceneTreeWidgetAskForIterator++;
3425 QTreeWidgetItem* item = getTreeWidgetItem(POindex);
3428 if ( item->checkState(0) == Qt::Checked) {
3436 bool G4OpenGLQtViewer::parseAndCheckVisibility(QTreeWidgetItem * treeNode,
int POindex){
3437 bool isFound =
false;
3438 for (
int i = 0; i < treeNode->childCount() ; ++i) {
3440 if (treeNode->child(i)->data(0,Qt::UserRole).toInt() == POindex) {
3441 if (treeNode->child(i)->checkState(0) == Qt::Checked) {
3445 isFound = parseAndCheckVisibility(treeNode->child(i),POindex);
3454 std::string G4OpenGLQtViewer::parseSceneTreeAndSaveState(){
3455 std::string commandLine =
"";
3456 for (
int b=0;
b<fSceneTreeComponentTreeWidget->topLevelItemCount();
b++) {
3457 commandLine += parseSceneTreeElementAndSaveState(fSceneTreeComponentTreeWidget->topLevelItem(
b),1)+
"\n";
3459 if (commandLine !=
"") {
3460 commandLine = std::string(
"# Disable auto refresh and quieten vis messages whilst scene and\n") +
3461 "# trajectories are established:\n" +
3462 "/vis/viewer/set/autoRefresh false\n" +
3463 "/vis/verbose errors" +
3465 "# Re-establish auto refreshing and verbosity:\n" +
3466 "/vis/viewer/set/autoRefresh true\n" +
3467 "/vis/verbose confirmations\n";
3473 std::string G4OpenGLQtViewer::parseSceneTreeElementAndSaveState(QTreeWidgetItem* item,
unsigned int level){
3475 std::string str( level,
' ' );
3476 std::string commandLine =
"\n#"+ str +
"PV Name: " + item->text(0).toStdString();
3478 if (item->text(3) !=
"") {
3479 commandLine +=
" LV Name: "+item->text(3).toStdString()+
"\n";
3481 commandLine +=
"/vis/geometry/set/visibility " + item->text(3).toStdString() +
" ! ";
3482 if (item->checkState(0) == Qt::Checked) {
3485 if (item->checkState(0) == Qt::Unchecked) {
3491 const QColor& c = item->data(2,Qt::UserRole).value<QColor>();
3492 std::stringstream red;
3493 red << ((double)c.red())/255;
3494 std::stringstream green;
3495 green << (double)c.
green()/255;
3496 std::stringstream blue;
3497 blue << ((double)c.blue())/255;
3498 std::stringstream
alpha;
3499 alpha << ((double)c.alpha())/255;
3501 commandLine +=
"/vis/geometry/set/colour " + item->text(3).toStdString() +
" ! " + red.str() +
" " + green.str() +
" " + blue.str() +
" " + alpha.str()+
"\n";
3504 commandLine +=
"\n";
3508 for (
int b=0;
b< item->childCount();
b++) {
3509 commandLine += parseSceneTreeElementAndSaveState(item->child(
b),level+1);
3516 void G4OpenGLQtViewer::sceneTreeComponentItemChanged(QTreeWidgetItem* item,
int) {
3518 if (fCheckSceneTreeComponentSignalLock ==
false) {
3519 fCheckSceneTreeComponentSignalLock =
true;
3521 if (item->checkState(0) == Qt::Checked) {
3524 setCheckComponent(item,checked);
3527 fCheckSceneTreeComponentSignalLock =
false;
3532 void G4OpenGLQtViewer::sceneTreeComponentSelected() {
3535 void G4OpenGLQtViewer::changeDepthInSceneTree (
int val){
3538 if (fSceneTreeComponentTreeWidget == NULL) {
3549 double depth = 1 + ((double)val)/1000 * ((double)fSceneTreeDepth+1);
3552 fCheckSceneTreeComponentSignalLock =
true;
3555 G4bool currentAutoRefresh = fVP.IsAutoRefresh();
3556 fVP.SetAutoRefresh(
false);
3558 for (
int b=0;
b<fSceneTreeComponentTreeWidget->topLevelItemCount();
b++) {
3559 changeDepthOnSceneTreeItem(depth,1.,fSceneTreeComponentTreeWidget->topLevelItem(
b));
3563 fVP.SetAutoRefresh(currentAutoRefresh);
3567 fCheckSceneTreeComponentSignalLock =
false;
3572 void G4OpenGLQtViewer::changeColorAndTransparency(QTreeWidgetItem* item,
int) {
3577 const QColor& old = QColor(item->data(2,Qt::UserRole).value<QColor>());
3579 #if QT_VERSION < 0x040500
3581 const QColor& color = QColor(QColorDialog::getRgba (old.rgba(),&
a,fSceneTreeComponentTreeWidget));
3583 const QColor& color = QColorDialog::getColor(old,
3584 fSceneTreeComponentTreeWidget,
3585 " Get color and transparency",
3586 QColorDialog::ShowAlphaChannel);
3589 if (color.isValid()) {
3591 changeColorAndTransparency(item->data(0,Qt::UserRole).toInt(),
3598 changeQColorForTreeWidgetItem(item,color);
3603 void G4OpenGLQtViewer::changeColorAndTransparency(GLuint index,
G4Color color) {
3607 if (iPO >= 0 && fTreeItemModels.find(iPO) != fTreeItemModels.end()) {
3608 const PVPath& fullPath = fTreeItemModels[iPO];
3610 if (fullPath.size()) {
3611 SetTouchable(fullPath);
3612 TouchableSetColour(fullPath, color);
3613 fMouseOnSceneTree =
true;
3619 G4Colour G4OpenGLQtViewer::getColorForPoIndex(
int poIndex) {
3621 QTreeWidgetItem* item = getTreeWidgetItem(poIndex);
3625 const QColor& color = item->data(2,Qt::UserRole).value<QColor>();
3638 G4OpenGLQtViewer::GetPrivateVisAttributesModifiers()
const
3640 static std::vector<G4ModelingParameters::VisAttributesModifier>
3641 privateVisAttributesModifiers;
3643 privateVisAttributesModifiers.clear();
3696 return &privateVisAttributesModifiers;
3700 void G4OpenGLQtViewer::changeSearchSelection()
3702 const QString& searchText = fFilterOutput->text();
3703 if (fSceneTreeComponentTreeWidget == NULL) {
3708 for (
int a=0; a<fSceneTreeComponentTreeWidget->topLevelItemCount(); a++) {
3709 fSceneTreeComponentTreeWidget->topLevelItem(a)->setExpanded(
false);
3710 fSceneTreeComponentTreeWidget->topLevelItem(a)->setSelected(
false);
3711 clearSceneTreeSelection(fSceneTreeComponentTreeWidget->topLevelItem(a));
3714 QList<QTreeWidgetItem *> itemList = fSceneTreeComponentTreeWidget->findItems (searchText,Qt::MatchContains | Qt::MatchRecursive,0);
3716 for (
int i = 0; i < itemList.size(); ++i) {
3717 QTreeWidgetItem* expandParentItem = itemList.at(i);
3718 while (expandParentItem->parent() != NULL) {
3719 expandParentItem->parent()->setExpanded(
true);
3720 expandParentItem = expandParentItem->parent();
3722 itemList.at(i)->setSelected(
true);
3728 void G4OpenGLQtViewer::clearSceneTreeSelection(QTreeWidgetItem* item) {
3729 for (
int a=0; a<item->childCount(); a++) {
3730 item->child(a)->setSelected(
false);
3731 item->child(a)->setExpanded(
false);
3732 clearSceneTreeSelection(item->child(a));
3738 bool G4OpenGLQtViewer::isPVVolume(QTreeWidgetItem* item) {
3739 QTreeWidgetItem* sParent = item;
3740 while (sParent->parent() != NULL) {
3741 sParent = sParent->parent();
3743 if (sParent->text(0) != fTouchableVolumes) {
3747 if (item->text(0) == fTouchableVolumes) {
3754 void G4OpenGLQtViewer::changeDepthOnSceneTreeItem(
3756 ,
double currentDepth
3757 ,QTreeWidgetItem* item
3759 double transparencyLevel = 0.;
3764 if (isPVVolume(item)) {
3765 if ((lookForDepth-currentDepth) < 0) {
3766 item->setCheckState(0,Qt::Checked);
3767 updatePositivePoIndexSceneTreeWidgetQuickMap(item->data(0,Qt::UserRole).toInt(),item);
3768 transparencyLevel = 1;
3769 }
else if ((lookForDepth-currentDepth) > 1 ){
3770 item->setCheckState(0,Qt::Unchecked);
3771 updatePositivePoIndexSceneTreeWidgetQuickMap(item->data(0,Qt::UserRole).toInt(),item);
3772 transparencyLevel = 0;
3774 item->setCheckState(0,Qt::Checked);
3775 updatePositivePoIndexSceneTreeWidgetQuickMap(item->data(0,Qt::UserRole).toInt(),item);
3776 transparencyLevel = 1-(lookForDepth-currentDepth);
3780 if (item->data(0,Qt::UserRole).toInt() >= 0) {
3781 const G4Colour& color = getColorForPoIndex(item->data(0,Qt::UserRole).toInt());
3793 if (((color.
GetAlpha()-transparencyLevel) > 0.000001) ||
3794 ((color.
GetAlpha()-transparencyLevel) < -0.000001)) {
3795 if ((item->text(3) !=
"")) {
3801 changeQColorForTreeWidgetItem(item,QColor((
int)(color.
GetRed()*255),
3804 (
int)(transparencyLevel*255)));
3809 for (
int b=0;
b< item->childCount();
b++) {
3810 changeDepthOnSceneTreeItem(lookForDepth,currentDepth+1,item->child(
b));
3815 void G4OpenGLQtViewer::clearTreeWidget(){
3818 if (fSceneTreeComponentTreeWidget) {
3820 if (fSceneTreeComponentTreeWidget->topLevelItemCount () > 0) {
3822 fPVRootNodeCreate =
false;
3825 fOldPositivePoIndexSceneTreeWidgetQuickMap.clear();
3826 fOldNullPoIndexSceneTreeWidgetQuickVector.clear();
3827 fOldTreeItemModels.clear();
3830 for (
int b =0;
b <fSceneTreeComponentTreeWidget->topLevelItemCount();
b++) {
3839 int poIndex = fSceneTreeComponentTreeWidget->topLevelItem(
b)->data(0,Qt::UserRole).toInt();
3840 if (poIndex != -1) {
3841 fOldPositivePoIndexSceneTreeWidgetQuickMap.insert(std::pair <int, QTreeWidgetItem*> (poIndex,cloneWidgetItem(fSceneTreeComponentTreeWidget->topLevelItem(
b))));
3843 fOldNullPoIndexSceneTreeWidgetQuickVector.push_back(cloneWidgetItem(fSceneTreeComponentTreeWidget->topLevelItem(
b)));
3847 cloneSceneTree(fSceneTreeComponentTreeWidget->topLevelItem(
b));
3851 fOldTreeItemModels.insert(fTreeItemModels.begin(), fTreeItemModels.end());
3854 int tmp2 = fSceneTreeComponentTreeWidget->topLevelItemCount();
3856 delete fSceneTreeComponentTreeWidget->takeTopLevelItem (0);
3857 tmp2 = fSceneTreeComponentTreeWidget->topLevelItemCount();
3859 fPositivePoIndexSceneTreeWidgetQuickMap.clear();
3862 fOldLastSceneTreeWidgetAskForIterator = fOldPositivePoIndexSceneTreeWidgetQuickMap.begin();
3863 fOldLastSceneTreeWidgetAskForIteratorEnd = fOldPositivePoIndexSceneTreeWidgetQuickMap.end();
3864 fSceneTreeDepth = 1;
3865 fModelShortNameItem = NULL;
3866 fMaxPOindexInserted = -1;
3879 QTreeWidgetItem * G4OpenGLQtViewer::cloneWidgetItem(QTreeWidgetItem* item) {
3881 QTreeWidgetItem* cloneItem =
new QTreeWidgetItem();
3885 cloneItem->setText(0,item->text(0));
3886 cloneItem->setData(1,Qt::UserRole,item->data(1,Qt::UserRole).toInt());
3887 cloneItem->setText(2,item->text(2));
3888 cloneItem->setData(0, Qt::UserRole,item->data(0,Qt::UserRole).toInt());
3889 cloneItem->setText(3,item->text(3));
3890 cloneItem->setFlags(item->flags());
3891 cloneItem->setToolTip(0,item->toolTip(0));
3892 cloneItem->setCheckState(0,item->checkState(0));
3893 cloneItem->setSelected(item->isSelected());
3894 cloneItem->setExpanded(item->isExpanded ());
3896 cloneItem->setData(2,Qt::UserRole,item->data(2,Qt::UserRole).value<QColor>());
3905 void G4OpenGLQtViewer::cloneSceneTree(
3906 QTreeWidgetItem* rootItem
3909 for (
int b=0;
b< rootItem->childCount();
b++) {
3911 QTreeWidgetItem *child = rootItem->child(
b);
3914 int poIndex = child->data(0,Qt::UserRole).toInt();
3915 if (poIndex != -1) {
3916 fOldPositivePoIndexSceneTreeWidgetQuickMap.insert(std::pair <int, QTreeWidgetItem*> (poIndex,cloneWidgetItem(child)));
3918 fOldNullPoIndexSceneTreeWidgetQuickVector.push_back(cloneWidgetItem(child));
3920 cloneSceneTree(child);
3928 void G4OpenGLQtViewer::updatePositivePoIndexSceneTreeWidgetQuickMap(
int POindex,QTreeWidgetItem* item) {
3931 std::map <int, QTreeWidgetItem*>::iterator i;
3932 i = fPositivePoIndexSceneTreeWidgetQuickMap.find(POindex);
3934 if (i == fPositivePoIndexSceneTreeWidgetQuickMap.end()) {
3935 fPositivePoIndexSceneTreeWidgetQuickMap.insert(std::pair <int, QTreeWidgetItem*> (POindex,item) );
3936 fLastSceneTreeWidgetAskForIterator = fPositivePoIndexSceneTreeWidgetQuickMap.end();
3937 fLastSceneTreeWidgetAskForIteratorEnd = fPositivePoIndexSceneTreeWidgetQuickMap.end();
3945 void G4OpenGLQtViewer::changeQColorForTreeWidgetItem(QTreeWidgetItem* item,
const QColor& qc) {
3947 int POIndex = item->data(0,Qt::UserRole).toInt();
3948 updatePositivePoIndexSceneTreeWidgetQuickMap(POIndex,item );
3950 QPixmap pixmap = QPixmap(QSize(16, 16));
3951 if (item->data(0,Qt::UserRole).toInt() != -1) {
3954 pixmap.fill (QColor(255,255,255,255));
3956 QPainter painter(&pixmap);
3957 painter.setPen(Qt::black);
3958 painter.drawRect(0,0,15,15);
3960 item->setIcon(0,pixmap);
3961 item->setData(2,Qt::UserRole,qc);
3970 QTreeWidgetItem* G4OpenGLQtViewer::getTreeWidgetItem(
int POindex){
3973 if (POindex == -1) {
3977 if (fPositivePoIndexSceneTreeWidgetQuickMap.size() == 0){
3981 if (fLastSceneTreeWidgetAskForIterator != fLastSceneTreeWidgetAskForIteratorEnd) {
3982 if (POindex == fLastSceneTreeWidgetAskForIterator->first) {
3983 if (fLastSceneTreeWidgetAskForIterator->second != NULL) {
3984 return fLastSceneTreeWidgetAskForIterator->second;
3990 fLastSceneTreeWidgetAskForIterator = fPositivePoIndexSceneTreeWidgetQuickMap.find(POindex);
3991 fLastSceneTreeWidgetAskForIteratorEnd = fPositivePoIndexSceneTreeWidgetQuickMap.end();
3993 if (fLastSceneTreeWidgetAskForIterator != fPositivePoIndexSceneTreeWidgetQuickMap.end()) {
3994 return fLastSceneTreeWidgetAskForIterator->second;
4003 QTreeWidgetItem* G4OpenGLQtViewer::getOldTreeWidgetItem(
int POindex){
4007 if (POindex == -1) {
4011 if (fOldPositivePoIndexSceneTreeWidgetQuickMap.size() == 0){
4017 if (fOldLastSceneTreeWidgetAskForIterator != fOldLastSceneTreeWidgetAskForIteratorEnd) {
4018 fOldLastSceneTreeWidgetAskForIterator++;
4021 if (fOldLastSceneTreeWidgetAskForIterator != fOldPositivePoIndexSceneTreeWidgetQuickMap.end()) {
4022 if (POindex == fOldLastSceneTreeWidgetAskForIterator->first) {
4023 if (fOldLastSceneTreeWidgetAskForIterator->second != NULL) {
4024 return fOldLastSceneTreeWidgetAskForIterator->second;
4030 fOldLastSceneTreeWidgetAskForIterator = fOldPositivePoIndexSceneTreeWidgetQuickMap.find(POindex);
4031 fOldLastSceneTreeWidgetAskForIteratorEnd = fOldPositivePoIndexSceneTreeWidgetQuickMap.end();
4033 if (fOldLastSceneTreeWidgetAskForIterator != fOldPositivePoIndexSceneTreeWidgetQuickMap.end()) {
4034 return fOldLastSceneTreeWidgetAskForIterator->second;
4045 void G4OpenGLQtViewer::displaySceneTreeComponent() {
4047 if (fUISceneTreeWidget == NULL) {
4050 if (fSceneTreeComponentTreeWidget == NULL) {
4055 fSceneTreeComponentTreeWidget->sortItems (0, Qt::AscendingOrder );
4067 void G4OpenGLQtViewer::updateToolbarAndMouseContextMenu(){
4073 d_style = fVP.GetDrawingStyle();
4077 if (fUiQt) fUiQt->SetIconWireframeSelected();
4079 fDrawingWireframe->setChecked(
true);
4080 fDrawingLineRemoval->setChecked(
false);
4081 fDrawingSurfaceRemoval->setChecked(
false);
4082 fDrawingLineSurfaceRemoval->setChecked(
false);
4085 if (fUiQt) fUiQt->SetIconHLRSelected();
4087 fDrawingLineRemoval->setChecked(
true);
4088 fDrawingWireframe->setChecked(
false);
4089 fDrawingSurfaceRemoval->setChecked(
false);
4090 fDrawingLineSurfaceRemoval->setChecked(
false);
4093 if (fUiQt) fUiQt->SetIconSolidSelected();
4095 fDrawingSurfaceRemoval->setChecked(
true);
4096 fDrawingWireframe->setChecked(
false);
4097 fDrawingLineRemoval->setChecked(
false);
4098 fDrawingLineSurfaceRemoval->setChecked(
false);
4101 if (fUiQt) fUiQt->SetIconHLHSRSelected();
4103 fDrawingLineSurfaceRemoval->setChecked(
true);
4104 fDrawingWireframe->setChecked(
false);
4105 fDrawingLineRemoval->setChecked(
false);
4106 fDrawingSurfaceRemoval->setChecked(
false);
4107 fDrawingLineSurfaceRemoval->setChecked(
false);
4113 G4double d_proj = fVP.GetFieldHalfAngle () ;
4115 if (fUiQt) fUiQt->SetIconOrthoSelected();
4117 fProjectionOrtho->setChecked(
true);
4118 fProjectionPerspective->setChecked(
false);
4121 if (fUiQt) fUiQt->SetIconPerspectiveSelected();
4123 fProjectionPerspective->setChecked(
true);
4124 fProjectionOrtho->setChecked(
false);
4130 if (fUiQt && fContextMenu) {
4131 if (fUiQt->IsIconPickSelected()) {
4132 fMousePickAction->setChecked(
true);
4133 fMouseZoomOutAction->setChecked(
false);
4134 fMouseZoomInAction->setChecked(
false);
4135 fMouseRotateAction->setChecked(
false);
4136 fMouseMoveAction->setChecked(
false);
4137 }
else if (fUiQt->IsIconZoomOutSelected()) {
4138 fMouseZoomOutAction->setChecked(
true);
4139 fMousePickAction->setChecked(
false);
4140 fMouseZoomInAction->setChecked(
false);
4141 fMouseRotateAction->setChecked(
false);
4142 fMouseMoveAction->setChecked(
false);
4143 }
else if (fUiQt->IsIconZoomInSelected()) {
4144 fMouseZoomInAction->setChecked(
true);
4145 fMousePickAction->setChecked(
false);
4146 fMouseZoomOutAction->setChecked(
false);
4147 fMouseRotateAction->setChecked(
false);
4148 fMouseMoveAction->setChecked(
false);
4149 }
else if (fUiQt->IsIconRotateSelected()) {
4150 fMouseRotateAction->setChecked(
true);
4151 fMousePickAction->setChecked(
false);
4152 fMouseZoomOutAction->setChecked(
false);
4153 fMouseZoomInAction->setChecked(
false);
4154 fMouseMoveAction->setChecked(
false);
4155 }
else if (fUiQt->IsIconMoveSelected()) {
4156 fMouseMoveAction->setChecked(
true);
4157 fMousePickAction->setChecked(
false);
4158 fMouseZoomOutAction->setChecked(
false);
4159 fMouseZoomInAction->setChecked(
false);
4160 fMouseRotateAction->setChecked(
false);
4168 void G4OpenGLQtViewer::updateSceneTreeWidget() {
4170 if (!fSceneTreeWidget) {
4171 createSceneTreeWidget();
4180 void G4OpenGLQtViewer::updateViewerPropertiesTableWidget() {
4182 if (!isCurrentWidget()) {
4187 if (!fViewerPropertiesTableWidget) {
4188 createViewerPropertiesWidget();
4190 int treeWidgetInfosIgnoredCommands = 0;
4200 if ((path->
GetCommandEntry()-fTreeWidgetInfosIgnoredCommands) != fViewerPropertiesTableWidget->rowCount()) {
4201 fViewerPropertiesTableWidget->clear();
4204 fViewerPropertiesTableWidget->blockSignals(
true);
4207 fViewerPropertiesTableWidget->setColumnCount (2);
4208 fViewerPropertiesTableWidget->setRowCount (path->
GetCommandEntry()-fTreeWidgetInfosIgnoredCommands);
4209 fViewerPropertiesTableWidget->setHorizontalHeaderLabels(QStringList() << tr(
"Property")
4211 fViewerPropertiesTableWidget->verticalHeader()->setVisible(
false);
4212 fViewerPropertiesTableWidget->setAlternatingRowColors (
true);
4220 QString params =
"";
4223 if (fVP.IsAutoRefresh()) {
4229 if (fVP.IsAuxEdgeVisible()) {
4235 params = QString().number(fVP.GetBackgroundColour().GetRed()) +
" "+
4236 QString().number(fVP.GetBackgroundColour().GetGreen()) +
" "+
4237 QString().number(fVP.GetBackgroundColour().GetBlue()) +
" "+
4238 QString().number(fVP.GetBackgroundColour().GetAlpha());
4241 params = QString().number(fVP. IsCulling ());
4246 params =
"intersection";
4250 params = QString().number(fVP.GetDefaultVisAttributes()->GetColor().GetRed()) +
" "+
4251 QString().number(fVP.GetDefaultVisAttributes()->GetColor().GetGreen()) +
" "+
4252 QString().number(fVP.GetDefaultVisAttributes()->GetColor().GetBlue()) +
" "+
4253 QString().number(fVP.GetDefaultVisAttributes()->GetColor().GetAlpha());
4256 params = QString().number(fVP.GetDefaultTextVisAttributes()->GetColor().GetRed()) +
" "+
4257 QString().number(fVP.GetDefaultTextVisAttributes()->GetColor().GetGreen()) +
" "+
4258 QString().number(fVP.GetDefaultTextVisAttributes()->GetColor().GetBlue()) +
" "+
4259 QString().number(fVP.GetDefaultTextVisAttributes()->GetColor().GetAlpha());
4269 params = QString().number(fVP.GetExplodeFactor()) +
" " + QString(
G4String(
G4BestUnit(fVP.GetExplodeFactor(),
"Length")).
data());
4271 }
else if(commandTmp->
GetCommandName() ==
"globalLineWidthScale") {
4272 params = QString().number(fVP.GetGlobalLineWidthScale());
4275 params = QString().number(fVP.GetGlobalMarkerScale());
4287 if (fVP.IsMarkerNotHidden()) {
4294 if (fVP.GetLightsMoveWithCamera()) {
4300 G4Vector3D direction = fVP.GetLightpointDirection();
4309 params = QString().number(fVP.GetLightpointDirection().x()) +
" "+
4310 QString().number(fVP.GetLightpointDirection().y()) +
" "+
4311 QString().number(fVP.GetLightpointDirection().z());
4313 }
else if(commandTmp->
GetCommandName() ==
"lineSegmentsPerCircle") {
4314 params = QString().number(fVP.GetNoOfSides());
4317 if (fVP.IsPicking()) {
4324 if (fVP.GetFieldHalfAngle() == 0.) {
4325 params =
"orthogonal";
4327 params = QString(
"perspective ") + QString().number(fVP.GetFieldHalfAngle()/
CLHEP::degree) +
" deg";
4332 params =
"constrainUpDirection";
4334 params =
"freeRotation";
4338 if (fVP.IsSection()) {
4339 params = QString(
"on ") +
4341 QString().number(fVP.GetSectionPlane().normal().x())
4342 +
" " + QString().number(fVP.GetSectionPlane().normal().y())
4343 +
" " + QString().number(fVP.GetSectionPlane().normal().z());
4350 params =
"wireframe";
4358 if (fSceneHandler.GetScene()) {
4359 G4String b =
G4BestUnit(fSceneHandler.GetScene()->GetStandardTargetPoint() + fVP.GetCurrentTargetPoint(),
"Length");
4373 params = QString().number(up.
x())+
" "+ QString().number(up.
y())+
" "+QString().number(up.
z())+
" ";
4376 G4Vector3D direction = fVP.GetViewpointDirection();
4385 G4Vector3D direction = fVP.GetViewpointDirection();
4386 params = QString().number(direction.
x())+
" "+ QString().number(direction.
y())+
" "+QString().number(direction.
z());
4416 QTableWidgetItem *nameItem;
4417 QTableWidgetItem *paramItem;
4420 QList<QTableWidgetItem *> list = fViewerPropertiesTableWidget->findItems (commandTmp->
GetCommandName().
data(),Qt::MatchExactly);
4421 if (list.size() == 1) {
4422 nameItem = list.first();
4423 paramItem = fViewerPropertiesTableWidget->item(nameItem->row(),1);
4426 nameItem =
new QTableWidgetItem();
4427 paramItem =
new QTableWidgetItem();
4428 fViewerPropertiesTableWidget->setItem(a-treeWidgetInfosIgnoredCommands, 0, nameItem);
4429 fViewerPropertiesTableWidget->setItem(a-treeWidgetInfosIgnoredCommands, 1, paramItem);
4434 for(
G4int i_thGuidance=0; i_thGuidance < n_guidanceEntry; i_thGuidance++ ) {
4438 nameItem->setToolTip(guidance);
4439 paramItem->setToolTip(GetCommandParameterList(commandTmp));
4441 fViewerPropertiesTableWidget->setRowHeight(a-treeWidgetInfosIgnoredCommands,15);
4446 paramItem->setText(params);
4448 nameItem->setFlags(Qt::NoItemFlags);
4449 nameItem->setForeground(QBrush());
4452 treeWidgetInfosIgnoredCommands++;
4456 for (
int i=0; i<treeWidgetInfosIgnoredCommands; i++) {
4457 fViewerPropertiesTableWidget->removeRow (fViewerPropertiesTableWidget->rowCount() - 1);
4461 if (!fViewerPropertiesTableWidgetIsInit) {
4462 fViewerPropertiesTableWidgetIsInit =
true;
4464 fViewerPropertiesTableWidget->resizeColumnsToContents();
4466 int x = fViewerPropertiesTableWidget->horizontalHeader()->length();
4467 int y = fViewerPropertiesTableWidget->verticalHeader()->length()+ fViewerPropertiesTableWidget->horizontalHeader()->sizeHint().height() + 2;
4473 QDialog* dial =
static_cast<QDialog*
> (fUIViewerPropertiesWidget->parent());
4475 dial->resize(x+56,y+46);
4478 fViewerPropertiesTableWidget->blockSignals(
false);
4480 fTreeWidgetInfosIgnoredCommands = treeWidgetInfosIgnoredCommands;
4487 void G4OpenGLQtViewer::updatePickInfosWidget(
int aX,
int aY) {
4488 fLastPickPoint = QPoint(aX,aY);
4490 if (!isCurrentWidget()) {
4494 if (!fPickInfosWidget) {
4495 createPickInfosWidget();
4498 const std::vector < G4OpenGLViewerPickMap* > & pickMapVector = GetPickDetails(aX,aY);
4501 if (fPickInfosWidget) {
4502 QLayoutItem * wItem;
4503 if (fPickInfosWidget->layout()->count()) {
4504 while ((wItem = fPickInfosWidget->layout()->takeAt(0)) != 0) {
4505 delete wItem->widget();
4511 if (!fPickInfosWidget) {
4512 createPickInfosWidget();
4517 #if QT_VERSION < 0x050600
4518 delete fSignalMapperPicking;
4519 fSignalMapperPicking =
new QSignalMapper(
this);
4523 G4int nPickedObjectsWithAttributes = 0;
4524 for (
unsigned int a=0; a< pickMapVector.size(); a++) {
4525 const auto& pickMap = pickMapVector[
a];
4527 std::ostringstream label;
4528 std::ostringstream content;
4529 std::string txt = pickMap->getAttributes()[0].data();
4530 if (pickMapVector[a]->getAttributes().size()) {
4531 ++nPickedObjectsWithAttributes;
4533 std::size_t pos1 = txt.find(
':');
4534 std::string storeKey = txt.substr(0,pos1);
4536 if (storeKey ==
"G4PhysicalVolumeModel") {
4539 std::size_t pos2 = txt.find(
':',pos1+1);
4540 std::size_t pos3 = txt.find(
'\n',pos2+1);
4541 label << txt.substr(pos2+1,pos3-pos2-1);
4543 }
else if (storeKey ==
"G4TrajectoriesModel") {
4545 label <<
"Trajectory:";
4546 std::size_t pos2 = txt.find(
':',pos1+1);
4547 std::size_t pos3 = txt.find(
'\n',pos2+1);
4548 label <<
" Run:" << txt.substr(pos2+1,pos3-pos2-1);
4549 std::size_t pos4 = txt.find(
':',pos3+1);
4550 std::size_t pos5 = txt.find(
'\n',pos4+1);
4551 label <<
", Event:" << txt.substr(pos4+1,pos5-pos4-1);
4555 label <<
"Hit number:" << a <<
", PickName: " << pickMap->getPickName();
4560 content << pickMap->print().data();
4561 G4int thisPickName = pickMap->getPickName();
4562 while (++a < pickMapVector.size()) {
4563 const auto& a_pickMap = pickMapVector[
a];
4564 if (a_pickMap->getPickName() == thisPickName) {
4565 content << a_pickMap->print().data();
4572 QPushButton* pickCoutButton =
new QPushButton(label.str().c_str());
4573 pickCoutButton->setStyleSheet (
"text-align: left; padding: 1px; border: 0px;");
4574 pickCoutButton->setIcon(*fTreeIconClosed);
4575 fPickInfosWidget->layout()->addWidget(pickCoutButton);
4580 newStr = QStringList(QString(content.str().c_str()).trimmed());
4582 QTextEdit* ed =
new QTextEdit();
4583 ed->setReadOnly(
true);
4584 fPickInfosWidget->layout()->addWidget(ed);
4585 ed->setVisible((
false));
4586 ed->append(newStr.join(
""));
4588 #if QT_VERSION < 0x050600
4589 connect(pickCoutButton, SIGNAL(clicked()), fSignalMapperPicking, SLOT(map()));
4590 fSignalMapperPicking->setMapping(pickCoutButton,fPickInfosWidget->layout()->count()-1);
4592 std::cout << pickCoutButton->text().toStdString() <<
" "<< fPickInfosWidget->layout()->count()-1<< std::endl;
4593 int tmp = fPickInfosWidget->layout()->count()-1;
4594 connect(pickCoutButton, &QPushButton::clicked , [=](){ this->toggleSceneTreeComponentPickingCout(tmp);});
4598 #if QT_VERSION < 0x050600
4599 connect(fSignalMapperPicking, SIGNAL(mapped(
int)),
this, SLOT(toggleSceneTreeComponentPickingCout(
int)));
4603 QLabel * pushUp =
new QLabel(
"");
4604 QSizePolicy vPolicy = QSizePolicy(QSizePolicy::Minimum,QSizePolicy::Minimum);
4605 vPolicy.setVerticalStretch(10);
4606 pushUp->setSizePolicy(vPolicy);
4607 fPickInfosWidget->layout()->addWidget(pushUp);
4612 changeColorAndTransparency(fLastHighlightName,fLastHighlightColor);
4614 if (pickMapVector.size() > 0 ) {
4616 fLastHighlightName = pickMapVector[0]->getPickName();
4617 fLastHighlightColor = getColorForPoIndex(fLastHighlightName);
4619 changeColorAndTransparency(fLastHighlightName,
G4Color(1,1,1,1));
4623 QDialog* dial =
static_cast<QDialog*
> (fUIPickInfosWidget->parent());
4626 std::ostringstream oss;
4627 if (nPickedObjectsWithAttributes == 0) {
4629 }
else if (nPickedObjectsWithAttributes == 1) {
4632 oss << nPickedObjectsWithAttributes <<
" objects";
4634 oss <<
" selected - " << GetName();
4635 dial->setWindowTitle(oss.str().c_str());
4638 fPickInfosScrollArea->setVisible(
true);
4642 void G4OpenGLQtViewer::toggleSceneTreeComponentPickingCout(
int pickItem) {
4647 for (
int a=0; a<fPickInfosWidget->layout()->count(); a++) {
4648 w = fPickInfosWidget->layout()->itemAt(a)->widget();
4649 QTextEdit* ed =
dynamic_cast<QTextEdit*
>(
w);
4650 QPushButton* button;
4652 if (a == pickItem) {
4653 w->setVisible(!w->isVisible());
4655 w->setVisible(
false);
4658 button =
dynamic_cast<QPushButton*
>(fPickInfosWidget->layout()->itemAt(a-1)->widget());
4660 if (button->isVisible()) {
4661 button->setIcon(*fTreeIconOpen);
4663 button->setIcon(*fTreeIconClosed);
4672 void G4OpenGLQtViewer::currentTabActivated(
int currentTab) {
4673 if (fUiQt->GetViewerTabWidget()->tabText(currentTab) == GetName()) {
4674 createViewerPropertiesWidget();
4675 createPickInfosWidget();
4676 createSceneTreeWidget();
4681 void G4OpenGLQtViewer::tableWidgetViewerSetItemChanged(QTableWidgetItem * item) {
4684 QTableWidgetItem* previous = fViewerPropertiesTableWidget->item(fViewerPropertiesTableWidget->row(item),0);
4686 fViewerPropertiesTableWidget->blockSignals(
true);
4688 + previous->text().toStdString()
4690 + item->text().toStdString()).c_str());
4691 fViewerPropertiesTableWidget->blockSignals(
false);
4696 bool G4OpenGLQtViewer::isCurrentWidget(){
4697 G4Qt* interactorManager = G4Qt::getInstance ();
4698 if (!interactorManager->IsExternalApp()) {
4701 if ( GetName() != fUiQt->GetViewerTabWidget()->tabText(fUiQt->GetViewerTabWidget()->currentIndex()).toStdString().c_str()) {
4715 QString G4OpenGLQtViewer::GetCommandParameterList (
4722 if( n_parameterEntry > 0 ) {
4727 for(
G4int i_thParameter=0; i_thParameter<n_parameterEntry; i_thParameter++ ) {
4732 txt +=
" Parameter type : " + QString(QChar(param->
GetParameterType())) +
"\n";
4734 txt +=
" Omittable : True\n";
4736 txt +=
" Omittable : False\n";
4739 txt +=
" Default value : taken from the current value\n";
4754 #ifdef G4MULTITHREADED
4756 void G4OpenGLQtViewer::DoneWithMasterThread()
4762 if(!lWaitForVisSubThreadQtOpenGLContextInitialized->owns_lock())
4763 lWaitForVisSubThreadQtOpenGLContextInitialized->lock();
4766 void G4OpenGLQtViewer::SwitchToVisSubThread()
4770 QGLWidget* qGLW =
dynamic_cast<QGLWidget*
> (fGLWidget) ;
4776 SetQGLContextVisSubThread(QThread::currentThread());
4782 if(!lWaitForVisSubThreadQtOpenGLContextMoved->owns_lock())
4783 lWaitForVisSubThreadQtOpenGLContextMoved->lock();
4787 lWaitForVisSubThreadQtOpenGLContextMoved);
4790 qGLW->makeCurrent();
4793 void G4OpenGLQtViewer::DoneWithVisSubThread()
4796 QGLWidget* qGLW =
dynamic_cast<QGLWidget*
> (fGLWidget) ;
4802 qGLW->doneCurrent();
4804 #if QT_VERSION > 0x050000
4806 qGLW->context()->moveToThread(fQGLContextMainThread);
4810 void G4OpenGLQtViewer::SwitchToMasterThread()
4814 QGLWidget* qGLW =
dynamic_cast<QGLWidget*
> (fGLWidget) ;
4821 if(lWaitForVisSubThreadQtOpenGLContextInitialized->owns_lock())
4822 lWaitForVisSubThreadQtOpenGLContextInitialized->unlock();
4824 qGLW->makeCurrent();
4828 void G4OpenGLQtViewer::MovingToVisSubThread(){
4831 QGLWidget* qGLW =
dynamic_cast<QGLWidget*
> (fGLWidget) ;
4838 if(!lWaitForVisSubThreadQtOpenGLContextInitialized->owns_lock())
4839 lWaitForVisSubThreadQtOpenGLContextInitialized->lock();
4843 lWaitForVisSubThreadQtOpenGLContextInitialized);
4846 SetQGLContextMainThread(QThread::currentThread());
4849 qGLW->doneCurrent();
4850 #if QT_VERSION > 0x050000
4851 qGLW->context()->moveToThread(fQGLContextVisSubThread);