36 #ifdef G4VIS_BUILD_OPENGLQT_DRIVER
56 #include <CLHEP/Units/SystemOfUnits.h>
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 #include <qsignalmapper.h>
87 #include <qmainwindow.h>
88 #include <qtablewidget.h>
89 #include <qheaderview.h>
90 #include <qscrollarea.h>
91 #include <qsplitter.h>
92 #include <qcheckbox.h>
96 void G4OpenGLQtViewer::CreateMainWindow (
104 if(fGLWidget)
return;
106 fGLWidget = glWidget ;
109 G4Qt* interactorManager = G4Qt::getInstance ();
111 ResizeWindow(fVP.GetWindowSizeHintX(),fVP.GetWindowSizeHintY());
123 if (UI == NULL)
return;
125 if (! static_cast<G4UIQt*> (UI->GetG4UIWindow())) {
130 fUiQt =
static_cast<G4UIQt*
> (UI->GetG4UIWindow());
132 bool isTabbedView =
false;
135 if (!interactorManager->IsExternalApp()) {
137 fWinSize_x = fVP.GetWindowSizeHintX();
138 fWinSize_y = fVP.GetWindowSizeHintY();
140 isTabbedView = fUiQt->AddTabWidget((QWidget*)fGLWidget,name);
142 fUISceneTreeComponentsTBWidget = fUiQt->GetSceneTreeComponentsTBWidget();
145 fUiQt->GetViewersWidget()->setCurrentWidget(fUISceneTreeComponentsTBWidget);
148 fSceneTreeWidget =
new QWidget();
149 QVBoxLayout* layoutSceneTree =
new QVBoxLayout();
150 fSceneTreeWidget->setStyleSheet (
"padding: 0px ");
152 fSceneTreeWidget->setLayout(layoutSceneTree);
153 fSceneTreeWidget->layout()->setContentsMargins(5,5,5,5);
155 if (fUISceneTreeComponentsTBWidget != NULL) {
156 fUISceneTreeComponentsTBWidget->addTab(fSceneTreeWidget,QString(GetName().data()));
160 if (dynamic_cast<G4OpenGLStoredQtViewer*> (
this)) {
161 initSceneTreeComponent();
162 toggleSceneTreeViewerInfos();
165 initViewerPropertiesComponent();
166 initPickingComponent();
169 toggleSceneTreeComponentTreeWidgetInfos();
172 #ifdef G4DEBUG_VIS_OGL
174 printf(
"G4OpenGLQtViewer::CreateMainWindow :: UIQt NOt found \n");
180 QWidget *glDialogWidget = getParentWidget();
181 #ifdef G4DEBUG_VIS_OGL
182 printf(
"G4OpenGLQtViewer::CreateMainWindow :: getParent OK \n");
184 if (glDialogWidget != NULL) {
185 glWidget->setParent(glDialogWidget);
187 QHBoxLayout *mainLayout =
new QHBoxLayout();
189 mainLayout->setMargin(0);
190 mainLayout->setSpacing(0);
191 mainLayout->addWidget(fGLWidget);
192 if (fGLWidget->inherits(
"QMainWindow")) {
193 fGLWidget->setWindowTitle( name);
195 glDialogWidget->setLayout(mainLayout);
199 int offset = QApplication::desktop()->height()
200 - QApplication::desktop()->availableGeometry().height();
202 G4int YPos= fVP.GetWindowAbsoluteLocationHintY(QApplication::desktop()->height());
203 if (fVP.GetWindowAbsoluteLocationHintY(QApplication::desktop()->height())< offset) {
206 glDialogWidget->resize(getWinWidth(), getWinHeight());
207 #ifdef G4DEBUG_VIS_OGL
208 printf(
"G4OpenGLQtViewer::CreateMainWindow :: resizing to %d %d \n",getWinWidth(), getWinHeight());
210 glDialogWidget->move(fVP.GetWindowAbsoluteLocationHintX(QApplication::desktop()->width()),YPos);
211 glDialogWidget->show();
214 if(!fGLWidget)
return;
223 G4OpenGLQtViewer::G4OpenGLQtViewer (
224 G4OpenGLSceneHandler& scene
227 ,G4OpenGLViewer (scene)
229 ,fRecordFrameNumber(0)
233 ,fHoldKeyEvent(false)
234 ,fHoldMoveEvent(false)
235 ,fHoldRotateEvent(false)
239 ,fMovieTempFolderPath(
"")
241 ,fParameterFileName(
"ppmtompeg_encode_parameter_file.par")
242 ,fMovieParametersDialog(NULL)
243 ,fRecordingStep(WAIT)
245 ,fNbMaxFramesPerSec(100)
246 ,fNbMaxAnglePerSec(360)
247 ,fLaunchSpinDelay(100)
248 ,fUISceneTreeComponentsTBWidget(NULL)
251 ,fControlKeyPress(false)
252 ,fShiftKeyPress(false)
254 ,fCheckSceneTreeComponentSignalLock(false)
255 ,fSceneTreeComponentTreeWidget(NULL)
256 ,fOldSceneTreeComponentTreeWidget(NULL)
257 ,fSceneTreeWidget(NULL)
258 ,fPVRootNodeCreate(false)
260 ,fViewerPropertiesButton(NULL)
263 ,fTouchableVolumes(
"Touchables")
264 ,fShortcutsDialog(NULL)
265 ,fSceneTreeComponentTreeWidgetInfos(NULL)
266 ,fSceneTreeComponentPickingInfos(NULL)
267 ,fSceneTreeComponentPickingScrollArea(NULL)
268 ,fTreeWidgetInfosIgnoredCommands(0)
269 ,fSceneTreeDepthSlider(NULL)
271 ,fModelShortNameItem(NULL)
272 ,fMaxPOindexInserted(-1)
274 ,fSignalMapperMouse(NULL)
275 ,fSignalMapperSurface(NULL)
276 ,fSignalMapperPicking(NULL)
278 ,fTreeIconClosed(NULL)
279 ,fLastExportSliderValue(80)
280 ,fLastHighlightColor(
G4Color(0,0,0,0))
281 ,fLastHighlightName(0)
289 G4Qt::getInstance ();
291 fLastPos3 = QPoint(-1,-1);
292 fLastPos2 = QPoint(-1,-1);
293 fLastPos1 = QPoint(-1,-1);
295 initMovieParameters();
297 fLastEventTime =
new QTime();
298 fSignalMapperMouse =
new QSignalMapper(
this);
299 fSignalMapperSurface =
new QSignalMapper(
this);
302 fFileSavePath = QDir::currentPath();
305 QList<QByteArray> formats = QImageWriter::supportedImageFormats ();
306 for (
int i = 0; i < formats.size(); ++i) {
307 addExportImageFormat(formats.at(i).data());
310 const char *
const icon1[]={
368 const char *
const icon2[]={
461 const char *
const search[] = {
473 "OOOOOOOOOOOOOOOOOOO",
474 "OOOOOOOOOOOOOOOOOOO",
475 "OOOOOOOo. .oOOOOOO",
478 "OOOOO. XOOOOX .OOOO",
481 "OOOOO. XOOOOo .OOOO",
485 "OOOOOOOOOOOOO. XOO",
486 "OOOOOOOOOOOOOO. XOO",
487 "OOOOOOOOOOOOOOOoOOO",
488 "OOOOOOOOOOOOOOOOOOO",
489 "OOOOOOOOOOOOOOOOOOO",
490 "OOOOOOOOOOOOOOOOOOO",
491 "OOOOOOOOOOOOOOOOOOO"
494 fSearchIcon =
new QPixmap(search);
495 fTreeIconOpen =
new QPixmap(icon1);
496 fTreeIconClosed =
new QPixmap(icon2);
498 #ifdef G4DEBUG_VIS_OGL
499 printf(
"G4OpenGLQtViewer::G4OpenGLQtViewer END\n");
504 G4OpenGLQtViewer::~G4OpenGLQtViewer (
514 if (fSceneTreeWidget != NULL) {
515 if (fSceneTreeWidget->layout() != NULL) {
516 while ((wItem = fSceneTreeWidget->layout()->takeAt(0)) != 0) {
517 delete wItem->widget();
521 if (fUISceneTreeComponentsTBWidget != NULL) {
522 fUISceneTreeComponentsTBWidget->removeTab(fUISceneTreeComponentsTBWidget->indexOf(fSceneTreeWidget));
527 delete fTreeIconOpen;
528 delete fTreeIconClosed;
530 G4cout <<removeTempFolder().toStdString().c_str() <<
G4endl;
537 void G4OpenGLQtViewer::createPopupMenu() {
539 fContextMenu =
new QMenu(
"All");
541 QMenu *mMouseAction = fContextMenu->addMenu(
"&Mouse actions");
543 fMouseRotateAction = mMouseAction->addAction(
"Rotate", fSignalMapperMouse, SLOT(map()));
544 fMouseMoveAction = mMouseAction->addAction(
"Move", fSignalMapperMouse, SLOT(map()));
545 fMousePickAction = mMouseAction->addAction(
"Pick", fSignalMapperMouse, SLOT(map()));
546 fMouseZoomOutAction = mMouseAction->addAction(
"Zoom out", fSignalMapperMouse, SLOT(map()));
547 fMouseZoomInAction = mMouseAction->addAction(
"Zoom in", fSignalMapperMouse, SLOT(map()));
548 QAction *shortcutsAction = mMouseAction->addAction(
"Show shortcuts");
550 fMouseRotateAction->setCheckable(
true);
551 fMouseMoveAction->setCheckable(
true);
552 fMousePickAction->setCheckable(
true);
553 fMouseZoomOutAction->setCheckable(
true);
554 fMouseZoomInAction->setCheckable(
true);
555 shortcutsAction->setCheckable(
false);
557 connect(fSignalMapperMouse, SIGNAL(mapped(
int)),
this, SLOT(toggleMouseAction(
int)));
558 fSignalMapperMouse->setMapping(fMouseRotateAction,1);
559 fSignalMapperMouse->setMapping(fMouseMoveAction,2);
560 fSignalMapperMouse->setMapping(fMousePickAction,3);
561 fSignalMapperMouse->setMapping(fMouseZoomOutAction,4);
562 fSignalMapperMouse->setMapping(fMouseZoomInAction,5);
564 QObject::connect(shortcutsAction,
565 SIGNAL(triggered(
bool)),
567 SLOT(showShortcuts()));
570 QMenu *mStyle = fContextMenu->addMenu(
"&Style");
572 QMenu *mProjection = mStyle->addMenu(
"&Projection");
574 fProjectionOrtho = mProjection->addAction(
"Orthographic", fSignalMapperSurface, SLOT(map()));
575 fProjectionPerspective = mProjection->addAction(
"Persepective", fSignalMapperSurface, SLOT(map()));
578 if (fVP.GetFieldHalfAngle() == 0) {
579 createRadioAction(fProjectionOrtho, fProjectionPerspective,SLOT(toggleProjection(
bool)),1);
581 createRadioAction(fProjectionOrtho, fProjectionPerspective,SLOT(toggleProjection(
bool)),2);
585 QMenu *mDrawing = mStyle->addMenu(
"&Drawing");
587 fDrawingWireframe = mDrawing->addAction(
"Wireframe", fSignalMapperSurface, SLOT(map()));
589 fDrawingLineRemoval = mDrawing->addAction(
"Hidden line removal", fSignalMapperSurface, SLOT(map()));
591 fDrawingSurfaceRemoval = mDrawing->addAction(
"Hidden Surface removal", fSignalMapperSurface, SLOT(map()));
593 fDrawingLineSurfaceRemoval = mDrawing->addAction(
"Hidden line and surface removal", fSignalMapperSurface, SLOT(map()));
595 fDrawingWireframe->setCheckable(
true);
596 fDrawingLineRemoval->setCheckable(
true);
597 fDrawingSurfaceRemoval->setCheckable(
true);
598 fDrawingLineSurfaceRemoval->setCheckable(
true);
600 connect(fSignalMapperSurface, SIGNAL(mapped(
int)),
this, SLOT(toggleSurfaceAction(
int)));
601 fSignalMapperSurface->setMapping(fDrawingWireframe,1);
602 fSignalMapperSurface->setMapping(fDrawingLineRemoval,2);
603 fSignalMapperSurface->setMapping(fDrawingSurfaceRemoval,3);
604 fSignalMapperSurface->setMapping(fDrawingLineSurfaceRemoval,4);
609 QAction *backgroundColorChooser ;
611 backgroundColorChooser = mStyle->addAction(
"Background color");
612 QObject ::connect(backgroundColorChooser,
615 SLOT(actionChangeBackgroundColor()));
619 QAction *textColorChooser ;
621 textColorChooser = mStyle->addAction(
"Text color");
622 QObject ::connect(textColorChooser,
625 SLOT(actionChangeTextColor()));
629 QAction *defaultColorChooser ;
631 defaultColorChooser = mStyle->addAction(
"Default color");
632 QObject ::connect(defaultColorChooser,
635 SLOT(actionChangeDefaultColor()));
639 QMenu *mActions = fContextMenu->addMenu(
"&Actions");
640 QAction *createEPS = mActions->addAction(
"Save as ...");
641 QObject ::connect(createEPS,
644 SLOT(actionSaveImage()));
647 QAction *movieParameters = mActions->addAction(
"Save as movie...");
648 QObject ::connect(movieParameters,
651 SLOT(actionMovieParameters()));
657 QMenu *mSpecial = fContextMenu->addMenu(
"S&pecial");
658 QMenu *mTransparency = mSpecial->addMenu(
"Transparency");
659 QAction *transparencyOn = mTransparency->addAction(
"On");
660 QAction *transparencyOff = mTransparency->addAction(
"Off");
662 if (transparency_enabled ==
false) {
663 createRadioAction(transparencyOn,transparencyOff,SLOT(toggleTransparency(
bool)),2);
664 }
else if (transparency_enabled ==
true) {
665 createRadioAction(transparencyOn,transparencyOff,SLOT(toggleTransparency(
bool)),1);
671 QMenu *mAntialiasing = mSpecial->addMenu(
"Antialiasing");
672 QAction *antialiasingOn = mAntialiasing->addAction(
"On");
673 QAction *antialiasingOff = mAntialiasing->addAction(
"Off");
675 if (antialiasing_enabled ==
false) {
676 createRadioAction(antialiasingOn,antialiasingOff,SLOT(toggleAntialiasing(
bool)),2);
677 }
else if (antialiasing_enabled ==
true) {
678 createRadioAction(antialiasingOn,antialiasingOff,SLOT(toggleAntialiasing(
bool)),1);
680 mAntialiasing->clear();
683 QMenu *mHaloing = mSpecial->addMenu(
"Haloing");
684 QAction *haloingOn = mHaloing->addAction(
"On");
685 QAction *haloingOff = mHaloing->addAction(
"Off");
686 if (haloing_enabled ==
false) {
687 createRadioAction(haloingOn,haloingOff,SLOT(toggleHaloing(
bool)),2);
688 }
else if (haloing_enabled ==
true) {
689 createRadioAction(haloingOn,haloingOff,SLOT(toggleHaloing(
bool)),1);
694 QMenu *mAux = mSpecial->addMenu(
"Auxiliary edges");
695 QAction *auxOn = mAux->addAction(
"On");
696 QAction *auxOff = mAux->addAction(
"Off");
697 if (!fVP.IsAuxEdgeVisible()) {
698 createRadioAction(auxOn,auxOff,SLOT(toggleAux(
bool)),2);
700 createRadioAction(auxOn,auxOff,SLOT(toggleAux(
bool)),1);
704 QMenu *mHiddenMarkers = mSpecial->addMenu(
"Hidden markers");
705 QAction *hiddenMarkersOn = mHiddenMarkers->addAction(
"On");
706 QAction *hiddenMarkersOff = mHiddenMarkers->addAction(
"Off");
707 if (fVP.IsMarkerNotHidden()) {
708 createRadioAction(hiddenMarkersOn,hiddenMarkersOff,SLOT(toggleHiddenMarkers(
bool)),2);
710 createRadioAction(hiddenMarkersOn,hiddenMarkersOff,SLOT(toggleHiddenMarkers(
bool)),1);
715 QMenu *mFullScreen = mSpecial->addMenu(
"&Full screen");
716 fFullScreenOn = mFullScreen->addAction(
"On");
717 fFullScreenOff = mFullScreen->addAction(
"Off");
718 createRadioAction(fFullScreenOn,fFullScreenOff,SLOT(toggleFullScreen(
bool)),2);
721 updateToolbarAndMouseContextMenu();
724 void G4OpenGLQtViewer::G4manageContextMenuEvent(QContextMenuEvent *e)
727 G4cerr <<
"Visualization window not defined, please choose one before" <<
G4endl;
734 if ( fContextMenu ) {
735 fContextMenu->exec( e->globalPos() );
751 void G4OpenGLQtViewer::createRadioAction(QAction *action1,QAction *action2,
const std::string& method,
unsigned int nCheck) {
753 action1->setCheckable(
true);
754 action2->setCheckable(
true);
757 action1->setChecked (
true);
759 action2->setChecked (
true);
761 QObject ::connect(action1, SIGNAL(triggered(
bool)),action2, SLOT(toggle()));
762 QObject ::connect(action2, SIGNAL(triggered(
bool)),action1, SLOT(toggle()));
764 QObject ::connect(action1, SIGNAL(toggled(
bool)),
this, method.c_str());
773 void G4OpenGLQtViewer::showShortcuts() {
776 text =
"========= Mouse Shortcuts =========\n";
778 if (fUiQt->IsIconRotateSelected()) {
779 text +=
"Click and move mouse to rotate volume \n";
780 text +=
"ALT + Click and move mouse to rotate volume (Toggle View/Theta-Phi Direction) \n";
781 text +=
"CTRL + Click and move mouse to zoom in/out \n";
782 text +=
"SHIFT + Click and move mouse to change camera point of view \n";
783 }
else if (fUiQt->IsIconMoveSelected()) {
784 text +=
"Move camera point of view with mouse \n";
785 }
else if (fUiQt->IsIconPickSelected()) {
786 text +=
"Click and pick \n";
789 text +=
"Click and move mouse to rotate volume \n";
790 text +=
"ALT + Click and move mouse to rotate volume (Toggle View/Theta-Phi Direction) \n";
791 text +=
"CTRL + Click and zoom mouse to zoom in/out \n";
792 text +=
"SHIFT + Click and zoommove camera point of view \n";
794 text +=
"========= Move Shortcuts ========= \n";
795 text +=
"Press left/right arrows to move volume left/right \n";
796 text +=
"Press up/down arrows to move volume up/down \n";
797 text +=
"Press '+'/'-' to move volume toward/forward \n";
799 text +=
"========= Rotation (Theta/Phi) Shortcuts ========= \n";
800 text +=
"Press SHIFT + left/right arrows to rotate volume left/right \n";
801 text +=
"Press SHIFT + up/down arrows to rotate volume up/down \n";
803 text +=
"========= Rotation (View Direction) Shortcuts ========= \n";
804 text +=
"Press ALT + left/right to rotate volume around vertical direction \n";
805 text +=
"Press ALT + up/down to rotate volume around horizontal direction \n";
807 text +=
"========= Zoom View ========= \n";
808 text +=
"Press CTRL + '+'/'-' to zoom into volume \n";
810 text +=
"========= Misc ========= \n";
811 text +=
"Press ALT +/- to slow/speed rotation/move \n";
812 text +=
"Press H to reset view \n";
813 text +=
"Press Esc to exit FullScreen \n";
815 text +=
"========= Video ========= \n";
816 text +=
"In video mode : \n";
817 text +=
" Press SPACE to Start/Pause video recording \n";
818 text +=
" Press RETURN to Stop video recording \n";
823 if ( fShortcutsDialog == NULL) {
824 fShortcutsDialog =
new QDialog();
825 fShortcutsDialogInfos =
new QTextEdit() ;
826 QVBoxLayout *mainLayout =
new QVBoxLayout;
827 mainLayout->addWidget(fShortcutsDialogInfos);
828 fShortcutsDialog->setLayout(mainLayout);
829 fShortcutsDialog->setWindowTitle(tr(
"Shortcuts"));
832 fShortcutsDialogInfos->setPlainText(text.data());
833 fShortcutsDialog->show();
844 void G4OpenGLQtViewer::toggleMouseAction(
int aAction) {
847 fUiQt->SetIconRotateSelected();
848 }
else if (aAction == 2) {
849 fUiQt->SetIconMoveSelected();
850 }
else if (aAction == 3) {
852 }
else if (aAction == 4) {
853 fUiQt->SetIconZoomOutSelected();
854 }
else if (aAction == 5) {
855 fUiQt->SetIconZoomInSelected();
859 updateToolbarAndMouseContextMenu();
873 void G4OpenGLQtViewer::toggleSurfaceAction(
int aAction) {
880 }
else if (aAction ==2) {
883 }
else if (aAction ==3) {
886 }
else if (aAction ==4) {
889 fVP.SetDrawingStyle(d_style);
891 updateToolbarAndMouseContextMenu();
906 void G4OpenGLQtViewer::toggleProjection(
bool check) {
909 fVP.SetOrthogonalProjection ();
911 fVP.SetPerspectiveProjection();
913 updateToolbarAndMouseContextMenu();
922 void G4OpenGLQtViewer::toggleTransparency(
bool check) {
925 transparency_enabled =
true;
927 transparency_enabled =
false;
929 SetNeedKernelVisit (
true);
930 updateToolbarAndMouseContextMenu();
938 void G4OpenGLQtViewer::toggleAntialiasing(
bool check) {
941 antialiasing_enabled =
false;
942 glDisable (GL_LINE_SMOOTH);
943 glDisable (GL_POLYGON_SMOOTH);
945 antialiasing_enabled =
true;
946 glEnable (GL_LINE_SMOOTH);
947 glHint (GL_LINE_SMOOTH_HINT, GL_NICEST);
948 glEnable (GL_POLYGON_SMOOTH);
949 glHint (GL_POLYGON_SMOOTH_HINT, GL_NICEST);
952 updateToolbarAndMouseContextMenu();
961 void G4OpenGLQtViewer::toggleHaloing(
bool check) {
963 haloing_enabled =
false;
965 haloing_enabled =
true;
968 updateToolbarAndMouseContextMenu();
977 void G4OpenGLQtViewer::toggleAux(
bool check) {
979 fVP.SetAuxEdgeVisible(
true);
981 fVP.SetAuxEdgeVisible(
false);
983 SetNeedKernelVisit (
true);
984 updateToolbarAndMouseContextMenu();
989 void G4OpenGLQtViewer::togglePicking() {
992 if (!fVP.IsPicking()) {
993 fUiQt->SetIconPickSelected();
995 fUiQt->SetIconRotateSelected();
1001 if (!fVP.IsPicking()) {
1002 UI->
ApplyCommand(std::string(
"/vis/viewer/set/picking true"));
1004 UI->
ApplyCommand(std::string(
"/vis/viewer/set/picking false"));
1015 void G4OpenGLQtViewer::toggleHiddenMarkers(
bool check) {
1017 fVP.SetMarkerHidden();
1019 fVP.SetMarkerNotHidden();
1022 updateToolbarAndMouseContextMenu();
1029 void G4OpenGLQtViewer::toggleFullScreen(
bool check) {
1030 if (check != fGLWidget->isFullScreen()) {
1031 fGLWidget->setWindowState(fGLWidget->windowState() ^ Qt::WindowFullScreen);
1036 void G4OpenGLQtViewer::savePPMToTemp() {
1037 if (fMovieTempFolderPath ==
"") {
1040 QGLWidget* qGLW =
dynamic_cast<QGLWidget*
> (fGLWidget) ;
1044 QString fileName =
"Test"+QString::number(fRecordFrameNumber)+
".ppm";
1045 QString filePath =fMovieTempFolderPath+fileName;
1048 image = qGLW->grabFrameBuffer();
1051 res = image.save(filePath,0);
1054 setRecordingInfos(
"Can't save tmp file "+filePath);
1058 setRecordingInfos(
"File "+fileName+
" saved");
1059 fRecordFrameNumber++;
1064 void G4OpenGLQtViewer::actionSaveImage() {
1066 for (
unsigned int i = 0; i < fExportImageFormatVector.size(); ++i) {
1067 filters += QString(
"*.") + fExportImageFormatVector.at(i).c_str() +
";;";
1070 QString* selectedFormat =
new QString(fDefaultExportImageFormat.c_str());
1072 qFilename = QFileDialog::getSaveFileName ( fGLWidget,
1079 std::string name = qFilename.toStdString().c_str();
1086 fFileSavePath = QFileInfo(qFilename).path();
1088 std::string format = selectedFormat->toLower().toStdString().c_str();
1091 fExportImageFormat = format.substr(format.find_last_of(
".") + 1);
1093 std::string filename =
name;
1094 std::string extension =
"";
1095 if (name.find_last_of(
".") != std::string::npos) {
1096 filename = name.substr(0,name.find_last_of(
".") + 1);
1097 extension = name.substr(name.find_last_of(
".") + 1);
1099 extension = fExportImageFormat;
1102 filename+=
"."+ extension;
1104 if (!setExportFilename(filename.c_str(),0)) {
1108 G4OpenGLQtExportDialog* exportDialog=
new G4OpenGLQtExportDialog(fGLWidget,format.c_str(),fGLWidget->height(),fGLWidget->width());
1109 if( exportDialog->exec()) {
1111 if ((exportDialog->getWidth() !=fGLWidget->width()) ||
1112 (exportDialog->getHeight() !=fGLWidget->height())) {
1113 setExportSize(exportDialog->getWidth(),exportDialog->getHeight());
1116 if (fExportImageFormat ==
"eps") {
1117 fVectoredPs = exportDialog->getVectorEPS();
1118 }
else if (fExportImageFormat ==
"ps") {
1121 fLastExportSliderValue = exportDialog->getSliderValue();
1123 if (exportImage(filename +
"." + fExportImageFormat)) {
1125 fDefaultExportImageFormat = format;
1134 void G4OpenGLQtViewer::actionChangeBackgroundColor() {
1142 #if QT_VERSION < 0x040500
1144 const QColor color = QColor(QColorDialog::getRgba (QColor(Qt::black).rgba(),&a,fGLWidget));
1146 const QColor color =
1147 QColorDialog::getColor(Qt::black,
1149 " Get background color and transparency",
1150 QColorDialog::ShowAlphaChannel);
1152 if (color.isValid()) {
1157 fVP.SetBackgroundColour(colour);
1159 updateToolbarAndMouseContextMenu();
1164 void G4OpenGLQtViewer::actionChangeTextColor() {
1166 #if QT_VERSION < 0x040500
1168 const QColor color = QColor(QColorDialog::getRgba (QColor(
Qt::yellow).rgba(),&a,fGLWidget));
1170 const QColor& color =
1173 " Get text color and transparency",
1174 QColorDialog::ShowAlphaChannel);
1176 if (color.isValid()) {
1182 fVP.SetDefaultTextColour(colour);
1184 updateToolbarAndMouseContextMenu();
1189 void G4OpenGLQtViewer::actionChangeDefaultColor() {
1191 #if QT_VERSION < 0x040500
1193 const QColor color = QColor(QColorDialog::getRgba (QColor(Qt::white).rgba(),&a,fGLWidget));
1195 const QColor& color =
1196 QColorDialog::getColor(Qt::white,
1198 " Get default color and transparency",
1199 QColorDialog::ShowAlphaChannel);
1201 if (color.isValid()) {
1207 fVP.SetDefaultColour(colour);
1209 updateToolbarAndMouseContextMenu();
1215 void G4OpenGLQtViewer::actionMovieParameters() {
1216 showMovieParametersDialog();
1220 void G4OpenGLQtViewer::showMovieParametersDialog() {
1221 if (!fMovieParametersDialog) {
1222 fMovieParametersDialog=
new G4OpenGLQtMovieDialog(
this,fGLWidget);
1223 displayRecordingStatus();
1224 fMovieParametersDialog->checkEncoderSwParameters();
1225 fMovieParametersDialog->checkSaveFileNameParameters();
1226 fMovieParametersDialog->checkTempFolderParameters();
1227 if (getEncoderPath() ==
"") {
1228 setRecordingInfos(
"ppmtompeg is needed to encode in video format. It is available here: http://netpbm.sourceforge.net ");
1231 fMovieParametersDialog->show();
1236 void G4OpenGLQtViewer::FinishView()
1252 void G4OpenGLQtViewer::G4MousePressEvent(QMouseEvent *evnt)
1254 if (evnt->button() == Qt::RightButton) {
1257 if ((evnt->button() & Qt::LeftButton) && (! (evnt->modifiers() & Qt::ControlModifier ))){
1258 fGLWidget->setMouseTracking(
true);
1260 fLastPos1 = evnt->pos();
1261 fLastPos2 = fLastPos1;
1262 fLastPos3 = fLastPos2;
1263 fLastEventTime->start();
1264 if (fUiQt != NULL) {
1266 if (fUiQt->IsIconZoomInSelected()) {
1269 float deltaX = ((float)getWinWidth()/2-evnt->pos().x());
1270 float deltaY = ((float)getWinHeight()/2-evnt->pos().y());
1274 if (getWinHeight() <getWinWidth()) {
1277 fVP.IncrementPan(-deltaX*coefTrans,deltaY*coefTrans,0);
1278 fVP.SetZoomFactor(1.5 * fVP.GetZoomFactor());
1282 }
else if (fUiQt->IsIconZoomOutSelected()) {
1284 moveScene(((
float)getWinWidth()/2-evnt->pos().x()),((
float)getWinHeight()/2-evnt->
pos().y()),0,true);
1286 fVP.SetZoomFactor(0.75 * fVP.GetZoomFactor());
1289 } else if (fUiQt->IsIconRotateSelected() ) {
1291 if (fShiftKeyPress) {
1292 fGLWidget->setCursor(QCursor(Qt::SizeAllCursor));
1295 fGLWidget->setCursor(QCursor(Qt::ClosedHandCursor));
1297 }
else if (fUiQt->IsIconMoveSelected()) {
1298 fGLWidget->setCursor(QCursor(Qt::SizeAllCursor));
1299 }
else if (fUiQt->IsIconPickSelected()) {
1300 fGLWidget->setCursor(QCursor(Qt::PointingHandCursor));
1308 void G4OpenGLQtViewer::G4MouseReleaseEvent(QMouseEvent *evnt)
1310 fSpinningDelay = fLastEventTime->elapsed();
1311 QPoint delta = (fLastPos3-fLastPos1);
1314 fGLWidget->setCursor(QCursor(Qt::ArrowCursor));
1316 if (fVP.IsPicking()){
1317 if ((delta.x() != 0) || (delta.y() != 0)) {
1320 std::vector < G4OpenGLViewerPickMap* > pickMap = GetPickDetails(evnt->pos().x(),evnt->pos().y());
1323 QLayoutItem * wItem;
1324 while ((wItem = fSceneTreeComponentPickingInfos->layout()->takeAt(0)) != 0) {
1325 delete wItem->widget();
1330 delete fSignalMapperPicking;
1331 fSignalMapperPicking =
new QSignalMapper(
this);
1334 for (
unsigned int a=0; a< pickMap.size(); a++) {
1336 std::ostringstream label;
1337 label <<
"Hit number:" << a <<
", PickName: " << pickMap[
a]->getPickName();
1339 QPushButton* pickCoutButton =
new QPushButton(label.str().c_str());
1340 pickCoutButton->setStyleSheet (
"text-align: left; padding: 1px; border: 0px;");
1341 pickCoutButton->setIcon(*fTreeIconClosed);
1342 fSceneTreeComponentPickingInfos->layout()->addWidget(pickCoutButton);
1347 newStr = QStringList(QString(pickMap[a]->
print().data()).trimmed());
1349 QTextEdit* ed =
new QTextEdit();
1350 ed->setFontFamily(
"Courier");
1351 ed->setFontPointSize(12);
1352 ed->setReadOnly(
true);
1353 fSceneTreeComponentPickingInfos->layout()->addWidget(ed);
1354 ed->setVisible((
false));
1355 ed->append(newStr.join(
""));
1357 connect(pickCoutButton, SIGNAL(clicked()), fSignalMapperPicking, SLOT(map()));
1358 fSignalMapperPicking->setMapping(pickCoutButton,fSceneTreeComponentPickingInfos->layout()->count()-1);
1361 connect(fSignalMapperPicking, SIGNAL(mapped(
int)),
this, SLOT(toggleSceneTreeComponentPickingCout(
int)));
1364 QLabel * pushUp =
new QLabel(
"");
1365 QSizePolicy vPolicy = QSizePolicy(QSizePolicy::Minimum,QSizePolicy::Minimum);
1366 vPolicy.setVerticalStretch(10);
1367 pushUp->setSizePolicy(vPolicy);
1368 fSceneTreeComponentPickingInfos->layout()->addWidget(pushUp);
1373 changeColorAndTransparency(fLastHighlightName,fLastHighlightColor);
1375 if (pickMap.size() > 0 ) {
1377 fLastHighlightName = pickMap[0]->getPickName();
1378 fLastHighlightColor = getColorForPoIndex(fLastHighlightName);
1380 changeColorAndTransparency(fLastHighlightName,
G4Color(1,1,1,1));
1384 fSceneTreeComponentPickingScrollArea->setVisible(
true);
1386 }
else if (fSpinningDelay < fLaunchSpinDelay ) {
1387 if ((delta.x() == 0) && (delta.y() == 0)) {
1393 lastMoveTime.start();
1395 float correctionFactor = 5;
1397 if ( lastMoveTime.elapsed() >= (int)(1000/fNbMaxFramesPerSec)) {
1398 float lTime = 1000/lastMoveTime.elapsed();
1399 if (((((
float)delta.x())/correctionFactor)*lTime > fNbMaxAnglePerSec) ||
1400 ((((
float)delta.x())/correctionFactor)*lTime < -fNbMaxAnglePerSec) ) {
1401 correctionFactor = (float)delta.x()*(lTime/fNbMaxAnglePerSec);
1402 if (delta.x() <0 ) {
1403 correctionFactor = -correctionFactor;
1406 if (((((
float)delta.y())/correctionFactor)*lTime > fNbMaxAnglePerSec) ||
1407 ((((
float)delta.y())/correctionFactor)*lTime < -fNbMaxAnglePerSec) ) {
1408 correctionFactor = (float)delta.y()*(lTime/fNbMaxAnglePerSec);
1409 if (delta.y() <0 ) {
1410 correctionFactor = -correctionFactor;
1421 lastMoveTime.start();
1423 bool rotate =
false;
1426 if (fUiQt != NULL) {
1427 if (fUiQt->IsIconRotateSelected()) {
1429 }
else if (fUiQt->IsIconMoveSelected()) {
1442 rotateQtScene(((
float)delta.x())/correctionFactor,((
float)delta.y())/correctionFactor);
1443 } else if (fAltKeyPress) {
1444 rotateQtSceneToggle(((
float)delta.x())/correctionFactor,((
float)delta.y())/correctionFactor);
1446 #ifdef G4DEBUG_VIS_OGL
1448 fTimeRotation += lastMoveTime.elapsed();
1449 printf(
"G4OpenGLQtViewer %f \n",fTimeRotation/(
float)fNbRotation);
1453 moveScene(-((
float)delta.x())/correctionFactor,-((
float)delta.y())/correctionFactor,0,true);
1456 ((QApplication*)G4Qt::getInstance ())->processEvents();
1459 fGLWidget->setMouseTracking(false);
1464 void G4OpenGLQtViewer::G4MouseDoubleClickEvent()
1466 fGLWidget->setMouseTracking(
true);
1477 void G4OpenGLQtViewer::G4MouseMoveEvent(QMouseEvent *evnt)
1480 Qt::MouseButtons mButtons = evnt->buttons();
1482 updateKeyModifierState(evnt->modifiers());
1488 fLastPos3 = fLastPos2;
1489 fLastPos2 = fLastPos1;
1490 fLastPos1 = QPoint(evnt->x(), evnt->y());
1492 int deltaX = fLastPos2.x()-fLastPos1.x();
1493 int deltaY = fLastPos2.y()-fLastPos1.y();
1496 if (fUiQt != NULL) {
1497 if (fUiQt->IsIconMoveSelected()) {
1502 if (mButtons & Qt::LeftButton) {
1504 rotateQtScene(((
float)deltaX),((
float)deltaY));
1505 }
else if (fAltKeyPress) {
1506 rotateQtSceneToggle(((
float)deltaX),((
float)deltaY));
1507 }
else if (fShiftKeyPress) {
1508 unsigned int sizeWin;
1509 sizeWin = getWinWidth();
1510 if (getWinHeight() < getWinWidth()) {
1511 sizeWin = getWinHeight();
1515 float factor = ((float)100/(
float)sizeWin) ;
1516 moveScene(-(
float)deltaX*factor,-(
float)deltaY*factor,0,
false);
1517 }
else if (fControlKeyPress) {
1518 fVP.SetZoomFactor(fVP.GetZoomFactor()*(1+((float)deltaY)));
1522 if (mButtons & Qt::LeftButton) {
1523 moveScene(-(
float)deltaX,-(
float)deltaY,0,
true);
1527 fLastEventTime->start();
1538 void G4OpenGLQtViewer::moveScene(
float dx,
float dy,
float dz,
bool mouseMove)
1542 fHoldMoveEvent =
true;
1545 GLdouble coefDepth = 0;
1548 if (getWinHeight() <getWinWidth()) {
1552 coefTrans = getSceneNearWidth()*fPan_sens;
1553 coefDepth = getSceneDepth()*fDeltaDepth;
1555 fVP.IncrementPan(-dx*coefTrans,dy*coefTrans,dz*coefDepth);
1559 ((QApplication*)G4Qt::getInstance ())->processEvents();
1561 fHoldMoveEvent =
false;
1570 void G4OpenGLQtViewer::rotateQtScene(
float dx,
float dy)
1572 if (fHoldRotateEvent)
1574 fHoldRotateEvent =
true;
1580 fHoldRotateEvent =
false;
1588 void G4OpenGLQtViewer::rotateQtSceneToggle(
float dx,
float dy)
1590 if (fHoldRotateEvent)
1592 fHoldRotateEvent =
true;
1594 rotateSceneToggle(dx,dy);
1598 fHoldRotateEvent =
false;
1609 void G4OpenGLQtViewer::rescaleImage(
1629 void G4OpenGLQtViewer::G4wheelEvent (QWheelEvent * evnt)
1631 fVP.SetZoomFactor(fVP.GetZoomFactor()+(fVP.GetZoomFactor()*(evnt->delta())/1200));
1636 void G4OpenGLQtViewer::G4keyPressEvent (QKeyEvent * evnt)
1641 fHoldKeyEvent =
true;
1645 updateKeyModifierState(evnt->modifiers());
1646 if ((fNoKeyPress) || (evnt->modifiers() == Qt::KeypadModifier )) {
1647 if (evnt->key() == Qt::Key_Down) {
1648 moveScene(0,1,0,
false);
1650 else if (evnt->key() == Qt::Key_Up) {
1651 moveScene(0,-1,0,
false);
1653 if (evnt->key() == Qt::Key_Left) {
1654 moveScene(-1,0,0,
false);
1656 else if (evnt->key() == Qt::Key_Right) {
1657 moveScene(1,0,0,
false);
1659 if (evnt->key() == Qt::Key_Minus) {
1660 moveScene(0,0,1,
false);
1662 else if (evnt->key() == Qt::Key_Plus) {
1663 moveScene(0,0,-1,
false);
1667 if (evnt->key() == Qt::Key_Escape) {
1668 toggleFullScreen(
false);
1677 if ((evnt->key() == Qt::Key_Return) || (evnt->key() == Qt::Key_Enter)){
1680 if (evnt->key() == Qt::Key_Space){
1685 if (evnt->key() == Qt::Key_H){
1692 if (fShiftKeyPress) {
1693 fGLWidget->setCursor(QCursor(Qt::SizeAllCursor));
1695 if (evnt->key() == Qt::Key_Down) {
1696 rotateQtScene(0,-fRot_sens);
1698 else if (evnt->key() == Qt::Key_Up) {
1699 rotateQtScene(0,fRot_sens);
1701 if (evnt->key() == Qt::Key_Left) {
1702 rotateQtScene(fRot_sens,0);
1704 else if (evnt->key() == Qt::Key_Right) {
1705 rotateQtScene(-fRot_sens,0);
1707 if (evnt->key() == Qt::Key_Plus) {
1709 moveScene(0,0,-1,
false);
1714 if ((fAltKeyPress)) {
1715 fGLWidget->setCursor(QCursor(Qt::ClosedHandCursor));
1717 if (evnt->key() == Qt::Key_Down) {
1718 rotateQtSceneToggle(0,-fRot_sens);
1720 else if (evnt->key() == Qt::Key_Up) {
1721 rotateQtSceneToggle(0,fRot_sens);
1723 if (evnt->key() == Qt::Key_Left) {
1724 rotateQtSceneToggle(fRot_sens,0);
1726 else if (evnt->key() == Qt::Key_Right) {
1727 rotateQtSceneToggle(-fRot_sens,0);
1731 if (evnt->key() == Qt::Key_Plus) {
1732 fRot_sens = fRot_sens/0.7;
1733 G4cout <<
"Auto-rotation set to : " << fRot_sens <<
G4endl;
1735 else if (evnt->key() == Qt::Key_Minus) {
1736 fRot_sens = fRot_sens*0.7;
1737 G4cout <<
"Auto-rotation set to : " << fRot_sens <<
G4endl;
1742 if ((fControlKeyPress)) {
1743 if (evnt->key() == Qt::Key_Plus) {
1744 fVP.SetZoomFactor(fVP.GetZoomFactor()*(1+fDeltaZoom));
1747 else if (evnt->key() == Qt::Key_Minus) {
1748 fVP.SetZoomFactor(fVP.GetZoomFactor()*(1-fDeltaZoom));
1753 fHoldKeyEvent =
false;
1757 void G4OpenGLQtViewer::G4keyReleaseEvent (QKeyEvent *)
1759 fGLWidget->setCursor(QCursor(Qt::ArrowCursor));
1763 void G4OpenGLQtViewer::updateKeyModifierState(
const Qt::KeyboardModifiers& modifier) {
1767 fAltKeyPress =
false;
1768 fShiftKeyPress =
false;
1769 fControlKeyPress =
false;
1771 if (modifier & Qt::AltModifier ) {
1772 fAltKeyPress =
true;
1773 fNoKeyPress =
false;
1775 if (modifier & Qt::ShiftModifier ) {
1776 fShiftKeyPress =
true;
1777 fNoKeyPress =
false;
1779 if (modifier & Qt::ControlModifier ) {
1780 fControlKeyPress =
true;
1781 fNoKeyPress =
false;
1788 void G4OpenGLQtViewer::stopVideo() {
1791 if (!fMovieParametersDialog) {
1792 showMovieParametersDialog();
1794 setRecordingStatus(STOP);
1796 if (fRecordFrameNumber >0) {
1798 if (!(fMovieParametersDialog->checkEncoderSwParameters())) {
1799 setRecordingStatus(BAD_ENCODER);
1800 }
else if (!(fMovieParametersDialog->checkSaveFileNameParameters())) {
1801 setRecordingStatus(BAD_OUTPUT);
1805 setRecordingInfos(
"No frame to encode.");
1811 void G4OpenGLQtViewer::saveVideo() {
1814 if (!fMovieParametersDialog) {
1815 showMovieParametersDialog();
1818 fMovieParametersDialog->checkEncoderSwParameters();
1819 fMovieParametersDialog->checkSaveFileNameParameters();
1821 if (fRecordingStep == STOP) {
1822 setRecordingStatus(SAVE);
1823 generateMpegEncoderParameters();
1831 void G4OpenGLQtViewer::startPauseVideo() {
1835 if ( fRecordingStep == WAIT) {
1836 if ( fRecordFrameNumber == 0) {
1837 if (getTempFolderPath() ==
"") {
1838 showMovieParametersDialog();
1839 setRecordingInfos(
"You should specified the temp folder in order to make movie");
1843 QString tmp = removeTempFolder();
1845 setRecordingInfos(tmp);
1848 tmp = createTempFolder();
1850 setRecordingInfos(
"Can't create temp folder."+tmp);
1856 if (fRecordingStep == WAIT) {
1857 setRecordingStatus(
START);
1858 }
else if (fRecordingStep ==
START) {
1859 setRecordingStatus(PAUSE);
1860 }
else if (fRecordingStep == PAUSE) {
1861 setRecordingStatus(CONTINUE);
1862 }
else if (fRecordingStep == CONTINUE) {
1863 setRecordingStatus(PAUSE);
1867 void G4OpenGLQtViewer::setRecordingStatus(RECORDING_STEP step) {
1869 fRecordingStep = step;
1870 displayRecordingStatus();
1874 void G4OpenGLQtViewer::displayRecordingStatus() {
1876 QString txtStatus =
"";
1877 if (fRecordingStep == WAIT) {
1878 txtStatus =
"Waiting to start...";
1879 fRecordFrameNumber = 0;
1880 }
else if (fRecordingStep ==
START) {
1881 txtStatus =
"Start Recording...";
1882 }
else if (fRecordingStep == PAUSE) {
1883 txtStatus =
"Pause Recording...";
1884 }
else if (fRecordingStep == CONTINUE) {
1885 txtStatus =
"Continue Recording...";
1886 }
else if (fRecordingStep == STOP) {
1887 txtStatus =
"Stop Recording...";
1888 }
else if (fRecordingStep == READY_TO_ENCODE) {
1889 txtStatus =
"Ready to Encode...";
1890 }
else if (fRecordingStep == ENCODING) {
1891 txtStatus =
"Encoding...";
1892 }
else if (fRecordingStep == FAILED) {
1893 txtStatus =
"Failed to encode...";
1894 }
else if ((fRecordingStep == BAD_ENCODER)
1895 || (fRecordingStep == BAD_OUTPUT)
1896 || (fRecordingStep == BAD_TMP)) {
1897 txtStatus =
"Correct above errors first";
1898 }
else if (fRecordingStep == SUCCESS) {
1899 txtStatus =
"File encoded successfully";
1903 if (fMovieParametersDialog) {
1904 fMovieParametersDialog->setRecordingStatus(txtStatus);
1908 setRecordingInfos(
"");
1912 void G4OpenGLQtViewer::setRecordingInfos(
const QString& txt) {
1913 if (fMovieParametersDialog) {
1914 fMovieParametersDialog->setRecordingInfos(txt);
1922 void G4OpenGLQtViewer::initMovieParameters() {
1926 fProcess =
new QProcess();
1928 QObject ::connect(fProcess,SIGNAL(finished (
int)),
1929 this,SLOT(processLookForFinished()));
1930 fProcess->setReadChannelMode(QProcess::MergedChannels);
1931 fProcess->start (
"which ppmtompeg");
1937 QString G4OpenGLQtViewer::getEncoderPath() {
1938 return fEncoderPath;
1946 QString G4OpenGLQtViewer::setEncoderPath(QString path) {
1948 return "File does not exist";
1951 path = QDir::cleanPath(path);
1952 QFileInfo *f =
new QFileInfo(path);
1954 return "File does not exist";
1955 }
else if (f->isDir()) {
1956 return "This is a directory";
1957 }
else if (!f->isExecutable()) {
1958 return "File exist but is not executable";
1959 }
else if (!f->isFile()) {
1960 return "This is not a file";
1962 fEncoderPath = path;
1964 if (fRecordingStep == BAD_ENCODER) {
1965 setRecordingStatus(STOP);
1971 bool G4OpenGLQtViewer::isRecording(){
1972 if ((fRecordingStep ==
START) || (fRecordingStep == CONTINUE)) {
1978 bool G4OpenGLQtViewer::isPaused(){
1979 if (fRecordingStep == PAUSE) {
1985 bool G4OpenGLQtViewer::isEncoding(){
1986 if (fRecordingStep == ENCODING) {
1992 bool G4OpenGLQtViewer::isWaiting(){
1993 if (fRecordingStep == WAIT) {
1999 bool G4OpenGLQtViewer::isStopped(){
2000 if (fRecordingStep == STOP) {
2006 bool G4OpenGLQtViewer::isFailed(){
2007 if (fRecordingStep == FAILED) {
2013 bool G4OpenGLQtViewer::isSuccess(){
2014 if (fRecordingStep == SUCCESS) {
2020 bool G4OpenGLQtViewer::isBadEncoder(){
2021 if (fRecordingStep == BAD_ENCODER) {
2026 bool G4OpenGLQtViewer::isBadTmp(){
2027 if (fRecordingStep == BAD_TMP) {
2032 bool G4OpenGLQtViewer::isBadOutput(){
2033 if (fRecordingStep == BAD_OUTPUT) {
2039 void G4OpenGLQtViewer::setBadEncoder(){
2040 fRecordingStep = BAD_ENCODER;
2041 displayRecordingStatus();
2043 void G4OpenGLQtViewer::setBadTmp(){
2044 fRecordingStep = BAD_TMP;
2045 displayRecordingStatus();
2047 void G4OpenGLQtViewer::setBadOutput(){
2048 fRecordingStep = BAD_OUTPUT;
2049 displayRecordingStatus();
2052 void G4OpenGLQtViewer::setWaiting(){
2053 fRecordingStep = WAIT;
2054 displayRecordingStatus();
2058 bool G4OpenGLQtViewer::isReadyToEncode(){
2059 if (fRecordingStep == READY_TO_ENCODE) {
2065 void G4OpenGLQtViewer::resetRecording() {
2066 setRecordingStatus(WAIT);
2073 QString G4OpenGLQtViewer::setTempFolderPath(QString path) {
2076 return "Path does not exist";
2078 path = QDir::cleanPath(path);
2079 QFileInfo *d =
new QFileInfo(path);
2081 return "Path does not exist";
2082 }
else if (!d->isDir()) {
2083 return "This is not a directory";
2084 }
else if (!d->isReadable()) {
2085 return path +
" is read protected";
2086 }
else if (!d->isWritable()) {
2087 return path +
" is write protected";
2090 if (fRecordingStep == BAD_TMP) {
2091 setRecordingStatus(WAIT);
2093 fTempFolderPath = path;
2099 QString G4OpenGLQtViewer::getTempFolderPath() {
2100 return fTempFolderPath;
2107 QString G4OpenGLQtViewer::setSaveFileName(QString path) {
2110 return "Path does not exist";
2113 QFileInfo *file =
new QFileInfo(path);
2114 QDir dir = file->dir();
2115 path = QDir::cleanPath(path);
2116 if (file->exists()) {
2117 return "File already exist, please choose a new one";
2118 }
else if (!dir.exists()) {
2119 return "Dir does not exist";
2120 }
else if (!dir.isReadable()) {
2121 return path +
" is read protected";
2124 if (fRecordingStep == BAD_OUTPUT) {
2125 setRecordingStatus(STOP);
2127 fSaveFileName = path;
2133 QString G4OpenGLQtViewer::getSaveFileName() {
2134 return fSaveFileName ;
2141 QString G4OpenGLQtViewer::createTempFolder() {
2142 fMovieTempFolderPath =
"";
2144 QString tmp = setTempFolderPath(fTempFolderPath);
2148 QString sep = QString(QDir::separator());
2149 QString path = sep+
"QtMovie_"+QDateTime::currentDateTime ().toString(
"dd-MM-yyyy_hh-mm-ss")+sep;
2150 QDir *d =
new QDir(QDir::cleanPath(fTempFolderPath));
2152 if (d->exists(path)) {
2153 return "Folder "+path+
" already exists.Please remove it first";
2155 if (d->mkdir(fTempFolderPath+path)) {
2156 fMovieTempFolderPath = fTempFolderPath+path;
2159 return "Can't create "+fTempFolderPath+path;
2164 QString G4OpenGLQtViewer::removeTempFolder() {
2166 if (fMovieTempFolderPath ==
"") {
2169 QDir *d =
new QDir(QDir::cleanPath(fMovieTempFolderPath));
2174 d->setFilter( QDir::Files );
2175 QStringList subDirList = d->entryList();
2178 for (QStringList::ConstIterator it = subDirList.begin() ;(it != subDirList.end()) ; it++) {
2179 const QString currentFile = *it;
2180 if (!d->remove(currentFile)) {
2182 QString file = fMovieTempFolderPath+currentFile;
2183 error +=
"Removing file failed : "+file;
2188 if (d->rmdir(fMovieTempFolderPath)) {
2189 fMovieTempFolderPath =
"";
2192 return "Dir "+fMovieTempFolderPath+
" should be empty, but could not remove it";
2196 return "Could not remove "+fMovieTempFolderPath+
" because of the following errors :"+
error;
2206 bool G4OpenGLQtViewer::exportImage(std::string name,
int width,
int height) {
2208 QGLWidget* qGLW =
dynamic_cast<QGLWidget*
> (fGLWidget) ;
2213 bool increaseFileNumber =
true;
2215 if (name.size() != name.substr(name.find_last_of(
".") + 1).size()) {
2216 increaseFileNumber =
false;
2218 if (! setExportFilename(name,increaseFileNumber)) {
2221 if ((width !=-1) && (height != -1)) {
2222 setExportSize(width, height);
2225 if (G4OpenGLViewer::exportImage()) {
2231 image = qGLW->grabFrameBuffer();
2233 bool res = image.save(QString(getRealPrintFilename().c_str()),0,fLastExportSliderValue);
2236 G4cerr <<
"Error saving file... " << getRealPrintFilename().c_str() <<
G4endl;
2239 G4cout <<
"File " << getRealPrintFilename().c_str() <<
" size: " << fGLWidget->width() <<
"x" << fGLWidget->height() <<
" has been saved " <<
G4endl;
2240 fExportFilenameIndex++;
2248 bool G4OpenGLQtViewer::hasPendingEvents () {
2249 return ((QApplication*)G4Qt::getInstance ())->hasPendingEvents ();
2252 bool G4OpenGLQtViewer::generateMpegEncoderParameters () {
2256 fp = fopen (QString(fMovieTempFolderPath+fParameterFileName).toStdString().c_str(),
"w");
2259 setRecordingInfos(
"Generation of parameter file failed");
2263 fprintf (fp,
"# Pattern affects speed, quality and compression. See the User's Guide\n");
2264 fprintf (fp,
"# for more info.\n");
2266 fprintf (fp,
"PATTERN IBBPBBPBBPBBPBBP\n");
2267 fprintf (fp,
"OUTPUT %s\n",getSaveFileName().toStdString().c_str());
2269 fprintf (fp,
"# You must specify the type of the input files. The choices are:\n");
2270 fprintf (fp,
"# YUV, PPM, JMOVIE, Y, JPEG, PNM\n");
2271 fprintf (fp,
"# (must be upper case)\n");
2273 fprintf (fp,
"BASE_FILE_FORMAT PPM\n");
2276 fprintf (fp,
"# if YUV format (or using parallel version), must provide width and height\n");
2277 fprintf (fp,
"# YUV_SIZE widthxheight\n");
2278 fprintf (fp,
"# this option is ignored if BASE_FILE_FORMAT is not YUV and you're running\n");
2279 fprintf (fp,
"# on just one machine\n");
2281 fprintf (fp,
"YUV_SIZE 352x240\n");
2283 fprintf (fp,
"# If you are using YUV, there are different supported file formats.\n");
2284 fprintf (fp,
"# EYUV or UCB are the same as previous versions of this encoder.\n");
2285 fprintf (fp,
"# (All the Y's, then U's then V's, in 4:2:0 subsampling.)\n");
2286 fprintf (fp,
"# Other formats, such as Abekas, Phillips, or a general format are\n");
2287 fprintf (fp,
"# permissible, the general format is a string of Y's, U's, and V's\n");
2288 fprintf (fp,
"# to specify the file order.\n");
2290 fprintf (fp,
"INPUT_FORMAT UCB\n");
2292 fprintf (fp,
"# the conversion statement\n");
2294 fprintf (fp,
"# Each occurrence of '*' will be replaced by the input file\n");
2296 fprintf (fp,
"# e.g., if you have a bunch of GIF files, then this might be:\n");
2297 fprintf (fp,
"# INPUT_CONVERT giftoppm *\n");
2299 fprintf (fp,
"# e.g., if you have a bunch of files like a.Y a.U a.V, etc., then:\n");
2300 fprintf (fp,
"# INPUT_CONVERT cat *.Y *.U *.V\n");
2302 fprintf (fp,
"# e.g., if you are grabbing from laser disc you might have something like\n");
2303 fprintf (fp,
"# INPUT_CONVERT goto frame *; grabppm\n");
2304 fprintf (fp,
"# 'INPUT_CONVERT *' means the files are already in the base file format\n");
2306 fprintf (fp,
"INPUT_CONVERT * \n");
2308 fprintf (fp,
"# number of frames in a GOP.\n");
2310 fprintf (fp,
"# since each GOP must have at least one I-frame, the encoder will find the\n");
2311 fprintf (fp,
"# the first I-frame after GOP_SIZE frames to start the next GOP\n");
2313 fprintf (fp,
"# later, will add more flexible GOP signalling\n");
2315 fprintf (fp,
"GOP_SIZE 16\n");
2317 fprintf (fp,
"# number of slices in a frame\n");
2319 fprintf (fp,
"# 1 is a good number. another possibility is the number of macroblock rows\n");
2320 fprintf (fp,
"# (which is the height divided by 16)\n");
2322 fprintf (fp,
"SLICES_PER_FRAME 1\n");
2324 fprintf (fp,
"# directory to get all input files from (makes this file easier to read)\n");
2325 fprintf (fp,
"INPUT_DIR %s\n",fMovieTempFolderPath.toStdString().c_str());
2327 fprintf (fp,
"# There are a bunch of ways to specify the input files.\n");
2328 fprintf (fp,
"# from a simple one-per-line listing, to the following \n");
2329 fprintf (fp,
"# way of numbering them. See the manual for more information.\n");
2330 fprintf (fp,
"INPUT\n");
2331 fprintf (fp,
"# '*' is replaced by the numbers 01, 02, 03, 04\n");
2332 fprintf (fp,
"# if I instead do [01-11], it would be 01, 02, ..., 09, 10, 11\n");
2333 fprintf (fp,
"# if I instead do [1-11], it would be 1, 2, 3, ..., 9, 10, 11\n");
2334 fprintf (fp,
"# if I instead do [1-11+3], it would be 1, 4, 7, 10\n");
2335 fprintf (fp,
"# the program assumes none of your input files has a name ending in ']'\n");
2336 fprintf (fp,
"# if you do, too bad!!!\n");
2339 fprintf (fp,
"Test*.ppm [0-%d]\n",fRecordFrameNumber-1);
2340 fprintf (fp,
"# can have more files here if you want...there is no limit on the number\n");
2341 fprintf (fp,
"# of files\n");
2342 fprintf (fp,
"END_INPUT\n");
2346 fprintf (fp,
"# Many of the remaining options have to do with the motion search and qscale\n");
2348 fprintf (fp,
"# FULL or HALF -- must be upper case\n");
2349 fprintf (fp,
"# Should be FULL for computer generated images\n");
2350 fprintf (fp,
"PIXEL FULL\n");
2352 fprintf (fp,
"# means +/- this many pixels for both P and B frame searches\n");
2353 fprintf (fp,
"# specify two numbers if you wish to serc different ranges in the two.\n");
2354 fprintf (fp,
"RANGE 10\n");
2356 fprintf (fp,
"# The two search algorithm parameters below mostly affect speed,\n");
2357 fprintf (fp,
"# with some affect on compression and almost none on quality.\n");
2359 fprintf (fp,
"# this must be one of {EXHAUSTIVE, SUBSAMPLE, LOGARITHMIC}\n");
2360 fprintf (fp,
"PSEARCH_ALG LOGARITHMIC\n");
2362 fprintf (fp,
"# this must be one of {SIMPLE, CROSS2, EXHAUSTIVE}\n");
2364 fprintf (fp,
"# note that EXHAUSTIVE is really, really, really slow\n");
2366 fprintf (fp,
"BSEARCH_ALG SIMPLE\n");
2369 fprintf (fp,
"# these specify the q-scale for I, P, and B frames\n");
2370 fprintf (fp,
"# (values must be between 1 and 31)\n");
2371 fprintf (fp,
"# These are the Qscale values for the entire frame in variable bit-rate\n");
2372 fprintf (fp,
"# mode, and starting points (but not important) for constant bit rate\n");
2375 fprintf (fp,
"# Qscale (Quantization scale) affects quality and compression,\n");
2376 fprintf (fp,
"# but has very little effect on speed.\n");
2378 fprintf (fp,
"IQSCALE 4\n");
2379 fprintf (fp,
"PQSCALE 5\n");
2380 fprintf (fp,
"BQSCALE 12\n");
2382 fprintf (fp,
"# this must be ORIGINAL or DECODED\n");
2383 fprintf (fp,
"REFERENCE_FRAME ORIGINAL\n");
2385 fprintf (fp,
"# for parallel parameters see parallel.param in the exmaples subdirectory\n");
2387 fprintf (fp,
"# if you want constant bit-rate mode, specify it as follows (number is bits/sec):\n");
2388 fprintf (fp,
"#BIT_RATE 1000000\n");
2390 fprintf (fp,
"# To specify the buffer size (327680 is default, measused in bits, for 16bit words)\n");
2391 fprintf (fp,
"BUFFER_SIZE 327680\n");
2393 fprintf (fp,
"# The frame rate is the number of frames/second (legal values:\n");
2394 fprintf (fp,
"# 23.976, 24, 25, 29.97, 30, 50 ,59.94, 60\n");
2395 fprintf (fp,
"FRAME_RATE 30\n");
2397 fprintf (fp,
"# There are many more options, see the users manual for examples....\n");
2398 fprintf (fp,
"# ASPECT_RATIO, USER_DATA, GAMMA, IQTABLE, etc.\n");
2403 setRecordingInfos(
"Parameter file "+fParameterFileName+
" generated in "+fMovieTempFolderPath);
2404 setRecordingStatus(READY_TO_ENCODE);
2408 void G4OpenGLQtViewer::encodeVideo()
2410 if ((getEncoderPath() !=
"") && (getSaveFileName() !=
"")) {
2411 setRecordingStatus(ENCODING);
2413 fProcess =
new QProcess();
2414 #if QT_VERSION > 0x040100
2415 QObject ::connect(fProcess,SIGNAL(finished (
int,QProcess::ExitStatus)),
2416 this,SLOT(processEncodeFinished()));
2417 QObject ::connect(fProcess,SIGNAL(readyReadStandardOutput ()),
2418 this,SLOT(processEncodeStdout()));
2420 QObject ::connect(fProcess,SIGNAL(finished (
int)),
2421 this,SLOT(processEncodeFinished()));
2422 QObject ::connect(fProcess,SIGNAL(readyReadStandardOutput ()),
2423 this,SLOT(processEncodeStdout()));
2425 fProcess->setReadChannelMode(QProcess::MergedChannels);
2426 fProcess->start (fEncoderPath, QStringList(fMovieTempFolderPath+fParameterFileName));
2432 void G4OpenGLQtViewer::processEncodeStdout()
2434 QString tmp = fProcess->readAllStandardOutput ().data();
2435 int start = tmp.lastIndexOf(
"ESTIMATED TIME");
2436 tmp = tmp.mid(start,tmp.indexOf(
"\n",start)-start);
2437 setRecordingInfos(tmp);
2441 void G4OpenGLQtViewer::processEncodeFinished()
2445 txt = getProcessErrorMsg();
2447 setRecordingStatus(SUCCESS);
2449 setRecordingStatus(FAILED);
2455 void G4OpenGLQtViewer::processLookForFinished()
2458 QString txt = getProcessErrorMsg();
2462 fEncoderPath = QString(fProcess->readAllStandardOutput ().data()).trimmed();
2464 if (fEncoderPath.contains(
" ")) {
2466 }
else if (!fEncoderPath.contains(
"ppmtompeg")) {
2469 setEncoderPath(fEncoderPath);
2472 setTempFolderPath(QDir::temp ().absolutePath ());
2476 QString G4OpenGLQtViewer::getProcessErrorMsg()
2479 if (fProcess->exitCode() != 0) {
2480 switch (fProcess->error()) {
2481 case QProcess::FailedToStart:
2482 txt =
"The process failed to start. Either the invoked program is missing, or you may have insufficient permissions to invoke the program.\n";
2484 case QProcess::Crashed:
2485 txt =
"The process crashed some time after starting successfully.\n";
2487 case QProcess::Timedout:
2488 txt =
"The last waitFor...() function timed out. The state of QProcess is unchanged, and you can try calling waitFor...() again.\n";
2490 case QProcess::WriteError:
2491 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";
2493 case QProcess::ReadError:
2494 txt =
"An error occurred when attempting to read from the process. For example, the process may not be running.\n";
2496 case QProcess::UnknownError:
2497 txt =
"An unknown error occurred. This is the default return value of error().\n";
2507 QWidget *G4OpenGLQtViewer::getParentWidget()
2510 G4Qt* interactorManager = G4Qt::getInstance ();
2515 QDialog* dialog = NULL;
2517 if (((QApplication*)interactorManager->GetMainInteractor())) {
2519 QWidgetList wl = QApplication::allWidgets();
2520 QWidget *widget = NULL;
2521 for (
int i=0; i < wl.size(); i++) {
2523 if ((found==
false) && (widget->inherits(
"QMainWindow"))) {
2524 dialog =
new QDialog(widget,Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowMinMaxButtonsHint);
2530 #ifdef G4DEBUG_VIS_OGL
2531 printf(
"G4OpenGLQtViewer::CreateMainWindow case Qapp exist, but not found\n");
2533 dialog =
new QDialog();
2536 #ifdef G4DEBUG_VIS_OGL
2537 printf(
"G4OpenGLQtViewer::CreateMainWindow case Qapp exist\n");
2539 dialog=
new QDialog();
2540 #ifdef G4DEBUG_VIS_OGL
2541 printf(
"G4OpenGLQtViewer::GetParentWidget fGLWidget\n");
2552 void G4OpenGLQtViewer::initSceneTreeComponent(){
2554 QGroupBox *groupBox =
new QGroupBox(
"");
2555 QVBoxLayout *vbox =
new QVBoxLayout;
2557 fSceneTreeViewerButton =
new QPushButton(
"Scene tree");
2558 fSceneTreeViewerButton->setStyleSheet (
"text-align: left; padding: 5px; border:0px; ");
2559 fSceneTreeViewerButton->setIcon(*fTreeIconClosed);
2561 vbox->addWidget(fSceneTreeViewerButton);
2562 connect(fSceneTreeViewerButton,SIGNAL(clicked()),
this, SLOT(toggleSceneTreeViewerInfos()));
2564 fSceneTreeViewerInfos =
new QWidget();
2565 fSceneTreeViewerInfos->setStyleSheet (
"padding: 0px ");
2566 fSceneTreeViewerInfos->setVisible(
false);
2567 fSceneTreeViewerInfos->setSizePolicy(QSizePolicy::Minimum,QSizePolicy::Minimum);
2569 QVBoxLayout* vLayout =
new QVBoxLayout();
2570 fSceneTreeViewerInfos->setLayout (vLayout);
2573 QWidget* coutButtonWidget =
new QWidget();
2574 QHBoxLayout* layoutCoutTBButtons =
new QHBoxLayout();
2576 fFilterOutput =
new QLineEdit();
2577 fFilterOutput->setToolTip(
"Filter output by...");
2578 fFilterOutput->setStyleSheet (
"padding: 0px ");
2580 QPixmap* searchIcon = fUiQt->getSearchIcon();
2581 #if QT_VERSION > 0x050100
2582 fFilterOutput->addAction(*searchIcon,QLineEdit::TrailingPosition);
2583 fFilterOutput->setStyleSheet (
"border-radius:7px;");
2585 QPushButton *coutTBFilterButton =
new QPushButton();
2586 coutTBFilterButton->setIcon(*searchIcon);
2587 coutTBFilterButton->setStyleSheet (
"padding-left: 0px; border:0px;");
2588 fFilterOutput->setStyleSheet (
"padding-right: 0px;");
2590 layoutCoutTBButtons->addWidget(fFilterOutput);
2592 #if QT_VERSION <= 0x050100
2593 layoutCoutTBButtons->addWidget(coutTBFilterButton);
2596 coutButtonWidget->setLayout(layoutCoutTBButtons);
2597 vLayout->addWidget(coutButtonWidget);
2600 vLayout->setContentsMargins(5,5,5,5);
2603 fSceneTreeComponentTreeWidget =
new QTreeWidget();
2604 fSceneTreeComponentTreeWidget->setSelectionMode(QAbstractItemView::SingleSelection);
2605 fSceneTreeComponentTreeWidget->setHeaderLabel (
"Scene tree : "+QString(GetName().data()));
2606 fSceneTreeComponentTreeWidget->setColumnHidden (1,
true);
2607 fSceneTreeComponentTreeWidget->setColumnHidden (2,
true);
2608 fSceneTreeComponentTreeWidget->setColumnHidden (3,
true);
2613 vLayout->addWidget(fSceneTreeComponentTreeWidget);
2615 connect(fSceneTreeComponentTreeWidget,SIGNAL(itemChanged(QTreeWidgetItem*,
int)),SLOT(sceneTreeComponentItemChanged(QTreeWidgetItem*,
int)));
2616 connect(fSceneTreeComponentTreeWidget,SIGNAL(itemSelectionChanged ()),SLOT(sceneTreeComponentSelected()));
2617 connect(fSceneTreeComponentTreeWidget,SIGNAL(itemDoubleClicked ( QTreeWidgetItem*,
int)),SLOT(changeColorAndTransparency( QTreeWidgetItem*,
int)));
2621 QWidget *helpWidget =
new QWidget();
2622 QHBoxLayout *helpLayout =
new QHBoxLayout();
2624 QWidget* depthWidget =
new QWidget();
2625 QWidget *showBox =
new QWidget(depthWidget);
2626 QHBoxLayout *showBoxLayout =
new QHBoxLayout();
2629 showBoxLayout->setContentsMargins(5,5,5,5);
2631 QLabel *zero =
new QLabel();
2632 zero->setText(
"Show all");
2633 QLabel *one =
new QLabel();
2634 one->setText(
"Hide all");
2635 fSceneTreeDepthSlider =
new QSlider ( Qt::Horizontal);
2636 fSceneTreeDepthSlider->setMaximum (1000);
2637 fSceneTreeDepthSlider->setMinimum (0);
2638 fSceneTreeDepthSlider->setTickPosition(QSlider::TicksAbove);
2640 fSceneTreeDepthSlider->setMinimumWidth (40);
2642 showBoxLayout->addWidget(zero);
2643 showBoxLayout->addWidget(fSceneTreeDepthSlider);
2644 showBoxLayout->addWidget(one);
2646 showBox->setLayout(showBoxLayout);
2648 helpLayout->addWidget(showBox);
2649 helpWidget->setLayout(helpLayout);
2650 helpLayout->setContentsMargins(0,0,0,0);
2652 vLayout->addWidget(helpWidget);
2653 QSizePolicy vPolicy = fSceneTreeViewerInfos->sizePolicy();
2654 vPolicy.setVerticalStretch(4);
2656 vbox->addWidget(fSceneTreeViewerInfos);
2658 groupBox->setLayout(vbox);
2659 fSceneTreeWidget->layout()->addWidget(groupBox);
2661 connect( fSceneTreeDepthSlider, SIGNAL( valueChanged(
int) ),
this, SLOT( changeDepthInSceneTree(
int) ) );
2662 fTreeItemModels.clear();
2664 fPVRootNodeCreate =
false;
2666 fMaxPOindexInserted = -1;
2672 void G4OpenGLQtViewer::initViewerPropertiesComponent() {
2675 QGroupBox *groupBox =
new QGroupBox(
"");
2676 QVBoxLayout *vbox =
new QVBoxLayout;
2677 fViewerPropertiesButton =
new QPushButton(
"Viewer properties");
2678 fViewerPropertiesButton->setStyleSheet (
"text-align: left; padding: 5px; border:0px; ");
2679 fViewerPropertiesButton->setIcon(*fTreeIconClosed);
2681 vbox->addWidget(fViewerPropertiesButton);
2682 connect(fViewerPropertiesButton,SIGNAL(clicked()),
this, SLOT(toggleSceneTreeComponentTreeWidgetInfos()));
2685 fSceneTreeComponentTreeWidgetInfos =
new QTableWidget();
2686 fSceneTreeComponentTreeWidgetInfos->setVisible(
false);
2687 fSceneTreeComponentTreeWidgetInfos->setStyleSheet (
"padding: 0px ");
2688 vbox->addWidget(fSceneTreeComponentTreeWidgetInfos);
2690 groupBox->setLayout(vbox);
2691 fSceneTreeWidget->layout()->addWidget(groupBox);
2692 QSizePolicy vPolicy = fSceneTreeComponentTreeWidgetInfos->sizePolicy();
2693 vPolicy.setVerticalStretch(4);
2695 connect(fSceneTreeComponentTreeWidgetInfos, SIGNAL(itemChanged(QTableWidgetItem*)),
this, SLOT(tableWidgetViewerSetItemChanged(QTableWidgetItem *)));
2697 updateSceneTreeComponentTreeWidgetInfos();
2701 void G4OpenGLQtViewer::initPickingComponent(){
2703 QGroupBox *groupBox =
new QGroupBox(
"");
2704 QVBoxLayout *vbox =
new QVBoxLayout;
2707 QWidget *pickingInfoWidget =
new QWidget();
2708 QHBoxLayout *pickingInfoLayout =
new QHBoxLayout();
2710 fViewerPickingButton =
new QPushButton(
"Picking informations");
2711 fViewerPickingButton->setStyleSheet (
"text-align: left; padding: 5px; border:0px; ");
2712 fViewerPickingButton->setIcon(*fTreeIconClosed);
2716 QCheckBox * activatePicking =
new QCheckBox(
"Picking mode active");
2717 if (fVP.IsPicking()) {
2718 activatePicking->setCheckState(Qt::Checked);
2720 activatePicking->setCheckState(Qt::Unchecked);
2722 activatePicking->setToolTip(
"Enable picking allow you to display properties of a selected object on the scene");
2723 connect(activatePicking, SIGNAL(clicked()),
this, SLOT(togglePicking()));
2725 pickingInfoLayout->addWidget(fViewerPickingButton);
2726 pickingInfoLayout->addWidget(activatePicking);
2728 pickingInfoWidget->setStyleSheet (
"padding-left: 0px; border:0px;");
2729 pickingInfoWidget->setLayout(pickingInfoLayout);
2731 vbox->addWidget(pickingInfoWidget);
2732 connect(fViewerPickingButton,SIGNAL(clicked()),
this, SLOT(toggleSceneTreeComponentPickingInfos()));
2736 fSceneTreeComponentPickingScrollArea =
new QScrollArea();
2737 fSceneTreeComponentPickingScrollArea->setWidgetResizable(
true);
2740 fSceneTreeComponentPickingInfos =
new QWidget();
2741 fSceneTreeComponentPickingInfos->setStyleSheet (
"padding: 0px ");
2742 fSceneTreeComponentPickingScrollArea->setVisible(
false);
2745 QVBoxLayout* vLayout =
new QVBoxLayout();
2746 fSceneTreeComponentPickingInfos->setLayout (vLayout);
2747 fSceneTreeComponentPickingScrollArea->setWidget(fSceneTreeComponentPickingInfos);
2749 QSizePolicy vPolicy = fSceneTreeComponentPickingInfos->sizePolicy();
2750 vPolicy.setVerticalStretch(4);
2751 vbox->addWidget(fSceneTreeComponentPickingScrollArea);
2753 groupBox->setLayout(vbox);
2754 fSceneTreeWidget->layout()->addWidget(groupBox);
2755 connect( fFilterOutput, SIGNAL( textEdited (
const QString &) ),
this, SLOT(changeSearchSelection()));
2762 void G4OpenGLQtViewer::setCheckComponent(QTreeWidgetItem* item,
bool check)
2766 item->setCheckState(0,Qt::Checked);
2768 item->setCheckState(0,Qt::Unchecked);
2770 updatePositivePoIndexSceneTreeWidgetQuickMap(item->data(0,Qt::UserRole).toInt(),item);
2771 int nChildCount = item->childCount();
2772 for (
int i = 0; i < nChildCount; i++) {
2773 setCheckComponent(item->child(i),check);
2779 void G4OpenGLQtViewer::DrawText(
const G4Text& g4text)
2781 QGLWidget* qGLW =
dynamic_cast<QGLWidget*
> (fGLWidget) ;
2785 if (isGl2psWriting()) {
2787 G4OpenGLViewer::DrawText(g4text);
2791 if (!fGLWidget)
return;
2794 G4double size = fSceneHandler.GetMarkerSize(g4text,sizeType);
2796 QFont font = QFont();
2797 font.setPointSizeF(size);
2799 const G4Colour& c = fSceneHandler.GetTextColour(g4text);
2805 const char* textCString = textString.c_str();
2807 glRasterPos3d(position.x(),position.y(),position.z());
2810 QFontMetrics* f =
new QFontMetrics (font);
2811 G4double span = f->width(textCString);
2824 ((position.x()+(2*xmove)/getWinWidth()),
2825 (position.y()+(2*ymove)/getWinHeight()),
2834 void G4OpenGLQtViewer::ResetView () {
2835 G4OpenGLViewer::ResetView();
2845 const QString& modelShortName = getModelShortName(model);
2847 if (modelShortName ==
"") {
2851 if (fSceneTreeComponentTreeWidget == NULL) {
2852 initSceneTreeComponent();
2856 if (fSceneTreeComponentTreeWidget == NULL) {
2860 fSceneTreeComponentTreeWidget->blockSignals(
true);
2864 if (!fPVRootNodeCreate) {
2865 const G4VisAttributes* visAttr = GetApplicableVisAttributes(pPVModel->
GetFullPVPath().at(0).GetPhysicalVolume()->GetLogicalVolume()->GetVisAttributes());
2868 fModelShortNameItem = createTreeWidgetItem(pPVModel->
GetFullPVPath(),
2876 fPVRootNodeCreate =
true;
2879 bool added = parseAndInsertInSceneTree(fModelShortNameItem,pPVModel,0,modelShortName,0,currentPOIndex);
2883 fSceneTreeComponentTreeWidget->blockSignals(
false);
2892 QTreeWidgetItem* G4OpenGLQtViewer::createTreeWidgetItem(
2894 ,
const QString& name
2897 ,
const QString& logicalName
2898 ,Qt::CheckState state
2899 ,QTreeWidgetItem * parentTreeNode
2904 if (fullPath.size() > fSceneTreeDepth) {
2905 fSceneTreeDepth = fullPath.size();
2907 if (fSceneTreeDepthSlider) {
2908 fSceneTreeDepthSlider->setTickInterval(1000/(fSceneTreeDepth+1));
2911 QTreeWidgetItem * newItem = NULL;
2912 if (parentTreeNode == NULL) {
2913 newItem =
new QTreeWidgetItem();
2914 fSceneTreeComponentTreeWidget->addTopLevelItem(newItem);
2916 newItem =
new QTreeWidgetItem(parentTreeNode);
2917 fSceneTreeComponentTreeWidget->addTopLevelItem(parentTreeNode);
2921 newItem->setText(0,name);
2922 newItem->setData(1,Qt::UserRole,copyNb);
2923 newItem->setText(2,QString::number(POIndex));
2924 newItem->setData(0, Qt::UserRole, POIndex);
2925 newItem->setText(3,logicalName);
2926 newItem->setFlags(newItem->flags()|Qt::ItemIsUserCheckable);
2927 newItem->setCheckState(0,state);
2928 newItem->setExpanded(
true);
2929 updatePositivePoIndexSceneTreeWidgetQuickMap(POIndex,newItem);
2931 changeQColorForTreeWidgetItem(newItem,QColor((
int)(color.
GetRed()*255),
2937 if ((state == Qt::Unchecked) && (POIndex == -1)) {
2938 newItem->setForeground (0, QBrush(
Qt::gray) );
2941 newItem->setToolTip (0,QString(
2942 "This node exists in the geometry but has not been\n")+
2943 "drawn, perhaps because it has been set invisible. It \n"+
2944 "cannot be made visible with a click on the button.\n"+
2945 "To see it, change the visibility, for example, with \n"+
2946 "/vis/geometry/set/visibility " + logicalName +
" 0 true\n"+
2947 "and rebuild the view with /vis/viewer/rebuild.\n"+
2948 "Click here will only show/hide all child components");
2951 newItem->setToolTip (0,QString(
"double-click to change the color"));
2957 state = Qt::Unchecked;
2958 newItem->setCheckState(0,state);
2959 updatePositivePoIndexSceneTreeWidgetQuickMap(POIndex,newItem);
2962 fTreeItemModels.insert(std::pair <int, PVPath > (POIndex,fullPath) );
2966 changeOpenCloseVisibleHiddenSelectedColorSceneTreeElement(newItem);
2983 bool G4OpenGLQtViewer::parseAndInsertInSceneTree(
2984 QTreeWidgetItem * parentItem
2986 ,
unsigned int fullPathIndex
2987 ,
const QString& parentRoot
2988 ,
unsigned int currentIndexInTreeSceneHandler
2989 ,
int currentPVPOIndex
2992 if (parentItem == NULL) {
2998 std::ostringstream oss;
2999 oss << fullPath.at(fullPathIndex).GetCopyNo();
3000 std::string currentPVName =
G4String(fullPath.at(fullPathIndex).GetPhysicalVolume()->GetName()+
" ["+oss.str()+
"]").data();
3002 int currentPVCopyNb = fullPath.at(fullPathIndex).GetCopyNo();
3004 const G4VisAttributes* visAttr = GetApplicableVisAttributes(fullPath.at(fullPathIndex).GetPhysicalVolume()->GetLogicalVolume()->GetVisAttributes());
3013 QTreeWidgetItem* subItem = NULL;
3014 QList<QTreeWidgetItem *> parentItemList;
3022 if ((currentIndexInTreeSceneHandler == (fullPath.size()-1)) && ((color.GetAlpha() == 1.))) {
3024 QString lookForString = QString(currentPVName.c_str());
3025 for (
int i = 0;i < parentItem->childCount(); i++ ) {
3026 if (parentItem->child(i)->text(0) == lookForString) {
3027 parentItemList.push_back(parentItem->child(i));
3032 for (
int i = 0; i < parentItemList.size(); ++i) {
3033 const std::string& parentItemName = parentItemList.at(i)->text(0).toStdString();
3034 int parentItemCopyNb = parentItemList.at(i)->data(1,Qt::UserRole).toInt();
3035 int parentItemPOIndex = parentItemList.at(i)->data(0,Qt::UserRole).toInt();
3043 if (((parentRoot == fTouchableVolumes) && (currentPVCopyNb == parentItemCopyNb)
3044 && (currentPVName == parentItemName)) ||
3046 ((parentRoot != fTouchableVolumes) && (currentPVCopyNb == parentItemCopyNb)
3048 && (currentPVName == parentItemName) && (currentPVPOIndex == parentItemPOIndex) )) {
3051 bool sameTransform =
true;
3052 if (parentItemPOIndex >= 0) {
3053 const PVPath& fullPathTmp = fTreeItemModels[parentItemPOIndex];
3054 if (fullPathTmp.size() > 0) {
3055 if (fullPathTmp.at(fullPathTmp.size()-1).GetTransform () == pPVModel->
GetTransformation ()) {
3056 sameTransform =
true;
3058 sameTransform =
false;
3064 if (sameTransform ==
true) {
3071 if (currentIndexInTreeSceneHandler == (fullPath.size()-1)) {
3073 parentItemList.at(i)->setText(2,QString::number(currentPVPOIndex));
3074 parentItemList.at(i)->setData(0, Qt::UserRole,currentPVPOIndex);
3076 fTreeItemModels.insert(std::pair <int, PVPath >(currentPVPOIndex,fullPath) );
3080 parentItemList.at(i)->setFont (0,f);
3083 parentItemList.at(i)->setForeground (0,QBrush());
3086 parentItemList.at(i)->setToolTip (0,
"");
3088 changeQColorForTreeWidgetItem(parentItemList.at(i),QColor((
int)(color.GetRed()*255),
3089 (
int)(color.GetGreen()*255),
3090 (
int)(color.GetBlue()*255),
3091 (
int)(color.GetAlpha()*255)));
3094 if (color.GetAlpha() > 0) {
3095 parentItemList.at(i)->setCheckState(0,Qt::Checked);
3096 updatePositivePoIndexSceneTreeWidgetQuickMap(currentPVPOIndex,parentItemList.at(i));
3100 subItem = parentItemList.at(i);
3104 }
else if (currentIndexInTreeSceneHandler < (fullPath.size()-1)) {
3105 subItem = parentItemList.at(i);
3112 if (currentIndexInTreeSceneHandler == (fullPath.size()-1)) {
3113 createTreeWidgetItem(fullPath,
3114 QString(currentPVName.c_str()),
3117 QString(fullPath.at(fullPathIndex).GetPhysicalVolume()->GetLogicalVolume()->GetName().data()),
3122 if (currentPVPOIndex > fMaxPOindexInserted) {
3123 fMaxPOindexInserted = currentPVPOIndex;
3129 if (subItem == NULL) {
3131 if (currentIndexInTreeSceneHandler < (fullPath.size()-1)) {
3132 subItem = createTreeWidgetItem(fullPath,
3133 QString(currentPVName.c_str()),
3136 QString(fullPath.at(fullPathIndex).GetPhysicalVolume()->GetLogicalVolume()->GetName().data()),
3143 return parseAndInsertInSceneTree(subItem,pPVModel,fullPathIndex+1,parentRoot,currentIndexInTreeSceneHandler+1,currentPVPOIndex);
3149 void G4OpenGLQtViewer::changeOpenCloseVisibleHiddenSelectedColorSceneTreeElement(
3150 QTreeWidgetItem* subItem
3154 QTreeWidgetItem* oldItem = NULL;
3156 QTreeWidgetItem* foundItem = getOldTreeWidgetItem(subItem->data(0,Qt::UserRole).toInt());
3158 if (foundItem != NULL) {
3159 if (isSameSceneTreeElement(foundItem,subItem)) {
3160 oldItem = foundItem;
3163 if (foundItem == NULL) {
3166 std::map <int, QTreeWidgetItem*>::const_iterator i;
3167 i = fOldPositivePoIndexSceneTreeWidgetQuickMap.begin();
3168 while (i != fOldPositivePoIndexSceneTreeWidgetQuickMap.end()) {
3169 if (isSameSceneTreeElement(i->second,subItem)) {
3170 oldItem = i->second;
3171 i = fOldPositivePoIndexSceneTreeWidgetQuickMap.end();
3177 if (oldItem == NULL) {
3179 while (a < fOldNullPoIndexSceneTreeWidgetQuickVector.size()) {
3180 if (isSameSceneTreeElement(fOldNullPoIndexSceneTreeWidgetQuickVector[a],subItem)) {
3181 oldItem = fOldNullPoIndexSceneTreeWidgetQuickVector[
a];
3182 a = fOldNullPoIndexSceneTreeWidgetQuickVector.size();
3191 if (oldItem != NULL) {
3192 subItem->setFlags(oldItem->flags());
3193 subItem->setCheckState(0,oldItem->checkState(0));
3194 subItem->setSelected(oldItem->isSelected());
3195 subItem->setExpanded(oldItem->isExpanded ());
3200 std::map <int, QTreeWidgetItem* >::iterator it;
3203 int oldPOIndex = oldItem->data(0,Qt::UserRole).toInt();
3204 it = fOldPositivePoIndexSceneTreeWidgetQuickMap.find(oldPOIndex);
3208 std::map <int, QColor >::iterator itVis;
3209 itVis = fOldVisAttrColorMap.find(oldPOIndex);
3211 QColor oldVisAttrColor;
3212 const QColor& newVisAttrColor = subItem->data(2,Qt::UserRole).value<QColor>();
3214 bool visAttrChange =
false;
3216 if (itVis != fOldVisAttrColorMap.end()) {
3217 oldVisAttrColor = itVis->second;
3218 if (oldVisAttrColor != newVisAttrColor) {
3219 visAttrChange =
true;
3222 visAttrChange =
true;
3225 if (visAttrChange) {
3226 fOldVisAttrColorMap.insert(std::pair <int, QColor > (subItem->data(0,Qt::UserRole).toInt(),newVisAttrColor) );
3230 if (it != fOldPositivePoIndexSceneTreeWidgetQuickMap.end()) {
3231 color = (it->second)->data(2,Qt::UserRole).value<QColor>();
3233 color = oldItem->data(2,Qt::UserRole).value<QColor>();
3235 #ifdef G4DEBUG_VIS_OGL
3236 printf(
"====color name:%s\n",color.name().toStdString().c_str());
3238 changeQColorForTreeWidgetItem(subItem,color);
3250 bool G4OpenGLQtViewer::isSameSceneTreeElement(
3251 QTreeWidgetItem* parentOldItem
3252 ,QTreeWidgetItem* parentNewItem
3258 int newCpNumber = -1;
3259 int oldCpNumber = -1;
3261 bool firstWhile =
true;
3263 while ((parentOldItem != NULL) && (parentNewItem != NULL)) {
3267 oldPO = parentOldItem->data(0,Qt::UserRole).toInt();
3268 newPO = parentNewItem->data(0,Qt::UserRole).toInt();
3274 const PVPath& oldFullPath = fOldTreeItemModels[oldPO];
3275 const PVPath& newFullPath = fTreeItemModels[newPO];
3276 if ((oldFullPath.size() > 0) &&
3277 (newFullPath.size() > 0)) {
3278 if (oldFullPath.size() != newFullPath.size()) {
3281 if (oldFullPath.at(oldFullPath.size()-1).GetTransform () == newFullPath.at(newFullPath.size()-1).GetTransform ()) {
3282 newCpNumber = newFullPath.at(newFullPath.size()-1).GetCopyNo();
3283 oldCpNumber = oldFullPath.at(oldFullPath.size()-1).GetCopyNo();
3292 if (oldCpNumber == -1) {
3293 oldCpNumber = parentOldItem->data(1,Qt::UserRole).toInt();
3295 if (newCpNumber == -1) {
3296 newCpNumber = parentNewItem->data(1,Qt::UserRole).toInt();
3298 if ((oldCpNumber != newCpNumber) ||
3300 (parentOldItem->text(0) != parentNewItem->text(0)) ) {
3303 }
else if ((parentOldItem->text(0) != parentNewItem->text(0)) ||
3304 (parentOldItem->text(3) != parentNewItem->text(3))) {
3307 parentOldItem = parentOldItem->parent();
3308 parentNewItem = parentNewItem->parent();
3316 void G4OpenGLQtViewer::addNonPVSceneTreeElement(
3319 ,
const std::string& modelDescription
3323 QString modelShortName = getModelShortName(model);
3328 const G4Text& g4Text =
dynamic_cast<const G4Text&
>(visible);
3329 color = fSceneHandler.GetTextColour(g4Text);
3331 catch (std::bad_cast) {
3332 color = fSceneHandler.
GetColour(visible);
3334 if (modelShortName ==
"") {
3338 if (fSceneTreeComponentTreeWidget == NULL) {
3339 initSceneTreeComponent();
3343 if (fSceneTreeComponentTreeWidget == NULL) {
3347 fSceneTreeComponentTreeWidget->blockSignals(
true);
3351 QList<QTreeWidgetItem *> resItem;
3352 resItem = fSceneTreeComponentTreeWidget->findItems (modelShortName, Qt::MatchExactly, 0 );
3353 QTreeWidgetItem * currentItem = NULL;
3354 const PVPath tmpFullPath;
3356 if (resItem.empty()) {
3357 currentItem = createTreeWidgetItem(tmpFullPath,
3366 currentItem = resItem.first();
3370 const QList<QTreeWidgetItem *>&
3371 resItems = fSceneTreeComponentTreeWidget->findItems (QString(modelDescription.c_str()), Qt::MatchFixedString| Qt::MatchCaseSensitive|Qt::MatchRecursive, 0 );
3373 bool alreadyPresent =
false;
3374 for (
int i = 0; i < resItems.size(); ++i) {
3375 if (currentPOIndex == resItems.at(i)->data(0,Qt::UserRole).toInt()) {
3376 alreadyPresent =
true;
3379 if (!alreadyPresent) {
3380 createTreeWidgetItem(tmpFullPath,
3381 QString(modelDescription.c_str()),
3389 fSceneTreeComponentTreeWidget->blockSignals(
false);
3397 QString G4OpenGLQtViewer::getModelShortName(
const G4String& model) {
3399 QString modelShortName = model.
data();
3400 if (modelShortName.mid(0,modelShortName.indexOf(
" ")) ==
"G4PhysicalVolumeModel") {
3401 modelShortName = fTouchableVolumes;
3403 if (modelShortName.mid(0,2) ==
"G4") {
3404 modelShortName = modelShortName.mid(2);
3406 if (modelShortName.indexOf(
"Model") != -1) {
3407 modelShortName = modelShortName.mid(0,modelShortName.indexOf(
"Model"));
3410 return modelShortName;
3415 bool G4OpenGLQtViewer::isTouchableVisible(
int POindex){
3418 if (fSceneTreeComponentTreeWidget == NULL) {
3424 if (fLastSceneTreeWidgetAskForIterator != fLastSceneTreeWidgetAskForIteratorEnd) {
3425 fLastSceneTreeWidgetAskForIterator++;
3427 QTreeWidgetItem* item = getTreeWidgetItem(POindex);
3430 if ( item->checkState(0) == Qt::Checked) {
3438 bool G4OpenGLQtViewer::parseAndCheckVisibility(QTreeWidgetItem * treeNode,
int POindex){
3439 bool isFound =
false;
3440 for (
int i = 0; i < treeNode->childCount() ; ++i) {
3442 if (treeNode->child(i)->data(0,Qt::UserRole).toInt() == POindex) {
3443 if (treeNode->child(i)->checkState(0) == Qt::Checked) {
3447 isFound = parseAndCheckVisibility(treeNode->child(i),POindex);
3456 std::string G4OpenGLQtViewer::parseSceneTreeAndSaveState(){
3457 std::string commandLine =
"";
3458 for (
int b=0;b<fSceneTreeComponentTreeWidget->topLevelItemCount();b++) {
3459 commandLine += parseSceneTreeElementAndSaveState(fSceneTreeComponentTreeWidget->topLevelItem(b),1)+
"\n";
3461 if (commandLine !=
"") {
3462 commandLine = std::string(
"# Disable auto refresh and quieten vis messages whilst scene and\n") +
3463 "# trajectories are established:\n" +
3464 "/vis/viewer/set/autoRefresh false\n" +
3465 "/vis/verbose errors" +
3467 "# Re-establish auto refreshing and verbosity:\n" +
3468 "/vis/viewer/set/autoRefresh true\n" +
3469 "/vis/verbose confirmations\n";
3475 std::string G4OpenGLQtViewer::parseSceneTreeElementAndSaveState(QTreeWidgetItem* item,
unsigned int level){
3477 std::string str( level,
' ' );
3478 std::string commandLine =
"\n#"+ str +
"PV Name: " + item->text(0).toStdString();
3480 if (item->text(3) !=
"") {
3481 commandLine +=
" LV Name: "+item->text(3).toStdString()+
"\n";
3483 commandLine +=
"/vis/geometry/set/visibility " + item->text(3).toStdString() +
" ! ";
3484 if (item->checkState(0) == Qt::Checked) {
3487 if (item->checkState(0) == Qt::Unchecked) {
3493 const QColor& c = item->data(2,Qt::UserRole).value<QColor>();
3494 std::stringstream
red;
3495 red << ((double)c.red())/255;
3496 std::stringstream green;
3497 green << (double)c.green()/255;
3498 std::stringstream
blue;
3499 blue << ((double)c.blue())/255;
3500 std::stringstream
alpha;
3501 alpha << ((double)c.alpha())/255;
3503 commandLine +=
"/vis/geometry/set/colour " + item->text(3).toStdString() +
" ! " + red.str() +
" " + green.str() +
" " + blue.str() +
" " + alpha.str()+
"\n";
3506 commandLine +=
"\n";
3510 for (
int b=0;b< item->childCount();b++) {
3511 commandLine += parseSceneTreeElementAndSaveState(item->child(b),level+1);
3518 void G4OpenGLQtViewer::sceneTreeComponentItemChanged(QTreeWidgetItem* item,
int) {
3520 if (fCheckSceneTreeComponentSignalLock ==
false) {
3521 fCheckSceneTreeComponentSignalLock =
true;
3523 if (item->checkState(0) == Qt::Checked) {
3526 setCheckComponent(item,checked);
3529 fCheckSceneTreeComponentSignalLock =
false;
3534 void G4OpenGLQtViewer::sceneTreeComponentSelected() {
3552 void G4OpenGLQtViewer::changeDepthInSceneTree (
int val){
3555 if (fSceneTreeComponentTreeWidget == NULL) {
3566 double depth = 1 + ((double)val)/1000 * ((double)fSceneTreeDepth+1);
3569 fCheckSceneTreeComponentSignalLock =
true;
3572 G4bool currentAutoRefresh = fVP.IsAutoRefresh();
3573 fVP.SetAutoRefresh(
false);
3575 for (
int b=0;b<fSceneTreeComponentTreeWidget->topLevelItemCount();b++) {
3576 changeDepthOnSceneTreeItem(depth,1.,fSceneTreeComponentTreeWidget->topLevelItem(b));
3580 fVP.SetAutoRefresh(currentAutoRefresh);
3584 fCheckSceneTreeComponentSignalLock =
false;
3589 void G4OpenGLQtViewer::changeColorAndTransparency(QTreeWidgetItem* item,
int) {
3594 const QColor& old = QColor(item->data(2,Qt::UserRole).value<QColor>());
3596 #if QT_VERSION < 0x040500
3598 const QColor& color = QColor(QColorDialog::getRgba (old.rgba(),&
a,fSceneTreeComponentTreeWidget));
3600 const QColor& color = QColorDialog::getColor(old,
3601 fSceneTreeComponentTreeWidget,
3602 " Get color and transparency",
3603 QColorDialog::ShowAlphaChannel);
3606 if (color.isValid()) {
3608 changeColorAndTransparency(item->data(0,Qt::UserRole).toInt(),
3615 changeQColorForTreeWidgetItem(item,color);
3620 void G4OpenGLQtViewer::changeColorAndTransparency(GLuint index,
G4Color color) {
3624 if (iPO >= 0 && fTreeItemModels.find(iPO) != fTreeItemModels.end()) {
3625 const PVPath& fullPath = fTreeItemModels[iPO];
3627 if (fullPath.size()) {
3635 fVP.AddVisAttributesModifier
3648 G4Colour G4OpenGLQtViewer::getColorForPoIndex(
int poIndex) {
3650 QTreeWidgetItem* item = getTreeWidgetItem(poIndex);
3654 const QColor& color = item->data(2,Qt::UserRole).value<QColor>();
3667 G4OpenGLQtViewer::GetPrivateVisAttributesModifiers()
const
3669 static std::vector<G4ModelingParameters::VisAttributesModifier>
3670 privateVisAttributesModifiers;
3672 privateVisAttributesModifiers.clear();
3724 return &privateVisAttributesModifiers;
3728 void G4OpenGLQtViewer::changeSearchSelection()
3730 const QString& searchText = fFilterOutput->text();
3731 if (fSceneTreeComponentTreeWidget == NULL) {
3736 for (
int a=0; a<fSceneTreeComponentTreeWidget->topLevelItemCount(); a++) {
3737 fSceneTreeComponentTreeWidget->topLevelItem(a)->setExpanded(
false);
3738 fSceneTreeComponentTreeWidget->topLevelItem(a)->setSelected(
false);
3739 clearSceneTreeSelection(fSceneTreeComponentTreeWidget->topLevelItem(a));
3742 QList<QTreeWidgetItem *> itemList = fSceneTreeComponentTreeWidget->findItems (searchText,Qt::MatchContains | Qt::MatchRecursive,0);
3744 for (
int i = 0; i < itemList.size(); ++i) {
3745 QTreeWidgetItem* expandParentItem = itemList.at(i);
3746 while (expandParentItem->parent() != NULL) {
3747 expandParentItem->parent()->setExpanded(
true);
3748 expandParentItem = expandParentItem->parent();
3750 itemList.at(i)->setSelected(
true);
3756 void G4OpenGLQtViewer::clearSceneTreeSelection(QTreeWidgetItem* item) {
3757 for (
int a=0; a<item->childCount(); a++) {
3758 item->child(a)->setSelected(
false);
3759 item->child(a)->setExpanded(
false);
3760 clearSceneTreeSelection(item->child(a));
3766 bool G4OpenGLQtViewer::isPVVolume(QTreeWidgetItem* item) {
3767 QTreeWidgetItem* sParent = item;
3768 while (sParent->parent() != NULL) {
3769 sParent = sParent->parent();
3771 if (sParent->text(0) != fTouchableVolumes) {
3775 if (item->text(0) == fTouchableVolumes) {
3782 void G4OpenGLQtViewer::changeDepthOnSceneTreeItem(
3784 ,
double currentDepth
3785 ,QTreeWidgetItem* item
3787 double transparencyLevel = 0.;
3792 if (isPVVolume(item)) {
3793 if ((lookForDepth-currentDepth) < 0) {
3794 item->setCheckState(0,Qt::Checked);
3795 updatePositivePoIndexSceneTreeWidgetQuickMap(item->data(0,Qt::UserRole).toInt(),item);
3796 transparencyLevel = 1;
3797 }
else if ((lookForDepth-currentDepth) > 1 ){
3798 item->setCheckState(0,Qt::Unchecked);
3799 updatePositivePoIndexSceneTreeWidgetQuickMap(item->data(0,Qt::UserRole).toInt(),item);
3800 transparencyLevel = 0;
3802 item->setCheckState(0,Qt::Checked);
3803 updatePositivePoIndexSceneTreeWidgetQuickMap(item->data(0,Qt::UserRole).toInt(),item);
3804 transparencyLevel = 1-(lookForDepth-currentDepth);
3808 if (item->data(0,Qt::UserRole).toInt() >= 0) {
3809 const G4Colour& color = getColorForPoIndex(item->data(0,Qt::UserRole).toInt());
3821 if (((color.
GetAlpha()-transparencyLevel) > 0.000001) ||
3822 ((color.
GetAlpha()-transparencyLevel) < -0.000001)) {
3823 if ((item->text(3) !=
"")) {
3829 changeQColorForTreeWidgetItem(item,QColor((
int)(color.
GetRed()*255),
3832 (
int)(transparencyLevel*255)));
3837 for (
int b=0;b< item->childCount();b++) {
3838 changeDepthOnSceneTreeItem(lookForDepth,currentDepth+1,item->child(b));
3843 void G4OpenGLQtViewer::clearTreeWidget(){
3846 if (fSceneTreeComponentTreeWidget) {
3848 if (fOldSceneTreeComponentTreeWidget == NULL) {
3849 fOldSceneTreeComponentTreeWidget =
new QTreeWidget();
3852 int tmp = fOldSceneTreeComponentTreeWidget->topLevelItemCount();
3854 delete fOldSceneTreeComponentTreeWidget->takeTopLevelItem (0);
3855 tmp = fOldSceneTreeComponentTreeWidget->topLevelItemCount();
3858 if (fSceneTreeComponentTreeWidget->topLevelItemCount () > 0) {
3860 fPVRootNodeCreate =
false;
3863 fOldPositivePoIndexSceneTreeWidgetQuickMap.clear();
3864 fOldNullPoIndexSceneTreeWidgetQuickVector.clear();
3865 fOldTreeItemModels.clear();
3868 for (
int b =0; b <fSceneTreeComponentTreeWidget->topLevelItemCount();b++) {
3877 int poIndex = fSceneTreeComponentTreeWidget->topLevelItem(b)->data(0,Qt::UserRole).toInt();
3878 if (poIndex != -1) {
3879 fOldPositivePoIndexSceneTreeWidgetQuickMap.insert(std::pair <int, QTreeWidgetItem*> (poIndex,cloneWidgetItem(fSceneTreeComponentTreeWidget->topLevelItem(b))));
3881 fOldNullPoIndexSceneTreeWidgetQuickVector.push_back(cloneWidgetItem(fSceneTreeComponentTreeWidget->topLevelItem(b)));
3885 cloneSceneTree(fSceneTreeComponentTreeWidget->topLevelItem(b));
3889 fOldTreeItemModels.insert(fTreeItemModels.begin(), fTreeItemModels.end());
3892 int tmp2 = fSceneTreeComponentTreeWidget->topLevelItemCount();
3894 delete fSceneTreeComponentTreeWidget->takeTopLevelItem (0);
3895 tmp2 = fSceneTreeComponentTreeWidget->topLevelItemCount();
3897 fPositivePoIndexSceneTreeWidgetQuickMap.clear();
3900 fOldLastSceneTreeWidgetAskForIterator = fOldPositivePoIndexSceneTreeWidgetQuickMap.begin();
3901 fOldLastSceneTreeWidgetAskForIteratorEnd = fOldPositivePoIndexSceneTreeWidgetQuickMap.end();
3902 fSceneTreeDepth = 1;
3903 fModelShortNameItem = NULL;
3904 fMaxPOindexInserted = -1;
3917 QTreeWidgetItem * G4OpenGLQtViewer::cloneWidgetItem(QTreeWidgetItem* item) {
3919 QTreeWidgetItem* cloneItem =
new QTreeWidgetItem();
3923 cloneItem->setText(0,item->text(0));
3924 cloneItem->setData(1,Qt::UserRole,item->data(1,Qt::UserRole).toInt());
3925 cloneItem->setText(2,item->text(2));
3926 cloneItem->setData(0, Qt::UserRole,item->data(0,Qt::UserRole).toInt());
3927 cloneItem->setText(3,item->text(3));
3928 cloneItem->setFlags(item->flags());
3929 cloneItem->setToolTip(0,item->toolTip(0));
3930 cloneItem->setCheckState(0,item->checkState(0));
3931 cloneItem->setSelected(item->isSelected());
3932 cloneItem->setExpanded(item->isExpanded ());
3934 cloneItem->setData(2,Qt::UserRole,item->data(2,Qt::UserRole).value<QColor>());
3943 void G4OpenGLQtViewer::cloneSceneTree(
3944 QTreeWidgetItem* rootItem
3947 for (
int b=0;b< rootItem->childCount();b++) {
3949 QTreeWidgetItem *child = rootItem->child(b);
3952 int poIndex = child->data(0,Qt::UserRole).toInt();
3953 if (poIndex != -1) {
3954 fOldPositivePoIndexSceneTreeWidgetQuickMap.insert(std::pair <int, QTreeWidgetItem*> (poIndex,cloneWidgetItem(child)));
3956 fOldNullPoIndexSceneTreeWidgetQuickVector.push_back(cloneWidgetItem(child));
3958 cloneSceneTree(child);
3966 void G4OpenGLQtViewer::updatePositivePoIndexSceneTreeWidgetQuickMap(
int POindex,QTreeWidgetItem* item) {
3969 std::map <int, QTreeWidgetItem*>::iterator i;
3970 i = fPositivePoIndexSceneTreeWidgetQuickMap.find(POindex);
3972 if (i == fPositivePoIndexSceneTreeWidgetQuickMap.end()) {
3973 fPositivePoIndexSceneTreeWidgetQuickMap.insert(std::pair <int, QTreeWidgetItem*> (POindex,item) );
3974 fLastSceneTreeWidgetAskForIterator = fPositivePoIndexSceneTreeWidgetQuickMap.end();
3975 fLastSceneTreeWidgetAskForIteratorEnd = fPositivePoIndexSceneTreeWidgetQuickMap.end();
3983 void G4OpenGLQtViewer::changeQColorForTreeWidgetItem(QTreeWidgetItem* item,
const QColor& qc) {
3985 int POIndex = item->data(0,Qt::UserRole).toInt();
3986 updatePositivePoIndexSceneTreeWidgetQuickMap(POIndex,item );
3988 QPixmap pixmap = QPixmap(QSize(16, 16));
3989 if (item->data(0,Qt::UserRole).toInt() != -1) {
3992 pixmap.fill (QColor(255,255,255,255));
3994 QPainter painter(&pixmap);
3995 painter.setPen(Qt::black);
3996 painter.drawRect(0,0,15,15);
3998 item->setIcon(0,pixmap);
3999 item->setData(2,Qt::UserRole,qc);
4008 QTreeWidgetItem* G4OpenGLQtViewer::getTreeWidgetItem(
int POindex){
4011 if (POindex == -1) {
4015 if (fPositivePoIndexSceneTreeWidgetQuickMap.size() == 0){
4019 if (fLastSceneTreeWidgetAskForIterator != fLastSceneTreeWidgetAskForIteratorEnd) {
4020 if (POindex == fLastSceneTreeWidgetAskForIterator->first) {
4021 if (fLastSceneTreeWidgetAskForIterator->second != NULL) {
4022 return fLastSceneTreeWidgetAskForIterator->second;
4028 fLastSceneTreeWidgetAskForIterator = fPositivePoIndexSceneTreeWidgetQuickMap.find(POindex);
4029 fLastSceneTreeWidgetAskForIteratorEnd = fPositivePoIndexSceneTreeWidgetQuickMap.end();
4031 if (fLastSceneTreeWidgetAskForIterator != fPositivePoIndexSceneTreeWidgetQuickMap.end()) {
4032 return fLastSceneTreeWidgetAskForIterator->second;
4041 QTreeWidgetItem* G4OpenGLQtViewer::getOldTreeWidgetItem(
int POindex){
4045 if (POindex == -1) {
4049 if (fOldPositivePoIndexSceneTreeWidgetQuickMap.size() == 0){
4055 if (fOldLastSceneTreeWidgetAskForIterator != fOldLastSceneTreeWidgetAskForIteratorEnd) {
4056 fOldLastSceneTreeWidgetAskForIterator++;
4059 if (fOldLastSceneTreeWidgetAskForIterator != fOldPositivePoIndexSceneTreeWidgetQuickMap.end()) {
4060 if (POindex == fOldLastSceneTreeWidgetAskForIterator->first) {
4061 if (fOldLastSceneTreeWidgetAskForIterator->second != NULL) {
4062 return fOldLastSceneTreeWidgetAskForIterator->second;
4068 fOldLastSceneTreeWidgetAskForIterator = fOldPositivePoIndexSceneTreeWidgetQuickMap.find(POindex);
4069 fOldLastSceneTreeWidgetAskForIteratorEnd = fOldPositivePoIndexSceneTreeWidgetQuickMap.end();
4071 if (fOldLastSceneTreeWidgetAskForIterator != fOldPositivePoIndexSceneTreeWidgetQuickMap.end()) {
4072 return fOldLastSceneTreeWidgetAskForIterator->second;
4083 void G4OpenGLQtViewer::displaySceneTreeComponent() {
4085 if (fUISceneTreeComponentsTBWidget == NULL) {
4088 if (fSceneTreeComponentTreeWidget == NULL) {
4093 fSceneTreeComponentTreeWidget->sortItems (0, Qt::AscendingOrder );
4105 void G4OpenGLQtViewer::updateToolbarAndMouseContextMenu(){
4111 d_style = fVP.GetDrawingStyle();
4115 if (fUiQt) fUiQt->SetIconWireframeSelected();
4117 fDrawingWireframe->setChecked(
true);
4118 fDrawingLineRemoval->setChecked(
false);
4119 fDrawingSurfaceRemoval->setChecked(
false);
4120 fDrawingLineSurfaceRemoval->setChecked(
false);
4123 if (fUiQt) fUiQt->SetIconHLRSelected();
4125 fDrawingLineRemoval->setChecked(
true);
4126 fDrawingWireframe->setChecked(
false);
4127 fDrawingSurfaceRemoval->setChecked(
false);
4128 fDrawingLineSurfaceRemoval->setChecked(
false);
4131 if (fUiQt) fUiQt->SetIconSolidSelected();
4133 fDrawingSurfaceRemoval->setChecked(
true);
4134 fDrawingWireframe->setChecked(
false);
4135 fDrawingLineRemoval->setChecked(
false);
4136 fDrawingLineSurfaceRemoval->setChecked(
false);
4139 if (fUiQt) fUiQt->SetIconHLHSRSelected();
4141 fDrawingLineSurfaceRemoval->setChecked(
true);
4142 fDrawingWireframe->setChecked(
false);
4143 fDrawingLineRemoval->setChecked(
false);
4144 fDrawingSurfaceRemoval->setChecked(
false);
4145 fDrawingLineSurfaceRemoval->setChecked(
false);
4151 G4double d_proj = fVP.GetFieldHalfAngle () ;
4153 if (fUiQt) fUiQt->SetIconOrthoSelected();
4155 fProjectionOrtho->setChecked(
true);
4156 fProjectionPerspective->setChecked(
false);
4159 if (fUiQt) fUiQt->SetIconPerspectiveSelected();
4161 fProjectionPerspective->setChecked(
true);
4162 fProjectionOrtho->setChecked(
false);
4168 if (fUiQt && fContextMenu) {
4169 if (fUiQt->IsIconPickSelected()) {
4170 fMousePickAction->setChecked(
true);
4171 fMouseZoomOutAction->setChecked(
false);
4172 fMouseZoomInAction->setChecked(
false);
4173 fMouseRotateAction->setChecked(
false);
4174 fMouseMoveAction->setChecked(
false);
4175 }
else if (fUiQt->IsIconZoomOutSelected()) {
4176 fMouseZoomOutAction->setChecked(
true);
4177 fMousePickAction->setChecked(
false);
4178 fMouseZoomInAction->setChecked(
false);
4179 fMouseRotateAction->setChecked(
false);
4180 fMouseMoveAction->setChecked(
false);
4181 }
else if (fUiQt->IsIconZoomInSelected()) {
4182 fMouseZoomInAction->setChecked(
true);
4183 fMousePickAction->setChecked(
false);
4184 fMouseZoomOutAction->setChecked(
false);
4185 fMouseRotateAction->setChecked(
false);
4186 fMouseMoveAction->setChecked(
false);
4187 }
else if (fUiQt->IsIconRotateSelected()) {
4188 fMouseRotateAction->setChecked(
true);
4189 fMousePickAction->setChecked(
false);
4190 fMouseZoomOutAction->setChecked(
false);
4191 fMouseZoomInAction->setChecked(
false);
4192 fMouseMoveAction->setChecked(
false);
4193 }
else if (fUiQt->IsIconMoveSelected()) {
4194 fMouseMoveAction->setChecked(
true);
4195 fMousePickAction->setChecked(
false);
4196 fMouseZoomOutAction->setChecked(
false);
4197 fMouseZoomInAction->setChecked(
false);
4198 fMouseRotateAction->setChecked(
false);
4207 void G4OpenGLQtViewer::updateSceneTreeComponentTreeWidgetInfos() {
4209 if (!fSceneTreeComponentTreeWidgetInfos) {
4212 int treeWidgetInfosIgnoredCommands = 0;
4222 if ((path->
GetCommandEntry()-fTreeWidgetInfosIgnoredCommands) != fSceneTreeComponentTreeWidgetInfos->rowCount()) {
4223 fSceneTreeComponentTreeWidgetInfos->clear();
4226 fSceneTreeComponentTreeWidgetInfos->blockSignals(
true);
4229 fSceneTreeComponentTreeWidgetInfos->setColumnCount (2);
4230 fSceneTreeComponentTreeWidgetInfos->setRowCount (path->
GetCommandEntry()-fTreeWidgetInfosIgnoredCommands);
4231 fSceneTreeComponentTreeWidgetInfos->setHorizontalHeaderLabels(QStringList() << tr(
"Property")
4233 fSceneTreeComponentTreeWidgetInfos->verticalHeader()->setVisible(
false);
4234 fSceneTreeComponentTreeWidgetInfos->setAlternatingRowColors (
true);
4242 QString params =
"";
4245 if (fVP.IsAutoRefresh()) {
4251 if (fVP.IsAuxEdgeVisible()) {
4257 params = QString().number(fVP.GetBackgroundColour().GetRed()) +
" "+
4258 QString().number(fVP.GetBackgroundColour().GetGreen()) +
" "+
4259 QString().number(fVP.GetBackgroundColour().GetBlue()) +
" "+
4260 QString().number(fVP.GetBackgroundColour().GetAlpha());
4263 params = QString().number(fVP. IsCulling ());
4268 params =
"intersection";
4272 params = QString().number(fVP.GetDefaultVisAttributes()->GetColor().GetRed()) +
" "+
4273 QString().number(fVP.GetDefaultVisAttributes()->GetColor().GetGreen()) +
" "+
4274 QString().number(fVP.GetDefaultVisAttributes()->GetColor().GetBlue()) +
" "+
4275 QString().number(fVP.GetDefaultVisAttributes()->GetColor().GetAlpha());
4278 params = QString().number(fVP.GetDefaultTextVisAttributes()->GetColor().GetRed()) +
" "+
4279 QString().number(fVP.GetDefaultTextVisAttributes()->GetColor().GetGreen()) +
" "+
4280 QString().number(fVP.GetDefaultTextVisAttributes()->GetColor().GetBlue()) +
" "+
4281 QString().number(fVP.GetDefaultTextVisAttributes()->GetColor().GetAlpha());
4291 params = QString().number(fVP.GetExplodeFactor()) +
" " + QString(
G4String(
G4BestUnit(fVP.GetExplodeFactor(),
"Length")).
data());
4293 }
else if(commandTmp->
GetCommandName() ==
"globalLineWidthScale") {
4294 params = QString().number(fVP.GetGlobalLineWidthScale());
4297 params = QString().number(fVP.GetGlobalMarkerScale());
4309 if (fVP.IsMarkerNotHidden()) {
4316 if (fVP.GetLightsMoveWithCamera()) {
4322 G4Vector3D direction = fVP.GetLightpointDirection();
4331 params = QString().number(fVP.GetLightpointDirection().x()) +
" "+
4332 QString().number(fVP.GetLightpointDirection().y()) +
" "+
4333 QString().number(fVP.GetLightpointDirection().z());
4335 }
else if(commandTmp->
GetCommandName() ==
"lineSegmentsPerCircle") {
4336 params = QString().number(fVP.GetNoOfSides());
4339 if (fVP.IsPicking()) {
4346 if (fVP.GetFieldHalfAngle() == 0.) {
4347 params =
"orthogonal";
4349 params = QString(
"perspective ") + QString().number(fVP.GetFieldHalfAngle()/
CLHEP::degree) +
" deg";
4354 params =
"constrainUpDirection";
4356 params =
"freeRotation";
4360 if (fVP.IsSection()) {
4361 params = QString(
"on ") +
4363 QString().number(fVP.GetSectionPlane().normal().x())
4364 +
" " + QString().number(fVP.GetSectionPlane().normal().y())
4365 +
" " + QString().number(fVP.GetSectionPlane().normal().z());
4372 params =
"wireframe";
4379 G4Point3D point = fVP.GetCurrentTargetPoint();
4380 if (fSceneHandler.GetScene()) {
4381 G4String b =
G4BestUnit(fSceneHandler.GetScene()->GetStandardTargetPoint() + fVP.GetCurrentTargetPoint(),
"Length");
4395 params = QString().number(up.x())+
" "+ QString().number(up.y())+
" "+QString().number(up.z())+
" ";
4398 G4Vector3D direction = fVP.GetViewpointDirection();
4407 G4Vector3D direction = fVP.GetViewpointDirection();
4408 params = QString().number(direction.x())+
" "+ QString().number(direction.y())+
" "+QString().number(direction.z());
4438 QTableWidgetItem *nameItem;
4439 QTableWidgetItem *paramItem;
4442 QList<QTableWidgetItem *> list = fSceneTreeComponentTreeWidgetInfos->findItems (commandTmp->
GetCommandName().
data(),Qt::MatchExactly);
4443 if (list.size() == 1) {
4444 nameItem = list.first();
4445 paramItem = fSceneTreeComponentTreeWidgetInfos->item(nameItem->row(),1);
4448 nameItem =
new QTableWidgetItem();
4449 paramItem =
new QTableWidgetItem();
4450 fSceneTreeComponentTreeWidgetInfos->setItem(a-treeWidgetInfosIgnoredCommands, 0, nameItem);
4451 fSceneTreeComponentTreeWidgetInfos->setItem(a-treeWidgetInfosIgnoredCommands, 1, paramItem);
4456 for(
G4int i_thGuidance=0; i_thGuidance < n_guidanceEntry; i_thGuidance++ ) {
4457 guidance += QString((
char*)(commandTmp->
GetGuidanceLine(i_thGuidance)).data()) +
"\n";
4460 nameItem->setToolTip(guidance);
4461 paramItem->setToolTip(GetCommandParameterList(commandTmp));
4463 fSceneTreeComponentTreeWidgetInfos->setRowHeight(a-treeWidgetInfosIgnoredCommands,15);
4468 paramItem->setText(params);
4470 nameItem->setFlags(Qt::NoItemFlags);
4471 nameItem->setForeground(QBrush());
4474 treeWidgetInfosIgnoredCommands++;
4478 for (
int i=0; i<treeWidgetInfosIgnoredCommands; i++) {
4479 fSceneTreeComponentTreeWidgetInfos->removeRow (fSceneTreeComponentTreeWidgetInfos->rowCount() - 1);
4482 fSceneTreeComponentTreeWidgetInfos->resizeColumnToContents(0);
4483 fSceneTreeComponentTreeWidgetInfos->horizontalHeader()->setStretchLastSection(
true);
4484 fSceneTreeComponentTreeWidgetInfos->blockSignals(
false);
4486 fTreeWidgetInfosIgnoredCommands = treeWidgetInfosIgnoredCommands;
4491 void G4OpenGLQtViewer::toggleSceneTreeViewerInfos() {
4492 if (! fSceneTreeViewerButton) {
4495 fSceneTreeViewerInfos->setVisible(!fSceneTreeViewerInfos->isVisible());
4496 if (fSceneTreeViewerInfos->isVisible()) {
4497 fSceneTreeViewerButton->setIcon(*fTreeIconOpen);
4499 fSceneTreeViewerButton->setIcon(*fTreeIconClosed);
4504 void G4OpenGLQtViewer::toggleSceneTreeComponentTreeWidgetInfos() {
4505 fSceneTreeComponentTreeWidgetInfos->setVisible(!fSceneTreeComponentTreeWidgetInfos->isVisible());
4506 if (fSceneTreeComponentTreeWidgetInfos->isVisible()) {
4507 fViewerPropertiesButton->setIcon(*fTreeIconOpen);
4509 fViewerPropertiesButton->setIcon(*fTreeIconClosed);
4514 void G4OpenGLQtViewer::toggleSceneTreeComponentPickingInfos() {
4515 fSceneTreeComponentPickingScrollArea->setVisible(!fSceneTreeComponentPickingScrollArea->isVisible());
4516 if (fViewerPickingButton->isVisible()) {
4517 fViewerPickingButton->setIcon(*fTreeIconOpen);
4519 fViewerPickingButton->setIcon(*fTreeIconClosed);
4524 void G4OpenGLQtViewer::toggleSceneTreeComponentPickingCout(
int pickItem) {
4529 for (
int a=0; a<fSceneTreeComponentPickingInfos->layout()->count(); a++) {
4530 w = fSceneTreeComponentPickingInfos->layout()->itemAt(a)->widget();
4531 QTextEdit* ed =
dynamic_cast<QTextEdit*
>(w);
4532 QPushButton* button;
4534 if (a == pickItem) {
4535 w->setVisible(!w->isVisible());
4537 w->setVisible(
false);
4540 button =
dynamic_cast<QPushButton*
>(fSceneTreeComponentPickingInfos->layout()->itemAt(a-1)->widget());
4542 if (button->isVisible()) {
4543 button->setIcon(*fTreeIconOpen);
4545 button->setIcon(*fTreeIconClosed);
4554 void G4OpenGLQtViewer::tableWidgetViewerSetItemChanged(QTableWidgetItem * item) {
4557 QTableWidgetItem* previous = fSceneTreeComponentTreeWidgetInfos->item(fSceneTreeComponentTreeWidgetInfos->row(item),0);
4559 fSceneTreeComponentTreeWidgetInfos->blockSignals(
true);
4561 + previous->text().toStdString()
4563 + item->text().toStdString()).c_str());
4564 fSceneTreeComponentTreeWidgetInfos->blockSignals(
false);
4577 QString G4OpenGLQtViewer::GetCommandParameterList (
4584 if( n_parameterEntry > 0 ) {
4589 for(
G4int i_thParameter=0; i_thParameter<n_parameterEntry; i_thParameter++ ) {
4591 txt +=
"\nParameter : " + QString((
char*)(param->
GetParameterName()).data()) +
"\n";
4594 txt +=
" Parameter type : " + QString(QChar(param->
GetParameterType())) +
"\n";
4596 txt +=
" Omittable : True\n";
4598 txt +=
" Omittable : False\n";
4601 txt +=
" Default value : taken from the current value\n";
4603 txt +=
" Default value : " + QString((
char*)(param->
GetDefaultValue()).data())+
"\n";
4606 txt +=
" Parameter range : " + QString((
char*)(param->
GetParameterRange()).data())+
"\n";
4616 #ifdef G4MULTITHREADED
4618 void G4OpenGLQtViewer::SwitchToVisSubThread()
4620 G4cout <<
"G4OpenGLQtViewer::SwitchToVisSubThread" <<
G4endl;
4621 QGLWidget* qGLW =
dynamic_cast<QGLWidget*
> (fGLWidget) ;
4625 qGLW->makeCurrent();
4628 void G4OpenGLQtViewer::SwitchToMasterThread()
4630 G4cout <<
"G4OpenGLQtViewer::SwitchToMasterThread" <<
G4endl;
G4UIcommandTree * FindCommandTree(const char *commandPath)
Try to match a command or a path with the one given.
void SetColour(const G4Colour &)
G4String GetParameterCandidates() const
G4double GetAlpha() const
G4int GetCommandEntry() const
G4String GetParameterName() const
G4UIcommand * GetCommand(G4int i)
const G4Transform3D & GetTransformation() const
static G4bool GetColour(const G4String &key, G4Colour &result)
const G4Colour & GetColour() const
HepGeom::Point3D< G4double > G4Point3D
HepGeom::Vector3D< G4double > G4Vector3D
#define G4BestUnit(a, b)
#define G4_USE_G4BESTUNIT_FOR_VERBOSE 1
G4Point3D GetPosition() const
const G4String & GetGuidanceLine(G4int i) const
static G4UImanager * GetUIpointer()
G4bool IsOmittable() const
G4double GetYOffset() const
G4GLOB_DLL std::ostream G4cout
G4double GetGreen() const
G4UIparameter * GetParameter(G4int i) const
std::vector< PVNodeID > PVPath
const std::vector< G4PhysicalVolumeNodeID > & GetFullPVPath() const
const G4String & GetCommandName() const
const char * data() const
G4double GetXOffset() const
static const G4double factor
G4UIcommandTree * GetTree() const
G4String GetDefaultValue() const
char GetParameterType() const
static const double degree
static MCTruthManager * instance
static PROLOG_HANDLER error
const G4String GetParameterGuidance() const
void print(const std::vector< T > &data)
G4String GetParameterRange() const
static const G4double alpha
G4int GetGuidanceEntries() const
G4int GetParameterEntries() const
G4bool GetCurrentAsDefault() const
static const G4double pos
G4int ApplyCommand(const char *aCommand)
std::vector< G4PolyconeSideRZ > g4c
G4GLOB_DLL std::ostream G4cerr